use crate::{
context::AudioContext,
node::{Inputs, Node},
ports::{PortBuilder, Ports},
resources::params::ParamKey,
};
#[derive(Clone)]
pub struct Signal {
key: ParamKey,
val: f32,
smoothing: f32,
ports: Ports,
}
impl Signal {
pub fn new(key: ParamKey, val: f32, smoothing_factor: f32) -> Self {
Self {
key,
val,
smoothing: smoothing_factor,
ports: PortBuilder::default().audio_out(1).build(),
}
}
}
impl Node for Signal {
fn process(&mut self, ctx: &mut AudioContext, _: &Inputs, outputs: &mut [&mut [f32]]) {
if let Ok(target) = ctx.get_param(&self.key) {
for channel in outputs.iter_mut() {
for sample in channel.iter_mut() {
self.val += (target - self.val) * self.smoothing;
*sample = self.val;
}
}
}
}
fn ports(&self) -> &Ports {
&self.ports
}
}