-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
e2e5cf3
commit 1f3a6f6
Showing
50 changed files
with
665 additions
and
304 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
Just some examples using the basic API. Though this continues to work, we recommend that you use the Stream API because it is easier to use... |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,31 @@ | ||
# Receive Sound Data from Bluetooth A2DP | ||
|
||
We receive some music via Bluetooth e.g. from your mobile phone and push it out on I2S: Something that the A2DP library does out of the box. | ||
However we just test this function here because the implementation runs via some additional buffers. The critical setting here is to make sure that the buffer for StreamCopy is big enough: we use 4100 bytes. | ||
|
||
### External DAC: | ||
|
||
For my tests I am using the 24-bit PCM5102 PCM5102A Stereo DAC Digital-to-analog Converter PLL Voice Module pHAT | ||
|
||
 | ||
|
||
I am just using the default pins defined by the framework. However I could change them with the help of the config object. The mute pin can be defined in the constructor of the I2SStream - by not defining anything we use the default which is GPIO23 | ||
|
||
|
||
| DAC | ESP32 | ||
| --------| --------------- | ||
| VDD | 5V | ||
| GND | GND | ||
| SD | OUT (GPIO22) | ||
| L/R | GND | ||
| WS | WS (GPIO15) | ||
| SCK | BCK (GPIO14) | ||
| FMT | GND | ||
| XSMT | GPIO23 | ||
|
||
|
||
- DEMP - De-emphasis control for 44.1kHz sampling rate(1): Off (Low) / On (High) | ||
- FLT - Filter select : Normal latency (Low) / Low latency (High) | ||
- SCK - System clock input (probably SCL on your board). | ||
- FMT - Audio format selection : I2S (Low) / Left justified (High) | ||
- XSMT - Soft mute control(1): Soft mute (Low) / soft un-mute (High) |
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,38 @@ | ||
/** | ||
/** | ||
* @file streams-a2dp-i2s.ino | ||
* @author Phil Schatzmann | ||
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/streams-a2dp-i2s/README.md | ||
* | ||
* @author Phil Schatzmann | ||
* @copyright GPLv3 | ||
* | ||
*/ | ||
#include "AudioTools.h" | ||
#include "AudioA2DP.h" | ||
|
||
using namespace audio_tools; | ||
|
||
A2DPStream in = A2DPStream::instance() ; // A2DP input - A2DPStream is a singleton! | ||
I2SStream out; | ||
StreamCopy copier(out, in, 4100); // copy in to out | ||
|
||
// Arduino Setup | ||
void setup(void) { | ||
Serial.begin(115200); | ||
|
||
// start the bluetooth audio receiver | ||
Serial.println("starting A2DP..."); | ||
in.begin(RX_MODE, "MyReceiver"); | ||
|
||
I2SConfig config = out.defaultConfig(TX_MODE); | ||
config.sample_rate = in.sink().sample_rate(); | ||
config.channels = 2; | ||
config.bits_per_sample = 16; | ||
out.begin(config); | ||
} | ||
|
||
// Arduino loop | ||
void loop() { | ||
copier.copy(); | ||
} |
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,3 @@ | ||
# Receive Sound Data from Bluetooth A2DP | ||
|
||
We receive some music via Bluetooth e.g. from your mobile phone and display it as CSV |
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,32 @@ | ||
/** | ||
* @file streams-a2dp-serial.ino | ||
* @author Phil Schatzmann | ||
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/streams-a2dp-serial/README.md | ||
* | ||
* @author Phil Schatzmann | ||
* @copyright GPLv3 | ||
* | ||
*/ | ||
#include "Arduino.h" | ||
#include "AudioTools.h" | ||
#include "AudioA2DP.h" | ||
|
||
using namespace audio_tools; | ||
|
||
A2DPStream in = A2DPStream::instance() ; // A2DP input - A2DPStream is a singleton! | ||
CsvStream<int16_t> out(Serial, 2); // ASCII stream as csv | ||
StreamCopy copier(out, in); // copy in to out | ||
|
||
// Arduino Setup | ||
void setup(void) { | ||
Serial.begin(115200); | ||
|
||
// start the bluetooth audio receiver | ||
Serial.println("starting A2DP..."); | ||
in.begin(RX_MODE, "MyReceiver"); | ||
} | ||
|
||
// Arduino loop | ||
void loop() { | ||
copier.copy(); | ||
} |
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,7 @@ | ||
# Digital output via I2S to a external DAC | ||
|
||
Sometimes it is quite useful to be able to generate a test tone. | ||
We can use the GeneratedSoundStream class together with a SoundGenerator class. In my example I use a SineWaveGenerator. | ||
|
||
To test the I2S output I'm using this generated signal and write it to A2DP (e.g. a Bluetooth Speaker). | ||
|
41 changes: 41 additions & 0 deletions
41
examples/streams-generator-a2dp/streams-generator-a2dp.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,41 @@ | ||
/** | ||
* @file streams-generator-a2dp.ino | ||
* @author Phil Schatzmann | ||
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/streams-generator-a2dp/README.md | ||
* | ||
* @author Phil Schatzmann | ||
* @copyright GPLv3 | ||
* | ||
*/ | ||
#include "AudioTools.h" | ||
#include "AudioA2DP.h" | ||
|
||
using namespace audio_tools; | ||
|
||
typedef int16_t sound_t; // sound will be represented as int16_t (with 2 bytes) | ||
uint16_t sample_rate=44100; | ||
uint8_t channels = 2; // The stream will have 2 channels | ||
SineWaveGenerator<sound_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000 | ||
GeneratedSoundStream<sound_t> in(sineWave, channels); // Stream generated from sine wave | ||
A2DPStream out = A2DPStream::instance() ; // A2DP input - A2DPStream is a singleton! | ||
StreamCopy copier(out, in); // copy in to out | ||
|
||
// Arduino Setup | ||
void setup(void) { | ||
Serial.begin(115200); | ||
|
||
// We send the test signal via A2DP - so we conect to the MyMusic Bluetooth Speaker | ||
out.begin(TX_MODE, "MyMusic"); | ||
|
||
Serial.println("A2DP is connected now..."); | ||
|
||
// Setup sine wave | ||
sineWave.begin(sample_rate, B4); | ||
|
||
} | ||
|
||
// Arduino loop | ||
void loop() { | ||
if (out) | ||
copier.copy(); | ||
} |
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,25 @@ | ||
# I2S Analog Output Test | ||
|
||
This is a simple basic test for the ESP32 __analog output__ using I2S. | ||
|
||
We just send a generated sine wave and expect to hear a clean signal. | ||
Please note the log level should be set so that there is no disturbing output! | ||
|
||
|
||
### Output Device: Piezo Electric Element | ||
|
||
To test the output I am using a piezo electric element | ||
|
||
 | ||
