Compiling custom Audio Library compatible classes for Teensy 4

Status
Not open for further replies.

DerekR

Well-known member
In the thread F_CPU_ACTUAL error in Teensy 4 but not Teensy 3 the issue of being unable to compile code that included custom (home-grown) Audio Library classes for the T4 was introduced. I have spent many frustrating hours over the past few days trying to make it work, and tonight seem to have resolved the issue, although I don't fully understand the situation.

KurtE made the suggestion of including the file "core_pins.h" in the header file for each custom Audio class. So I tried it - and it worked sometimes. But the breakthrough for me was to realize that the
#include "core_pins.h" MUST appear before the
#include "AudioStream.h" in the MyAudioObject.h file that you have written.
and that now makes sense.

For example, in the simple test case (audio pass through) I wrote for the above thread

Code:
  //
  #define audio_passthru_h_
  #include "core_pins.h"
  #include "AudioStream.h"
  #include "Arduino.h"
  //
works fine, BUT
Code:
  //
  #define audio_passthru_h_
  #include "AudioStream.h"
  #include "core_pins.h"
  #include "Arduino.h"
  //
fails completely. The problem is due to the fact that "core_pins.h" contains some new #defines that are needed for AudioStream in the T4. In my initial struggles I was not paying attention to the order, causing me to rip out the two remaining hairs on my head in frustration.

Solution: Edit AudioStream.h itself to include #include "core_pins.h" in the ...\Arduino\hardware\teensy\avr\cores\teensy4 directory (you will have to do this as an administrator).
@Paul - can this be made permanent - if it's the right thing to do?
 
Last edited:
That might make it compile but I’m not sure everything will work for reasons Paul explained in your other thread.

One would have to look at each library and actually look at the use of F_CPU to understand if this would make sense or not.
 
Status
Not open for further replies.
Back
Top