当前位置:网站首页>STM32 MP3 music player based on FatFs r0.14b & SD card (also a simple application of FatFs)
STM32 MP3 music player based on FatFs r0.14b & SD card (also a simple application of FatFs)
2022-07-24 06:45:00 【Like warm know cold】
This article is not perfect !!!
So far, it's just for learning notes , Please be careful when reading this article !!
Write it at the front :
FatFs Of I/O Interface operation has been written in the previous article , Now use it directly !
The project mainly refers to the codes of wildfire and punctual atoms .
Said in the previous : In fact, I don't like the code style of punctual atoms , Basically, they wrap their own function interfaces on the official library . Development projects are convenient , But it is not conducive to learning . Compared with wildfire, I like it very much , Its code is less modified in the official library or official routines , And the video lesson explains clear .
This article will be published in STM32F103 Elite Edition provides code routines based on , Understand its operation principle , And realize the function of music player based on the official library .
Inevitably, there will be code bug, This article just combs the programming ideas , Implementation process
In the choice of chips , Both wildfire and punctual atoms are selected VS1053, This is quite consistent . The chip is a little expensive .
See other alternatives later , In short, when calling FatFs There should be little difference .
VS1053
Although I don't want to use this chip , But the routine is there , I have to see it too .
This chip supports many strange formats !
According to the official English manual ( In fact, I didn't quite understand !):
Supported audio decoding :Ogg Vorbis, MP3, AAC, WMA and WAV PCM + ADPCM
In fact, I can't use so much , There is one MP3 That's it , There is no need to record .( I feel so superficial when I say so )
Communications
VS1053 adopt SPI Protocol to communicate with the host .48 Pins , I have to say so much .
VS1002 Local mode ( A new model )

🧐 The line to be connected
| name | explain |
|---|---|
| XCS | Film selection input ( Low level active ) |
| XDCS | Data slice selection / Byte synchronization |
| SCK | SPI Clock bus |
| SI | SPI Data input line |
| SO | SPI Data output line |
| DREQ | Data request |
| RST | Reset ( Low level active ) |
register
Unexpectedly 16 A register , Register pairs can be used VS1053 Control

I won't elaborate on the functions of each register , Specific to see :VS1053b Data manual
About VS1053 That's what I learned , Now let's read and write the file !
Implementation problems
Read the implementation code of wildfire , It doesn't feel good .
read MP3 File list
DIR dir;
u8 res;
FILINFO filinfo;
u8 *fn; // Long filename
res = f_opendir(&dir,"0:"); // Suppose the drive letter is 0
if(res == FR_OK)
{
while(1)
{
res = f_readdir(&dir,&filinfo); // Read file information
if(res != FR_OK || filinfo.fname[0] == 0) // I didn't read the file
break;
fn = (u8 *)(* filinfo.fname) // It is simpler to judge the file name here than before , I don't know
res = f_typetell(fn); // Here you can determine the file type by yourself
if(res == MP3) // Judge to be MP3 file type
{
// It is judged here that MP3 File name for , You can store
// The list will be displayed soon after the storage
}
}
}Show
res = f_opendir(&dir,"0:/");
while(res == FR_OK)
{
dir_sdi(&mp3dir,mp3indextbl[curindex]); // Directory index function ??? This version is gone
res = r_readdir(&dir.&filinfo); // Read the next file in the directory
if(res != FR_OK || filinfo.fname[0] == 0)
break; // At the end
fn = (u8 *)(* filinfo.fname); // It is simpler to judge the file name here than before , I don't know
// This step can directly display fn 了 !
strcpy((char*)pname,"0:/");
strcat((char*)pname,(const char*)fn);
// Then play music
PlaySong(pname);
}Play
FIL* fmp3;
u8 *databuf;
u16 br;
u8 res,rval;
u16 i=0;
rval=0;
fmp3=(FIL*)mymalloc(SRAMIN,sizeof(FIL));// Application memory
databuf=(u8*)mymalloc(SRAMIN,4096); // open up 4096 Byte memory area
if(databuf==NULL||fmp3==NULL)rval=0XFF ;// Memory request failed
if(rval==0)
{
VS_Restart_Play(); // Restart playback
VS_Set_All(); // Set volume and other information
VS_Reset_DecodeTime(); // Reset decoding time
}
res = f_typetell(pname);
if(res == MP3)
{
VS_Load_Patch((u16*)vs1053b_patch,VS1053B_PATCHLEN);
}
res=f_open(fmp3,(const TCHAR*)pname,FA_READ); // Open file
if(res == 0)
{
VS_SPI_SpeedHigh(); // High speed
while(rval == 0)
{
res = f_read(fmp3,databuf,4096,(UINT*)&br);// read out 4096 Bytes
i=0;
do
{
if(VS_Send_MusicData(databuf+i)==0)// to VS10XX Send audio data
i +=32;
else
mp3_msg_show(fmp3->fsize);// Show MP3 Information about
}while(i<4096);// Cycle to send 4096 Bytes
if(br!=4096||res!=0) // Read it or make mistakes
{
rval=0;
break;// After reading the .
}
f_close(fmp3); // Close file
}
else rval = 0xff; // Something went wrong
}
myfree(SRAMIN,databuf);
myfree(SRAMIN,fmp3);
return rval;
got it !!!! Understand the meaning !!!
I understand the implementation method !
1️⃣ Define an array first or The linked list is used to store song names , Convenient access , It is also convenient to print playlists !
2️⃣ Open Directory , Then read the directory entry ,f_readdir Items in the directory can be read in order ! Then through the read object information , Judge its name . Four characters at the end of the foundation (.mp3) Judge whether it is MP3 file , If yes, it is stored in the song name sequence
3️⃣ By calling the song name sequence , Use f_open Open the file and use f_read Read file transfer decoding , In the transmission process, you can also judge whether there is the operation of the previous song and the next song . You can even select tracks to operate , Because there are song name sequences , It's also simpler .
In fact, most of them are VS1053 Chip related functions . Feel instantly transparent .
ok, Take a small step forward every day , Not impatient ! come on.
Later, read and understand the code update !
边栏推荐
猜你喜欢

Redis分布式缓存学习笔记

RAID的配置实验

Experiment: creation, expansion, and deletion of LVM logical volumes

Kubernetes' deployment, service concept, dynamic capacity expansion

Solution: exit status 1 and exit status 145 appear when the console uses NVM to control the node version

【波形/信号发生器】基于 STC1524K32S4 for C on Keil

机器学习案例:孕妇吸烟与胎儿健康

Learn more about when to use MySQL two locks (table lock and row lock)

Combination of grep and regular

Talk about browser cache again
随机推荐
kubernetes 的Deployment(部署),Service概念,动态扩缩容
LM393 voltage comparator and its typical circuit introduction
FTP service and experiment
进程和计划任务管理
Explain the event cycle mechanism and differences between browser and node in detail
Solution of forgetting root password in mysql5.7 under Windows
JMeter distributed pressure measurement
类加载的过程(生命周期)详情分析
系统安全及应用
【LVGL(2)】LVGL入门,在CodeBlock上进行模拟以及移植STM32
It's not too much to fight a landlord in idea!
在IDEA里斗个地主不过分吧!
歹徒逃亡3
Special effects - cobweb background effects
深入了解MySQL 两把锁啥时候用(表锁,行锁)
ES10 subtotal flat and flatmap
Quick start of go language
Crud of MySQL
Sed command
Introduction to kubernetes (kubernetes benefits)