Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Music Maker Shield Gapless Looping
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Music Maker Shield Gapless Looping

by akoebbe on Sun Jul 19, 2020 3:14 am

So I'm revisiting a project I gave up on 4 years ago. I have a Music Maker Shield for an Arduino Uno and I have a file I want to continually loop over without a gap when it starts over. I tried just doing a playFullFIle() and just doing that in the loop, but I assumed there was a gap due to closing the file and reopening it. On the advice I got when I first started the project I modified the library to not close the file, but seek back to the beginning of the file and just keep shoveling in data to the chip. I think this has shortened the gap, but it's still there. Here is the block of code I modified.

Code: Select all | TOGGLE FULL SIZE
void Adafruit_VS1053_FilePlayer::feedBuffer_noLock(void) {
  if ((!playingMusic) // paused or stopped
      || (!currentTrack) || (!readyForData())) {
    return; // paused or stopped
  }

  // Feed the hungry buffer! :)
  while (readyForData()) {
    // Read some audio data from the SD card file
    int bytesread = currentTrack.read(mp3buffer, VS1053_DATABUFFERLEN);

    if (bytesread == 0) {
      // must be at the end of the file, seek back to the beginning and start over!
      currentTrack.seek(mp3_ID3Jumper(currentTrack)); // <-- It's an mp3 file so we skip the ID3 info
      bytesread = currentTrack.read(mp3buffer, VS1053_DATABUFFERLEN); // <-- since we have not bytes we need some to give to the chip
    }

    playData(mp3buffer, bytesread);
  }
}


Here is my main code. Much of which is taken from the Simple Test example

Code: Select all | TOGGLE FULL SIZE
void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit VS1053 Simple Test");

  if (! musicPlayer.begin()) { // initialise the music player
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }
  Serial.println(F("VS1053 found"));
 
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }

  patchVS1053(); // <-- loading in the latest patchs from VLSI

  // Set volume for left, right channels. lower numbers == louder volume!
  musicPlayer.setVolume(20,20);

  // Timer interrupts are not suggested, better to use DREQ interrupt!
  //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

  // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
}

void loop() {
  Serial.println(F("Playing file"));
  musicPlayer.playFullFile("/noise.mp3");
}

akoebbe
 
Posts: 9
Joined: Sat Jan 23, 2016 8:16 pm

Please be positive and constructive with your questions and comments.