Music player 1-FATFS related operations

Source: Internet
Author: User
Tags strcmp

Music player two key points: 1, with Fatfs music file management, including open, read and so on. 2, configure the codec chip, through the DMA, the reading music file data sent to the codec.

In this project, the main implementation of the first large point of some operations.

Directly on the program, you need to pay attention to a few points.

#include"Sys.h"#include"Delay.h"#include"usart.h"#include"led.h"#include"lcd.h"#include"Key.h"#include"sram.h"#include"malloc.h"#include"sdio_sdcard.h"#include"malloc.h"#include"ff.h"#include"string.h"#include"Fattester.h"voidUpperChar*p); This function is used to convert lowercase letters to uppercase U8 Tell_type (Char*p); Identify file types by suffix U8 wav_decode (FIL*P);decoding of//wav filesU8*readbuf; UINT MYBR;intMainvoid) {U8 key,res,music_number; Char*MYFN;Char*myfn_temp;Char*filename_temp;
Fatfs variables related toFATFS *fs[1]; FIL *myfile; DIR Mydir; Filinfo Myfileinfo; Fresult Myres; //InitializeNvic_prioritygroupconfig (nvic_prioritygroup_2); Delay_init (168); Uart_init (115200); Led_init (); Key_init (); My_mem_init (sramin); My_mem_init (SRAMCCM);   //SD Card Initialization while(Sd_init ()) {Delay_ms ( -); LED0=! LED0; } //FATFS related to many functions, the use of the structure, need to apply for memory, otherwise it will be wrong, such as F_mount/f_openGs:0]= (fatfs*) mymalloc (Sramin,sizeof(FATFS)); Myfile= (fil*) mymalloc (Sramin,sizeof(FIL)); Myfileinfo.lfsize = _MAX_LFN *2+1; Myfileinfo.lfname= Mymalloc (sramin,myfileinfo.lfsize);//Support long file name, method is 3, need to request memory dynamically_use_lfn=3readbuf= (u8*) mymalloc (Sramin, +);//read the buffer of the fileMyfn_temp= (Char*) Mymalloc (sramin,myfileinfo.lfsize); Res=f_mount (fs[0],"0:",1);//Mount while(1) {Key=key_scan (0); if(key==1)//test the current directory for file reads, f_open-----f_read{f_open (myfile,"Test1.txt", Fa_read); Res=f_read (Myfile,readbuf, -,&MYBR); if(res) printf ("Read error:%d\r\n", RES); Else while(*readbuf!=' /') {printf ("%c",*readbuf); Readbuf++; } } if(key==2)//File type identification{Music_number=0; F_opendir (&mydir,"0:/music");// while(1) {Myres=f_readdir (&mydir,&myfileinfo);//Loop through all files in the folder if(myres! = FR_OK | | myfileinfo.fname[0] ==0) Break; MYFN= *myfileinfo.lfname? Myfileinfo.lfname:myfileinfo.fname; printf"\r\nfile name is%s\r\n", MYFN);filename_temp=MYFN; Res=Tell_type (MYFN); if(res==0) {printf ("This is a music file.\r\n"); Music_number++;//strcat (MYFN_TEMP,MYFN);strcpy ((Char*) Myfn_temp,"0:/music/"); Strcat ((Char*) Myfn_temp, (Const Char*) MYFN); Gets the absolute path of the file printf ("\r\nfile name is%s\r\n", myfn_temp); F_open (Myfile,myfn_temp,fa_read); Wav_decode (myfile); }} printf ("\r\nthere is%d music file\r\n", Music_number); } if(key==3)//{F_opendir (&mydir,"0:/music"); F_open (MyFile,"0:/music/µëxïæå-äã°ñîò¹àxí.wav", Fa_read);Wav_decode (myfile); } } }//change uppercase in a string to lowercasevoidUpperChar*p) { while(*p!=' /') { if((*p>= the) && (*p<= -)) *p=*p- +; P++; }}//identify file types with suffix namesU8 Tell_type (Char*p) { intI=0; Char*attr; while(i< $) { if(*p==' /') Break; I++; P++; } if(i== $)return 1; I=0; while(i<5) { if(*p=='.'){p++; attr=p; Break; } I++; P--; } if(i==5)return 2; if(strcmp (attr,"WAV")==0)|| (strcmp (attr,"wav")==0)) { return 0; } Else { return 4; }}//Riff¿étypedef __packedstruct{u32 chunkid; // 0x46464952U32 ChunkSize; U32 Format;}chunkriff;//Fmt¿étypedef __packedstruct{u32 chunkid; U32 ChunkSize; U16 Audioformat; U16 Numofchannels; U32 samplerate; U32 byterate; U16 Blockalign; U16 BitsPerSample;//U16 Byteextradata; }chunkfmt; //Fact¿étypedef __packedstruct{u32 chunkid; U32 ChunkSize; U32 Numofsamples;}chunkfact;u8 Wav_decode (FIL*2) {U8 res; Chunkriff*riff; Chunkfmt*FMT; Res=f_read (P,readbuf, +, &AMP;MYBR);//Ôúíâãæöðòñ¾open if(res==FR_OK) {Riff= (Chunkriff *) Readbuf; printf ("This is RIFF Chunk Read-----------\ r \ n"); printf ("RIFF Chunkid is%x\r\n",riff->chunkid); printf ("RIFF ChunkSize is%d mb\r\n",riff->chunksize>> -); printf ("RIFF Format is%x\r\n",riff->Format); printf ("This is FMT Chunk Read-----------\ r \ n"); FMT= (CHUNKFMT *) (readbuf+ A); printf ("FMT Chunkid is%x\r\n",fmt->chunkid); printf ("FMT ChunkSize is%d\r\n",fmt->ChunkSize); printf ("FMT Channle is%d\r\n",fmt->numofchannels); } Else{printf ("Read err:%d\r\n", RES); } returnRes;}

Music player 1-FATFS related operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.