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);
esp_log_level_set(TAG, ESP_LOG_INFO);
ESP_LOGI(TAG, “[ 1 ] Start audio codec chip”);
audio_hal_codec_config_t audio_hal_codec_cfg = AUDIO_HAL_ES8388_DEFAULT();
audio_hal_handle_t hal = audio_hal_init(&audio_hal_codec_cfg, 0); // 初始化编解码驱动
audio_hal_ctrl_codec(hal, AUDIO_HAL_CODEC_MODE_DECODE, AUDIO_HAL_CTRL_START); // 启动解码
int player_volume;
audio_hal_get_volume(hal, &player_volume); // 获取音量
ESP_LOGI(TAG, “[ 2 ] Create audio pipeline, add all elements to pipeline, and subscribe pipeline event”);
audio_pipeline_cfg_t pipeline_cfg = DEFAULT_AUDIO_PIPELINE_CONFIG();
pipeline = audio_pipeline_init(&pipeline_cfg); // 初始化管道
mem_assert(pipeline);
ESP_LOGI(TAG, “[2.1] Create mp3 decoder to decode mp3 file and set custom read callback”);
mp3_decoder_cfg_t mp3_cfg = DEFAULT_MP3_DECODER_CONFIG();
mp3_decoder = mp3_decoder_init(&mp3_cfg); // 初始化mp3 decoder元素
audio_element_set_read_cb(mp3_decoder, mp3_music_read_cb, NULL);
ESP_LOGI(TAG, “[2.2] Create i2s stream to write data to codec chip”);
i2s_stream_cfg_t i2s_cfg = I2S_STREAM_CFG_DEFAULT();
i2s_cfg.type = AUDIO_STREAM_WRITER;
i2s_stream_writer = i2s_stream_init(&i2s_cfg); // 初始化i2s stream元素
ESP_LOGI(TAG, “[2.3] Register all elements to audio pipeline”); // 注册元素到管道中去
audio_pipeline_register(pipeline, mp3_decoder, “mp3”);
audio_pipeline_register(pipeline, i2s_stream_writer, “i2s”);
ESP_LOGI(TAG, “[2.4] Link it together [mp3_music_read_cb]–>mp3_decoder–>i2s_stream–>[codec_chip]”);
audio_pipeline_link(pipeline, (const char *[]) {“mp3”, “i2s”}, 2); // 将mp3_music_read_cb mp3_decoder i2s_stream codec_chip关联在一起
ESP_LOGI(TAG, “[ 3 ] Initialize peripherals”);
esp_periph_config_t periph_cfg = { 0 };
esp_periph_init(&periph_cfg);
ESP_LOGI(TAG, “[3.1] Initialize Touch peripheral”);
periph_touch_cfg_t touch_cfg = {
.touch_mask = TOUCH_SEL_SET | TOUCH_SEL_PLAY | TOUCH_SEL_VOLUP | TOUCH_SEL_VOLDWN,
.tap_threshold_percent = 70,
};
esp_periph_handle_t touch_periph = periph_touch_init(&touch_cfg); // 初始化按键
ESP_LOGI(TAG, “[3.2] Start all peripherals”);
esp_periph_start(touch_periph);
ESP_LOGI(TAG, “[ 4 ] Setup event listener”);
audio_event_iface_cfg_t evt_cfg = AUDIO_EVENT_IFACE_DEFAULT_CFG();
audio_event_iface_handle_t evt = audio_event_iface_init(&evt_cfg);
ESP_LOGI(TAG, “[4.1] Listening event from all elements of pipeline”);
audio_pipeline_set_listener(pipeline, evt); // 设置按键事件
ESP_LOGI(TAG, “[4.2] Listening event from peripherals”); // 设置外设监听事件
audio_event_iface_set_listener(esp_periph_get_event_iface(), evt);
ESP_LOGW(TAG, “[ 5 ] Tap touch buttons to control music player:”);
ESP_LOGW(TAG, " [Play] to start, pause and resume, [Set] to stop.");
ESP_LOGW(TAG, " [Vol-] or [Vol+] to adjust volume.");
while (1) {
audio_event_iface_msg_t msg;
esp_err_t ret = audio_event_iface_listen(evt, &msg, portMAX_DELAY);
if (ret != ESP_OK) {
ESP_LOGE(TAG, “[ * ] Event interface error : %d”, ret);
continue;
}
if (msg.source_type == AUDIO_ELEMENT_TYPE_ELEMENT && 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, “[ * ] Receive music info from mp3 decoder, sample_rates=%d, bits=%d, ch=%d”,
music_info.sample_rates, music_info.bits, music_info.channels);
audio_element_setinfo(i2s_stream_writer, &music_info);
i2s_stream_set_clk(i2s_stream_writer, music_info.sample_rates, music_info.bits, music_info.channels);
continue;
}
if (msg.source_type == PERIPH_ID_TOUCH
&& msg.cmd == PERIPH_TOUCH_TAP
&& msg.source == (void *)touch_periph) {
if ((int) msg.data == TOUCH_PLAY) { // 改变播放状态
ESP_LOGI(TAG, “[ * ] [Play] touch tap event”);
audio_element_state_t el_state = audio_element_get_state(i2s_stream_writer);
switch (el_state) {
case AEL_STATE_INIT :
ESP_LOGI(TAG, “[ * ] Starting audio pipeline”);
audio_pipeline_run(pipeline);
break;
case AEL_STATE_RUNNING :
ESP_LOGI(TAG, “[ * ] Pausing audio pipeline”);
audio_pipeline_pause(pipeline);
break;
case AEL_STATE_PAUSED :
ESP_LOGI(TAG, “[ * ] Resuming audio pipeline”);
audio_pipeline_resume(pipeline);
break;
case AEL_STATE_FINISHED :
ESP_LOGI(TAG, “[ * ] Rewinding audio pipeline”);
audio_pipeline_stop(pipeline);
adf_music_mp3_pos = 0;
audio_pipeline_resume(pipeline);
break;
default :
ESP_LOGI(TAG, “[ * ] Not supported state %d”, el_state);
}
} else if ((int) msg.data == TOUCH_SET) {
ESP_LOGI(TAG, “[ * ] [Set] touch tap event”);
ESP_LOGI(TAG, “[ * ] Stopping audio pipeline”);
break;
} else if ((int) msg.data == TOUCH_VOLUP) {
ESP_LOGI(TAG, “[ * ] [Vol+] touch tap event”);
player_volume += 10;
if (player_volume > 100) {
player_volume = 100;
}
audio_hal_set_volume(hal, player_volume);
ESP_LOGI(TAG, “[ * ] Volume set to %d %%”, player_volume);
} else if ((int) msg.data == TOUCH_VOLDWN) {
ESP_LOGI(TAG, “[ * ] [Vol-] touch tap event”);
player_volume -= 10;
if (player_volume < 0) {
player_volume = 0;
}
audio_hal_set_volume(hal, player_volume);
ESP_LOGI(TAG, “[ * ] Volume set to %d %%”, player_volume);
}
}
}
ESP_LOGI(TAG, “[ 6 ] Stop audio_pipeline”);
audio_pipeline_terminate(pipeline);
audio_pipeline_unregister(pipeline, mp3_decoder);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
![](https://img-blog.csdnimg.cn/img_convert/75a9b81caa6a61428098d11d8daa37f8.jpeg)
总结
可以看出,笔者的工作学习模式便是由以下 「六个要点」 组成:
❝ 多层次的工作/学习计划 + 番茄工作法 + 定额工作法 + 批处理 + 多任务并行 + 图层工作法❞
希望大家能将这些要点融入自己的工作学习当中,我相信一定会工作与学习地更富有成效。
下面是我学习用到的一些书籍学习导图,以及系统的学习资料。每一个知识点,都有对应的导图,学习的资料,视频,面试题目。
**如:我需要学习 **Flutter的知识。(大家可以参考我的学习方法)
- Flutter 的思维导图(无论学习什么,有学习路线都会事半功倍)
- Flutter进阶学习全套手册
- Flutter进阶学习全套视频
大概就上面这几个步骤,这样学习不仅高效,而且能系统的学习新的知识。
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
片转存中…(img-woRiGsyB-1712486758537)]
- Flutter进阶学习全套手册
[外链图片转存中…(img-tFBneiw2-1712486758537)]
- Flutter进阶学习全套视频
[外链图片转存中…(img-C1luTGh5-1712486758537)]
大概就上面这几个步骤,这样学习不仅高效,而且能系统的学习新的知识。
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!