ESP ADF : Pipe (SDCard - MP3Decoder - I2S) => Wrong Sample Rate

ThomasESP32
Posts: 229
Joined: Thu Jul 14, 2022 5:15 am

ESP ADF : Pipe (SDCard - MP3Decoder - I2S) => Wrong Sample Rate

Postby ThomasESP32 » Tue Feb 14, 2023 2:23 pm

Good afternoon,

I have tried to implement a pipe in order to decode a MP3 file on a SDCard and to sent it to an audio amplifier using I2S.

The program compiles normally, using an oscilloscope, I can see datas on the I2S_Out, so I think that the MP3 file is decoded and sent.
However, the LR_CLK and the BIT_CLK are not OK.

I would like to have a LR_CLK = 16KHz (Equal to the sample rate) but I have a LR_CLK = 1,3KHz.
The BIT_CLK is 96Khz.
So I do not ear anything on my amplifier.

Here is my config :
i2s_stream_cfg_t i2s_cfg;
i2s_cfg.type = AUDIO_STREAM_WRITER;
i2s_cfg.i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX);
i2s_cfg.i2s_config.sample_rate = 16000;
i2s_cfg.i2s_config.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT;
i2s_cfg.i2s_config.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT;
i2s_cfg.i2s_config.communication_format = I2S_COMM_FORMAT_STAND_I2S;
i2s_cfg.i2s_config.intr_alloc_flags = ESP_INTR_FLAG_LEVEL2 | ESP_INTR_FLAG_IRAM;
i2s_cfg.i2s_config.dma_buf_count = 3;
i2s_cfg.i2s_config.dma_buf_len = 300;
i2s_cfg.i2s_config.use_apll = false;
i2s_cfg.i2s_config.tx_desc_auto_clear = true;
i2s_cfg.i2s_config.fixed_mclk = 0;
i2s_cfg.i2s_config.mclk_multiple = I2S_MCLK_MULTIPLE_384;
i2s_cfg.i2s_port = I2S_NUM_0;
i2s_cfg.use_alc = false;
i2s_cfg.volume = 0;
i2s_cfg.out_rb_size = I2S_STREAM_RINGBUFFER_SIZE;
i2s_cfg .task_stack = I2S_STREAM_TASK_STACK;
i2s_cfg.task_core = I2S_STREAM_TASK_CORE;
i2s_cfg.task_prio = I2S_STREAM_TASK_PRIO;
i2s_cfg.stack_in_ext = false;
i2s_cfg.multi_out_num = 0;
i2s_cfg.uninstall_drv = true;
i2s_cfg.need_expand = false;
i2s_cfg.expand_src_bits = I2S_BITS_PER_SAMPLE_16BIT;
i2s_stream_writer = i2s_stream_init(&i2s_cfg);

Could you please help me on the subject ?

Best regards,

Thomas TRUILHE.

AndiRo
Posts: 3
Joined: Mon Dec 12, 2022 2:45 pm

Re: ESP ADF : Pipe (SDCard - MP3Decoder - I2S) => Wrong Sample Rate

Postby AndiRo » Tue Feb 14, 2023 3:26 pm

Hello ThomasESP32

at first it is recommended to initialise your config with

Code: Select all

i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
and then override the default config values

If you have no i2s to DAC chip you have to use the internal one

for this you have to define
SOC_I2S_SUPPORTS_ADC_DAC

you also can use
i2s_stream_set_clk(audio_element_handle_ti2s_stream, int rate, int bits, int ch)

to set the clock and bit rate

Best regards
Last edited by AndiRo on Fri Feb 17, 2023 9:25 am, edited 1 time in total.

AndiRo
Posts: 3
Joined: Mon Dec 12, 2022 2:45 pm

Re: ESP ADF : Pipe (SDCard - MP3Decoder - I2S) => Wrong Sample Rate

Postby AndiRo » Wed Feb 15, 2023 7:25 am

Hello Thomas

at first it is recomended to initialise your struct like this:

Code: Select all

i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
and then override the default values

like in the samples

if you do not have an i2s to dac then you need to define

Code: Select all

SOC_I2S_SUPPORTS_ADC_DAC
you can also try this function to set the clock

Code: Select all

esp_err_t i2s_stream_set_clk(audio_element_handle_ti2s_stream, int rate, int bits, int ch)
there are also a lot of examples in esp-adf
https://github.com/espressif/esp-adf/tr ... p3_control

best regards

Who is online

Users browsing this forum: No registered users and 10 guests