aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src
diff options
context:
space:
mode:
authorKapten Z∅∅m <55669224+default-username-852@users.noreply.github.com>2021-02-13 22:07:42 +0100
committerGitHub <noreply@github.com>2021-02-13 22:07:42 +0100
commitd6348155f3420e9c01f805f0bb3a520cbd1d4c1c (patch)
treec535e7cba1447e4fae00a67da22d0e80bcaf21f4 /mumd/src
parentf31577b69d2fa9c8fa32151083447f8e31936d95 (diff)
parent4aa12943714cf6b8d1ae996af424b58c7368e5d8 (diff)
downloadmum-d6348155f3420e9c01f805f0bb3a520cbd1d4c1c.tar.gz
Merge pull request #66 from mum-rs/noise_gate_fix
Change noise gate to be dynamic instead of static
Diffstat (limited to 'mumd/src')
-rw-r--r--mumd/src/audio.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs
index eee6716..9dbb61e 100644
--- a/mumd/src/audio.rs
+++ b/mumd/src/audio.rs
@@ -201,7 +201,6 @@ impl Audio {
StreamingSignalExt::into_interleaved_samples(
StreamingNoiseGate::new(
from_interleaved_samples_stream::<_, f32>(sample_receiver), //TODO group frames correctly
- 0.09,
10_000))).enumerate().map(|(i, e)| VoicePacket::Audio {
_dst: std::marker::PhantomData,
target: 0, // normal speech
@@ -399,21 +398,20 @@ fn get_default_sfx() -> Cow<'static, [u8]> {
struct StreamingNoiseGate<S: StreamingSignal> {
open: usize,
signal: S,
- activate_threshold: <<S::Frame as Frame>::Sample as Sample>::Float,
deactivation_delay: usize,
+ alltime_high: <<S::Frame as Frame>::Sample as Sample>::Float,
}
impl<S: StreamingSignal> StreamingNoiseGate<S> {
pub fn new(
signal: S,
- activate_threshold: <<S::Frame as Frame>::Sample as Sample>::Float,
deactivation_delay: usize,
) -> StreamingNoiseGate<S> {
Self {
open: 0,
signal,
- activate_threshold,
- deactivation_delay
+ deactivation_delay,
+ alltime_high: <<<S::Frame as Frame>::Sample as Sample>::Float as Sample>::EQUILIBRIUM,
}
}
}
@@ -426,6 +424,8 @@ impl<S> StreamingSignal for StreamingNoiseGate<S>
type Frame = S::Frame;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Frame> {
+ const MUTE_PERCENTAGE: f32 = 0.1;
+
let s = self.get_mut();
let frame = match S::poll_next(Pin::new(&mut s.signal), cx) {
@@ -433,14 +433,18 @@ impl<S> StreamingSignal for StreamingNoiseGate<S>
Poll::Pending => return Poll::Pending,
};
+ if let Some(highest) = frame.to_float_frame().channels().find(|e| abs(e.clone()) > s.alltime_high) {
+ s.alltime_high = highest;
+ }
+
match s.open {
0 => {
- if frame.to_float_frame().channels().any(|e| abs(e) >= s.activate_threshold) {
+ if frame.to_float_frame().channels().any(|e| abs(e) >= s.alltime_high.mul_amp(MUTE_PERCENTAGE.to_sample())) {
s.open = s.deactivation_delay;
}
}
_ => {
- if frame.to_float_frame().channels().any(|e| abs(e) >= s.activate_threshold) {
+ if frame.to_float_frame().channels().any(|e| abs(e) >= s.alltime_high.mul_amp(MUTE_PERCENTAGE.to_sample())) {
s.open = s.deactivation_delay;
} else {
s.open -= 1;