内容介绍
内容介绍
Part1 硬件介绍
Part2 任务分析
0.读取SD卡(SD卡自备)中的音频文件,使用板卡上的3.5mm音频接口播放音乐。
1)sdcard的读取(fatfs)
2)音频的播放(iis)
1.流程图设计
Part3 实现思路
0. 使用fatfs读取音频文件
注册卷
if (f_mount(&g_fileSystem, driverNumberBuffer, 0U)) {
PRINTF("Mount volume failed.\r\n");
return -1;
}
尝试打开根目录下的1.wav
error = f_open(&g_fileObject, _T("/1.wav"), (FA_READ | FA_OPEN_ALWAYS));
if (error) {
if (error == FR_EXIST) {
PRINTF("File exists.\r\n");
} else {
PRINTF("Open file failed.\r\n");
return -1;
}
}
将读取的文件写入tf_Music0缓冲区
error = f_read(&g_fileObject, tf_Music0, sizeof(tf_Music0), &bytesRead);
if ((error) || (bytesRead != sizeof(tf_Music0))) {
PRINTF("Read file failed. \r\n");
failedFlag = true;
}
1. 使用iis驱动音频设备 iis时序图
wm8904配置文件
wm8904_config_t wm8904Config = {
.i2cConfig = {.codecI2CInstance = BOARD_CODEC_I2C_INSTANCE, .codecI2CSourceClock = BOARD_CODEC_I2C_CLOCK_FREQ},
.recordSource = kWM8904_RecordSourceLineInput,
.recordChannelLeft = kWM8904_RecordChannelLeft2,
.recordChannelRight = kWM8904_RecordChannelRight2,
.playSource = kWM8904_PlaySourceDAC,
.slaveAddress = WM8904_I2C_ADDRESS,
.protocol = kWM8904_ProtocolI2S,
.format = {.sampleRate = kWM8904_SampleRate11025Hz, .bitWidth = kWM8904_BitWidth16},
.mclk_HZ = DEMO_I2S_MASTER_CLOCK_FREQUENCY,
.master = false,
};
选择iis模式,11025采样率,352kps比特率
i2s参考资料https://www.nxp.com.cn/docs/zh/application-note/AN12758.pdf
https://www.nxp.com/docs/zh/application-note/AN4520.pdf
音乐素材制作
https://convertio.co/zh/m4a-wav/
2. 主程序
while(1)
{
if (Music_flag != sd_flag)
{
sd_flag = Music_flag;
if (Music_flag == 0)
{
error = f_read(&g_fileObject, tf_Music1, sizeof(tf_Music1),
&bytesRead);
if ((error) || (bytesRead != sizeof(tf_Music1)))
{
PRINTF(" That's all. \r\n");
break;
}
}
else if (Music_flag == sd_flag)
{
error = f_read(&g_fileObject, tf_Music0, sizeof(tf_Music0),
&bytesRead);
if ((error) || (bytesRead != sizeof(tf_Music0)))
{
PRINTF(" That's all. \r\n");
break;
}
}
}
}
Part4 项目展示
使用m5stack uintv2进行实时监控音频播放
Part5心得体会
第一次使用nxp的开发板,体验MCUXpresso ide后感觉比stm32cubeide好用多了。接下来我也会使用lpc55系列制作一些小作品。
原工程代码
https://gitee.com/nleisure/funpack11.git
附件下载
附件.zip
团队介绍
评论
0 / 100
查看更多