VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
tklb::ConvolverRefTpl< T > Class Template Reference

Wraps up the FttConvolver to support type conversion. More...

#include <TConvolverRef.hpp>

Collaboration diagram for tklb::ConvolverRefTpl< T >:

Public Member Functions

 ConvolverRefTpl ()=default
 
template<typename T2 >
void load (const AudioBufferTpl< T2 > &ir, const Size blockSize)
 Load a impulse response and prepare the convolution. More...
 
template<typename T2 >
void process (const AudioBufferTpl< T2 > &in, AudioBufferTpl< T2 > &out)
 Do the convolution. More...
 

Static Public Member Functions

static const char * getLicense ()
 

Private Types

using Buffer = AudioBufferTpl< T >
 
using uchar = unsigned char
 
using Size = typename Buffer::Size
 

Private Attributes

fftconvolver::FFTConvolver mConvolvers [AudioBufferTpl< T >::MAX_CHANNELS]
 
AudioBufferTpl< fftconvolver::Sample > mConversion
 
Size mBlockSize
 
uchar mIrChannels = 0
 

Detailed Description

template<typename T>
class tklb::ConvolverRefTpl< T >

Wraps up the FttConvolver to support type conversion.

Definition at line 20 of file TConvolverRef.hpp.

Member Typedef Documentation

◆ Buffer

template<typename T >
using tklb::ConvolverRefTpl< T >::Buffer = AudioBufferTpl<T>
private

Definition at line 21 of file TConvolverRef.hpp.

◆ Size

template<typename T >
using tklb::ConvolverRefTpl< T >::Size = typename Buffer::Size
private

Definition at line 23 of file TConvolverRef.hpp.

◆ uchar

template<typename T >
using tklb::ConvolverRefTpl< T >::uchar = unsigned char
private

Definition at line 22 of file TConvolverRef.hpp.

Constructor & Destructor Documentation

◆ ConvolverRefTpl()

template<typename T >
tklb::ConvolverRefTpl< T >::ConvolverRefTpl ( )
default

Member Function Documentation

◆ getLicense()

template<typename T >
static const char * tklb::ConvolverRefTpl< T >::getLicense ( )
inlinestatic

Definition at line 109 of file TConvolverRef.hpp.

109 {
110 return
111 "Realtime Convolution by\n"
112 "https://github.com/HiFi-LoFi\n"
113 "https://github.com/HiFi-LoFi/FFTConvolver\n"
114 "MIT License\n\n";
115 }

◆ load()

template<typename T >
template<typename T2 >
void tklb::ConvolverRefTpl< T >::load ( const AudioBufferTpl< T2 > &  ir,
const Size  blockSize 
)
inline

Load a impulse response and prepare the convolution.

Parameters
bufferThe ir buffer.
channelWhich channel to use from the AudioBuffer
blockSizeSize of blocks ir will be divided in

Definition at line 41 of file TConvolverRef.hpp.

41 {
42 // trim silence, since longer IRs increase CPU usage considerably
43 Size irLength = ir.size();
44 if (irLength == 0) { return; }
45 const T2 silence = 0.0001;
46
47 for (Size i = irLength - 1; 0 < i; i--) {
48 for (uchar c = 0; c < ir.channels(); c++) {
49 if (silence < fabs(ir[c][i])) {
50 // if any of the channels are over the
51 // silence threshold we use the current
52 // size and bail
53 irLength = i + 1;
54 goto endLoop;
55 }
56 }
57 }
58 endLoop:
59 mIrChannels = ir.channels();
60 mBlockSize = blockSize;
61
62 if (std::is_same<T2, fftconvolver::Sample>::value) {
63 for (uchar c = 0; c < mIrChannels; c++) {
64 auto buffer = reinterpret_cast<const fftconvolver::Sample*>(ir[c]);
65 mConvolvers[c].init(blockSize, buffer, irLength);
66 }
67 } else {
68 mConversion.clone(ir);
69 for (uchar c = 0; c < mIrChannels; c++) {
70 mConvolvers[c].init(blockSize, mConversion[c], irLength);
71 }
72 }
73
74 mConversion.resize(blockSize); // in case we need to convert
75 }
typename Buffer::Size Size
fftconvolver::FFTConvolver mConvolvers[AudioBufferTpl< T >::MAX_CHANNELS]
AudioBufferTpl< fftconvolver::Sample > mConversion
float Sample
Default sample types used where ever possible, changing this means the engine needs to be recompiled,...
Definition: vae.hpp:32
Here is the call graph for this function:

◆ process()

template<typename T >
template<typename T2 >
void tklb::ConvolverRefTpl< T >::process ( const AudioBufferTpl< T2 > &  in,
AudioBufferTpl< T2 > &  out 
)
inline

Do the convolution.

Parameters
inInput signal, can be mono
outOutput buffer, needs to have enough space allocated

Definition at line 83 of file TConvolverRef.hpp.

83 {
84 const Size length = in.validSize();
85 const Size n = out.size();
86 Size samplesLeft = n;
87
88 for (Size i = 0; i < length; i += mBlockSize) {
89 const Size remaining = std::min(mBlockSize, samplesLeft);
90 for (uchar c = 0; c < out.channels(); c++) {
91 // eg the input is mono, but the IR stereo
92 // the result will still be stereo
93 const uchar inChannel = c % in.channels();
94 // TODO tklb the convolver channels can't be crossed
95 // so each output needds its own convolver
96 if (std::is_same<T2, fftconvolver::Sample>::value) {
97 auto inBuf = reinterpret_cast<const fftconvolver::Sample*>(in[inChannel] + i);
98 auto outBuf = reinterpret_cast<fftconvolver::Sample*>(out[c] + i);
99 mConvolvers[c].process(inBuf, outBuf, remaining);
100 } else {
101 // TODO tklb conversion
102 }
103
104 }
105 samplesLeft -= remaining;
106 }
107 }
T min(const T &v1, const T &v2)
Definition: TMath.hpp:16
Here is the call graph for this function:

Member Data Documentation

◆ mBlockSize

template<typename T >
Size tklb::ConvolverRefTpl< T >::mBlockSize
private

Definition at line 28 of file TConvolverRef.hpp.

◆ mConversion

template<typename T >
AudioBufferTpl<fftconvolver::Sample> tklb::ConvolverRefTpl< T >::mConversion
private

Definition at line 27 of file TConvolverRef.hpp.

◆ mConvolvers

template<typename T >
fftconvolver::FFTConvolver tklb::ConvolverRefTpl< T >::mConvolvers[AudioBufferTpl< T >::MAX_CHANNELS]
private

Definition at line 25 of file TConvolverRef.hpp.

◆ mIrChannels

template<typename T >
uchar tklb::ConvolverRefTpl< T >::mIrChannels = 0
private

Definition at line 29 of file TConvolverRef.hpp.


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