From dcfc4e82386f41bd36c3b102512bd225fc5331b6 Mon Sep 17 00:00:00 2001 From: Graham Northup Date: Wed, 20 Sep 2017 01:49:04 -0400 Subject: more of the same for the night :) --- src/synth/noise.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/synth/noise.rs (limited to 'src/synth/noise.rs') diff --git a/src/synth/noise.rs b/src/synth/noise.rs new file mode 100644 index 0000000..4d90f3b --- /dev/null +++ b/src/synth/noise.rs @@ -0,0 +1,26 @@ +use std::mem; +use super::*; + +use ::rand::{XorShiftRng, Rng}; + +#[derive(Debug)] +pub struct Noise { + pub rng: XorShiftRng, + pub buf: SampleBuffer, +} + +impl Generator for Noise { + fn eval<'a>(&'a mut self, params: &Parameters) -> &'a SampleBuffer { + self.buf.rate = Rate::Sample; + + for i in 0..self.buf.len() { + self.buf[i] = self.rng.next_f32(); + } + + &self.buf + } + fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer { + mem::replace(&mut self.buf, buf) + } +} + -- cgit v1.2.3-70-g09d2