Audacity 3.2.0
Classes | Typedefs | Functions
RealFFTf.h File Reference
#include "MemoryX.h"
Include dependency graph for RealFFTf.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  FFTParam
 
struct  FFTDeleter
 

Typedefs

using fft_type = float
 
using HFFT = std::unique_ptr< FFTParam, FFTDeleter >
 

Functions

MATH_API HFFT GetFFT (size_t)
 
MATH_API void RealFFTf (fft_type *, const FFTParam *)
 
MATH_API void InverseRealFFTf (fft_type *, const FFTParam *)
 
MATH_API void ReorderToTime (const FFTParam *hFFT, const fft_type *buffer, fft_type *TimeOut)
 
MATH_API void ReorderToFreq (const FFTParam *hFFT, const fft_type *buffer, fft_type *RealOut, fft_type *ImagOut)
 

Typedef Documentation

◆ fft_type

using fft_type = float

Definition at line 6 of file RealFFTf.h.

◆ HFFT

using HFFT = std::unique_ptr< FFTParam, FFTDeleter >

Definition at line 20 of file RealFFTf.h.

Function Documentation

◆ GetFFT()

MATH_API HFFT GetFFT ( size_t  fftlen)

Definition at line 105 of file RealFFTf.cpp.

106{
107 // To do: smarter policy about when to retain in the pool and when to
108 // allocate a unique instance.
109
110 wxCriticalSectionLocker locker{ getFFTMutex };
111
112 size_t h = 0;
113 auto n = fftlen/2;
114 auto size = hFFTArray.size();
115 for(;
116 (h < size) && hFFTArray[h] && (n != hFFTArray[h]->Points);
117 h++)
118 ;
119 if(h < size) {
120 if(hFFTArray[h] == NULL) {
121 hFFTArray[h].reset( InitializeFFT(fftlen).release() );
122 }
123 return HFFT{ hFFTArray[h].get() };
124 } else {
125 // All buffers used, so fall back to allocating a NEW set of tables
126 return InitializeFFT(fftlen);
127 }
128}
static std::vector< std::unique_ptr< FFTParam > > hFFTArray(MAX_HFFT)
HFFT InitializeFFT(size_t fftlen)
Definition: RealFFTf.cpp:56
wxCriticalSection getFFTMutex
Definition: RealFFTf.cpp:101
std::unique_ptr< FFTParam, FFTDeleter > HFFT
Definition: RealFFTf.h:22

References getFFTMutex, hFFTArray(), InitializeFFT(), and size.

Referenced by SpectrogramSettings::CacheWindows(), EffectNoiseRemoval::Initialize(), InverseRealFFT(), PowerSpectrum(), and RealFFT().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InverseRealFFTf()

MATH_API void InverseRealFFTf ( fft_type buffer,
const FFTParam h 
)

Definition at line 264 of file RealFFTf.cpp.

265{
266 fft_type *A,*B;
267 const fft_type *sptr;
268 const fft_type *endptr1,*endptr2;
269 const int *br1;
270 fft_type HRplus,HRminus,HIplus,HIminus;
271 fft_type v1,v2,sin,cos;
272
273 auto ButterfliesPerGroup = h->Points / 2;
274
275 /* Massage input to get the input for a real output sequence. */
276 A = buffer + 2;
277 B = buffer + h->Points * 2 - 2;
278 br1 = h->BitReversed.get() + 1;
279 while(A<B)
280 {
281 sin=h->SinTable[*br1];
282 cos=h->SinTable[*br1+1];
283 HRplus = (HRminus = *A - *B ) + (*B * 2);
284 HIplus = (HIminus = *(A+1) - *(B+1)) + (*(B+1) * 2);
285 v1 = (sin*HRminus + cos*HIplus);
286 v2 = (cos*HRminus - sin*HIplus);
287 *A = (HRplus + v1) * (fft_type)0.5;
288 *B = *A - v1;
289 *(A+1) = (HIminus - v2) * (fft_type)0.5;
290 *(B+1) = *(A+1) - HIminus;
291
292 A+=2;
293 B-=2;
294 br1++;
295 }
296 /* Handle center bin (just need conjugate) */
297 *(A+1)=-*(A+1);
298 /* Handle DC bin separately - this ignores any Fs/2 component
299 buffer[1]=buffer[0]=buffer[0]/2;*/
300 /* Handle DC and Fs/2 bins specially */
301 /* The DC bin is passed in as the real part of the DC complex value */
302 /* The Fs/2 bin is passed in as the imaginary part of the DC complex value */
303 /* (v1+v2) = buffer[0] == the DC component */
304 /* (v1-v2) = buffer[1] == the Fs/2 component */
305 v1=0.5f*(buffer[0]+buffer[1]);
306 v2=0.5f*(buffer[0]-buffer[1]);
307 buffer[0]=v1;
308 buffer[1]=v2;
309
310 /*
311 * Butterfly:
312 * Ain-----Aout
313 * \ /
314 * / \
315 * Bin-----Bout
316 */
317
318 endptr1 = buffer + h->Points * 2;
319
320 while(ButterfliesPerGroup > 0)
321 {
322 A = buffer;
323 B = buffer + ButterfliesPerGroup * 2;
324 sptr = h->SinTable.get();
325
326 while(A < endptr1)
327 {
328 sin = *(sptr++);
329 cos = *(sptr++);
330 endptr2 = B;
331 while(A < endptr2)
332 {
333 v1 = *B * cos - *(B + 1) * sin;
334 v2 = *B * sin + *(B + 1) * cos;
335 *B = (*A + v1) * (fft_type)0.5;
336 *(A++) = *(B++) - v1;
337 *B = (*A + v2) * (fft_type)0.5;
338 *(A++) = *(B++) - v2;
339 }
340 A = B;
341 B += ButterfliesPerGroup * 2;
342 }
343 ButterfliesPerGroup >>= 1;
344 }
345}
float fft_type
Definition: RealFFTf48x.h:6
#define A(N)
Definition: ToChars.cpp:62
size_t Points
Definition: RealFFTf.h:10
ArrayOf< int > BitReversed
Definition: RealFFTf.h:8
ArrayOf< fft_type > SinTable
Definition: RealFFTf.h:9

