Skip to content

Commit dfb4b29

Browse files
committed
Resample
1 parent 9a2ec94 commit dfb4b29

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,16 @@
66
* @copyright GPLv3
77
*/
88

9-
/**
10-
* @file basic-a2dp-audioi2s.ino
11-
* @brief A2DP Sink with output to SPDIFStream
12-
*
13-
* @author Phil Schatzmann
14-
* @copyright GPLv3
15-
*/
16-
179
#define USE_A2DP
1810
#include "AudioConfigLocal.h"
1911
#include "AudioTools.h"
20-
#include "AudioExperiments/Resample.h"
2112

2213
BluetoothA2DPSink a2dp_sink;
2314
I2SStream i2s;
24-
Resample<int16_t> out(i2s, 2, 2);
2515

2616
// Write data to SPDIF in callback
2717
void read_data_stream(const uint8_t *data, uint32_t length) {
28-
out.write(data, length);
18+
i2s.write(data, length);
2919
}
3020

3121
void setup() {
@@ -42,7 +32,7 @@ void setup() {
4232
// setup output
4333
auto cfg = i2s.defaultConfig();
4434
cfg.pin_data = 23;
45-
cfg.sample_rate = a2dp_sink.sample_rate()*2;
35+
cfg.sample_rate = a2dp_sink.sample_rate();
4636
cfg.channels = 2;
4737
cfg.bits_per_sample = 16;
4838
i2s.begin(cfg);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
#define I2S_BUFFER_COUNT 8
4+
#define I2S_BUFFER_SIZE 256
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* @file basic-a2dp-audioi2s.ino
3+
* @brief A2DP Sink with output to respampled I2S
4+
*
5+
* @author Phil Schatzmann
6+
* @copyright GPLv3
7+
*/
8+
9+
#define USE_A2DP
10+
#include "AudioConfigLocal.h"
11+
#include "AudioTools.h"
12+
#include "AudioExperiments/Resample.h"
13+
14+
BluetoothA2DPSink a2dp_sink;
15+
I2SStream i2s;
16+
Resample<int16_t> out(i2s, 2, 2);
17+
18+
// Write data to SPDIF in callback
19+
void read_data_stream(const uint8_t *data, uint32_t length) {
20+
out.write(data, length);
21+
}
22+
23+
void setup() {
24+
Serial.begin(115200);
25+
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
26+
27+
// register callback
28+
a2dp_sink.set_stream_reader(read_data_stream, false);
29+
30+
// Start Bluetooth Audio Receiver
31+
a2dp_sink.set_auto_reconnect(false);
32+
a2dp_sink.start("a2dp-i2s");
33+
34+
// setup output
35+
auto cfg = i2s.defaultConfig();
36+
cfg.pin_data = 23;
37+
cfg.sample_rate = a2dp_sink.sample_rate()*2;
38+
cfg.channels = 2;
39+
cfg.bits_per_sample = 16;
40+
i2s.begin(cfg);
41+
42+
}
43+
44+
void loop() {
45+
delay(100);
46+
}

0 commit comments

Comments
 (0)