Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: Source/WebCore/webaudio/RealtimeAnalyser.cpp

Issue 7793016: Merge 94002 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/835/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebCore/webaudio/RealtimeAnalyser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/webaudio/RealtimeAnalyser.cpp
===================================================================
--- Source/WebCore/webaudio/RealtimeAnalyser.cpp (revision 94028)
+++ Source/WebCore/webaudio/RealtimeAnalyser.cpp (working copy)
@@ -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);
« no previous file with comments | « Source/WebCore/webaudio/RealtimeAnalyser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698