Skip to content

feedBuffer_noLock not adapted to fast processor #34

Closed
@briancouchman

Description

@briancouchman

Hello dear Adafruit

I purchased a Feather Huzzah 32 with a ESP32 on it, and a Adafruit Music Maker FeatherWing - MP3 OGG WAV MIDI Synth Player (PID: 3357).
I used the V1053 library and it didn't work. In fact only the first bytes of the data is played for a fraction of a second.
Looking into the code in the feedBuffer_noLock I noticed that if readyForData() returns 0 everything stops, and it seems that the data is fed too fast. After 110 times of writing 32 bytes, readyForData() returns 0 . The datasheet of the chip explains that when that happens the code should just wait for the buffer to be ready again and continue.

I have tentatively changed the code to this

void Adafruit_VS1053_FilePlayer::feedBuffer_noLock(void) {
  if ((! playingMusic) // paused or stopped
      || (! currentTrack)
      || (! readyForData())) {
    return; // paused or stopped
  }

  int cnt = 0;
  // Feed the hungry buffer! :)
  while (playingMusic/*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, wrap it up!
      playingMusic = false;
      currentTrack.close();
      break;
    }

    while(!readyForData()){
      //wait for the buffer to be ready to receive more data
    }
    playData(mp3buffer, bytesread);
  }
}

It keeps reading the data the until playingMusic becomes false.
But it will wait for readyForData() to be 1 before calling playData()

Hopefully it can be an improvement to the library for controllers like ESP32.
I am very new to whole this so if you see a problem in my code or my thinking it's very welcome.

Thanks

By the way Adafruit, you are so awesome !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions