⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 mp3量不要让站长把时间都花费在为您修正说明上。压缩包解压时不能有密码。系统会自动删除debug和release目录
💻 C
📖 第 1 页 / 共 4 页
字号:
			{
				lrcaddr = LrcStruct_p->eeaddr;
				while(1)
				{
					temp = lrcdatbuf[lrcaddr++];
					//if(lrcaddr<MAXLRCDATSIZE)temp = lrcdatbuf[lrcaddr++];
					//else temp = eeprom_read_byte(lrcaddr++ - MAXLRCDATSIZE);
					if(temp == 0)break;
					uart0_putc(temp);
				}
				printf_P(("\r\n"));
				if(LrcStruct_p->next == 0)break;
				LrcStruct_p = LrcStruct_p->next;
			}
		#endif

	}
	else lrc = 0;
	#endif
	return 0;
}

#if 0
/*  put the time and lyric info to the teminal, for speed consideration we did not use printf_P() */
/*  format: [XX:XX] XXXXXXXXXXXXXXXX                                                              */
void putsLrc(unsigned char * time,unsigned char * lrcbuffer)
{
	uart0_putc(0x0d);
	uart0_putc(0x0a);
	uart0_putc('[');
	while(*time)	/* time */
	{
		uart0_putc(*time++);
	}
	uart0_putc(']');
	uart0_putc(0x20);
	while(*lrcbuffer)	/* lyric */
	{
		uart0_putc(*lrcbuffer++);
	}
}
#endif

