Prepares audio samples from the named file to the audio buffer, and sets the volume.
Audio.prepare(buffer, samples, volume);
- buffer (short) : the named buffer holding the audio file.
- samples (int) : number of samples to write
- volume (int) : a 10-bit number representing the volume of the audio being played. 0 turns the sound off, 1023 is the maximum volume.
/* Demonstrates the use of the Audio library for the Arduino Due Hardware required : *Arduino shield with a SD card on CS 4 (the Ethernet sheild will work) *Audio amplifier circuit with speaker attached to DAC0 Original by Massimo Banzi September 20, 2012 Modified by Scott Fitzgerald October 19, 2012 */
// debug output at 9600 baud
// setup SD-card
Serial.print("Initializing SD card...");
// hi-speed SPI transfers
// 44100Khz stereo => 88200 sample rate
// 100 mSec of prebuffering.
// open wave file from sdcard
File myFile = SD.open("test.wav");
// if the file didn't open, print an error and stop
Serial.println("error opening test.wav");
const int S=1024;// Number of samples to read in block
// until the file is not finished
// read from the file into buffer
// Prepare samples
int volume =1024;
Audio.prepare(buffer, S, volume);
// Feed samples to audio
// Every 100 block print a '.'
Serial.println("End of file. Thank you for listening!");