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

📄 mp3.c

📁 台湾凌阳方案300万数码相机源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
     XBYTE[0x266b] = 1;
     XBYTE[0x266b] = 0;

     for (i = 0; i < 10; i++)
     {     
          DELAY_1ms();
     }

     XBYTE[0x266b] = 1;     

     for (i = 0; i < 10; i++)
     {     
          DELAY_1ms();
     }

     //printf("write reset command\n");
	MP3_WriteCommandID(0x01, 0x00);	//Reset/Stop.

     //printf("wait FCEB1 high\n");
     MP3_WaitMPFCEB1High();

     //printf("initial table\n");
	MP3_InitTable();     

	//patch4.5@ada@for MP3 volume begin
     //MP3_WriteCommandID(G_MP3_Volume, 0x02);	//ID2: volume
     MP3_WriteCommandID(G_MP3_Volume, 0x12);	//ID2: volume
	//patch4.5@ada@for MP3 volume end
}

//---------------------------------------------------------------------------------------------------------------------------------------
//MP3_WriteCommandID
//---------------------------------------------------------------------------------------------------------------------------------------
//patch4.5@ada@for MP3 variable declaring begin
void MP3_WriteCommandID(UCHAR Cmd,UCHAR Id) USING_0
//void MP3_WriteCommandID(UCHAR Cmd,Id) USING_0
//patch4.5@ada@for MP3 variable declaring end
{
	if (Cmd != 0x01)	//dlchiou - 2002-12-11 11:29
	{
     	MP3_WaitMPFCEB1High();
	}
	
	MP3_SetTransferWordLength(1,K_DirToMP3);
	MP3_Write1WordToMP3(Cmd,Id);
     DELAY_10us();
     MP3_SendDummyClock();
}

//---------------------------------------------------------------------------------------------------------------------------------------
//MP3_SetTransferWordLength
//---------------------------------------------------------------------------------------------------------------------------------------
void MP3_SetTransferWordLength(USHORT Length,UCHAR Direction) USING_0
{
	XBYTE[0x2665] = Direction;	
	XBYTE[0x2668] = (UCHAR)((Length & 0xff00) >> 8);	//length high byte(in words)
	XBYTE[0x2667] = (UCHAR)(Length & 0x00ff);	     //length low byte(in words)
}

//---------------------------------------------------------------------------------------------------------------------------------------
//MP3_WaitMPFCEB1High
//---------------------------------------------------------------------------------------------------------------------------------------
void MP3_WaitMPFCEB1High(void) USING_0
{
     while ((XBYTE[0x2669] & 0x02) == 0);
}

//---------------------------------------------------------------------------------------------------------------------------------------
//MP3_WaitMPSIready
//---------------------------------------------------------------------------------------------------------------------------------------
void MP3_WaitMPSIready(void) USING_0
{
     while ((XBYTE[0x2669] & 0x01) == 0);
}

//---------------------------------------------------------------------------------------------------------------------------------------
//MP3_SendDummyClock
//---------------------------------------------------------------------------------------------------------------------------------------
void MP3_SendDummyClock(void) USING_0
{
     MP3_WaitMPSIready();
     XBYTE[0x266a] |= 0x02;   //Send 8 dummy clock
     MP3_WaitMPSIready();
}

//---------------------------------------------------------------------------------------------------------------------------------------
//MP3_Write1WordToMP3
//---------------------------------------------------------------------------------------------------------------------------------------
void MP3_Write1WordToMP3(UCHAR HighByte,UCHAR LowByte) USING_0
{
     MP3_WaitMPSIready();

	XBYTE[0x2660] = LowByte;
	XBYTE[0x2661] = HighByte;

     MP3_WaitMPSIready();
}

//---------------------------------------------------------------------------------------------------------------------------------------
//MP3_InitTable
//---------------------------------------------------------------------------------------------------------------------------------------
void MP3_InitTable(void) USING_0
{
     USHORT i;

	MP3_WriteCommandID(0x00, 0x0f);	//SInit
	MP3_SetTransferWordLength(256,K_DirToMP3);
	MP3_SendDummyClock();

	for (i = 0;i < 256; i++)
     {
		MP3_Write1WordToMP3(T_Parameter[i * 2 + 1],T_Parameter[i * 2]);
	}

     MP3_SendDummyClock();
}

