Superpowered SDKs  1.4.0
Pain-free Audio, Cryptographics and Networking Development for Android, iOS, macOS, tvOS, Linux and Windows
Public Member Functions | Public Attributes | List of all members
SuperpoweredFrequencyDomain Class Reference

Transforms between time-domain and frequency-domain audio, including buffering, windowing (HanningZ) and window overlap handling (default: 4:1). More...

Public Member Functions

 SuperpoweredFrequencyDomain (int fftLogSize=11, int maxOverlap=4)
 Creates an instance. More...
 
void setStereoPairs (unsigned int numStereoPairs)
 This class handles one stereo audio channel pair by default. You can extend it to handle more. More...
 
void addInput (float *input, int numberOfSamples)
 Add some audio input. Use it only if you created the instance with pool = 0. More...
 
void addInput (SuperpoweredAudiobufferlistElement *input)
 Add some audio input (advanced use). Use it only if you created the instance with an existing buffer pool. More...
 
bool timeDomainToFrequencyDomain (float *magnitudeL, float *magnitudeR, float *phaseL, float *phaseR, float valueOfPi=0, bool complexMode=false, int stereoPairIndex=0)
 Converts the audio inputs to frequency domain. More...
 
bool timeDomainToFrequencyDomain (float *magnitude, float *phase, float valueOfPi=0, bool complexMode=false)
 Converts the mono audio input to frequency domain. More...
 
void advance (int numberOfSamples=0)
 
void frequencyDomainToTimeDomain (float *magnitudeL, float *magnitudeR, float *phaseL, float *phaseR, float *output, float valueOfPi=0, int incrementSamples=0, bool complexMode=false, int stereoPairIndex=0)
 Converts frequency domain data to audio output. More...
 
void reset ()
 Reset all internals, sets the instance as good as new.
 

Public Attributes

int fftSize
 
int numberOfInputSamplesNeeded
 
SuperpoweredAudiopointerListinputList
 

Detailed Description

One instance allocates around 131 kb. How to use:

Parameters
fftSizeFFT size.
numberOfInputSamplesNeededHow many samples required to some frequency domain output. Read only.
inputListFor advanced uses: access to the internal audio input pointer list.

Constructor & Destructor Documentation

◆ SuperpoweredFrequencyDomain()

SuperpoweredFrequencyDomain::SuperpoweredFrequencyDomain ( int  fftLogSize = 11,
int  maxOverlap = 4 
)
Parameters
fftLogSizeFFT log size, between 8 and 13 (FFT 256 - 8192). The default value (11) provides a good compromise in precision (~22 Hz per bin), CPU load and time-domain event sensitivity.
maxOverlapMaximum overlap:1 (default: 4:1).

Member Function Documentation

◆ setStereoPairs()

void SuperpoweredFrequencyDomain::setStereoPairs ( unsigned int  numStereoPairs)
Parameters
numStereoPairsThe number of stereo audio channel pairs.

◆ addInput() [1/2]

void SuperpoweredFrequencyDomain::addInput ( float *  input,
int  numberOfSamples 
)
Parameters
input32-bit floating point stereo input.
numberOfSamplesThe number of input samples.

◆ addInput() [2/2]

void SuperpoweredFrequencyDomain::addInput ( SuperpoweredAudiobufferlistElement input)
Parameters
inputThe input buffer.

◆ timeDomainToFrequencyDomain() [1/2]

bool SuperpoweredFrequencyDomain::timeDomainToFrequencyDomain ( float *  magnitudeL,
float *  magnitudeR,
float *  phaseL,
float *  phaseR,
float  valueOfPi = 0,
bool  complexMode = false,
int  stereoPairIndex = 0 
)

Each frequency bin is (samplerate / fftSize / 2) wide.

Returns
True, if a conversion was possible (enough samples were available).
Parameters
magnitudeLMagnitudes for each frequency bin, left side. Must be at least fftSize big.
magnitudeRMagnitudes for each frequency bin, right side. Must be at least fftSize big.
phaseLPhases for each frequency bin, left side. Must be at least fftSize big.
phaseRPhases for each frequency bin, right side. Must be at least fftSize big.
valueOfPiPi can be translated to any value (Google: the tau manifesto). Leave it at 0 for M_PI.
complexModeInstead of polar transform, returns complex values (magnitude: real, phase: imag).
stereoPairIndexThe index of the stereo pair to process.

◆ timeDomainToFrequencyDomain() [2/2]

bool SuperpoweredFrequencyDomain::timeDomainToFrequencyDomain ( float *  magnitude,
float *  phase,
float  valueOfPi = 0,
bool  complexMode = false 
)

Each frequency bin is (samplerate / fftSize / 2) wide.

Returns
True, if a conversion was possible (enough samples were available).
Parameters
magnitudeMagnitudes for each frequency bin. Must be at least fftSize big.
phasePhases for each frequency bin. Must be at least fftSize big.
valueOfPiPi can be translated to any value (Google: the tau manifesto). Leave it at 0 for M_PI.
complexModeInstead of polar transform, returns complex values (magnitude: real, phase: imag).

◆ frequencyDomainToTimeDomain()

void SuperpoweredFrequencyDomain::frequencyDomainToTimeDomain ( float *  magnitudeL,
float *  magnitudeR,
float *  phaseL,
float *  phaseR,
float *  output,
float  valueOfPi = 0,
int  incrementSamples = 0,
bool  complexMode = false,
int  stereoPairIndex = 0 
)
Parameters
magnitudeLMagnitudes for each frequency bin, left side. Must be at least fftSize big.
magnitudeRMagnitudes for each frequency bin, right side. Must be at least fftSize big.
phaseLPhases for each frequency bin, left side. Must be at least fftSize big.
phaseRPhases for each frequency bin, right side. Must be at least fftSize big.
outputOutput goes here.
valueOfPiPi can be translated to any value (Google: the tau manifesto). Leave it at 0 for M_PI.
incrementSamplesFor advanced use, if you know how window overlapping works. 0 (the default value) means 4:1 overlap (good compromise in audio quality).
complexModeInstead of polar transform, returns complex values (magnitude: real, phase: imag).
stereoPairIndexThe index of the stereo pair to process.