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

Side by Side Diff: Source/platform/audio/ffmpeg/FFTFrameFFMPEG.cpp

Issue 536843002: Change members's order and combine duplicated method for FFTFrame. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Separated using VectorMatch::vsmul from FFTFrameMac.cpp Created 6 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 namespace blink { 45 namespace blink {
46 46
47 #if ENABLE(ASSERT) 47 #if ENABLE(ASSERT)
48 const int kMaxFFTPow2Size = 24; 48 const int kMaxFFTPow2Size = 24;
49 #endif 49 #endif
50 50
51 // Normal constructor: allocates for a given fftSize. 51 // Normal constructor: allocates for a given fftSize.
52 FFTFrame::FFTFrame(unsigned fftSize) 52 FFTFrame::FFTFrame(unsigned fftSize)
53 : m_FFTSize(fftSize) 53 : m_FFTSize(fftSize)
54 , m_log2FFTSize(static_cast<unsigned>(log2(fftSize))) 54 , m_log2FFTSize(static_cast<unsigned>(log2(fftSize)))
55 , m_realData(fftSize / 2)
56 , m_imagData(fftSize / 2)
55 , m_forwardContext(0) 57 , m_forwardContext(0)
56 , m_inverseContext(0) 58 , m_inverseContext(0)
57 , m_complexData(fftSize) 59 , m_complexData(fftSize)
58 , m_realData(fftSize / 2)
59 , m_imagData(fftSize / 2)
60 { 60 {
61 // We only allow power of two. 61 // We only allow power of two.
62 ASSERT(1UL << m_log2FFTSize == m_FFTSize); 62 ASSERT(1UL << m_log2FFTSize == m_FFTSize);
63 63
64 m_forwardContext = contextForSize(fftSize, DFT_R2C); 64 m_forwardContext = contextForSize(fftSize, DFT_R2C);
65 m_inverseContext = contextForSize(fftSize, IDFT_C2R); 65 m_inverseContext = contextForSize(fftSize, IDFT_C2R);
66 } 66 }
67 67
68 // Creates a blank/empty frame (interpolate() must later be called). 68 // Creates a blank/empty frame (interpolate() must later be called).
69 FFTFrame::FFTFrame() 69 FFTFrame::FFTFrame()
70 : m_FFTSize(0) 70 : m_FFTSize(0)
71 , m_log2FFTSize(0) 71 , m_log2FFTSize(0)
72 , m_forwardContext(0) 72 , m_forwardContext(0)
73 , m_inverseContext(0) 73 , m_inverseContext(0)
74 { 74 {
75 } 75 }
76 76
77 // Copy constructor. 77 // Copy constructor.
78 FFTFrame::FFTFrame(const FFTFrame& frame) 78 FFTFrame::FFTFrame(const FFTFrame& frame)
79 : m_FFTSize(frame.m_FFTSize) 79 : m_FFTSize(frame.m_FFTSize)
80 , m_log2FFTSize(frame.m_log2FFTSize) 80 , m_log2FFTSize(frame.m_log2FFTSize)
81 , m_realData(frame.m_FFTSize / 2)
82 , m_imagData(frame.m_FFTSize / 2)
81 , m_forwardContext(0) 83 , m_forwardContext(0)
82 , m_inverseContext(0) 84 , m_inverseContext(0)
83 , m_complexData(frame.m_FFTSize) 85 , m_complexData(frame.m_FFTSize)
84 , m_realData(frame.m_FFTSize / 2)
85 , m_imagData(frame.m_FFTSize / 2)
86 { 86 {
87 m_forwardContext = contextForSize(m_FFTSize, DFT_R2C); 87 m_forwardContext = contextForSize(m_FFTSize, DFT_R2C);
88 m_inverseContext = contextForSize(m_FFTSize, IDFT_C2R); 88 m_inverseContext = contextForSize(m_FFTSize, IDFT_C2R);
89 89
90 // Copy/setup frame data. 90 // Copy/setup frame data.
91 unsigned nbytes = sizeof(float) * (m_FFTSize / 2); 91 unsigned nbytes = sizeof(float) * (m_FFTSize / 2);
92 memcpy(realData(), frame.realData(), nbytes); 92 memcpy(realData(), frame.realData(), nbytes);
93 memcpy(imagData(), frame.imagData(), nbytes); 93 memcpy(imagData(), frame.imagData(), nbytes);
94 } 94 }
95 95
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // Compute inverse transform. 138 // Compute inverse transform.
139 av_rdft_calc(m_inverseContext, interleavedData); 139 av_rdft_calc(m_inverseContext, interleavedData);
140 140
141 // Scale so that a forward then inverse FFT yields exactly the original data . For some reason 141 // Scale so that a forward then inverse FFT yields exactly the original data . For some reason
142 // av_rdft_calc above returns values that are half of what I expect. Hence m ake the scale factor 142 // av_rdft_calc above returns values that are half of what I expect. Hence m ake the scale factor
143 // twice as large to compensate for that. 143 // twice as large to compensate for that.
144 const float scale = 2.0 / m_FFTSize; 144 const float scale = 2.0 / m_FFTSize;
145 VectorMath::vsmul(interleavedData, 1, &scale, data, 1, m_FFTSize); 145 VectorMath::vsmul(interleavedData, 1, &scale, data, 1, m_FFTSize);
146 } 146 }
147 147
148 float* FFTFrame::realData() const
149 {
150 return const_cast<float*>(m_realData.data());
151 }
152
153 float* FFTFrame::imagData() const
154 {
155 return const_cast<float*>(m_imagData.data());
156 }
157
158 float* FFTFrame::getUpToDateComplexData() 148 float* FFTFrame::getUpToDateComplexData()
159 { 149 {
160 // FIXME: if we can't completely get rid of this method, SSE 150 // FIXME: if we can't completely get rid of this method, SSE
161 // optimization could be considered if it shows up hot on profiles. 151 // optimization could be considered if it shows up hot on profiles.
162 int len = m_FFTSize / 2; 152 int len = m_FFTSize / 2;
163 const float* real = m_realData.data(); 153 const float* real = m_realData.data();
164 const float* imag = m_imagData.data(); 154 const float* imag = m_imagData.data();
165 float* c = m_complexData.data(); 155 float* c = m_complexData.data();
166 for (int i = 0; i < len; ++i) { 156 for (int i = 0; i < len; ++i) {
167 int baseComplexIndex = 2 * i; 157 int baseComplexIndex = 2 * i;
(...skipping 14 matching lines...) Expand all
182 172
183 RDFTContext* context = av_rdft_init(pow2size, (RDFTransformType)trans); 173 RDFTContext* context = av_rdft_init(pow2size, (RDFTransformType)trans);
184 return context; 174 return context;
185 } 175 }
186 176
187 } // namespace blink 177 } // namespace blink
188 178
189 #endif // USE(WEBAUDIO_FFMPEG) 179 #endif // USE(WEBAUDIO_FFMPEG)
190 180
191 #endif // ENABLE(WEB_AUDIO) 181 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« no previous file with comments | « Source/platform/audio/android/FFTFrameOpenMAXDLAndroid.cpp ('k') | Source/platform/audio/ipp/FFTFrameIPP.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698