1
0
Fork 0

Revert windowing change from 93ab08e

This is actually needed to prevent spectral leakage from IDTFs with
small window sizes.
This commit is contained in:
Robbert van der Helm 2022-03-06 19:17:42 +01:00
parent 93ab08e5d5
commit e61a42e96f
2 changed files with 8 additions and 3 deletions

View file

@ -2,6 +2,7 @@ use fftw::array::AlignedVec;
use fftw::plan::{C2RPlan, C2RPlan32, R2CPlan, R2CPlan32};
use fftw::types::{c32, Flag};
use nih_plug::prelude::*;
use std::f32;
use std::pin::Pin;
const WINDOW_SIZE: usize = 2048;
@ -49,8 +50,11 @@ impl Default for Stft {
let filter_window = util::window::hann(FILTER_WINDOW_SIZE);
real_fft_scratch_buffer[0..FILTER_WINDOW_SIZE].copy_from_slice(&filter_window);
// And make sure to normalize this so convolution sums to 1
let filter_normalization_factor = real_fft_scratch_buffer.iter().sum::<f32>().recip();
// And make sure to normalize this so convolution sums to `e` which together with the
// compensation for the windowing causes everything to stay about at unit level. Don't ask
// my why this number.
let filter_normalization_factor =
real_fft_scratch_buffer.iter().sum::<f32>().recip() * f32::consts::E;
for sample in real_fft_scratch_buffer.as_slice_mut() {
*sample *= filter_normalization_factor;
}
@ -130,7 +134,7 @@ impl Plugin for Stft {
) -> ProcessStatus {
// Compensate for the window function, the overlap, and the extra gain introduced by the
// IDFT operation
const GAIN_COMPENSATION: f32 = 2.0 / OVERLAP_TIMES as f32 / WINDOW_SIZE as f32;
const GAIN_COMPENSATION: f32 = 1.0 / OVERLAP_TIMES as f32 / WINDOW_SIZE as f32;
self.stft.process_overlap_add(
buffer,

View file

@ -248,6 +248,7 @@ impl<const NUM_SIDECHAIN_INPUTS: usize> StftHelper<NUM_SIDECHAIN_INPUTS> {
process_cb(channel_idx, None, &mut self.scratch_buffer);
// The actual overlap-add part of the equation
multiply_with_window(&mut self.scratch_buffer, window_function);
add_scratch_to_ring_buffer(
&self.scratch_buffer,
self.current_pos,