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

📄 l2_audio.c

📁 台湾凌阳方案300万数码相机源代码
💻 C
📖 第 1 页 / 共 2 页
字号:

		XBYTE[0x2019] = 0x20; // P1 as probe signal
		XBYTE[0x20e1] = 0x06; // audio probe
		XBYTE[0x26e0] = 0x18; // dacdout

		L2_InitEmbAudCodec(1); // play

//		i = 0;
//		while(1)
//		{
//			XBYTE[0x2600] = (UCHAR) i;
//			i++;
//		}
		//----------------------------------------
		// DRAM configuration


		if (Decompression == 0x01)
			XBYTE[0x2680] = 0x02;

		// return
        return(status);
}




//-----------------------------------------------------------------------------
//L2_RecordAud
//-----------------------------------------------------------------------------
/*
routine description:
		Record the audio data from the codec in DRAM at the specific address.
arguments:
				DRAMAddr	DRAM address where the sound file resides.
				AudBufSize	0: 1K bytes
								1: 2K bytes
								2: 4K bytes
								3: 8K bytes
				AudFormat	Bit[0]: channel
										0: mono
										1: stereo
								Bit[1]: resolution
										0: 8bit per sample
										1: 16bit per sample
								Bit[2]: pcm format
										0: pcm
										1: pcm8
								Bit[3]: reserved
								Bit[5-4]: downsample mode
										0: no downsample
										1: 1/2 downsample
										2: 1/6 downsample
								Bit[6]: compression
										0: non-compression
										1: IMA-ADPCM compression
								Bit[7]: reserved


return value:
		0x00	- success
		others	- error
*/

UCHAR L2_RecordAud(ULONG DRAMAddr, UCHAR AudBufSize, UCHAR AudFormat)
{
        UCHAR status = L2K_SUCCESS;
		UCHAR Compression = 0x00;

	   	//----------------------------------------
		// Audio configuration

		L2_StopAud();

		XBYTE[0x2605] = 0x03; // ADC/AC97-to-DRAM
//		XBYTE[0x2605] = 0x01; // ADC/AC97-to-CPU
		if((AudFormat&0x40)==0x40)
			Compression = 0x01;
		else
			Compression = 0x00;
		if(Compression == 0x01)
			AudFormat |= 0x02; // Aud16bit for compression mode

		AudFormat = AudFormat & 0xbf;
                //PRINT_L2("Audformat = %bx\n", AudFormat);
		XBYTE[0x2606] = AudFormat;

//#ifdef EmbCodec
#if (EmbCodec)
		L2_InitEmbAudCodec(0);
		//XBYTE[0x26e3] = 0x01; // audtestmode
#endif
//#ifdef	AC97
#if (AC97)
		L2_InitAC97();
#endif

		//----------------------------------------
		// DRAM configuration

		XBYTE[0x273A] = (UCHAR)DRAMAddr; // Audio buffer start address
		XBYTE[0x273B] = (UCHAR)(DRAMAddr>>8); // Audio buffer start address
		XBYTE[0x273C] = (UCHAR)(DRAMAddr>>16); // Audio buffer start address


		XBYTE[0x27A1] = 0x40; // Set audcliprst

		XBYTE[0x2723] = AudBufSize; // Set DRAM audio buffer size

		//Joe@2003.3.12 9:21 add begin
		//XBYTE[0x2000] = 0x00;
		//Joe@2003.3.12 9:22 add end

		//XBYTE[0x2000] = 0x03; // Set videoclip mode


		//----------------------------------------
		// Clear AudBuf and Set ADPCM Codec

		XBYTE[0x26a0] = 0x02; // Clear 1K AudBuf(SRAM)

		if (Compression == 1)
			XBYTE[0x2680] = 0x01; // Enable ADPCM encoder

		XBYTE[0x273E] = 0x03; // Set audclip enable and auddir=1

		// return
        return(status);
}


//-----------------------------------------------------------------------------
//L2_RecordAudDMAMode
//-----------------------------------------------------------------------------
/*
routine description:
		Record the audio data from the codec with DMA
arguments:
				DRAMAddr	DRAM address where the sound file resides.
				AudFormat	Bit[0]: channel
										0: mono
										1: stereo
								Bit[1]: resolution
										0: 8bit per sample
										1: 16bit per sample
								Bit[2]: pcm format
										0: pcm
										1: pcm8
								Bit[3]: reserved
								Bit[5-4]: downsample mode
										0: no downsample
										1: 1/2 downsample
										2: 1/6 downsample
								Bit[6]: compression
										0: non-compression
										1: IMA-ADPCM compression
								Bit[7]: reserved


return value:
		0x00	- success
		others	- error
*/

