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

📄 audiocodec.c

📁 凌阳MP3 spSPCA755yuanma
💻 C
字号:
/*++
Copyright (c) 2001 Sunplus Technology Co., Ltd.
Module Name:
        audiocodec.c
Abstract:
        Module related to AUDIO PLAY/RECORD
Environment:
        Keil C51 Compiler
Note:

Revision History:
        11/14/2002      ch chang    created
--*/
/*==================
  Headfile
====================*/
#include "general.h"
#include "main.h"
#include "storage.h"
#include "lcd1.h"
#include "spl10.h"
#include "L2_adsp.h"
#include "dosusr.h"
#include "doslink.h"
#include "uiflow.h"
#include "DSPui.h"
#include "Initio.h"

void WMA_Error_BitstreamProcessor(void);
bit                     _G_RecordNextFile=0;
data    BIT     _WMAFrameChange=0;
xdata   USHORT  G_FrameCounterCount;
xdata   USHORT  G_WMA_OldTime;
void Rep_AB();
/*============
  Code
==============*/
void Rep_AB_Goto_Apoint_To_Play()
{
	WORD tmp;

//	L2_DSP_SendCommandSet(DCMD_Pause);

	G_sectorNUM = G_ASectorNUM;             // Restore the A point sectornum     
	G_searchCluster = G_AsearchCluster;		// Restore the A point searchCluster
        
        L2_DSP_Write_DMem16(DSP_CmdReady, 0);   //@@chchang_021303
	//patch2.2.1@chamber
	if(G_DSPPrimeMODE==KDSP_DVRD_MODE)
		L2_DSP_DVRD_StopCommand();
	else
		L2_DSP_SendCommandSet(DCMD_Stop); 
	//end of patch2.2.1@chamber

  	do{                                                 
		tmp = L2_DSP_Read_DMem16(DSP_CmdReady);              
	}while(tmp!=1);   

#if (SPCA757_OPTION==0)
        if(_WMA==1)
        {//WMA  //@@chchang_020703 
        	
                MCUSTDAdress = 0; 
                L2_DSP_Write_DMem16(DSP_CmdReady, 0);
        	L2_DSP_SendCommandSet(DCMD_Play);   
                while(L2_DSP_Read_DMem16(DSP_CmdReady) != 1); 
                                                
               	L2_DSP_Write_DMem16(DSP_WMACrtlReg0,0);
       		L2_DSP_Write_DMem16(DSP_WMARndAcc,1);
       		L2_DSP_Write_DMem16(DSP_WMAPageCnt,G_sectorNUM);      
        }       
        else
#endif        
        {//MP3&ADPCM&G723
                L2_DSP_SetDecodeMode(G_DSPPrimeMODE);                                                                                                                                                				                         									                                                                 
               	MCUSTDAdress = 0;                                                                                  
                
                

		L2_DSP_Write_DMem16(DSP_CmdReady, 0);
		L2_DSP_SendCommandSet(DCMD_Play);
        	while(L2_DSP_Read_DMem16(DSP_CmdReady) != 1);                              

                if(G_DSPPrimeMODE==KDSP_DVRD_MODE)
                L2_DSP_Write_DMem24(DSP_PlayDvrFrac, G_AFrameCnt);
                else if (G_DSPPrimeMODE==KDSP_MP3_MODE)
		L2_DSP_Write_DMem24(DSP_FrameCnt, G_AFrameCnt);                                                     
                

        }                                                                       

}
//==================================================================================
//void Spectrum_DisplayRead(void);
//==================================================================================

