Pages: [1]   Go Down
Author Topic: Arduino Due Audio Library and Performing Other Tasks During Playback  (Read 666 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Has anyone been able to modify the Simple Audio Player sketch so that playback can happen without pausing other operations in the loop code for the Due board?  I'm not sure whether it's the buffer that's causing the pause or the Audio.write command, but I added a blinking light line of code in and when I press the button I've assigned to play my audio file, the light completely stops until the audio is done playing.  I'm hoping there is a way to perform an audio playback on both DACs as well as run the regular loop code simultaneously.  Shouldn't be too hard since it's pushing analog signals from a buffer, but I'm lost... Here's my test code.

Code:
#include <SD.h>
#include <SPI.h>
#include <Audio.h>

unsigned long previousMillis = 0;
boolean ledstate = true;

void setup()
{
pinMode(5,OUTPUT); //this is the LED output
digitalWrite(5,ledstate);
pinMode(7,INPUT); //this is the button input, I just run a 10k resistor to GND to activate the sound
digitalWrite(7,HIGH); //internal pullup to apply a high voltage to the pin so we can pull it low to activate

  SPI.setClockDivider(4);
  Audio.begin(12800, 100); //my wav file was recorded at a slower bit rate
}

void loop()
{
  //flashing the LED every 250 milliseconds
  unsigned long currentMillis = millis();
   if(currentMillis-previousMillis > 250){
   previousMillis = currentMillis;
   if (ledstate == LOW){
     ledstate = HIGH;
   }
   else
   {
ledstate = LOW;
   }
   digitalWrite(5,ledstate);
 }

if(digitalRead(7) == LOW){
  // open wave file from sdcard
  File myFile = SD.open("talking.wav");

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

  // 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);

  }
  myFile.close();
}
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Another thing I will note is that the first playback of the audio sounds good, but playing the audio after that sounds very scratchy for some reason... I have absolutely no clue why unless i should clear my buffer or something...
Logged

Pages: [1]   Go Up
Jump to: