Title: [94029] branches/chromium/835/Source/WebCore/webaudio
Revision
94029
Author
[email protected]
Date
2011-08-29 16:35:40 -0700 (Mon, 29 Aug 2011)

Log Message

Merge 94002
BUG=93978
Review URL: http://codereview.chromium.org/7793016

Modified Paths

Diff

Modified: branches/chromium/835/Source/WebCore/webaudio/RealtimeAnalyser.cpp (94028 => 94029)


--- branches/chromium/835/Source/WebCore/webaudio/RealtimeAnalyser.cpp	2011-08-29 23:21:22 UTC (rev 94028)
+++ branches/chromium/835/Source/WebCore/webaudio/RealtimeAnalyser.cpp	2011-08-29 23:35:40 UTC (rev 94029)
@@ -49,6 +49,8 @@
 const double RealtimeAnalyser::DefaultMaxDecibels = -30.0;
 
 const unsigned RealtimeAnalyser::DefaultFFTSize = 2048;
+// All FFT implementations are expected to handle power-of-two sizes MinFFTSize <= size <= MaxFFTSize.
+const unsigned RealtimeAnalyser::MinFFTSize = 128;
 const unsigned RealtimeAnalyser::MaxFFTSize = 2048;
 const unsigned RealtimeAnalyser::InputBufferSize = RealtimeAnalyser::MaxFFTSize * 2;
 
@@ -82,15 +84,16 @@
     // Only allow powers of two.
     unsigned log2size = static_cast<unsigned>(log2(size));
     bool isPOT(1UL << log2size == size);
-    
-    if (!isPOT || size > MaxFFTSize) {
+
+    if (!isPOT || size > MaxFFTSize || size < MinFFTSize) {
         // FIXME: It would be good to also set an exception.
         return;
     }
 
     if (m_fftSize != size) {
-        m_analysisFrame = adoptPtr(new FFTFrame(m_fftSize));
-        m_magnitudeBuffer.allocate(size);
+        m_analysisFrame = adoptPtr(new FFTFrame(size));
+        // m_magnitudeBuffer has size = fftSize / 2 because it contains floats reduced from complex values in m_analysisFrame.
+        m_magnitudeBuffer.allocate(size / 2);
         m_fftSize = size;
     }
 }
@@ -165,8 +168,6 @@
     // Do the analysis.
     m_analysisFrame->doFFT(tempP);
 
-    size_t n = DefaultFFTSize / 2;
-
     float* realP = m_analysisFrame->realData();
     float* imagP = m_analysisFrame->imagData();
 
@@ -183,7 +184,8 @@
     
     // Convert the analysis data from complex to magnitude and average with the previous result.
     float* destination = magnitudeBuffer().data();
-    for (unsigned i = 0; i < n; ++i) {
+    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);

Modified: branches/chromium/835/Source/WebCore/webaudio/RealtimeAnalyser.h (94028 => 94029)


--- branches/chromium/835/Source/WebCore/webaudio/RealtimeAnalyser.h	2011-08-29 23:21:22 UTC (rev 94028)
+++ branches/chromium/835/Source/WebCore/webaudio/RealtimeAnalyser.h	2011-08-29 23:35:40 UTC (rev 94029)
@@ -70,6 +70,7 @@
     static const double DefaultMaxDecibels;
 
     static const unsigned DefaultFFTSize;
+    static const unsigned MinFFTSize;
     static const unsigned MaxFFTSize;
     static const unsigned InputBufferSize;
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to