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

Side by Side Diff: Source/modules/webaudio/RealtimeAnalyser.cpp

Issue 156993002: Use correct FFT scaling for WebAudio AnalyserNode (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « LayoutTests/webaudio/realtimeanalyser-fft-scaling-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Do the analysis. 171 // Do the analysis.
172 m_analysisFrame->doFFT(tempP); 172 m_analysisFrame->doFFT(tempP);
173 173
174 float* realP = m_analysisFrame->realData(); 174 float* realP = m_analysisFrame->realData();
175 float* imagP = m_analysisFrame->imagData(); 175 float* imagP = m_analysisFrame->imagData();
176 176
177 // Blow away the packed nyquist component. 177 // Blow away the packed nyquist component.
178 imagP[0] = 0; 178 imagP[0] = 0;
179 179
180 // Normalize so than an input sine wave at 0dBfs registers as 0dBfs (undo FF T scaling factor). 180 // Normalize so than an input sine wave at 0dBfs registers as 0dBfs (undo FF T scaling factor).
181 const double magnitudeScale = 1.0 / DefaultFFTSize; 181 const double magnitudeScale = 1.0 / fftSize;
182 182
183 // A value of 0 does no averaging with the previous result. Larger values p roduce slower, but smoother changes. 183 // A value of 0 does no averaging with the previous result. Larger values p roduce slower, but smoother changes.
184 double k = m_smoothingTimeConstant; 184 double k = m_smoothingTimeConstant;
185 k = max(0.0, k); 185 k = max(0.0, k);
186 k = min(1.0, k); 186 k = min(1.0, k);
187 187
188 // Convert the analysis data from complex to magnitude and average with the previous result. 188 // Convert the analysis data from complex to magnitude and average with the previous result.
189 float* destination = magnitudeBuffer().data(); 189 float* destination = magnitudeBuffer().data();
190 size_t n = magnitudeBuffer().size(); 190 size_t n = magnitudeBuffer().size();
191 for (size_t i = 0; i < n; ++i) { 191 for (size_t i = 0; i < n; ++i) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 scaledValue = UCHAR_MAX; 291 scaledValue = UCHAR_MAX;
292 292
293 destination[i] = static_cast<unsigned char>(scaledValue); 293 destination[i] = static_cast<unsigned char>(scaledValue);
294 } 294 }
295 } 295 }
296 } 296 }
297 297
298 } // namespace WebCore 298 } // namespace WebCore
299 299
300 #endif // ENABLE(WEB_AUDIO) 300 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « LayoutTests/webaudio/realtimeanalyser-fft-scaling-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698