Skip to main content

aether_nodes/
mixer.rs

1//! N-input mixer. Sums up to MAX_INPUTS signals with per-channel gain.
2//!
3//! Param layout:
4//!   0..MAX_INPUTS = per-channel gain (default 1.0)
5
6use aether_core::{node::DspNode, param::ParamBlock, BUFFER_SIZE, MAX_INPUTS};
7
8pub struct Mixer;
9
10impl DspNode for Mixer {
11    fn process(
12        &mut self,
13        inputs: &[Option<&[f32; BUFFER_SIZE]>; MAX_INPUTS],
14        output: &mut [f32; BUFFER_SIZE],
15        params: &mut ParamBlock,
16        _sample_rate: f32,
17    ) {
18        output.fill(0.0);
19        for (slot, maybe_input) in inputs.iter().enumerate() {
20            if let Some(buf) = maybe_input {
21                let gain = if slot < params.count {
22                    params.get(slot).current
23                } else {
24                    1.0
25                };
26                for (i, out) in output.iter_mut().enumerate() {
27                    *out += buf[i] * gain;
28                }
29            }
30        }
31        params.tick_all();
32    }
33
34    fn type_name(&self) -> &'static str {
35        "Mixer"
36    }
37}