summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer_v1.0/doc/html/fft_8hcc-source.html
blob: d4cfdb6a98631d728376e92edbaaf3bf237b4755 (plain)
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Graphic Equalizer 2: C:/Project  Marcel &amp; Oliver/Graphic_Equalizer/src/fft.hcc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">C:</a>&nbsp;/&nbsp;<a class="el" href="dir_000001.html">Project  Marcel &amp; Oliver</a>&nbsp;/&nbsp;<a class="el" href="dir_000002.html">Graphic_Equalizer</a>&nbsp;/&nbsp;<a class="el" href="dir_000004.html">src</a></div>
<h1>fft.hcc</h1><a href="fft_8hcc.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 
00020 <span class="preprocessor">#include &lt;stdlib.hch&gt;</span>
00021 <span class="preprocessor">#include "pal_master.hch"</span>
00022 
00023 <span class="preprocessor">#include "<a class="code" href="audio_8hch.html">audio.hch</a>"</span>
00024 <span class="preprocessor">#include "<a class="code" href="weights__256_8hch.html">weights_256.hch</a>"</span>
00025 <span class="preprocessor">#include "<a class="code" href="configuration_8hch.html">configuration.hch</a>"</span>
00026 <span class="preprocessor">#include "xilinxmult.hch"</span>
00027 <span class="preprocessor">#include "<a class="code" href="fft_8hch.html">fft.hch</a>"</span>
00028 
00029 <span class="preprocessor">#if HAVE_DEBUG</span>
00030 <span class="preprocessor"></span><span class="preprocessor">        #include "debug.hch"</span>
00031 <span class="preprocessor">#endif</span>
00032 <span class="preprocessor"></span>
00033 <span class="comment">/* Define two multi-port RAMs for FFT calculation; one for real and one for imaginary values</span>
00034 <span class="comment"> * Extra block RAM settings are defined to make sure read and write actions can be performed</span>
00035 <span class="comment"> * within one clock-cycle.</span>
00036 <span class="comment"> * Left out extra settings on new board the clock changes TODO !!!!</span>
00037 <span class="comment"> */</span>
00038 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00039 <span class="preprocessor"></span>mpram
00040 {
00041   ram <span class="keywordtype">signed</span> 18 rwrite[256];
00042   rom <span class="keywordtype">signed</span> 18 read[256];
00043 } real with {block = <span class="stringliteral">"BlockRAM"</span><span class="comment">/*, westart=2.5, welength=1, rclkpos={1.5}, wclkpos={3}, clkpulselen=0.5*/</span>};
00044 
00045 mpram 
00046 {
00047   ram <span class="keywordtype">signed</span> 18 rwrite[256];
00048   rom <span class="keywordtype">signed</span> 18 read[256];
00049 } imaginary with {block = <span class="stringliteral">"BlockRAM"</span><span class="comment">/*, westart=2.5, welength=1, rclkpos={1.5}, wclkpos={3}, clkpulselen=0.5*/</span>};
00050 <span class="preprocessor">#else</span>
00051 <span class="preprocessor"></span>mpram
00052 {
00053   ram <span class="keywordtype">signed</span> 24 rwrite[256];
00054   rom <span class="keywordtype">signed</span> 24 read[256];
00055 } real with {block = <span class="stringliteral">"BlockRAM"</span><span class="comment">/*, westart=2.5, welength=1, rclkpos={1.5}, wclkpos={3}, clkpulselen=0.5*/</span>};
00056 
00057 mpram 
00058 {
00059   ram <span class="keywordtype">signed</span> 24 rwrite[256];
00060   rom <span class="keywordtype">signed</span> 24 read[256];
00061 } imaginary with {block = <span class="stringliteral">"BlockRAM"</span><span class="comment">/*, westart=2.5, welength=1, rclkpos={1.5}, wclkpos={3}, clkpulselen=0.5*/</span>};
00062 <span class="preprocessor">#endif</span>
00063 <span class="preprocessor"></span><span class="comment">// multiplication factors for equalizer function</span>
<a name="l00064"></a><a class="code" href="fft_8hcc.html#a1">00064</a> ram <span class="keywordtype">signed</span> 7 <a class="code" href="fft_8hcc.html#a1">eq_settings</a>[16] = {0,2,4,7,10,13,16,19,22,26,30,35,41,48,55,63};
00065 
00066 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00067 <span class="preprocessor"></span><span class="preprocessor">#define DC_COMPONENT            0</span>
00068 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00069"></a><a class="code" href="fft_8hcc.html#a0">00069</a> <span class="preprocessor"></span><span class="preprocessor">#define DC_COMPONENT            8470527</span>
00070 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00071 <span class="preprocessor"></span>
<a name="l00082"></a><a class="code" href="fft_8hcc.html#a2">00082</a> macro proc <a class="code" href="fft_8hcc.html#a2">multiply</a>(result, op_a, op_b)
00083 {
00084 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00085 <span class="preprocessor"></span>        xilinxmult(result, op_a, adjs(op_b,18));
00086 <span class="preprocessor">#else</span>
00087 <span class="preprocessor"></span>        result = (adjs(op_a,38))*(adjs(op_a,38));
00088 <span class="preprocessor">#endif  </span>
00089 <span class="preprocessor"></span>}
00090 
00091 
00092 
00093 
<a name="l00104"></a><a class="code" href="fft_8hcc.html#a3">00104</a> <span class="keywordtype">void</span> <a class="code" href="fft_8hcc.html#a3">calculate_fft</a>(<span class="keywordtype">unsigned</span> 1 select_inverse)
00105 {
00106   <span class="keywordtype">unsigned</span> 4 level;
00107   <span class="keywordtype">unsigned</span> 8 point1,point2,j,f,k;
00108   <span class="keywordtype">unsigned</span> 9 e,i;
00109   <span class="keywordtype">signed</span> 16 weight1,weight2;
00110 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00111 <span class="preprocessor"></span>  <span class="keywordtype">signed</span> 18 p,q,r,t;
00112 <span class="preprocessor">#else</span>
00113 <span class="preprocessor"></span>  <span class="keywordtype">signed</span> 24 p,q,r,t;    
00114 <span class="preprocessor">#endif</span>
00115 <span class="preprocessor"></span>  <span class="keywordtype">signed</span> a,b;
00116 
00117 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00118 <span class="preprocessor"></span>  <span class="comment">// Macro to provide rescaling of 36-bit result of fixed point multiply</span>
00119   <span class="comment">// down to an 18-bit result. The range of bits selected depends on the </span>
00120   <span class="comment">// number that represents the value of "1" in the trig function lookup</span>
00121   <span class="comment">// tables. (Eg. for 16384 == 1, the lowest bit selected should be [14]).</span>
00122   macro expr rescale (x) = (x[35] @ x[30:14]);
00123 <span class="preprocessor">#else</span>
00124 <span class="preprocessor"></span>  <span class="comment">//Macro to rescale the multiply result down to a 24-bit value.</span>
00125   macro expr rescale (x) = ((x&gt;&gt;FRACBITS)&lt;-24);
00126 <span class="preprocessor">#endif</span>
00127 <span class="preprocessor"></span>
00128   <span class="keywordflow">for</span>(level=1;level&lt;=NUMBER_OF_COLUMNS;level++) <span class="comment">// count all the columns</span>
00129   {
00130         e=1&lt;&lt;(<a class="code" href="fft_8hch.html#a0">NUMBER_OF_COLUMNS</a>-level+1); <span class="comment">// number of points in each block in this column</span>
00131         f=(e&gt;&gt;1)&lt;-8;                      <span class="comment">// number of butterflies in each block in this column</span>
00132 
00133         <span class="keywordflow">for</span>(j=1;j&lt;=f;j++)       <span class="comment">// count all the butterflies in each block</span>
00134         {
00135                 par
00136                 {
00137                         <span class="comment">// Weight factors for real (the same for FFT and iFFT)</span>
00138                         weight1 = <a class="code" href="weights__256_8hch.html#a2">weight_re</a>[((j-1)&lt;&lt;(level-1))&lt;-7]; 
00139 
00140                         
00141                         <span class="comment">// Weight factors for imaginary (opposite for FFT and iFFT)</span>
00142                         weight2 = (!select_inverse) ? (<a class="code" href="weights__256_8hch.html#a3">weight_im</a>[((j-1)&lt;&lt;(level-1))&lt;-7]) : -(<a class="code" href="weights__256_8hch.html#a3">weight_im</a>[((j-1)&lt;&lt;(level-1))&lt;-7]); 
00143 
00144                         <span class="comment">/* ORIGINAL CODE BELOW, MODIFIED BECAUSE OF MISMATCHING OUTPUT WITH BORLAND TESTAPP</span>
00145 <span class="comment">                        weight2 = (!select_inverse) ? -(weight_im[((j-1)&lt;&lt;(level-1))&lt;-7]) : weight_im[((j-1)&lt;&lt;(level-1))&lt;-7]; </span>
00146 <span class="comment">                        */</span>
00147                         
00148                         
00149 
00150                         <span class="keywordflow">for</span>(i=0@j;i&lt;=NUMBER_OF_POINTS;i+=e)   <span class="comment">// count all the blocks in this column</span>
00151                         {       <span class="comment">// Butterfly calculation</span>
00152                                 par
00153                                 {
00154                                         point1 = ((i&lt;-8)-1);
00155                                         point2 = (((i&lt;-8)+f)-1);
00156                                 }
00157                                 
00158                                 par
00159                                 {
00160                                         p = (real.read[point1] &gt;&gt; 1) + (real.rwrite[point2] &gt;&gt; 1);
00161                                         q = (imaginary.read[point1] &gt;&gt; 1) + (imaginary.rwrite[point2] &gt;&gt; 1);
00162                                 }
00163                                 
00164                                 par
00165                                 {
00166                                         r = (real.read[point1] &gt;&gt; 1) - (real.rwrite[point2] &gt;&gt; 1);
00167                                         t = (imaginary.read[point1] &gt;&gt; 1) - (imaginary.rwrite[point2] &gt;&gt; 1);
00168                                 }               
00169 
00170                                 <a class="code" href="fft_8hcc.html#a2">multiply</a>(a,r,weight1);
00171                                 <a class="code" href="fft_8hcc.html#a2">multiply</a>(b,t,weight2);
00172 
00173                                 par
00174                                 {
00175                                         real.rwrite[point2] = (rescale(a-b));
00176                                         imaginary.rwrite[point1] = q;
00177                                 }
00178 
00179                                 <a class="code" href="fft_8hcc.html#a2">multiply</a>(a,t,weight1);
00180                                 <a class="code" href="fft_8hcc.html#a2">multiply</a>(b,r,weight2);
00181 
00182                                 par
00183                                 {       
00184                                         real.rwrite[point1] = p;
00185                                         imaginary.rwrite[point2] = (rescale(a+b));
00186                                 }
00187 
00188                         }
00189                 }
00190         }
00191   }
00192 
00193   j=1;
00194   <span class="keywordflow">for</span>(i=1;i&lt;NUMBER_OF_POINTS;i++)
00195   {
00196         <span class="keywordflow">if</span>(i&lt;(0@j))
00197         {
00198                 par
00199                 {
00200                         point1=j-1;
00201                         point2=(i-1)&lt;-8;
00202                 }
00203                 <span class="comment">/*</span>
00204 <span class="comment">                  COPYING ARRAY VALUES FROM ONE PLACE TO ANOTHER IN THE ARRAT MUST BE DONE IN </span>
00205 <span class="comment">                  2 STEPS. FIRSTLY THE VALUES ARE COPIED TO SEPARATE VARIABLES AFTER THAT THEY</span>
00206 <span class="comment">                  ARE COPIED BACK TO THEIR NEW POSITION IN THE ARRAY. THIS MUST BE DONE TO </span>
00207 <span class="comment">                  PREVENT TIMING ISSUES FROM OCCURING.</span>
00208 <span class="comment">                */</span>
00209                 par
00210                 {
00211                         p = real.read[point1];
00212                         q = imaginary.read[point1];
00213                 }
00214                 par
00215                 {
00216                         r = real.read[point2];
00217                         t = imaginary.read[point2];
00218                 }
00219                 par
00220                 {
00221                         real.rwrite[point1] = r;        
00222                         imaginary.rwrite[point1] = t;
00223                 }
00224                 par
00225                 {
00226                         real.rwrite[point2] = p;
00227                         imaginary.rwrite[point2] = q;
00228                 }
00229         }
00230 
00231         k = <a class="code" href="fft_8hch.html#a1">NUMBER_OF_POINTS</a>&gt;&gt;1;
00232 
00233 
00234         <span class="keywordflow">while</span>(k&lt;j)
00235         {
00236                 j = j-k;
00237                 k = k&gt;&gt;1;
00238         }
00239 
00240         j+=k;
00241   }
00242 
00243 }
00244 
00256 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00257 <span class="preprocessor"></span><span class="keywordtype">void</span> <a class="code" href="fft_8hcc.html#a4">perform_fft</a>(<span class="keywordtype">signed</span> 18 *pcm_audio)
00258 #<span class="keywordflow">else</span>
<a name="l00259"></a><a class="code" href="fft_8hcc.html#a4">00259</a> <span class="keywordtype">void</span> <a class="code" href="fft_8hcc.html#a4">perform_fft</a>(<span class="keywordtype">signed</span> 16 *pcm_audio)
00260 #endif
00261 {
00262         <span class="keywordtype">unsigned</span> 8 k;
00263 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00264 <span class="preprocessor"></span>        <span class="keywordtype">signed</span> 18 sample;
00265         k=0;
00266         sample = adjs(pcm_audio[k],18);
00267 <span class="preprocessor">#else</span>
00268 <span class="preprocessor"></span>        <span class="keywordtype">signed</span> 24 sample;
00269         k=0;
00270         sample = adjs(pcm_audio[k],24);
00271 <span class="preprocessor">#endif</span>
00272 <span class="preprocessor"></span>        
00273         <span class="comment">//initialize variables for the copying pipeline</span>
00274 
00275         
00276         <span class="comment">// copy audio data to real-array before starting FFT calculation</span>
00277         <span class="comment">// and set imaginary values to zero</span>
00278         <span class="keywordflow">do</span>
00279         {
00280                 <span class="comment">//Copying the array values has been pipelined to prevent parallel access to the</span>
00281                 <span class="comment">//pcm_audio array. This copying procedure must be finished before another </span>
00282                 <span class="comment">//sample is read from the audio input. The time available for this loop is </span>
00283                 <span class="comment">//determined by the sampling rate of 44,1 Khz</span>
00284                 par
00285                 {
00286                         <span class="comment">//COPYING NEEDS TO BE DONE IN 2 STEPS, BECAUSE THE VALUE THAT NEEDS TO WRITTEN</span>
00287                         <span class="comment">//TO THE REAL-RAM NEEDS TO BE AVAILABLE ON THE START OFF THE CLOCKCYCLE.</span>
00288 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00289 <span class="preprocessor"></span>                        sample = adjs(pcm_audio[k+1],18);
00290 <span class="preprocessor">#else</span>
00291 <span class="preprocessor"></span>                        sample = adjs(pcm_audio[k+1],24);
00292 <span class="preprocessor">#endif</span>
00293 <span class="preprocessor"></span>                        real.rwrite[k] = sample;
00294                         imaginary.rwrite[k] = 0;
00295                         k++;
00296                 }               
00297         }  <span class="keywordflow">while</span> (k);
00298 
00299         
00300 
00301 <span class="preprocessor">#if PERFORM_FFT_CALCULATION</span>
00302 <span class="preprocessor"></span>        <a class="code" href="fft_8hcc.html#a3">calculate_fft</a>(0);
00303 <span class="preprocessor">#endif</span>
00304 <span class="preprocessor"></span>
00305 
00306 }
00307 
00321 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00322 <span class="preprocessor"></span><span class="keywordtype">void</span> <a class="code" href="fft_8hcc.html#a5">perform_ifft</a>(<span class="keywordtype">signed</span> 18 *modified_audio, <span class="keywordtype">unsigned</span> 6 *ifft_info)
00323 #<span class="keywordflow">else</span>
<a name="l00324"></a><a class="code" href="fft_8hcc.html#a5">00324</a> <span class="keywordtype">void</span> <a class="code" href="fft_8hcc.html#a5">perform_ifft</a>(<span class="keywordtype">signed</span> 16 *modified_audio, <span class="keywordtype">unsigned</span> 6 *ifft_info)
00325 #endif
00326 {
00327         <span class="keywordtype">unsigned</span> 6 k;
00328 <span class="preprocessor">#if HARDWARE_MULTIPLY </span>
00329 <span class="preprocessor"></span>        <span class="keywordtype">signed</span> 18 p;
00330 <span class="preprocessor">#else</span>
00331 <span class="preprocessor"></span>        <span class="keywordtype">signed</span> 24 p;
00332 <span class="preprocessor">#endif</span>
00333 <span class="preprocessor"></span><span class="preprocessor">#if PERFORM_FFT_CALCULATION     </span>
00334 <span class="preprocessor"></span>        <a class="code" href="fft_8hcc.html#a3">calculate_fft</a>(1);
00335 <span class="preprocessor">#endif</span>
00336 <span class="preprocessor"></span>
00337         k=0;
00338 <span class="comment">//initialize variables for the copying pipeline</span>
00339 <span class="preprocessor">#if PERFORM_FFT_CALCULATION     </span>
00340 <span class="preprocessor"></span><span class="preprocessor">        #if HARDWARE_MULTIPLY </span>
00341 <span class="preprocessor"></span>                p = (real.read[(0@k)+95] &lt;&lt; NUMBER_OF_COLUMNS);
00342 <span class="preprocessor">        #else</span>
00343 <span class="preprocessor"></span>                p = (real.read[(0@k)+95] &gt;&gt; NUMBER_OF_COLUMNS);
00344 <span class="preprocessor">        #endif</span>
00345 <span class="preprocessor"></span><span class="preprocessor">#else</span>
00346 <span class="preprocessor"></span>                p = (real.read[(0@k)+95]);
00347 <span class="preprocessor">#endif</span>
00348 <span class="preprocessor"></span>
00349         <span class="keywordflow">do</span>
00350         {
00351                 <span class="comment">//Copying the array values has been pipelined to prevent parallel access to the</span>
00352                 <span class="comment">//pcm_audio array. This copying procedure must be finished before another </span>
00353                 <span class="comment">//sample is read from the audio input. The time available for this loop is </span>
00354                 <span class="comment">//determined by the sampling rate of 44,1 Khz</span>
00355                 par
00356                 {
00357                         <span class="comment">/*</span>
00358 <span class="comment">                        *       Before copying the modified audio from the local real-array </span>
00359 <span class="comment">                        *       to the output array of the audio I/O component, compensate</span>
00360 <span class="comment">                        *       for the FFT calculation by shifting the values. </span>
00361 <span class="comment">                        *       95 is added to start the output from the middle of the sliding</span>
00362 <span class="comment">                        *       window, this is done to get a better sound quality.</span>
00363 <span class="comment">                        */</span>
00364 <span class="preprocessor">#if PERFORM_FFT_CALCULATION     </span>
00365 <span class="preprocessor"></span><span class="preprocessor">        #if HARDWARE_MULTIPLY </span>
00366 <span class="preprocessor"></span>                        p = (real.read[(0@k)+95] &lt;&lt; NUMBER_OF_COLUMNS);
00367 <span class="preprocessor">        #else</span>
00368 <span class="preprocessor"></span>                        p = (real.read[(0@k)+95] &gt;&gt; NUMBER_OF_COLUMNS);
00369 <span class="preprocessor">        #endif</span>
00370 <span class="preprocessor"></span><span class="preprocessor">#else</span>
00371 <span class="preprocessor"></span>                        p = (real.read[(0@k)+95]);
00372 <span class="preprocessor">#endif</span>
00373 <span class="preprocessor"></span>                        <span class="comment">//Copy the modified audio from the local real array to the output array of the audio I/O component.</span>
00374 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00375 <span class="preprocessor"></span>                        modified_audio[k] = p ;
00376 <span class="preprocessor">#else</span>
00377 <span class="preprocessor"></span>                        modified_audio[k] = (p&lt;-16);
00378 <span class="preprocessor">#endif</span>
00379 <span class="preprocessor"></span>                        <span class="comment">//Fill the array for displaying the waveform, only the 6 MSB are needed.</span>
00380                         ifft_info[k] = (<span class="keywordtype">unsigned</span> 6)(32+(p[17:12]));             
00381                         k++;
00382                 }
00383         } <span class="keywordflow">while</span>(k);
00384 }
00385 
<a name="l00398"></a><a class="code" href="fft_8hcc.html#a6">00398</a> <span class="keywordtype">void</span> <a class="code" href="fft_8hcc.html#a6">equalize_audio</a>(<a class="code" href="structaudiodata__t.html">audiodata_t</a> *audiodata)
00399 {
00400 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00401 <span class="preprocessor"></span>  <span class="keywordtype">signed</span> 18 p,q;
00402 <span class="preprocessor">#else</span>
00403 <span class="preprocessor"></span>  <span class="keywordtype">signed</span> 24 p,q;
00404 <span class="preprocessor">#endif</span>
00405 <span class="preprocessor"></span>  <span class="keywordtype">signed</span> 18 a;
00406   <span class="keywordtype">unsigned</span> 8 i, mirror_i, bit, m, n;
00407   <span class="keywordtype">unsigned</span> 7 old_value;
00408   <span class="keywordtype">unsigned</span> 9 tmp;
00409   
00410   <span class="comment">//macro expr equalize_bar = multiply(q,a)[29:6];</span>
00411   
00412   macro proc equalize_bar(retval)
00413   {
00414          <span class="keywordtype">signed</span> result;
00415          <a class="code" href="fft_8hcc.html#a2">multiply</a>(result, q,a);
00416 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00417 <span class="preprocessor"></span>         retval = result[23:6]; <span class="comment">//drop last 6 bit to compensate the maximum multiplication with 64 from the eq_settings array</span>
00418 <span class="preprocessor">#else</span>
00419 <span class="preprocessor"></span>         retval = result[29:6]; <span class="comment">//drop last 6 bit to compensate the maximum multiplication with 64 from the eq_settings array</span>
00420 <span class="preprocessor">#endif</span>
00421 <span class="preprocessor"></span>  } 
00422 
00423   p = real.read[0] - DC_COMPONENT; <span class="comment">// remove DC component for calculations</span>
00424   real.rwrite[0] = p;
00425   
00426   <span class="keywordflow">for</span>(i=0;i!=NUMBER_OF_FREQUENCIES;i++)   
00427   {  
00428         
00429                 <span class="comment">// set multiplication factor (0..64) for current frequency bar, The first frequency band must be equalized at 100% (63) since there is no DC-component taken into account.</span>
00430                 a = adjs(<a class="code" href="fft_8hcc.html#a1">eq_settings</a>[audiodata-&gt;<a class="code" href="structaudiodata__t.html#o0">equalizer_levels_ptr</a>[i &lt;- 7]],18);
00431 
00432 
00433                 <span class="comment">// multiply frequency with this factor and divide by 64 (drop 6 LSB's)</span>
00434                 q = real.read[i];
00435         equalize_bar(p);
00436         real.rwrite[i] = p;
00437 
00438         q = imaginary.read[i];
00439         equalize_bar(p);
00440         imaginary.rwrite[i] = p;
00441 
00442         <span class="comment">// the upper part(128..255) of the spectrum is mirrored to the lower part; </span>
00443         <span class="comment">// these values need to be adjusted too</span>
00444         <span class="keywordflow">if</span> ((i&lt;-7)!=0) <span class="comment">// if not in DC component bar</span>
00445         {
00446                 mirror_i = (<a class="code" href="fft_8hch.html#a1">NUMBER_OF_POINTS</a>-1)-i+1;
00447                 q = real.read[mirror_i];
00448                 equalize_bar(p);
00449                 real.rwrite[mirror_i] = p;
00450 
00451                 q = imaginary.read[mirror_i];
00452                 equalize_bar(p);
00453                 imaginary.rwrite[mirror_i] = p;
00454         }
00455   }
00456   
00457   <span class="comment">//write data to fft_info for display purposes</span>
00458   <span class="keywordflow">for</span>(i=0;i&lt;NUMBER_OF_FREQUENCIES;i++)
00459   {
00460                 p = real.read[i];
00461                 q = imaginary.read[i];
00462 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00463 <span class="preprocessor"></span>                <span class="keywordflow">if</span> (p[17] == 1) p = -p; <span class="keywordflow">else</span> delay;
00464                 <span class="keywordflow">if</span> (q[17] == 1) q = -q; <span class="keywordflow">else</span> delay;
00465 <span class="preprocessor">#else</span>
00466 <span class="preprocessor"></span>                <span class="keywordflow">if</span> (p[23] == 1) p = -p; <span class="keywordflow">else</span> delay;
00467                 <span class="keywordflow">if</span> (q[23] == 1) q = -q; <span class="keywordflow">else</span> delay;
00468 <span class="preprocessor">#endif</span>
00469 <span class="preprocessor"></span>        p = (p&lt;q) ? q : p; <span class="comment">// This is done to get the best visual frequency result</span>
00470          
00471         <span class="keywordflow">if</span> (!audiodata-&gt;<a class="code" href="structaudiodata__t.html#o1">display_log</a>)
00472         {
00473 
00474                 bit=126;
00475 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00476 <span class="preprocessor"></span>                <span class="keywordflow">while</span> ((p[15] == 0) &amp;&amp; (bit != 0))
00477 <span class="preprocessor">#else</span>
00478 <span class="preprocessor"></span>                <span class="keywordflow">while</span> ((p[21] == 0) &amp;&amp; (bit != 0))
00479 <span class="preprocessor">#endif</span>
00480 <span class="preprocessor"></span>                        par
00481                         {
00482                                 p = p&lt;&lt;1;
00483                                 bit = bit - 18;
00484                         }
00485                 old_value = audiodata-&gt;fft_info.write[0 @ (i &lt;- 7)];
00486                 tmp = ((0@old_value) + (0@bit))&gt;&gt;1;
00487                 audiodata-&gt;fft_info.write[0 @ (i &lt;- 7)] = (old_value &lt;= (tmp&lt;-7)) ? (tmp&lt;-7) : old_value-1;
00488         } 
00489         <span class="keywordflow">else</span> 
00490         {
00491                 old_value = audiodata-&gt;fft_info.write[0 @ (i &lt;- 7)];
00492 <span class="preprocessor">#if HARDWARE_MULTIPLY</span>
00493 <span class="preprocessor"></span>                audiodata-&gt;fft_info.write[0 @ (i &lt;- 7)] = (old_value&lt;=(unsigned)(p[15:9])) ? (unsigned)(p[15:9]) : old_value-1;
00494 <span class="preprocessor">#else</span>
00495 <span class="preprocessor"></span>                audiodata-&gt;fft_info.write[0 @ (i &lt;- 7)] = (old_value&lt;=(unsigned)(p[21:15])) ? (unsigned)(p[21:15]) : old_value-1;
00496 <span class="preprocessor">#endif</span>
00497 <span class="preprocessor"></span>        }
00498   }
00499 
00500   <span class="comment">// add DC component again before inverse FFT calculation is performed</span>
00501 
00502   p = real.read[0] + DC_COMPONENT; 
00503   real.rwrite[0] = p;
00504 }
00505 
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Dec 9 14:37:07 2004 for Graphic Equalizer 2 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
</body>
</html>