贴个MP3播放功能的函数,最高速度大概在160Kbps,请大家提建议
sbit LED3Pin = P0^4;
void PlayMP3(unsigned char *SongName) { int i =0,m =0; // static uint16 pointer=0; uchar *PDataBuffPoint; //数据缓冲区指针. bool bFileEndFlag; //读数据进行到文件结尾标志 uchar ucOldKeyValue;
// uchar p; uchar ucFileExtNameString[4]; uchar xdata ucDispBuff[20];
memset(ucFileExtNameString,0x0,4); memcpy(ucFileExtNameString,SongName+8,3); ComShowString(c_COM1,"Current Play File ExtName is:"); ComShowString(c_COM1,ucFileExtNameString); sprintf(ucDispBuff,"Music Mode:%s",ucFileExtNameString); // LCD_ShowString(3,0,"Mode:"); LCD_ShowString(3,0,ucDispBuff); bFileEndFlag = false; while (!bFileEndFlag) { // ComShowString(c_COM1,"Start Read Mp3 File Sector"); RDCOUNT = ReadSector(SongName, Sector_Buf); if(RDCOUNT <512) { bFileEndFlag = true; }
// EA =1; // ComShowString(c_COM1,"Read Data Length is:"); // ComSendText(c_COM1,&RDCOUNT,2); LED3Pin = ~LED3Pin; //指示灯闪烁 // ComSendText(c_COM1,Sector_Buf,512); // pointer=0; PDataBuffPoint = Sector_Buf;
while(PDataBuffPoint < Sector_Buf+512) { if(CheckVS1003B_DRQ()) { Mp3SelectData();
VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++); VS1003B_WriteDAT(*PDataBuffPoint++);
Mp3DeselectData(); } else { if(!GetIR_Remote_Status()) //检测到红外线遥控信号的起始位 { IRProcess(); ucOldKeyValue = c_Key_NoUse; }
if(KbHit()) // { uchar ucKeyValue; ucKeyValue = KbGet(); if(ucKeyValue != ucOldKeyValue) //有新的按键时启动定时器 { TH0 = 0; TL0 = 0;
TR0 = 1; ucOldKeyValue = ucKeyValue; KbProcess(ucKeyValue); //按键处理 } else { if(TF0) //延时时间到 { //重新启动定时器 TH0 = 0; TL0 = 0; TR0 = 1; TF0=0; KbProcess(ucKeyValue); //按键处理 } } } } } //--------------------------------插入按键处理----------------------- #if 0 if(KbHit()) { if(KbHit()) //双保险,2级防抖 { uchar ucKeyValue; ucKeyValue = KbGet(); KbProcess(ucKeyValue); //按键处理 } // while(KbHit()); //等待按键释放 } #endif //--------------------------------按键处理结束--------------------------------- if (RDCOUNT < 512) { //读取到最后一包数据的处理 //判定当前播放的歌曲是否为Midi if(strcmp(ucFileExtNameString,"MID") == 0) { ComShowString(c_COM1,"Midi File End Process"); VS1003B_Fill2048Zero(); }
NowPlaying++; //指向下一曲。 MP3InitFlag = 1;
return; }
if (ChangeSong) { DataRead = 0; ChangeSong = 0; //判定当前播放的歌曲是否为Midi if(strcmp(ucFileExtNameString,"MID") == 0) { ComShowString(c_COM1,"Midi File End Process"); VS1003B_Fill2048Zero(); }
return; } } }
|
|