diff --git a/gui/src/effects.rs b/gui/src/effects.rs index b1aa12e..8fcf83c 100644 --- a/gui/src/effects.rs +++ b/gui/src/effects.rs @@ -10,6 +10,8 @@ use tracing::{error, info}; use crate::imp; static DF_MODEL: Asset = asset!("/assets/DeepFilterNet3_ll_onnx.tar.gz"); +// TODO: make this user configurable. +static DEFAULT_NOISE_FLOOR: f32 = 0.001; enum DenoisingModelState { Nothing, @@ -76,6 +78,7 @@ pub struct AudioProcessor { denoise: bool, spawn: imp::SpawnHandle, buffer: Vec, + noise_floor: f32, } impl AudioProcessor { @@ -84,6 +87,7 @@ impl AudioProcessor { denoise: false, spawn: imp::SpawnHandle::current(), buffer: Vec::new(), + noise_floor: DEFAULT_NOISE_FLOOR, } } @@ -92,6 +96,7 @@ impl AudioProcessor { denoise: true, spawn: imp::SpawnHandle::current(), buffer: Vec::new(), + noise_floor: DEFAULT_NOISE_FLOOR, } } } @@ -132,6 +137,16 @@ impl AudioProcessor { if include_raw { output.extend(audio.iter().step_by(channels).copied()); } + + // Adds threshoulding to prevent sending audio when things are really quiet. + let avg: f32 = if output.is_empty() { + 0.0 + } else { + output.iter().map(|x| x.abs()).sum::() / output.len() as f32 + }; + if avg < self.noise_floor { + output.clear(); + } } }