Bug 1308438 - Part 1: Implement ReverseCopyFromInputBuffer to perform copy from input buffer in reverse order. r?dminor, r?padenot draft
authorBeekill95 <nnn_bikiu0707@yahoo.com>
Tue, 21 Mar 2017 22:01:41 +0700
changeset 502798 1028d0fde2baf014941d4d6e1327b20e29f825da
parent 481225 b772e0f4138540113e91a46c99bb0d14ecc8acca
child 502799 fb7641e07bad3ab775d9f10673eb3bd3574b43b7
push id50409
push userbmo:nnn_bikiu0707@yahoo.com
push dateWed, 22 Mar 2017 11:28:53 +0000
reviewersdminor, padenot
bugs1308438
milestone54.0a1
Bug 1308438 - Part 1: Implement ReverseCopyFromInputBuffer to perform copy from input buffer in reverse order. r?dminor, r?padenot MozReview-Commit-ID: AmdCyjHQaCd
dom/media/webaudio/AudioBufferSourceNode.cpp
--- 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,