summaryrefslogtreecommitdiff
path: root/apps/codecs/libalac
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 /apps/codecs/libalac
parentd2e75bf02d1ad91fca0e283e8c71b1091ec85a80 (diff)
downloadrockbox-347992e9d93ed0f91cde7e2d580cfdc8d5eb95f4.zip
rockbox-347992e9d93ed0f91cde7e2d580cfdc8d5eb95f4.tar.gz
rockbox-347992e9d93ed0f91cde7e2d580cfdc8d5eb95f4.tar.bz2
rockbox-347992e9d93ed0f91cde7e2d580cfdc8d5eb95f4.tar.xz
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
Diffstat (limited to 'apps/codecs/libalac')
-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 638ca93..0082b6d 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)
alac->input_buffer_bitaccumulator *= -1;
}
-/* hideously inefficient. could use a bitmask search,
- * alternatively bsr on x86,
- */
-static inline int count_leading_zeros(int32_t input)
+static inline int count_leading_zeros(int input)
{
- int i = 0;
- while (!(0x80000000 & input) && i < 32)
+ int output = 0;
+ int curbyte = 0;
+
+ curbyte = input >> 24;
+ if (curbyte) goto found;
+ output += 8;
+
+ curbyte = input >> 16;
+ if (curbyte & 0xff) goto found;
+ output += 8;
+
+ curbyte = input >> 8;
+ if (curbyte & 0xff) goto found;
+ output += 8;
+
+ curbyte = input;
+ if (curbyte & 0xff) goto found;
+ output += 8;
+
+ return output;
+
+found:
+ if (!(curbyte & 0xf0))
{
- i++;
- input = input << 1;
+ output += 4;
}
- return i;
+ else
+ curbyte >>= 4;
+
+ if (curbyte & 0x8)
+ return output;
+ if (curbyte & 0x4)
+ return output + 1;
+ if (curbyte & 0x2)
+ return output + 2;
+ if (curbyte & 0x1)
+ return output + 3;
+
+ /* shouldn't get here: */
+ return output + 4;
}
void basterdised_rice_decompress(alac_file *alac,