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

Thread: Can not get PropShield to Play MP3's with MP3Player

  1. #1
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102

    Can not get PropShield to Play MP3's with MP3Player

    I new to the audio world and just trying out different examples using a propshield and a T3.5. I am using 1.38Beta1 teensyduino by the way. For a speaker I am using a old 0.25watt 8ohm one.

    I am sure the wiring is ok because if I run examples from the Talkie Library and TTS library there is no problem with the sound. At that point figured I wanted to give playing some music from SerialFlash so I used teensytransfer to transfer the mp3 to serialflash. Verified by listing the files and do some prints from the MP3Play.ino (File size) so I know its seeing it. The sketch says its playing the file but no sound. I did try changing audiomemory to 20 instead of 8 but still nothing.

    One quick question, dac1 is the equivalent of dac0?

    Thanks in advance.

    For reference here is the sketch:
    Code:
    // Simple MP3 file player example
    //
    // https://forum.pjrc.com/threads/27059-MP3-Player-Lib-with-example?p=101537&viewfull=1#post101537
    //
    // Requires the prop-shield and Teensy 3.2 or 3.1
    // This example code is in the public domain.
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <play_sd_mp3.h> // https://github.com/FrankBoesing/Arduino-Teensy-Codec-lib
    //#include <play_sd_aac.h>
    
    
    // GUItool: begin automatically generated code
    //AudioPlaySdWav           playSdWav1;     //xy=154,422
    AudioPlaySdMp3           playMp31; //xy=154,422
    AudioMixer4              mixer1;         //xy=327,432
    AudioOutputAnalog        dac1;           //xy=502,412
    AudioConnection          patchCord1(playMp31, 0, mixer1, 0);
    AudioConnection          patchCord2(playMp31, 1, mixer1, 1);
    AudioConnection          patchCord3(mixer1, dac1);
    // GUItool: end automatically generated code
    
    
    #define PROP_AMP_ENABLE    5
    #define FLASH_CHIP_SELECT  6
    //#define FLASH_CHIP_SELECT 21  // Arduino 101 built-in SPI Flash
    
    void setup() {
      Serial.begin(9600);
      AudioMemory(8); //4
      delay(2000);
    
      // Start SerialFlash
      if (!SerialFlash.begin(FLASH_CHIP_SELECT)) {
        while (1) {
          Serial.println ("Cannot access SPI Flash chip");
          delay (1000);
        }
      }
    
      //Set Volume
      mixer1.gain(0, 0.5);
      mixer1.gain(1, 0.5);
    
      //Start Amplifier
      pinMode(PROP_AMP_ENABLE, OUTPUT);
      digitalWrite(PROP_AMP_ENABLE, HIGH);    // Enable Amplifier
    }
    
    void playFile(const char *filename)
    {
      SerialFlashFile ff = SerialFlash.open(filename);
      Serial.print("Playing file: ");
      Serial.println(filename);
    
      uint32_t sz = ff.size();
      uint32_t pos = ff.getFlashAddress();
    
      // Start playing the file.  This sketch continues to
      // run while the file plays.
      playMp31.play(pos,sz);
    
      // Simply wait for the file to finish playing.
      while (playMp31.isPlaying()) {
        yield();
      }
    }
    
    
    void loop() {
      playFile("zarathustra.mp3");
      delay(1000);
    }

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,530
    dac1 is the second DAC of the Teensy 3.6. Try to replace it by dac0 (default).

  3. #3
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    Tried replacing dac1 with dac0 but did not work. Also trying playing a .wav but that did not work either. Almost like the amplifier is turned on but the code is there to turn it on.

  4. #4
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,196
    You are using AudioPlaySdWav, i don't think there is an AudioPlaySerialflashWav. try playing .RAW files.

    here is sketch i use to play .RAW files with the teensy DAC pin jumpered to prop shield audioIN and speaker on shield's + -

    Code:
    // prop shield audio from raw
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    AudioPlaySerialflashRaw playRaw1;
    AudioOutputAnalog  audioOutput;
    AudioConnection          patchCord1(playRaw1, audioOutput);
    
    #define PROP_AMP_ENABLE   5
    #define FLASH_CHIP_SELECT           6
    
    void setup() {
      Serial.begin(9600);
    
      // wait up to 3 seconds for the Serial device to become available
      long unsigned debug_start = millis ();
      while (!Serial && ((millis () - debug_start) <= 3000))
        ;
    
      Serial.println ("Start prop shield wav player");
    
      // Enable the amplifier on the prop shield
      pinMode(PROP_AMP_ENABLE, OUTPUT);
      digitalWrite(PROP_AMP_ENABLE, HIGH);
    
      // Audio connections require memory to work.  For more
      // detailed information, see the MemoryAndCpuUsage example
      AudioMemory(8);
    
      // Start SerialFlash
      if (!SerialFlash.begin(FLASH_CHIP_SELECT)) {
        while (1)
        {
          Serial.println ("Cannot access SPI Flash chip");
          delay (1000);
        }
      }
    }
    
    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.
      playRaw1.play(filename);
    
      // A brief delay for the library read WAV info
      delay(5);
    
      // Simply wait for the file to finish playing.
      while (playRaw1.isPlaying()) {
        // uncomment these lines if you audio shield
        // has the optional volume pot soldered
        //float vol = analogRead(15);
        //vol = vol / 1024;
        // sgtl5000_1.volume(vol);
      }
    }
    
    
    void loop() {
      playFile("TOPGUN.RAW");  // filenames are always uppercase 8.3 format
    
      delay(1500);
    }
    Last edited by manitou; 06-21-2017 at 10:27 PM.

  5. #5
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    Hi Manitou, is there a mp3 to raw converter? thanks.

    I tried editing the mp3 code to use the same type header that you use in you raw file:
    Code:
    AudioPlaySdMp3            playMp31; //xy=154,422
    AudioOutputAnalog         audioOutput;
    AudioConnection           patchCord1(playMp31, audioOutput);
    Still did not work. That's why the question on converter.

  6. #6
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,196
    Quote Originally Posted by mjs513 View Post
    Hi Manitou, is there a mp3 to raw converter? thanks.
    google or other forum members may be able to suggest tools based on what OS you are using. I've converted .WAV to .RAW on linux.
    audacity is a tool that can do various conversions and it runs on various OS's

    read the posts around https://forum.pjrc.com/threads/33328...l=1#post101152

    EDIT: another variation. in the audio lib examples, edit the WavFilePlayer example. uncomment
    AudioOutputAnalog audioOutput;
    and comment out the other audioOutput line, and comment out all the stuff dealing with codec sgtl5000_1.
    Now assuming you have some .WAV files on the SD card on the T3.5, change the sketch to use
    #define SDCARD_CS_PIN BUILTIN_SDCARD

    and jumper DAC0 to the propshield audioIN and set pin 5 HIGH to enable propshield amp/speaker, and run the sketch ...
    it should play the .WAV files
    Last edited by manitou; 06-21-2017 at 11:39 PM.

  7. #7
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    Manitou. thanks for pointing me to that reference. I started going through that thread but didn't get that far. I used one of his raw files as a test case with your sketch since I don't have the TOPGUN.RAW file. It worked fine.

    I then used audacity to convert to raw format (had to check google on that, its in other compressed, but have to select the right 16-bit format). I got it playing but sounds very speeded up, like a chimpmunk. I had to use either 8-bit or 16-bit PCM format

    Other formats just played noise.

    I did find this thread https://forum.pjrc.com/threads/40599...wav2trw-sketch that helped since I started with trying to convert using FrankB's wav2trw.exe.

    Now I guess I have to start digging a little deeper. Not sure why the mp3 example would not work out of the box.

    Thanks for your help and getting me on right track.

    Mike
    Last edited by mjs513; 06-22-2017 at 12:38 AM.

  8. #8
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    Ok. Gave modifying the wavePlayer a try and same thing - ran but nothing played: Here is the sketch. Its getting late so I might have missed something:

    Code:
    #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
    AudioOutputAnalog      audioOutput;
    AudioConnection          patchCord1(playWav1, 0, audioOutput, 0);
    AudioConnection          patchCord2(playWav1, 1, audioOutput, 1);
    
    // 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
    
    
    #define PROP_AMP_ENABLE    5
    #define FLASH_CHIP_SELECT  6
    //#define FLASH_CHIP_SELECT 21  // Arduino 101 built-in SPI Flash
    
    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);
      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);
        }
      }
      
      //Start Amplifier
      pinMode(PROP_AMP_ENABLE, OUTPUT);
      digitalWrite(PROP_AMP_ENABLE, HIGH);    // Enable Amplifier
    
    }
    
    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() {
      playFile("ODD.WAV");  // filenames are always uppercase 8.3 format
      delay(1500);
    
    }
    Also modified same code to use serialflash but same thing. Ran but nothing. Here is my wav file if you want to give it a try.
    Attached Files Attached Files

  9. #9
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,196
    With a scope on T3.5 DAC0(A21), your sketch above works for me with Paul's SDTEST1.WAV. Can you try it with a known good WAV file from
    https://www.pjrc.com/teensy/td_libs_AudioDataFiles.html

    your odd.wav was RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 22050 Hz
    it needs to be 44khz.
    SDTEST1.WAV: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz

    EDIT: hooked DAC0 to propshield, Paul's WAV files play ok through 8ohm speaker
    Last edited by manitou; 06-22-2017 at 10:53 AM.

  10. #10
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    Good morning Manitou. Downloaded the sdstest1.wav file and I also converted the odd.wav to stereo and 44100hz. Modified the sketch to play both files from the SD card. It worked but no volume. Had to put the speaker next to my ear to hear it. I did change the audiomemory to 20 but no change. I am using a .25w 8ohm speaker if that matters.

    By the way I guess the mp3 format would be the same, 44K, 16bit stereo. Where is it that defines what format the files have to be in?

    Thanks for checking on this for me.

  11. #11
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    Ok. I went back and converted the mp3 file to stereo and 44Khz and saved it to flash. Reran the MP3Player and changed dac1 to dac0 and it now works. Volume level is low but can easily hear it unlike the wav files. I can get it louder by adding the analogreference(EXTERNAL).

    So what this is boiling down to is best to have the sound files formatted to stereo with a 44khz sample rate. I am going to try later a mono version using only one channel and one mixer and see it that works for mono files.

    Looking at some of posts it appeared that mono at 22khz should work as well? Confused, but have to do more playing.

  12. #12
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    I started putting together the test sketches that I used with some of my notes. Still a work in progress. Was wondering if you could take a look and let me know if I said anything that I shouldn't have. Still need to add references to some of the sketches to give folks credit and clean up.

    Thanks
    Mike

    EDIT: Oops. Forgot the link. https://github.com/mjs513/PRJC-PropS...ctice-Sketches
    Last edited by mjs513; 06-26-2017 at 10:36 PM.

  13. #13
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102

    Reading wav and mp3 files from SD card not working

    I know I am probably doing something wrong but I just can't figure it out. I am writing a sketch to play all music files from the sd card on a teensy 3.5 with the prop shield and its just does't want to play the wav files (I am using the test wav sketch). I can get the files to play if I just play mp3's or wav's using a separate sketch for each by specifying their filenames. What I am trying to do here is read the directory and then play the file. I have tried several variations but to no avail. I would appreciate any help you can offer.

    Thanks in advance.

    Code:
    // AAC + MP3 file player example
    //
    // Requires the prop-shield
    // This example code is in the public domain.
    
    #include <string.h>
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <play_sd_mp3.h>
    
    // GUItool: begin automatically generated code
    AudioPlaySdMp3           playMp3; //xy=154,422
    AudioPlaySdWav           playWav; //xy=154,422
    AudioMixer4              mixer1;         //xy=323,326
    AudioOutputAnalog        dac1;           //xy=445,393
    AudioConnection          patchCord1(playMp3, 0, mixer1, 0);
    AudioConnection          patchCord2(playMp3, 1, mixer1, 1);
    AudioConnection          patchCord3(playWav, 0, mixer1, 2);
    AudioConnection          patchCord4(playWav, 1, mixer1, 3);
    AudioConnection          patchCord5(mixer1, dac1);
    
    
    #define PROP_AMP_ENABLE    5
    #define FLASH_CHIP_SELECT  6
    
    float volume = 0.5f;
    File root, entry;
    
    void setup() {
      
      AudioMemory(40);
      dac1.analogReference(EXTERNAL);  //plays really loud, may get hissing
                                  //if your speakers can't handle it.
    
      delay(2000); 
    
      if (!(SD.begin(BUILTIN_SDCARD))) {
        // stop here, but print a message repetitively
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
    
      Serial.println("initialization done.");
      root = SD.open("/");
    
      //Start Amplifier
      pinMode(PROP_AMP_ENABLE , OUTPUT);
      digitalWrite(PROP_AMP_ENABLE , HIGH);
    
    }
    
    void playFile(const char *filename)
    {
      int filetype;
    
      filetype = 0;
      if (strstr(filename, ".MP3") != NULL) {
          filetype = 1;
      } else if (strstr(filename, ".WAV") != NULL ) {
          filetype = 2;
      } else
        filetype = 0;
    
      if (filetype > 0) {
        Serial.print("Playing file: ");
        Serial.println(filename);
        
        switch (filetype) {
          case 1 :
            mixer1.gain(0, volume);
            mixer1.gain(1, volume);
            mixer1.gain(2, 0.0f);
            mixer1.gain(3, 0.0f);
            playMp3.play(filename);
            while (playMp3.isPlaying()) {
            }
            break;
          case 2 :
            mixer1.gain(0, 0.0f);
            mixer1.gain(1, 0.0f);
            mixer1.gain(2, volume);
            mixer1.gain(3, volume);
            if(SD.exists(filename)) Serial.println("I exist!");
            playWav.play(filename);
            while (playWav.isPlaying()) {
              Serial.println(playWav.isPlaying());
            }
            break;
        }
      }
    }
    
    
    void loop() {
    
      char filename[64];
      int numTabs = 0;
      
       while(true) {
        //if (!playMp3.isPlaying() && !playWav.isPlaying()) {
         entry =  root.openNextFile();
         if (! entry) {
           // no more files
           Serial.println("**nomorefiles**");
           break;
         }
         for (uint8_t i=0; i<numTabs; i++) {
           Serial.print('\t');
         }
         Serial.print(entry.name());
         if (entry.isDirectory()) {
           Serial.println("Directory/");
         } else {
           // files have sizes, directories do not
           Serial.print("\t\t");
           Serial.println(entry.size(), DEC);
           // files have sizes, directories do not
           strcpy(filename, entry.name());
           playFile(filename);
         }
       //}
       entry.close();
     }
    }

  14. #14
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,196
    try adding a delay(5); after playWav.play() and playMp3.play() and before the the while(play...)
    (also comment out Serial.println(playWav.isPlaying()); in the while or it will flood the monitor )

    although it still goes crazy printing nomorefiles after one pass through loop, might need to close root and re-open
    (I only tested with .WAV, commented out mp3 stuff)
    Last edited by manitou; 06-27-2017 at 12:32 AM.

  15. #15
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    Just added the delays and it worked like a charm. This was my initial pass. The serial prints was part of my debugging . Now to clean it up, get it to loop properly and like you said will need to close root and re-open and do sub-directories. By the way , when I tried SD.close() it gave me an error and said I could only do that on files. If I can impose on you for one more question, how do you do that.

    Thanks for all your help. I am actually learning how to do this

  16. #16
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,196
    root.close();
    root = SD.open("/");

  17. #17
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    Didn't think about that. Getting denser and denser in my old age

  18. #18
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,196
    Quote Originally Posted by manitou View Post
    root.close();
    root = SD.open("/");
    root.rewindDirectory() should work too

  19. #19
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    Used the root.rewindDirectory() and as you said it did work. Loops fine.

  20. #20
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    Hi @manitou

    Finished the sketch. Got looping and playing any music in directories you have on the sd card. Thought I would share since you got me through this. Haven't teste the aac or raw files yet.

    Thanks. Mike

    Code:
    // Requires the prop-shield
    // This example code is in the public domain.
    
    #include <string.h>
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <play_sd_mp3.h>
    #include <play_sd_aac.h>
    
    // GUItool: begin automatically generated code
    AudioPlaySdMp3           playMp3; //xy=154,422
    AudioPlaySdWav           playWav; //xy=154,422
    AudioPlaySdRaw           playRaw; //xy=154,422
    AudioPlaySdAac           playAac; //xy=154,422
    AudioMixer4              mixer1;         //xy=323,326
    AudioMixer4              mixer2;         //xy=323,326
    AudioOutputAnalog        dac1;           //xy=445,393
    AudioConnection          patchCord1(playMp3, 0, mixer1, 0);
    AudioConnection          patchCord2(playMp3, 1, mixer1, 1);
    AudioConnection          patchCord3(playWav, 0, mixer1, 2);
    AudioConnection          patchCord4(playWav, 1, mixer1, 3);
    AudioConnection          patchCord5(playAac, 0, mixer2, 0);
    AudioConnection          patchCord6(playAac, 1, mixer2, 1);
    AudioConnection          patchCor7(playRaw, 0, mixer2, 2);
    AudioConnection          patchCord8(mixer1, dac1);
    AudioConnection          patchCord9(mixer2, dac1);
    
    #define PROP_AMP_ENABLE    5
    #define FLASH_CHIP_SELECT  6
    
    float volume = 0.5f;
    File root, entry;
    
    void setup() {
      
      AudioMemory(40);
      dac1.analogReference(EXTERNAL);  //plays really loud, may get static
      
      delay(100); 
    
      if (!(SD.begin(BUILTIN_SDCARD))) {
        // stop here, but print a message repetitively
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
      Serial.println("initialization done.");
      root = SD.open("/");
    
      //Start Amplifier
      pinMode(PROP_AMP_ENABLE , OUTPUT);
      digitalWrite(PROP_AMP_ENABLE , HIGH);
    }
    
    void playFile(const char *filename)
    {
      int filetype;
    
      filetype = 0;
      if (strstr(filename, ".MP3") != NULL) {
          filetype = 1;
      } else if (strstr(filename, ".WAV") != NULL ) {
          filetype = 2;
      } else if (strstr(filename, ".AAC") != NULL ) {
          filetype = 3;
      } else if (strstr(filename, ".RAW") != NULL ) {
          filetype = 4;
      } else
        filetype = 0;
    
      if (filetype > 0) {
        Serial.print("Playing file: ");
        Serial.println(filename);
        
        switch (filetype) {
          case 1 :
            mixer1.gain(0, volume);
            mixer1.gain(1, volume);
            mixer1.gain(2, 0.0f);
            mixer1.gain(3, 0.0f);
            playMp3.play(filename);
            delay(5);
            while (playMp3.isPlaying()) {
            }
            break;
          case 2 :
            mixer1.gain(0, 0.0f);
            mixer1.gain(1, 0.0f);
            mixer1.gain(2, volume);
            mixer1.gain(3, volume);
            playWav.play(filename);
            delay(5);
            while (playWav.isPlaying()) {
            }
            break;
          case 3 :
            mixer2.gain(0, volume);
            mixer2.gain(1, volume);
            mixer2.gain(2, 0.0f);
            playWav.play(filename);
            delay(5);
            while (playAac.isPlaying()) {
            }
            break;
          case 4 :
            mixer2.gain(0, 0.0f);
            mixer2.gain(1, 0.0f);
            mixer2.gain(2, volume);
            playRaw.play(filename);
            delay(5);
            while (playRaw.isPlaying()) {
            }
            break;
        }
      }
    }
    
    void loop() {
      playAll(root);
    }
    
    void playAll(File dir){
      char filename[64];
      char filnam[64];
      
       while(true) {
         entry =  dir.openNextFile();
         if (! entry) {
           // no more files
           // rewind to begining of directory and start over
           dir.rewindDirectory();
           break;
         }
         //Serial.print(entry.name());
         if (entry.isDirectory()) {
           //Serial.println("Directory/");
           //do nothing for now
           Serial.println(entry.name());
           playAll(entry);
         } else {
           // files have sizes, directories do not
           //Serial.print("\t\t");
           //Serial.println(entry.size(), DEC);
           // files have sizes, directories do not
           strcpy(filename, dir.name());
           strcat(filename, "/");
           strcat(filename, strcpy(filnam, entry.name()));
           playFile(filename);
         }
       entry.close();
     }
    }

  21. #21
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    4,102
    Ok. Tested aac and flac and it works fine. I added flac but I downloaded @Frank B's lib since in didn't see it the audio library. Just now sure what format I should save files in FLA format from Audacity but it works with the sample .fla file. I am attaching the final version in a zip file. PropShieldPlayAllSD.zip

  22. #22
    Junior Member
    Join Date
    Mar 2017
    Posts
    5
    Guess I am having the same problem. I cannot get a Mp3 file to play from serial flash memory using the Propshield. I successfully transferred the mp3 file to serial flash memory using teensytransfer. It shows up listed with the -l command. I tested the DAQ on the teensy 3.2 I'm using with noisetest.ino to create white noise and it work fine. I am using the Mp3player.ino sketch with no modifications except changing the filename to the one I am using. First I started out using a mono audio file at 44kbps rate, lame Mp3 encoded. Then I converted it to stereo @ 44kbps. It still will not play. File size is 12.6k. I am at a loss here and looking for help. It would be greatly appreciated. The teensy 3.2 seems fine. I also have an OLED display attached to the teensy in parallel 4bit mode which is not sharing any I/O with the propshield and it works fine. It is not included in the code below because I took it out for now. I am wondering if the Mp3 file needs to have a certain bitrate to work? Can a mono audio file work with this or does it need to be stereo? I really can't think of anything else that could be wrong. The code runs as I can see that in the serial monitor as it is looping the file name. No errors during compiling either. I am compiling with Arduino 1.8.1. Thanks for any help.

    // Simple MP3 file player example
    //
    // https://forum.pjrc.com/threads/27059...l=1#post101537
    //
    // Requires the prop-shield and Teensy 3.2 or 3.1
    // This example code is in the public domain.

    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <play_sd_mp3.h> // https://github.com/FrankBoesing/Ardu...ensy-Codec-lib
    //#include <play_sd_aac.h>


    // GUItool: begin automatically generated code
    //AudioPlaySdWav playSdWav1; //xy=154,422
    AudioPlaySdMp3 playMp31; //xy=154,422
    AudioMixer4 mixer1; //xy=327,432
    AudioOutputAnalog dac1; //xy=502,412
    AudioConnection patchCord1(playMp31, 0, mixer1, 0);
    AudioConnection patchCord2(playMp31, 1, mixer1, 1);
    AudioConnection patchCord3(mixer1, dac1);
    // GUItool: end automatically generated code


    #define PROP_AMP_ENABLE 5
    #define FLASH_CHIP_SELECT 6
    //#define FLASH_CHIP_SELECT 21 // Arduino 101 built-in SPI Flash

    void setup() {
    Serial.begin(9600);
    AudioMemory(8); //4
    delay(2000);

    // Start SerialFlash
    if (!SerialFlash.begin(FLASH_CHIP_SELECT)) {
    while (1) {
    Serial.println ("Cannot access SPI Flash chip");
    delay (1000);
    }
    }

    //Set Volume
    mixer1.gain(0, 0.5);
    mixer1.gain(1, 0.5);

    //Start Amplifier
    pinMode(PROP_AMP_ENABLE, OUTPUT);
    digitalWrite(PROP_AMP_ENABLE, HIGH); // Enable Amplifier
    }

    void playFile(const char *filename)
    {
    SerialFlashFile ff = SerialFlash.open(filename);
    Serial.print("Playing file: ");
    Serial.println(filename);

    uint32_t sz = ff.size();
    uint32_t pos = ff.getFlashAddress();

    // Start playing the file. This sketch continues to
    // run while the file plays.
    playMp31.play(pos,sz);

    // Simply wait for the file to finish playing.
    while (playMp31.isPlaying()) {
    yield();
    }
    }


    void loop() {
    playFile("test2.mp3");
    delay(10000);
    }

  23. #23
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,196
    Your sketch works for me. (Use CODE tags rather than QUOTE tags to retain sketch indentation).

    T3.2 and propshield, with DAC/A14 of T3.2 hooked to propshield AudioIN, shield has 8ohm speaker off of + -
    I converted WAV to MP3
    lame -b 320 -h TOPGUN.WAV TOPGUN.MP3
    file TOPGUN.MP3
    TOPGUN.MP3: MPEG ADTS, layer III, v1, 320 kbps, 44.1 kHz, JntStereo
    teensytransfer TOPGUN.MP3

  24. #24
    Junior Member
    Join Date
    Mar 2017
    Posts
    5
    OK, it is working now. How the mp3 is encoded (bitrate and sampling) apparently makes a difference. Mono or stereo both work fine.

    Thanks

Posting Permissions

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