use std::f64::consts::PI;
pub fn rectangle(window: &mut [f32]) {
window.fill(1.0);
}
pub fn hann(window: &mut [f32]) {
let l = window.len() as i32;
let n_den = (l - 1) as f64;
for (n, w) in window.iter_mut().enumerate() {
let arg = (2.0 * PI * n as f64 / n_den) as f32;
*w = 0.5f32 - 0.5f32 * arg.cos();
}
}
pub fn tukey(window: &mut [f32], p: f32) {
if p <= 0.0 {
rectangle(window);
} else if p >= 1.0 {
hann(window);
} else if !(p > 0.0 && p < 1.0) {
tukey(window, 0.5);
} else {
let l = window.len() as i32;
let np = (p / 2.0f32 * l as f32) as i32 - 1;
rectangle(window);
if np > 0 {
let npf = np as f64;
for n in 0..=np {
let rise = (PI * n as f64 / npf) as f32;
window[n as usize] = 0.5f32 - 0.5f32 * rise.cos();
let fall = (PI * (n + np) as f64 / npf) as f32;
window[(l - np - 1 + n) as usize] = 0.5f32 - 0.5f32 * fall.cos();
}
}
}
}