firefly_audio/
processor.rs

1use crate::*;
2use alloc::vec::Vec;
3
4pub type Nodes = Vec<Node>;
5
6pub trait Processor {
7    fn set(&mut self, _param: u8, _val: f32) {
8        // do nothing
9    }
10
11    fn reset(&mut self) {
12        // do nothing
13    }
14
15    // TODO: seek
16
17    fn process_children(&mut self, cn: &mut Nodes) -> Option<Frame> {
18        let mut sum = Frame::zero();
19        let mut count = 0;
20        for node in cn.iter_mut() {
21            let Some(frame) = node.next_frame() else {
22                continue;
23            };
24            sum = sum + &frame;
25            count += 1;
26        }
27        if count == 0 {
28            return None;
29        }
30        let f = sum / count as f32;
31        self.process_frame(f)
32    }
33
34    fn process_frame(&mut self, f: Frame) -> Option<Frame> {
35        let left = self.process_sample(f.left)?;
36        let right = match f.right {
37            Some(right) => {
38                let right = self.process_sample(right)?;
39                Some(right)
40            }
41            None => None,
42        };
43        Some(Frame { left, right })
44    }
45
46    fn process_sample(&mut self, s: Sample) -> Option<Sample> {
47        Some(s)
48    }
49}