VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
tklb::Oversampler< CHANNELS, MAX_BLOCK > Class Template Reference

Super simple wrapper for the hiir up and down samplers It only goes up to 4x oversampling Its type is also bound to the Audiouffers default sample type in order to avoid including all versions of the hiir library. More...

#include <TOversampler.hpp>

Collaboration diagram for tklb::Oversampler< CHANNELS, MAX_BLOCK >:

Public Types

using T = AudioBuffer::sample
 
using uchar = unsigned char
 
using uint = unsigned int
 
using Size = AudioBuffer::Size
 
using ProcessFunction = std::function< void(T **, T **, Size)>
 

Public Member Functions

 Oversampler ()
 
void setProcessFunc (const ProcessFunction &f)
 
void setFactor (const uchar factor)
 
int getFactor () const
 
void process (AudioBuffer &in, AudioBuffer &out)
 
void process (T **in, T **out, const Size frames)
 

Static Public Member Functions

static const char * getLicense ()
 

Private Member Functions

 TKLB_OVERSAMPLER_UP (12) mUp2x[CHANNELS]
 
 TKLB_OVERSAMPLER_UP (4) mUp4x[CHANNELS]
 
 TKLB_OVERSAMPLER_DOWN (12) mDown2x[CHANNELS]
 
 TKLB_OVERSAMPLER_DOWN (4) mDown4x[CHANNELS]
 

Private Attributes

AudioBuffer mBuf2xUp
 
AudioBuffer mBuf2xDown
 
AudioBuffer mBuf4xUp
 
AudioBuffer mBuf4xDown
 
const double coeffs2x [12]
 Straight up stolen from the hiir oversampler wrapper from iPlug2 https://github.com/iPlug2/iPlug2/blob/master/IPlug/Extras/Oversampler.h. More...
 
const double coeffs4x [4]
 
uchar mFactor = 1
 
ProcessFunction mProc
 

Detailed Description

template<int CHANNELS = 2, int MAX_BLOCK = 512>
class tklb::Oversampler< CHANNELS, MAX_BLOCK >

Super simple wrapper for the hiir up and down samplers It only goes up to 4x oversampling Its type is also bound to the Audiouffers default sample type in order to avoid including all versions of the hiir library.

Definition at line 69 of file TOversampler.hpp.

Member Typedef Documentation

◆ ProcessFunction

template<int CHANNELS = 2, int MAX_BLOCK = 512>
using tklb::Oversampler< CHANNELS, MAX_BLOCK >::ProcessFunction = std::function<void(T**, T**, Size)>

Definition at line 79 of file TOversampler.hpp.

◆ Size

template<int CHANNELS = 2, int MAX_BLOCK = 512>
using tklb::Oversampler< CHANNELS, MAX_BLOCK >::Size = AudioBuffer::Size

Definition at line 75 of file TOversampler.hpp.

◆ T

template<int CHANNELS = 2, int MAX_BLOCK = 512>
using tklb::Oversampler< CHANNELS, MAX_BLOCK >::T = AudioBuffer::sample

Definition at line 71 of file TOversampler.hpp.

◆ uchar

template<int CHANNELS = 2, int MAX_BLOCK = 512>
using tklb::Oversampler< CHANNELS, MAX_BLOCK >::uchar = unsigned char

Definition at line 73 of file TOversampler.hpp.

◆ uint

template<int CHANNELS = 2, int MAX_BLOCK = 512>
using tklb::Oversampler< CHANNELS, MAX_BLOCK >::uint = unsigned int

Definition at line 74 of file TOversampler.hpp.

Constructor & Destructor Documentation

◆ Oversampler()

template<int CHANNELS = 2, int MAX_BLOCK = 512>
tklb::Oversampler< CHANNELS, MAX_BLOCK >::Oversampler ( )
inline

Definition at line 108 of file TOversampler.hpp.

