SuperpoweredSDK  v2.0.2
Superpowered Audio SDK
Superpowered::FrequencyDomain Class Reference

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

#include "SuperpoweredFrequencyDomain.h"

Collaboration diagram for Superpowered::FrequencyDomain:

Public Member Functions

 FrequencyDomain (unsigned int fftLogSize=11, unsigned int maxOverlap=4)
 Constructor. More...
 
 ~FrequencyDomain ()
 
void addInput (float *input, int numberOfFrames)
 Add some audio input. More...
 
void addInput (AudiopointerlistElement *input)
 Add some audio input (advanced use). More...
 
void advance (int numberOfFrames=0)
 Advances the input buffer (removes the earliest frames). More...
 
void frequencyDomainToTimeDomain (float *magnitudeL, float *magnitudeR, float *phaseL, float *phaseR, float *output, float valueOfPi=0, int incrementFrames=0, bool complexMode=false, int stereoPairIndex=0)
 Converts frequency domain data to audio output. More...
 
unsigned int getNumberOfInputFramesNeeded ()
 
void reset ()
 Reset all internals, sets the instance as good as new. More...
 
void setStereoPairs (unsigned int numStereoPairs)
 This class can handle one stereo audio channel pair by default (left+right). More...
 
bool timeDomainToFrequencyDomain (float *magnitudeL, float *magnitudeR, float *phaseL, float *phaseR, float valueOfPi=0, bool complexMode=false, int stereoPairIndex=0)
 Converts the audio input (added by addInput()) to the frequency domain. More...
 
bool timeDomainToFrequencyDomainMono (float *magnitude, float *phase, float valueOfPi=0, bool complexMode=false)
 Converts mono audio input (added by addInput()) to the frequency domain. More...
 

Public Attributes

Superpowered::AudiopointerListinputList
 For advanced uses: access to the internal audio input pointer list. More...
 

Private Member Functions

 FrequencyDomain (const FrequencyDomain &)
 
FrequencyDomainoperator= (const FrequencyDomain &)
 

Private Attributes

frequencyDomainInternals * internals
 

Detailed Description

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

One instance allocates around 131 kb. How to use:

  1. Audio input using addInput().
  2. Call timeDomainToFrequencyDomain(), if it returns false go back to 1.
  3. The output of timeDomainToFrequencyDomain is frequency domain data you can work with.
  4. Call advance() (if required).
  5. Call frequencyDomainToTimeDomain() to create time domain audio from frequency domain data.

Constructor & Destructor Documentation

◆ FrequencyDomain() [1/2]

Superpowered::FrequencyDomain::FrequencyDomain ( unsigned int  fftLogSize = 11,
unsigned int  maxOverlap = 4 
)

Constructor.

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.
maxOverlap[Maximum overlap]:1 (default: 4:1).

◆ ~FrequencyDomain()

Superpowered::FrequencyDomain::~FrequencyDomain ( )

◆ FrequencyDomain() [2/2]

Superpowered::FrequencyDomain::FrequencyDomain ( const FrequencyDomain )
private

Member Function Documentation

◆ addInput() [1/2]

void Superpowered::FrequencyDomain::addInput ( float *  input,
int  numberOfFrames 
)

Add some audio input.

Parameters
inputPointer to floating point numbers. 32-bit interleaved stereo input.
numberOfFramesThe number of input frames.

◆ addInput() [2/2]

void Superpowered::FrequencyDomain::addInput ( AudiopointerlistElement input)

Add some audio input (advanced use).

Parameters
inputThe input buffer.

◆ advance()

void Superpowered::FrequencyDomain::advance ( int  numberOfFrames = 0)

Advances the input buffer (removes the earliest frames).

Parameters
numberOfFramesFor advanced use, if you know how window overlapping works. Use 0 (the default value) otherwise for a 4:1 overlap (good compromise in audio quality).

◆ frequencyDomainToTimeDomain()

void Superpowered::FrequencyDomain::frequencyDomainToTimeDomain ( float *  magnitudeL,
float *  magnitudeR,
float *  phaseL,
float *  phaseR,
float *  output,
float  valueOfPi = 0,
int  incrementFrames = 0,
bool  complexMode = false,
int  stereoPairIndex = 0 
)

