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
73
74
75
76
77
78
79
80
81
use super::*;
pub mod stereo;
pub use stereo::*;
pub trait Panner<SF,G>
where SF: Panner<SF,G>,
G: Sized
{
fn to_sample_format(s: SampleT, g: G) -> SF;
}
pub fn sample_from_u8(v: u8) -> SampleT {
(v as SampleT - 128.0) / 128.0
}
pub fn sample_from_u8_bytes(v:[u8;1]) -> SampleT {
(v[0] as SampleT - 128.0) / 128.0
}
pub fn sample_to_u8(s: SampleT) -> u8 {
(s * 128.0 + 128.0).round() as u8
}
pub fn sample_to_u8_bytes(s: SampleT) -> [u8;1] {
[sample_to_u8(s)]
}
pub fn sample_from_i16(v: i16) -> SampleT {
v as SampleT / ((1 << 15) as SampleT - 1.0)
}
pub fn sample_from_i16_bytes(v:[u8;2]) -> SampleT {
(i16::from_le_bytes(v) as SampleT) / ((1 << 15) as SampleT - 1.0)
}
pub fn sample_to_i16(s: SampleT) -> i16 {
(s * ((1<<15) as SampleT - 1.0)).round() as i16
}
pub fn sample_to_i16_bytes(s: SampleT) -> [u8; 2] {
sample_to_i16(s).to_le_bytes()
}
pub fn sample_from_i24(v: i32) -> SampleT {
v as SampleT / ((1 << 23) as SampleT - 1.0)
}
pub fn sample_from_i24_bytes(v:[u8;3]) -> SampleT {
(i32::from_le_bytes([v[0],v[1],v[2],0]) as SampleT) / ((1 << 23) as SampleT - 1.0)
}
pub fn sample_to_i24(s: SampleT) -> i32 {
(s * ((1<<23) as SampleT - 1.0)).round() as i32
}
pub fn sample_to_i24_bytes(s: SampleT) -> [u8; 3] {
let i = sample_to_i24(s).to_le_bytes();
[i[0],i[1],i[2]]
}