Skip to content

Commit 99b6a07

Browse files
committed
Buffer size for ESP32 I2S
1 parent 00e29ca commit 99b6a07

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "AudioTools.h"
2+
#include "AudioCodecs/CodecAACFDK.h"
3+
#include "AudioLibs/AudioBoardStream.h"
4+
5+
URLStream url("ssid","password"); // or replace with ICYStream to get metadata
6+
AudioBoardStream i2s(AudioKitEs8388V1); // final output of decoded stream
7+
EncodedAudioStream dec(&i2s, new AACDecoderFDK()); // Decoding stream
8+
StreamCopy copier(dec, url); // copy url to decoder
9+
10+
11+
void setup(){
12+
Serial.begin(115200);
13+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
14+
15+
// setup i2s
16+
auto config = i2s.defaultConfig(TX_MODE);
17+
i2s.begin(config);
18+
19+
// setup I2S based on sampling rate provided by decoder
20+
dec.begin();
21+
22+
// aac radio
23+
url.begin("http://peacefulpiano.stream.publicradio.org/peacefulpiano.aac","audio/aac");
24+
25+
}
26+
27+
void loop(){
28+
copier.copy();
29+
}

src/AudioI2S/I2SConfigESP32V1.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class I2SConfigESP32V1 : public AudioInfo {
7979
LOGI("bits per sample: %d", bits_per_sample);
8080
LOGI("number of channels: %d", channels);
8181
LOGI("signal_type: %s", i2s_signal_types[signal_type]);
82+
LOGI("buffer_count:%d", buffer_count);
83+
LOGI("buffer_size:%d", buffer_size);
8284
if (signal_type==Digital){
8385
LOGI("i2s_format: %s", i2s_formats[i2s_format]);
8486
}

src/AudioI2S/I2SESP32V1.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,14 @@ class I2SDriverESP32V1 {
195195

196196
i2s_chan_config_t getChannelConfig(I2SConfigESP32V1 &cfg) {
197197
TRACED();
198-
return I2S_CHANNEL_DEFAULT_CONFIG(
198+
i2s_chan_config_t result = I2S_CHANNEL_DEFAULT_CONFIG(
199199
(i2s_port_t)cfg.port_no,
200200
cfg.is_master ? I2S_ROLE_MASTER : I2S_ROLE_SLAVE);
201+
// use the legicy size parameters for frame num
202+
int size = cfg.buffer_size * cfg.buffer_count;
203+
int frame_size = cfg.bits_per_sample * cfg.channels / 8;
204+
if (size > 0) result.dma_frame_num = size / frame_size;
205+
return result;
201206
}
202207

203208
i2s_std_clk_config_t getClockConfig(I2SConfigESP32V1 &cfg) {

0 commit comments

Comments
 (0)