/*****************************************************************************/
/* Filename: agc_aduio.c */
/* Author:ZhangYong */
/* 2002-12 */
/*****************************************************************************/
#include "agc_face.h"
#include "agc_func.h"
int dIn,dOut;
int Read_BSP1(void);
void Write_BSP1(int);
void Led_Light(void);
int AGC_audio(int);
// Main program
void main()
{
init_board();
while (1)
{
dIn=Read_BSP1();
dOut=AGC_audio(dIn);
Write_BSP1(dOut);
Led_Light();
}
}
int Read_BSP1(void)
{
int dDataIn;
*(volatile u16 *)SPSA_ADDR(1)=SPCR1_SUBADDR; //Receive Data from McBSP1
while(!((*(volatile u16 *)SPSD_ADDR(1)) & 0x0002)){};
dDataIn=*(volatile u16*)DRR1_ADDR(1);
return dDataIn;
}
void Write_BSP1(int dDataOut)
{
*(volatile u16 *)SPSA_ADDR(1)=SPCR2_SUBADDR; //Transmit Data To McBSP1
while(!((*(volatile u16 *)SPSD_ADDR(1)) & 0x0002)){};
*(volatile u16 *)DXR1_ADDR(1)=dDataOut;
}
void Led_Light(void)
{
static int i=0;
if(i>1024)
{
// *(int *)(0x0007)^=0x2000;
*(volatile u16 *)reg_ST1 ^= 0x2000; //Every 1024 times XF changed
i=0;
}
i++;
}
int AGC_audio(int AGC_in)
{
int AGC_out;
static int dTime=0;
static float AGC_Coff=1.0;
static int maxAGC_in=0;
static int maxArrIn=0;
if(AGC_in>maxArrIn)
maxArrIn=AGC_in;
if(-1*AGC_in>maxArrIn)
maxArrIn=-1*AGC_in;
if(dTime>4096)
{
if(maxArrIn<maxAGC_in)
maxAGC_in=maxArrIn;
maxArrIn=0;
dTime=0;
}
dTime++;
if(AGC_in > maxAGC_in)
{
maxAGC_in=AGC_in;
if(maxAGC_in>1)
AGC_Coff=20000.0/maxAGC_in;
}
if((-1*AGC_in)>maxAGC_in)
{
maxAGC_in=-1*AGC_in;
if(maxAGC_in>1)
AGC_Coff=20000.0/maxAGC_in;
}
AGC_out=AGC_in*AGC_Coff;
if(AGC_out>20000)
AGC_out=20000;
if(AGC_out<-20000)
AGC_out=-20000;
return AGC_out;
}
评论0