Problem with mp3 library

Status
Not open for further replies.

Stuntmunky

Active member
More than likely the problem is me :eek:

I have been trying to add an mp3 player to a small busking amp I have made. I managed to get an external mp3 module working with it but was getting unwanted noise . I put an audio loop isolation transformer in but it didn't sound great and so I started to look for alternatives.

I have been using the Complete_MP3_AAC_MP4_M4A example in the Audiocodecs library to try and implement a player into my existing code. I have two audio shields and a teensy 3.2. The code compiles and the existing lines in/out and controls all function as usual but the mp3 is not working.

When I open the serial monitor it looks like it is just skipping through all the tracks without giving them time to play.

I have tried putting in a delay after playMp31.play(filename); but it didn't help

I also changed the mp3 files in audacity to 16 bit but no joy either

I will keep plugging away at it but if anyone can see where I may have gone wrong I would be very grateful, I'm not an absolute beginner but not far off :D

Here's the code:
Code:
#include <IRremote.h>
#include <Encoder.h>
#include <Bounce.h>
#include <EEPROM.h>
#include <play_sd_mp3.h>

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>


// GUItool: begin automatically generated code
AudioInputI2SQuad        i2s_quad1;      //xy=72,136
AudioPlaySdWav           playSdWav1;     //xy=83,349
AudioMixer4              mixer5;         //xy=202,218
AudioMixer4              mixer1;         //xy=220,76
AudioMixer4              mixer2;         //xy=344,140
AudioMixer4              mixer4;         //xy=442,57
AudioMixer4              mixer3;         //xy=469,196
AudioFilterStateVariable filter1;        //xy=583,32
AudioFilterStateVariable filter2;        //xy=722,35
AudioOutputI2SQuad       i2s_quad2;      //xy=789,187
AudioConnection          patchCord1(i2s_quad1, 0, mixer1, 0);
AudioConnection          patchCord2(i2s_quad1, 1, mixer1, 1);
AudioConnection          patchCord3(i2s_quad1, 2, mixer2, 1);
AudioConnection          patchCord4(playSdWav1, 0, mixer3, 1);
AudioConnection          patchCord5(playSdWav1, 1, mixer3, 2);
AudioConnection          patchCord6(mixer5, 0, mixer2, 2);
AudioConnection          patchCord7(mixer1, 0, mixer2, 0);
AudioConnection          patchCord8(mixer2, 0, mixer3, 0);
AudioConnection          patchCord9(mixer4, 0, filter1, 0);
AudioConnection          patchCord10(mixer4, 0, i2s_quad2, 1);
AudioConnection          patchCord11(mixer4, 0, i2s_quad2, 0);
AudioConnection          patchCord12(mixer3, 0, mixer4, 0);
AudioConnection          patchCord13(filter1, 0, filter2, 0);
AudioConnection          patchCord14(filter2, 2, i2s_quad2, 3);
AudioControlSGTL5000     sgtl5000_1;     //xy=67,20
AudioControlSGTL5000     sgtl5000_2;     //xy=195,20
// GUItool: end automatically generated code


AudioPlaySdMp3           playMp31; //needs manual patching into sys
AudioConnection          patch1(playMp31,0,mixer5,0);
AudioConnection          patch2(playMp31,1,mixer5,1);

#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

#define NUM_BUTTONS   7       // number of remote buttons
#define RECV_PIN      2

int track;
int tracknum;
int trackext[255]; // 0= nothing, 1= mp3, 2= aac, 3= wav.
String tracklist[255];
File root;
char playthis[15];
boolean trackchange;
boolean paused;

const int ledPin1 =  3;
const int ledPin2 =  4;
const int ledPin3 =  5;

uint16_t lastCode = 0;
const uint16_t BUTTON_volup = 0xFFA857; //ir remote codes
const uint16_t BUTTON_voldown = 0xFFE01F;
const uint16_t BUTTON_back = 0xFF22DD;
const uint16_t BUTTON_pp = 0xFFC23D;
const uint16_t BUTTON_fwd = 0xFF02FD;
const uint16_t BUTTON_1 = 0xFF30CF;
const uint16_t BUTTON_2 = 0xFF18E7;

Bounce button1 = Bounce(1, 15);  // 15 = 15 ms debounce time

