Page 1 of 1

i2s Playback Rate

Posted: Mon Jan 08, 2024 12:18 pm
by sb_espressif
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?

Re: i2s Playback Rate

Posted: Mon Jan 08, 2024 1:19 pm
by ESP_Sprite
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.

Re: i2s Playback Rate

Posted: Mon Jan 08, 2024 8:30 pm
by sb_espressif
Cool, that's very helpful, thank you!