📄 fir.c
字号:
#include "short6713cfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include <stdio.h>
#include <math.h>
/*
------------------------------------------------------------------------------
Defines
------------------------------------------------------------------------------
*/
#define pi 3.1415927
#define Length 512
/*
------------------------------------------------------------------------------
Function prototyping
------------------------------------------------------------------------------
*/
/* Codec configuration settings */
DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x01f9, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x01f9, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
/*
------------------------------------------------------------------------------
Global variables
------------------------------------------------------------------------------
*/
double npass,h[51], x, y, xmid[51];
float in[Length], out[Length];
int m=50;
int n=256;
double fs,fstop,r,rm;
int i,j,p,k=0;
int x_in;
// Left and right signal samples
Uint32 xL, xR;
//================================================================
void firdes (int m, double npass);
/*
* main() - Main code routine, initializes BSL and connects input samples
* to output samples in an infinite while loop.
*/
/* The main programme of FIR */
void main()
{
// Codec data handle structure
DSK6713_AIC23_CodecHandle hCodec;
//Define filter variables
/* Initialize the board support library, must be called first */
DSK6713_init();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);
// Set sampling frequency via the number before KHZ in the define.
// Choose from 8, 16, 24, 32, 44.1, 48, or 96 Khz.
DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_32KHZ);
fs = 32000;
fstop = 1000;
npass = fstop/fs;
for (i=0; i<=m; i++)
{
xmid[i]=0;
}
firdes(m, npass);
// Infinite loop so that we can continue to process samples forever
while(1)
{
// read A/D
while (!DSK6713_AIC23_read(hCodec, &xL));
while (!DSK6713_AIC23_read(hCodec, &xR));
x_in = (Int16) xL;
x = (float) x_in;
in[k] = x;
for (p=0; p<=m; p++)
{
xmid[m-p] = xmid[m-p-1];
}
xmid[0] = x;
r = 0;
rm= 0;
for (j=0; j<=m; j++)
{
r = xmid[j] * h[j];
rm = rm + r;
}
y = rm;
out[k] = y;
xL = (int)(y);
while (!DSK6713_AIC23_write(hCodec, xL));
while (!DSK6713_AIC23_write(hCodec, xL));
k++;
k = k%Length;
if (k == 0)
{
k = 0;
}
}
/* Close the codec in theory, but unreachable with the above while loop*/
//DSK6713_AIC23_closeCodec(hCodec);
}
//================================================================
//================================================================
void firdes(int m, double npass)
{
int t;
for (t=0; t<=m; t++)
{
h[t] = sin((t-m/2.0)*npass*pi)/(pi*(t-m/2.0));
}
if (t=m/2) h[t]=npass;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -