diff options
| author | Eskil Queseth <eskilq@kth.se> | 2021-02-11 23:13:09 +0100 |
|---|---|---|
| committer | Eskil Queseth <eskilq@kth.se> | 2021-02-11 23:13:09 +0100 |
| commit | 4aa12943714cf6b8d1ae996af424b58c7368e5d8 (patch) | |
| tree | 1ae51f9155903094c769fd58918325c0eb4e3f1e /mumd/src/audio.rs | |
| parent | 154a2930b3bbe5ede06648c3a10b8fa4904277f4 (diff) | |
| download | mum-4aa12943714cf6b8d1ae996af424b58c7368e5d8.tar.gz | |
change noise gate to be dynamig instead of static
Diffstat (limited to 'mumd/src/audio.rs')
| -rw-r--r-- | mumd/src/audio.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index 598dde6..88eb601 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -210,7 +210,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 @@ -408,21 +407,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, } } } @@ -435,6 +433,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) { @@ -442,14 +442,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; |
