Keypad and playing wav with DUE

MADMAN-_-zZ:
Another code cleanup here, let me know if it still works as per before, not sure about your issue playing antanas.wav, so after playing that file you can no longer play anymore sounds? only after playing that one?

#include <DAC.h>

#include <SD.h>
#include <SPI.h>
#include <Audio.h>
#include <Key.h>
#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
  // debug output at 9600 baud
  Serial.begin(9600);
  // setup SD-card
  SD.begin(10);
}

void loop() {
  //pressing the key -> assigning the filename
  keypadInput();
}

void keypadInput(){
char customKey = customKeypad.getKey();

if (customKey){ //Check for valid input
    switch(customKey){
      case '1':
        playSound("jonas.wav");
        break;
      case '2':
        playSound("petras.wav");
        break;
      case '3':
        playSound("antanas.wav");
        break;
        case '4':
        playSound("test.wav");
        break;
      default:
        break;
    }
  }
}

void playSound(const char* cName){
  File myFile = SD.open(cName);
  const int S = 1024; // Number of samples to read in block
  short buffer[S];
    // until the file is not finished
  Serial.println("playing ");
  Serial.print(cName);
  Audio.begin(44100, 100);
  while (myFile.available()) {
    myFile.read(buffer, sizeof(buffer));
        // Prepare samples
    int volume = 1024;
    Audio.prepare(buffer, S, volume);
    Audio.write(buffer, S);   
  }
  Audio.end();
  myFile.close(); 
}

Thanks a bunch! This version works the same, but now I don't have Audio.begin() in 4 places, very nice, thanks. Apparently antanas.wav file was damaged... :confused: When duplicating jonas.wav and renaming it as antanas.wav works just fine. [edit] Also, I just re-exported antanas.wav - works fine!

Have some karma for the help!

Now I will try instead of just pressing one button assign a short "phone number" to each soundtracks. Should be easy I guess.