RealtimeAnalyserNode does not consistently respect .minDecibels
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2012 20:57:02 +0000 (20:57 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Feb 2012 20:57:02 +0000 (20:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78729

Make use of m_minDecibel consistent.  Clean up some style issues
with names of local variables and style issues with float
constants.

Patch by Raymond Toy <rtoy@google.com> on 2012-02-17
Reviewed by Chris Rogers.

No new tests because the changes are cosmetic for style issues.

* webaudio/RealtimeAnalyser.cpp:
(WebCore):
(WebCore::RealtimeAnalyser::doFFTAnalysis):
(WebCore::RealtimeAnalyser::getFloatFrequencyData):
(WebCore::RealtimeAnalyser::getByteFrequencyData):
(WebCore::RealtimeAnalyser::getByteTimeDomainData):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@108110 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/webaudio/RealtimeAnalyser.cpp

index d64d73f..728b170 100644 (file)
@@ -1,3 +1,23 @@
+2012-02-17  Raymond Toy  <rtoy@google.com>
+
+        RealtimeAnalyserNode does not consistently respect .minDecibels
+        https://bugs.webkit.org/show_bug.cgi?id=78729
+
+        Make use of m_minDecibel consistent.  Clean up some style issues
+        with names of local variables and style issues with float
+        constants.
+        
+        Reviewed by Chris Rogers.
+
+        No new tests because the changes are cosmetic for style issues.
+
+        * webaudio/RealtimeAnalyser.cpp:
+        (WebCore):
+        (WebCore::RealtimeAnalyser::doFFTAnalysis):
+        (WebCore::RealtimeAnalyser::getFloatFrequencyData):
+        (WebCore::RealtimeAnalyser::getByteFrequencyData):
+        (WebCore::RealtimeAnalyser::getByteTimeDomainData):
+
 2012-02-17  Abhishek Arya  <inferno@chromium.org>
 
         :before content incorrectly placed in continuation
index a3f807d..54a9d1c 100644 (file)
@@ -45,8 +45,8 @@ using namespace std;
 namespace WebCore {
 
 const double RealtimeAnalyser::DefaultSmoothingTimeConstant  = 0.8;
-const double RealtimeAnalyser::DefaultMinDecibels = -100.0;
-const double RealtimeAnalyser::DefaultMaxDecibels = -30.0;
+const double RealtimeAnalyser::DefaultMinDecibels = -100;
+const double RealtimeAnalyser::DefaultMaxDecibels = -30;
 
 const unsigned RealtimeAnalyser::DefaultFFTSize = 2048;
 // All FFT implementations are expected to handle power-of-two sizes MinFFTSize <= size <= MaxFFTSize.
@@ -132,13 +132,13 @@ void applyWindow(float* p, size_t n)
     
     // Blackman window
     double alpha = 0.16;
-    double a0 = 0.5 * (1.0 - alpha);
+    double a0 = 0.5 * (1 - alpha);
     double a1 = 0.5;
     double a2 = 0.5 * alpha;
     
     for (unsigned i = 0; i < n; ++i) {
         double x = static_cast<double>(i) / static_cast<double>(n);
-        double window = a0 - a1 * cos(2.0 * piDouble * x) + a2 * cos(4.0 * piDouble * x);
+        double window = a0 - a1 * cos(2 * piDouble * x) + a2 * cos(4 * piDouble * x);
         p[i] *= float(window);
     }
 }
@@ -175,10 +175,10 @@ void RealtimeAnalyser::doFFTAnalysis()
     float* imagP = m_analysisFrame->imagData();
 
     // Blow away the packed nyquist component.
-    imagP[0] = 0.0f;
+    imagP[0] = 0;
     
     // Normalize so than an input sine wave at 0dBfs registers as 0dBfs (undo FFT scaling factor).
-    const double MagnitudeScale = 1.0 / DefaultFFTSize;
+    const double magnitudeScale = 1.0 / DefaultFFTSize;
 
     // A value of 0 does no averaging with the previous result.  Larger values produce slower, but smoother changes.
     double k = m_smoothingTimeConstant;
@@ -190,8 +190,8 @@ void RealtimeAnalyser::doFFTAnalysis()
     size_t n = magnitudeBuffer().size();
     for (size_t i = 0; i < n; ++i) {
         Complex c(realP[i], imagP[i]);
-        double scalarMagnitude = abs(c) * MagnitudeScale;        
-        destination[i] = float(k * destination[i] + (1.0 - k) * scalarMagnitude);
+        double scalarMagnitude = abs(c) * magnitudeScale;        
+        destination[i] = float(k * destination[i] + (1 - k) * scalarMagnitude);
     }
 }
 
@@ -205,7 +205,7 @@ void RealtimeAnalyser::getFloatFrequencyData(Float32Array* destinationArray)
     doFFTAnalysis();
     
     // Convert from linear magnitude to floating-point decibels.
-    const double MinDecibels = m_minDecibels;
+    const double minDecibels = m_minDecibels;
     unsigned sourceLength = magnitudeBuffer().size();
     size_t len = min(sourceLength, destinationArray->length());
     if (len > 0) {
@@ -214,7 +214,7 @@ void RealtimeAnalyser::getFloatFrequencyData(Float32Array* destinationArray)
         
         for (unsigned i = 0; i < len; ++i) {
             float linearValue = source[i];
-            double dbMag = !linearValue ? MinDecibels : AudioUtilities::linearToDecibels(linearValue);
+            double dbMag = !linearValue ? minDecibels : AudioUtilities::linearToDecibels(linearValue);
             destination[i] = float(dbMag);
         }
     }
@@ -233,21 +233,22 @@ void RealtimeAnalyser::getByteFrequencyData(Uint8Array* destinationArray)
     unsigned sourceLength = magnitudeBuffer().size();
     size_t len = min(sourceLength, destinationArray->length());
     if (len > 0) {
-        const double RangeScaleFactor = m_maxDecibels == m_minDecibels ? 1.0 : 1.0 / (m_maxDecibels - m_minDecibels);
+        const double rangeScaleFactor = m_maxDecibels == m_minDecibels ? 1 : 1 / (m_maxDecibels - m_minDecibels);
+        const double minDecibels = m_minDecibels;
 
         const float* source = magnitudeBuffer().data();
         unsigned char* destination = destinationArray->data();        
         
         for (unsigned i = 0; i < len; ++i) {
             float linearValue = source[i];
-            double dbMag = !linearValue ? m_minDecibels : AudioUtilities::linearToDecibels(linearValue);
+            double dbMag = !linearValue ? minDecibels : 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 - m_minDecibels) * RangeScaleFactor;
+            double scaledValue = UCHAR_MAX * (dbMag - minDecibels) * rangeScaleFactor;
 
             // Clip to valid range.
-            if (scaledValue < 0.0)
-                scaledValue = 0.0;
+            if (scaledValue < 0)
+                scaledValue = 0;
             if (scaledValue > UCHAR_MAX)
                 scaledValue = UCHAR_MAX;
             
@@ -280,12 +281,12 @@ void RealtimeAnalyser::getByteTimeDomainData(Uint8Array* destinationArray)
             // Buffer access is protected due to modulo operation.
             float value = inputBuffer[(i + writeIndex - fftSize + InputBufferSize) % InputBufferSize];
 
-            // Scale from nominal -1.0 -> +1.0 to unsigned byte.
-            double scaledValue = 128.0 * (value + 1.0);
+            // Scale from nominal -1 -> +1 to unsigned byte.
+            double scaledValue = 128 * (value + 1);
 
             // Clip to valid range.
-            if (scaledValue < 0.0)
-                scaledValue = 0.0;
+            if (scaledValue < 0)
+                scaledValue = 0;
             if (scaledValue > UCHAR_MAX)
                 scaledValue = UCHAR_MAX;