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
--- 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");