IRrecv irrecv(RECV_PIN);
decode_results results;

Encoder myEnc(0, 21);

int tonevolsel = 1;

float bass = 0.0;
float treble = 0.0;
float vol = 0.0;

float oldPosition1  = 0.0;
//long newPosition;

void setup() {
  
  AudioMemory(60);
  
  Serial.begin(115200);
 
  
  irrecv.enableIRIn(); // Start the receiver
 pinMode (RECV_PIN, INPUT);

 pinMode(ledPin1, OUTPUT);
 pinMode(ledPin2, OUTPUT); 
 pinMode(ledPin3, OUTPUT);

 pinMode(1, INPUT_PULLUP);

 track = EEPROM.read(0);
 
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }

  
  sgtl5000_1.setAddress(LOW);
  sgtl5000_1.enable();
  sgtl5000_1.lineOutLevel(13);
  sgtl5000_1.lineInLevel(9);
  sgtl5000_1.muteHeadphone();
  sgtl5000_1.audioPostProcessorEnable();
 // sgtl5000_1.eqBands(bass,treble);
  
  
  sgtl5000_2.setAddress(HIGH);
  sgtl5000_2.enable();
  sgtl5000_2.lineOutLevel(13);
  sgtl5000_2.lineInLevel(9);
  sgtl5000_2.muteHeadphone();
  sgtl5000_2.audioPostProcessorEnable();
//  sgtl5000_2.eqBands(bass,treble);
  
  filter1.frequency(9000);
  filter2.frequency(70);

 
  // Stereo linein/bluetooth to mono
   mixer1.gain(0, 0.5);
   mixer1.gain(1, 0.5);

  // Control for line/mp3/mic
   mixer2.gain(0, 0.0);
   mixer2.gain(1, 0.0);
   mixer2.gain(2, 0.0);

  // Turns sd to mono and mixes with product of mixer2
   mixer3.gain(0, 0.5);
   mixer3.gain(1, 0.25);
   mixer3.gain(2, 0.25);

   // Master volume
   mixer4.gain(0,0);
   
   // Turns mp3 stereo into mono
   mixer5.gain(0,0.45);
   mixer5.gain(1,0.45);

    root = SD.open("/");

  while(true) {

    File files =  root.openNextFile();
    if (!files) {
      //If no more files, break out.
      break;
    }
    String curfile = files.name(); //put file in string
    //look for MP3 or AAC files
    int m = curfile.lastIndexOf(".MP3");
    int a = curfile.lastIndexOf(".AAC");
    int a1 = curfile.lastIndexOf(".MP4");
    int a2 = curfile.lastIndexOf(".M4A");
    //int w = curfile.lastIndexOf(".WAV");

    // if returned results is more then 0 add them to the list.
    if(m > 0 || a > 0 || a1 > 0 || a2 > 0 ){  

      tracklist[tracknum] = files.name();
      if(m > 0) trackext[tracknum] = 1;
      if(a > 0) trackext[tracknum] = 2;  
      if(a1 > 0) trackext[tracknum] = 2;
      if(a2 > 0) trackext[tracknum] = 2;
      //  if(w > 0) trackext[tracknum] = 3;
      Serial.print(m);
      tracknum++;  
    }
    // close 
    files.close();
  }
   if(track > tracknum){
    //if it is too big, reset to 0
    EEPROM.write(0,0);
    track = 0;
  }
  tracklist[track].toCharArray(playthis, sizeof(tracklist[track]));
}

