Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playMP3(fileName, timecode) #5

Open
JonGordon123 opened this issue Oct 13, 2022 · 0 comments
Open

playMP3(fileName, timecode) #5

JonGordon123 opened this issue Oct 13, 2022 · 0 comments

Comments

@JonGordon123
Copy link

JonGordon123 commented Oct 13, 2022

Arduino 1.8.19
LilyPad MP3

I was having a few issues when attempting to play an mp3 from a specified ms time and found the following.

  1. The variable "bitrate" is declared in SFEMP3Shield.h as a uint8_t, which only allows bitrates up to 224kbps. I changed it to uint16_t which solves that issue.

  2. The If...else if... else if... else statement found in the getBitRateFromMP3File(filename) function (SFEMP3Shield.cpp) seems to not be functioning as, I imagine, it should be. If the MP3 file is MPEG Version 2/2.5 then the first if statement evaluates true, and no other code is run in the if/else if block.... causing the "bitrate" variable to be filled with an incorrect bitrate.
    I tested with multiple files, bitrates, and sample rates and was getting incorrect bitrates often.

 //found the 11 1's
  //parse version, layer and bitrate out and save bitrate
  if(!(temp & 0b00001000)) { //!true if Version 1, !false version 2 and 2.5
    row_num = 3;
  }
  else if((temp & 0b00000110) == 0b00000100) { //true if layer 2, false if layer 1 or 3
    row_num += 1;
  }
  else if((temp & 0b00000110) == 0b00000010) { //true if layer 3, false if layer 2 or 1
    row_num += 2;
  } else {
    continue; // Not found, need to skip the rest and continue looking.
              // \warning But this can lead to a dead end and file end of file.
  }

I seem to have fixed my issue by replacing the existing if...else if....else if...else with the following.

bool nobits = true;

if(!(temp & 0b00001000)) {
   // MPEG Version 2 or 2.5
   row_num = 3;
   nobits = false;
}
if((temp & 0b00000110) == 0b00000110) {
  // Layer 1
  //row_num += 0;
  nobits = false;
}
if((temp & 0b00000110) == 0b00000100) {
  // Layer 2
  row_num += 1;
  nobits = false;
}
if((temp & 0b00000110) == 0b00000010) {
  // Layer 3
  row_num += 2;
  nobits = false;
}
if(nobits){
  continue;
}

These two changes allowed me to play any file from any ms timestamp, without issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant