Go Down

Topic: DUE won't play long .wav files twice (Read 236 times) previous topic - next topic

atlaikesbriedi

Jul 16, 2018, 10:35 am Last Edit: Jul 16, 2018, 10:44 am by atlaikesbriedi
Hi guys!
I am designing this "phone", where users (children) use coins and keypad to make it speak (play .wav files) through the handset. For this project I am using 16x2 LCD, 4x4 Keypad, SD shield + amplifier + speaker, Sparkfun 6 coin types acceptor, Arduino DUE.

Program works as follows:
1. Insert 1€ or more into the coin acceptor.
2. Lcd shows you inserted amount, and informs you when 1€ is reached.
3. Dial a number (123, 456 or 789).
4. Hear a sound e.g. ledaiLT.wav, blogasEN.wav, etc.

The problem is that program only plays short .wav (up to 20sec.) files well (e.g. when you dial a wrong number it plays short messages right). It will play long file well, if nothing was played before - so if a user dials a wrong number and then corrects it - program will freeze. Such a weird problem. Longest file I need to play is 1min 15sec.

Maybe someone has any ideas? Thanks!

[edit] - Attaching full file.
The full code is too long. These are sections responsible for playing the file:

Code: [Select]
void calculateAndPlay() {
  //if we have 3+1 numbers - proceed
  //the keys pressed are stored into chars I convert them to int then i did some multiplication to get the code as an int of xxxx
  i1 = (keypresses[0] - 48) * 100;
  i2 = (keypresses[1] - 48) * 10;
  i3 = (keypresses[2] - 48) * 1;

  tot = i1 + i2 + i3;
  if (language == 'A') {
    if (tot == code1) //if the code is correct you trigger to play .wav
    {
      playSound("ledaiLT.wav");
    }
    else if (tot == code2)
    {
      playSound("zuvisLT.wav");
    }
    else if (tot == code3)
    {
      playSound("draugLT.wav");
    }
    else //if the code is wrong you get a beep and audio message
    {
      playSound("blogasLT.wav");
    }


// Playing assigned filename
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.println(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();
  }

ard_newbie


IMO your buffer is incorrectly initialized. See how buffer is initialized in the example sketch which comes with audio library.

atlaikesbriedi

Seems that adding a bit of delay to my audio player solves this issue!
Code: [Select]
  Audio.begin(44100, 100);
    delay(200);
  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();
  delay(200);
}

Go Up