summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libwavpack/float.c
diff options
context:
space:
mode:
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}