From ef6f6ae5e4c96622286b563658d5cd62a6cf1197 Mon Sep 17 00:00:00 2001 From: rtoy Date: Fri, 26 Feb 2016 18:11:17 -0800 Subject: [PATCH] Don't clip FFT output values to minDecibels. If the (linear) FFT value is zero, the dB value was set to analyser.minDecibels. The spec doesn't require this and it makes more sense to return the expected -Infinity instead. BUG=588853 TEST=realtimeanalyser-zero.html Review URL: https://codereview.chromium.org/1729783002 Cr-Commit-Position: refs/heads/master@{#378081} --- .../realtimeanalyser-zero-expected.txt | 10 +++ .../webaudio/realtimeanalyser-zero.html | 63 +++++++++++++++++++ .../modules/webaudio/RealtimeAnalyser.cpp | 5 +- .../Source/platform/audio/AudioUtilities.cpp | 6 +- 4 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 third_party/WebKit/LayoutTests/webaudio/realtimeanalyser-zero-expected.txt create mode 100644 third_party/WebKit/LayoutTests/webaudio/realtimeanalyser-zero.html diff --git a/third_party/WebKit/LayoutTests/webaudio/realtimeanalyser-zero-expected.txt b/third_party/WebKit/LayoutTests/webaudio/realtimeanalyser-zero-expected.txt new file mode 100644 index 0000000000000..6991218e6be70 --- /dev/null +++ b/third_party/WebKit/LayoutTests/webaudio/realtimeanalyser-zero-expected.txt @@ -0,0 +1,10 @@ +Test AnalyserNode getFloatFrequencyData With Zero-Valued Input + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS getFloatFrequencyData() with zero-valued input contains only the constant -Infinity. +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/third_party/WebKit/LayoutTests/webaudio/realtimeanalyser-zero.html b/third_party/WebKit/LayoutTests/webaudio/realtimeanalyser-zero.html new file mode 100644 index 0000000000000..3c12bda7fdc8b --- /dev/null +++ b/third_party/WebKit/LayoutTests/webaudio/realtimeanalyser-zero.html @@ -0,0 +1,63 @@ + + + + + + + Test getFloatFrequencyData With Zero Inputs + + + + + + diff --git a/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp b/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp index 78088ad423ee6..902e7900e11b7 100644 --- a/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp +++ b/third_party/WebKit/Source/modules/webaudio/RealtimeAnalyser.cpp @@ -188,7 +188,6 @@ void RealtimeAnalyser::doFFTAnalysis() void RealtimeAnalyser::convertFloatToDb(DOMFloat32Array* destinationArray) { // Convert from linear magnitude to floating-point decibels. - const double minDecibels = m_minDecibels; unsigned sourceLength = magnitudeBuffer().size(); size_t len = std::min(sourceLength, destinationArray->length()); if (len > 0) { @@ -197,7 +196,7 @@ void RealtimeAnalyser::convertFloatToDb(DOMFloat32Array* destinationArray) for (unsigned i = 0; i < len; ++i) { float linearValue = source[i]; - double dbMag = !linearValue ? minDecibels : AudioUtilities::linearToDecibels(linearValue); + double dbMag = AudioUtilities::linearToDecibels(linearValue); destination[i] = float(dbMag); } } @@ -234,7 +233,7 @@ void RealtimeAnalyser::convertToByteData(DOMUint8Array* destinationArray) for (unsigned i = 0; i < len; ++i) { float linearValue = source[i]; - double dbMag = !linearValue ? minDecibels : AudioUtilities::linearToDecibels(linearValue); + double dbMag = AudioUtilities::linearToDecibels(linearValue); // The range m_minDecibels to m_maxDecibels will be scaled to byte values from 0 to UCHAR_MAX. double scaledValue = UCHAR_MAX * (dbMag - minDecibels) * rangeScaleFactor; diff --git a/third_party/WebKit/Source/platform/audio/AudioUtilities.cpp b/third_party/WebKit/Source/platform/audio/AudioUtilities.cpp index e716d6ca6566f..f162c6be9079d 100644 --- a/third_party/WebKit/Source/platform/audio/AudioUtilities.cpp +++ b/third_party/WebKit/Source/platform/audio/AudioUtilities.cpp @@ -37,11 +37,7 @@ float decibelsToLinear(float decibels) float linearToDecibels(float linear) { - // It's not possible to calculate decibels for a zero linear value since it would be -Inf. - // -1000.0 dB represents a very tiny linear value in case we ever reach this case. - ASSERT(linear); - if (!linear) - return -1000; + ASSERT(linear >= 0); return 20 * log10f(linear); }