aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-05-08 19:40:42 -0600
committerMelody Horn <melody@boringcactus.com>2021-05-08 19:40:42 -0600
commit1732015dd975fe2cf560923eb7e24ca8219f9258 (patch)
tree6c071f8d2611fc3957abe2acfc3da9b2ebc9c3de
parent33efd41a3da31c3a1d6f2ab4855147ccf576f42c (diff)
downloadsynthfinity-1732015dd975fe2cf560923eb7e24ca8219f9258.tar.gz
synthfinity-1732015dd975fe2cf560923eb7e24ca8219f9258.zip
quantize note length and pitch
-rw-r--r--src/main.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 6b79749..0909b1f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,12 +10,17 @@ fn main() {
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
+ let bpm = 140.0;
+ let seconds_per_beat = (1.0 / bpm) * 60.0;
+
loop {
let mut rng = rand::thread_rng();
- let freq = rng.gen_range((440 / 4)..(440 * 4));
+ let freq = (440.0
+ * (2f32.powf(1.0 / 12.0)).powf(rng.gen_range((12 * -2)..=(12 * 0)) as f32))
+ as u32;
let wave = SineWave::new(freq);
let zero: Zero<f32> = Zero::new(1, 48_000);
- let length = rng.gen_range(0.1..0.3);
+ let length = (rng.gen_range(1..4) as f32) / 4.0 * seconds_per_beat;
let source = wave
.take_crossfade_with(zero, Duration::from_secs_f32(length))
.amplify(0.20);