diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/src/main.rs b/src/main.rs index c284820..7f8e14e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,32 +2,18 @@ use std::io; use std::io::*; extern crate rand; -use rand::{Rng, SeedableRng}; extern crate synfone; use synfone::synth::*; +use synfone::lang::*; const FRAMES: usize = 44100 * 2; +const GEN: &'static str = "add(mul(sine(param('freq', 440)), 0.5), mul(sine(param('freq2', 660)), 0.5))"; + fn main() { let mut params = Parameters::default(); - //let mut freq: GenBox = Box::new(Param { name: "freq".to_string(), default: 440.0, buf: SampleBuffer::new(1) }); - //let mut sg: GenBox = Box::new(Saw { freq: freq, phase: 0.0, buf: SampleBuffer::new(params.env.default_buffer_size) }); - let mut osrng = rand::os::OsRng::new().expect("Couldn't initialize OS RNG"); - let mut seed: [u32; 4] = Default::default(); - for i in seed.iter_mut() { - *i = osrng.next_u32(); - } - let mut sg: GenBox = Box::new(Noise { rng: rand::XorShiftRng::from_seed(seed), buf: SampleBuffer::new(params.env.default_buffer_size) }); - - let mut freq2: GenBox = Box::new(Param { name: "freq2".to_string(), default: 660.0, buf: SampleBuffer::new(1) }); - let mut sg2: GenBox = Box::new(Sine { freq: freq2, phase: 0.0, buf: SampleBuffer::new(params.env.default_buffer_size) }); - - let mut half1: GenBox = Box::new(Param { name: "half".to_string(), default: 1.0, buf: SampleBuffer::new(1) }); - let mut half2: GenBox = Box::new(Param { name: "half".to_string(), default: 0.0, buf: SampleBuffer::new(1) }); - let mut sc1: GenBox = Box::new(Mul { factors: vec![sg, half1], buf: SampleBuffer::new(params.env.default_buffer_size) }); - let mut sc2: GenBox = Box::new(Mul { factors: vec![sg2, half2], buf: SampleBuffer::new(params.env.default_buffer_size) }); - let mut gen: GenBox = Box::new(Add { terms: vec![sc1, sc2], buf: SampleBuffer::new(params.env.default_buffer_size) }); + let mut gen = Parser::new(Tokenizer::new(GEN.chars())).expect("Failed to get first token").parse().expect("Failed to compile generator"); let mut counter = 0; let mut out = io::stdout(); |