forked from len0rd/rockbox
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
This commit is contained in:
parent
d2e75bf02d
commit
347992e9d9
1 changed files with 39 additions and 9 deletions
|
|
@ -184,18 +184,48 @@ static inline void unreadbits(alac_file *alac, int bits)
|
||||||
alac->input_buffer_bitaccumulator *= -1;
|
alac->input_buffer_bitaccumulator *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hideously inefficient. could use a bitmask search,
|
static inline int count_leading_zeros(int input)
|
||||||
* alternatively bsr on x86,
|
|
||||||
*/
|
|
||||||
static inline int count_leading_zeros(int32_t input)
|
|
||||||
{
|
{
|
||||||
int i = 0;
|
int output = 0;
|
||||||
while (!(0x80000000 & input) && i < 32)
|
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++;
|
output += 4;
|
||||||
input = input << 1;
|
|
||||||
}
|
}
|
||||||
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,
|
void basterdised_rice_decompress(alac_file *alac,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue