#![deny(
clippy::all,
clippy::cargo,
clippy::nursery,
// clippy::restriction,
// clippy::pedantic
)]
#![allow(
clippy::suboptimal_flops,
clippy::redundant_pub_crate,
clippy::fallible_impl_from
)]
#![deny(missing_debug_implementations)]
#![deny(rustdoc::all)]
pub mod spectrum;
pub mod waveform;
pub mod dynamic;
#[cfg(test)]
mod tests;
pub mod util;
#[derive(Debug, Copy, Clone)]
pub enum ChannelInterleavement {
LRLR,
LLRR,
}
impl ChannelInterleavement {
pub const fn is_lrlr(&self) -> bool {
matches!(self, ChannelInterleavement::LRLR)
}
pub const fn is_lllrr(&self) -> bool {
matches!(self, ChannelInterleavement::LLRR)
}
pub fn to_channel_data(&self, interleaved_data: &[i16]) -> (Vec<i16>, Vec<i16>) {
let mut left_data = vec![];
let mut right_data = vec![];
if self.is_lrlr() {
let mut is_left = true;
for sample in interleaved_data {
if is_left {
left_data.push(*sample);
} else {
right_data.push(*sample)
}
is_left = !is_left;
}
} else {
let n = interleaved_data.len();
for sample_i in interleaved_data.iter().take(n / 2).copied() {
left_data.push(sample_i);
}
for sample_i in interleaved_data.iter().skip(n / 2).copied() {
right_data.push(sample_i);
}
}
(left_data, right_data)
}
}
#[derive(Debug, Copy, Clone)]
pub enum Channels {
Mono,
Stereo(ChannelInterleavement),
}
impl Channels {
pub const fn is_mono(&self) -> bool {
matches!(self, Channels::Mono)
}
pub const fn is_stereo(&self) -> bool {
matches!(self, Channels::Stereo(_))
}
pub fn stereo_interleavement(&self) -> ChannelInterleavement {
match self {
Channels::Stereo(interleavmement) => *interleavmement,
_ => panic!("Not stereo"),
}
}
}