Skip to content

Commit 6cbac83

Browse files
committed
fix(polysynth): change mapping of resonance into biquad
1 parent ba562c3 commit 6cbac83

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/polysynth/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ keywords.workspace = true
1313
crate-type = ["lib", "cdylib"]
1414

1515
[dependencies]
16-
fastrand = { version = "2.1.1", default-features = false }
17-
fastrand-contrib = { version = "0.1.0", default-features = false }
18-
valib = { path = "../..", features = ["filters", "oversample", "oscillators", "voice", "voice-upsampled", "nih-plug"]}
1916
nih_plug = { workspace = true, features = ["standalone"] }
2017
nih_plug_vizia.workspace = true
21-
num-traits.workspace = true
18+
num-traits.workspace = true
19+
numeric_literals.workspace = true
20+
valib = { path = "../..", features = ["filters", "oversample", "oscillators", "voice", "voice-upsampled", "nih-plug"]}
21+
22+
fastrand = { version = "2.1.1", default-features = false }
23+
fastrand-contrib = { version = "0.1.0", default-features = false }

examples/polysynth/src/dsp.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use fastrand_contrib::RngExt;
55
use nih_plug::nih_log;
66
use nih_plug::util::{db_to_gain, db_to_gain_fast};
77
use num_traits::{ConstOne, ConstZero};
8+
use numeric_literals::replace_float_literals;
89
use std::sync::atomic::{AtomicU64, Ordering};
910
use std::sync::Arc;
1011
use valib::dsp::{BlockAdapter, DSPMeta, DSPProcess, SampleAdapter};
@@ -431,15 +432,16 @@ impl<T: Scalar> FilterImpl<T> {
431432
}
432433
}
433434

435+
#[replace_float_literals(T::from_f64(literal))]
434436
fn set_params(&mut self, samplerate: T, cutoff: T, resonance: T) {
435437
match self {
436438
Self::Transistor(p) => {
437439
p.set_cutoff(cutoff);
438-
p.set_resonance(T::from_f64(4.) * resonance);
440+
p.set_resonance(4. * resonance);
439441
}
440442
Self::Ota(p) => {
441443
p.set_cutoff(cutoff);
442-
p.set_resonance(T::from_f64(4.) * resonance);
444+
p.set_resonance(4. * resonance);
443445
}
444446
Self::Svf(_, p) => {
445447
p.set_cutoff(cutoff);
@@ -448,7 +450,7 @@ impl<T: Scalar> FilterImpl<T> {
448450
Self::Biquad(p) => {
449451
p.update_coefficients(&Biquad::lowpass(
450452
cutoff / samplerate,
451-
T::from_f64(4.7) * (T::from_f64(2.) * resonance - T::one()).simd_exp(),
453+
0.1 + 4.7 * (2. * resonance - 1.).simd_exp() * resonance,
452454
));
453455
}
454456
}
@@ -552,8 +554,8 @@ impl<T: Scalar> Filter<T> {
552554
Svf::new(self.samplerate, cutoff, T::one() - resonance).with_saturator(Sinh),
553555
),
554556
FilterType::Digital if !matches!(self.fimpl, FilterImpl::Biquad(..)) => {
555-
let resonance =
556-
T::from_f64(4.7) * (T::from_f64(2.) * resonance - T::one()).simd_exp();
557+
let resonance = T::from_f64(0.1)
558+
+ T::from_f64(4.7) * (T::from_f64(2.) * resonance - T::one()).simd_exp();
557559
FilterImpl::Biquad(
558560
Biquad::lowpass(cutoff / self.samplerate, resonance)
559561
.with_saturators(Default::default(), Default::default()),

0 commit comments

Comments
 (0)