summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2006-02-03 08:27:53 +0000
committerDave Chapman <dave@dchapman.com>2006-02-03 08:27:53 +0000
commit347992e9d93ed0f91cde7e2d580cfdc8d5eb95f4 (patch)
tree631dade87e98ef745730460067f7560919dae459
parentd2e75bf02d1ad91fca0e283e8c71b1091ec85a80 (diff)
downloadrockbox-347992e9d93ed0f91cde7e2d580cfdc8d5eb95f4.tar.gz
rockbox-347992e9d93ed0f91cde7e2d580cfdc8d5eb95f4.zip
Optimised C version of count_leading_zeros() taken from alac-0.1.1. This makes ALAC very close to realtime on the ipod (just the very occasional skip during disk reading - it is realtime when the disk is sleeping).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8545 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/libalac/alac.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/apps/codecs/libalac/alac.c b/apps/codecs/libalac/alac.c
index 638ca93c16..0082b6dd42 100644
--- a/apps/codecs/libalac/alac.c
+++ b/apps/codecs/libalac/alac.c
@@ -184,18 +184,48 @@ static inline void unreadbits(alac_file *alac, int bits)
184 alac->input_buffer_bitaccumulator *= -1; 184 alac->input_buffer_bitaccumulator *= -1;
185} 185}
186 186
187/* hideously inefficient. could use a bitmask search, 187static inline int count_leading_zeros(int input)
188 * alternatively bsr on x86,
189 */
190static inline int count_leading_zeros(int32_t input)
191{ 188{
192 int i = 0; 189 int output = 0;
193 while (!(0x80000000 & input) && i < 32) 190 int curbyte = 0;
191
192 curbyte = input >> 24;
193 if (curbyte) goto found;
194 output += 8;
195
196 curbyte = input >> 16;
197 if (curbyte & 0xff) goto found;
198 output += 8;
199
200 curbyte = input >> 8;
201 if (curbyte & 0xff) goto found;
202 output += 8;
203
204 curbyte = input;
205 if (curbyte & 0xff) goto found;
206 output += 8;
207
208 return output;
209
210found:
211 if (!(curbyte & 0xf0))
194 { 212 {
195 i++; 213 output += 4;
196 input = input << 1;
197 } 214 }
198 return i; 215 else
216 curbyte >>= 4;
217
218 if (curbyte & 0x8)
219 return output;
220 if (curbyte & 0x4)
221 return output + 1;
222 if (curbyte & 0x2)
223 return output + 2;
224 if (curbyte & 0x1)
225 return output + 3;
226
227 /* shouldn't get here: */
228 return output + 4;
199} 229}
200 230
201void basterdised_rice_decompress(alac_file *alac, 231void basterdised_rice_decompress(alac_file *alac,