Skip to content

Commit fb11232

Browse files
committed
Update smooth implementation
1 parent 6daa744 commit fb11232

File tree

16 files changed

+371
-318
lines changed

16 files changed

+371
-318
lines changed

lv2/Cargo.lock

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

lv2/src/lib.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate lv2;
22
extern crate reverse;
33
use lv2::prelude::*;
4-
use reverse::Reverse;
4+
use reverse::{Params, Reverse};
55

66
#[derive(PortCollection)]
77
struct Ports {
@@ -15,7 +15,7 @@ struct Ports {
1515
#[uri("https://github.com/davemollen/dm-Reverse")]
1616
struct DmReverse {
1717
reverse: Reverse,
18-
is_active: bool,
18+
params: Params,
1919
}
2020

2121
impl Plugin for DmReverse {
@@ -27,27 +27,24 @@ impl Plugin for DmReverse {
2727
type AudioFeatures = ();
2828

2929
// Create a new instance of the plugin; Trivial in this case.
30-
fn new(_plugin_info: &PluginInfo, _features: &mut ()) -> Option<Self> {
30+
fn new(plugin_info: &PluginInfo, _features: &mut ()) -> Option<Self> {
31+
let sample_rate = plugin_info.sample_rate() as f32;
32+
3133
Some(Self {
32-
reverse: Reverse::new(_plugin_info.sample_rate() as f32),
33-
is_active: false,
34+
reverse: Reverse::new(sample_rate),
35+
params: Params::new(sample_rate),
3436
})
3537
}
3638

3739
// Process a chunk of audio. The audio ports are dereferenced to slices, which the plugin
3840
// iterates over.
3941
fn run(&mut self, ports: &mut Ports, _features: &mut (), _sample_count: u32) {
40-
let time = *ports.time;
41-
let feedback = *ports.feedback * 0.01;
42-
let mix = *ports.mix * 0.01;
43-
44-
if !self.is_active {
45-
self.reverse.initialize_params(time, feedback, mix);
46-
self.is_active = true;
47-
}
42+
self
43+
.params
44+
.set(*ports.time, *ports.feedback * 0.01, *ports.mix * 0.01);
4845

4946
for (in_frame, out_frame) in Iterator::zip(ports.input.iter(), ports.output.iter_mut()) {
50-
*out_frame = self.reverse.process(*in_frame, time, feedback, mix);
47+
*out_frame = self.reverse.process(*in_frame, &mut self.params);
5148
}
5249
}
5350
}

0 commit comments

Comments
 (0)