1. 完成了对音频播放类的完整C++封装,测试通过

2. 修复了LVGL渲染类当中的一些小bug
3. 增加了一些CPU资源占用的日志打印函数,运行在主线程当中
4. 完善了底层通信类的封装,基于websocket,尚未测试
This commit is contained in:
Misaki
2025-09-12 02:11:50 +08:00
parent 4985fee7c2
commit 97fe13da26
16 changed files with 1297 additions and 85 deletions
+15 -2
View File
@@ -91,8 +91,8 @@ void Audio_Init(void)
.mute_fn = audio_mute_function,
.write_fn = bsp_i2s_write,
.clk_set_fn = bsp_i2s_reconfig_clk,
.priority = 3,
.coreID = 1
.priority = 5,
.coreID = 0 // 运行在0号核,避免与lvgl抢占资源
};
ret = audio_player_new(config);
if (ret != ESP_OK) {
@@ -124,12 +124,25 @@ void Play_Music(const char* directory, const char* fileName)
} else {
snprintf(filePath, maxPathLength, "%s/%s", directory, fileName);
}
ESP_LOGD(TAG, "Playing MP3 file: %s", filePath);
Music_File = Open_File(filePath);
if (!Music_File) {
ESP_LOGE(TAG, "Failed to open MP3 file: %s", filePath);
return;
}
// 跳过非音频数据
uint8_t buf[4];
while (fread(buf, 1, 4, Music_File) == 4) {
uint32_t head = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
if ((head & 0xFFE00000) == 0xFFE00000) { // 找到 MP3 帧头
fseek(Music_File, -4, SEEK_CUR); // 回退 4 字节
break;
}
fseek(Music_File, -3, SEEK_CUR); // 逐字节滑动窗口
}
ESP_LOGI(TAG, "Skipped non-audio data, now at offset %ld", ftell(Music_File));
expected_event = AUDIO_PLAYER_CALLBACK_EVENT_PLAYING;
esp_err_t ret = audio_player_play(Music_File);
if (ret != ESP_OK) {