made the decay declick optional
This commit is contained in:
parent
46d59dfc02
commit
f7bf197a48
1 changed files with 18 additions and 0 deletions
|
@ -14,6 +14,8 @@ pub struct Sampl {
|
||||||
srate: f64,
|
srate: f64,
|
||||||
trig: Trigger,
|
trig: Trigger,
|
||||||
is_playing: bool,
|
is_playing: bool,
|
||||||
|
last_sample: f32,
|
||||||
|
decaying: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sampl {
|
impl Sampl {
|
||||||
|
@ -23,6 +25,8 @@ impl Sampl {
|
||||||
srate: 44100.0,
|
srate: 44100.0,
|
||||||
trig: Trigger::new(),
|
trig: Trigger::new(),
|
||||||
is_playing: false,
|
is_playing: false,
|
||||||
|
last_sample: 0.0,
|
||||||
|
decaying: 0.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub const freq : &'static str =
|
pub const freq : &'static str =
|
||||||
|
@ -129,6 +133,7 @@ impl Sampl {
|
||||||
|
|
||||||
if triggered {
|
if triggered {
|
||||||
self.phase = 0.0;
|
self.phase = 0.0;
|
||||||
|
self.decaying = self.last_sample;
|
||||||
is_playing = true;
|
is_playing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +199,7 @@ impl Sampl {
|
||||||
s *= ramp_atten_factor as f32;
|
s *= ramp_atten_factor as f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.last_sample = s;
|
||||||
out.write(frame, s);
|
out.write(frame, s);
|
||||||
|
|
||||||
if !do_loop && prev_phase > self.phase {
|
if !do_loop && prev_phase > self.phase {
|
||||||
|
@ -206,6 +212,16 @@ impl Sampl {
|
||||||
0.0
|
0.0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let s =
|
||||||
|
if !declick || self.decaying.abs() < 0.00001 {
|
||||||
|
self.decaying = 0.0;
|
||||||
|
s
|
||||||
|
} else {
|
||||||
|
self.decaying *= 0.98;
|
||||||
|
(s + self.decaying).clamp(-1.0, 1.0)
|
||||||
|
};
|
||||||
|
|
||||||
|
self.last_sample = s;
|
||||||
out.write(frame, s);
|
out.write(frame, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,6 +254,7 @@ impl DspNode for Sampl {
|
||||||
for frame in 0..ctx.nframes() {
|
for frame in 0..ctx.nframes() {
|
||||||
out.write(frame, 0.0);
|
out.write(frame, 0.0);
|
||||||
}
|
}
|
||||||
|
self.last_sample = 0.0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,6 +269,7 @@ impl DspNode for Sampl {
|
||||||
for frame in 0..ctx.nframes() {
|
for frame in 0..ctx.nframes() {
|
||||||
out.write(frame, 0.0);
|
out.write(frame, 0.0);
|
||||||
}
|
}
|
||||||
|
self.last_sample = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let last_frame = ctx.nframes() - 1;
|
let last_frame = ctx.nframes() - 1;
|
||||||
|
|
Loading…
Reference in a new issue