UCHAR L2_RecordAudDMAMode(UCHAR AudFormat)
{
        UCHAR status = L2K_SUCCESS;
		UCHAR Compression = 0x00;

	   	//----------------------------------------
		// Audio configuration
		L2_StopAud();

		XBYTE[0x2605] = 0x05; // ADC/AC97-to-DMAC
//		XBYTE[0x2605] = 0x01; // ADC/AC97-to-CPU
		if((AudFormat&0x40)==0x40)
			Compression = 0x01;
		else
			Compression = 0x00;
		if(Compression == 0x01)
			AudFormat |= 0x02; // Aud16bit for compression mode

		AudFormat = AudFormat & 0xbf;
                //PRINT_L2("AudFormat = %bx\n", AudFormat);
		XBYTE[0x2606] = AudFormat;


//#ifdef EmbCodec
#if (EmbCodec)
//		XBYTE[0x26e3] = 0x01; // audtestmode
		L2_InitEmbAudCodec(0);
#endif
//#ifdef	AC97
#if (AC97)
		L2_InitAC97();
#endif

		//----------------------------------------
		// Clear AudBuf and Set ADPCM Codec

		XBYTE[0x26a0] = 0x02; // Clear 1K AudBuf(SRAM)

		if (Compression == 1)
			XBYTE[0x2680] = 0x01; // Enable ADPCM encoder

		// return
        return(status);
}


//-----------------------------------------------------------------------------
//L2_StopAud
//-----------------------------------------------------------------------------
/*
routine description:
		Stop the audio record/play process and disable the
		corresponding codec.
arguments:
		Play	- 0: record. Enable the embedded ADC
				  1: play. Enable the embedded DAC

return value:
		0x00	- success
		others	- error
*/

UCHAR L2_StopAud(void)
{
        UCHAR status = L2K_SUCCESS;


	//----------------------------------------
	// Stop ADC
	XBYTE[0x2670] = 0x01; // Disable ADC
	XBYTE[0x2671] = 0x01; // Mute ADC
	XBYTE[0x2675] = 0x00; // Disable DAC
	XBYTE[0x2605] = 0x00; // AudBuf Mode
	XBYTE[0x2606] = 0x00;
	XBYTE[0x26a0] = 0x02; // Clear buffer
	XBYTE[0x2674] = 0x00;

	//----------------------------------------
	// Stop ADPCM Codec
	XBYTE[0x2680] = 0x00;

	//----------------------------------------
	// Reset DMAC (only for testing)
	//XBYTE[0x2301] = 0x00;
	//XBYTE[0x2304] = 0x01;
	//XBYTE[0x2304] = 0x00;

	//----------------------------------------
	// Reset DRAM related registers
	XBYTE[0x27A1] = 0x40;

	//Joe@2003.3.12 9:21 add begin
	//XBYTE[0x2000] = 0x00;
	//Joe@2003.3.12 9:22 add end

	//XBYTE[0x2000] = 0x00;
	XBYTE[0x273d] = 0x00;
	XBYTE[0x273e] = 0x00;



    return(status);
}

//-----------------------------------------------------------------------------
//L2_RecordAudToDRAM
//-----------------------------------------------------------------------------
/*
routine description:
		Record To DRAM
arguments:
				DRAMAddr	DRAM address where the sound file resides.
				AudBufSize	0: 1K bytes
								1: 2K bytes
								2: 4K bytes
								3: 8K bytes
				AudFormat	Bit[0]: channel
										0: mono
										1: stereo
								Bit[1]: resolution
										0: 8bit per sample
										1: 16bit per sample
								Bit[2]: pcm format
										0: pcm
										1: pcm8
								Bit[3]: reserved
								Bit[5-4]: downsample mode
										0: no downsample
										1: 1/2 downsample
										2: 1/6 downsample
								Bit[6]: compression
										0: non-compression
										1: IMA-ADPCM compression
								Bit[7]: reserved

return value:
		0x00	- success
		others	- error
*/

UCHAR L2_RecordAudToDRAM(ULONG DRAMAddr, UCHAR AudBufSize, UCHAR AudFormat)
{
		ULONG AudBufCnt;
		ULONG AudBufFullCnt;
        UCHAR status = L2K_SUCCESS;
//		ULONG i;
//		UCHAR j;

		L2_RecordAud(DRAMAddr, AudBufSize, AudFormat);

		if (AudBufSize == 0)
			AudBufFullCnt = 1024;
		else if (AudBufSize == 1)
			AudBufFullCnt = 2048;
		else if (AudBufSize == 2)
			AudBufFullCnt = 4096;
		else if (AudBufSize == 3)
			AudBufFullCnt = 8192;
		else if (AudBufSize == 4)
			AudBufFullCnt = 128;


//		for (i=0;i<8193;i++)
//		{
//			XBYTE[0x26e4] = (UCHAR)i;
                        //PRINT_L2("i = %bx\n", (UCHAR)0xff);

//			XBYTE[0x26e3] = 0x03;
			//AudBufCnt = ((ULONG)XBYTE[0x27b4]<<8) | ((ULONG)XBYTE[0x27b3]);
                        //PRINT_L2("AudBufCnt = %lx\n", AudBufCnt);
//		}

//		for (i=0;i<0x8;i++)
//		{
                        //PRINT_L2("AudData = %lx\n", (ULONG)XBYTE[0x2600]);
//		}

		AudBufCnt = ((ULONG)XBYTE[0x27b4]<<8) | ((ULONG)XBYTE[0x27b3]);
		//("AudBufFullCnt = %lx\n", (ULONG)AudBufFullCnt);
                //PRINT_L2("AudBufCnt = %lx\n", (ULONG)AudBufCnt);
		while(AudBufCnt != AudBufFullCnt)
		{
			AudBufCnt = ((ULONG)XBYTE[0x27b4]<<8) | ((ULONG)XBYTE[0x27b3]);
                        //PRINT_L2("AudBufCnt = %lx\n", AudBufCnt);
		}

		L2_StopAud();

		status = 0;
        return(status);
}



//-----------------------------------------------------------------------------
//L2_PlayAudFromDRAM
//-----------------------------------------------------------------------------
/*
routine description:
		Play the audio data in the SDRAM to the audio codec.

arguments:
				DRAMAddr	DRAM address where the sound file resides.
				AudBufSize	0: 1K bytes
								1: 2K bytes
								2: 4K bytes
								3: 8K bytes
				AudFormat	Bit[0]: channel
										0: mono
										1: stereo
								Bit[1]: resolution
										0: 8bit per sample
										1: 16bit per sample
								Bit[2]: pcm format
										0: pcm
										1: pcm8
								Bit[3]: compression
										0: non-compression
										1: IMA-ADPCM compression
								Bit[7-4]: reserved
				PlayFreq		Play frequency.
								0: 48KHz
								1: 24KHz
								2: 8KHz


return value:
		0x00	- success
		others	- error
*/

UCHAR L2_PlayAudFromDRAM(ULONG DRAMAddr, UCHAR AudBufSize, UCHAR AudFormat, UCHAR PlayFreq )
{
        UCHAR status = L2K_SUCCESS;
		ULONG AudBufCnt;
                //PRINT_L2("check1");
		//while(1);
		//XBYTE[0x2676] = 0x5;

		L2_PlayAud(DRAMAddr, AudBufSize, AudFormat, PlayFreq);
		AudBufCnt = ((ULONG)XBYTE[0x27b4]<<8) | ((ULONG)XBYTE[0x27b3]);
                //PRINT_L2("AudBufCnt before enable 0x273e = %lx\n", AudBufCnt);
		XBYTE[0x273E] = 0x01; // Set audclip enable and auddir=0
		AudBufCnt = ((ULONG)XBYTE[0x27b4]<<8) | ((ULONG)XBYTE[0x27b3]);
                //PRINT_L2("AudBufCnt after enable 0x273e = %lx\n", AudBufCnt);

		//while(1);
		while(AudBufCnt != 0x00)
		{
			AudBufCnt = ((ULONG)XBYTE[0x27b4]<<8) | ((ULONG)XBYTE[0x27b3]);
                        //PRINT_L2("AudBufCnt = %lx\n", AudBufCnt);
		}

//		L2_StopAud();

        return(status);
}


//-----------------------------------------------------------------------------
//L2_ReadAudBufCnt
//-----------------------------------------------------------------------------
/*
routine description:
		Read the number of data in the audio buffer(SRAM)
arguments:
		pAudBufCnt - pointer to the AudBufCnt
return value:
		0x00	- success
		others	- error
*/

UCHAR L2_ReadAudBufCnt(ULONG *pAudBufCnt)
{


	*pAudBufCnt = ((ULONG)XBYTE[0x26b5]<<8) | ((ULONG)XBYTE[0x26b4]);

    return L2K_SUCCESS;
}


//-----------------------------------------------------------------------------
//L2_ReadDRAMAudBufCnt
//-----------------------------------------------------------------------------
/*
routine description:
		Read the number of data in the audio buffer(DRAM)
arguments:
		pDRAMAudBufCnt - pointer to the AudBufCnt
return value:
		0x00	- success
		others	- error
*/

UCHAR L2_ReadDRAMAudBufCnt(ULONG *pDRAMAudBufCnt)
{


	*pDRAMAudBufCnt = ((ULONG)XBYTE[0x27b4]<<8) | ((ULONG)XBYTE[0x27b3]);

    return L2K_SUCCESS;
}



//-----------------------------------------------------------------------------
//L2_SetDRAMAudDMACnt()
//-----------------------------------------------------------------------------
/*
routine description:
		Enable/disable the DRAM Audio DMA counter
arguments:
		Enable 	0: disable the DRAM Audio DMA counter
				1: enable the DRAM Audio DMA counter
return value:
		0x00	- success
		others	- error
*/

UCHAR L2_SetDRAMAudDMACnt(UCHAR Enable)
{


	XBYTE[0x273D] = Enable;

    return L2K_SUCCESS;
}



#ifdef TestModeEn

UCHAR L2_TestAudio(UCHAR TestLevel)
{
	UCHAR Temp0= TestLevel;
       UCHAR status = L2K_SUCCESS;
		UCHAR i;
		ULONG SRAMAddr;

		//body

		// Audio SRAM Test
		XBYTE[0x20E0]=0x00; // Disable CPUSRAMEn
		XBYTE[0x26E1]=0x00; // Aud Page Selection: page 0
		XBYTE[0x20E0]=0x02; // Enable CPUSRAMEn
		for(SRAMAddr=0x2600;SRAMAddr<0x26FF;SRAMAddr++)
        	XBYTE[SRAMAddr] = 0x55;
		for(SRAMAddr=0x2600;SRAMAddr<0x26FF;SRAMAddr++)
        	if(XBYTE[SRAMAddr]!=0x55) status = 1;
		for(SRAMAddr=0x2600;SRAMAddr<0x26FF;SRAMAddr++)
        	XBYTE[SRAMAddr] = 0xAA;
		for(SRAMAddr=0x2600;SRAMAddr<0x26FF;SRAMAddr++)
        	if(XBYTE[SRAMAddr]!=0xAA) status = 1;
		for(SRAMAddr=0x2600;SRAMAddr<0x26FF;SRAMAddr++)
        	XBYTE[SRAMAddr] = 0xFF;
		for(SRAMAddr=0x2600;SRAMAddr<0x26FF;SRAMAddr++)
        	if(XBYTE[SRAMAddr]!=0xFF) status = 1;
		for(SRAMAddr=0x2600;SRAMAddr<0x26FF;SRAMAddr++)
        	XBYTE[SRAMAddr] = 0x00;
		for(SRAMAddr=0x2600;SRAMAddr<0x26FF;SRAMAddr++)
        	if(XBYTE[SRAMAddr]!=0x00) status = 1;

		i=0;
		for(SRAMAddr=0x2600;SRAMAddr<0x26FF;SRAMAddr++)
		{
        	XBYTE[SRAMAddr] = i;
			i++;
		}
		i=0;
		for(SRAMAddr=0x2600;SRAMAddr<0x26FF;SRAMAddr++)
		{
        	if(XBYTE[SRAMAddr]!=i) status = 1;
			i++;
		}

		//if (status==1) P1 = 0xf0;

		return L2K_SUCCESS;
}

#endif

⌨️ 快捷键说明

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