From d6e399973e9bc6447a28b80cacffcbc6a768f1ed Mon Sep 17 00:00:00 2001 From: thajohns Date: Thu, 9 Sep 2021 01:15:22 -0400 Subject: got pre-linking steps working, removed glob includes --- src/synth/lut.rs | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src/synth/lut.rs') diff --git a/src/synth/lut.rs b/src/synth/lut.rs index 73b5efa..deda6d9 100644 --- a/src/synth/lut.rs +++ b/src/synth/lut.rs @@ -1,4 +1,7 @@ -use super::*; +use super::{ + mem, FactoryParameters, GenBox, GenFactoryError, Generator, GeneratorFactory, ParamValue, + Parameters, Rate, Sample, SampleBuffer, +}; #[derive(Debug)] pub struct Lut { @@ -14,13 +17,16 @@ impl Generator for Lut { let pvel = self.freq.eval(params).first() / params.env.sample_rate; for i in 0..self.buf.len() { - self.buf[i] = self.lut[(((self.phase + pvel * (i as f32)) % 1.0) * (self.lut.len() as f32)) as usize]; + self.buf[i] = self.lut + [(((self.phase + pvel * (i as f32)) % 1.0) * (self.lut.len() as f32)) as usize]; } self.phase = (self.phase + pvel * (self.buf.len() as f32)) % 1.0; &self.buf } - fn buffer(&self) -> &SampleBuffer { &self.buf } + fn buffer(&self) -> &SampleBuffer { + &self.buf + } fn set_buffer(&mut self, buf: SampleBuffer) -> SampleBuffer { mem::replace(&mut self.buf, buf) } @@ -32,7 +38,9 @@ impl GeneratorFactory for LutDataFactory { fn new(&self, params: &mut FactoryParameters) -> Result { Ok(Box::new(Lut { freq: params.remove_param("freq", 0)?.into_gen()?, - phase: params.get_param("phase", 1, &mut ParamValue::Float(0.0)).as_f32()?, + phase: params + .get_param("phase", 1, &mut ParamValue::Float(0.0)) + .as_f32()?, buf: SampleBuffer::new(params.env.default_buffer_size), lut: { let mut lut: Vec = Vec::new(); @@ -44,7 +52,10 @@ impl GeneratorFactory for LutDataFactory { } if lut.is_empty() { - return Err(GenFactoryError::MissingRequiredParam("samples".to_string(), 2)); + return Err(GenFactoryError::MissingRequiredParam( + "samples".to_string(), + 2, + )); } lut @@ -62,13 +73,20 @@ impl GeneratorFactory for LutGenFactory { eprintln!("LutGenFactory::new({:?})", params); Ok(Box::new(Lut { freq: params.remove_param("freq", 2)?.into_gen()?, - phase: params.get_param("phase", 3, &mut ParamValue::Float(0.0)).as_f32()?, + phase: params + .get_param("phase", 3, &mut ParamValue::Float(0.0)) + .as_f32()?, buf: SampleBuffer::new(params.env.default_buffer_size), lut: { let mut gen = params.remove_param("gen", 0)?.into_gen()?; let samps = params.get_req_param("samples", 1)?.as_f32()?; - let var = params.get_param("var", 4, &mut ParamValue::String("lut_freq".to_string())).as_string()?; - let mut genparams = Parameters { env: params.env.clone(), ..Default::default() }; + let var = params + .get_param("var", 4, &mut ParamValue::String("lut_freq".to_string())) + .as_string()?; + let mut genparams = Parameters { + env: params.env.clone(), + ..Default::default() + }; genparams.env.sample_rate = samps; genparams.vars.insert(var, 1.0); -- cgit v1.2.3-70-g09d2