Files
Misaki ce0998c1c6 1. 完成了PWR按键相关的测试,测试通过
2. 完成了语言识别测试,测试基本通过,后续需要修改从sd卡导入模型以配合ota
2025-09-01 00:11:00 +08:00

123 lines
4.1 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// Created by misaki on 2025/8/24.
//
/******************************************************************************
* test_audio_player.c
*
* 本文件用于对 PCM5101 + SD 卡 MP3 播放方案做一次“黑盒”集成测试。
* 测试流程:
* 1. 初始化 SD 卡
* 2. 扫描 /sdcard/music 目录下所有 *.mp3
* 3. 顺序播放 10 秒 -> 暂停 2 秒 -> 恢复播放 5 秒 -> 停止
* 4. 动态调节音量 0→50→100
* 5. 打印运行结果
*
* 使用须知:
* - 在 menuconfig 里把 "format_if_mount_failed" 设为 false,防止误格式化
* - 在 /sdcard/music 里放至少 1 首 MP3,文件名不要含中文或空格
* - 本测试默认用 1-Line SDMMC,若硬件是 4-Line 只需改 slot_config.width = 4
* - 默认采样率 44.1 kHz16bit 立体声
*
* 编译:idf.py build
* 烧录:idf.py flash monitor
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "unity.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "PCM5101.h" // 来自您的工程
/*-------------------- 私有宏 --------------------*/
#define TEST_TAG "TEST_AUDIO"
#define MUSIC_DIR "/sdcard/music" // 测试用目录
#define MAX_MP3_FILES 64 // 最多扫 64 首
#define FILE_NAME_LEN 100 // 与 Folder_retrieval 保持一致
/*-------------------- 静态变量 --------------------*/
static char mp3_list[MAX_MP3_FILES][FILE_NAME_LEN]; // 保存扫描到的文件名
static uint16_t mp3_count = 0; // 实际扫描到的文件数
static uint16_t current_idx = 0; // 当前播放的索引
/*-------------------- 私有函数 --------------------*/
/*-------------------------------------------------
* 扫描指定目录的 MP3
*------------------------------------------------*/
static void test_scan_music_dir(void)
{
mp3_count = Folder_retrieval(MUSIC_DIR, ".mp3", mp3_list, MAX_MP3_FILES);
if (mp3_count == 0) {
ESP_LOGE(TEST_TAG, "没扫到任何 MP3,请检查 %s 目录", MUSIC_DIR);
} else {
ESP_LOGI(TEST_TAG, "扫描到 %d 首 MP3", mp3_count);
for (int i = 0; i < mp3_count; i++) {
ESP_LOGI(TEST_TAG, "[%d] %s", i, mp3_list[i]);
}
}
}
/*-------------------------------------------------
* 播放一首 MP3 并做暂停/恢复/音量测试
*------------------------------------------------*/
void test_play_one(const char *dir, const char *file)
{
ESP_LOGI(TEST_TAG, "开始播放 %s/%s", dir, file);
/* 1. 播放 10 秒 */
Volume_adjustment(50);
Play_Music(dir, file);
vTaskDelay(pdMS_TO_TICKS(10000));
/* 2. 暂停 2 秒 */
ESP_LOGI(TEST_TAG, "暂停 2 秒");
Music_pause();
vTaskDelay(pdMS_TO_TICKS(2000));
/* 3. 恢复播放 5 秒 */
ESP_LOGI(TEST_TAG, "恢复播放 20 秒");
Music_resume();
vTaskDelay(pdMS_TO_TICKS(20000));
/* 4. 动态调音量 */
ESP_LOGI(TEST_TAG, "音量 0%%");
Volume_adjustment(0);
vTaskDelay(pdMS_TO_TICKS(2000));
ESP_LOGI(TEST_TAG, "音量 50%%");
Volume_adjustment(50);
vTaskDelay(pdMS_TO_TICKS(2000));
ESP_LOGI(TEST_TAG, "音量 70%%");
Volume_adjustment(70);
vTaskDelay(pdMS_TO_TICKS(2000));
/* 5. 主动停止 */
Music_pause();
ESP_LOGI(TEST_TAG, "测试结束,停止播放");
}
#include "tools.h"
/*-------------------------------------------------
* 测试入口
*------------------------------------------------*/
void run_audio_test(void)
{
create_print_sys_memory_task();
/* 1. 初始化外设 */
ESP_LOGI(TEST_TAG, "=== 音频测试开始 ===");
SD_Init(); // 挂载 SD 卡
Audio_Init(); // 初始化 I2S + AudioPlayer
/* 2. 扫描 MP3 */
test_scan_music_dir();
TEST_ASSERT_GREATER_THAN(0, mp3_count); // 至少要有 1 首
/* 3. 依次测试每首 MP3(这里只演示第一首)*/
test_play_one(MUSIC_DIR, mp3_list[0]);
ESP_LOGI(TEST_TAG, "=== 音频测试结束 ===");
}