bug 1389641 adjust ConvolverNode buffer normalization gain calibration to match spec r?padenot draft
authorKarl Tomlinson <karlt+@karlt.net>
Sat, 12 Aug 2017 08:55:05 +1200
changeset 645179 23337d67c5b5f765f956700a47de414df0e53b2a
parent 645178 7091192fd5ee850f172178ec5f577787a363c5d8
child 725839 b3ca2335d800aeee9c8eb16b6423599921c1c233
push id73684
push userktomlinson@mozilla.com
push dateFri, 11 Aug 2017 22:29:12 +0000
reviewerspadenot
bugs1389641
milestone57.0a1
bug 1389641 adjust ConvolverNode buffer normalization gain calibration to match spec r?padenot This reduces the amplitude by about 0.7%. MozReview-Commit-ID: EpVCPCRWk48
dom/media/webaudio/blink/Reverb.cpp
testing/web-platform/tests/webaudio/the-audio-api/the-convolvernode-interface/convolver-normalization.html
--- a/dom/media/webaudio/blink/Reverb.cpp
+++ b/dom/media/webaudio/blink/Reverb.cpp
@@ -33,17 +33,17 @@
 #include "ReverbConvolver.h"
 #include "mozilla/FloatingPoint.h"
 
 using namespace mozilla;
 
 namespace WebCore {
 
 // Empirical gain calibration tested across many impulse responses to ensure perceived volume is same as dry (unprocessed) signal
-const float GainCalibration = -58;
+const float GainCalibration = 0.00125;
 const float GainCalibrationSampleRate = 44100;
 
 // A minimum power value to when normalizing a silent (or very quiet) impulse response
 const float MinPower = 0.000125f;
 
 static float calculateNormalizationScale(const nsTArray<const float*>& response, size_t aLength, float sampleRate)
 {
     // Normalize by RMS power
@@ -59,17 +59,17 @@ static float calculateNormalizationScale
     power = sqrt(power / (numberOfChannels * aLength));
 
     // Protect against accidental overload
     if (!IsFinite(power) || IsNaN(power) || power < MinPower)
         power = MinPower;
 
     float scale = 1 / power;
 
-    scale *= powf(10, GainCalibration * 0.05f); // calibrate to make perceived volume same as unprocessed
+    scale *= GainCalibration; // calibrate to make perceived volume same as unprocessed
 
     // Scale depends on sample-rate.
     if (sampleRate)
         scale *= GainCalibrationSampleRate / sampleRate;
 
     // True-stereo compensation
     if (numberOfChannels == 4)
         scale *= 0.5f;
--- a/testing/web-platform/tests/webaudio/the-audio-api/the-convolvernode-interface/convolver-normalization.html
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-convolvernode-interface/convolver-normalization.html
@@ -63,19 +63,19 @@ function test_normalization_via_response
         if (output[i] > max) {
           max = output[i];
           maxIndex = i;
         } else if (output[i] < min) {
           min = output[i];
           minIndex = i;
         }
       }
-      // Blink and Gecko use a slighty different GainCalibration to that
-      // specified, and so, instead of expecting unit output, check that the
-      // output is constant.
+      // Blink uses a slighty different GainCalibration to that specified,
+      // and so, instead of expecting unit output, check that the output is
+      // constant.
       assert_approx_equals(output[maxIndex], output[minIndex], EPSILON,
                            "output at " + maxIndex +
                            " differs from output at " + minIndex);
     });
 }
 
 promise_test(test_normalization_via_response_concat,
              "via response concatenation");