small code cleanup

This commit is contained in:
Weird Constructor 2021-06-14 18:42:40 +02:00
parent c45c15d64b
commit 3fbc471ff4

View file

@ -17,14 +17,24 @@ macro_rules! fa_ad_mult { ($formatter: expr, $v: expr, $denorm_v: expr) => { {
write!($formatter, "{}", s) write!($formatter, "{}", s)
} } } } } }
const AD_STAGES : i8 = 2;
/// A simple amplifier /// A simple amplifier
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Ad { pub struct Ad {
srate: f64,
phase: f64,
last_value: f32,
stage: i8,
} }
impl Ad { impl Ad {
pub fn new(_nid: &NodeId) -> Self { pub fn new(_nid: &NodeId) -> Self {
Self { Self {
srate: 44100.0,
phase: 0.0,
last_value: 0.0,
stage: -1,
} }
} }
pub const inp : &'static str = pub const inp : &'static str =
@ -158,46 +168,15 @@ impl DspNode for Ad {
{ {
use crate::dsp::{out, inp, denorm, denorm_v, inp_dir, at}; use crate::dsp::{out, inp, denorm, denorm_v, inp_dir, at};
let gain = inp::Amp::gain(inputs); let out = out::Ad::sig(outputs);
let att = inp::Amp::att(inputs);
let inp = inp::Amp::inp(inputs);
let out = out::Amp::sig(outputs);
let neg = at::Amp::neg_att(atoms);
let last_frame = ctx.nframes() - 1; let last_frame = ctx.nframes() - 1;
let last_val =
if neg.i() > 0 {
for frame in 0..ctx.nframes() { for frame in 0..ctx.nframes() {
out.write(frame, out.write(frame, 0.0);
inp.read(frame)
* denorm_v::Amp::att(
inp_dir::Amp::att(att, frame)
.max(0.0))
* denorm::Amp::gain(gain, frame));
} }
inp.read(last_frame) ctx_vals[0].set(0.0);
* denorm_v::Amp::att( // ctx_vals[1].set(self.phase / self. + self.stage * );
inp_dir::Amp::att(att, last_frame)
.max(0.0))
* denorm::Amp::gain(gain, last_frame)
} else {
for frame in 0..ctx.nframes() {
out.write(frame,
inp.read(frame)
* denorm_v::Amp::att(
inp_dir::Amp::att(att, frame).abs())
* denorm::Amp::gain(gain, frame));
}
inp.read(last_frame)
* denorm_v::Amp::att(
inp_dir::Amp::att(att, last_frame).abs())
* denorm::Amp::gain(gain, last_frame)
};
ctx_vals[0].set(last_val);
} }
} }