Fix gain compensation in STFT example
This commit is contained in:
parent
f05d209169
commit
376c1d7b0a
|
@ -50,11 +50,8 @@ impl Default for Stft {
|
||||||
let filter_window = util::window::hann(FILTER_WINDOW_SIZE);
|
let filter_window = util::window::hann(FILTER_WINDOW_SIZE);
|
||||||
real_fft_scratch_buffer[0..FILTER_WINDOW_SIZE].copy_from_slice(&filter_window);
|
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
|
// And make sure to normalize this so convolution sums to 1
|
||||||
// compensation for the windowing causes everything to stay about at unit level. Don't ask
|
let filter_normalization_factor = real_fft_scratch_buffer.iter().sum::<f32>().recip();
|
||||||
// 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() {
|
for sample in real_fft_scratch_buffer.as_slice_mut() {
|
||||||
*sample *= filter_normalization_factor;
|
*sample *= filter_normalization_factor;
|
||||||
}
|
}
|
||||||
|
@ -134,7 +131,7 @@ impl Plugin for Stft {
|
||||||
) -> ProcessStatus {
|
) -> ProcessStatus {
|
||||||
// Compensate for the window function, the overlap, and the extra gain introduced by the
|
// Compensate for the window function, the overlap, and the extra gain introduced by the
|
||||||
// IDFT operation
|
// 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(
|
self.stft.process_overlap_add(
|
||||||
buffer,
|
buffer,
|
||||||
|
|
Loading…
Reference in a new issue