Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: C++ template based AudioMixer

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    8

    C++ template based AudioMixer

    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/template...s-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.

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,445
    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

  3. #3
    Junior Member
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    8
    ok thanks,
    I have now moved all implementations to a separate tpp file which is included at the end of the h file,
    just as you have done in FlexCAN.
    so hopefully it's now more clean code.

    new files:
    https://github.com/manicken/Audio/blob/master/mixer.cpp
    https://github.com/manicken/Audio/blob/master/mixer.h
    https://github.com/manicken/Audio/blob/master/mixer.tpp

    old files:
    https://github.com/manicken/Audio/bl.../mixer.cpp.old
    https://github.com/manicken/Audio/bl...er/mixer.h.old

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •