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

📄 tone.c

📁 TM公司CCS平台上开发的IIR无限级数字滤波器程序。
💻 C
字号:
/*
 *  Copyright 2005 by Spectrum Digital Incorporated.
 *  All rights reserved. Property of Spectrum Digital Incorporated.
 */

/*
 *  ======== tone.c ========
 *
 *  This example uses the PCM3002 codec module of the DSK5416 Board Support
 *  Library to generate a 1KHz sine wave on the audio outputs for 5 seconds.
 *  The sine wave data is calculated and stored in an array called sinetable.
 *  The codec operates at 48KHz by default.  Since the sine wave table has 48
 *  entries per period, each pass through the inner loop takes 1 millisecond.
 *  5000 passes through the inner loop takes 5 seconds.
 *
 *  Please see the DSK5416 help file for more detailed information.
 */

#include "tonecfg.h"
#include "dsk5416.h"
#include "dsk5416_pcm3002.h"
#include <math.h>



#define PI              ( ( double )3.1415927 )


#define jishu 16    // 7 for lowpass,6 for highpass,10 for bandpass,16 for bandstop

/*int xishu[jishu][6]={	32,64,32,32,-56,29,		//lowpass
						32,64,32,32,-51,24,
						32,64,32,32,-47,20,
						32,64,32,32,-45,17,
						32,64,32,32,-43,15,
						32,64,32,32,-42,14,
						32,32, 0,32,-21, 0 };	*/

/*int xishu[jishu][6]={	32,-64,32,32,-55,28,	//highpass
						32,-64,32,32,-50,23,
						32,-64,32,32,-46,18,
						32,-64,32,32,-43,15,
						32,-64,32,32,-42,14,
						32,-32, 0,32,-21, 0};	*/

/*int xishu[jishu][6]={	64,0,-64,64,-42,50,		//bandpass
						64,0,-64,64,-125,62,
						64,0,-64,64,-121,58,
						64,0,-64,64,-36,30,
						64,0,-64,64,-118,55,
						64,0,-64,64,-35,17,
						64,0,-64,64,-114,51,
						64,0,-64,64,-35,10,
						64,0,-64,64,-111,49,
						64,0,-64,64,-37,6};		*/

int xishu[jishu][6]={	64,-116,64,64,-76,58,	//bandstop
						64,-116,64,64,-124,62,
						64,-116,64,64,-70,48,
						64,-116,64,64,-120,59,
						64,-116,64,64,-117,56,
						64,-116,64,64,-67,39,
						64,-116,64,64,-114,53,
						64,-116,64,64,-66,33,
						64,-116,64,64,-110,49,
						64,-116,64,64,-66,28,
						64,-116,64,64,-105,45,
						64,-116,64,64,-68,25,
						64,-116,64,64,-99,40,
						64,-116,64,64,-72,25,
						64,-116,64,64,-91,34,
						64,-116,64,64,-79,27};



DSK5416_PCM3002_Config setup = {
    0x01ff, // Set-Up Reg 0 - Left  channel DAC attenuation
    0x01ff, // Set-Up Reg 1 - Right channel DAC attenuation
    0x0002, // Set-Up Reg 2 - Various ctl e.g. power-down modes
    0x0000  // Set-Up Reg 3 - Codec data format control
};

/*
 *  InitSineTable() - Initialize the sine wave table data
 */


/*
 *  UserTask() - The main user task
 */

void UserTask()
{
}
void UserTask1()
{
    DSK5416_PCM3002_CodecHandle hCodec;

	Int16  tempval,tempout;
	int jc=0;
	int i,j;
	long temp[jishu+1][6];
	for(i=0;i<jishu;i++)
		for(j=0;j<6;j++)
			temp[i][j]=0;
    /* Start the codec */
    hCodec = DSK5416_PCM3002_openCodec( 0, &setup );
	
	DSK5416_PCM3002_setFreq(hCodec,12000);		//48000 for lowpass&highpass,12000 for bandpass&bandstop

    for (;;)
    {
        while(!DSK5416_PCM3002_read16(hCodec,&tempval));
		while(!DSK5416_PCM3002_read16(hCodec,&tempval));
		
		temp[0][3]=tempval/10;
		for(jc=0;jc<jishu;jc++)
		{
			temp[jc][0]=(xishu[jc][0]*temp[jc][3]-xishu[jc][4]*temp[jc][1]
					+xishu[jc][1]*temp[jc][4]-xishu[jc][5]*temp[jc][2]
					+xishu[jc][2]*temp[jc][5])>>6;		//>>5 for lowpass&highpass, 6 for bandpass&bandstop		
			temp[jc][5]=temp[jc][4];
			temp[jc][4]=temp[jc][3];
			temp[jc][2]=temp[jc][1];
			temp[jc][1]=temp[jc][0];
			temp[jc+1][3]=temp[jc][0];		//>>5 for lowpass,none for highpass,1 for bandpass,none for bandstop
		}
		tempout=temp[jishu-1][0]>>1;		//<<2 for lowpass&highpass,none for bandpass,>>1 for bandstop 	
					
		
        while(!DSK5416_PCM3002_write16(hCodec,tempval));
		while(!DSK5416_PCM3002_write16(hCodec,tempout));
    }


//    DSK5416_PCM3002_closeCodec( hCodec );
}

void main()
{
    /* Call BSL init */
    DSK5416_init();

	UserTask1();
}

⌨️ 快捷键说明

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