-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.c
More file actions
262 lines (217 loc) · 9.07 KB
/
Code.c
File metadata and controls
262 lines (217 loc) · 9.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "dsk6713_led.h"
#include "dsk6713_dip.h"
#include "stdio.h"
#include "math.h"
#define FILTER_TAP_NUM 51
float filter_CoeffLP[] ={
0 ,
0.000049608861821017358889607251626330253,
0.000175443920653175475026994134530866631,
0.00029786851054089359333576503274798597 ,
0.000288971722266924988063024892781527342,
-0.000000000000000000371322791167561227329 ,
-0.000699832904882783670384716057100149555,
-0.001879711838647565511073445065903797513,
-0.003506992366779230260037669708594876283,
-0.005418901093464816021150198821487720124,
-0.007313447328525437586554946989281233982,
-0.008764176697271001612032925720541243209,
-0.00925970169938160163336515751097977045 ,
-0.008264777033277645457154392261145403609,
-0.005295731039614491077183178191489787423,
0.000000000000000002545084273054902558083,
0.007772096567045187753830504107099841349,
0.017915006469745888700861868869651516434,
0.030044624755503311630544516219742945395,
0.043509913397754021446850458687549689785,
0.05744056104303514598274915670117479749 ,
0.070826566655021627738619827141519635916,
0.082620806666336671364447852283774409443,
0.091851972326956382586260474454320501536,
0.097733338747162418203018319218244869262,
0.099752984716003814669171845253003994003,
0.097733338747162418203018319218244869262,
0.091851972326956382586260474454320501536,
0.082620806666336671364447852283774409443,
0.070826566655021627738619827141519635916,
0.05744056104303514598274915670117479749 ,
0.043509913397754021446850458687549689785,
0.030044624755503311630544516219742945395,
0.017915006469745888700861868869651516434,
0.007772096567045187753830504107099841349,
0.000000000000000002545084273054902558083,
-0.005295731039614491077183178191489787423,
-0.008264777033277645457154392261145403609,
-0.00925970169938160163336515751097977045 ,
-0.008764176697271001612032925720541243209,
-0.007313447328525437586554946989281233982,
-0.005418901093464816021150198821487720124,
-0.003506992366779230260037669708594876283,
-0.001879711838647565511073445065903797513,
-0.000699832904882783670384716057100149555,
-0.000000000000000000371322791167561227329,
0.000288971722266924988063024892781527342,
0.00029786851054089359333576503274798597 ,
0.000175443920653175475026994134530866631,
0.000049608861821017358889607251626330253,
0
};
float filter_CoeffHP[] ={
0 ,
0.000042304293864484321342420147793461638,
0.000106225036835177601775466460498620336,
0.000039858694955552608190762348128188819,
-0.000324466491538566448055852520226949309,
-0.001074656399503071037976331680852126738,
-0.002129988606651402483632695705750847992,
-0.003195991435196208086538804948872893874,
-0.003791529961888590125745901460163622687,
-0.003357356446093438372829664828600471083,
-0.001430315126670510597617358428124134662,
0.002156571794958916758744305042228006641,
0.007103457381328751214788486123552502249,
0.012559351307486872617591444623030838557,
0.017166528133025417413026758595151477493,
0.019247774839255639423019061950981267728,
0.017114806867134887968795453616621671245,
0.009441793901231117919214952394213469233,
-0.004375816262759674515891994417415844509,
-0.023962982095345797955987521277165797073,
-0.047878322197848481589499414212696137838,
-0.07373669354988479640589105201797792688 ,
-0.09853401832611993760302482314727967605 ,
-0.119121234219301777579325118949782336131,
-0.1327380508830541261389157625671941787 ,
0.862499537750731182228491888963617384434,
-0.1327380508830541261389157625671941787 ,
-0.119121234219301777579325118949782336131,
-0.09853401832611993760302482314727967605 ,
-0.07373669354988479640589105201797792688 ,
-0.047878322197848481589499414212696137838,
-0.023962982095345797955987521277165797073,
-0.004375816262759674515891994417415844509,
0.009441793901231117919214952394213469233,
0.017114806867134887968795453616621671245,
0.019247774839255639423019061950981267728,
0.017166528133025417413026758595151477493,
0.012559351307486872617591444623030838557,
0.007103457381328751214788486123552502249,
0.002156571794958916758744305042228006641,
-0.001430315126670510597617358428124134662,
-0.003357356446093438372829664828600471083,
-0.003791529961888590125745901460163622687,
-0.003195991435196208086538804948872893874,
-0.002129988606651402483632695705750847992,
-0.001074656399503071037976331680852126738,
-0.000324466491538566448055852520226949309,
0.000039858694955552608190762348128188819,
0.000106225036835177601775466460498620336,
0.000042304293864484321342420147793461638,
0
};
static short in_buffer1[100];
static short in_buffer2[100];
DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 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 */ \
};
/*
* main() - Main code routine, initializes BSL and generates tone
*/
void main()
{
Uint32 FH=0;
Uint32 SH=0;
Uint32 lp_output, hp_output;
long long int y = 0;
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
/* Initialize the board support library, must be called first */
DSK6713_init();
DSK6713_LED_init();
DSK6713_DIP_init();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec, 1);
while(1)
{
/* Read a sample to the left channel */
while (! DSK6713_AIC23_read(hCodec, &l_input));
while (! DSK6713_AIC23_read(hCodec, &r_input));
/* Read a sample to the right channel */
lp_output=(Int16)FIR_FILTERLP(&filter_CoeffLP,l_input);
hp_output=(Int16)FIR_FILTERHP(&filter_CoeffHP,l_input);
r_output=hp_output;
if(y == 8000)
{
if (FH > SH)
{
printf("Tone is first Harmonic\n");
}
else
{
printf("Tone is seventh Harmonic\n");
}
}
if (y <=8000)
{
FH = FH + abs(lp_output);
SH = SH + abs(hp_output);
}
if(y>8000){
y=0;
FH=0;
SH=0;
}
if(FH > SH){
DSK6713_LED_on(0);
DSK6713_LED_on(1);
DSK6713_LED_off(2);
DSK6713_LED_off(3);
}
else{
DSK6713_LED_on(2);
DSK6713_LED_on(3);
DSK6713_LED_off(0);
DSK6713_LED_off(1);
}
/* Send a sample to the left channel *//* Send a sample to the right channel */
while (! DSK6713_AIC23_write(hCodec, hp_output));
while (! DSK6713_AIC23_write(hCodec, r_output));
y++;
}
/* Close the codec */
DSK6713_AIC23_closeCodec(hCodec);
}
signed int FIR_FILTERLP(float * lp, signed int x)
{
int i=0;
signed long outputlp=0;
in_buffer1[0] = x; /* new input at buffer[0] */
for(i=51;i>0;i--)
in_buffer1[i] = in_buffer1[i-1]; /* shuffle the buffer */
for(i=0;i<51;i++)
outputlp = outputlp + lp[i] * in_buffer1[i];
return(outputlp);
}
signed int FIR_FILTERHP(float * hp, signed int x)
{
int i=0;
signed long outputhp=0;
in_buffer2[0] = x; /* new input at buffer[0] */
for(i=51;i>0;i--)
in_buffer2[i] = in_buffer2[i-1]; /* shuffle the buffer */
for(i=0;i<51;i++)
outputhp = outputhp + hp[i] * in_buffer2[i];
return(outputhp);
}