/*
* tone_fir.c
*
* Created on: 2013-5-23
* Author: 1121
*/
#include "dsk6416.h"
#include "dsk6416_aic23.h"
#define FILTER_SIZE 65
DSK6416_AIC23_Config config = { 0x0017, // 0 DSK6416_AIC23_LEFTINVOL Left line input channel volume
0x0017, // 1 DSK6416_AIC23_RIGHTINVOL Right line input channel volume
0x00d8, // 2 DSK6416_AIC23_LEFTHPVOL Left channel headphone volume
0x00d8, // 3 DSK6416_AIC23_RIGHTHPVOL Right channel headphone volume
0x0011, // 4 DSK6416_AIC23_ANAPATH Analog audio path control
0x0000, // 5 DSK6416_AIC23_DIGPATH Digital audio path control
0x0000, // 6 DSK6416_FILTER_SIZEAIC23_POWERDOWN Power down control
0x0043, // 7 DSK6416_AIC23_DIGIF Digital audio interface format
0x0001, // 8 DSK6416_AIC23_SAMPLERATE Sample rate control
0x0001 // 9 DSK6416_AIC23_DIGACT Digital interface activation
};
//#pragma DATA_ALIGN(h,8);
short h[FILTER_SIZE] = { 30, 36, 42, 68, 84, 117, 144, 187, 226, 279, 330, 394,
458, 532, 607, 690, 773, 862, 951, 1043, 1132, 1222, 1309, 1392, 1470,
1543, 1608, 1665, 1713, 1751, 1778, 1795, 1801, 1795, 1778, 1751, 1713,
1665, 1608, 1543, 1470, 1392, 1309, 1222, 1132, 1043, 951, 862, 773,
690, 607, 532, 458, 394, 330, 279, 226, 187, 144, 117, 84, 68, 42, 36,
30 };
//#pragma DATA_ALIGN(input,8);
short input[113] = { 0, 12564, 13847, 3827, -6258, -5171, 7071, 19192, 19919,
9239, -1599, -1344, 10000, 21173, 20918, 9239, -2598, -3325, 7071,
17346, 16258, 3827, -8670, -9953, -0000, 9953, 8670, -3827, -16258,
-17346, -7071, 3325, 2598, -9239, -20918, -21173, -10000, 1344, 1599,
-9239, -19919, -19192, -7071, 5171, 6258, -3827, -13847, -12564, 0,
12564, 13847, 3827, -6258, -5171, 7071, 19192, 19919, 9239, -1599,
-1344, 10000, 21173, 20918, 9239, -2598, -3325, 7071, 17346, 16258,
3827, -8670, -9953, -0000, 9953, 8670, -3827, -16258, -17346, -7071,
3325, 2598, -9239, -20918, -21173, -10000, 1344, 1599, -9239, -19919,
-19192, -7071, 5171, 6258, -3827, -13847, -12564, 0, 12564, 13847,
3827, -6258, -5171, 7071, 19192, 19919, 9239, -1599, -1344, 10000,
21173, 20918, 9239, -2598 };
//#pragma DATA_ALIGN(output,8);
int output[177] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
void Filter(short*restrict input, short*restrict h, int* restrict output) {
int i, j;
_nassert(((int) (input) & 0x3) == 0);
_nassert(((int) (h) & 0x3) == 0);
for (i = 63; i < 113; i++) {
//#pragma UNROLL(4);
for (j = 0; j < FILTER_SIZE; j++) {
//if ((i - j >= 0) && (i - j < 113))
output[i] += h[j] * input[i + j];
}
}
}
void main() {
//Filter(input, h, output);
DSK6416_init();
DSK6416_AIC23_CodecHandle hCodec;
int msec, sample;
hCodec = DSK6416_AIC23_openCodec(0, &config);
//混频输出
//Filter(input, h, output);
for (msec = 0; msec < 5000; msec++) {
for (sample = 0; sample < FILTER_SIZE; sample++) {
/* Send a sample to the left channel */
while (!DSK6416_AIC23_write(hCodec, input[sample]))
;
/* Send a sample to the right channel */
while (!DSK6416_AIC23_write(hCodec, input[sample]))
;
}
}
//低通滤波
Filter(input, h, output);
// 滤波后输
for (msec = 0; msec < 5000; msec++) {
for (sample = 64; sample < 112; sample++) {
/* Send a sample to the left channel */
while (!DSK6416_AIC23_write(hCodec, output[sample]))
;
/* Send a sample to the left channel */
while (!DSK6416_AIC23_write(hCodec, output[sample]))
;
}
}
//关闭AIC32
DSK6416_AIC23_closeCodec(hCodec);
}