From 9866c0f34c268a09ecaaa9a4361c1c267799358e Mon Sep 17 00:00:00 2001 From: Graham Northup Date: Tue, 19 Sep 2017 23:56:15 -0400 Subject: Starting work on proto decode --- src/synth/saw.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/synth/saw.rs (limited to 'src/synth/saw.rs') diff --git a/src/synth/saw.rs b/src/synth/saw.rs new file mode 100644 index 0000000..bfd3cb0 --- /dev/null +++ b/src/synth/saw.rs @@ -0,0 +1,25 @@ +use super::*; + +#[derive(Debug)] +pub struct Saw { + pub freq: GenBox, + pub phase: f32, + pub buf: SampleBuffer, +} + +impl Generator for Saw { + fn eval<'a>(&'a mut self, params: &Parameters) -> &'a SampleBuffer { + self.buf.rate = Rate::Sample; + + let pvel = self.freq.eval(params).first() / params.env.sample_rate; + for i in 0..self.buf.len() { + self.buf[i] = 2.0 * ((self.phase + pvel * (i as f32)) % 1.0) - 1.0; + } + + self.phase = (self.phase + pvel * (self.buf.len() as f32)) % 1.0; + &self.buf + } + fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer { + mem::replace(&mut self.buf, buf) + } +} -- cgit v1.2.3-70-g09d2