use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign}; use crate::beep::hack::StableClamp; #[derive(Default, Clone, Copy)] pub struct StereoSample { pub left: f32, pub right: f32, } impl StereoSample { pub fn clip(self) -> Self { Self { left: self.left.clamp_(-1.0, 1.0), right: self.right.clamp_(-1.0, 1.0), } } } impl Add for StereoSample { type Output = Self; fn add(self, rhs: Self) -> Self::Output { Self { left: self.left + rhs.left, right: self.right + rhs.right, } } } impl Div for StereoSample { type Output = Self; fn div(self, rhs: f32) -> Self::Output { Self { left: self.left / rhs, right: self.right / rhs, } } } impl Mul for StereoSample { type Output = Self; fn mul(self, rhs: f32) -> Self::Output { Self { left: self.left * rhs, right: self.right * rhs, } } } impl AddAssign for StereoSample { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs } } impl DivAssign for StereoSample { fn div_assign(&mut self, rhs: f32) { *self = *self / rhs } } impl MulAssign for StereoSample { fn mul_assign(&mut self, rhs: f32) { *self = *self * rhs } }