From 8995541fda0ab4b0a02f7da243024be4e249cba2 Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Sun, 20 Jun 2021 08:28:40 +0200 Subject: [PATCH] parameter fine tuning --- src/dsp/helpers.rs | 41 +++++++++++++++++++++++++++++++++++++++++ src/dsp/mod.rs | 10 ++++++++-- src/dsp/node_delay.rs | 14 ++++++++++---- 3 files changed, 59 insertions(+), 6 deletions(-) diff --git a/src/dsp/helpers.rs b/src/dsp/helpers.rs index 077c47f..a9e0cbe 100644 --- a/src/dsp/helpers.rs +++ b/src/dsp/helpers.rs @@ -564,6 +564,47 @@ impl DelayBuffer { } } +// translated from Odin 2 Synthesizer Plugin +// Copyright (C) 2020 TheWaveWarden +// under GPLv3 or any later +#[derive(Debug, Clone)] +pub struct DCBlockFilter { + xm1: f64, + ym1: f64, + R: f64, +} + +impl DCBlockFilter { + pub fn new() -> Self { + Self { + xm1: 0.0, + ym1: 0.0, + R: 0.995, + } + } + + pub fn reset(&mut self) { + self.xm1 = 0.0; + self.ym1 = 0.0; + } + + pub fn set_sample_rate(&mut self, srate: f32) { + self.R = 0.995; + if srate > 90000.0 { + self.R = 0.9965; + } else if srate > 120000.0 { + self.R = 0.997; + } + } + + pub fn next(&mut self, input: f32) -> f32 { + let y = input as f64 - self.xm1 + self.R * self.ym1; + self.xm1 = input as f64; + self.ym1 = y; + y as f32 + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/dsp/mod.rs b/src/dsp/mod.rs index 12e11ac..f321b7a 100644 --- a/src/dsp/mod.rs +++ b/src/dsp/mod.rs @@ -298,7 +298,13 @@ macro_rules! r_ems { ($x: expr, $coarse: expr) => { /// The rounding function for milliseconds knobs macro_rules! r_tms { ($x: expr, $coarse: expr) => { if $coarse { - n_time!((d_time!($x)).round()) + if d_time!($x) > 1000.0 { + n_time!((d_time!($x) / 100.0).round() * 100.0) + } else if d_time!($x) > 100.0 { + n_time!((d_time!($x) / 10.0).round() * 10.0) + } else { + n_time!((d_time!($x)).round()) + } } else { n_time!((d_time!($x) * 10.0).round() / 10.0) } @@ -363,7 +369,7 @@ define_exp!{n_declick d_declick 0.0, 50.0} define_exp!{n_env d_env 0.0, 1000.0} -define_exp!{n_time d_time 0.0, 5000.0} +define_exp!{n_time d_time 0.5, 5000.0} // Special linear gain factor for the Out node, to be able // to reach more exact "1.0". diff --git a/src/dsp/node_delay.rs b/src/dsp/node_delay.rs index 02e7a09..f4d3b3e 100644 --- a/src/dsp/node_delay.rs +++ b/src/dsp/node_delay.rs @@ -4,7 +4,7 @@ use crate::nodes::{NodeAudioContext, NodeExecContext}; use crate::dsp::{NodeId, SAtom, ProcBuf, DspNode, LedPhaseVals}; -use crate::dsp::helpers::{DelayBuffer, crossfade}; +use crate::dsp::helpers::{DelayBuffer, crossfade, DCBlockFilter}; #[macro_export] macro_rules! fa_dly_s { ($formatter: expr, $v: expr, $denorm_v: expr) => { { @@ -31,6 +31,7 @@ macro_rules! fa_dly_s { ($formatter: expr, $v: expr, $denorm_v: expr) => { { pub struct Delay { buffer: Box, fb_sample: f32, + dcblock: DCBlockFilter, } impl Delay { @@ -38,6 +39,7 @@ impl Delay { Self { buffer: Box::new(DelayBuffer::new()), fb_sample: 0.0, + dcblock: DCBlockFilter::new(), } } @@ -82,10 +84,12 @@ impl DspNode for Delay { fn set_sample_rate(&mut self, srate: f32) { self.buffer.set_sample_rate(srate); + self.dcblock.set_sample_rate(srate); } fn reset(&mut self) { self.buffer.reset(); + self.dcblock.reset(); } #[inline] @@ -96,7 +100,8 @@ impl DspNode for Delay { { use crate::dsp::{out, inp, denorm}; - let buffer = &mut *self.buffer; + let buffer = &mut *self.buffer; + let dcblock = &mut self.dcblock; let inp = inp::Delay::inp(inputs); let time = inp::Delay::time(inputs); @@ -116,8 +121,9 @@ impl DspNode for Delay { denorm::Delay::time(time, frame)); out.write(frame, - crossfade(dry, out_sample, - denorm::Delay::mix(mix, frame).clamp(0.0, 1.0))); + dcblock.next( + crossfade(dry, out_sample, + denorm::Delay::mix(mix, frame).clamp(0.0, 1.0)))); fb_s = out_sample; }