2005-02-25 17:05:30 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2005-07-04 06:38:00 +00:00
|
|
|
// **** WAVPACK **** //
|
|
|
|
// Hybrid Lossless Wavefile Compressor //
|
|
|
|
// Copyright (c) 1998 - 2004 Conifer Software. //
|
|
|
|
// All Rights Reserved. //
|
2005-02-25 17:05:30 +00:00
|
|
|
// Distributed under the BSD Software License (see license.txt) //
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// float.c
|
|
|
|
|
|
|
|
#include "wavpack.h"
|
|
|
|
|
|
|
|
int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd)
|
|
|
|
{
|
|
|
|
int bytecnt = wpmd->byte_length;
|
|
|
|
char *byteptr = wpmd->data;
|
|
|
|
|
|
|
|
if (bytecnt != 4)
|
2005-07-04 06:38:00 +00:00
|
|
|
return FALSE;
|
2005-02-25 17:05:30 +00:00
|
|
|
|
|
|
|
wps->float_flags = *byteptr++;
|
|
|
|
wps->float_shift = *byteptr++;
|
|
|
|
wps->float_max_exp = *byteptr++;
|
|
|
|
wps->float_norm_exp = *byteptr;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-01-08 04:24:32 +00:00
|
|
|
/* This function converts WavPack floating point data into standard Rockbox
|
|
|
|
* 28-bit integers. It is assumed that clipping will be taken care of later.
|
|
|
|
*/
|
2005-07-04 06:38:00 +00:00
|
|
|
|
2007-01-08 04:24:32 +00:00
|
|
|
void float_values (WavpackStream *wps, int32_t *values, int32_t num_values)
|
2005-02-25 17:05:30 +00:00
|
|
|
{
|
2007-01-08 04:24:32 +00:00
|
|
|
int shift = wps->float_max_exp - wps->float_norm_exp + wps->float_shift + 5;
|
|
|
|
|
|
|
|
if (shift > 32)
|
|
|
|
shift = 32;
|
|
|
|
else if (shift < -32)
|
|
|
|
shift = -32;
|
|
|
|
|
|
|
|
if (shift > 0)
|
|
|
|
while (num_values--)
|
|
|
|
*values++ <<= shift;
|
|
|
|
else if (shift < 0)
|
|
|
|
while (num_values--)
|
|
|
|
*values++ >>= -shift;
|
2005-02-25 17:05:30 +00:00
|
|
|
}
|