|
||
It should also be possible to connect a headphone to the output pins... | ||
|
||
|
||
On the ESP32 the output is on the Pins GPIO26 and GPIO27 | ||
|
||
| PIEZO | ESP32 | ||
| --------| --------------- | ||
| + | GPIO25 / GPIO26 | ||
| - | GND | ||
|
||
|
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 @@ | ||
/** | ||
* @file streams-generator-dac.ino | ||
* @author Phil Schatzmann | ||
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/streams-generator-dac/README.md | ||
* @author Phil Schatzmann | ||
* @copyright GPLv3 | ||
**/ | ||
|
||
#include "AudioTools.h" | ||
#include "AudioA2DP.h" | ||
|
||
using namespace audio_tools; | ||
|
||
typedef int16_t sound_t; // sound will be represented as int16_t (with 2 bytes) | ||
uint16_t sample_rate=44100; | ||
uint8_t channels = 2; // The stream will have 2 channels | ||
SineWaveGenerator<sound_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000 | ||
GeneratedSoundStream<sound_t> sound(sineWave, channels); // Stream generated from sine wave | ||
AnalogAudioStream out; | ||
StreamCopy copier(out, sound); // copies sound into i2s | ||
|
||
// Arduino Setup | ||
void setup(void) { | ||
// Open Serial | ||
Serial.begin(115200); | ||
|
||
// start the bluetooth | ||
Serial.println("starting A2DP..."); | ||
AnalogConfig config = out.defaultConfig(TX_MODE); | ||
config.sample_rate = sample_rate; | ||
out.begin(config); | ||
|
||
// Setup sine wave | ||
sineWave.begin(sample_rate, B4); | ||
} | ||
|
||
// Arduino loop - copy sound to out | ||
void loop() { | ||
copier.copy(); | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,31 @@ | ||
/** | ||
* @file streams-a2dp-serial.ino | ||
* @author Phil Schatzmann | ||
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/streams-a2dp-serial/README.md | ||
* | ||
* @author Phil Schatzmann | ||
* @copyright GPLv3 | ||
* | ||
*/ | ||
#include "AudioTools.h" | ||
#include "AudioA2DP.h" | ||
|
||
using namespace audio_tools; | ||
|
||
A2DPStream in = A2DPStream::instance() ; // A2DP input - A2DPStream is a singleton! | ||
CsvStream<int16_t> out(Serial, 2); // ASCII stream as csv | ||
StreamCopy copier(out, in); // copy in to out | ||
|
||
// Arduino Setup | ||
void setup(void) { | ||
Serial.begin(115200); | ||
|
||
// start the bluetooth audio receiver | ||
Serial.println("starting A2DP..."); | ||
in.begin(RX_MODE, "MyReceiver"); | ||
} | ||
|
||
// Arduino loop | ||
void loop() { | ||
copier.copy(); | ||
} |
Oops, something went wrong.