uint8 PlayMusicwithKey()//播放音乐函数,一旦执行不会退出
{
#if 1
	uint16 keylen;			//用于键处理		//for key processing
	uint16 count;			//数据计数			//data counting
	uint8 i;				//循环变量			//loop variable
	uint16 j;				//循环变量			//loop variable
	DWORD p;				//簇指示值			//cluster
	DWORD totalsect;		//文件拥有的扇区数	//cotain the total sector number of a file
	uint16 leftbytes;		//剩余字节			//cotain the left bytes number of a file //the last cluster usually not fully occupied by the file
	uint8 *buffer;			//缓冲				//buffer
	DWORD sector;			//扇区				//recor the current sector to judge the end sector
	uint8 flag;				//播放/暂停标志		//flag of pause
	uint16 vol= DEFAULT_VOLUME;//初始音量,应与vs1003函数里的初始音量相同	//default volume
	uint8 vol_temp;
	uint16 songs=1;			//默认放第一首歌	//play the fist songs by default
	uint16 songs_cnt = 0;					//how many songs have been played
	uint8 mode=0;			//单曲重复			//repet all by default
	uint32 rand_val;
	
	uint8 total[6];	/* for total songs indication */
	uint8 current[12];	/* Current songs number */
	uint16 temp = totalsongs;

	uint8 time[6];
	uint16 decodetime;

	uint8 volume[3];
	uint8 min,sec;

        
	struct LrcStruct_s * LrcStruct_pp;
	uint16 lrcaddr;

	/* the display buffer (characters) */
	#define MAX_LRC_DISP 52
	uint8 lrcdata[MAX_LRC_DISP];
	uint8 lrcDisFlag = 0;	/* indicate if it need display lyric on the lcd */
	uint8 lrcCnt = 0;		/* lrcdata buffer count */

	ClearTrackInfo();

      
	printf_P(("\r\nCurrent mode : "));
	switch(mode)
	{
		case REPET_ALL: printf_P(("repet all"));break;
		case REPET_ONE:printf_P(("repet one"));break;
		case RANDOM:printf_P(("shuffle"));break;
	}

	if(totalsongs==0)//如果没有歌曲则异常退出	//if no music file return
	{
		lcdClrDisBuf();
		LCD_print12_P(0,20,("File not found!"));
		lcdUpdateDisplay();
		return 1; 
	}
	
/**********************************************/
	for(i=0;i<5;i++)
	{
		total[4-i] = temp%10;
		temp /= 10;
	}
	for(i=0;i<5;i++)
	{
		if(total[i])break;
	}
	for(j=0;j<5-i;j++)
	{
		total[j] = total[j+i] + 0x30;
	}
	total[j] = 0;
/**********************************************/
	vol_temp = 100-((DEFAULT_VOLUME & 0x00ff)*100/255);
	volume[0] = vol_temp/10 + 0x30;
	volume[1] = vol_temp%10 +0x30;    
	volume[2] = '\0'; 
/**********************************************/

	//Timer1_Initial();//启动定时器,用于产生随机函数的种子	//initialize the timer
next://下一首歌的起始地方						//label for "goto"

	if(mode==RANDOM)//随机播放歌曲 				//if the mode is shuffle the songs
	{
		songs_cnt++;
		if(songs_cnt == totalsongs && totalsongs<1025)
		{
			ClearTrackInfo();
			songs_cnt = 0;
		}
		rand_val = T0TC;

		srand(rand_val);
		if(totalsongs>1024)
		{
			songs = (uint16)(((unsigned long)rand()/2147483 * (unsigned long)totalsongs)/1000)+1;//随机产生歌曲序号	//create random song number
		}
		while(totalsongs<1025)
		{
			songs = (uint16)(((unsigned long)rand()/2147483 * (unsigned long)totalsongs)/1000)+1;//随机产生歌曲序号	//create random song number
			//iprintf("total = %ld  songs = %ld rand_max = %ld rand() = %ld\r\n",totalsongs,songs,RAND_MAX,rand());
			if(SetTrack(songs) == 0)break;
		}	
	}
	count=0;//清基数	//clear count
	flag=1;
	if(type != MID)VS1003B_Fill2048Zero();

	lrcDisFlag = 0;	/* clear the flag in case some lyric is not displayed of last songs */
	lrcCnt = 0;		/* clear the lrc count, maybe more lyric will display on one screen, for sometimes cpu do not have time to display the last one */
	//decodetime = -1;	
	//lcdInit();	/* the connection of the 3310lcd is not stable, so we reinitialize it every time */
	VS1003B_SoftReset();//soft reset //in case of playing wma files//软件复位

#if FIX_DIRECTORY
	Search((uint8 *)(MUSIC_PATH),&MusicInfo,&songs,&type);		//找到相应的文件		//find the file
#else
	Search(&lrcaddr,&MusicInfo,&songs,&type);		//找到相应的文件		//find the file
#endif

	/* here we use lrcaddr to get the record address in the eeprom which the file placed */

	for(j=0;j<MAX_LONG_NAME_SIZE/2;j++)			/* cut off the extension, only leave the name*/
	{
		if(((uint16 *)LongNameBuffer)[j] == 0)
		{
			((uint16 *)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 */
/******************************************************/
	temp = songs;
	for(i=0;i<5;i++)
	{
		current[4-i] = temp%10;
		temp /= 10;
	}
	for(i=0;i<5;i++)
	{
		if(current[i])break;
	}
	for(j=0;j<5-i;j++)
	{
		current[j] = current[j+i] + 0x30;
	}
	current[j++] = '/';
	for(i=0;i<6;i++)
	{
		current[j+i] = total[i];
	}
/********************************************************/	
	lcdClrDisBuf();
	switch(type)
	{
		case MP3:LCD_print12_P(0,0,("mp3"));break;
		case WMA:LCD_print12_P(0,0,("wma"));break;
		case MID:LCD_print12_P(0,0,("mid"));break;
		case WAV:LCD_print12_P(0,0,("wav"));break;
		default:break;
	}
	Print_ICON_12(18,0,Playing);
	LCD_print12(30,0,current);
	switch(mode)
	{
		case REPET_ALL:Print_ICON_12(72,0,RepetAll);break;
		case REPET_ONE:Print_ICON_12(72,0,RepetOne);break;
		case RANDOM   :Print_ICON_12(72,0,Shuffle);break;
		default:break;
	}
/*****************************************************/
	//LCD_print12(30,36,time);
	//LCD_print12(72,36,volume);
	//Print_ICON_12(60,36,Speaker);
	//Print_ICON_12(0,12,Music);	
/******************************************************/
	if(LongNameFlag)
	{
		if(HanziEnable)	/* if HanziEnable, convert the long name from unicode to GBK */
		{
			buffer = malloc(MAX_LONG_NAME_SIZE);
			if(buffer == 0)return 1;
			i = 0;
			j=0;
			while(1)
			{
				temp = ((uint16 *)LongNameBuffer)[i++];
				/*  you may confused about following code, because at previous we set "." to 0 for lry search*/
				if(temp == 0 )
				{
					buffer[j++] = '.';
					while(1)	/*copy the extention */
					{
						temp = ((uint16 *)LongNameBuffer)[i++];
						if(temp == 0)break;	/* end */
						buffer[j++] = (uint8)temp;
						
					}
					break;
				}
				else if (temp<0x80)
				{
					buffer[j++]=(uint8)temp;
				}
				else if(temp<0x4e00)
				{
					put16_little(&buffer[j],'?');
					j+=2;
				}
				else if(temp<0x9fa6)
				{
					if(Unicode_to_GBK((uint8 *)&temp))return 1;
					put16_little(&buffer[j],temp);
					j+=2; 
				}
				else
				{
					put16_little(&buffer[j],'?');
					j+=2;
				}
			}
			buffer[j] = 0;
			LCD_print12(12,12,buffer);
			//LCD_print_unicode12(12,12,(unsigned int *)LongNameBuffer);
		}
		else
		{
			LCD_print12_P(0,12,("-- --By bozai\nFirmware lost!"));
		}
	}
	else 	/* short name */
	{
		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)LCD_print12(12,12,LongNameBuffer);
		else
		{
			LCD_print12_P(0,12,("    -By bozai\nFirmware lost!"));
		}
	} 
/*************************************************************/
	LCD_print12(30,36,time);
	LCD_print12(72,36,volume);
	Print_ICON_12(60,36,Speaker);
	Print_ICON_12(0,12,Music);	
	lcdUpdateDisplay();
/**************************************************************/

	printf_P(("\r\nNow playing "));
	printf_P(("%s :"),current);
	if(LongNameFlag && HanziEnable)
	{
		printf_P(("%s"),buffer);
		free(buffer);
	}
	else
	{
		for(j=0;j<8;j++)
		{
			if(MusicInfo.deName[j]==0x20)break;
			uart0_putc(MusicInfo.deName[j]);
		}
        
		uart0_putc('.');
		for(j=0;j<3;j++)
		{
			//if(MusicInfo.deName[j]==0x20)break;
			uart0_putc(MusicInfo.deExtension[j]);
		}
	}
	printf_P("\r\n");
/**************************************************************/
#if FIX_DIRECTORY
	LrcProc(LongNameBuffer);
#else
	LrcProc(LongNameBuffer,lrcaddr);			/* search lyc file */
											/* lrcaddr indicate the record address of eeprom */
											/* first search the current folder then the default */
#endif											
	LrcStruct_pp = LrcStructHead.header;

/**************************************************************/

	p     = get16_little(MusicInfo.deStartCluster)+(((uint32)get16_little(MusicInfo.deHighClust))<<16);//读文件首簇	//the first cluster of the file
		
	totalsect = get32_little(MusicInfo.deFileSize)/512; //计算扇区数			//calculate the total sectors
	leftbytes = get32_little(MusicInfo.deFileSize)%512; //计算剩余的字节数	//calculate the left bytes	
	i=0;
	sector=0;

	if(lrc && HanziEnable)		/* clear the previous time area */
	{
		if(LrcStruct_pp->time/1000 == 0 && LrcStruct_pp != 0)/* see if it has lyric at time 00:00 */
		{
			
			decodetime = -1;	/* for display the lyric which is at time 00:00 */
		}
		else
		{
			decodetime = 0;		/* otherwise, it will not flush screen when 00:00, then you can see the filename and other info for 1 second */
		}
		LCD_print12_P(36,36,("    "));
		lcdClrDisBuf(); 
	}
    
	while(1)
	{
		keylen=0;
		for(;i<SectorsPerClust;i++)		//一个簇	//a cluster
		{
			buffer=malloc(512);
			FAT_LoadPartCluster(p,i,buffer);//读一个扇区	//read a sector												
			count=0;
			while(count<512)
			{
				if(flag==0){if(keylen){Delay(100);keylen--;}}
				else if(type == MID){if(keylen){Delay(100);keylen--;}}

				if(VS1003B_NeedData() && flag)	//根据需要送数据  //send data  honoring DREQ
				{
					VS1003B_Write32B(&buffer[count]);
					count += 32;
					if(keylen)keylen--;			//用于键处理			//for key processing
					if(sector == totalsect && count >= leftbytes)		//如果文件已结束		//if this is the end of the file
					{
						if(type == MID)//waiting the midi file was decoded
							VS1003B_Fill2048Zero();
						i=SectorsPerClust;
						break;
					}//文件结束			//file ended
					if(count == 511){break;}//512字节送完跳出		//break if a sector was sent
				}
				else if(VS1003B_ReadDecodeTime() != decodetime)
				{
					decodetime = VS1003B_ReadDecodeTime();
					min = decodetime/60;
					sec = decodetime%60;
					if(lrc)
					{ 
						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_print12_fast(54,36,time);
						} 
						else
						{
							time[0] = min/10 + 0x30;
							time[1] = min%10 + 0x30;
							time[3] = sec/10 + 0x30;
							time[4] = sec%10 + 0x30;
							LCD_print12_fast(30,36,time);
						}
						while(1)
						{
							if(LrcStruct_pp->time/1000 <= decodetime && LrcStruct_pp != 0)
							{
								lrcaddr = LrcStruct_pp->eeaddr;
								while(1)
								{
									//if(lrcaddr<MAXLRCDATSIZE)temp = lrcdatbuf[lrcaddr++];
									//else temp = eeprom_read_byte(lrcaddr++ - MAXLRCDATSIZE);
									temp = lrcdatbuf[lrcaddr++];
									if(temp == 0)
									{
										break;
									}
									if(lrcCnt<MAX_LRC_DISP-1)lrcdata[lrcCnt++] = temp;
								}
								lrcdata[lrcCnt] = '\n';
								LrcStruct_pp = LrcStruct_pp->next;
							}
							else
							{
								if(lrcCnt && HanziEnable)
								{
									lcdClrDisBuf(); 
									lrcdata[lrcCnt] = '\0';
									printf_P(("[%s] %s\r\n"),time,lrcdata);
									//putsLrc(time,lrcdata);	/* faster string put */

									lrcDisFlag = 1;	/* we do not display the lyric now, it will display at next time */
													/* then it will not take many time to process the lyric          */
													/* otherwise, when playing 320Kbps file, glitch may occurs       */
									
									//LCD_print12_fast(0,0,lrcdata);
									//LCD_print12_fast(54,36,time);
								}
								else if(lrcCnt)
								{
									lrcdata[lrcCnt] = '\0';
									printf_P(("[%s] %s\r\n"),time,lrcdata);
									LCD_print12_fast(30,36,time);
								}
								break;
							}
						}
						lcdUpdateDisplay();
					}
					else
					{
						if(min>99);
						else
						{
							time[0] = min/10 + 0x30;
							time[1] = min%10 + 0x30;
							time[3] = sec/10 + 0x30;
							time[4] = sec%10 + 0x30;
							LCD_print12(30,36,time);
							lcdUpdateDisplay();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -