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

Thread: Audio Play Sd Wav, Sd_t3 issues

  1. #1
    Senior Member
    Join Date
    Dec 2014
    Posts
    306

    Audio Play Sd Wav, Sd_t3 issues

    Hi all,

    I've been banging my head against a wall on and off for weeks on this one.
    I have some Teensy 3.2's playing sound with the AudioPlaySdWav objects; two of them, fed into a mixer, fed to a DAC, using the normal SD card library. Shimples.

    Except, occasionally, at random intervals (could be minutes, could be days), they just... stop playing.
    I've done some fairly in-depth debugging to try and get some information as to what's going on.

    It seems that the AudioPlaySdWav objects simply stop accepting new tracks to play. I came to this conclusion by putting together a code block along the lines of:

    Code:
    elapsedMillis playStartCheckTimer = 0;
    if(!soundChannel0.play(trackString.c_str()) {
    Serial.println("Failed to play track!");
    return;
    }
    while(playStartCheckTimer < 100 && !soundChannel0.isPlaying());
    if(!soundChannel0.isPlaying()) {
    Serial.println("Audio play attempt timed out!");
    }
    Normally, the AudioPlaySdWav object will start playing within 11-15ms for the particular cards I'm using, yet, when it begins to fail, it will time-out every single time from that point onwards. The channels do not seem to be independent - ie, when one fails, they both fail. Resetting the teensy appears to solve the issue (without removing power from the SD card).

    To try and remedy this upon detection of the error, I've made a few futile attempts including:
    - Re-initialising SD card with SD.begin(PIN_SD_CS);
    - Calling AudioPlaySdWav.begin()

    I've checked I'm not using too much memory (AudioMemory(10) being allocated by max of 3 being used).
    I was originally doing this on Teensyduino 1.32 on Arduino 1.6.5 however, I've since updated to 1.40 on 1.8.5, with no better results.

    I came across this issue report, with the exact same problem as my own (https://github.com/PaulStoffregen/Audio/issues/172) so I've attempted to move to using sd_t3.h. I've done this through changing from #include <SD.h> to #include <SD_t3.h>, and uncommenting the USE_TEENSY3_OPTIMIZED_CODE in SD_t3.h. However, when doing so, I can't seem to get sound to play at all. SD.begin seems to fail. The following sketch should reproduce, provided you have a similar hardware setup to mine of course.

    Code:
    #include <Audio.h>
    #include <SPI.h>
    #include <SD_t3.h>
    #include <SerialFlash.h>
    
    #define PIN_MOSI    11
    #define PIN_MISO    12
    #define PIN_SCK     13
    #define PIN_SD_CS   15
    #define PIN_AUD_L_EN  20
    #define PIN_AUD_R_EN  21
    #define PIN_DAC     A14
    
    
    AudioPlaySdWav    soundChannel0;
    AudioPlaySdWav    soundChannel1;
    AudioOutputAnalog soundOutput;
    AudioMixer4     soundMixer;
    AudioConnection   soundC1(soundChannel0, 0, soundMixer, 0);
    AudioConnection   soundC2(soundMixer, soundOutput);
    AudioConnection   soundC3(soundChannel1, 0, soundMixer, 1);
    
    elapsedMillis playStartCheckTimer = 0;
    elapsedMillis timer = 0;
    
    void setup() {
      // put your setup code here, to run once:
      SD.begin(PIN_SD_CS);
      pinMode(PIN_AUD_L_EN, OUTPUT);
      pinMode(PIN_AUD_R_EN, OUTPUT); 
      digitalWrite(PIN_AUD_L_EN, true);
      digitalWrite(PIN_AUD_R_EN, true);
      
      AudioMemory(10);
      soundOutput.analogReference(EXTERNAL);
      soundMixer.gain(0, 0.3);
      soundMixer.gain(1, 0.3);
    }
    
    void loop() {
      if(timer >= 50) {
        timer = 0;
        Serial.println("Playing track: SOUND032.WAV on channel 0");
        playStartCheckTimer = 0;
        if (!soundChannel0.play("SOUND032.WAV")) {
          Serial.println("Failed to play track 32 on channel 0");
        } else {
          while (playStartCheckTimer < 100 && !soundChannel0.isPlaying()); 
          if (soundChannel0.isPlaying()) {
            Serial.println("Playing... Delay: " + String(playStartCheckTimer));
          }
          else {
            Serial.println("PLAY TIMED OUT.");
          }
        }
    
        Serial.println("Playing track: SOUND057.WAV on channel 0");
        playStartCheckTimer = 0;
        if (!soundChannel1.play("SOUND057.WAV")) {
          Serial.println("Failed to play track 57 on channel 0");
        } else {
          while (playStartCheckTimer < 100 && !soundChannel1.isPlaying()); 
          if (soundChannel1.isPlaying()) {
            Serial.println("Playing... Delay: " + String(playStartCheckTimer));
          }
          else {
            Serial.println("PLAY TIMED OUT.");
          }
        }
      }
    }
    If you run this code with the normal SD.h libraries, or with SD_t3.h but without USE_TEENSY3_OPTIMISED_CODE uncommented, when the issue playing sound occurs, you'll see something like this in the serial monitor:
    Code:
    Playing track: SOUND057.WAV on channel 1
    Playing... Delay: 15
    Playing track: SOUND032.WAV on channel 0
    Playing... Delay: 11
    Playing track: SOUND057.WAV on channel 1
    Playing... Delay: 15
    Playing track: SOUND032.WAV on channel 0
    Playing... Delay: 14
    Playing track: SOUND057.WAV on channel 1
    Playing... Delay: 14
    Playing track: SOUND032.WAV on channel 0
    PLAY TIMED OUT.
    Playing track: SOUND057.WAV on channel 1
    PLAY TIMED OUT.
    Playing track: SOUND032.WAV on channel 0
    PLAY TIMED OUT.
    Playing track: SOUND057.WAV on channel 1
    PLAY TIMED OUT.
    Playing track: SOUND032.WAV on channel 0
    PLAY TIMED OUT.
    Playing track: SOUND057.WAV on channel 1
    Note that it doesn't fail to play the track (and hence show "Failed to play track xx") but rather, it believes it has succeeded, but doesn't actually play.

    Thanks in advance,
    Iestyn.
    Last edited by Cosford; 02-12-2018 at 09:56 PM.

  2. #2
    Senior Member
    Join Date
    Dec 2014
    Posts
    306
    Any ideas on this one anyone?

    Is there a way of re-initialising all of the Audio library objects perhaps? Current workaround is just to soft reset the teensy, but it's a far from ideal solution.

Posting Permissions

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