Simple WAV Player

Hello fellow Arduines

I'm having trouble playing back more than one WAV files from Micro SD per session. Each WAV after

the first lags terribly and I'm guessing (as a newb) that this has something to do with the 'buffer'

retaining some value and needing to be reset for next audio.prepare/audio.write. I'm using the Audio.h

library with an Arduino Due and running code that isn't much more than the 'Simple WAV Player'

example. This problem of lag also occurs when I try to play a WAV of duration exceeding 30sec.

Here's the code:

void loop()

const int S = 1024; // SD audio; Number of samples to read in block
short buffer[S];
 

File wlcm = SD.open("welcome.wav");

    while (wlcm.available()) {
    // read from the file into buffer
    wlcm.read(buffer, sizeof(buffer));

    int volume = 1024;
    // Prepare samples
        Audio.prepare(buffer, S, volume);
    // Feed samples to audio
        Audio.write(buffer, S);

        }
    
     wlcm.close();

File intro = SD.open("proveyou.wav");

      while (intro.available()) {
      // read from the file into buffer
      intro.read(buffer, sizeof(buffer));

      int volume = 1024;
      // Prepare samples
          Audio.prepare(buffer, S, volume);
      // Feed samples to audio
          Audio.write(buffer, S);

        }
    
      intro.close();

The first file plays perfectly on initial playback but if it plays again (in loop for example) it lags at the same rate as the second file.

Solution:

http://forum.arduino.cc/index.php?topic=335703.0