void Audio_CoDec(void) USING_0
{
	UCHAR i;

	if(_G_UIPostError)	// UI post-processor error happen !!
	{
		// reset the state to IDLE state --
		_G_UIPostError = FALSE;		// reset the error flag
//		DbgPrint("UI error happened\n");
		if((G_STATE==STATE_PLAY)||(G_STATE==STATE_IDLE_PLAY))
		{
			if(G_PLAY_SeqMode == 0x02)
			{//repeat one
				//==initialize parameters==//
				G_STATE=STATE_IDLE;
			}
			else
			{
				//repeat all and no repeat
				if(G_FileCurrentIndex==G_USR_DirList[G_UIMODE].totalFile)
				{
					G_STATE=STATE_IDLE;//error happern,goto idle state
					G_FileCurrentIndex=1;
				}
				else
				{
					_G_Openfile = TRUE; // Make Openfile post-processor activity
					G_FileCurrentIndex=G_FileCurrentIndex+1;
				}
			}
		}
		else
		{//xyq 021228
			G_UIMODE=0x01; //return DVRD mode
			G_DSPPrimeMODE = KDSP_DVRD_MODE;
			if(G_STATE==STATE_RECORD)
			{
				if(_G_Storage_Full)
				{
					LCD10_Disp_Full();
					G_STATE=STATE_FLASH_FULL;
					G_Power_Off_Timer = 16;
				}
				else
				{
					G_STATE=STATE_IDLE;
				}
			}
		}
		return;
	}

	if((G_STATE==STATE_PLAY)||(G_STATE==STATE_IDLE_PLAY))
    //if(G_STATE==STATE_PLAY)
	{//1
		UCHAR sts;
	
//		DbgPrint("G_FileCurrentIndex=%x\n",G_FileCurrentIndex);    
#if (SPCA757_OPTION==0)                          
		WMA_Error_BitstreamProcessor();
#endif
		
		if(!G_end_of_file)
		{//A
			if((G_AB_Cnt==2) && (G_sectorNUM >= G_BSectorNUM))
			{
#if  (Auto_Repeat_OPTION==1)			
				if(_G_StudyFunc)
				{
					if(G_StudyRepTimes)
					{
						G_StudyRepTimes--;
						Rep_AB_Goto_Apoint_To_Play();//return to Apoint	to play
					}
					else
					{
						G_AB_Cnt=0;
						Rep_AB();
//						L2_DSP_Write_DMem16(DSP_SilenceST,0x0000);
//						G_AutoRepTimer=8;
						G_StudyRepTimes=1;
					}
				}
				else
#endif				
				{
					Rep_AB_Goto_Apoint_To_Play();//return to Apoint	to play
				}
			}

			if(L2_DSP_DMBuffer_Status()&0x01)// set to 1
			{//B
				//Catch data from flash card
				File_ReadToSram(G_sectorNUM, G_total_sectorNUM);
				G_sectorNUM++;
				//Fed data from MCU to DSP
				sts = L2_Data_MCU2DSP(G_DSPPrimeMODE); //mask it off
				if(sts)
				{//C
					//DbgPrint("Data In Command Error\n");
					return;
				}//C
                                                              
				//-- End of Post-Processor
			}//B
			else
			{
				if(_GPlayPause)
				{					 
					G_STATE=STATE_PLAY_PAUSE;
					sts = L2_DSP_SendCommandSet(DCMD_Pause); //mask it off
					if(sts)
					{//C
						return;
					}//C
				}
			
			}
			//patch3.04@chamber@Low_Bitrate begin
			L2_DSP_CheckSongTime(G_DSPPrimeMODE);
			//patch3.04@chamber@Low_Bitrate end
			//Spectrum_DisplayRead();

		} //A
		else
		{//A --- End of File for play
            File_Close(1, NULL, K_DOS_ReadFile, 0); //@@chchang_012703 
			L2_DSP_SendCommandSet(DCMD_EOF);
			//patch2.2.1@chamber

#if (SPCA757_OPTION==0)
			if(_WMA) 
				L2_DSP_WMA_PostProcessor();
			// end of patch2.2.1@chamber
#endif
			
			//-update the Timer again for more corrrective
			//L2_DSP_CheckSongTime(G_DSPPrimeMODE);
//			USER_DelayDT(4000);		// Delay 10mS for de-bounce

			//== play sequence mode procedure ==//

			if(G_PLAY_SeqMode == 0x02) //repeat one,
			{
				_G_Openfile = TRUE; // Make Openfile post-processor activity
			}else{
				if(G_FileCurrentIndex==G_USR_DirList[G_UIMODE].totalFile)
				{
					if(G_PLAY_SeqMode == 0x01) //repeat all,
					{
						_G_Openfile = TRUE; // Make Openfile post-processor activity
						G_FileCurrentIndex=1;

					}
					else	// Mode=0 , Single play,  stop play right now!
					{
						G_STATE=STATE_IDLE;
					
					}
				}
				else
				{
					_G_Openfile = TRUE; // Make Openfile post-processor activity
					G_FileCurrentIndex=G_FileCurrentIndex+1;
				}
			}
		}//A
	}//1
	else if (G_STATE==STATE_RECORD)
	{//1
		BYTE fileSts = TRUE;
		//        BYTE sts;
		if(!G_end_of_file)
		{//1B
			if(L2_DSP_DMBuffer_Status()&0x08)
			{//1C   
				L2_Data_DSP2MCU();
				fileSts = File_Write(1, K_DOS_SrcSram, 512, 0, 0);
				if(fileSts==FALSE)  //the FLASH card is full
				{
					_G_Storage_Full=1;
					G_end_of_file = TRUE;
					//DbgPrint("The FLASH card is full\n");
				}else{
					G_REC_fileSize += 512;
				}
				//record time count
				L2_DSP_EncTime_SecCount();
				// if only 2 cluster available then eof
				if (DOS_IsFreeAvailable() <= 2)
				{
					_G_Storage_Full=1;
///					DbgPrint("FreeAvailable<2\n");
					G_end_of_file = TRUE;
//					return;
				}

			}//1C			
		    //    if(!_G_Storage_Full)	// if Disk is full no more updating the Record data
			   DOS_IdleStuff();
		/*	if(G_W_OldTime>=5999)//no hour display, so when record to 99 minute,record next file
			{
				_G_RecordNextFile=1;
				G_end_of_file = TRUE;
			}
			else*/
			{
				_G_RecordNextFile=0;
			}
		}//1B
		else
		{//1B
		    if((_G_Storage_Full== FALSE)&&(_GRecordPauseAndStop==FALSE))	// if Disk is full no more updating the Record data
			{			   
				i = 0;
				//DbgPrint("Rec more\n");
				while (i < 4)
				{//**
					if ((L2_DSP_DMBuffer_Status()&0x08))
					{
						L2_Data_DSP2MCU();
						fileSts = File_Write(1, K_DOS_SrcSram, 512, 0, 0);
						if ((fileSts == FALSE) || (G_DOS_ErrCode != 0))
						{
							G_REC_fileSize += 512;
							break;
						}
						i++;
						//DbgPrint("record i=%bx\n",i);	
					}
					DOS_IdleStuff();			
				}//**.
				
			}
			// Close the file Creation
//			DbgPrint("G_DOS_FileWriteSize=%lx\n",G_DOS_FileWriteSize);
//			DbgPrint("G_REC_fileSize=%lx\n",G_REC_fileSize);
			USR_File_Close(/*G_DSPMinorMODE,*/ G_DOS_FileWriteSize, REC_name); 
			//==parameter initial==//
			G_EVENT=0;
			G_UIMODE=0x01; //return DVRD mode
			G_DSPPrimeMODE = KDSP_DVRD_MODE;
			//if(G_FileCurrentIndex<G_USR_DirList[G_UIMODE].totalFile)
			{
				G_FileCurrentIndex = G_USR_DirList[G_UIMODE].totalFile;
				UI_GetFileAttr();
			}
			if(_G_Storage_Full)
			{
				LCD10_Disp_Full();
				G_STATE=STATE_FLASH_FULL;
				G_Power_Off_Timer = 16; 
			}
			else
			{
				if(_G_RecordNextFile==1)
				{
					G_UIMODE=0x02;
					G_DSPPrimeMODE = KDSP_DVRE_MODE;
					LCD10_Disp_FileIndex_InDIR(G_USR_DirList[G_UIMODE-1].totalFile+1);
					_G_Openfile = TRUE; // Make Openfile post-processor activity
				}
				else
				{
					G_STATE=STATE_IDLE;
				}
				
			}
			_TClock = FALSE;
			L2_DSP_StopCommand();
//			L2_DSP_SendCommandSet(DCMD_Stop);
//			L2_DSP_DVRE_STOP_Processor();
		}//1B
	}//1
}

