i2s Playback Rate

sb_espressif
Posts: 28
Joined: Fri Dec 08, 2023 3:04 am

i2s Playback Rate

Postby sb_espressif » Mon Jan 08, 2024 12:18 pm

Hi there;

I'm trying to achieve the effect of speeding up/slowing down audio playback based on user input. One way I can think to do this is to simply repeatedly reconfigure the i2s clock after reading some user input, before sending audio samples. But doing this inside a playback loop:

Code: Select all

    i2s_channel_disable(tx_handle);
    i2s_config.clk_cfg.sample_rate_hz = mp3_info.hz * USER_INPUT;
    i2s_channel_reconfig_std_clock(tx_handle, &i2s_config.clk_cfg);
    i2s_channel_enable(tx_handle);
results in choppy audio, which I think implies these operations take too long to complete (?).

The other option would be investigating sample rate conversion methods, to lengthen or shorten the audio buffer I send to i2s (while keeping the i2s clock itself constant). I'm not opposed to this route, just curious why the above doesn't seem to work.

Is it unusual to try to rapidly modify the i2s clock like this? Or is it a totally reasonable approach but maybe I have some bugs elsewhere that would introduce the choppy playback?

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: i2s Playback Rate

Postby ESP_Sprite » Mon Jan 08, 2024 1:19 pm

Decently sure the i2s_channel_disable and _enable stop and flush the I2S queue, leading to stuttering. Not sure if you can change the sample rate without those, but it may be worth a try. I imagine software resampling is usually done, especially if you also want to mix multiple sounds playing at different rates.

sb_espressif
Posts: 28
Joined: Fri Dec 08, 2023 3:04 am

Re: i2s Playback Rate

Postby sb_espressif » Mon Jan 08, 2024 8:30 pm

Cool, that's very helpful, thank you!

Who is online

Users browsing this forum: No registered users and 110 guests