glicol_synth/node/signal/
noise.rs1use crate::{impl_to_boxed_nodedata, BoxedNodeSend, Buffer, Input, Message, Node, NodeData};
2use hashbrown::HashMap;
3
4use dasp_signal::{self as signal, Signal};
5
6pub struct Noise {
7 sig: Box<dyn Signal<Frame = f64> + Send>,
8 input_order: Vec<usize>,
9}
10
11impl Noise {
12 pub fn new(seed: usize) -> Self {
13 Self {
14 sig: Box::new(signal::noise(seed as u64)),
15 input_order: Vec::new(),
16 }
17 }
18 impl_to_boxed_nodedata!();
19}
20
21impl<const N: usize> Node<N> for Noise {
22 fn process(&mut self, _inputs: &mut HashMap<usize, Input<N>>, output: &mut [Buffer<N>]) {
23 for out in output {
24 out.iter_mut().for_each(|s| *s = self.sig.next() as f32);
25 }
26 }
27 fn send_msg(&mut self, info: Message) {
28 match info {
29 Message::SetToNumber(0, value) => self.sig = Box::new(signal::noise(value as u64)),
30 Message::Index(i) => self.input_order.push(i),
31 Message::IndexOrder(pos, index) => self.input_order.insert(pos, index),
32 _ => {}
33 }
34 }
35}