Skip to content

Commit 7818061

Browse files
committed
vs1053 midi-file
1 parent f4f46ec commit 7818061

File tree

5 files changed

+3952
-4277
lines changed

5 files changed

+3952
-4277
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @file basic-a2dp-audiovs1053.ino
3+
* @brief A2DP Sink with output to vs1053. The vs1053 expects encoded data so we encode the stream
4+
* to a WAV file
5+
*
6+
* @author Phil Schatzmann
7+
* @copyright GPLv3
8+
*/
9+
10+
// install https://github.com/pschatzmann/arduino-vs1053.git
11+
12+
#include "AudioTools.h"
13+
#include "AudioLibs/VS1053Stream.h"
14+
#include "BluetoothA2DPSink.h"
15+
16+
BluetoothA2DPSink a2dp_sink;
17+
VS1053Stream out; // final output
18+
bool active = false;
19+
// Write data to SPDIF in callback
20+
void read_data_stream(const uint8_t *data, uint32_t length) {
21+
if (active) out.write(data, length);
22+
}
23+
24+
// for esp_a2d_audio_state_t see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/bluetooth/esp_a2dp.html#_CPPv421esp_a2d_audio_state_t
25+
void audio_state_changed(esp_a2d_audio_state_t state, void *ptr){
26+
Serial.println(a2dp_sink.to_str(state));
27+
switch(state){
28+
case ESP_A2D_AUDIO_STATE_STARTED:
29+
out.begin();
30+
active = true;
31+
break;
32+
case ESP_A2D_AUDIO_STATE_STOPPED:
33+
case ESP_A2D_AUDIO_STATE_REMOTE_SUSPEND:
34+
active = false;
35+
out.end();
36+
break;
37+
}
38+
}
39+
40+
41+
void setup() {
42+
Serial.begin(115200);
43+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
44+
45+
// register callbacks
46+
a2dp_sink.set_stream_reader(read_data_stream, false);
47+
a2dp_sink.set_on_audio_state_changed(audio_state_changed);
48+
49+
// Start Bluetooth Audio Receiver
50+
a2dp_sink.set_auto_reconnect(false);
51+
a2dp_sink.start("a2dp-vs1053");
52+
53+
// setup VS1053
54+
auto cfg = out.defaultConfig();
55+
cfg.sample_rate = a2dp_sink.sample_rate();
56+
cfg.channels = 2;
57+
cfg.bits_per_sample = 16;
58+
// Use your custom pins or define in AudioCodnfig.h
59+
//cfg.cs_pin = VS1053_CS;
60+
//cfg.dcs_pin = VS1053_DCS;
61+
//cfg.dreq_pin = VS1053_DREQ;
62+
//cfg.reset_pin = VS1053_RESET;
63+
64+
out.begin(cfg);
65+
out.end();
66+
}
67+
68+
void loop() { delay(1000); }

0 commit comments

Comments
 (0)