Skip to content

Commit 9c9f4fe

Browse files
committed
A2DP examples
1 parent 87fb313 commit 9c9f4fe

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed

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

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

37-
// open decoder
37+
// make sure we have enough space for the pcm data
38+
decoder.transformationReader().resizeResultQueue(1024 * 8)
3839
if (!decoder.begin()) {
3940
Serial.println("decoder failed");
4041
stop();

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

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,65 @@
22
* @file basic-player-a2dp.ino
33
* @author Phil Schatzmann
44
* @brief Sketch which uses the A2DP callback to provide data from the AudioPlayer via a Queue
5-
*
5+
* The queue is filled by the Arduino loop.
66
* @version 0.1
77
* @date 2022-12-04
88
*
99
* @copyright Copyright (c) 2022
1010
*
1111
*/
1212

13-
#include "AudioTools.h"
14-
#include "AudioTools/AudioLibs/A2DPStream.h"
15-
#include "AudioTools/Disk/AudioSourceSDFAT.h"
16-
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
17-
#include "AudioTools/AudioLibs/AudioBoardStream.h" // for SD Pins
18-
19-
int buffer_count = 30;
20-
int buffer_size = 512;
21-
const char *startFilePath="/";
22-
const char* ext="mp3";
23-
AudioSourceSDFAT source(startFilePath, ext, PIN_AUDIO_KIT_SD_CARD_CS);
24-
MP3DecoderHelix decoder;
25-
//Setup of synchronized buffer
26-
SynchronizedNBuffer buffer(buffer_size,buffer_count, portMAX_DELAY, 10);
27-
QueueStream<uint8_t> out(buffer); // convert Buffer to Stream
28-
AudioPlayer player(source, out, decoder);
29-
BluetoothA2DPSource a2dp;
30-
31-
// Provide data to A2DP
32-
int32_t get_data(uint8_t *data, int32_t bytes) {
13+
#include "AudioTools.h"
14+
#include "AudioTools/AudioLibs/A2DPStream.h"
15+
#include "AudioTools/Disk/AudioSourceSDFAT.h"
16+
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
17+
//#include "AudioTools/AudioLibs/AudioBoardStream.h" // for SD Pins
18+
19+
const int cs = 33; //PIN_AUDIO_KIT_SD_CARD_CS;
20+
const int buffer_size = 15*1024;
21+
const char *startFilePath = "/";
22+
const char *ext = "mp3";
23+
AudioSourceSDFAT source(startFilePath, ext, cs);
24+
MP3DecoderHelix decoder;
25+
//Setup of synchronized buffer
26+
BufferRTOS<uint8_t> buffer(0);
27+
QueueStream<uint8_t> out(buffer); // convert Buffer to Stream
28+
AudioPlayer player(source, out, decoder);
29+
BluetoothA2DPSource a2dp;
30+
31+
// Provide data to A2DP
32+
int32_t get_data(uint8_t *data, int32_t bytes) {
3333
size_t result_bytes = buffer.readArray(data, bytes);
3434
//LOGI("get_data_channels %d -> %d of (%d)", bytes, result_bytes , buffer.available());
3535
return result_bytes;
36-
}
37-
38-
void setup() {
39-
Serial.begin(115200);
40-
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning);
41-
42-
// sd_active is setting up SPI with the right SD pins by calling
43-
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);
44-
45-
// start QueueStream
46-
out.begin();
47-
48-
// setup player
49-
player.setDelayIfOutputFull(0);
50-
player.setVolume(0.1);
51-
player.begin();
36+
}
5237

53-
// fill buffer with some data
54-
player.getStreamCopy().copyN(5);
55-
56-
// start a2dp source
57-
Serial.println("starting A2DP...");
58-
a2dp.set_data_callback(get_data);
59-
a2dp.start("LEXON MINO L");
60-
Serial.println("Started!");
61-
62-
}
63-
64-
void loop() {
65-
// decode data to buffer
66-
player.copy();
67-
}
38+
void setup() {
39+
Serial.begin(115200);
40+
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
41+
42+
// allocate in PSRAM only possible in setup or loop
43+
buffer.resize(buffer_size);
44+
45+
// sd_active is setting up SPI with the right SD pins by calling
46+
// 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);
47+
48+
// start QueueStream when 95% full
49+
out.begin(95);
50+
51+
// setup player
52+
player.setDelayIfOutputFull(0);
53+
player.setVolume(0.1);
54+
player.begin();
55+
56+
// start a2dp source
57+
Serial.println("starting A2DP...");
58+
a2dp.set_data_callback(get_data);
59+
a2dp.start("LEXON MINO L");
60+
Serial.println("Started!");
61+
}
62+
63+
void loop() {
64+
// decode data to buffer
65+
player.copy();
66+
}

0 commit comments

Comments
 (0)