void playFileMP3(const char *filename)
{
  Serial.print("Playing file: ");
  Serial.print(track);
  Serial.print(" - ");
  Serial.println(filename);
  trackchange = true; //auto track change is allowed.
  // Start playing the file.  This sketch continues to
  // run while the file plays.
  EEPROM.write(0,track); //meanwhile write the track position to eeprom address 0
  playMp31.play(filename);
   delay(10);

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

void controls() {
  // ir buttons and decoder 
{
  if (irrecv.decode(&results)) {
    uint16_t resultCode = (results.value & 0xFFFF);
    if (resultCode == 0xFFFF)
      resultCode = lastCode;
    else
      lastCode = resultCode;
    switch (resultCode)
    {
      
      case BUTTON_volup:
      vol = vol + 0.1;
   
    if (vol>1){
      vol = 1;}
      if (vol<0){
      vol = 0;}
      Serial.println(vol); 
      mixer4.gain(0,vol);
        break;

    case BUTTON_voldown:
      vol = vol - 0.1;
   
    if (vol>1){
      vol = 1;}
      if (vol<0){
      vol = 0;}
       Serial.println(vol); 
      mixer4.gain(0,vol);
        break;
         
      case BUTTON_back:
            prevtrack();
             break;
      
      case BUTTON_pp:
    
        pausetrack();
 
       //   Serial.println("play/pause");
        break;
        
       case BUTTON_fwd:
     nexttrack();
        break; 
         
     
      case BUTTON_1:
          playSdWav1.stop(); 
        // Serial.println("wav1");
          playSdWav1.play("1.WAV");
          delay(10); // wait for library to parse WAV info
           break;
      
   
      case BUTTON_2:
          playSdWav1.stop(); 
        // Serial.println("wav2");
          playSdWav1.play("2.WAV");
          delay(10); // wait for library to parse WAV info
           break;
   
         
      
      default:
        Serial.print("Unrecognized code received: 0x");
        Serial.println(results.value, HEX);
        break;
    }

    irrecv.resume();
  }
}
}
void loop() {
  Serial.println();
  Serial.println();
  Serial.println(tracknum);
  Serial.println(track);
  Serial.println(trackext[track]);
  Serial.println(tracklist[track]);


  if(trackext[track] == 1){
    Serial.println("MP3" );
    playFileMP3(playthis);
    delay(10);
  }
   if(trackchange == true){ //when your track is finished, go to the next one. when using buttons, it will not skip twice.
    nexttrack();
  }
  delay(100);
  
  button1.update();
  if (button1.fallingEdge()) {
    tonevolsel  ++ ;
  if (tonevolsel == 4) tonevolsel = 1;
  }
  
 if (tonevolsel == 1){
  digitalWrite(ledPin1, HIGH);
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin3, LOW);
  
    float newPosition = myEnc.read()/4;
  if (newPosition != oldPosition1) {
   oldPosition1 = newPosition;
   //Serial.println(newPosition);
 
    vol = vol + newPosition / 20;
   
    if (vol>1.0){
      vol = 1.0;}
      if (vol<0.0){
      vol = 0.0;}
   //    Serial.println("vol");
   //    Serial.println(vol); 
   mixer4.gain(0,vol);
    
  myEnc.write(0);
   }
 }

 if (tonevolsel == 2){
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, HIGH);
  digitalWrite(ledPin3, LOW);
  
    float newPosition = myEnc.read()/4;
  if (newPosition != oldPosition1) {
   oldPosition1 = newPosition;
 // Serial.println(newPosition);
 
    bass = bass + newPosition / 20;
   
    if (bass>1){
      bass = 1;}
      if (bass<-1){
      bass = -1;}
  //    Serial.println("bass"); 
   //    Serial.println(bass); 
   sgtl5000_1.eqBands(bass,treble);
   sgtl5000_2.eqBands(bass,treble);
   myEnc.write(0);}
 }
if (tonevolsel == 3){
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin3, HIGH);
  
    float newPosition = myEnc.read()/4;
  if (newPosition != oldPosition1) {
   oldPosition1 = newPosition;
  // Serial.println(newPosition);
 
    treble = treble + newPosition / 20;
   
    if (treble>1){
      treble = 1;}
      if (treble<-1){
      treble = -1;}
   //    Serial.println("treble");
  //     Serial.println(treble); 
   sgtl5000_1.eqBands(bass,treble);
   sgtl5000_2.eqBands(bass,treble);
   myEnc.write(0);}
 } 
 
  int mic = analogRead(A2);
  float micvol = (float)mic / 1023.0;
  mixer2.gain(0,micvol);
  //Serial.print("mic volume = ");
 // Serial.println(micvol);

  int line = analogRead(A3);
  float linevol = (float)line / 1023.0;
  mixer2.gain(1,linevol);
//  Serial.print("line volume = ");
 //Serial.println(linevol);

  int oompah3 = analogRead(A6);
  float mp3vol = (float)oompah3 / 1023.0;
  mixer2.gain(2,mp3vol);
 // Serial.print("mp3 volume = ");
