adafruit / Adafruit_VS1053_Library

This is a Arduino library for the Adafruit VS1053 Codec Breakout and Music Maker Shields
https://www.adafruit.com/products/1381
135 stars 113 forks source link

VS1053b load patch from SDCard #41

Closed mycroft2k closed 2 years ago

mycroft2k commented 6 years ago

Is it possible that will be integrated to the lib?

TheNitek commented 6 years ago

You can do it like this:

bool patchVS1053() {
  uint16_t i = 0;

  Serial.println(F("Installing patch to VS1053"));

  SdFile file;
  if (!file.open("patches.053", O_READ)) return false;

  uint16_t addr, n, val;

  while (file.read(&addr, 2) && file.read(&n, 2)) {
    i += 2;
    if (n & 0x8000U) {
      n &= 0x7FFF;
      if (!file.read(&val, 2)) {
        file.close();
        return false;
      }
      while (n--) {
        musicPlayer.sciWrite(addr, val);
      }
    } else {
      while (n--) {
        if (!file.read(&val, 2)) {
          file.close();
          return false;
        }
        i++;
        musicPlayer.sciWrite(addr, val);
      }
    }
  }
  file.close();

  Serial.print(F("Number of bytes: ")); Serial.println(i);
}
mycroft2k commented 6 years ago

thx it works great

akoebbe commented 4 years ago

I'm having trouble with this solution. The first problem was that the following lines errored out...

  SdFile file;
  if (!file.open("/patches/flac.028", O_READ)) return false;

with the following error

src/main.cpp:54:45: error: no matching function for call to 'SdFile::open(const char [18], const uint8_t&)'

So I changed the code to the following

  File file = SD.open("/patches/flac.028", O_READ);
  if (!file) return false;

At this point the program can compile, but it doesn't seem like the patch is completely loading. It keeps bailing at the commented line below...

bool patchVS1053() {
  uint16_t i = 0;

  Serial.println(F("Installing patch to VS1053"));

  SdFile file;
  if (!file.open("/patches/flac.028", O_READ)) return false;

  uint16_t addr, n, val;

  while (file.read(&addr, 2) && file.read(&n, 2)) {
    i += 2;
    if (n & 0x8000U) {
      n &= 0x7FFF;
      if (!file.read(&val, 2)) {
        file.close();
        return false;
      }
      while (n--) {
        musicPlayer.sciWrite(addr, val);
      }
    } else {
      while (n--) {
        if (!file.read(&val, 2)) {
          file.close();
          return false; // <--- returning here!!!!
        }
        i++;
        musicPlayer.sciWrite(addr, val);
      }
    }
  }
  file.close();

  Serial.print(F("Number of bytes: ")); Serial.println(i); // I'm never getting here
}

Just to be sure, I should be using the .plg files from VLSI, correct?

akoebbe commented 4 years ago

Ok. So I just looked at the actual .plg file from VLSI. I was expecting to see binary, but instead I'm seeing what looks like C code. I'm getting the feeling I'm not loading the right file. What should I be looking for?

TheNitek commented 4 years ago

https://raw.githubusercontent.com/madsci1016/Sparkfun-MP3-Player-Shield-Arduino-Library/master/plugins/patches.053

akoebbe commented 4 years ago

Thanks @TheNitek but that seems like a really old patch. VLSI has patches as recent as 2020-04-29 (http://www.vlsi.fi/en/support/software/vs10xxpatches.html) so how do I get them in to the right format?

akoebbe commented 4 years ago

I just found the perl script (https://github.com/madsci1016/Sparkfun-MP3-Player-Shield-Arduino-Library/blob/master/plugins/vs_plg_to_bin.pl) in that same repo. I'll give it a shot.

akoebbe commented 4 years ago

It worked! Thanks.

caternuson commented 2 years ago

Closing. Seems resolved.