-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFloatUtils.cs
66 lines (52 loc) · 1.39 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
59
60
61
62
63
64
65
66
using System;
/*
** FloatUtils.cs
**
** Copyright (c) 2010-2016 Peter McQuillan
**
** All Rights Reserved.
**
** Distributed under the BSD Software License (see license.txt)
***/
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];
counter++;
wps.float_shift = byteptr[counter];
counter++;
wps.float_max_exp = byteptr[counter];
counter++;
wps.float_norm_exp = byteptr[counter];
return Defines.TRUE;
}
internal static int[] 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] > 8388607L)
values[value_counter] = (int) SupportClass.Identity(8388607L);
else if (values[value_counter] < - 8388608L)
values[value_counter] = (int) SupportClass.Identity(- 8388608L);
value_counter++;
num_values--;
}
return values;
}
}