wip audio synthesizer based on the rust crate cpal
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beeper/src/beep/sample.rs

68 lines
1.3 KiB

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<f32> for StereoSample {
type Output = Self;
fn div(self, rhs: f32) -> Self::Output {
Self {
left: self.left / rhs,
right: self.right / rhs,
}
}
}
impl Mul<f32> for StereoSample {
type Output = Self;
fn mul(self, rhs: f32) -> Self::Output {
Self {
left: self.left * rhs,
right: self.right * rhs,
}
}
}
impl AddAssign<Self> for StereoSample {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl DivAssign<f32> for StereoSample {
fn div_assign(&mut self, rhs: f32) {
*self = *self / rhs
}
}
impl MulAssign<f32> for StereoSample {
fn mul_assign(&mut self, rhs: f32) {
*self = *self * rhs
}
}