devalang_wasm/engine/audio/effects/processors/
stereo.rs1use crate::engine::audio::effects::processors::super_trait::EffectProcessor;
2
3#[derive(Debug, Clone)]
4pub struct StereoProcessor {
5 pub width: f32, }
7
8impl StereoProcessor {
9 pub fn new(width: f32) -> Self {
10 Self {
11 width: width.clamp(0.0, 2.0),
12 }
13 }
14}
15
16impl Default for StereoProcessor {
17 fn default() -> Self {
18 Self::new(1.0)
19 }
20}
21
22impl EffectProcessor for StereoProcessor {
23 fn process(&mut self, samples: &mut [f32], _sr: u32) {
24 for i in (0..samples.len()).step_by(2) {
25 let l = samples[i];
26 let r = if i + 1 < samples.len() {
27 samples[i + 1]
28 } else {
29 l
30 };
31 let mid = (l + r) * 0.5;
32 let side = (l - r) * 0.5 * self.width;
33 samples[i] = mid + side;
34 if i + 1 < samples.len() {
35 samples[i + 1] = mid - side;
36 }
37 }
38 }
39 fn reset(&mut self) {}
40 fn name(&self) -> &str {
41 "Stereo"
42 }
43}