diff options
author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-05-18 20:06:37 +0000 |
---|---|---|
committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-05-18 20:06:37 +0000 |
commit | a45af1c4fecc9dc522ac46bca39a7e6c6ef5d612 (patch) | |
tree | 860c4e89fe3626c07344a42855e77ca2dbb23f95 | |
parent | 9b6910c348fd9870d63e9d0736717f00bb2fbdf6 (diff) | |
download | rockbox-a45af1c4fecc9dc522ac46bca39a7e6c6ef5d612.tar.gz rockbox-a45af1c4fecc9dc522ac46bca39a7e6c6ef5d612.zip |
Reduce FRACMUL calls in equalizer.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29898 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/eq.c | 43 |
1 files changed, 25 insertions, 18 deletions
@@ -44,16 +44,18 @@ void filter_shelf_coefs(unsigned long cutoff, long A, bool low, int32_t *c) | |||
44 | sin = fp_sincos(cutoff/2, &cos); | 44 | sin = fp_sincos(cutoff/2, &cos); |
45 | if (low) { | 45 | if (low) { |
46 | const int32_t sin_div_g = fp_div(sin, g, 25); | 46 | const int32_t sin_div_g = fp_div(sin, g, 25); |
47 | const int32_t sin_g = FRACMUL(sin, g); | ||
47 | cos >>= 3; | 48 | cos >>= 3; |
48 | b0 = FRACMUL(sin, g) + cos; /* 0.25 .. 4.10 */ | 49 | b0 = sin_g + cos; /* 0.25 .. 4.10 */ |
49 | b1 = FRACMUL(sin, g) - cos; /* -1 .. 3.98 */ | 50 | b1 = sin_g - cos; /* -1 .. 3.98 */ |
50 | a0 = sin_div_g + cos; /* 0.25 .. 4.10 */ | 51 | a0 = sin_div_g + cos; /* 0.25 .. 4.10 */ |
51 | a1 = sin_div_g - cos; /* -1 .. 3.98 */ | 52 | a1 = sin_div_g - cos; /* -1 .. 3.98 */ |
52 | } else { | 53 | } else { |
53 | const int32_t cos_div_g = fp_div(cos, g, 25); | 54 | const int32_t cos_div_g = fp_div(cos, g, 25); |
55 | const int32_t cos_g = FRACMUL(cos, g); | ||
54 | sin >>= 3; | 56 | sin >>= 3; |
55 | b0 = sin + FRACMUL(cos, g); /* 0.25 .. 4.10 */ | 57 | b0 = sin + cos_g; /* 0.25 .. 4.10 */ |
56 | b1 = sin - FRACMUL(cos, g); /* -3.98 .. 1 */ | 58 | b1 = sin - cos_g; /* -3.98 .. 1 */ |
57 | a0 = sin + cos_div_g; /* 0.25 .. 4.10 */ | 59 | a0 = sin + cos_div_g; /* 0.25 .. 4.10 */ |
58 | a1 = sin - cos_div_g; /* -3.98 .. 1 */ | 60 | a1 = sin - cos_div_g; /* -3.98 .. 1 */ |
59 | } | 61 | } |
@@ -130,11 +132,12 @@ void eq_pk_coefs(unsigned long cutoff, unsigned long Q, long db, int32_t *c) | |||
130 | int32_t a0, a1, a2; /* these are all s3.28 format */ | 132 | int32_t a0, a1, a2; /* these are all s3.28 format */ |
131 | int32_t b0, b1, b2; | 133 | int32_t b0, b1, b2; |
132 | const long alphadivA = fp_div(alpha, A, 27); | 134 | const long alphadivA = fp_div(alpha, A, 27); |
135 | const long alphaA = FRACMUL(alpha, A); | ||
133 | 136 | ||
134 | /* possible numerical ranges are in comments by each coef */ | 137 | /* possible numerical ranges are in comments by each coef */ |
135 | b0 = one + FRACMUL(alpha, A); /* [1 .. 5] */ | 138 | b0 = one + alphaA; /* [1 .. 5] */ |
136 | b1 = a1 = -2*(cs >> 3); /* [-2 .. 2] */ | 139 | b1 = a1 = -2*(cs >> 3); /* [-2 .. 2] */ |
137 | b2 = one - FRACMUL(alpha, A); /* [-3 .. 1] */ | 140 | b2 = one - alphaA; /* [-3 .. 1] */ |
138 | a0 = one + alphadivA; /* [1 .. 5] */ | 141 | a0 = one + alphadivA; /* [1 .. 5] */ |
139 | a2 = one - alphadivA; /* [-3 .. 1] */ | 142 | a2 = one - alphadivA; /* [-3 .. 1] */ |
140 | 143 | ||
@@ -160,22 +163,24 @@ void eq_ls_coefs(unsigned long cutoff, unsigned long Q, long db, int32_t *c) | |||
160 | const long alpha = fp_sincos(cutoff, &cs)/(2*Q)*10 >> 1; /* s1.30 */ | 163 | const long alpha = fp_sincos(cutoff, &cs)/(2*Q)*10 >> 1; /* s1.30 */ |
161 | const long ap1 = (A >> 4) + one; | 164 | const long ap1 = (A >> 4) + one; |
162 | const long am1 = (A >> 4) - one; | 165 | const long am1 = (A >> 4) - one; |
166 | const long ap1_cs = FRACMUL(ap1, cs); | ||
167 | const long am1_cs = FRACMUL(am1, cs); | ||
163 | const long twosqrtalpha = 2*FRACMUL(sqrtA, alpha); | 168 | const long twosqrtalpha = 2*FRACMUL(sqrtA, alpha); |
164 | int32_t a0, a1, a2; /* these are all s6.25 format */ | 169 | int32_t a0, a1, a2; /* these are all s6.25 format */ |
165 | int32_t b0, b1, b2; | 170 | int32_t b0, b1, b2; |
166 | 171 | ||
167 | /* [0.1 .. 40] */ | 172 | /* [0.1 .. 40] */ |
168 | b0 = FRACMUL_SHL(A, ap1 - FRACMUL(am1, cs) + twosqrtalpha, 2); | 173 | b0 = FRACMUL_SHL(A, ap1 - am1_cs + twosqrtalpha, 2); |
169 | /* [-16 .. 63.4] */ | 174 | /* [-16 .. 63.4] */ |
170 | b1 = FRACMUL_SHL(A, am1 - FRACMUL(ap1, cs), 3); | 175 | b1 = FRACMUL_SHL(A, am1 - ap1_cs, 3); |
171 | /* [0 .. 31.7] */ | 176 | /* [0 .. 31.7] */ |
172 | b2 = FRACMUL_SHL(A, ap1 - FRACMUL(am1, cs) - twosqrtalpha, 2); | 177 | b2 = FRACMUL_SHL(A, ap1 - am1_cs - twosqrtalpha, 2); |
173 | /* [0.5 .. 10] */ | 178 | /* [0.5 .. 10] */ |
174 | a0 = ap1 + FRACMUL(am1, cs) + twosqrtalpha; | 179 | a0 = ap1 + am1_cs + twosqrtalpha; |
175 | /* [-16 .. 4] */ | 180 | /* [-16 .. 4] */ |
176 | a1 = -2*((am1 + FRACMUL(ap1, cs))); | 181 | a1 = -2*(am1 + ap1_cs); |
177 | /* [0 .. 8] */ | 182 | /* [0 .. 8] */ |
178 | a2 = ap1 + FRACMUL(am1, cs) - twosqrtalpha; | 183 | a2 = ap1 + am1_cs - twosqrtalpha; |
179 | 184 | ||
180 | /* [0.1 .. 1.99] */ | 185 | /* [0.1 .. 1.99] */ |
181 | const long rcp_a0 = fp_div(1, a0, 55); /* s1.30 */ | 186 | const long rcp_a0 = fp_div(1, a0, 55); /* s1.30 */ |
@@ -199,22 +204,24 @@ void eq_hs_coefs(unsigned long cutoff, unsigned long Q, long db, int32_t *c) | |||
199 | const long alpha = fp_sincos(cutoff, &cs)/(2*Q)*10 >> 1; /* s1.30 */ | 204 | const long alpha = fp_sincos(cutoff, &cs)/(2*Q)*10 >> 1; /* s1.30 */ |
200 | const long ap1 = (A >> 4) + one; | 205 | const long ap1 = (A >> 4) + one; |
201 | const long am1 = (A >> 4) - one; | 206 | const long am1 = (A >> 4) - one; |
207 | const long ap1_cs = FRACMUL(ap1, cs); | ||
208 | const long am1_cs = FRACMUL(am1, cs); | ||
202 | const long twosqrtalpha = 2*FRACMUL(sqrtA, alpha); | 209 | const long twosqrtalpha = 2*FRACMUL(sqrtA, alpha); |
203 | int32_t a0, a1, a2; /* these are all s6.25 format */ | 210 | int32_t a0, a1, a2; /* these are all s6.25 format */ |
204 | int32_t b0, b1, b2; | 211 | int32_t b0, b1, b2; |
205 | 212 | ||
206 | /* [0.1 .. 40] */ | 213 | /* [0.1 .. 40] */ |
207 | b0 = FRACMUL_SHL(A, ap1 + FRACMUL(am1, cs) + twosqrtalpha, 2); | 214 | b0 = FRACMUL_SHL(A, ap1 + am1_cs + twosqrtalpha, 2); |
208 | /* [-63.5 .. 16] */ | 215 | /* [-63.5 .. 16] */ |
209 | b1 = -FRACMUL_SHL(A, am1 + FRACMUL(ap1, cs), 3); | 216 | b1 = -FRACMUL_SHL(A, am1 + ap1_cs, 3); |
210 | /* [0 .. 32] */ | 217 | /* [0 .. 32] */ |
211 | b2 = FRACMUL_SHL(A, ap1 + FRACMUL(am1, cs) - twosqrtalpha, 2); | 218 | b2 = FRACMUL_SHL(A, ap1 + am1_cs - twosqrtalpha, 2); |
212 | /* [0.5 .. 10] */ | 219 | /* [0.5 .. 10] */ |
213 | a0 = ap1 - FRACMUL(am1, cs) + twosqrtalpha; | 220 | a0 = ap1 - am1_cs + twosqrtalpha; |
214 | /* [-4 .. 16] */ | 221 | /* [-4 .. 16] */ |
215 | a1 = 2*((am1 - FRACMUL(ap1, cs))); | 222 | a1 = 2*(am1 - ap1_cs); |
216 | /* [0 .. 8] */ | 223 | /* [0 .. 8] */ |
217 | a2 = ap1 - FRACMUL(am1, cs) - twosqrtalpha; | 224 | a2 = ap1 - am1_cs - twosqrtalpha; |
218 | 225 | ||
219 | /* [0.1 .. 1.99] */ | 226 | /* [0.1 .. 1.99] */ |
220 | const long rcp_a0 = fp_div(1, a0, 55); /* s1.30 */ | 227 | const long rcp_a0 = fp_div(1, a0, 55); /* s1.30 */ |