1
0
Fork 0
forked from len0rd/rockbox

Update libwavpack with latest changes from the tiny_encoder. This allows

playback of floating-point audio files, fixes a obscure decoding bug, and
improves encoding speed somewhat.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11944 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dave Bryant 2007-01-08 04:24:32 +00:00
parent 5693622cd4
commit 2446b22db9
4 changed files with 41 additions and 78 deletions

View file

@ -25,59 +25,23 @@ int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd)
return TRUE;
}
/* This function converts WavPack floating point data into standard Rockbox
* 28-bit integers. It is assumed that clipping will be taken care of later.
*/
void float_values (WavpackStream *wps, int32_t *values, int32_t num_values)
{
while (num_values--) {
int shift_count = 0, exp = wps->float_max_exp;
f32 outval = { 0, 0, 0 };
int shift = wps->float_max_exp - wps->float_norm_exp + wps->float_shift + 5;
if (*values) {
*values <<= wps->float_shift;
if (shift > 32)
shift = 32;
else if (shift < -32)
shift = -32;
if (*values < 0) {
*values = -*values;
outval.sign = 1;
}
if (*values == 0x1000000)
outval.exponent = 255;
else {
if (exp)
while (!(*values & 0x800000) && --exp) {
shift_count++;
*values <<= 1;
}
if (shift_count && (wps->float_flags & FLOAT_SHIFT_ONES))
*values |= ((1 << shift_count) - 1);
outval.mantissa = *values;
outval.exponent = exp;
}
}
* (f32 *) values++ = outval;
}
}
void float_normalize (int32_t *values, int32_t num_values, int delta_exp)
{
f32 *fvalues = (f32 *) values, fzero = { 0, 0, 0 };
int exp;
if (!delta_exp)
return;
while (num_values--) {
if ((exp = fvalues->exponent) == 0 || exp + delta_exp <= 0)
*fvalues = fzero;
else if (exp == 255 || (exp += delta_exp) >= 255) {
fvalues->exponent = 255;
fvalues->mantissa = 0;
}
else
fvalues->exponent = exp;
fvalues++;
}
if (shift > 0)
while (num_values--)
*values++ <<= shift;
else if (shift < 0)
while (num_values--)
*values++ >>= -shift;
}