108 {
109 for (uchar c = 0; c < CHANNELS; c++) {
110 mUp2x[c].set_coefs(coeffs2x);
111 mDown2x[c].set_coefs(coeffs2x);
112 mUp4x[c].set_coefs(coeffs4x);
113 mDown4x[c].set_coefs(coeffs4x);
114 }
115 mBuf2xDown.resize(MAX_BLOCK * 2, CHANNELS);
116 mBuf2xUp.resize(MAX_BLOCK * 2, CHANNELS);
117 mBuf4xDown.resize(MAX_BLOCK * 4, CHANNELS);
118 mBuf4xUp.resize(MAX_BLOCK * 4, CHANNELS);
119 }
bool resize(const Size length, uchar channels)
! Will not keep the contents! Resizes the buffer to the desired length and channel count.
AudioBuffer mBuf2xDown
const double coeffs4x[4]
AudioBuffer mBuf2xUp
AudioBuffer mBuf4xUp
AudioBuffer mBuf4xDown
unsigned char uchar
const double coeffs2x[12]
Straight up stolen from the hiir oversampler wrapper from iPlug2 https://github.com/iPlug2/iPlug2/blo...
Here is the call graph for this function:

Member Function Documentation

◆ getFactor()

template<int CHANNELS = 2, int MAX_BLOCK = 512>
int tklb::Oversampler< CHANNELS, MAX_BLOCK >::getFactor ( ) const
inline

Definition at line 129 of file TOversampler.hpp.

129 {
130 return mFactor;
131 }

◆ getLicense()

template<int CHANNELS = 2, int MAX_BLOCK = 512>
static const char * tklb::Oversampler< CHANNELS, MAX_BLOCK >::getLicense ( )
inlinestatic

Definition at line 179 of file TOversampler.hpp.

179 {
180 return
181 "HIIR Library by\n"
182 "WTFPL Licensed\n";
183 "Using iPlug2 filter coefficients.";
184 }

◆ process() [1/2]

template<int CHANNELS = 2, int MAX_BLOCK = 512>
void tklb::Oversampler< CHANNELS, MAX_BLOCK >::process ( AudioBuffer in,
AudioBuffer out 
)
inline

Definition at line 133 of file TOversampler.hpp.

133 {
134 process(in.getRaw(), out.getRaw(), in.size());
135 }
void process(AudioBuffer &in, AudioBuffer &out)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process() [2/2]

template<int CHANNELS = 2, int MAX_BLOCK = 512>
void tklb::Oversampler< CHANNELS, MAX_BLOCK >::process ( T **  in,
T **  out,
const Size  frames 
)
inline

No OverSampling at all

2x OverSampling

4x OverSampling

Definition at line 137 of file TOversampler.hpp.

137 {
138 TKLB_ASSERT(frames <= MAX_BLOCK)
139 /**
140 * No OverSampling at all
141 */
142 if (mFactor == 1) {
143 mProc(in, out, frames);
144 return;
145 }
146
147 /**
148 * 2x OverSampling
149 */
150 if (mFactor == 2 || mFactor == 3) {
151 for (uchar c = 0; c < CHANNELS; c++) {
152 mUp2x[c].process_block(mBuf2xUp[c], in[c], frames);
153 }
154
155 mProc(mBuf2xUp.getRaw(), mBuf2xDown.getRaw(), frames * 2);
156
157 for (uchar c = 0; c < CHANNELS; c++) {
158 mDown2x[c].process_block(out[c], mBuf2xDown[c], frames);
159 }
160 return;
161 }
162
163 /**
164 * 4x OverSampling
165 */
166 for (uchar c = 0; c < CHANNELS; c++) {
167 mUp2x[c].process_block(mBuf2xUp[c], in[c], frames);
168 mUp4x[c].process_block(mBuf4xUp[c], mBuf2xUp[c], frames * 2);
169 }
170
171 mProc(mBuf4xUp.getRaw(), mBuf4xDown.getRaw(), frames * 4);
172
173 for (uchar c = 0; c < CHANNELS; c++) {
174 mDown4x[c].process_block(mBuf2xDown[c], mBuf4xDown[c], frames * 2);
175 mDown2x[c].process_block(out[c], mBuf2xDown[c], frames);
176 }
177 }
#define TKLB_ASSERT(condition)
Wrap assertions.
Definition: TAssert.h:18
void getRaw(T **put)
Fills an 2d array of size maxChannels() with pointers to each channel.
ProcessFunction mProc
Here is the call graph for this function:

◆ setFactor()

template<int CHANNELS = 2, int MAX_BLOCK = 512>
void tklb::Oversampler< CHANNELS, MAX_BLOCK >::setFactor ( const uchar  factor)
inline