//---------------------------------------------------------------------------------------------------------------------------------------
//MP3_PlayMP3Song
//---------------------------------------------------------------------------------------------------------------------------------------
void MP3_PlayMP3Song(ULONG DramAddr,USHORT FileIndex,USHORT startCluster) USING_0
{
     UCHAR sts;
     USHORT i,j;
     UCHAR name[12];
     USHORT fHandle;
     ULONG TempFileOffset;
     ULONG TempFileLength;
     UCHAR tmp1,tmp2;
     USHORT BufferSize;
     USHORT LoopCount;

	MP3_WriteCommandID(0x01, 0x00);	//Reset/Stop.

     DOS_SetCurrDir(G_USR_Mp3Dir1Cluster);

     USR_SetMp3Name(name,FileIndex);

     fHandle = File_Open(name, K_DOS_ReadFile, startCluster);

     TempFileOffset = 0;
     TempFileLength = G_DOS_FileSize;
     BufferSize = 8192/4;	//8192;	//MP3_DEBUG	;//dlchiou - 2002-12-11 11:21
     LoopCount = (USHORT)(BufferSize / 512);  //Put song in a 8K byte buffer

     MP3_WriteCommandID(0x02,0x00);	//ID0, State bit1: play music
     
     if (fHandle)
     {
     	while (TempFileLength > 0)
          {    
               UI_Mp3KeyFunction();

               if (G_Mp3KeyState != K_Play_Song)
               {
                    XBYTE[0x266b] = 1;
                    XBYTE[0x266b] = 0;     
                    DELAY_1ms();
                    XBYTE[0x266b] = 1;     

                    File_Close(fHandle, name, K_DOS_ReadFile, 0);     
                    DOS_SetCurrDir(G_USR_Mp3Dir1Cluster);
                    return;
               }

               sts = M_Card_File_Read(fHandle,K_DOS_DstDram,BufferSize,DramAddr,TempFileOffset);

               L2_DRAMSetStartAddr(DramAddr,K_SDRAM_Prefetch);

               for (j = 0; j < LoopCount; j++)
               {
                    //MP3_WaitMPFCEB1High();	//MP3_DEBUG	//dlchiou - 2002-12-11 11:23
     
                   	MP3_WriteCommandID(0x00, 0x06);	//ID6: data in

                   	MP3_SetTransferWordLength(256,K_DirToMP3);
     
                   	MP3_SendDummyClock();

             		if (TempFileLength >= 512)
                    {
					//MP3_DEBUG	BEGIN		//dlchiou - 2002-12-11 11:27
                       	for (i = 0; i < 256; i++)	//MP3_DEBUG	//dlchiou - 2002-12-11 11:25
                        {
                            //L2_DRAMReadWord(&tmp1,&tmp2);		//OLD
							//MP3_Write1WordToMP3(tmp2,tmp1);
							while(XBYTE[0x27b0]&0x01);			//NEW
     						MP3_WaitMPSIready();
							XBYTE[0x2660] = XBYTE[0x2700];
							XBYTE[0x2661] = XBYTE[0x2701];
                        }
						MP3_WaitMPSIready();
						//MP3_SendDummyClock();	//OLD
						XBYTE[0x266a] |= 0x02;
     					MP3_WaitMPSIready();
					//MP3_DEBUG	END		//dlchiou - 2002-12-11 11:27
					
                       	DramAddr += 256;    
   	                    TempFileLength -= 512;
                         TempFileOffset += 512;
                    }
                    else
                    {
                         if (TempFileLength % 2)
                         {
                  	          for (i = 0; i < (USHORT)(TempFileLength / 2); i++)
                              {
                                   L2_DRAMReadWord(&tmp1,&tmp2);
                                   MP3_Write1WordToMP3(tmp2,tmp1);
                              }

                              //Last byte
                              L2_DRAMReadWord(&tmp1,&tmp2);
                              MP3_Write1WordToMP3(0,tmp1);

                  	          for (i = 0; i < (USHORT)((512 - TempFileLength) / 2); i++)
                              {
                                   MP3_Write1WordToMP3(0,0);
                              }
                         }
                         else
                         {
                            	for (i = 0; i < (USHORT)(TempFileLength / 2); i++)
                              {
                                   L2_DRAMReadWord(&tmp1,&tmp2);
                                   MP3_Write1WordToMP3(tmp2,tmp1);
                              }

                  	          for (i = 0; i < (USHORT)((512 - TempFileLength) / 2); i++)
                              {
                                   MP3_Write1WordToMP3(0,0);
                              }
                         }

             	          TempFileLength = 0;
                         G_Mp3KeyState = K_Stop_Song;
                    }
               }
          }

          XBYTE[0x266b] = 1;
          XBYTE[0x266b] = 0;     
          DELAY_1ms();
          XBYTE[0x266b] = 1;     

 	     //MP3_WriteCommandID(0x01, 0x00);	//Reset/Stop.
     }

     File_Close(fHandle, name, K_DOS_ReadFile, 0);     

     DOS_SetCurrDir(G_USR_Mp3Dir1Cluster);

     //printf("Play end\n");
}
#endif

⌨️ 快捷键说明

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