1 //! Window generating functions.
4 /// Known window types.
5 #[derive(Debug,Clone,Copy,PartialEq)]
7 /// Simple square window.
9 /// Simple sine window.
11 /// Kaiser-Bessel derived window.
15 /// Calculates window coefficients for the requested window type and size.
17 /// Set `half` flag to calculate only the first half of the window.
18 pub fn generate_window(mode: WindowType, scale: f32, size: usize, half: bool, dst: &mut [f32]) {
20 WindowType::Square => {
21 for n in 0..size { dst[n] = scale; }
25 consts::PI / ((2 * size) as f32)
27 consts::PI / (size as f32)
30 dst[n] = (((n as f32) + 0.5) * param).sin() * scale;
33 WindowType::KaiserBessel(alpha) => {
34 let dlen = if half { size as f32 } else { (size as f32) * 0.5 };
35 let alpha2 = f64::from((alpha * consts::PI / dlen) * (alpha * consts::PI / dlen));
37 let mut kb: Vec<f64> = Vec::with_capacity(size);
40 let b = bessel_i0(((n * (size - n)) as f64) * alpha2);
46 dst[n] = (kb[n] / sum).sqrt() as f32;
52 fn bessel_i0(inval: f64) -> f64 {
53 let mut val: f64 = 1.0;
54 for n in (1..64).rev() {
55 val *= inval / f64::from(n * n);