//Serial.println(mp3vol);

 
  controls();
 }
 void nexttrack(){
  Serial.println("Next track!");
  trackchange=false; // we are doing a track change here, so the auto trackchange will not skip another one.
  playMp31.stop();
  
  track++;
  if(track >= tracknum){ // keeps in tracklist.
    track = 0;
  }  
  tracklist[track].toCharArray(playthis, sizeof(tracklist[track])); //since we have to convert String to Char will do this    
}

void prevtrack(){
  Serial.println("Previous track! ");
  trackchange=false; // we are doing a track change here, so the auto trackchange will not skip another one.
  playMp31.stop();
 
  track--;
  if(track <0){ // keeps in tracklist.
    track = tracknum-1;
  }  
  tracklist[track].toCharArray(playthis, sizeof(tracklist[track])); //since we have to convert String to Char will do this    
}

void pausetrack(){
  if(paused){
    Serial.println("Playing!");
  }
  else{
    Serial.println("Paused!");
  }
  paused = playMp31.pause(!paused);
}
 
It was a bit late for tinkering here too last night (uk) :)

I tried the simple player, I did have to alter it a little to match my hardware but kept it as simple as possible. I am still getting the same problem, the serial monitor is just listing each track as playing but is going through them all in about half a second and continues to loop through them until I turn it off. No audio output either.

I will try some different files and see if that makes a difference

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>

#include <play_sd_mp3.h>


AudioOutputI2SQuad       i2s_quad2;      //xy=506,136// GUItool: begin automatically generated code
AudioPlaySdMp3           playMp31;       //xy=154,78
AudioConnection          patch1(playMp31,0,i2s_quad2,2);
AudioConnection          patch2(playMp31,1,i2s_quad2,3);

// GUItool: begin automatically generated code

AudioControlSGTL5000     sgtl5000_1;     //xy=64.5,20
AudioControlSGTL5000     sgtl5000_2;     //xy=195,20
// GUItool: end automatically generated code

void setup() {
  Serial.begin(9600);

  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(5);

  sgtl5000_1.enable();
  sgtl5000_1.volume(0.25);
   sgtl5000_2.enable();
  sgtl5000_2.volume(0.25);

  SPI.setMOSI(7);
  SPI.setSCK(14);
  if (!(SD.begin(10))) {
    // 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.
  playMp31.play(filename);

  // Simply wait for the file to finish playing.
  while (playMp31.isPlaying()) {
    // uncomment these lines if your audio shield
    // has the optional volume pot soldered
    //float vol = analogRead(15);
    //vol = vol / 1024;
    // sgtl5000_1.volume(vol);

#if 0	
	 Serial.print("Max Usage: ");
	 Serial.print(playMp31.processorUsageMax());
	 Serial.print("% Audio, ");
	 Serial.print(playMp31.processorUsageMaxDecoder());	 	 
	 Serial.print("% Decoding max, ");
	 
	 Serial.print(playMp31.processorUsageMaxSD());	 
	 Serial.print("% SD max, ");
	 	 
	 Serial.print(AudioProcessorUsageMax());	 
	 Serial.println("% All");
	 
	 AudioProcessorUsageMaxReset();
	 playMp31.processorUsageMaxReset();
	 playMp31.processorUsageMaxResetDecoder();
#endif 
	 
	 delay(250);
  }
}


void loop() {
  playFile("03 - Audio Track.mp3");	
  playFile("04 - Audio Track.mp3");
  playFile("02 - Audio Track.mp3");
  delay(500);
}
 
Some progress :)

I tried with 3 new mp3 files and the simple player, two of which played with no problems and one that skips through as before.

I hadn't set the address high and low for the two shields in the second sketch, oops! I also added a mixer to take the volume down, all is working fine.

Unfortunately I still get the same problem with my original sketch even with these new files, I will keep trying though. At least now I have a sketch to test files and come up with a playlist that should work if I can sort the code out.

On the plus side the system sounds great when it is playing
 
In a further attempt to debug I tried uploading the "Complete_MP3_AAC_MP4_M4A" example as close to the original as possible with my hardware setup.

The only thing I changed was the audio connections and the name of the mixer to match, see code below.

This has the same problem as my sketch, even with the files that work in the simple sketch.

