Add an in-place version of the Hann function
This commit is contained in:
parent
81308d0c8d
commit
17f3c6cc6c
1 changed files with 12 additions and 0 deletions
|
@ -17,6 +17,18 @@ pub fn hann(size: usize) -> Vec<f32> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// The same as [`hann()`], but filling an existing slice instead.
|
||||
pub fn hann_in_place(window: &mut [f32]) {
|
||||
let size = window.len();
|
||||
|
||||
// We want to scale `[0, size - 1]` to `[0, pi]`.
|
||||
let scale = (size as f32 - 1.0).recip() * f32::consts::TAU;
|
||||
for (i, sample) in window.iter_mut().enumerate() {
|
||||
let cos = (i as f32 * scale).cos();
|
||||
*sample = 0.5 - (0.5 * cos)
|
||||
}
|
||||
}
|
||||
|
||||
/// Multiply a buffer with a window function.
|
||||
#[inline]
|
||||
pub fn multiply_with_window(buffer: &mut [f32], window_function: &[f32]) {
|
||||
|
|
Loading…
Add table
Reference in a new issue