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

#include <TOouraFFT.hpp>

Collaboration diagram for tklb::FFTOoura:

Public Member Functions

 FFTOoura (uint size=0)
 
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
 
HeapBuffer< int, 16 > mIp
 
AudioBufferDouble mW
 
AudioBufferDouble mBuffer
 

Detailed Description

Definition at line 10 of file TOouraFFT.hpp.

Member Typedef Documentation

◆ uchar

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

Definition at line 11 of file TOouraFFT.hpp.

◆ uint

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

Definition at line 12 of file TOouraFFT.hpp.

Constructor & Destructor Documentation

◆ FFTOoura()

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

Definition at line 22 of file TOouraFFT.hpp.

22 {
23 if (size == 0) { return; }
24 resize(size);
25 }
void resize(uint size)
Definition: TOouraFFT.hpp:27
Here is the call graph for this function:

Member Function Documentation

◆ back()

template<typename T >
void tklb::FFTOoura::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 88 of file TOouraFFT.hpp.

88 {
89 TKLB_ASSERT(input.validSize() % mSize == 0) // Only multiples os the chunk size
90 const T* real = input[0];
91 const T* imaginary = input[1];
92 T* out = result[0];
93 uint processed = 0;
94 while (processed < input.validSize()) {
95 {
96 // TODO tklb make this mess readable
97 double* b = mBuffer[0];
98 double* bEnd = b + mSize;
99 const uint processedHalf = processed / 2;
100 const T* r = real + processedHalf;
101 const T* i = imaginary + processedHalf;
102 while (b != bEnd) {
103 *(b++) = (*(r++));
104 *(b++) = -(*(i++));
105 }
106 mBuffer[0][1] = real[mSize / 2];
107 }
108
109 ooura::rdft(int(mSize), -1, mBuffer[0], mIp.data(), mW[0]);
110
111 const T volume = 2.0 / T(mSize);
112 if (std::is_same<T, double>::value) {
113 mBuffer.multiply(volume); // scale the output
114 mBuffer.put(reinterpret_cast<double*>(out + processed), mSize);
115 } else {
116 // or the old fashioned way if we need to convert sample types anyways
117 const double* buf = mBuffer[0];
118 for (uint i = 0; i < mSize; i++) {
119 out[i + processed] = buf[i] * volume;
120 }
121 }
122 processed += mSize;
123 }
124 }
#define TKLB_ASSERT(condition)
Wrap assertions.
Definition: TAssert.h:18
void multiply(const AudioBufferTpl< T2, STORAGE2 > &buffer, Size length=0, Size offsetSrc=0, Size offsetDst=0)
Multiply two buffers.
Size put(T2 *target, Size length=0, const uchar channel=0, const Size offset=0) const
Fill the provided array with the contents of this buffer.
HeapBuffer< int, 16 > mIp
Definition: TOouraFFT.hpp:16
unsigned int uint
Definition: TOouraFFT.hpp:12
AudioBufferDouble mW
Definition: TOouraFFT.hpp:18
AudioBufferDouble mBuffer
Definition: TOouraFFT.hpp:19
Here is the call graph for this function:

◆ forward()

template<typename T >
void tklb::FFTOoura::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

converts or copies the data we shouldn't use the original buffer since mBuffer gets written to by ooura

Definition at line 45 of file TOouraFFT.hpp.

45 {
46 TKLB_ASSERT(input.validSize() % mSize == 0) // Only multiples os the chunk size
47 uint processed = 0;
48 while (processed < input.validSize()) {
49 const uint processedHalf = processed / 2;
50 T* real = result[0] + processedHalf;
51 T* imaginary = result[1] + processedHalf;
52 const T* in = input[0] + processed;
53 /**
54 * converts or copies the data
55 * we shouldn't use the original buffer since
56 * mBuffer gets written to by ooura
57 */
58 mBuffer.set(in, mSize);
59 ooura::rdft(mSize, +1, mBuffer[0], mIp.data(), mW[0]);
60
61 // Convert back to split-complex
62 {
63 // TODO tklb make this mess readable
64 double* b = mBuffer[0];
65 double* bEnd = b + mSize;
66 T* r = real;
67 T* i = imaginary;
68 while (b != bEnd) {
69 *(r++) = (*(b++));
70 *(i++) = (-(*(b++)));
71 }
72 }
73 const size_t size2 = mSize / 2;
74 // real[size2] = -imaginary[0]; // this doens't make any sense
75 // imaginary[0] = 0.0;
76 // imaginary[size2] = 0.0; // this doesn't either
77 processed += mSize;
78 }
79
80 }
void set(const T2 *samples, Size length, const uchar channel=0, const Size offsetDst=0)
Set a single channel from an array.
Here is the call graph for this function:

◆ resize()

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

Definition at line 27 of file TOouraFFT.hpp.

27 {
28 if (size == mSize) { return; }
29 mIp.resize(2 + int(std::sqrt(double(size))));
30 mW.resize(size / 2);
31 mBuffer.resize(size);
32 mSize = size;
33
34 const int size4 = size / 4;
35 ooura::makewt(size4, mIp.data(), mW[0]);
36 ooura::makect(size4, mIp.data(), mW[0] + size4);
37 }
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

AudioBufferDouble tklb::FFTOoura::mBuffer
private

Definition at line 19 of file TOouraFFT.hpp.

◆ mIp

HeapBuffer<int, 16> tklb::FFTOoura::mIp
private

Definition at line 16 of file TOouraFFT.hpp.

◆ mSize

uint tklb::FFTOoura::mSize
private

Definition at line 14 of file TOouraFFT.hpp.

◆ mW

AudioBufferDouble tklb::FFTOoura::mW
private

Definition at line 18 of file TOouraFFT.hpp.


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