Audio examples do not build

MichaelMeissner

Senior Member+
Note, I built the audio examples on a Fedora 36 system using the Teensy 1.58 beta 2 release laid over the arduino 1.8.19 release.

I was answering a question on the adafruit forum about mixing sounds (where the suggestion was to buy separate audio boards to play two sounds at the same time), so I answered about the Teensy audio system. So I tried Examples -> Audio -> Tutorial -> Part_2_02_Mixers, and it looks like the file no longer has the audio includes:

Code:
Part_2_02_Mixers: In function 'void setup()':
Part_2_02_Mixers:33: error: 'AudioMemory' was not declared in this scope
   33 |   AudioMemory(8);
      |   ^~~~~~~~~~~
Part_2_02_Mixers:34: error: 'sgtl5000_1' was not declared in this scope
   34 |   sgtl5000_1.enable();
      |   ^~~~~~~~~~
Part_2_02_Mixers:36: error: 'SPI' was not declared in this scope; did you mean 'SPIF'?
   36 |   SPI.setMOSI(SDCARD_MOSI_PIN);
      |   ^~~
      |   SPIF
Part_2_02_Mixers:38: error: 'SD' was not declared in this scope; did you mean 'SS'?
   38 |   if (!(SD.begin(SDCARD_CS_PIN))) {
      |         ^~
      |         SS
Part_2_02_Mixers:45: error: 'mixer1' was not declared in this scope
   45 |   mixer1.gain(0, 0.5);
      |   ^~~~~~
Part_2_02_Mixers:47: error: 'mixer2' was not declared in this scope
   47 |   mixer2.gain(0, 0.5);
      |   ^~~~~~
Part_2_02_Mixers: In function 'void loop()':
Part_2_02_Mixers:53: error: 'playSdWav1' was not declared in this scope
   53 |   if (playSdWav1.isPlaying() == false) {
      |       ^~~~~~~~~~
Part_2_02_Mixers:58: error: 'playSdWav2' was not declared in this scope
   58 |   if (playSdWav2.isPlaying() == false) {
      |       ^~~~~~~~~~
'AudioMemory' was not declared in this scope

In going through the examples, it looks like the following also are missing the declarations:
  • Part_2_01_First_Design_Tool_use
  • Part_2_03_Samples
  • Part_2_04_Microphone_Check
  • Part_2_05_Simple_Delay
  • Part_2_06_Feedback_Delay
  • Part_2_07_Filters
  • Part_2_08_Oscillators
  • Part_3_01_Peak_Detection
  • Part_3_02_Fourier_Transform
  • Part_3_03_TFT_Display

And as I've complained about in the past, all of the examples that reference the SD card should have #ifdef's for Teensy 4.0/4.1. It would be nice if the Teensy 3.5, 3.6, and 4.1 selected the builtin-SD card by default, but at least for the Teensy 4.0/4.1 use the correct CS/SCLK/MOSI for the audio adapters. The examples I noticed are:
  • Part_1_03_Playing_Music
  • Part_1_04_Blink_While_Playing
  • Part_2_02_Mixers
  • Part_1_05_Do_More_While_Playing
  • Part_2_07_Filters
  • Part_3_01_Peak_Detection
  • Part_3_02_Fourier_Transform
  • Part_3_03_TFT_Display

For example, with Part_2_07_Filters, it has the lines:

Code:
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

// Use these with the Teensy 3.5 & 3.6 SD card
//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13

I think it should have:

Code:
// Use these with the Teensy 3.5, 3.6, and 4.1 SD card:
#if defined(PROCESSOR_TEENSY_3_5) || defined(PROCESSOR_TEENSY_3_6) || defined(PROCESSOR_TEENSY_4_1)
#define SDCARD_CS_PIN    BUILTIN_SDCARD
#define SDCARD_MOSI_PIN  11  // not actually used
#define SDCARD_SCK_PIN   13  // not actually used

// Use these with the Teensy 4.0 to use the audio adapter SD card
#elif defined(PROCESSOR_TEENSY_4_0)
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  11
#define SDCARD_SCK_PIN   13

// Use these with the Teensy 3.2
#else
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14
#endif

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13

Alternatively, you could always use the SD card on the audio adapter by default, and indicate the 3.5/3.6/4.1 in the comments:

Code:
// Use these with the Teensy 4.0/.41 to use the audio adapter SD card
#if defined(PROCESSOR_TEENSY_4_0) || defined(PROCESSOR_TEENSY_4_1)
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  11
#define SDCARD_SCK_PIN   13

// Use these with the Teensy 3.2, 3.5, or 3.6
#else
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14
#endif

// Use these with the Teensy 3.5, 3.6, and 4.1 SD card:
//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13
 
Are these the missing declarations "to be inserted by the tutor'e" after working with the Audio tool?
In going through the examples, it looks like the following also are missing the declarations:
Part_2_01_First_Design_Tool_use
Part_2_03_Samples
Part_2_04_Microphone_Check
Part_2_05_Simple_Delay
Part_2_06_Feedback_Delay
Part_2_07_Filters
Part_2_08_Oscillators
Part_3_01_Peak_Detection
Part_3_02_Fourier_Transform
Part_3_03_TFT_Display

Have popped into them trying for an example finding the stuff missing could be copied from related files?

And easy to use with T_4.x's would be handy - what about T_MM?
 
Are these the missing declarations "to be inserted by the tutor'e" after working with the Audio tool?


Have popped into them trying for an example finding the stuff missing could be copied from related files?

And easy to use with T_4.x's would be handy - what about T_MM?

IMHO, the actual examples in the examples directory should compile cleanly. Yes, you might need to change the pins if you aren't using the standard pins, but it should compile cleanly. Sure it is probably boiler plate, but it can be frustrating to recommend Teensy to newcomers if the examples don't build. And given the examples haven't been updated for the Teensy 4.x and the Teensy 3.x is likely to be missing for quite some time, it may turn people off. I imagine we want a stream of newbies to come in and start using the stuff (and of course buying more Teensies).

The T_MM is a good question. I don't have any experience with it, but since you don't have the standard 2x14 pin layout you would have to use jumper wires to connect the appropriate pins. But yeah, it should use the standard audio stuff, assuming it uses the same pin numbers, and you manually connect the missing pieces. There you might want to change the
Code:
#elif defined(TEENSY_PROCESSOR_4_0)

to

Code:
#elif defined(__IMXRT1062__)
 
T_MM would be an odd one - hand wired and using SD through standard SPI.

As far as the missing code - it was maintained as a tutorial where work is required :(
Code:
///////////////////////////////////
// copy the Design Tool code here
///////////////////////////////////

Either Audio Tool design or Copy/Paste parts from this file in the folder: ...Audio_Tutorial\Reference\Reference.ino
 
IMHO, the actual examples in the examples directory should compile cleanly.

Only the tutorial part is this way, because the written tutorial material specifically says to use the design tool and copy the results into the example code.

If those tutorial files were published as fully formed examples, then anyone following the tutorial PDF would get compile errors due to duplicate definitions when they copy the design tool stuff into them.
 
Only the tutorial part is this way, because the written tutorial material specifically says to use the design tool and copy the results into the example code.

If those tutorial files were published as fully formed examples, then anyone following the tutorial PDF would get compile errors due to duplicate definitions when they copy the design tool stuff into them.

Morning all,

Yep - used that tuturial for ref a few times. Think the other part of Michael's question was the outdated info on the audio shield pin outs for the audio shield and the fact that only the T3.5, t3.6 is mentioned, i.e.:
Code:
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

// Use these with the Teensy 3.5 & 3.6 SD card
//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13

so maybe changing that at some point to what @MichaelMeissner suggested :
Code:
// Use these with the Teensy 4.0/.41 to use the audio adapter SD card
#if defined(PROCESSOR_TEENSY_4_0) || defined(PROCESSOR_TEENSY_4_1)
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  11
#define SDCARD_SCK_PIN   13

// Use these with the Teensy 3.2, 3.5, or 3.6
#else
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14
#endif

// Use these with the Teensy 3.5, 3.6, and 4.1 SD card:
//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13
 
Back
Top