diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..b863520 --- /dev/null +++ b/docs/api.md @@ -0,0 +1,266 @@ +# AudioZero + +## Functions + +### `begin()` + +#### Description +Initializes the AudioZero library by specifying the target sample rate. + +#### Syntax + +``` +AudioZero.begin(rate); +``` + +#### Parameters +rate (int) : the sample rate of the sound file. + +#### Returns +nothing + +#### Example + +``` +/* + Simple Audio Player for Arduino Zero + + Demonstrates the use of the Audio library for the Arduino Zero + + Hardware required : + * Arduino shield with a SD card on CS4 + * A sound file named "test.wav" in the root directory of the SD card + * An audio amplifier to connect to the DAC0 and ground + * A speaker to connect to the audio amplifier + + + Arturo Guadalupi + Angelo Scialabba + Claudio Indellicati + + This example code is in the public domain + + http://arduino.cc/en/Tutorial/SimpleAudioPlayerZero + +*/ + +#include +#include +#include + +void setup() +{ + // debug output at 115200 baud + Serial.begin(115200); + + // setup SD-card + Serial.print("Initializing SD card..."); + if (!SD.begin(4)) { + Serial.println(" failed!"); + return; + } + Serial.println(" done."); + // hi-speed SPI transfers + SPI.setClockDivider(4); + + // 88200 sample rate + AudioZero.begin(88200); +} + +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); + } + + Serial.print("Playing"); + + // until the file is not finished + AudioZero.play(myFile); + AudioZero.end(); + + Serial.println("End of file. Thank you for listening!"); + while (true) ; +} + +``` + +### `play()` + +#### Description +Writes an audio signal read from the SD card to DAC0. + +#### Syntax + +``` +AudioZero.play(); +``` + +#### Returns +nothing + +#### Example + +``` +/* + Simple Audio Player for Arduino Zero + + Demonstrates the use of the Audio library for the Arduino Zero + + Hardware required : + * Arduino shield with a SD card on CS4 + * A sound file named "test.wav" in the root directory of the SD card + * An audio amplifier to connect to the DAC0 and ground + * A speaker to connect to the audio amplifier + + + Arturo Guadalupi + Angelo Scialabba + Claudio Indellicati + + This example code is in the public domain + + http://arduino.cc/en/Tutorial/SimpleAudioPlayerZero + +*/ + +#include +#include +#include + +void setup() +{ + // debug output at 115200 baud + Serial.begin(115200); + + // setup SD-card + Serial.print("Initializing SD card..."); + if (!SD.begin(4)) { + Serial.println(" failed!"); + return; + } + Serial.println(" done."); + // hi-speed SPI transfers + SPI.setClockDivider(4); + + // 88200 sample rate + AudioZero.begin(88200); +} + +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); + } + + Serial.print("Playing"); + + // until the file is not finished + AudioZero.play(myFile); + AudioZero.end(); + + Serial.println("End of file. Thank you for listening!"); + while (true) ; +} + +``` + +### `end()` + +#### Description + +Stops the timer used to write an audio signal read from the SD card to DAC0 and writes 0. + +#### Syntax + +``` +AudioZero.end(); +``` + +#### Returns +nothing + +#### Example + +``` +/* + Simple Audio Player for Arduino Zero + + Demonstrates the use of the Audio library for the Arduino Zero + + Hardware required : + * Arduino shield with a SD card on CS4 + * A sound file named "test.wav" in the root directory of the SD card + * An audio amplifier to connect to the DAC0 and ground + * A speaker to connect to the audio amplifier + + + Arturo Guadalupi + Angelo Scialabba + Claudio Indellicati + + This example code is in the public domain + + http://arduino.cc/en/Tutorial/SimpleAudioPlayerZero + +*/ + +#include +#include +#include + +void setup() +{ + // debug output at 115200 baud + Serial.begin(115200); + + // setup SD-card + Serial.print("Initializing SD card..."); + if (!SD.begin(4)) { + Serial.println(" failed!"); + return; + } + Serial.println(" done."); + // hi-speed SPI transfers + SPI.setClockDivider(4); + + // 88200 sample rate + AudioZero.begin(88200); +} + +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); + } + + Serial.print("Playing"); + + // until the file is not finished + AudioZero.play(myFile); + AudioZero.end(); + + Serial.println("End of file. Thank you for listening!"); + while (true) ; +} + +``` + diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..000f44f --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,15 @@ +# AudioZero + +The Audio library enables an Arduino an Arduino based on SAMD architectures (all MKR boards, Nano 33 IoT and more) to play back **.wav** files from a storage device like an SD card. + +The Zero and the MKR1000 use the DAC0 pin to play sounds. + +To use this library + +``` +#include +``` + +## Examples + +- [Simple Audio Player](https://github.com/arduino/docs.arduino.cc/blob/main/content/tutorials/generic/simple-audio-player/simple-audio-player.md) \ No newline at end of file