Skip to content

Instantly share code, notes, and snippets.

@tomara-x
Created September 4, 2024 04:29
Show Gist options
  • Save tomara-x/c888b418125e3a83f05b2c5e1bff97f0 to your computer and use it in GitHub Desktop.
Save tomara-x/c888b418125e3a83f05b2c5e1bff97f0 to your computer and use it in GitHub Desktop.
/// phasor (ramp from 0..1)
/// - input 0: frequency
/// - output 0: ramp output
#[derive(Default, Clone)]
pub struct Ramp {
val: f32,
sr: f32,
}
impl Ramp {
pub fn new() -> Self {
Ramp { val: 0., sr: 44100. }
}
}
impl AudioNode for Ramp {
const ID: u64 = 1116;
type Inputs = U1;
type Outputs = U1;
#[inline]
fn tick(&mut self, input: &Frame<f32, Self::Inputs>) -> Frame<f32, Self::Outputs> {
let buffer = [self.val];
self.val += input[0] / self.sr;
if self.val >= 1. {
self.val -= 1.;
}
buffer.into()
}
fn reset(&mut self) {
self.val = 0.;
}
fn set_sample_rate(&mut self, sample_rate: f64) {
self.sr = sample_rate as f32;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment