remove bad supertrait, add remaining AsSample impl

This commit is contained in:
Ponj 2024-07-03 22:27:30 +02:00
parent 41bbd3d371
commit f688dbe225
Signed by: p6nj
GPG key ID: CEAB625B75A836B2
2 changed files with 23 additions and 19 deletions

View file

@ -1,9 +1,4 @@
use dasp_sample::{FromSample, Sample, U24}; use dasp_sample::{FromSample, Sample, U24, U48};
mod media;
pub trait AsMedia<M, T> {
fn as_media(self) -> T;
}
pub trait AsSample<S> pub trait AsSample<S>
where where
@ -21,41 +16,51 @@ where
} }
} }
impl<S> AsSample<S> for (u8, u8) impl<S> AsSample<S> for [u8; 2]
where where
S: Sample + FromSample<u16>, S: Sample + FromSample<u16>,
{ {
fn as_sample(self) -> S { 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<S> AsSample<S> for (u8, u8, u8) impl<S> AsSample<S> for [u8; 3]
where where
S: Sample + FromSample<U24>, S: Sample + FromSample<U24>,
{ {
fn as_sample(self) -> S { fn as_sample(self) -> S {
(((U24::from(self.0)) << 16.into()) | (U24::from(self.1) << 8.into()) | U24::from(self.2)) (((U24::from(self[0])) << 16.into())
.to_sample() | (U24::from(self[1]) << 8.into())
| U24::from(self[2]))
.to_sample()
} }
} }
impl<S> AsSample<S> for (u8, u8, u8, u8) impl<S> AsSample<S> for [u8; 4]
where where
S: Sample + FromSample<u32>, S: Sample + FromSample<u32>,
{ {
fn as_sample(self) -> S { 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() .to_sample()
} }
} }
impl<T, S> AsMedia<media::Sample, S> for T impl<S> AsSample<S> for [u8; 6]
where where
T: AsSample<S>, S: Sample + FromSample<U48>,
S: Sample,
{ {
fn as_media(self) -> S { fn as_sample(self) -> S {
self.as_sample() ((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()
} }
} }

View file

@ -1 +0,0 @@
pub struct Sample;