I think it might be something to do with the way it changes tracks and the boolean trackchange, will continue to play around.

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Bounce.h> //Buttons
#include <EEPROM.h> // store last track

#include <play_sd_mp3.h> //mp3 decoder
#include <play_sd_aac.h> // AAC decoder

#define BUTTON1 2  //NEXT
#define BUTTON2 3  //Play Pause
#define BUTTON3 4  //PREV 

Bounce bouncer1 = Bounce(BUTTON1, 50); 
Bounce bouncer2 = Bounce(BUTTON2, 50); 
Bounce bouncer3 = Bounce(BUTTON3, 50);

//const int chipSelect = 10;  // if using another pin for SD card CS.
int track;
int tracknum;
int trackext[255]; // 0= nothing, 1= mp3, 2= aac, 3= wav.
String tracklist[255];
File root;
char playthis[15];
boolean trackchange;
boolean paused;

AudioPlaySdMp3           playMp31;
AudioPlaySdAac           playAac1;
AudioMixer4              mixer1;         //xy=309,134
AudioOutputI2SQuad       i2s_quad2;      //xy=506,136
AudioConnection          patchCord1(playMp31, 0, mixer1, 0);
AudioConnection          patchCord2(playMp31, 1, mixer1, 1);
AudioConnection          patchCord1a(playAac1, 0, mixer1, 2);
AudioConnection          patchCord2a(playAac1, 1, mixer1, 3);
AudioConnection          patchCord3(mixer1, 0, i2s_quad2, 3);
AudioControlSGTL5000     sgtl5000_1;     //xy=64.5,20
AudioControlSGTL5000     sgtl5000_2;     //xy=195,20


