summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libwavpack/float.c
diff options
context:
space:
mode:
authorSean Bartell <wingedtachikoma@gmail.com>2011-06-25 21:32:25 -0400
committerNils Wallménius <nils@rockbox.org>2012-04-25 22:13:20 +0200
commitf40bfc9267b13b54e6379dfe7539447662879d24 (patch)
tree9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libwavpack/float.c
parenta0009907de7a0107d49040d8a180f140e2eff299 (diff)
downloadrockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz
rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97 Reviewed-on: http://gerrit.rockbox.org/137 Reviewed-by: Nils Wallménius <nils@rockbox.org> Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libwavpack/float.c')
-rw-r--r--lib/rbcodec/codecs/libwavpack/float.c47
1 files changed, 47 insertions, 0 deletions
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 @@
1////////////////////////////////////////////////////////////////////////////
2// **** WAVPACK **** //
3// Hybrid Lossless Wavefile Compressor //
4// Copyright (c) 1998 - 2004 Conifer Software. //
5// All Rights Reserved. //
6// Distributed under the BSD Software License (see license.txt) //
7////////////////////////////////////////////////////////////////////////////
8
9// float.c
10
11#include "wavpack.h"
12
13int read_float_info (WavpackStream *wps, WavpackMetadata *wpmd)
14{
15 int bytecnt = wpmd->byte_length;
16 char *byteptr = wpmd->data;
17
18 if (bytecnt != 4)
19 return FALSE;
20
21 wps->float_flags = *byteptr++;
22 wps->float_shift = *byteptr++;
23 wps->float_max_exp = *byteptr++;
24 wps->float_norm_exp = *byteptr;
25 return TRUE;
26}
27
28/* This function converts WavPack floating point data into standard Rockbox
29 * 28-bit integers. It is assumed that clipping will be taken care of later.
30 */
31
32void float_values (WavpackStream *wps, int32_t *values, int32_t num_values)
33{
34 int shift = wps->float_max_exp - wps->float_norm_exp + wps->float_shift + 5;
35
36 if (shift > 32)
37 shift = 32;
38 else if (shift < -32)
39 shift = -32;
40
41 if (shift > 0)
42 while (num_values--)
43 *values++ <<= shift;
44 else if (shift < 0)
45 while (num_values--)
46 *values++ >>= -shift;
47}