Bug 1308438 - Part 1: Implement ReverseCopyFromInputBuffer to perform copy from input buffer in reverse order. r?dminor, r?padenot
MozReview-Commit-ID: AmdCyjHQaCd
--- a/dom/media/webaudio/AudioBufferSourceNode.cpp
+++ b/dom/media/webaudio/AudioBufferSourceNode.cpp
@@ -233,16 +233,31 @@ public:
for (uint32_t i = 0; i < aChannels; ++i) {
float* baseChannelData = aOutput->ChannelFloatsForWrite(i);
memcpy(baseChannelData + aOffsetWithinBlock,
mBuffer->GetData(i) + mBufferPosition,
aNumberOfFrames * sizeof(float));
}
}
+ // This has the same function as CopyFromInputBuffer
+ // but the input buffer is copied in reverse order
+ void ReverseCopyFromInputBuffer(AudioBlock* aOutput,
+ uint32_t aChannels,
+ uintptr_t aOffsetWithinBlock,
+ uint32_t aNumberOfFrames) {
+ for (uint32_t i = 0; i < aChannels; ++i) {
+ float* baseChannelData = aOutput->ChannelFloatsForWrite(i) + aOffsetWithinBlock;
+ const float* bufferData = mBuffer->GetData(i);
+ for (uint32_t j = 0; j < aNumberOfFrames; ++j) {
+ baseChannelData[j] = bufferData[mBufferPosition - j - 1];
+ }
+ }
+ }
+
// Resamples input data to an output buffer, according to |mBufferSampleRate| and
// the playbackRate/detune.
// The number of frames consumed/produced depends on the amount of space
// remaining in both the input and output buffer, and the playback rate (that
// is, the ratio between the output samplerate and the input samplerate).
void CopyFromInputBufferWithResampling(AudioBlock* aOutput,
uint32_t aChannels,
uint32_t* aOffsetWithinBlock,