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

VS1053b load patch from SDCard #41

Closed
mycroft2k opened this issue Feb 5, 2018 · 9 comments
Closed

VS1053b load patch from SDCard #41

mycroft2k opened this issue Feb 5, 2018 · 9 comments

Comments

@mycroft2k
Copy link

Is it possible that will be integrated to the lib?

@TheNitek
Copy link
Contributor

TheNitek commented Feb 5, 2018

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
Copy link
Author

thx it works great

@akoebbe
Copy link

akoebbe commented Jul 19, 2020

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
Copy link

akoebbe commented Jul 19, 2020

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?

@akoebbe
Copy link

akoebbe commented Jul 19, 2020

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
Copy link

akoebbe commented Jul 19, 2020

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
Copy link

akoebbe commented Jul 19, 2020

It worked! Thanks.

@caternuson
Copy link
Contributor

Closing. Seems resolved.

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

4 participants