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

Brute force convolver using element wise multiplication. More...

#include <TConvolverBrute.hpp>

Collaboration diagram for tklb::ConvolverBruteTpl< T >:

Public Member Functions

 ConvolverBruteTpl ()=default
 
template<typename T2 >
void load (const AudioBufferTpl< T2 > &ir, const uint 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...
 

Private Types

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

Private Attributes

Buffer mIr
 

Detailed Description

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

Brute force convolver using element wise multiplication.

Super slow especially for longer impulse responses

Definition at line 15 of file TConvolverBrute.hpp.

Member Typedef Documentation

◆ Buffer

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

Definition at line 18 of file TConvolverBrute.hpp.

◆ Size

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

Definition at line 19 of file TConvolverBrute.hpp.

◆ uchar

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

Definition at line 16 of file TConvolverBrute.hpp.

◆ uint

template<typename T >
using tklb::ConvolverBruteTpl< T >::uint = unsigned int
private

Definition at line 17 of file TConvolverBrute.hpp.

Constructor & Destructor Documentation

◆ ConvolverBruteTpl()

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

Member Function Documentation

◆ load()

template<typename T >
template<typename T2 >
void tklb::ConvolverBruteTpl< T >::load ( const AudioBufferTpl< T2 > &  ir,
const uint  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 32 of file TConvolverBrute.hpp.

32 {
33 // trim silence, since longer IRs increase CPU usage considerably
34 Size irLength = ir.size();
35 if (irLength == 0) { return; }
36 const T2 silence = 0.0001;
37
38 for (Size i = irLength - 1; 0 < i; i--) {
39 for (uchar c = 0; c < ir.channels(); c++) {
40 if (silence < fabs(ir[c][i])) {
41 // if any of the channels are over the
42 // silence threshold we use the current
43 // size and bail
44 irLength = i + 1;
45 goto endLoop;
46 }
47 }
48 }
49 endLoop:
50
51 mIr.resize(irLength, ir.channels());
52 mIr.set(ir);
53 }
typename Buffer::Size Size
Here is the call graph for this function:

◆ process()

template<typename T >
template<typename T2 >
void tklb::ConvolverBruteTpl< 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 61 of file TConvolverBrute.hpp.

61 {
62 const Size nf = mIr.size();
63 const Size ng = in.validSize();
64 const Size n = out.size();
65
66 for (uchar c = 0; c < out.channels(); c++) {
67 // eg the input is mono, but the IR stereo
68 // the result will still be stereo
69 const uchar inChannel = c % in.channels();
70
71 // eg the ir is mono, it'll be used
72 // for all channels
73 const uchar irChannel = c % mIr.channels();
74 // TODO tklb check for underflows
75 for(Size i = 0; i < n; i++) {
76 const Size jmn = (i >= ng - 1) ? (i - (ng - 1)) : 0;
77 const Size jmx = (i < nf - 1) ? i : (nf - 1);
78 for(Size j = jmn; j <= jmx; j++) {
79 // nested loop goes brr
80 out[c][i] += (mIr[irChannel][j] * in[inChannel][i - j]);
81 }
82 }
83 }
84 }
Here is the call graph for this function:

Member Data Documentation

◆ mIr

template<typename T >
Buffer tklb::ConvolverBruteTpl< T >::mIr
private

Definition at line 20 of file TConvolverBrute.hpp.


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