aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/audio/transformers.rs
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2021-06-12 15:58:44 +0200
committerEskil Queseth <eskilq@kth.se>2021-06-12 15:58:44 +0200
commit3cb2c612fb030278aaf5e4d49d42cf689bdc9cc0 (patch)
treeb16df1d03495e9fc87fd82ede016c88ed94c530f /mumd/src/audio/transformers.rs
parent62be7e8d5f22888d95984ce2634f676ca8b055c4 (diff)
downloadmum-3cb2c612fb030278aaf5e4d49d42cf689bdc9cc0.tar.gz
re-add noise gate
Diffstat (limited to 'mumd/src/audio/transformers.rs')
-rw-r--r--mumd/src/audio/transformers.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/mumd/src/audio/transformers.rs b/mumd/src/audio/transformers.rs
new file mode 100644
index 0000000..5c9681b
--- /dev/null
+++ b/mumd/src/audio/transformers.rs
@@ -0,0 +1,17 @@
+use dasp_ring_buffer::Bounded;
+
+
+pub fn create_noise_gate(chunks: usize, mute_percentage: f32) -> impl FnMut(&mut [f32]) -> Option<&mut [f32]> {
+ let mut peaks = Bounded::from_full(vec![0.0; chunks]);
+ let mut alltime_high: f32 = 0.0;
+ move |buf: &mut [f32]| {
+ let max = buf.iter().map(|e| e.abs()).max_by(|a, b| a.partial_cmp(b).unwrap()).unwrap();
+ peaks.push(max);
+ alltime_high = alltime_high.max(max);
+ if peaks.iter().any(|e| *e >= alltime_high * mute_percentage) {
+ Some(buf)
+ } else {
+ None
+ }
+ }
+}