use biquad::DirectForm1;
use num_traits::Float;
use crate::{
audio_buffer::{AudioBuffer, AudioChannelLayout},
float_type::FloatType,
};
pub trait AudioMathImpl<T: FloatType + Clone> {
fn mix_signals_inplace(a: &mut [T], b: &[T], gain: f32);
fn mix_signals(a: &mut [T], b: &[T]);
fn normalize_rms(buffer: &mut [T], rms_factor: T);
fn normalize(buffer: &mut [T], factor: T);
fn scale_volume_db(audio: &mut [T], db: T);
fn scale_volume_db_clipped(audio: &mut [T], db: T);
fn normalize_to_max_db(audio: &mut [T], target_max_db: T);
fn normalize_with_headroom(audio: &mut [T], target_max_db: T, headroom_db: T);
}
pub trait AudioFilterImpl<T: FloatType + Float>: Sized {
fn new(
low_cut: f32,
high_cut: f32,
sample_rate: f32,
channel_layout: AudioChannelLayout,
) -> AudioFilter<T>;
fn set_channel_layout(&mut self, channel_layout: AudioChannelLayout);
fn process(&mut self, input: &mut AudioBuffer<T>);
fn set_low_cut(&mut self, low_cut: f32);
fn get_low_cut(&self) -> f32;
fn set_high_cut(&mut self, high_cut: f32);
fn get_high_cut(&self) -> f32;
fn set_sample_rate(&mut self, sample_rate: f32);
fn get_sample_rate(&self) -> f32;
}
pub trait AudioMathPrivateImpl<T: FloatType>: Sized {
fn db_to_gain(db: T) -> T;
fn gain_to_db(gain: T) -> T;
}
pub trait AudioFilterPrivateImpl<T: FloatType + Float>: Sized {
fn process_channel(&mut self, input: &mut [T], channel: usize);
}
pub struct AudioFilter<T: FloatType + Float> {
pub(super) lowpass: Vec<DirectForm1<T>>,
pub(super) highpass: Vec<DirectForm1<T>>,
pub(super) low_cut: f32,
pub(super) high_cut: f32,
pub(super) sample_rate: f32,
pub(super) channel_layout: AudioChannelLayout,
}
pub struct AudioMath {}