-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bcef45b
commit b3891a8
Showing
11 changed files
with
233 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Stream SD File to I2S external DAC | ||
|
||
We are reading a raw audio file from the SD card and write the data to the I2S interface. The audio file must be available using 16 bit integers with 2 channels. | ||
|
||
[Audacity](https://www.audacityteam.org/) might help you out here: export with the file name audio.raw as RAW signed 16 bit PCM and copy it to the SD card. In my example I was using the file [audio.raw](https://pschatzmann.github.io/arduino-audio-tools/resources/audio.raw). | ||
|
||
### SD Pins: | ||
|
||
The SD module is connected with the help of the SPI bus | ||
|
||
![sd](https://pschatzmann.github.io/arduino-audio-tools/resources/sd-module.jpeg) | ||
|
||
We connect the SD to the ESP32: | ||
|
||
| SD | ESP32 | ||
|---------|--------------- | ||
| VCC | 5V | ||
| GND | GND | ||
| CS | CS GP5 | ||
| SCK | SCK GP18 | ||
| MOSI | MOSI GP23 | ||
| MISO | MISO GP19 | ||
|
||
|
||
### External DAC: | ||
|
||
| DAC | ESP32 | ||
| --------| --------------- | ||
| VDD | 5V | ||
| GND | GND | ||
| SD | OUT (GPIO22) | ||
| L/R | GND | ||
| WS | WS (GPIO15) | ||
| SCK | BCK (GPIO14) | ||
|
||
|
||
|
||
|
||
|
||
|
46 changes: 46 additions & 0 deletions
46
sandbox/file_raw-I2S_external_dac/file_raw-I2S_external_dac.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @file file_raw-external_dac.ino | ||
* @author Phil Schatzmann | ||
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/file_raw-external_dac/README.md | ||
* | ||
* @author Phil Schatzmann | ||
* @copyright GPLv3 | ||
*/ | ||
|
||
#include "AudioTools.h" | ||
#include <SPI.h> | ||
#include <SD.h> | ||
|
||
using namespace audio_tools; | ||
|
||
File sound_file; | ||
I2S<int16_t> i2s; | ||
I2SStream i2s_stream(i2s); | ||
StreamCopy streamCopy(i2s_stream, sound_file, 1024); | ||
const char* file_name = "/audio.raw"; | ||
const int sd_ss_pin = 5; | ||
|
||
|
||
// Arduino Setup | ||
void setup(void) { | ||
Serial.begin(115200); | ||
|
||
// Setup SD and open file | ||
SD.begin(sd_ss_pin); | ||
sound_file = SD.open(file_name, FILE_READ); | ||
|
||
// start I2S with external DAC | ||
Serial.println("starting I2S..."); | ||
i2s.begin(i2s.defaultConfig(TX_MODE)); | ||
} | ||
|
||
// Arduino loop - repeated processing | ||
void loop() { | ||
if (streamCopy.copy()){ | ||
Serial.print("."); | ||
} else { | ||
Serial.println(); | ||
Serial.println("Copy ended"); | ||
delay(10000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Stream SD File to I2S internal DAC | ||
|
||
We are reading a raw audio file from the SD card and write the data to the analog pins of the ESP32 using the I2S interface. The audio file must be available using 16 bit integers with 2 channels. | ||
|
||
[Audacity](https://www.audacityteam.org/) might help you out here: export with the file name audio.raw as RAW signed 16 bit PCM and copy it to the SD card. In my example I was using the file [audio.raw](https://pschatzmann.github.io/arduino-audio-tools/resources/audio.raw). | ||
|
||
### SD Pins: | ||
|
||
The SD module is connected with the help of the SPI bus | ||
|
||
![sd](https://pschatzmann.github.io/arduino-audio-tools/resources/sd-module.jpeg) | ||
|
||
We connect the SD to the ESP32: | ||
|
||
| SD | ESP32 | ||
|---------|--------------- | ||
| VCC | 5V | ||
| GND | GND | ||
| CS | CS GP5 | ||
| SCK | SCK GP18 | ||
| MOSI | MOSI GP23 | ||
| MISO | MISO GP19 | ||
|
||
|
||
### Amplifier Pins: | ||
|
||
To hear the sound we connect the ESP32 to an amplifier module: The analog output is available on GPIO25 & GPIO26. You could also use some earphones. | ||
|
||
|
||
| Amp | ESP32 | ||
|---------|--------------- | ||
| + | 5V | ||
| - | GND | ||
| L | GPIO25 | ||
| R | GPIO26 | ||
| T | GND | ||
|
||
|
||
|
||
|
||
|
48 changes: 48 additions & 0 deletions
48
sandbox/file_raw-I2S_internal_dac/file_raw-I2S_internal_dac.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @file file_raw-internal_dac.ino | ||
* @author Phil Schatzmann | ||
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/file_raw-internal_dac/README.md | ||
* | ||
* @author Phil Schatzmann | ||
* @copyright GPLv3 | ||
*/ | ||
|
||
#include "AudioTools.h" | ||
#include <SPI.h> | ||
#include <SD.h> | ||
|
||
using namespace audio_tools; | ||
|
||
File sound_file; | ||
I2S<int16_t> i2s; | ||
I2SStream i2s_stream(i2s); | ||
StreamCopy streamCopy(i2s_stream, sound_file, 1024); | ||
const char* file_name = "/audio.raw"; | ||
const int sd_ss_pin = 5; | ||
|
||
|
||
// Arduino Setup | ||
void setup(void) { | ||
Serial.begin(115200); | ||
|
||
// Setup SD and open file | ||
SD.begin(sd_ss_pin); | ||
sound_file = SD.open(file_name, FILE_READ); | ||
|
||
// start I2S with internal DAC -> GPIO25 & GPIO26 | ||
Serial.println("starting I2S..."); | ||
I2SConfig<int16_t> config = i2s.defaultConfig(TX_MODE); | ||
config.i2s.mode = static_cast<i2s_mode_t>( I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN); | ||
i2s.begin(config); | ||
} | ||
|
||
// Arduino loop - repeated processing | ||
void loop() { | ||
if (streamCopy.copy()){ | ||
Serial.print("."); | ||
} else { | ||
Serial.println(); | ||
Serial.println("Copy ended"); | ||
delay(10000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters