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

📄 test_sound.c

📁 Taiwan sunplus develop spce3200, it is a test program ----- testboard source code
💻 C
字号:
//====================================================================================
//File Name:	Test_Sound.c
//Description:	Sound test
//Update:		V1.0 by wangtao <wangtao@sunnorth.com.cn>
//====================================================================================
#include "SystemHeader.h"
#include "string.h"

void Test_PlaySound(void)
{
	short x, y;
	int i;
	short Channel = 2;
	TFT_SetBGColor(COLOR_WHITE);
	TFT_SetWindow(40, 40, 279, 199);
	TFT_SetColor(COLOR_RED);
	TFT_Rectangle(0, 0, 239, 159, PAINT_HOLLOW);
	TFT_SetColor(COLOR_BLUE);
	TFT_SetTextPos(50, 30);
	TFT_SetTextPos(40, 80);
	TFT_Print("Click any position on the screen to return");
	SP_Wave_Init();
	while(1)
	{
		if(SP_Play_Status()==0)
		{
			TFT_SetTextPos(30, 30);
			if(Channel==1)
			{
				TFT_Print("Right channel is playing sound...\n");
				Channel = 2;
			}
			else
			{
				TFT_Print("Left channel is playing sound...\n");
				Channel = 1;
			}	
			SP_Wave_Setup((unsigned short *)RES_TESTSOUND_WAV,(unsigned short *)RES_TESTSOUND_WAV_END,8000, Channel);			
		}
		Touch_Get(&x, &y);
		if(x!=-1)
		{
			SP_Wave_Stop();
			for(i=0; i<1000000; i++);
			break;
		}
	}
	TFT_SetBGColor(0x0001);
	TFT_SetWindow(0, 0, TFT_WIDTH-1, TFT_HEIGHT-1);
}

void Test_Record(void)
{
	unsigned int i,k;
	unsigned int DataSizes;
	unsigned char *PCMDataPtr;
	unsigned char StreamPtr[(DATANUM_COUNT * DATANUM_SIZES)*4];

	TFT_SetBGColor(COLOR_WHITE);
	TFT_SetWindow(40, 40, 279, 199);
	TFT_SetColor(COLOR_RED);
	TFT_Rectangle(0, 0, 239, 159, PAINT_HOLLOW);
	TFT_SetColor(COLOR_BLUE);
	TFT_SetTextPos(20, 30);
	TFT_Print("Sound input from MIC is outputted via speaker");
	TFT_SetTextPos(20, 80);
	TFT_Print("Automatically return 10 seconds later");
	SP_Wave_Init();

    	//MIC init
	MIC32Init(16000);        										//Sample rate 16000Hz, use IRQ33
	//DAC init and On
	DAC_EnableSoftCh(16000); 										//Sample rate 16000Hz, use IRQ63
	         
	k=0;
	while(k++<0x100000)
    {            
                
		DataSizes = MICGetBuffSizes(); 								//Get Data pool sizes (bytes) in AUDIO_PCM_BUFFER
		           
		PCMDataPtr = (unsigned char *) MICGetDataPtr(DataSizes);	//Request Data and return pointer  
				      	                                			//The return pointer is the start address of data pool.
				      	                                		              				    
		if(PCMDataPtr==MIC_DATA_NOT_ENOUGH)
		{				     	
			DataSizes = 0; 											//Must clear DataSizes to prevent fill duplicate data
		}
			    
		for(i=0;i<DataSizes;i++)
		{
			StreamPtr[i] = PCMDataPtr[i];
		}
			
		if(DAC_Get_PCM_Free_Bytes() > DataSizes) 					//Make sure DAC PCM buffer has enough space to store data
		{
																	//According to PCMDataPtr(Source data pointer) and DataSizes  requested by users, put the data to DAC PCM data pool                    
			DAC_Write_PCM_Data((unsigned short*)StreamPtr,DataSizes);  
			//DAC_CheckFIFOEnough();    							//Make sure to have enough PCMData in DAC fifo 
		}	
	}	         
	         
	//MIC Off
	MIC32_Off();
	//DAC Off
	DAC_DisableSoftCh(); 
	Touch_Init();
	TFT_SetBGColor(0x0001);
	TFT_SetWindow(0, 0, TFT_WIDTH-1, TFT_HEIGHT-1);
}

short Test_Sound(void)
{
	short x, y, MenuItem;
	int i;
	static short Visited = 0;
	static char *MenuText[] = {"Sound output test\0★", "Sound input test\0★", "Return"};
	MENU SoundMenu = {
		80, 70,														// x, y
		150, 30,													// width, height
		3,															// ItemCount
		-1,															// ItemSelected
		0, 															// Chinese Font
		0,															// ASCII Font
		15,															// Spacing
		COLOR_RED, COLOR_BLACK,		                				// Forecolor, Corecolor_Sel
		COLOR_GREEN, COLOR_WHITE,	                				// Back
		COLOR_YELLOW, COLOR_RED,									// Border
		MenuText,
	};
			
	
	TFT_SetBGColor(0x0001);
	TFT_SetWindow(0, 0, TFT_WIDTH-1, TFT_HEIGHT-1);
	Menu_Display(&SoundMenu);
	
	while(1)
	{
		Touch_Get(&x, &y);
		MenuItem = Menu_CursorItem(x, y);
		SoundMenu.ItemSelected = MenuItem;
		Menu_ServiceLoop();
		if(MenuItem != -1)
		{
			for(i=0; i<1000000; i++);
			switch(MenuItem)
			{
				case 0:
					Test_PlaySound();
					strcpy(MenuText[0], "★ Sound output test");
					Visited |= 0x01;
					break;
				case 1:
					Test_Record();	
					strcpy(MenuText[1], "★ Sound input test");
					Visited |= 0x02;
					break;
				case 2:
					TFT_SetBGColor(0x0001);
					TFT_SetWindow(0, 0, TFT_WIDTH-1, TFT_HEIGHT-1);
					if(Visited==0x03)
						return 1;
					else
						return 0;
				default:
					break;
			}
			SoundMenu.ItemSelected = -1;
			Menu_Display(&SoundMenu);
		}
	}
}

⌨️ 快捷键说明

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