-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.rs
52 lines (49 loc) · 1.45 KB
/
build.rs
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
use std::io::Write;
fn pfir(pfirm: [f64; 6]) -> [i32; 64] {
let mut pfir = [0; 64];
for (i, v) in pfir.iter_mut().enumerate() {
let i = i as i32;
let a = i / 8;
let a = a * 8;
let b = match i % 8 {
0 => [0, 1, 2, 3, 4, 5],
b => [b; 6],
};
*v = (pfirm[0] * (2 * (a >> b[0] & 1) - 1) as f64
+ pfirm[1] * (2 * (a >> b[1] & 1) - 1) as f64
+ pfirm[2] * (2 * (a >> b[2] & 1) - 1) as f64
+ pfirm[3] * (2 * (a >> b[3] & 1) - 1) as f64
+ pfirm[4] * (2 * (a >> b[4] & 1) - 1) as f64
+ pfirm[5] * (2 * (a >> b[5] & 1) - 1) as f64) as i32
}
pfir
}
fn main() {
let pfira = pfir([
2048.0 * 1.190566,
2048.0 * 0.162580,
2048.0 * 0.002208,
2048.0 * 0.025475,
2048.0 * -0.001522,
2048.0 * 0.007322,
]);
let pfirb = pfir([
2048.0 * 0.001774,
2048.0 * 0.004529,
2048.0 * -0.001561,
2048.0 * 0.000776,
2048.0 * -0.000486,
2048.0 * 0.002017,
]);
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let dest_path = std::path::Path::new(&out_dir).join("pink.rs");
let mut dest_file = std::fs::File::create(dest_path).unwrap();
write!(
dest_file,
"const PFIRA: [i32; 64] = {:?};\
const PFIRB: [i32; 64] = {:?};",
pfira, pfirb,
)
.unwrap();
println!("cargo:rerun-if-changed=build.rs");
}