1
0
Fork 0

Fix gain compensation in STFT examples

This commit is contained in:
Robbert van der Helm 2022-04-28 17:24:35 +02:00
parent e35886c216
commit 58d7dc034c
2 changed files with 2 additions and 3 deletions

View file

@ -124,7 +124,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 = f32::consts::E / OVERLAP_TIMES as f32 / WINDOW_SIZE as f32; const GAIN_COMPENSATION: f32 = 1.0 / (OVERLAP_TIMES as f32 / 2.0) / WINDOW_SIZE as f32;
self.stft self.stft
.process_overlap_add(buffer, OVERLAP_TIMES, |_channel_idx, real_fft_buffer| { .process_overlap_add(buffer, OVERLAP_TIMES, |_channel_idx, real_fft_buffer| {

View file

@ -205,8 +205,7 @@ impl Plugin for PubertySimulator {
let window_size = self.window_size(); let window_size = self.window_size();
let overlap_times = self.overlap_times(); let overlap_times = self.overlap_times();
let sample_rate = context.transport().sample_rate; let sample_rate = context.transport().sample_rate;
let gain_compensation: f32 = let gain_compensation: f32 = (overlap_times as f32 / 2.0).recip() / window_size as f32;
(overlap_times as f32 / 2.0).sqrt().recip() / window_size as f32;
// If the window size has changed since the last process call, reset the buffers and chance // If the window size has changed since the last process call, reset the buffers and chance
// our latency. All of these buffers already have enough capacity // our latency. All of these buffers already have enough capacity