diff --git a/bingus/src/lib.rs b/bingus/src/lib.rs index a717ba8..385b96b 100644 --- a/bingus/src/lib.rs +++ b/bingus/src/lib.rs @@ -1,9 +1,4 @@ -use dasp_sample::{FromSample, Sample, U24}; -mod media; - -pub trait AsMedia { - fn as_media(self) -> T; -} +use dasp_sample::{FromSample, Sample, U24, U48}; pub trait AsSample where @@ -21,41 +16,51 @@ where } } -impl AsSample for (u8, u8) +impl AsSample for [u8; 2] where S: Sample + FromSample, { fn as_sample(self) -> S { - (((self.0 as u16) << 8) | self.1 as u16).to_sample() + (((self[0] as u16) << 8) | self[1] as u16).to_sample() } } -impl AsSample for (u8, u8, u8) +impl AsSample for [u8; 3] where S: Sample + FromSample, { fn as_sample(self) -> S { - (((U24::from(self.0)) << 16.into()) | (U24::from(self.1) << 8.into()) | U24::from(self.2)) - .to_sample() + (((U24::from(self[0])) << 16.into()) + | (U24::from(self[1]) << 8.into()) + | U24::from(self[2])) + .to_sample() } } -impl AsSample for (u8, u8, u8, u8) +impl AsSample for [u8; 4] where S: Sample + FromSample, { fn as_sample(self) -> S { - (((self.0 as u32) << 24) | ((self.1 as u32) << 16) | ((self.2 as u32) << 8) | self.3 as u32) + (((self[0] as u32) << 24) + | ((self[1] as u32) << 16) + | ((self[2] as u32) << 8) + | self[3] as u32) .to_sample() } } -impl AsMedia for T +impl AsSample for [u8; 6] where - T: AsSample, - S: Sample, + S: Sample + FromSample, { - fn as_media(self) -> S { - self.as_sample() + fn as_sample(self) -> S { + ((U48::from(self[0]) << 40u8.into()) + | (U48::from(self[1]) << 32u8.into()) + | (U48::from(self[2]) << 24u8.into()) + | (U48::from(self[3]) << 16u8.into()) + | (U48::from(self[4]) << 8u8.into()) + | U48::from(self[3])) + .to_sample() } } diff --git a/bingus/src/media.rs b/bingus/src/media.rs deleted file mode 100644 index 43abd1f..0000000 --- a/bingus/src/media.rs +++ /dev/null @@ -1 +0,0 @@ -pub struct Sample;