void setup() {
   Serial.begin(115200);


  sgtl5000_1.setAddress(LOW);
  sgtl5000_1.enable();
  sgtl5000_1.lineOutLevel(13);
  sgtl5000_1.lineInLevel(9);
  sgtl5000_1.muteHeadphone();
   sgtl5000_2.setAddress(HIGH);
  sgtl5000_2.enable();
  sgtl5000_2.lineOutLevel(13);
  sgtl5000_2.lineInLevel(9);
  sgtl5000_2.muteHeadphone();
  
  SPI.setMOSI(7);                   
  SPI.setSCK(14);

  //setup pins with pullups
  pinMode(BUTTON1,INPUT_PULLUP);
  pinMode(BUTTON3,INPUT_PULLUP);
  pinMode(BUTTON2,INPUT_PULLUP);  
  // reads the last track what was playing.
  track = EEPROM.read(0); 

  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(16);
  //put the gain a bit lower, some MP3 files will clip otherwise.
  mixer1.gain(0,0.1);
  mixer1.gain(1,0.1);
   mixer1.gain(2,0.1);
  mixer1.gain(3,0.1);
  
  //Start SD card
  if (!(SD.begin(10))) {
    // stop here, but print a message repetitively
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
  //Starting to index the SD card for MP3/AAC.
  root = SD.open("/");

  while(true) {

    File files =  root.openNextFile();
    if (!files) {
      //If no more files, break out.
      break;
    }
    String curfile = files.name(); //put file in string
    //look for MP3 or AAC files
    int m = curfile.lastIndexOf(".MP3");
    int a = curfile.lastIndexOf(".AAC");
    int a1 = curfile.lastIndexOf(".MP4");
    int a2 = curfile.lastIndexOf(".M4A");
    //int w = curfile.lastIndexOf(".WAV");

    // if returned results is more then 0 add them to the list.
    if(m > 0 || a > 0 || a1 > 0 || a2 > 0 ){  

      tracklist[tracknum] = files.name();
      if(m > 0) trackext[tracknum] = 1;
      if(a > 0) trackext[tracknum] = 2;  
      if(a1 > 0) trackext[tracknum] = 2;
      if(a2 > 0) trackext[tracknum] = 2;
      //  if(w > 0) trackext[tracknum] = 3;
      Serial.print(m);
      tracknum++;  
    }
    // close 
    files.close();
  }
  //check if tracknum exist in tracklist from eeprom, like if you deleted some files or added.
  if(track > tracknum){
    //if it is too big, reset to 0
    EEPROM.write(0,0);
    track = 0;
  }
  tracklist[track].toCharArray(playthis, sizeof(tracklist[track]));
}

void playFileMP3(const char *filename)
{
  Serial.print("Playing file: ");
  Serial.print(track);
  Serial.print(" - ");
  Serial.println(filename);
  trackchange = true; //auto track change is allowed.
  // Start playing the file.  This sketch continues to
  // run while the file plays.
  EEPROM.write(0,track); //meanwhile write the track position to eeprom address 0
  playMp31.play(filename);


  // Simply wait for the file to finish playing.
  while (playMp31.isPlaying()) {
    // update controls!
    controls();
    serialcontrols();
  }
}

void playFileAAC(const char *filename)
{
  Serial.print("Playing file: ");
  Serial.print(track);
  Serial.print(" - ");
  Serial.println(filename);
  trackchange = true; //auto track change is allowed.
  // Start playing the file.  This sketch continues to
  // run while the file plays.
  EEPROM.write(0,track); //meanwhile write the track position to eeprom address 0
  playAac1.play(filename);


  // Simply wait for the file to finish playing.
  while (playAac1.isPlaying()) {
    // update controls!
    controls();
    serialcontrols();
  }
}

void controls() {
  bouncer1.update();
  bouncer2.update();
  bouncer3.update();
  if ( bouncer1.fallingEdge()) { 
    nexttrack();
  }
  if ( bouncer2.fallingEdge()) {  
    pausetrack();
  }
  if ( bouncer3.fallingEdge()) { 
    prevtrack();
  }  
}

void serialcontrols(){
  if(Serial.available()){
    byte incomingByte = Serial.read();

    switch(incomingByte){

    case 78:     //Next track  N
      nexttrack();
      break;

    case 80:     //Previous track P
      prevtrack();
      break;

    case 73:     //pause track I
      pausetrack();
      break;               

    case 75:     //List tracklist K
      //list our tracklist over serial
      for(int i =0; i < tracknum;i++){
        Serial.print(i);
        Serial.print("\t");
        Serial.print(tracklist[i]);
        Serial.print("\t");
        Serial.println(trackext[i]);
      }        
      break;  

    case 67: //current track C
      Serial.print("current track = ");      
      Serial.print(track);  
      Serial.print(" - ");  
      Serial.println(tracklist[track]);    
      break;  
    case 82: //random track
      randomtrack();
      break;
    }         
    incomingByte = 0;

  }

}



void loop() {


  Serial.println();
  Serial.println();
  Serial.println(tracknum);
  Serial.println(track);
  Serial.println(trackext[track]);
  Serial.println(tracklist[track]);


  if(trackext[track] == 1){
    Serial.println("MP3" );
    playFileMP3(playthis);
  }else if(trackext[track] == 2){
    Serial.println("aac");
    playFileAAC(playthis);
  }


  if(trackchange == true){ //when your track is finished, go to the next one. when using buttons, it will not skip twice.
    nexttrack();
  }
  delay(100);
}

void nexttrack(){
  Serial.println("Next track!");
  trackchange=false; // we are doing a track change here, so the auto trackchange will not skip another one.
  playMp31.stop();
  playAac1.stop();
  track++;
  if(track >= tracknum){ // keeps in tracklist.
    track = 0;
  }  
  tracklist[track].toCharArray(playthis, sizeof(tracklist[track])); //since we have to convert String to Char will do this    
}

void prevtrack(){
  Serial.println("Previous track! ");
  trackchange=false; // we are doing a track change here, so the auto trackchange will not skip another one.
  playMp31.stop();
  playAac1.stop();
  track--;
  if(track <0){ // keeps in tracklist.
    track = tracknum-1;
  }  
  tracklist[track].toCharArray(playthis, sizeof(tracklist[track])); //since we have to convert String to Char will do this    
}

void pausetrack(){
  if(paused){
    Serial.println("Playing!");
  }
  else{
    Serial.println("Paused!");
  }
  paused = playMp31.pause(!paused);
}


void randomtrack(){
  Serial.println("Random track!");
  trackchange=false; // we are doing a track change here, so the auto trackchange will not skip another one.
  if(trackext[track] == 1) playMp31.stop();
  if(trackext[track] == 2) playAac1.stop();

  track= random(tracknum);

  tracklist[track].toCharArray(playthis, sizeof(tracklist[track])); //since we have to convert String to Char will do this    
}
 
Can you check if the files are 44.1kHz with fixed bitrate? Only those will work. Which bitrate you are using? I remember some users had problems playing files with 320kbps (which is overkill anyway).

Please send me a not working mp3. I'll look tomorrow.
 
Will do and thank you, how is best to send it to you?

The track that doesn't work is 128kbps 44.1hz and constant bitrate

The two tracks that do work are 235 kbps 44.1hz with variable bitrate and 256 kbps 44.1hz with constant bitrate.
 
Thanks Frank, I take it that means files must be labelled with 8 characters or less and then 3 for the file type?

I renamed one of the tracks that wouldn't play originally and its working in the simple player now so I presume that is the case.

I did read the entire thread about the development of the library and any docs I could find but it was late so I may well have missed that info, sorry.

I loaded up the test files and tried them with the complete player example and my original sketch but had the same issue with both as before, any ideas?

Been through the code several times but I am stumped
 
The 8.3 format is a restriction of the SD-Library. It has a historical backgrund. The orginal FAT used this format, and for long years only 8.3 filenames were allowed (well, in DOS/Windows). All newer FATxx formats are still compatible, and store 8.3, plus a long version of the filename. The SD library still reads the short 8.3 format only.
So, this the case for all files, i.e. *.wav, too.

Your sketch: Dunno, not easy, I don't have your hardware.. maybe, I try it tomorrow, if I have some time.
 
That explains why I haven't come across that problem before, so far I have been using short .wav files that I have renamed according to what triggers them so button1.wav for example.

I tried loading a completely unchanged version of the complete player example, with the test files. I know it won't output to the right places for my current setup but I figured the serial monitor should show if it was working.

I was getting the same results with that, just wondering if you or anyone else has the hardware to test that example and see if it is working ok with an audio board?
It says in the example that the creator didn't have an audio board at the time so I wonder if anyone has managed to test it.

No worries if not or you don't have time I appreciate the time you have spent on it already
 
Oh, I know that MP3 works with an audioboard :) It works with all outputs, for sure, because it's independend of the choosen output.
It's an other problem...
 
