Help with Adafruit Audio FX

I am using the arduino FX with an arduino nano to produce sound fx for a prop. I am using a string to store names for the sound files in the code below. Everything works fine as long as I have 17 or less names in the string. If I have 18 or more, the Arduino FX ceases to work at all. Here's a look at some of the code:

    // audio track names on soundboard
    const String startupTrack =   "T00     WAV";
    const String blastTrack =     "T01     WAV";
    const String endTrack =       "T02     WAV";
    const String idleTrack =      "T03     WAV";
    const String shutdownTrack =  "T04     WAV";
    const String clickTrack =     "T05     WAV";
    const String chargeTrack =    "T06     WAV";
    const String warnTrack =      "T07     WAV";
    const String ventTrack =      "T08     WAV";
    const String texTrack =       "T09     WAV";
    const String choreTrack =     "T10     WAV";
    const String toolsTrack =     "T11     WAV";
    const String listenTrack =    "T12     WAV";
    const String thatTrack =      "T13     WAV";
    const String neutronizedTrack="T14     WAV";
    const String boxTrack =       "T15     WAV";
    const String themeTrack =     "T16     OGG";
    const String slimeTrack =     "T17     OGG";

    void setup() {   
      // softwareserial at 9600 baud for the audio board
      ss.begin(9600);

      // see if we have the soundboard
      // If we fail to communicate, loop forever for now but it would be nice to warn the user somehow
      if (!sfx.reset()) {
        while (1);
      }

      // set act modes for the fx board
      pinMode(ACT, INPUT);

    /* ************* Audio Board Helper Functions ************* */
    // helper function to play a track by name on the audio board
    void playAudio( String trackname, int playing ) {
      // stop track if one is going
      if (playing == 0) {
        sfx.stop();
      }
     
      char charName[20];
      trackname.toCharArray(charName, 20);
     
      // now go play
      if (sfx.playTrack(charName)) {
        sfx.unpause();
      }
    }

    void loop() {
      // get the current time
      unsigned long currentMillis = millis();

      // find out of the audio board is playing audio
      int playing = digitalRead(ACT);

      // get the current switch states
      int theme_switch = digitalRead(THEME_SWITCH);

      // if the theme switch has recently changed from off to on we
      // should play the full ghostbusters theme song
      if (theme_switch == 1) {
        if (theme == false) {
          playAudio(themeTrack, playing);
          theme = true;
        }
      } else {
        theme = false;
      }

How can I fix this, or is there another way to do this?

grogking:
I am using the arduino FX with an arduino nano to produce sound fx for a prop. I am using a string to store names for the sound files in the code below. Everything works fine as long as I have 17 or less names in the string. If I have 18 or more, the Arduino FX ceases to work at all.

It's likely you are running out of memory.

Using String is not a good idea it uses a lot of memory... in any case you have to convert String into a char array in your playAudio() function:

      char charName[20];
      trackname.toCharArray(charName, 20);
     
      // now go play
      if (sfx.playTrack(charName)) {

You can define the track names as char arrays and modify playAudio() like:

    // audio track names on soundboard
    char startupTrack[]= "T00     WAV";
    char blastTrack[]=    "T01     WAV";
...

    // helper function to play a track - now given a char array
    void playAudio( char * trackName, int playing ) {
    ...
    if (sfx.playTrack( trackName )) {
    ...
    }

When you have that working, you can move those track names into program memory to save more space in working memory by looking at the examples in: PROGMEM

Yours,
TonyWilk

Thanks! That did it, been stumped by this one for a while.