The code below crashes the Teensy 4.1 + Audio Shield. It's a sketch that attempts to play four tracks simultaneously. It works for 1 or 2 simultaneous tracks, but the third track causes NULL-pointer exception.
Using Arduino 1.8.16, Teensyduino 1.55. (Note: I tried a newer Teensyduino, I think it was 1.58, but it wouldn't compile anything that used the SdFat library, reporting that it was finding the wrong version of the SD library.)
The output on the Serial Monitor looks like this:
It never gets to the 4th track. The first three tracks are sort of playing, but badly distorted. I get a crash report:
Which, when run through addr2line reports this:
Thanks for any help.
Craig
Using Arduino 1.8.16, Teensyduino 1.55. (Note: I tried a newer Teensyduino, I think it was 1.58, but it wouldn't compile anything that used the SdFat library, reporting that it was finding the wrong version of the SD library.)
Code:
#include <Arduino.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioPlaySdWav playSdWav1; //xy=124,100
AudioPlaySdWav playSdWav2; //xy=124,160
AudioPlaySdWav playSdWav3; //xy=124,220
AudioPlaySdWav playSdWav4; //xy=124,280
AudioMixer4 mixer1; //xy=470,160
AudioMixer4 mixer2; //xy=470,280
AudioOutputI2S i2s1; //xy=650,220
AudioConnection patchCord1(playSdWav1, 0, mixer1, 0);
AudioConnection patchCord2(playSdWav1, 1, mixer2, 0);
AudioConnection patchCord3(playSdWav2, 0, mixer1, 1);
AudioConnection patchCord4(playSdWav2, 1, mixer2, 1);
AudioConnection patchCord5(playSdWav3, 0, mixer1, 2);
AudioConnection patchCord6(playSdWav3, 1, mixer2, 2);
AudioConnection patchCord7(playSdWav4, 0, mixer1, 3);
AudioConnection patchCord8(playSdWav4, 1, mixer2, 3);
AudioConnection patchCord9(mixer1, 0, i2s1, 0);
AudioConnection patchCord10(mixer2, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000; //xy=127,379.111083984375
void setup() {
// Start the SD card. These definitions are specific to the
// Teensy Audio Shield when mounted on the Teensy 4.1 computer.
#define SDCARD_MOSI_PIN 11
#define SDCARD_SCK_PIN 13
#define SDCARD_CS_PIN 10
Serial.println("Initializing SD card...");
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!SD.begin(SDCARD_CS_PIN)) {
Serial.println("SD card initialization failed!"); // always print, even of logging turned off.
while (1);
}
// Initialization for the Teensy Audio Shield
AudioMemory(8);
sgtl5000.enable();
sgtl5000.volume(1.0);
delay(1000); // wait for SGTL5000 to initialize
for (int i = 0; i < 4; i++) {
mixer1.gain(i, 1.0);
mixer2.gain(i, 1.0);
}
Serial.println("setup() done.\n");
}
void loop() {
Serial.println("play 1");
playSdWav1.play("SDTEST1.WAV");
delay(2000);
Serial.println("play 2");
playSdWav2.play("SDTEST2.WAV");
delay(2000);
Serial.println("play 3");
playSdWav3.play("SDTEST4.WAV");
delay(2000);
Serial.println("play 4");
playSdWav4.play("SDTEST4.WAV");
delay(2000);
Serial.println("stop 1");
playSdWav1.stop();
delay(2000);
Serial.println("stop 2");
playSdWav2.stop();
delay(2000);
Serial.println("stop 3");
playSdWav3.stop();
delay(2000);
Serial.println("stop 4");
playSdWav4.stop();
delay(2000);
}
The output on the Serial Monitor looks like this:
Code:
Initializing SD card...
setup() done.
play 1
play 2
play 3
It never gets to the 4th track. The first three tracks are sort of playing, but badly distorted. I get a crash report:
Code:
CrashReport:
A problem occurred at (system time) 0:0:23
Code was executing from address 0x120
CFSR: 82
(DACCVIOL) Data Access Violation
(MMARVALID) Accessed Address: 0x0 (nullptr)
Check code at 0x120 - very likely a bug!
Run "addr2line -e mysketch.ino.elf 0x120" for filename & line number.
Temperature inside the chip was 38.04 °C
Startup CPU clock speed is 600MHz
Which, when run through addr2line reports this:
Code:
$ addr2line -e /var/folders/9t/cb_zcrt138n3z64mj13z74k80000gn/T/arduino_build_939888/test_multi_track_raw.ino.elf 0x120
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio/play_sd_wav.h:37
Thanks for any help.
Craig