Definition at line 125 of file TOversampler.hpp.

125 {
126 mFactor = factor;
127 }

◆ setProcessFunc()

template<int CHANNELS = 2, int MAX_BLOCK = 512>
void tklb::Oversampler< CHANNELS, MAX_BLOCK >::setProcessFunc ( const ProcessFunction f)
inline

Definition at line 121 of file TOversampler.hpp.

121 {
122 mProc = f;
123 }

◆ TKLB_OVERSAMPLER_DOWN() [1/2]

template<int CHANNELS = 2, int MAX_BLOCK = 512>
tklb::Oversampler< CHANNELS, MAX_BLOCK >::TKLB_OVERSAMPLER_DOWN ( 12  )
private

◆ TKLB_OVERSAMPLER_DOWN() [2/2]

template<int CHANNELS = 2, int MAX_BLOCK = 512>
tklb::Oversampler< CHANNELS, MAX_BLOCK >::TKLB_OVERSAMPLER_DOWN ( )
private

◆ TKLB_OVERSAMPLER_UP() [1/2]

template<int CHANNELS = 2, int MAX_BLOCK = 512>
tklb::Oversampler< CHANNELS, MAX_BLOCK >::TKLB_OVERSAMPLER_UP ( 12  )
private

◆ TKLB_OVERSAMPLER_UP() [2/2]

template<int CHANNELS = 2, int MAX_BLOCK = 512>
tklb::Oversampler< CHANNELS, MAX_BLOCK >::TKLB_OVERSAMPLER_UP ( )
private

Member Data Documentation

◆ coeffs2x

template<int CHANNELS = 2, int MAX_BLOCK = 512>
const double tklb::Oversampler< CHANNELS, MAX_BLOCK >::coeffs2x[12]
private
Initial value:
= {
0.036681502163648017, 0.13654762463195794, 0.27463175937945444,
0.42313861743656711, 0.56109869787919531, 0.67754004997416184,
0.76974183386322703, 0.83988962484963892, 0.89226081800387902,
0.9315419599631839, 0.96209454837808417, 0.98781637073289585
}

Straight up stolen from the hiir oversampler wrapper from iPlug2 https://github.com/iPlug2/iPlug2/blob/master/IPlug/Extras/Oversampler.h.

Definition at line 93 of file TOversampler.hpp.

◆ coeffs4x

template<int CHANNELS = 2, int MAX_BLOCK = 512>
const double tklb::Oversampler< CHANNELS, MAX_BLOCK >::coeffs4x[4]
private
Initial value:
= {
0.041893991997656171, 0.16890348243995201,
0.39056077292116603, 0.74389574826847926
}

Definition at line 99 of file TOversampler.hpp.

◆ mBuf2xDown

template<int CHANNELS = 2, int MAX_BLOCK = 512>
AudioBuffer tklb::Oversampler< CHANNELS, MAX_BLOCK >::mBuf2xDown
private

Definition at line 87 of file TOversampler.hpp.

◆ mBuf2xUp

template<int CHANNELS = 2, int MAX_BLOCK = 512>
AudioBuffer tklb::Oversampler< CHANNELS, MAX_BLOCK >::mBuf2xUp
private

Definition at line 87 of file TOversampler.hpp.

◆ mBuf4xDown

template<int CHANNELS = 2, int MAX_BLOCK = 512>
AudioBuffer tklb::Oversampler< CHANNELS, MAX_BLOCK >::mBuf4xDown
private

Definition at line 87 of file TOversampler.hpp.

◆ mBuf4xUp

template<int CHANNELS = 2, int MAX_BLOCK = 512>
AudioBuffer tklb::Oversampler< CHANNELS, MAX_BLOCK >::mBuf4xUp
private

Definition at line 87 of file TOversampler.hpp.

◆ mFactor

template<int CHANNELS = 2, int MAX_BLOCK = 512>
uchar tklb::Oversampler< CHANNELS, MAX_BLOCK >::mFactor = 1
private

Definition at line 104 of file TOversampler.hpp.

◆ mProc

template<int CHANNELS = 2, int MAX_BLOCK = 512>
ProcessFunction tklb::Oversampler< CHANNELS, MAX_BLOCK >::mProc
private

Definition at line 105 of file TOversampler.hpp.


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