VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
tklb::FFTpffft Class Reference

#include <Tpffft.hpp>

Collaboration diagram for tklb::FFTpffft:

Public Member Functions

 FFTpffft (uint size=0)
 
 ~FFTpffft ()
 
void resize (uint size)
 
template<typename T >
void forward (const AudioBufferTpl< T > &input, AudioBufferTpl< T > &result)
 timedomain to frequency domain More...
 
template<typename T >
void back (const AudioBufferTpl< T > &input, AudioBufferTpl< T > &result)
 Frequency domain back to time domain. More...
 

Private Types

using uchar = unsigned char
 
using uint = unsigned int
 

Private Attributes

uint mSize
 
PFFFT_Setup * mSetup = nullptr
 
AudioBufferFloat mBuffer
 
AudioBufferFloat mRc
 

Detailed Description

Definition at line 20 of file Tpffft.hpp.

Member Typedef Documentation

◆ uchar

using tklb::FFTpffft::uchar = unsigned char
private

Definition at line 21 of file Tpffft.hpp.

◆ uint

using tklb::FFTpffft::uint = unsigned int
private

Definition at line 22 of file Tpffft.hpp.

Constructor & Destructor Documentation

◆ FFTpffft()

tklb::FFTpffft::FFTpffft ( uint  size = 0)
inline

Definition at line 30 of file Tpffft.hpp.

30 {
31 if (size == 0) { return; }
32 resize(size);
33 }
void resize(uint size)
Definition: Tpffft.hpp:40
Here is the call graph for this function:

◆ ~FFTpffft()

tklb::FFTpffft::~FFTpffft ( )
inline

Definition at line 35 of file Tpffft.hpp.

35 {
36 if (mSetup == nullptr) { return; }
37 pffft_destroy_setup(mSetup);
38 }
PFFFT_Setup * mSetup
Definition: Tpffft.hpp:25

Member Function Documentation

◆ back()

template<typename T >
void tklb::FFTpffft::back ( const AudioBufferTpl< T > &  input,
AudioBufferTpl< T > &  result 
)
inline

Frequency domain back to time domain.

Parameters
inputBuffer with 2 channels. channel 0 for real and 1 for imaginary
resultSingle channel output buffer. Needs to be twice the size of the imput buffer

Definition at line 89 of file Tpffft.hpp.

89 {
90 uint processed = 0;
91 TKLB_ASSERT(input.validSize() % mSize == 0) // Only multiples os the chunk size
92 while (processed < input.validSize()) {
93 const uint sizeHalf = mSize / 2;
94 const uint processedHalf = processed / 2;
95 mRc.set(input[0] + processedHalf, sizeHalf);
96 mRc.set(input[1] + processedHalf, sizeHalf, sizeHalf);
97 const T volume = 1.0 / double(mSize);
98 if (std::is_same<T, float>::value) {
99 float* out = reinterpret_cast<float*>(result[0]) + processed;
100 pffft_transform_ordered(mSetup, mRc[0], out, nullptr, PFFFT_BACKWARD);
101 result.multiply(volume); // scale the result
102 } else {
103 pffft_transform_ordered(mSetup, mRc[0], mBuffer[0], nullptr, PFFFT_BACKWARD);
104 const float* buf = mBuffer[0];
105 T* out = result[0] + processed;
106 for (uint i = 0; i < mSize; i++) {
107 out[i] = buf[i] * volume; // scale the result + type conversion
108 }
109 }
110 processed += mSize;
111 }
112 }
#define TKLB_ASSERT(condition)
Wrap assertions.
Definition: TAssert.h:18
void set(const T2 *samples, Size length, const uchar channel=0, const Size offsetDst=0)
Set a single channel from an array.
AudioBufferFloat mBuffer
Definition: Tpffft.hpp:26
AudioBufferFloat mRc
Definition: Tpffft.hpp:27
unsigned int uint
Definition: Tpffft.hpp:22
Here is the call graph for this function:
Here is the caller graph for this function:

◆ forward()

template<typename T >
void tklb::FFTpffft::forward ( const AudioBufferTpl< T > &  input,
AudioBufferTpl< T > &  result 
)
inline

timedomain to frequency domain

Parameters
inputInput buffer, validSize needs to be a multiple of 2
outputOutput buffer, must have 2 channel for real and imaginary. Half the length of thie input buffer

Definition at line 56 of file Tpffft.hpp.

56 {
57 uint processed = 0;
58 TKLB_ASSERT(input.validSize() % mSize == 0) // Only multiples os the chunk size
59 while (processed < input.validSize()) {
60 const float* data = nullptr;
61 if (std::is_same<T, float>::value) {
62 data = reinterpret_cast<const float*>(input[0] + processed);
63 } else {
64 mBuffer.set(input[0] + processed, mSize); // Type conversion
65 data = mBuffer[0];
66 }
67
68 pffft_transform_ordered(mSetup, data, mRc[0], nullptr, PFFFT_FORWARD);
69
70 // Split real and complex in two channels
71 const uint sizeHalf = mSize / 2;
72
73 // mRc[0][sizeHalf] = 0;
74 // result.setFromInterleaved(mRc[0], sizeHalf, 2, processed / 2);
75 result.set(mRc[0], mSize, processed);
76 // result.set(mRc[0], sizeHalf, 0, processed / 2);
77 // result.set(mRc[0] + sizeHalf, sizeHalf, 1, processed / 2);
78
79 processed += mSize;
80 }
81 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resize()

void tklb::FFTpffft::resize ( uint  size)
inline

Definition at line 40 of file Tpffft.hpp.

40 {
41 if (mSetup != nullptr) {
42 pffft_destroy_setup(mSetup);
43 }
44 mSetup = pffft_new_setup(size, PFFFT_REAL);
45 mBuffer.resize(size);
46 mRc.resize(size * 2);
47 mSize = size;
48 }
bool resize(const Size length, uchar channels)
! Will not keep the contents! Resizes the buffer to the desired length and channel count.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mBuffer

AudioBufferFloat tklb::FFTpffft::mBuffer
private

Definition at line 26 of file Tpffft.hpp.

◆ mRc

AudioBufferFloat tklb::FFTpffft::mRc
private

Definition at line 27 of file Tpffft.hpp.

◆ mSetup

PFFFT_Setup* tklb::FFTpffft::mSetup = nullptr
private

Definition at line 25 of file Tpffft.hpp.

◆ mSize

uint tklb::FFTpffft::mSize
private

Definition at line 24 of file Tpffft.hpp.


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