|
1 | 1 | use caw_core::*; |
2 | 2 | use caw_interactive::{ |
3 | | - window::{Visualization, Window}, |
4 | 3 | Input, |
| 4 | + window::{Visualization, Window}, |
5 | 5 | }; |
6 | 6 | use caw_modules::*; |
7 | 7 | use rand::Rng; |
8 | 8 | use rgb_int::Rgb24; |
9 | 9 | use std::{ |
10 | 10 | sync::{ |
11 | | - mpsc::{self, Receiver, Sender}, |
12 | 11 | Arc, RwLock, |
| 12 | + mpsc::{self, Receiver, Sender}, |
13 | 13 | }, |
14 | 14 | thread, |
15 | 15 | }; |
16 | 16 |
|
17 | 17 | fn signal() -> Sig<impl SigT<Item = f32>> { |
18 | 18 | let base_freq_hz = 50.0; |
19 | | - let mut rng = rand::thread_rng(); |
20 | | - let freq_hz = |
21 | | - (rng.gen_range(1..=3) as f32 * base_freq_hz) + (rng.gen::<f32>() * 0.1); |
22 | | - let lfo = |
23 | | - oscillator(Saw, rng.gen::<f32>() * 0.1).build() * rng.gen::<f32>(); |
| 19 | + let mut rng = rand::rng(); |
| 20 | + let freq_hz = (rng.random_range(1..=3) as f32 * base_freq_hz) |
| 21 | + + (rng.random::<f32>() * 0.1); |
| 22 | + let lfo = oscillator(Saw, rng.random::<f32>() * 0.1).build() |
| 23 | + * rng.random::<f32>(); |
24 | 24 | oscillator(Saw, freq_hz + lfo).build() * 0.2 |
25 | 25 | } |
26 | 26 |
|
@@ -62,7 +62,7 @@ struct MultithreadedSignal { |
62 | 62 | } |
63 | 63 |
|
64 | 64 | impl MultithreadedSignal { |
65 | | - fn new(num_threads: usize, input: Input) -> Sig<impl SigT<Item = f32>> { |
| 65 | + fn new_sig(num_threads: usize, input: Input) -> Sig<impl SigT<Item = f32>> { |
66 | 66 | let mut thread_info = Vec::new(); |
67 | 67 | for _ in 0..num_threads { |
68 | 68 | let (send_query, recv_query) = mpsc::channel(); |
@@ -132,7 +132,7 @@ fn main() -> anyhow::Result<()> { |
132 | 132 | let thresh = 10.0; |
133 | 133 | let input = window.input(); |
134 | 134 | let sig = Stereo::new_fn(|| { |
135 | | - MultithreadedSignal::new(6, input.clone()) |
| 135 | + MultithreadedSignal::new_sig(6, input.clone()) |
136 | 136 | .map(|x| x.clamp(-thresh, thresh)) |
137 | 137 | }); |
138 | 138 | window.play_stereo(sig, Default::default()) |
|
0 commit comments