Skip to content

Commit dc13e1e

Browse files
committed
file example
1 parent 69b3561 commit dc13e1e

File tree

7 files changed

+32
-21
lines changed

7 files changed

+32
-21
lines changed

.DS_Store

0 Bytes
Binary file not shown.

docs/.DS_Store

6 KB
Binary file not shown.

examples/file_raw-a2dp/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ The SD module is connected with the help of the SPI bus
1010

1111
### Pins:
1212

13-
We use SPI2 (HSPI):
13+
We connect the SD to the ESP32:
1414

15-
| MCP6022 | ESP32
15+
| SD | ESP32
1616
|---------|---------------
1717
| VCC | 5V
1818
| GND | GND
19-
| CS | CS GP15
20-
| SCK | SCK GP14
21-
| MOSI | MOSI GP13
22-
| MISO | MISO GP12
19+
| CS | CS GP5
20+
| SCK | SCK GP18
21+
| MOSI | MOSI GP23
22+
| MISO | MISO GP19
23+
2324

2425

examples/file_raw-a2dp/file_raw-a2dp.ino

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55

66
BluetoothA2DPSource a2dp_source;
77
File sound_file;
8-
const char* file_name = "audio.raw";
9-
const int sd_ss_pin = 4;
8+
const char* file_name = "/audio.raw";
9+
const int sd_ss_pin = 5;
10+
const int frame_size_bytes = sizeof(int16_t) * 2;
11+
1012

1113
// callback used by A2DP to provide the sound data
1214
int32_t get_sound_data(Channels* data, int32_t len) {
1315
// the data in the file must be in int16 with 2 channels
14-
return sound_file.read((uint8_t*)data, len * sizeof(int16_t) * 2 );
16+
size_t result_len_bytes = sound_file.read((uint8_t*)data, len * frame_size_bytes );
17+
// result is in number of frames
18+
int32_t result_len = result_len_bytes / frame_size_bytes;
19+
ESP_LOGD("get_sound_data", "%d -> %d",len );
20+
return result_len;
1521
}
1622

1723
// Arduino Setup

examples/file_raw-serial/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ The SD module is connected with the help of the SPI bus
1010

1111
### Pins:
1212

13-
We use SPI2 (HSPI):
13+
We connect the SD to the ESP32:
1414

15-
| MCP6022 | ESP32
15+
| SD | ESP32
1616
|---------|---------------
1717
| VCC | 5V
1818
| GND | GND
19-
| CS | CS GP15
20-
| SCK | SCK GP14
21-
| MOSI | MOSI GP13
22-
| MISO | MISO GP12
19+
| CS | CS GP5
20+
| SCK | SCK GP18
21+
| MOSI | MOSI GP23
22+
| MISO | MISO GP19
2323

2424

examples/file_raw-serial/file_raw-serial.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <SD.h>
44

55
File sound_file;
6-
const char* file_name = "audio.raw";
7-
const int sd_ss_pin = 4;
6+
const char* file_name = "/audio.raw";
7+
const int sd_ss_pin = 5;
88
const int32_t max_buffer_len = 512;
99
int32_t buffer[max_buffer_len][2];
1010

examples/i2s-a2dp/i2s-a2dp.ino

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@ using namespace sound_tools;
1212
BluetoothA2DPSource a2dp_source;
1313
I2S<int32_t> i2s;
1414
ChannelConverter<int32_t> converter(&convertFrom32To16);
15-
const size_t max_buffer_len = 512;
15+
FilterFillLeftAndRight<int32_t> bothChannels;
16+
const size_t max_buffer_len = 1024;
1617
int32_t buffer[max_buffer_len][2];
1718

1819
// callback used by A2DP to provide the sound data
1920
int32_t get_sound_data(Channels* data, int32_t len) {
2021
size_t req_len = min(max_buffer_len,(size_t) len);
2122

2223
// the microphone provides data in int32_t -> we read it into the buffer of int32_t data
23-
size_t result = i2s.read(buffer, req_len);
24+
size_t result_len = i2s.read(buffer, req_len);
25+
26+
// we have data only in 1 channel but we want to fill both
27+
bothChannels.process(buffer, result_len);
2428

2529
// convert buffer to int16 for A2DP
26-
converter.convert(buffer, data, len);
27-
return result;
30+
converter.convert(buffer, data, result_len);
31+
return result_len;
2832
}
2933

3034
// Arduino Setup

0 commit comments

Comments
 (0)