|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2013-5-16 21:11:49
|
显示全部楼层
六、功能介绍
1.歌曲切换 ,音量控制,暂停,并加载字库
2.可以显示歌曲的名字
3. 可以显示图片 ,控制符号
4. 显示图片的数目
5. 显示解码时间
6. 显示歌曲数目
7. 显示播放符号
主功能函数:
void PlayTone()
{
uint8 min,sec;
uint16 i,j;
DWORD p;
uchar* buffer;
uint8 mode=0; //单曲重复
uint16 totalsect;
uint16 leftbytes;
uint16 count=0;
uint16 keylen;
uchar flag=1;
DWORD sector=0;
uint16 vol;
uint16 temp;
uchar vol_temp =99;
uint8 time[6];
uint16 decodetime;
songs=1; //启动时,播放第一首曲
if(totalsongs==0)
return; //如果没有歌曲则异常退出
unsigned long rand_val;
LongNameFlag=0; //显示短歌名
//---------------------------------------------------------------------
//---------------------------------------------------------------------
vol = (uint8)(255-(vol_temp*255)/100); //初始化声音
vol =(vol<<8) + vol;
VS1003B_SetVolume(vol);
//**********************************************************************
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
next:
if(type != MID)
VS1003B_Fill2048Zero();
count=0; //清基数
flag=1;
while(count<2048 && (type != MID)) //recommand 2048 zeros honoring DREQ befor soft reset
{ //用于从wma跳出到下一首歌,和一首歌结束填充数据//midi格式不需要
if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0)
{
for(j=0;j<32;j++)
{
VS1003B_WriteDAT(0x00); //填充0
count++;
}
if(count == 2047)break;
}
}
VS1003B_SoftReset(); //soft reset //in case of playing wma files//软件复位
//-----------------------------------------------------------------------------
//=============================歌曲类型判定程序部分=============================
//******************************************************************************
SearchMP3("\\MP3",&MusicInfo,&songs,&type); //搜索根目下的歌曲 不包含子目录
//SearchInit();
//Search(&MusicInfo,&songs,&type);
for(j=0;j<MAX_LONG_NAME_SIZE/2;j++) /* cut off the extension, only leave the name*/
{
if(((unsigned int*)LongNameBuffer)[j] == 0)
{
((unsigned int*)LongNameBuffer)[j-4] = 0;
break;
}
}
//-------------------------------------------------------------------------------------------
/****************************************************/
time[0] = '0';
time[1] = '0';
time[2] = ':';
time[3] = '0';
time[4] = '0';
time[5] = '\0';
decodetime = -1; /* for display the lyric which is at time 00:00 */
/******************************************************/
//--------------------------------------------------------------------------------------------
//------------------------------------显示歌曲名程序------------------------------------------
if(LongNameFlag)
{
if(HanziEnable)
{
buffer = malloc(MAX_LONG_NAME_SIZE);
if(buffer==0)
return 1;
i=0;
j=0;
while(1)
{
temp = ((unsigned int *)LongNameBuffer)[i++];
if(temp==0)
{
buffer[j++] = '.';
while(1)
{
temp = ((unsigned int *)LongNameBuffer)[i++];
if(temp == 0)
break; /* end */
buffer[j++] = (uint8)temp;
}
break;
}
else if(temp<0x80)
{
buffer[j++]=(uint8)temp;
}
else if(temp<0x4e00)
{
*((unsigned int*)&(buffer[j])) = "?";
j+=2;
}
else if(temp<0x9fa6)
{
if(Unicode_to_GBK((unsigned char *)&temp))return 1;
*((unsigned int*)&(buffer[j])) = temp;
j+=2;
}
else
{
*((unsigned int*)&(buffer[j])) = "?";
j+=2;
}
}
buffer[j] = 0;
BackColor=BLACK;
LCDRePain(10,100);
LCD_PrintfStr16(10,100,buffer,RED);
}
else
{
LCD_PrintfStr16(10,100,"显示失败!",RED);
}
}
else
{
for(j=0;j<8;j++)
{
if(MusicInfo.deName[j]==0x20)break;
LongNameBuffer[j]=MusicInfo.deName[j];
}
//LongNameBuffer[j++]='\0';
LongNameBuffer[j++]='.';
count = j+3;
for(count=0;count<3;count++)LongNameBuffer[j+count]=MusicInfo.deExtension[count];
LongNameBuffer[j+count]='\0';
if(HanziEnable)
{
BackColor=BLACK;
LCDRePain(10,100);
LCD_PrintfStr16(10,100,LongNameBuffer,RED);
}
else
{
LCD_PrintfStr16(10,100,"显示失败!",RED);
}
}
//-------------------------------------------------------------------------------------------
DisplaySongsNum(); //显示歌曲数目
Print_ICON1_12(150,15,0,RED,BLACK,1); //小喇叭
LCD_PutGB1616_String(10,200,"PLAY",RED,BLACK,1);
Print_ICON_12(100,200,0,RED,BLACK,1); //显示正在播放
LCD_PutGB1616_String(130,200,time,RED,BLACK,1);
//显示歌曲类型
switch(type)
{
case MP3:LCD_PutGB1616_String(10,15,"MP3",GREEN,BLACK,1);break;
case WMA:LCD_PutGB1616_String(10,15,"WMV",GREEN,BLACK,1);break;
case MID:LCD_PutGB1616_String(10,15,"MID",GREEN,BLACK,1);break;
case WAV:LCD_PutGB1616_String(10,15,"WAV",GREEN,BLACK,1);break;
default:break;
}
//=============================================================================================
//------------------------------------------播放歌曲程序部分==================================
//=============================================================================================
p = MusicInfo.deStartCluster+(((unsigned long)MusicInfo.deHighClust)<<16);//读文件首簇
totalsect = MusicInfo.deFileSize/512; //计算扇区数
leftbytes = MusicInfo.deFileSize%512; //计算剩余的字节数
i=0;
sector=0;
while(1)
{
//-----------------------------------------------------------------------
keylen=0;
for(;i<SectorsPerClust;i++) //一个簇 //a cluster
{
buffer=malloc(512);
FAT_LoadPartCluster(p,i,buffer); //读一个扇区 //read a sector
VS1003B_SPI_High(); //调到适合vs1003的速度
count=0;
while(count<512)
{
if(flag==0)
{
if(keylen)
{
delay_us(100);
keylen--;
}
}
else if(type == MID)
{
if(keylen)
{
delay_us(100);
keylen--;
}
}
if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 && flag)//根据需要送数据
{
for(j=0;j<32;j++)//每次送32个数据
{
VS1003B_WriteDAT(buffer[count]);
count++;
}
if(keylen) keylen--;//用于键处理
if(sector == totalsect && count >= leftbytes)//如果文件已结束
{
if(type == MID)//waiting the midi file was decoded
{//对于mid音乐要接着送2048个零
count=0;
while(count<2048)//recommand 2048 zeros honoring DREQ goto next songs
{
if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 )
{
for(j=0;j<32;j++)
{
VS1003B_WriteDAT(0x00);
count++;
}
if(count == 2047)break;
}
}
}
i=SectorsPerClust;
break;
}//文件结束
if(count == 511)
{
break;
}//512字节送完跳出
else if(VS1003B_ReadDecodeTime() != decodetime)
{
decodetime = VS1003B_ReadDecodeTime();
min = decodetime/60;
sec = decodetime%60;
if(min>99);
else if(HanziEnable)
{
time[0] = min/10 + 0x30;
time[1] = min%10 + 0x30;
time[3] = sec/10 + 0x30;
time[4] = sec%10 + 0x30;
LCD_PutGB1616_String(130,200,time,RED,BLACK,1);
}
else
{
time[0] = min/10 + 0x30;
time[1] = min%10 + 0x30;
time[3] = sec/10 + 0x30;
time[4] = sec%10 + 0x30;
LCD_PutGB1616_String(130,200,time,RED,BLACK,1);
}
}
}
//////////////////////////////键盘控制函数///////////////////////////////////////////
//------------------------------------------------------------------------------------
if(!(KEYIN&NEXT)) //下一曲
{
while(!(KEYIN&NEXT));
songs++;
if(songs > totalsongs)songs=1;
free(buffer);
goto next;
}
else if(!(KEYIN&PREV)) //上一曲
{
while(!(PINC&PREV));
songs--;
if(songs == 1)songs=totalsongs;
free(buffer);
goto next;
}
else if((KEYIN&STOP)==0 && keylen==0) //暂停
{
while(!(KEYIN&STOP));
keylen=10000;
if(flag)
{
flag=0;
BackColor=BLACK; //定义字体背景色
LCD_PutGB1616_String(10,200,"STOP",RED,BLACK,1);
Print_ICON_12(100,200,1,RED,BLACK,1); //显示暂停
}
else
{
flag=1;
BackColor=BLACK; //定义字体背景色
LCD_PutGB1616_String(10,200,"PLAY",RED,BLACK,1);
Print_ICON_12(100,200,0,RED,BLACK,1); //显示正在播放
}
}
else if((KEYIN&UP)==0 && keylen==0) //音量+
{
if(!(PINC&UP))
{
keylen=200;
vol=vol-((uint)(1<<8)+1);
if(vol<=0x0101) vol=0x0101;
else VS1003B_WriteCMD(0x0b,vol);
}
}
else if((KEYIN&DOWN)==0 && keylen==0) //音量-
{
if(!(KEYIN&DOWN))
{
keylen=200;
vol=vol+((uint)(1<<8)+1);
if(vol>=0xFEFE) vol=0xFEFE;
else VS1003B_WriteCMD(0x0b,vol);
}
}
////////////////////////////////////////////////////////////////////////////////////////
//--------------------------------------------------------------------------------------
}
sector++;
free(buffer);
}
i=0;
p=FAT_NextCluster(p); //重置簇内扇区计数
if(p == 0x0fffffff || p == 0x0ffffff8 || (FAT32_Enable == 0 && p== 0xffff))
{
if(mode==REPET_ALL)
songs++;
if(songs>totalsongs)
songs=1;
goto next;
}
}
}
Code:
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|