From f40bfc9267b13b54e6379dfe7539447662879d24 Mon Sep 17 00:00:00 2001 From: Sean Bartell Date: Sat, 25 Jun 2011 21:32:25 -0400 Subject: Add codecs to librbcodec. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97 Reviewed-on: http://gerrit.rockbox.org/137 Reviewed-by: Nils Wallménius Tested-by: Nils Wallménius --- lib/rbcodec/codecs/libwavpack/float.c | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 lib/rbcodec/codecs/libwavpack/float.c (limited to 'lib/rbcodec/codecs/libwavpack/float.c') diff --git a/lib/rbcodec/codecs/libwavpack/float.c b/lib/rbcodec/codecs/libwavpack/float.c new file mode 100644 index 0000000000..6e5c4e4f61 --- /dev/null +++ b/lib/rbcodec/codecs/libwavpack/float.c @@ -0,0 +1,47 @@ +//////////////////////////////////////////////////////////////////////////// +// **** WAVPACK **** // +// Hybrid Lossless Wavefile Compressor // +// Copyright (c) 1998 - 2004 Conifer Software. // +// All Rights Reserved. // +// 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) + return FALSE; + + wps->float_flags = *byteptr++; + wps->float_shift = *byteptr++; + wps->float_max_exp = *byteptr++; + wps->float_norm_exp = *byteptr; + 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) +{ + 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; +} -- cgit v1.2.3