File tree Expand file tree Collapse file tree 7 files changed +32
-21
lines changed Expand file tree Collapse file tree 7 files changed +32
-21
lines changed Original file line number Diff line number Diff line change @@ -10,15 +10,16 @@ The SD module is connected with the help of the SPI bus
10
10
11
11
### Pins:
12
12
13
- We use SPI2 (HSPI) :
13
+ We connect the SD to the ESP32 :
14
14
15
- | MCP6022 | ESP32
15
+ | SD | ESP32
16
16
|---------|---------------
17
17
| VCC | 5V
18
18
| 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
+
23
24
24
25
Original file line number Diff line number Diff line change 5
5
6
6
BluetoothA2DPSource a2dp_source;
7
7
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
+
10
12
11
13
// callback used by A2DP to provide the sound data
12
14
int32_t get_sound_data (Channels* data, int32_t len) {
13
15
// 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;
15
21
}
16
22
17
23
// Arduino Setup
Original file line number Diff line number Diff line change @@ -10,15 +10,15 @@ The SD module is connected with the help of the SPI bus
10
10
11
11
### Pins:
12
12
13
- We use SPI2 (HSPI) :
13
+ We connect the SD to the ESP32 :
14
14
15
- | MCP6022 | ESP32
15
+ | SD | ESP32
16
16
|---------|---------------
17
17
| VCC | 5V
18
18
| 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
23
24
24
Original file line number Diff line number Diff line change 3
3
#include < SD.h>
4
4
5
5
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 ;
8
8
const int32_t max_buffer_len = 512 ;
9
9
int32_t buffer[max_buffer_len][2 ];
10
10
Original file line number Diff line number Diff line change @@ -12,19 +12,23 @@ using namespace sound_tools;
12
12
BluetoothA2DPSource a2dp_source;
13
13
I2S<int32_t > i2s;
14
14
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 ;
16
17
int32_t buffer[max_buffer_len][2 ];
17
18
18
19
// callback used by A2DP to provide the sound data
19
20
int32_t get_sound_data (Channels* data, int32_t len) {
20
21
size_t req_len = min (max_buffer_len,(size_t ) len);
21
22
22
23
// 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);
24
28
25
29
// 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 ;
28
32
}
29
33
30
34
// Arduino Setup
You can’t perform that action at this time.
0 commit comments