References A, FFTParam::BitReversed, FFTParam::Points, and FFTParam::SinTable.

Referenced by EffectEqualization::Filter(), InverseRealFFT(), SpectrumTransformer::OutputStep(), and EffectNoiseRemoval::RemoveNoise().

Here is the caller graph for this function:

◆ RealFFTf()

MATH_API void RealFFTf ( fft_type buffer,
const FFTParam h 
)

Definition at line 162 of file RealFFTf.cpp.

163{
164 fft_type *A,*B;
165 const fft_type *sptr;
166 const fft_type *endptr1,*endptr2;
167 const int *br1,*br2;
168 fft_type HRplus,HRminus,HIplus,HIminus;
169 fft_type v1,v2,sin,cos;
170
171 auto ButterfliesPerGroup = h->Points/2;
172
173 /*
174 * Butterfly:
175 * Ain-----Aout
176 * \ /
177 * / \
178 * Bin-----Bout
179 */
180
181 endptr1 = buffer + h->Points * 2;
182
183 while(ButterfliesPerGroup > 0)
184 {
185 A = buffer;
186 B = buffer + ButterfliesPerGroup * 2;
187 sptr = h->SinTable.get();
188
189 while(A < endptr1)
190 {
191 sin = *sptr;
192 cos = *(sptr+1);
193 endptr2 = B;
194 while(A < endptr2)
195 {
196 v1 = *B * cos + *(B + 1) * sin;
197 v2 = *B * sin - *(B + 1) * cos;
198 *B = (*A + v1);
199 *(A++) = *(B++) - 2 * v1;
200 *B = (*A - v2);
201 *(A++) = *(B++) + 2 * v2;
202 }
203 A = B;
204 B += ButterfliesPerGroup * 2;
205 sptr += 2;
206 }
207 ButterfliesPerGroup >>= 1;
208 }
209 /* Massage output to get the output for a real input sequence. */
210 br1 = h->BitReversed.get() + 1;
211 br2 = h->BitReversed.get() + h->Points - 1;
212
213 while(br1<br2)
214 {
215 sin=h->SinTable[*br1];
216 cos=h->SinTable[*br1+1];
217 A=buffer+*br1;
218 B=buffer+*br2;
219 HRplus = (HRminus = *A - *B ) + (*B * 2);
220 HIplus = (HIminus = *(A+1) - *(B+1)) + (*(B+1) * 2);
221 v1 = (sin*HRminus - cos*HIplus);
222 v2 = (cos*HRminus + sin*HIplus);
223 *A = (HRplus + v1) * (fft_type)0.5;
224 *B = *A - v1;
225 *(A+1) = (HIminus + v2) * (fft_type)0.5;
226 *(B+1) = *(A+1) - HIminus;
227
228 br1++;
229 br2--;
230 }
231 /* Handle the center bin (just need a conjugate) */
232 A=buffer+*br1+1;
233 *A=-*A;
234 /* Handle DC bin separately - and ignore the Fs/2 bin
235 buffer[0]+=buffer[1];
236 buffer[1]=(fft_type)0;*/
237 /* Handle DC and Fs/2 bins separately */
238 /* Put the Fs/2 value into the imaginary part of the DC bin */
239 v1=buffer[0]-buffer[1];
240 buffer[0]+=buffer[1];
241 buffer[1]=v1;
242}

References A, FFTParam::BitReversed, FFTParam::Points, and FFTParam::SinTable.

Referenced by SpecCache::CalculateOneSpectrum(), anonymous_namespace{SpectrumCache.cpp}::ComputeSpectrumUsingRealFFTf(), EffectNoiseRemoval::FillFirstHistoryWindow(), SpectrumTransformer::FillFirstWindow(), EffectEqualization::Filter(), PowerSpectrum(), and RealFFT().

Here is the caller graph for this function:

◆ ReorderToFreq()

MATH_API void ReorderToFreq ( const FFTParam hFFT,
const fft_type buffer,
fft_type RealOut,
fft_type ImagOut 
)

Definition at line 347 of file RealFFTf.cpp.

349{
350 // Copy the data into the real and imaginary outputs
351 for(size_t i = 1; i < hFFT->Points; i++) {
352 RealOut[i] = buffer[hFFT->BitReversed[i] ];
353 ImagOut[i] = buffer[hFFT->BitReversed[i]+1];
354 }
355 RealOut[0] = buffer[0]; // DC component
356 ImagOut[0] = 0;
357 RealOut[hFFT->Points] = buffer[1]; // Fs/2 component
358 ImagOut[hFFT->Points] = 0;
359}

References FFTParam::BitReversed, and FFTParam::Points.

◆ ReorderToTime()

MATH_API void ReorderToTime ( const FFTParam hFFT,
const fft_type buffer,
fft_type TimeOut 
)

Definition at line 361 of file RealFFTf.cpp.

362{
363 // Copy the data into the real outputs
364 for(size_t i = 0; i < hFFT->Points; i++) {
365 TimeOut[i*2 ]=buffer[hFFT->BitReversed[i] ];
366 TimeOut[i*2+1]=buffer[hFFT->BitReversed[i]+1];
367 }
368}

References FFTParam::BitReversed, and FFTParam::Points.

Referenced by EffectEqualization::Filter(), and InverseRealFFT().

Here is the caller graph for this function: