Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
266 changes: 266 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -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 <a.guadalupi@arduino.cc>
Angelo Scialabba <a.scialabba@arduino.cc>
Claudio Indellicati <c.indellicati@arduino.cc>

This example code is in the public domain

http://arduino.cc/en/Tutorial/SimpleAudioPlayerZero

*/

#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>

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 <a.guadalupi@arduino.cc>
Angelo Scialabba <a.scialabba@arduino.cc>
Claudio Indellicati <c.indellicati@arduino.cc>

This example code is in the public domain

http://arduino.cc/en/Tutorial/SimpleAudioPlayerZero

*/

#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>

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 <a.guadalupi@arduino.cc>
Angelo Scialabba <a.scialabba@arduino.cc>
Claudio Indellicati <c.indellicati@arduino.cc>

This example code is in the public domain

http://arduino.cc/en/Tutorial/SimpleAudioPlayerZero

*/

#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>

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

```

15 changes: 15 additions & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
@@ -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 <AudioZero.h>
```

## Examples

- [Simple Audio Player](https://github.com/arduino/docs.arduino.cc/blob/main/content/tutorials/generic/simple-audio-player/simple-audio-player.md)