Sample Organization of Elements in Audio Pipeline
将MP3解码器和I2S流两个元素添加进管道,解码器的输入是MP3文件数据流,I2S流将解码后的音频数据输出到片外,各应用程序之间通过事件接口通信。
1. 代码分析
static const char *TAG = “PLAY_MP3_FLASH”;
/*
To embed it in the app binary, the mp3 file is named
in the component.mk COMPONENT_EMBED_TXTFILES variable.
*/
extern const uint8_t adf_music_mp3_start[] asm(“_binary_adf_music_mp3_start”);
extern const uint8_t adf_music_mp3_end[] asm(“_binary_adf_music_mp3_end”);
static int adf_music_mp3_pos;
int mp3_music_read_cb(audio_element_handle_t el, char *buf, int len, TickType_t wait_time, void *ctx)
{
int read_size = adf_music_mp3_end - adf_music_mp3_start - adf_music_mp3_pos;
if (read_size == 0) {
return AEL_IO_DONE;
} else if (len < read_size) {
read_size = len;
}
memcpy(buf, adf_music_mp3_start + adf_music_mp3_pos, read_size);
adf_music_mp3_pos += read_size;
return read_size;
}
void app_main(void)
{
audio_pipeline_handle_t pipeline; // 管道
audio_element_handle_t i2s_stream_writer, mp3_decoder; // 音频元素
esp_log_level_set(“*”, ESP_LOG_WARN);
es