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

Thread: Simple WavFilePlayer not working

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    2

    Simple WavFilePlayer not working

    Hi

    I have teensy 3.5 and I'm trying to get this sample to work on my board.
    Looks like for some reason, if play method is called teensy somehow hangs. I can't print anything to serial and so on.
    I'm trying to play it on internal DAC from built-in sd card reader.
    I tried multiple computers, sd cards and teensy boards so something must be very wrong somewhere.
    I got this to work back in december 2018, and when I'm using computer which was used back then (so with older version of teensy and arduino), it still works.
    But if I try the same code somewhere else, it does not work
    Can anyone help with that/try if this is working for them?
    I might be missing something obvious here, but I tried many things before posting here.
    I'm using arduino 1.8.9
    Here is the code:
    Code:
    // Simple WAV file player example
    //
    // Three types of output may be used, by configuring the code below.
    //
    //   1: Digital I2S - Normally used with the audio shield:
    //         http://www.pjrc.com/store/teensy3_audio.html
    //
    //   2: Digital S/PDIF - Connect pin 22 to a S/PDIF transmitter
    //         https://www.oshpark.com/shared_projects/KcDBKHta
    //
    //   3: Analog DAC - Connect the DAC pin to an amplified speaker
    //         http://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog
    //
    // To configure the output type, first uncomment one of the three
    // output objects.  If not using the audio shield, comment out
    // the sgtl5000_1 lines in setup(), so it does not wait forever
    // trying to configure the SGTL5000 codec chip.
    //
    // The SD card may connect to different pins, depending on the
    // hardware you are using.  Uncomment or configure the SD card
    // pins to match your hardware.
    //
    // Data files to put on your SD card can be downloaded here:
    //   http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
    //
    // This example code is in the public domain.
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    AudioPlaySdWav           playWav1;
    // Use one of these 3 output types: Digital I2S, Digital S/PDIF, or Analog DAC
    //AudioOutputI2S           audioOutput;
    //AudioOutputSPDIF       audioOutput;
    AudioOutputAnalog      audioOutput;
    AudioConnection          patchCord1(playWav1, 0, audioOutput, 0);
    AudioConnection          patchCord2(playWav1, 1, audioOutput, 1);
    AudioControlSGTL5000     sgtl5000_1;
    
    // 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
    
    void setup() {
      Serial.begin(9600);
    
      // Audio connections require memory to work.  For more
      // detailed information, see the MemoryAndCpuUsage example
      AudioMemory(8);
    
    
      SPI.setMOSI(SDCARD_MOSI_PIN);
      SPI.setSCK(SDCARD_SCK_PIN);
      Serial.println("Hello1234");
      if (!(SD.begin(SDCARD_CS_PIN))) {
        // stop here, but print a message repetitively
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
    }
    
    void playFile(const char *filename)
    {
      Serial.print("Playing file: ");
      Serial.println(filename);
    
      // Start playing the file.  This sketch continues to
      // run while the file plays.
      playWav1.play(filename);
    
      // A brief delay for the library read WAV info
      delay(5);
    
      // Simply wait for the file to finish playing.
      while (playWav1.isPlaying()) {
      }
    }
    
    
    void loop() {
      Serial.println("test");
      playFile("ACDC.WAV");  // filenames are always uppercase 8.3 format
      delay(500);
    }

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,587
    Does it play with the 4 sample WAV files?

  3. #3
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,200
    Curious. I could not get your sketch to work on 1.8.8 with 1.47-beta2, but it works if i go back to 1.8.5/1.42 ??? Under 1.8.8, it seems to hang up the serial port, and i have to push program button to load a new sketch ???

    I also had a simple wav to 2 DACs sketch, and that sketch also hung on 1.8.8, but was ok on 1.8.5 ????

    i was using T3.6 (similar results on T3.5 and T4 beta 2)
    Last edited by manitou; 05-22-2019 at 05:11 PM.

  4. #4
    Junior Member
    Join Date
    May 2019
    Posts
    2
    Quote Originally Posted by PaulStoffregen View Post
    Does it play with the 4 sample WAV files?
    Nope
    Quote Originally Posted by manitou View Post
    Curious. I could not get your sketch to work on 1.8.8 with 1.47-beta2, but it works if i go back to 1.8.5/1.42 ??? Under 1.8.8, it seems to hang up the serial port, and i have to push program button to load a new sketch ???

    I also had a simple wav to 2 DACs sketch, and that sketch also hung on 1.8.8, but was ok on 1.8.5 ????

    i was using T3.6
    It hangs for me the same way. Sometimes I got something on serial if I print it in setup method, probably related with flushing buffers. But playWav1.play(filename); always hangs everything

  5. #5
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,200
    Using the audio lib example WavFilePlayer on T3.6 to DACs with onboard uSD, the sketch hangs on 1.8.8/1.47-beta2 and on 1.8.7/1.46. As noted, it works on 1.8.5./1.42 and works on 1.8.7/1.45. So something in the upgrade from 1.45 to 1.46 and later broke the WavFilePlayer example on T3.6. ??

    Another data point: instead of the onboard uSD, i hooked up external SD card (SPI 10-13) to T3.6, and the WavFilePlayer sketch worked with 1.8.8/1.47-beta2. So something amiss with onboard uSD driver/lib? (SD listfiles example works just fine with onboard uSD and T3.6 1.8.8/1.47-beta2)

    EDIT: another data point: i replaced the Teensy SD lib on 1.47-beta2 with the the SD lib from 1.45 and the WavFilePlayer example worked on T3.6. So something broke in extending SD lib to support T4 or use of DMA instead of polling? (@WMXZ SDHC update to SD lib in February?)

    EDIT2: on T4B2 WavFilePlayer example "works" from audio adapter uSD (SPI) (I don't have needed SMD resistor for codec, so i get noise through ear buds, but it appears WAV files are playing). If I use BUILTIN_SDCARD, i get no audio and serial monitor never says it's "playing"
    Last edited by manitou; 05-21-2019 at 05:06 PM.

  6. #6
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,344
    OK,
    I tried Cardinfo.ino with T3.6 and SD library (I was working with) it worked.
    T3.5 failed:
    Could not find FAT16/FAT32 partition.
    Make sure you've formatted the card
    Will investigate

  7. #7
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,344
    Quote Originally Posted by WMXZ View Post
    Will investigate
    First observations:

    Using CardInfo
    start of program and first sector with T3.5 reads
    Code:
    Initializing SD card...Wiring is correct and a card is present.
    
    Card type: SDHC
    
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    a8 98 8b 9e d9 88 88 88 9d fd fc cc 88 88 88 8a
    8b 88 8c fe ff ff 88 a8 88 88 88 d8 b8 8b 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88
    88 88 88 88 88 88 88 88 88 88 88 88 88 88 dd aa
    
    Could not find FAT16/FAT32 partition.
    Make sure you've formatted the card
    it should read (as with T3.6)
    Code:
    Initializing SD card...Wiring is correct and a card is present.
    
    Card type: SDHC
    
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    20 18 03 16 51 00 00 00 9d 7d 74 c4 00 00 00 82
    03 00 0c fe ff ff 00 20 00 00 00 d8 b8 03 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa

    Same card both T3.6 and T3.5 without pins
    Could it be a HW or NXP problem? (seems 4th bit of SDHC is always high)

    Note, this test is done not with latest ARDUINO / TD version, but the one I used to port SD to T4

  8. #8
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,200
    With 1.8.8/1.47-beta2 (BUILTIN_SDCARD), cardinfo works for me on T3.5, T3.6, T4B2 with both kingston and SanDisk uSD. The SD file io seems to be working for me, except for the WavFilePlayer -- some funky interaction between audio lib and SD lib -- dueling DMAs?
    Last edited by manitou; 05-21-2019 at 07:28 PM.

  9. #9
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,344
    Quote Originally Posted by manitou View Post
    dueling DMAs?
    SDHC has it own DMA (which according to Bill Greiman is not working ?)
    The original (non T4) version is also using internal DMA,
    continue to look into

  10. #10
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,344
    Quote Originally Posted by WMXZ View Post
    continue to look into
    the '8' seen in the T3.5 data where indeed the 4th bit, and it was indeed HW, but a contact issue of the sd card holder and not the T3.x board or the processor.
    (It was a fresh T3.5 never used since Kickstarter, sic!)
    So Cardinfo worked with both T3.5 and 3.6. (1.8.8/1.47-beta1)

  11. #11
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,200
    Quote Originally Posted by WMXZ View Post
    continue to look into
    Were you able to confirm hang with WavFilePlayer for BUILTIN_SDCARD?

  12. #12
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,200
    maybe this recent post fixes the problem ? https://forum.pjrc.com/threads/56355...ignment-issues
    Further testing required ...

Posting Permissions

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