forked from soiaf/C-Sharp-WavPack-Decoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FloatUtils.cs
58 lines (49 loc) · 1.24 KB
/
FloatUtils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
** FloatUtils.cs
**
** Copyright (c) 2010-2016 Peter McQuillan
**
** All Rights Reserved.
**
** Distributed under the BSD Software License (see license.txt)
***/
namespace WavPack
{
class FloatUtils
{
internal static int read_float_info(WavpackStream wps, WavpackMetadata wpmd)
{
int bytecnt = wpmd.byte_length;
byte[] byteptr = wpmd.data;
int counter = 0;
if (bytecnt != 4)
return Defines.FALSE;
wps.float_flags = byteptr[counter++];
wps.float_shift = byteptr[counter++];
wps.float_max_exp = byteptr[counter++];
wps.float_norm_exp = byteptr[counter++];
return Defines.TRUE;
}
internal static void float_values(WavpackStream wps, int[] values, long num_values, int bufferStartPos)
{
int shift = wps.float_max_exp - wps.float_norm_exp + wps.float_shift;
int value_counter = bufferStartPos;
if (shift > 32)
shift = 32;
else if (shift < -32)
shift = -32;
while (num_values-- > 0)
{
if (shift > 0)
values[value_counter] <<= shift;
else if (shift < 0)
values[value_counter] >>= -shift;
if (values[value_counter] > 8388607)
values[value_counter] = 8388607;
else if (values[value_counter] < -8388608)
values[value_counter] = -8388608;
value_counter++;
}
}
}
}