Skip to content

Commit

Permalink
Buffer size for ESP32 I2S
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Sep 21, 2024
1 parent 00e29ca commit 99b6a07
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "AudioTools.h"
#include "AudioCodecs/CodecAACFDK.h"
#include "AudioLibs/AudioBoardStream.h"

URLStream url("ssid","password"); // or replace with ICYStream to get metadata
AudioBoardStream i2s(AudioKitEs8388V1); // final output of decoded stream
EncodedAudioStream dec(&i2s, new AACDecoderFDK()); // Decoding stream
StreamCopy copier(dec, url); // copy url to decoder


void setup(){
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Info);

// setup i2s
auto config = i2s.defaultConfig(TX_MODE);
i2s.begin(config);

// setup I2S based on sampling rate provided by decoder
dec.begin();

// aac radio
url.begin("http://peacefulpiano.stream.publicradio.org/peacefulpiano.aac","audio/aac");

}

void loop(){
copier.copy();
}
2 changes: 2 additions & 0 deletions src/AudioI2S/I2SConfigESP32V1.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class I2SConfigESP32V1 : public AudioInfo {
LOGI("bits per sample: %d", bits_per_sample);
LOGI("number of channels: %d", channels);
LOGI("signal_type: %s", i2s_signal_types[signal_type]);
LOGI("buffer_count:%d", buffer_count);
LOGI("buffer_size:%d", buffer_size);
if (signal_type==Digital){
LOGI("i2s_format: %s", i2s_formats[i2s_format]);
}
Expand Down
7 changes: 6 additions & 1 deletion src/AudioI2S/I2SESP32V1.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,14 @@ class I2SDriverESP32V1 {

i2s_chan_config_t getChannelConfig(I2SConfigESP32V1 &cfg) {
TRACED();
return I2S_CHANNEL_DEFAULT_CONFIG(
i2s_chan_config_t result = I2S_CHANNEL_DEFAULT_CONFIG(
(i2s_port_t)cfg.port_no,
cfg.is_master ? I2S_ROLE_MASTER : I2S_ROLE_SLAVE);
// use the legicy size parameters for frame num
int size = cfg.buffer_size * cfg.buffer_count;
int frame_size = cfg.bits_per_sample * cfg.channels / 8;
if (size > 0) result.dma_frame_num = size / frame_size;
return result;
}

i2s_std_clk_config_t getClockConfig(I2SConfigESP32V1 &cfg) {
Expand Down

0 comments on commit 99b6a07

Please sign in to comment.