start lib
This commit is contained in:
parent
453dda5111
commit
50572b3d88
5 changed files with 62 additions and 10 deletions
|
@ -1,14 +1,61 @@
|
|||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
use dasp_sample::{FromSample, Sample, U24};
|
||||
mod media;
|
||||
|
||||
pub trait AsMedia<M, T> {
|
||||
fn as_media(self) -> T;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
pub trait AsSample<S>
|
||||
where
|
||||
S: Sample,
|
||||
{
|
||||
fn as_sample(self) -> S;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
impl<S> AsSample<S> for u8
|
||||
where
|
||||
S: Sample + FromSample<u8>,
|
||||
{
|
||||
fn as_sample(self) -> S {
|
||||
self.to_sample()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> AsSample<S> for (u8, u8)
|
||||
where
|
||||
S: Sample + FromSample<u16>,
|
||||
{
|
||||
fn as_sample(self) -> S {
|
||||
(((self.0 as u16) << 8) | self.1 as u16).to_sample()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> AsSample<S> for (u8, u8, u8)
|
||||
where
|
||||
S: Sample + FromSample<U24>,
|
||||
{
|
||||
fn as_sample(self) -> S {
|
||||
(((U24::from(self.0)) << 16.into()) | (U24::from(self.1) << 8.into()) | U24::from(self.2))
|
||||
.to_sample()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> AsSample<S> for (u8, u8, u8, u8)
|
||||
where
|
||||
S: Sample + FromSample<u32>,
|
||||
{
|
||||
fn as_sample(self) -> S {
|
||||
(((self.0 as u32) << 24) | ((self.1 as u32) << 16) | ((self.2 as u32) << 8) | self.3 as u32)
|
||||
.to_sample()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S> AsMedia<media::Sample, S> for T
|
||||
where
|
||||
T: AsSample<S>,
|
||||
S: Sample,
|
||||
{
|
||||
fn as_media(self) -> S {
|
||||
self.as_sample()
|
||||
}
|
||||
}
|
||||
|
|
1
bingus/src/media.rs
Normal file
1
bingus/src/media.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub struct Sample;
|
Loading…
Add table
Add a link
Reference in a new issue