Bug 1424906 - Fix PeriodicWave disableNormalization false behaviour; r=padenot
authorDan Minor <dminor@mozilla.com>
Thu, 14 Dec 2017 09:43:21 -0600
changeset 448269 1d950eec8c65c3d39dd65cd900263cd7884c98c4
parent 448268 bed16c4af706a958adeb3e4222fbe833fd7ecdfa
child 448270 8f884ff63d0cec6f15752c7cb971804cb7c8fa8b
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1424906
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1424906 - Fix PeriodicWave disableNormalization false behaviour; r=padenot This adds a scaling factor of 0.5 even when normalization is disabled, which is required for correct results. MozReview-Commit-ID: J0VbMcaacGc
dom/media/webaudio/blink/PeriodicWave.cpp
dom/media/webaudio/test/test_periodicWaveDisableNormalization.html
--- a/dom/media/webaudio/blink/PeriodicWave.cpp
+++ b/dom/media/webaudio/blink/PeriodicWave.cpp
@@ -269,28 +269,30 @@ void PeriodicWave::createBandLimitedTabl
     m_bandLimitedTables[rangeIndex] = table;
 
     // Apply an inverse FFT to generate the time-domain table data.
     float* data = m_bandLimitedTables[rangeIndex]->Elements();
     frame.GetInverseWithoutScaling(data);
 
     // For the first range (which has the highest power), calculate
     // its peak value then compute normalization scale.
-    if (!m_disableNormalization && !rangeIndex) {
+    if (m_disableNormalization) {
+      // See Bug 1424906, results need to be scaled by 0.5 even
+      // when normalization is disabled.
+      m_normalizationScale = 0.5;
+    } else if (!rangeIndex) {
         float maxValue;
         maxValue = AudioBufferPeakValue(data, m_periodicWaveSize);
 
         if (maxValue)
             m_normalizationScale = 1.0f / maxValue;
     }
 
     // Apply normalization scale.
-    if (!m_disableNormalization) {
-      AudioBufferInPlaceScale(data, m_normalizationScale, m_periodicWaveSize);
-    }
+    AudioBufferInPlaceScale(data, m_normalizationScale, m_periodicWaveSize);
 }
 
 void PeriodicWave::generateBasicWaveform(OscillatorType shape)
 {
     const float piFloat = float(M_PI);
     unsigned fftSize = periodicWaveSize();
     unsigned halfSize = fftSize / 2;
 
--- a/dom/media/webaudio/test/test_periodicWaveDisableNormalization.html
+++ b/dom/media/webaudio/test/test_periodicWaveDisableNormalization.html
@@ -76,19 +76,17 @@ var gTest = {
       buffer.getChannelData(0)[i] = 1.0 / realPeak *
         (real[1] * Math.cos(2 * Math.PI * realFundamental * i /
                             context.sampleRate) +
          real[realMax] * Math.cos(2 * Math.PI * realMax * realFundamental * i /
                             context.sampleRate));
 
       buffer.getChannelData(1)[i] = buffer.getChannelData(0)[i];
 
-      // TODO: We need to scale by a factor of two to make the results work
-      //       out here. This seems suspicious, see Bug 1266737.
-      buffer.getChannelData(2)[i] = 2.0 *
+      buffer.getChannelData(2)[i] =
         (real[1] * Math.cos(2 * Math.PI * realFundamental * i /
                             context.sampleRate) +
          real[realMax] * Math.cos(2 * Math.PI * realMax * realFundamental * i /
                             context.sampleRate));
     }
     return buffer;
   },
   'numberOfChannels': 3,