Page 1 of 1

官方示例代码播放不同采样率的MP3时由于重采样器异步配置 导致播放开头时速度异常

Posted: Thu Jan 08, 2026 11:42 am
by eagle_shuai
官方示例代码播放不同采样率的MP3时由于重采样器异步配置 导致播放开头时速度异常

ESP-ADF官方示例代码play_sdcard_mp3_control_example,播放MP3时,如果MP3文件的采样率与重采样器初始化时的源采样率
不一致时,音频流水线中的decoder元素获得mp3采样率信息后,是通过异步方式通知到重采样器的,这好像会导致在decoder解析出
MP3采样率信息之前,有几十毫秒的音频速率播放异常


音频流水线如下:
ESP_LOGI(TAG, "[4.5] Register all elements to audio pipeline");
audio_pipeline_register(pipeline, fatfs_stream_reader, "file");
audio_pipeline_register(pipeline, mp3_decoder, "mp3");
audio_pipeline_register(pipeline, rsp_handle, "filter");
audio_pipeline_register(pipeline, i2s_stream_writer, "i2s");

ESP_LOGI(TAG, "[4.6] Link it together [sdcard]-->fatfs_stream-->mp3_decoder-->resample-->i2s_stream-->[codec_chip]");
const char *link_tag[4] = {"file", "mp3", "filter", "i2s"};
audio_pipeline_link(pipeline, &link_tag[0], 4);

异步配置重采样器代码如下
if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT)
{
// Set music info for a new song to be played
if (msg.source == (void *)mp3_decoder && msg.cmd == AEL_MSG_CMD_REPORT_MUSIC_INFO)
{
audio_element_info_t music_info = {0};
audio_element_getinfo(mp3_decoder, &music_info);
ESP_LOGI(TAG, "[ * ] Received music info from mp3 decoder, sample_rates=%d, bits=%d, ch=%d",
music_info.sample_rates, music_info.bits, music_info.channels);
rsp_filter_set_src_info(rsp_handle, music_info.sample_rates, music_info.channels);
continue;
}

Re: 官方示例代码播放不同采样率的MP3时由于重采样器异步配置 导致播放开头时速度异常

Posted: Thu Jan 08, 2026 11:43 am
by eagle_shuai
图2 与此不相关