Audacity  2.2.0
FFT.cpp File Reference

Fast Fourier Transform routines. More...

#include "Audacity.h"
#include "FFT.h"
#include "MemoryX.h"
#include "SampleFormat.h"
#include <wx/intl.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "RealFFTf.h"
#include "Experimental.h"

Functions

static void InitFFT ()
 
static bool IsPowerOfTwo (size_t x)
 
static size_t NumberOfBitsNeeded (size_t PowerOfTwo)
 
int ReverseBits (size_t index, size_t NumBits)
 
void DeinitFFT ()
 
static size_t FastReverseBits (size_t i, size_t NumBits)
 
void FFT (size_t NumSamples, bool InverseTransform, const float *RealIn, const float *ImagIn, float *RealOut, float *ImagOut)
 
void RealFFT (size_t NumSamples, const float *RealIn, float *RealOut, float *ImagOut)
 
void InverseRealFFT (size_t NumSamples, const float *RealIn, const float *ImagIn, float *RealOut)
 
void PowerSpectrum (size_t NumSamples, const float *In, float *Out)
 
int NumWindowFuncs ()
 
const wxChar * WindowFuncName (int whichFunction)
 
void NewWindowFunc (int whichFunction, size_t NumSamples, bool extraSample, float *in)
 
void WindowFunc (int whichFunction, size_t NumSamples, float *in)
 
void DerivativeOfWindowFunc (int whichFunction, size_t NumSamples, bool extraSample, float *in)
 

Variables

static ArraysOf< int > gFFTBitTable
 
static const size_t MaxFastBits = 16
 

Detailed Description

Fast Fourier Transform routines.

This file contains a few FFT routines, including a real-FFT routine that is almost twice as fast as a normal complex FFT, and a power spectrum routine when you know you don't care about phase information.

Some of this code was based on a free implementation of an FFT by Don Cross, available on the web at:

http://www.intersrv.com/~dcross/fft.html

The basic algorithm for his code was based on Numerican Recipes in Fortran. I optimized his code further by reducing array accesses, caching the bit reversal table, and eliminating float-to-double conversions, and I added the routines to calculate a real FFT and a real power spectrum.

Function Documentation

void DeinitFFT ( )

Referenced by AudacityApp::OnExit().

void DerivativeOfWindowFunc ( int  whichFunction,
size_t  NumSamples,
bool  extraSample,
float *  in 
)
static size_t FastReverseBits ( size_t  i,
size_t  NumBits 
)
inlinestatic

References MaxFastBits, and ReverseBits().

Referenced by FFT().

void FFT ( size_t  NumSamples,
bool  InverseTransform,
const float *  RealIn,
const float *  ImagIn,
float *  RealOut,
float *  ImagOut 
)
void InitFFT ( )
static

References MaxFastBits, ArraysOf< X >::reinit(), and ReverseBits().

Referenced by FFT().

void InverseRealFFT ( size_t  NumSamples,
const float *  RealIn,
const float *  ImagIn,
float *  RealOut 
)
static bool IsPowerOfTwo ( size_t  x)
static

Referenced by FFT().

void NewWindowFunc ( int  whichFunction,
size_t  NumSamples,
bool  extraSample,
float *  in 
)
static size_t NumberOfBitsNeeded ( size_t  PowerOfTwo)
static

Referenced by FFT().

void PowerSpectrum ( size_t  NumSamples,
const float *  In,
float *  Out 
)

References GetFFT(), and RealFFTf().

Referenced by SpectrumAnalyst::Calculate(), and ComputeSpectrum().

void RealFFT ( size_t  NumSamples,
const float *  RealIn,
float *  RealOut,
float *  ImagOut 
)
int ReverseBits ( size_t  index,
size_t  NumBits 
)

Referenced by FastReverseBits(), and InitFFT().

void WindowFunc ( int  whichFunction,
size_t  NumSamples,
float *  in 
)

Variable Documentation

ArraysOf<int> gFFTBitTable
static
const size_t MaxFastBits = 16
static

Referenced by FastReverseBits(), and InitFFT().