Add a default noise floor.
Pretty simple, if the average amplitude is under a certain value clear out the buffer! The value I chose (.001) was an arbitrary value I got from printf debugging. I was able to show that this worked pretty well on the desktop session. Hopefully we'll add this to the settings page at some point.
This commit is contained in:
@@ -10,6 +10,8 @@ use tracing::{error, info};
|
|||||||
use crate::imp;
|
use crate::imp;
|
||||||
|
|
||||||
static DF_MODEL: Asset = asset!("/assets/DeepFilterNet3_ll_onnx.tar.gz");
|
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 {
|
enum DenoisingModelState {
|
||||||
Nothing,
|
Nothing,
|
||||||
@@ -76,6 +78,7 @@ pub struct AudioProcessor {
|
|||||||
denoise: bool,
|
denoise: bool,
|
||||||
spawn: imp::SpawnHandle,
|
spawn: imp::SpawnHandle,
|
||||||
buffer: Vec<f32>,
|
buffer: Vec<f32>,
|
||||||
|
noise_floor: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AudioProcessor {
|
impl AudioProcessor {
|
||||||
@@ -84,6 +87,7 @@ impl AudioProcessor {
|
|||||||
denoise: false,
|
denoise: false,
|
||||||
spawn: imp::SpawnHandle::current(),
|
spawn: imp::SpawnHandle::current(),
|
||||||
buffer: Vec::new(),
|
buffer: Vec::new(),
|
||||||
|
noise_floor: DEFAULT_NOISE_FLOOR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +96,7 @@ impl AudioProcessor {
|
|||||||
denoise: true,
|
denoise: true,
|
||||||
spawn: imp::SpawnHandle::current(),
|
spawn: imp::SpawnHandle::current(),
|
||||||
buffer: Vec::new(),
|
buffer: Vec::new(),
|
||||||
|
noise_floor: DEFAULT_NOISE_FLOOR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,6 +137,16 @@ impl AudioProcessor {
|
|||||||
if include_raw {
|
if include_raw {
|
||||||
output.extend(audio.iter().step_by(channels).copied());
|
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::<f32>() / output.len() as f32
|
||||||
|
};
|
||||||
|
if avg < self.noise_floor {
|
||||||
|
output.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user