mirror of
https://github.com/robbert-vdh/nih-plug.git
synced 2026-07-01 10:46:55 +00:00
Fix gain compensation in STFT example
This commit is contained in:
@@ -50,11 +50,8 @@ 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 `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;
|
||||
// And make sure to normalize this so convolution sums to 1
|
||||
let filter_normalization_factor = real_fft_scratch_buffer.iter().sum::<f32>().recip();
|
||||
for sample in real_fft_scratch_buffer.as_slice_mut() {
|
||||
*sample *= filter_normalization_factor;
|
||||
}
|
||||
@@ -134,7 +131,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 = 1.0 / OVERLAP_TIMES as f32 / WINDOW_SIZE as f32;
|
||||
const GAIN_COMPENSATION: f32 = f32::consts::E / OVERLAP_TIMES as f32 / WINDOW_SIZE as f32;
|
||||
|
||||
self.stft.process_overlap_add(
|
||||
buffer,
|
||||
|
||||
Reference in New Issue
Block a user