comparison Plugins/Input/wma/iir.c @ 300:e35b0290f77c trunk

[svn] Squash 3 warnings by compiling as C99 code. Remove round_trick kludge.
author chainsaw
date Fri, 16 Dec 2005 18:25:18 -0800
parents 53751ea823c3
children
comparison
equal deleted inserted replaced
299:0235eaed75fe 300:e35b0290f77c
21 */ 21 */
22 22
23 /* IIR filter coefficients */ 23 /* IIR filter coefficients */
24 #include "iir.h" 24 #include "iir.h"
25 #include <math.h> 25 #include <math.h>
26 #include <tgmath.h> 26 #include <strings.h>
27 27
28 /* History for two filters */ 28 /* History for two filters */
29 static sXYData data_history[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned)); 29 static sXYData data_history[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned));
30 static sXYData data_history2[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned)); 30 static sXYData data_history2[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned));
31 31
47 { (5.4697667908e-01), (2.2651166046e-01), (1.0153238114e+00) }, /* 6000.0 Hz */ 47 { (5.4697667908e-01), (2.2651166046e-01), (1.0153238114e+00) }, /* 6000.0 Hz */
48 { (3.1023210589e-01), (3.4488394706e-01), (-1.8142472036e-01) }, /* 12000.0 Hz */ 48 { (3.1023210589e-01), (3.4488394706e-01), (-1.8142472036e-01) }, /* 12000.0 Hz */
49 { (2.6718639778e-01), (3.6640680111e-01), (-5.2117742267e-01) }, /* 14000.0 Hz */ 49 { (2.6718639778e-01), (3.6640680111e-01), (-5.2117742267e-01) }, /* 14000.0 Hz */
50 { (2.4201241845e-01), (3.7899379077e-01), (-8.0847117831e-01) }, /* 16000.0 Hz */ 50 { (2.4201241845e-01), (3.7899379077e-01), (-8.0847117831e-01) }, /* 16000.0 Hz */
51 }; 51 };
52
53 int round_trick(float floatvalue_to_round);
54
55 /* Round function provided by Frank Klemm which saves around 100K
56 * CPU cycles in my PIII for each call to the IIR function
57 */
58 __inline__ int round_trick(float floatvalue_to_round)
59 {
60 float floattmp ;
61 int rounded_value ;
62
63 floattmp = (int) 0x00FD8000L + (floatvalue_to_round);
64 rounded_value = *(int*)(&floattmp) - (int)0x4B7D8000L;
65
66 if ( rounded_value != (short) rounded_value )
67 rounded_value = ( rounded_value >> 31 ) ^ 0x7FFF;
68 return rounded_value;
69 }
70 52
71 /* Init the filter */ 53 /* Init the filter */
72 void init_iir() 54 void init_iir()
73 { 55 {
74 iir_cf = iir_cforiginal10; 56 iir_cf = iir_cforiginal10;
168 */ 150 */
169 151
170 out[channel] += (data[index+channel]>>2); 152 out[channel] += (data[index+channel]>>2);
171 153
172 /* Round and convert to integer */ 154 /* Round and convert to integer */
173 #ifdef __i386__
174 tempgint = round_trick(out[channel]);
175 #else
176 tempgint = (int)lroundf(out[channel]); 155 tempgint = (int)lroundf(out[channel]);
177 #endif
178 156
179 /* Limit the output */ 157 /* Limit the output */
180 if (tempgint < -32768) 158 if (tempgint < -32768)
181 data[index+channel] = -32768; 159 data[index+channel] = -32768;
182 else if (tempgint > 32767) 160 else if (tempgint > 32767)
195 173
196 }/* For each pair of samples */ 174 }/* For each pair of samples */
197 175
198 return length; 176 return length;
199 } 177 }
200
201