Just a quick update, some success and a lot of weird/inconsistent results. I carried on testing last night but wanted to check again before posting, so as to be clear what was going on. Unfortunately the results seem to be changing without me doing much but I will try my best to describe it.

With both the unchanged and the version changed to my hardware of the complete player example, if just the test files (mp3) are on the card it skips through without playing as before. If I put a an M4A file labelled SDTEST5.m4a on the card with the test files . Both sketches start playing with the m4a and will then play the mp3's.

If I send "N" through the serial the unchanged version will go to the next track and with the version for my hardware will sometimes goto the next track and will sometimes skip a track

If I then just load the sd card with just the m4a track both sketches will just skip through as with the mp3's when on their own.

If I label the m4a as SDTEST.m4a with the test tracks on the card as well, so that the m4a appears first on the list. Both sketches then skip through the tracks the same when one file type is on the disk.

This is fairly consistent except sometimes i will get a can't access sd card message, if I press the reset button this usually clears it but not always.

Last night with different tracks and a mix of m4a and mp3's my original sketch was working and reacting the same as the other two sketches. Today it is skipping through no matter what I try.

All this might be moot though, as when the original sketch was working last night, I put on the card the short wav files connected to the ir buttons. In the past I have had no problems with playing 2 wav files at the same time, unless I really spam the buttons.
Pressing them once with the mp3 or m4a playing caused the wav to play about halfway before stopping and the mp3 would restart from the beginning.

For me this is a deal breaker, I need to be able to play two files at the same time. The appeal for me of a software mp3 player was that it would cut out the background noise problems I have been having with an external player and being able to change tracks on the sd card without having to name them in software was also a bonus.

I have a different mp3 board coming on the slow boat from china so I think I will see how that goes or just return to named wav files for the remote in my show and use the bluetooth for playlists from phones for fun in the park/ambient music.

I would still like to know what is going on from an intellectual/learning perspective if anyone has any bright ideas and thanks to you Frank for your time.

Just now I am wearing a bald patch in my head from scratching it so I think I'm going to explore other avenues
 
Status
Not open for further replies.
Back
Top