basic_reverb/
stereo_basic_reverb.rs

1use crate::basic_reverb::BasicReverb;
2
3pub struct StereoBasicReverb<const CHANNELS: usize, const SAMPLE_RATE: u32> {
4    basic_reverb: BasicReverb<CHANNELS, SAMPLE_RATE>,
5}
6
7impl<const CHANNELS: usize, const SAMPLE_RATE: u32> StereoBasicReverb<CHANNELS, SAMPLE_RATE> {
8    pub fn new(room_size_ms: f64, rt60: f64, dry: f64, wet: f64) -> Self {
9        Self {
10            basic_reverb: BasicReverb::new(room_size_ms, rt60, dry, wet),
11        }
12    }
13
14    pub fn process_sample(&mut self, sample: (f64, f64)) -> (f64, f64) {
15        let mut input = [0.; CHANNELS];
16
17        // Duplicate input as many times as needed
18        for i in 0..CHANNELS / 2 {
19            input[2 * i] = sample.0;
20            input[2 * i + 1] = sample.1;
21        }
22
23        let output = self.basic_reverb.process(input);
24
25        // Mix down into stereo
26        let mut sum = (0., 0.);
27        for i in 0..CHANNELS / 2 {
28            sum.0 = output[2 * i];
29            sum.1 = output[2 * i + 1];
30        }
31
32        (sum.0 / (CHANNELS / 2) as f64, sum.1 / (CHANNELS / 2) as f64)
33    }
34}