-
Notifications
You must be signed in to change notification settings - Fork 0
/
FloatUtils.hx
72 lines (60 loc) · 1.91 KB
/
FloatUtils.hx
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
67
68
69
70
71
72
/*
** FloatUtils.hx
**
** Copyright (c) 2008 - 2013 Peter McQuillan
**
** All Rights Reserved.
**
** Distributed under the BSD Software License (see license.txt)
**
*/
class FloatUtils
{
public static function read_float_info (wps : WavpackStream, wpmd : WavpackMetadata) : Int
{
var bytecnt : Int = wpmd.byte_length;
#if flash10
var byteptr : flash.Vector < Int > = wpmd.data;
#else
var byteptr : Array < Int > = wpmd.data;
#end
var counter : Int = 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;
}
#if flash10
public static function float_values (wps : WavpackStream, values : flash.Vector < Int >, num_values : Float, bufferStartPos : Int) : flash.Vector < Int >
#else
public static function float_values (wps : WavpackStream, values : Array < Int >, num_values : Float, bufferStartPos : Int) : Array < Int >
#end
{
var shift : Int = wps.float_max_exp - wps.float_norm_exp + wps.float_shift;
var value_counter : Int = 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++;
num_values--;
}
return values;
}
}