]> code.octet-stream.net Git - m17rt/blob - m17core/src/shaping.rs
Successful round tripping wav -> rrc -> audio out
[m17rt] / m17core / src / shaping.rs
1 pub static RRC_48K: [f32; 81] = [
2 -0.0031955054,
3 -0.002930098,
4 -0.001940547,
5 -0.00035607078,
6 0.0015469185,
7 0.003389342,
8 0.0047616027,
9 0.0053105336,
10 0.0048244493,
11 0.003297721,
12 0.00095865194,
13 -0.0017498062,
14 -0.00423843,
15 -0.005881418,
16 -0.006149877,
17 -0.0047450834,
18 -0.0017040828,
19 0.0025476913,
20 0.0072151264,
21 0.011230345,
22 0.013421123,
23 0.012729687,
24 0.008449026,
25 0.00043672565,
26 -0.010734711,
27 -0.023725418,
28 -0.03649577,
29 -0.04649801,
30 -0.0509759,
31 -0.04733776,
32 -0.03355284,
33 -0.008513286,
34 0.027694825,
35 0.07365995,
36 0.1266812,
37 0.18297966,
38 0.23806532,
39 0.28721792,
40 0.3260201,
41 0.35087407,
42 0.35943073,
43 0.35087407,
44 0.3260201,
45 0.28721792,
46 0.23806532,
47 0.18297966,
48 0.1266812,
49 0.07365995,
50 0.027694825,
51 -0.008513286,
52 -0.03355284,
53 -0.04733776,
54 -0.0509759,
55 -0.04649801,
56 -0.03649577,
57 -0.023725418,
58 -0.010734711,
59 0.00043672565,
60 0.008449026,
61 0.012729687,
62 0.013421123,
63 0.011230345,
64 0.0072151264,
65 0.0025476913,
66 -0.0017040828,
67 -0.0047450834,
68 -0.006149877,
69 -0.005881418,
70 -0.00423843,
71 -0.0017498062,
72 0.00095865194,
73 0.003297721,
74 0.0048244493,
75 0.0053105336,
76 0.0047616027,
77 0.003389342,
78 0.0015469185,
79 -0.00035607078,
80 -0.001940547,
81 -0.002930098,
82 -0.0031955054,
83 ];
84
85 #[cfg(test)]
86 mod test {
87 use std::f32::consts::PI;
88
89 #[test]
90 fn calculate_rrc_coefficients() {
91 let mut rrc = [0.0; 81];
92 let roll_off = 0.5;
93 let t_s: f32 = 10.0;
94
95 let inf_t = t_s / (4.0 * roll_off);
96
97 for i in 0..81 {
98 let t = (i as isize - 40) as f32;
99
100 if t == 0.0 {
101 rrc[i] = 1.0 / t_s.sqrt() * ((1.0 - roll_off) + (4.0 * roll_off / PI));
102 } else if t == inf_t || t == -inf_t {
103 rrc[i] = roll_off / (2.0 * t_s).sqrt()
104 * ((1.0 + 2.0 / PI) * f32::sin(PI / (4.0 * roll_off))
105 + (1.0 - 2.0 / PI) * f32::cos(PI / (4.0 * roll_off)));
106 } else {
107 rrc[i] = 1.0 / t_s.sqrt()
108 * (f32::sin((PI * t * (1.0 - roll_off)) / t_s)
109 + (4.0 * roll_off * t) / t_s * f32::cos((PI * t * (1.0 + roll_off)) / t_s))
110 / (PI * t / t_s * (1.0 - (4.0 * roll_off * t / t_s).powi(2)));
111 }
112 }
113
114 println!("{:?}", rrc);
115 for (a, b) in rrc.iter().zip(super::RRC_48K.iter()) {
116 assert!((a - b).abs() < 0.00001);
117 }
118 }
119 }