📄 audio.c
字号:
//***********************************************************************
// Audio interrupt routine for the TigerSHARC EZ-Kit
// Audio Pass Through example in C
// Audio.c
//***********************************************************************
//************************* Includes ************************************
#include <sysreg.h>
#include <builtins.h>
#include <defTS201.h>
#include "TSEZKitDef.h"
#include <stats.h>
#include <math.h>
//************************* Externs *************************************
extern long ReadDataLeft, ReadDataRight, WriteDataLeft, WriteDataRight;
//***********************************************************************
#define PI 3.1415926535
#define NUM_POINTS 1024 //Number of sample points in the calculation
//int Window; //control the window type
float W[NUM_POINTS]; //Windows
float Inbuf[NUM_POINTS],Outbuf[NUM_POINTS];//Inbuffer and outbuffer length
float InbufLeft[NUM_POINTS],InbufRight[NUM_POINTS];//Left channel and right channel length
float Outputbuf[NUM_POINTS]; //Outbuffer length
int Counter0; //the Inbuffer pointer
int Sample; //control the state of calculation,Sample=0,the function
//work in the sample state,and Sample=1 the function work
//in the Acorr calculate state
int OutNum; //the Outbuffer pointer
//--------------------------------------------------------------------------//
// Function: Init_Windows //
// //
// Description: Initialize Process Data for Acorr //
//--------------------------------------------------------------------------//
void Init_Window(void)
{
int i;
for(i=0;i<NUM_POINTS;i++)
{
if(Window==1)
W[i]=0.54-0.46*cos(2*PI*i/(NUM_POINTS-1));
else W[i]=1.0;
}
}
//************************* Audio Interrupt *****************************
void audio_int( void )
{
int i;
/**************Sample the data******************/
if(Sample==0) //if Sample=0,start to sample the data
{
InbufLeft[Counter0]=(float)((ReadDataLeft<<8)>>8);;//从A/D得到的数据数据为低24位有效的有符号数,
//要先左移8位保证其符号位在最高位,在右移8位保证数值大小不变。
WriteDataLeft=(long)Outbuf[Counter0];
Counter0++;
if(Counter0>=NUM_POINTS)
{
Counter0=0;
Sample=1; //sample is over,start to Acorr calculate
}
}
/************do Autocorrelation*****************/
if(Sample==1)
{
for(i=0;i<NUM_POINTS;i++)
{
Inbuf[i]=((float)InbufLeft[i]*W[i]);//add the Window
}
/////////////
autocorrf(Inbuf,NUM_POINTS,NUM_POINTS,Outbuf);//do Autocorrelation
Sample=0; //the Acorr calculate is over,and start to sample the data again
}
}
//********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -