summaryrefslogtreecommitdiff
path: root/apps/codecs
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2006-02-05 09:12:57 +0000
committerDave Chapman <dave@dchapman.com>2006-02-05 09:12:57 +0000
commit1a03c3794776d2295b733ed516edee887bc81fcc (patch)
treeaeb656060f46969129ea58da416cd514407efe41 /apps/codecs
parentf9df934d9066488357c2020f0fda3a659b4b0a3b (diff)
downloadrockbox-1a03c3794776d2295b733ed516edee887bc81fcc.zip
rockbox-1a03c3794776d2295b733ed516edee887bc81fcc.tar.gz
rockbox-1a03c3794776d2295b733ed516edee887bc81fcc.tar.bz2
rockbox-1a03c3794776d2295b733ed516edee887bc81fcc.tar.xz
A better count_leading_zeros() function, courtesy of Jens Arnold
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8577 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs')
-rw-r--r--apps/codecs/libalac/alac.c64
1 files changed, 27 insertions, 37 deletions
diff --git a/apps/codecs/libalac/alac.c b/apps/codecs/libalac/alac.c
index 0082b6d..5487c68 100644
--- a/apps/codecs/libalac/alac.c
+++ b/apps/codecs/libalac/alac.c
@@ -184,50 +184,40 @@ static inline void unreadbits(alac_file *alac, int bits)
alac->input_buffer_bitaccumulator *= -1;
}
+static const unsigned char bittab[16] ICONST_ATTR = {
+ 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4
+};
+
static inline int count_leading_zeros(int input)
{
- 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;
+ int output = 32;
- return output;
-
-found:
- if (!(curbyte & 0xf0))
+#if 0
+ /* Experimentation has shown that the following test is always false,
+ so we don't bother to perform it. */
+ if (input & 0xffff0000)
{
- output += 4;
+ input >>= 16;
+ output -= 16;
}
- 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;
+#endif
+ if (input & 0xff00)
+ {
+ input >>= 8;
+ output -= 8;
+ }
+ if (input & 0xf0)
+ {
+ input >>= 4;
+ output -= 4;
+ }
+ output -= bittab[input];
+ return output;
}
+
+
+
void basterdised_rice_decompress(alac_file *alac,
int32_t *output_buffer,
int output_size,