diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index 711463b..05538e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,17 +10,33 @@ 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(Sine { freq: freq, phase: 0.0, buf: SampleBuffer::new(params.env.default_buffer_size) }); + let mut sg: GenBox = Box::new(Saw { freq: freq, phase: 0.0, 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 counter = 0; let mut out = io::stdout(); + let mut outbuf: Vec<u8> = Vec::new(); params.vars.insert("freq".to_string(), 440.0); + params.vars.insert("freq2".to_string(), 660.0); while counter < FRAMES { *params.vars.get_mut("freq").unwrap() = 440.0 + 440.0 * ((counter as f32) / (FRAMES as f32)); - let buf = sg.eval(¶ms); - out.write_all(buf.bytes()); + *params.vars.get_mut("freq2").unwrap() = 660.0 + 220.0 * ((counter as f32) / (FRAMES as f32)); + let buf = gen.eval(¶ms); + let curlen = outbuf.len(); + outbuf.reserve_exact(buf.size() - curlen); + unsafe { outbuf.set_len(buf.size()); } + buf.bytes(&mut outbuf); + out.write_all(&outbuf); counter += buf.len(); } } |