From 3eb0824c6477bc7720b3ed0ac49f58a34cfa0546 Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Fri, 17 Dec 2021 20:41:38 -0600 Subject: Add: more detailed Risset's Bell implementation also hooks duration up to the main synth to control the length of the Instrument notes that get played, since they aren't subject to the ADSR envelope --- klangfarbrs/src/lib.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'klangfarbrs/src/lib.rs') diff --git a/klangfarbrs/src/lib.rs b/klangfarbrs/src/lib.rs index de3322a..aa133e7 100644 --- a/klangfarbrs/src/lib.rs +++ b/klangfarbrs/src/lib.rs @@ -82,14 +82,14 @@ impl MonoSynth { Self { osc: Osc::new(freq, sprt), - instrument: Instrument::new(freq, vec![0.56, 0.92, 1.19, 1.7, 2.0, 2.74, 3.0, 3.76, 4.07], sprt), + instrument: Instrument::bell(freq, 10000, sprt), sample_rate: sprt, frequency: freq, apply_bend: false, phasor_bend: Vector2::new(0.0, 0.0), play_instrument: false, continuous: true, - duration: 0, + duration: 5000, envelope: Envelope::new(30, 500, 0.5, 1000, sprt), cutoff: 0.0, frequency_modulation: false, @@ -184,6 +184,11 @@ impl MonoSynth { self.fm_depth = fm_depth } + #[export] + fn duration(&mut self, _owner: &Node, duration: Millisecond) { + self.duration = duration + } + #[export] fn set_attack(&mut self, _owner: &Node, attack: Millisecond) { self.attack = attack @@ -215,7 +220,7 @@ impl MonoSynth { #[export] fn trigger(&mut self, _owner: &Node, ) { - self.instrument = Instrument::new(self.frequency, vec![0.56, 0.92, 1.19, 1.7, 2.0, 2.74, 3.0, 3.76, 4.07], self.sample_rate); + self.instrument = Instrument::bell(self.frequency, self.duration, self.sample_rate); self.envelope = Envelope::new(self.attack, self.decay, self.sustain, self.release, self.sample_rate); } @@ -244,7 +249,7 @@ impl MonoSynth { // self.phasor.phase = next_phase; // } - if !self.continuous { + if !self.continuous && !self.play_instrument { sample *= match self.envelope.next() { Some(a) => a, None => 0.0, -- cgit v1.2.3