#if (SPCA757_OPTION==0)
void WMA_Error_BitstreamProcessor(void)
{
	USHORT 	tmp; 
	USHORT 	dbgTmp;
	USHORT 	Current_Time; 
	USHORT 	TimeOUT = 0xFFFF;                         
	ULONG 	stortmp;
	UCHAR	iLoop;

	//DbgPrint("G_end_of_file=%x\n", (USHORT)G_end_of_file);
	if(_WMA) //@@chchang_040203
	{				
		tmp=L2_DSP_Read_DMem16(0x3F51)&0xC0;
//		tmp&=0xC0;
//		DbgPrint("tmp=%x\n",tmp);
		if(tmp==0)
		{
//			L2_DSP_CheckSongTime(G_DSPPrimeMODE);
//			Current_Time=((USHORT)G_DISPLAY_Min*60+G_DISPLAY_Sec);
			Current_Time =L2_DSP_Read_DMem16(0x3fbd);																							
			if(G_WMA_OldTime!=Current_Time)
			{
				//_WMAFrameChange=0;							
				G_WMA_OldTime=Current_Time;
				G_FrameCounterCount=0;						
			}
			else
			{//G_WMA_OldTime=Current_Time
				G_FrameCounterCount++;
				if(G_FrameCounterCount==0xFFFF)
				{
//					DbgPrint("G_FrameCounterCount=%x\n",G_FrameCounterCount);
					L2_DSP_Write_DMem16(DSP_CmdReady, 0); 
					L2_DSP_SendCommandSet(DCMD_Stop); 
					//check command ready
    					do{                                                 
      						dbgTmp = L2_DSP_Read_DMem16(DSP_CmdReady); 
						TimeOUT --; 
						if(TimeOUT==0) 
        					{
						// DSP reset
							DSP_Initialize();
        						break;
        					}           
   					}while(dbgTmp!=1); 										
					G_end_of_file=true;
					G_FrameCounterCount=0;	
					L2_DSP_Write_DMem16(0x3CAE,0);			
				}								
			}
							
																				
		}
/*
		else if(tmp==0xC0)
		{	
			DbgPrint("0xc0 \n");
			L2_DSP_Write_DMem16(DSP_CmdReady, 0); 
			L2_DSP_SendCommandSet(DCMD_Stop); 					
			//check command ready
    			do{                                                 
    				dbgTmp = L2_DSP_Read_DMem16(DSP_CmdReady); 
				TimeOUT --; 
				if(TimeOUT==0) 
        			{
				// DSP reset
					DSP_Initialize();
               				break;
        			}           
   			}while(dbgTmp!=1); 
												
			G_end_of_file=true;						
			
		}													
*/
		else		// tmp =0x40 || 0x80
		{

			DbgPrint("0x40-0x80\n");

			L2_DSP_Write_DMem16(DSP_CmdReady, 0); 
			L2_DSP_SendCommandSet(DCMD_Stop); 						

			//check command ready
			do{                                                 
				dbgTmp = L2_DSP_Read_DMem16(DSP_CmdReady); 
				TimeOUT --; 
				if(TimeOUT==0) 
				{
				// DSP reset
					DSP_Initialize();
					break;
				}           
			}while(dbgTmp!=1); 

			L2_DSP_Write_DMem16(0x3CAE,0);			
			stortmp = G_sectorNUM+5;	// Skip the Error Bitstream

			_G_Openfile = TRUE;
			UI_EventPostDpc();		// Re-Open the current file !


			iLoop = 0;
			do
			{
				if(L2_DSP_DMBuffer_Status()&0x01)// set to 1
				{
	 				File_ReadToSram(G_sectorNUM, G_total_sectorNUM);
					G_sectorNUM++;
					L2_Data_MCU2DSP(G_DSPPrimeMODE); //mask it off                               
//					DbgPrint("xxxG_sectorNUM=%lx\n",G_sectorNUM);																

					iLoop ++;	
				}
			}
			while(iLoop!=0x05);

			L2_DSP_SendCommandSet(DCMD_Stop); 						

			G_sectorNUM = stortmp ;

			USER_DelayDT(30000);	
//			DbgPrint("stortmp=%lx\n",stortmp);																
//			DbgPrint("G_sectorNUM=%lx\n",G_sectorNUM);																

			G_searchCluster = USR_File_Seek(G_sectorNUM);				
			MCUSTDAdress = 0; 
			//Play continue                                    
			L2_DSP_SendCommandSet(DCMD_Play);                                                               			
			L2_DSP_Write_DMem16(DSP_WMACrtlReg0,0);
         		L2_DSP_Write_DMem16(DSP_WMARndAcc,1);
	       		L2_DSP_Write_DMem16(DSP_WMAPageCnt,G_sectorNUM);                      	
//			L2_DSP_SendCommandSet(DCMD_Play);                                                               			


		}
				
	}

}
#endif

/*
void Spectrum_DisplayRead(void)
{

	UCHAR	i;
	USHORT	StartAddress=0x3F67;	

//	for(i=0;i<=6;i++)
//	{
		//StartAddress +=i;
		DbgPrint(" %bx ",(UCHAR)L2_DSP_Read_DMem16(0x3F67));				
		DbgPrint(" %bx ",(UCHAR)L2_DSP_Read_DMem16(0x3F68));				
		DbgPrint(" %bx ",(UCHAR)L2_DSP_Read_DMem16(0x3F69));				
		DbgPrint(" %bx ",(UCHAR)L2_DSP_Read_DMem16(0x3F6A));				
		DbgPrint(" %bx ",(UCHAR)L2_DSP_Read_DMem16(0x3F6B));				
		DbgPrint(" %bx ",(UCHAR)L2_DSP_Read_DMem16(0x3F6C));				
		DbgPrint(" %bx ",(UCHAR)L2_DSP_Read_DMem16(0x3F6D));				
//	}
	DbgPrint(" \n ");				
	
}
*/

⌨️ 快捷键说明

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