Skip to content

Commit 519d1ff

Browse files
committed
A2DP examples
1 parent d4b14b5 commit 519d1ff

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

examples/examples-communication/a2dp/basic-adc-a2dp/basic-adc-a2dp.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ void setup(void) {
3737
// start the bluetooth
3838
Serial.println("starting A2DP...");
3939
a2dp_source.set_auto_reconnect(false);
40-
a2dp_source.start("MyMusic", get_sound_data);
40+
a2dp_source.set_data_callback_in_frames(get_sound_data);
41+
a2dp_source.start("MyMusic");
4142
}
4243

4344
// Arduino loop - repeated processing

examples/examples-communication/a2dp/basic-audiokit-a2dp/basic-audiokit-a2dp.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ void setup(void) {
3434

3535
// start the bluetooth
3636
Serial.println("starting A2DP...");
37-
a2dp_source.start("LEXON MINO L", get_sound_data);
37+
a2dp_source.set_data_callback_in_frames(get_sound_data);
38+
a2dp_source.start("LEXON MINO L");
3839
}
3940

4041
// Arduino loop - repeated processing
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Experiment: We use the decoding on the input side to provid pcm data
2+
// Conclusion: the lag is too big!
3+
4+
#include "SPI.h"
5+
#include "SD.h"
6+
#include "AudioTools.h"
7+
#include "AudioTools/AudioLibs/A2DPStream.h"
8+
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
9+
//#include "AudioTools/AudioLibs/AudioBoardStream.h" // for SPI pins
10+
11+
File file;
12+
MP3DecoderHelix mp3; // or change to MP3DecoderMAD
13+
EncodedAudioStream decoder(&file, &mp3);
14+
BluetoothA2DPSource a2dp_source;
15+
const int chipSelect = SS //PIN_AUDIO_KIT_SD_CARD_CS;
16+
17+
// callback used by A2DP to provide the sound data - usually len is 128 2 channel int16 frames
18+
int32_t get_sound_data(uint8_t* data, int32_t size) {
19+
int32_t result = decoder.readBytes((uint8_t*)data, size);
20+
delay(1); // feed the dog
21+
return result;
22+
}
23+
24+
// Arduino Setup
25+
void setup(void) {
26+
Serial.begin(115200);
27+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
28+
29+
// open file
30+
//SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
31+
SD.begin(chipSelect);
32+
file = SD.open("/test.mp3", FILE_READ);
33+
if (!file) {
34+
Serial.println("file failed");
35+
stop();
36+
}
37+
38+
// open decoder
39+
if (!decoder.begin()) {
40+
Serial.println("decoder failed");
41+
stop();
42+
}
43+
44+
// start the bluetooth
45+
Serial.println("starting A2DP...");
46+
a2dp_source.set_data_callback(get_sound_data);
47+
a2dp_source.start("LEXON MINO L");
48+
}
49+
50+
// Arduino loop - repeated processing
51+
void loop() {
52+
delay(1000);
53+
}

examples/examples-communication/a2dp/basic-i2s-a2dp/basic-i2s-a2dp.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ void setup(void) {
4141
// start the bluetooth
4242
Serial.println("starting A2DP...");
4343
// a2dp_source.set_auto_reconnect(false);
44-
a2dp_source.start("LEXON MINO L", get_sound_data);
44+
a2dp_source.set_data_callback_in_frames(get_sound_data);
45+
a2dp_source.start("LEXON MINO L");
4546

4647
Serial.println("A2DP started");
4748
}

examples/examples-communication/a2dp/streams-synth-a2dp/streams-synth-a2dp.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ void setup() {
4141
cfg.sample_rate = 44100;
4242
in.begin(cfg);
4343

44-
a2dp_source.start("LEXON MINO L", get_sound_data);
44+
a2dp_source.set_data_callback_in_frames(get_sound_data);
45+
a2dp_source.start("LEXON MINO L");
4546
a2dp_source.set_volume(20);
4647
}
4748

0 commit comments

Comments
 (0)