bug 1389638 include leading unaligned AudioBufferSumOfSquares input in length count and check for end of buffer r?dminor draft
authorKarl Tomlinson <karlt+@karlt.net>
Fri, 11 Aug 2017 23:25:56 +1200
changeset 645177 b550b7963ac72d9f7417d544cf5cb78d2c7d6836
parent 645176 331446e2f876ceb06639f26b4c793cf3c86b0db8
child 645178 7091192fd5ee850f172178ec5f577787a363c5d8
push id73684
push userktomlinson@mozilla.com
push dateFri, 11 Aug 2017 22:29:12 +0000
reviewersdminor
bugs1389638
milestone57.0a1
bug 1389638 include leading unaligned AudioBufferSumOfSquares input in length count and check for end of buffer r?dminor The length of the array for AudioBufferSumOfSquares_SSE() is calculated from available aligned input, instead of total input.
dom/media/webaudio/AudioNodeEngine.cpp
--- a/dom/media/webaudio/AudioNodeEngine.cpp
+++ b/dom/media/webaudio/AudioNodeEngine.cpp
@@ -349,24 +349,28 @@ AudioBlockPanStereoToStereo(const float 
 float
 AudioBufferSumOfSquares(const float* aInput, uint32_t aLength)
 {
   float sum = 0.0f;
 
 #ifdef USE_SSE2
   if (mozilla::supports_sse()) {
     const float* alignedInput = ALIGNED16(aInput);
-    uint32_t vLength = (aLength >> 4) << 4;
 
     // use scalar operations for any unaligned data at the beginning
     while (aInput != alignedInput) {
-        sum += *aInput * *aInput;
-        ++aInput;
+      if (!aLength) {
+        return sum;
+      }
+      sum += *aInput * *aInput;
+      ++aInput;
+      --aLength;
     }
 
+    uint32_t vLength = (aLength >> 4) << 4;
     sum += AudioBufferSumOfSquares_SSE(alignedInput, vLength);
 
     // adjust aInput and aLength to use scalar operations for any
     // remaining values
     aInput = alignedInput + 1;
     aLength -= vLength;
   }
 #endif