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

Side by Side Diff: Source/platform/audio/FFTFrame.cpp

Issue 176843021: Remove redundancies of multiply() in FFTFrame. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 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
« no previous file with comments | « Source/platform/audio/FFTFrame.h ('k') | Source/platform/audio/FFTFrameStub.cpp » ('j') | 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 14 matching lines...) Expand all
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "config.h" 29 #include "config.h"
30 30
31 #if ENABLE(WEB_AUDIO) 31 #if ENABLE(WEB_AUDIO)
32 32
33 #include "platform/audio/FFTFrame.h" 33 #include "platform/audio/FFTFrame.h"
34 34
35 #include "platform/audio/VectorMath.h"
36
35 #ifndef NDEBUG 37 #ifndef NDEBUG
36 #include <stdio.h> 38 #include <stdio.h>
37 #endif 39 #endif
38 40
39 #include "platform/Logging.h" 41 #include "platform/Logging.h"
40 #include "wtf/Complex.h" 42 #include "wtf/Complex.h"
41 #include "wtf/MathExtras.h" 43 #include "wtf/MathExtras.h"
42 #include "wtf/OwnPtr.h" 44 #include "wtf/OwnPtr.h"
43 45
44 namespace WebCore { 46 namespace WebCore {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 254
253 phase += i * phaseAdj; 255 phase += i * phaseAdj;
254 256
255 Complex c2 = complexFromMagnitudePhase(mag, phase); 257 Complex c2 = complexFromMagnitudePhase(mag, phase);
256 258
257 realP[i] = static_cast<float>(c2.real()); 259 realP[i] = static_cast<float>(c2.real());
258 imagP[i] = static_cast<float>(c2.imag()); 260 imagP[i] = static_cast<float>(c2.imag());
259 } 261 }
260 } 262 }
261 263
264 void FFTFrame::multiply(const FFTFrame& frame)
265 {
266 FFTFrame& frame1 = *this;
267 FFTFrame& frame2 = const_cast<FFTFrame&>(frame);
268
269 float* realP1 = frame1.realData();
270 float* imagP1 = frame1.imagData();
271 const float* realP2 = frame2.realData();
272 const float* imagP2 = frame2.imagData();
273
274 unsigned halfSize = fftSize() / 2;
275 float real0 = realP1[0];
276 float imag0 = imagP1[0];
277
278 VectorMath::zvmul(realP1, imagP1, realP2, imagP2, realP1, imagP1, halfSize);
279
280 // Multiply the packed DC/nyquist component
281 realP1[0] = real0 * realP2[0];
282 imagP1[0] = imag0 * imagP2[0];
283 }
284
262 #ifndef NDEBUG 285 #ifndef NDEBUG
263 void FFTFrame::print() 286 void FFTFrame::print()
264 { 287 {
265 FFTFrame& frame = *this; 288 FFTFrame& frame = *this;
266 float* realP = frame.realData(); 289 float* realP = frame.realData();
267 float* imagP = frame.imagData(); 290 float* imagP = frame.imagData();
268 WTF_LOG(WebAudio, "**** \n"); 291 WTF_LOG(WebAudio, "**** \n");
269 WTF_LOG(WebAudio, "DC = %f : nyquist = %f\n", realP[0], imagP[0]); 292 WTF_LOG(WebAudio, "DC = %f : nyquist = %f\n", realP[0], imagP[0]);
270 293
271 int n = m_FFTSize / 2; 294 int n = m_FFTSize / 2;
272 295
273 for (int i = 1; i < n; i++) { 296 for (int i = 1; i < n; i++) {
274 double mag = sqrt(realP[i] * realP[i] + imagP[i] * imagP[i]); 297 double mag = sqrt(realP[i] * realP[i] + imagP[i] * imagP[i]);
275 double phase = atan2(realP[i], imagP[i]); 298 double phase = atan2(realP[i], imagP[i]);
276 299
277 WTF_LOG(WebAudio, "[%d] (%f %f)\n", i, mag, phase); 300 WTF_LOG(WebAudio, "[%d] (%f %f)\n", i, mag, phase);
278 } 301 }
279 WTF_LOG(WebAudio, "****\n"); 302 WTF_LOG(WebAudio, "****\n");
280 } 303 }
281 #endif // NDEBUG 304 #endif // NDEBUG
282 305
283 } // namespace WebCore 306 } // namespace WebCore
284 307
285 #endif // ENABLE(WEB_AUDIO) 308 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/platform/audio/FFTFrame.h ('k') | Source/platform/audio/FFTFrameStub.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698