Audaspace 1.5.0
A high level audio library.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
FFTConvolver Class Reference

This class allows to easily convolve a sound using the Fourier transform. More...

#include <FFTConvolver.h>

Public Member Functions

 FFTConvolver (std::shared_ptr< std::vector< std::complex< sample_t > > > ir, std::shared_ptr< FFTPlan > plan)
 Creates a new FFTConvolver.
 
void getNext (const sample_t *inBuffer, sample_t *outBuffer, int &length)
 Convolves the data that is provided with the inpulse response.
 
void getNext (const sample_t *inBuffer, sample_t *outBuffer, int &length, fftwf_complex *transformedData)
 Convolves the data that is provided with the inpulse response.
 
void getNext (const fftwf_complex *inBuffer, sample_t *outBuffer, int &length)
 Convolves the data that is provided with the inpulse response.
 
void getTail (int &length, bool &eos, sample_t *buffer)
 Gets the internally stored extra data which is result of the convolution.
 
void clear ()
 Resets the internally stored data so a new convolution can be started.
 
void IFFT_FDL (const fftwf_complex *inBuffer, sample_t *outBuffer, int &length)
 Calculates the Inverse Fast Fourier Transform of the input array.
 
void getNextFDL (const std::complex< sample_t > *inBuffer, std::complex< sample_t > *accBuffer)
 Multiplicates a frequency domain input by the impulse response and accumulates the result to a buffer.
 
void getNextFDL (const sample_t *inBuffer, std::complex< sample_t > *accBuffer, int &length, fftwf_complex *transformedData)
 Transforms an input array of real data to the frequency domain and multiplies it by the impulse response.
 
void setImpulseResponse (std::shared_ptr< std::vector< std::complex< sample_t > > > ir)
 Changes the impulse response and resets the FFTConvolver.
 
std::shared_ptr< std::vector< std::complex< sample_t > > > getImpulseResponse ()
 Retrieves the current impulse response being used.
 

Detailed Description

This class allows to easily convolve a sound using the Fourier transform.

Constructor & Destructor Documentation

◆ FFTConvolver()

FFTConvolver::FFTConvolver ( std::shared_ptr< std::vector< std::complex< sample_t > > > ir,
std::shared_ptr< FFTPlan > plan )

Creates a new FFTConvolver.

Parameters
irA shared pointer to a vector with the impulse response data in the frequency domain (see ImpulseResponse class for an easy way to obtain it).
planA shared pointer to and FFT plan.

Member Function Documentation

◆ getImpulseResponse()

std::shared_ptr< std::vector< std::complex< sample_t > > > FFTConvolver::getImpulseResponse ( )

Retrieves the current impulse response being used.

Returns
The current impulse response.

◆ getNext() [1/3]

void FFTConvolver::getNext ( const fftwf_complex * inBuffer,
sample_t * outBuffer,
int & length )

Convolves the data that is provided with the inpulse response.

Parameters
[in]inBufferA buffer with the input data to be convolved. Its length must be N/2 + 1
[in]outBufferA pointer to the buffer in which the convolution result will be written.
[in,out]lengthThe number of samples to be convolved and the length of the outBuffer. The convolution output should be larger than the input, but since this class uses the overlap add method, the extra length will be saved internally. It must be equal or lower than N/2 (N=size of the FFTPlan) or the call will fail and set the value of length to 0 since no data would be written in the outBuffer.

◆ getNext() [2/3]

void FFTConvolver::getNext ( const sample_t * inBuffer,
sample_t * outBuffer,
int & length )

Convolves the data that is provided with the inpulse response.

Parameters
[in]inBufferA buffer with the input data to be convolved.
[in]outBufferA pointer to the buffer in which the convolution result will be written.
[in,out]lengthThe number of samples to be convolved (the length of both the inBuffer and the outBuffer). The convolution output should be larger than the input, but since this class uses the overlap add method, the extra length will be saved internally. It must be equal or lower than N/2 (N=size of the FFTPlan) or the call will fail, setting this variable to 0 since no data would be written in the outBuffer.

◆ getNext() [3/3]

void FFTConvolver::getNext ( const sample_t * inBuffer,
sample_t * outBuffer,
int & length,
fftwf_complex * transformedData )

Convolves the data that is provided with the inpulse response.

Parameters
[in]inBufferA buffer with the input data to be convolved.
[in]outBufferA pointer to the buffer in which the convolution result will be written.
[in,out]lengthThe number of samples to be convolved (the length of both the inBuffer and the outBuffer). The convolution output should be larger than the input, but since this class uses the overlap add method, the extra length will be saved internally. It must be equal or lower than N/2 (N=size of the FFTPlan) or the call will fail, setting this variable to 0 since no data would be written in the outBuffer.
[in]transformedDataA pointer to a buffer in which the Fourier transform of the input will be written.

◆ getNextFDL() [1/2]

void FFTConvolver::getNextFDL ( const sample_t * inBuffer,
std::complex< sample_t > * accBuffer,
int & length,
fftwf_complex * transformedData )

Transforms an input array of real data to the frequency domain and multiplies it by the impulse response.

The result is accumulated to a buffer.

Parameters
[in]inBufferA buffer of real numbers, samples in the time domain, that will be multiplied by the impulse response.
[in]accBufferA pointer to the buffer into which the result of the multiplication will be summed. Its length must be N/2 + 1.
[in,out]lengthThe number of samples to be transformed and the length of the inBuffer. It must be equal or lower than N/2 (N=size of the FFTPlan) or the call will fail and the value of length will be setted to 0, since no data would be written in the outBuffer.
[in]transformedDataA pointer to a buffer in which the Fourier transform of the input will be written.

◆ getNextFDL() [2/2]

void FFTConvolver::getNextFDL ( const std::complex< sample_t > * inBuffer,
std::complex< sample_t > * accBuffer )

Multiplicates a frequency domain input by the impulse response and accumulates the result to a buffer.

Parameters
[in]inBufferA buffer of complex numbers, samples in the frequency domain, that will be multiplied by the impulse response. Its length must be N/2 + 1
[in]accBufferA pointer to the buffer into which the result of the multiplication will be summed. Its length must be N/2 + 1

◆ getTail()

void FFTConvolver::getTail ( int & length,
bool & eos,
sample_t * buffer )

Gets the internally stored extra data which is result of the convolution.

Parameters
[in,out]lengthThe count of samples that should be read. Shall contain the real count of samples after reading, in case there were only fewer samples available. A smaller value also indicates the end of the data.
[out]eosEnd of stream, whether the end is reached or not.
[in]bufferThe pointer to the buffer to read into.

◆ IFFT_FDL()

void FFTConvolver::IFFT_FDL ( const fftwf_complex * inBuffer,
sample_t * outBuffer,
int & length )

Calculates the Inverse Fast Fourier Transform of the input array.

Parameters
[in]inBufferA buffer with the input data to be transformed. Its length must be N/2 + 1
[in]outBufferA pointer to the buffer in which the transform result will be written.
[in,out]lengthThe number of samples to be transformed and the length of the outBuffer. It must be equal or lower than N, but tipically N/2 should be used (N=size of the FFTPlan) or the call will fail and the value of length will be setted to 0, since no data would be written in the outBuffer.

◆ setImpulseResponse()

void FFTConvolver::setImpulseResponse ( std::shared_ptr< std::vector< std::complex< sample_t > > > ir)

Changes the impulse response and resets the FFTConvolver.

Parameters
irA shared pointer to a vector with the data of the impulse response in the frequency domain.

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