Converts frequency domain data to audio output.

Parameters
magnitudeLPointer to floating point numbers. Magnitudes for each frequency bin, left side. Must be at least [FFT SIZE] big.
magnitudeRPointer to floating point numbers. Magnitudes for each frequency bin, right side. Must be at least [FFT SIZE] big.
phaseLPointer to floating point numbers. Phases for each frequency bin, left side. Must be at least [FFT SIZE] big.
phaseRPointer to floating point numbers. Phases for each frequency bin, right side. Must be at least [FFT SIZE] big.
outputPointer to floating point numbers. 32-bit interleaved stereo output.
valueOfPiPi can be translated to any value (Google: the tau manifesto). Leave it at 0 for M_PI.
incrementFramesFor advanced use, if you know how window overlapping works. Use 0 (the default value) otherwise for a 4:1 overlap (good compromise in audio quality).
complexModeIf true, then the magnitude and phase inputs represent complex numbers (magnitude: real, phase: imag).
stereoPairIndexThe index of the stereo pair to process.

◆ getNumberOfInputFramesNeeded()

unsigned int Superpowered::FrequencyDomain::getNumberOfInputFramesNeeded ( )
Returns
Returns with how many frames of input should be provided to produce some output.

◆ operator=()

FrequencyDomain& Superpowered::FrequencyDomain::operator= ( const FrequencyDomain )
private

◆ reset()

void Superpowered::FrequencyDomain::reset ( )

Reset all internals, sets the instance as good as new.

◆ setStereoPairs()

void Superpowered::FrequencyDomain::setStereoPairs ( unsigned int  numStereoPairs)

This class can handle one stereo audio channel pair by default (left+right).

You can extend it to handle more.

Parameters
numStereoPairsThe number of stereo audio channel pairs. Valid values: one (stereo) to four (8 channels).

◆ timeDomainToFrequencyDomain()

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

Converts the audio input (added by addInput()) to the frequency domain.

Each frequency bin is (samplerate / [FFT SIZE] / 2) wide.

Returns
True, if a conversion was possible (enough frames were available).
Parameters
magnitudeLPointer to floating point numbers. Magnitudes for each frequency bin, left side. Must be at least [FFT SIZE] big.
magnitudeRPointer to floating point numbers. Magnitudes for each frequency bin, right side. Must be at least [FFT SIZE] big.
phaseLPointer to floating point numbers. Phases for each frequency bin, left side. Must be at least [FFT SIZE] big.
phaseRPointer to floating point numbers. Phases for each frequency bin, right side. Must be at least [FFT SIZE] big.
valueOfPiPi can be translated to any value (Google: the tau manifesto). Keep it at 0 for M_PI.
complexModeIf true, then it returns with complex numbers (magnitude: real, phase: imag). Performs polar transform otherwise (the output is magnitudes and phases).
stereoPairIndexThe index of the stereo pair to process.

◆ timeDomainToFrequencyDomainMono()

bool Superpowered::FrequencyDomain::timeDomainToFrequencyDomainMono ( float *  magnitude,
float *  phase,
float  valueOfPi = 0,
bool  complexMode = false 
)

Converts mono audio input (added by addInput()) to the frequency domain.

Each frequency bin is (samplerate / [FFT SIZE] / 2) wide.

Returns
True, if a conversion was possible (enough frames were available).
Parameters
magnitudePointer to floating point numbers. Magnitudes for each frequency bin. Must be at least [FFT SIZE] big.
phasePointer to floating point numbers. Phases for each frequency bin. Must be at least [FFT SIZE] big.
valueOfPiPi can be translated to any value (Google: the tau manifesto). Keep it at 0 for M_PI.
complexModeIf true, then it returns with complex numbers (magnitude: real, phase: imag). Performs polar transform otherwise (the output is magnitudes and phases).

Member Data Documentation

◆ inputList

Superpowered::AudiopointerList* Superpowered::FrequencyDomain::inputList

For advanced uses: access to the internal audio input pointer list.

◆ internals

frequencyDomainInternals* Superpowered::FrequencyDomain::internals
private

The documentation for this class was generated from the following file: