Pages: [1]   Go Down
Author Topic: DUE audio library interupt driven?  (Read 503 times)
0 Members and 1 Guest are viewing this topic.
Michigan
Offline Offline
Newbie
*
Karma: 1
Posts: 33
IR Combat
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I tested the Audio library on the DUE last night using my micro SD card reader and a 3 watt amplifier from sparkfun.  There was a lot of static on the amplifier (unsure if it's software or hardware yet).  It does work technically, but are you able to go off and do other code while the file plays?   

The waveHC library allowed me to go do other code and still have some interupts while the file played in the background.  Any idea how this one works and if there are other libraries in the works?

Code:
void loop()
{
  int count=0;

  // open wave file from sdcard
  File myFile = SD.open("test.wav");
  if (!myFile) {
    // if the file didn't open, print an error and stop
    Serial.println("error opening test.wav");
    while (true);
  }

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

  Serial.print("Playing");
  // until the file is not finished
  while (myFile.available()) {
    // read from the file into buffer
    myFile.read(buffer, sizeof(buffer));

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

    // Every 100 block print a '.'
    count++;
    if (count == 100) {
      Serial.print(".");
      count = 0;
    }
  }
  myFile.close();

  Serial.println("End of file. Thank you for listening!");
  while (true) ;
}
Logged

IR Combat laser tag developer/inventor

Pages: [1]   Go Up
Jump to: