esp32~mp3播放实例解析

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值