C++ template based AudioMixer

manicksan

Well-known member
Hi Paul,
I did some changes to the AudioMixer so that is uses C++ template,
so that it can be instanced with:

AudioMixer<N> mixer; // N defines the number of inputs.

To make the code easier to maintain
I removed the AudioMixer4 class and replaced it with:
#define AudioMixer4 AudioMixer<4>

also all code is removed in Mixer.cpp and moved to
Mixer.h because templates don't work that way (compiler limitations), as described at:
https://isocpp.org/wiki/faq/templates#templates-defn-vs-decl

also to share the function applyGain between AudioMixer<N> and AudioAmplifier.

the changed files are at
https://github.com/manicken/Audio/blob/master/mixer.h
https://github.com/manicken/Audio/blob/master/mixer.cpp

I hope that they can be merged to the official branch so that we don't need to make special classes for every number of inputs that is needed.
 
templates work under .tpp with compiler, you may check out the sources in FlexCAN_T4 (which has compile time and runtime object creation(user object and ISR forwarding)) and even WDT_T4. The template data must be appended to all declared functions in the tpp file, I shortened the lengths by declaring definitions in the H file to make the TPP file easier to manage
 
Back
Top