reorganize bingus
This commit is contained in:
parent
1dec7aad56
commit
14c98f484b
|
@ -1,5 +1,5 @@
|
|||
use anyhow::Result;
|
||||
use bingus::BytesToSample;
|
||||
use bingus::convert::samples::BytesToSample;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
dbg!([1u8, 2, 3].to_sample::<f64>());
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
pub mod samples;
|
||||
|
||||
pub type Byte = u8;
|
|
@ -0,0 +1,6 @@
|
|||
use super::Byte;
|
||||
|
||||
mod from;
|
||||
mod into;
|
||||
|
||||
pub use into::BytesToSample;
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
use std::{
|
||||
array, mem,
|
||||
ops::{BitOr, Shl},
|
||||
};
|
||||
|
||||
use dasp_sample::{FromSample, Sample, U24, U48};
|
||||
use fundsp::Real;
|
||||
|
||||
use super::Byte;
|
||||
|
||||
pub trait BytesToSample<Ir, It, Ii>
|
||||
where
|
||||
Self: IntoIterator<Item = It, IntoIter = Ii> + Sized,
|
||||
Ii: Iterator<Item = It>,
|
||||
Ir: FromSample<It>
|
||||
+ Sample
|
||||
+ Default
|
||||
+ From<u8>
|
||||
+ Shl<Ir, Output = Ir>
|
||||
+ BitOr<Ir, Output = Ir>,
|
||||
It: Sample,
|
||||
{
|
||||
fn to_sample<S>(self) -> S
|
||||
where
|
||||
S: Real + Sample + FromSample<Ir>,
|
||||
{
|
||||
self.into_iter()
|
||||
.map(|it| Ir::from_sample(it))
|
||||
.reduce(|acc, ir| (acc << Ir::from(mem::size_of::<It>() as u8 * 8u8)) | ir)
|
||||
.unwrap()
|
||||
.to_sample()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_bts_for_array_of {
|
||||
($($N:expr, $Ir:ty);*) =>
|
||||
{
|
||||
$(
|
||||
impl BytesToSample<$Ir, Byte, array::IntoIter<Byte, $N>> for [Byte; $N] {}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
impl_bts_for_array_of! {
|
||||
1, u8;
|
||||
2, u16;
|
||||
3, U24;
|
||||
4, u32;
|
||||
6, U48;
|
||||
8, u64
|
||||
}
|
|
@ -1,51 +1 @@
|
|||
use std::{
|
||||
array, mem,
|
||||
ops::{BitOr, Shl},
|
||||
};
|
||||
|
||||
use dasp_sample::{FromSample, Sample, U24, U48};
|
||||
use fundsp::Real;
|
||||
|
||||
pub type Byte = u8;
|
||||
|
||||
pub trait BytesToSample<Ir, It, Ii>
|
||||
where
|
||||
Self: IntoIterator<Item = It, IntoIter = Ii> + Sized,
|
||||
Ii: Iterator<Item = It>,
|
||||
Ir: FromSample<It>
|
||||
+ Sample
|
||||
+ Default
|
||||
+ From<u8>
|
||||
+ Shl<Ir, Output = Ir>
|
||||
+ BitOr<Ir, Output = Ir>,
|
||||
It: Sample,
|
||||
{
|
||||
fn to_sample<S>(self) -> S
|
||||
where
|
||||
S: Real + Sample + FromSample<Ir>,
|
||||
{
|
||||
self.into_iter()
|
||||
.map(|it| Ir::from_sample(it))
|
||||
.reduce(|acc, ir| (acc << Ir::from(mem::size_of::<It>() as u8 * 8u8)) | ir)
|
||||
.unwrap()
|
||||
.to_sample()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_bts_for_array_of {
|
||||
($($N:expr, $Ir:ty);*) =>
|
||||
{
|
||||
$(
|
||||
impl BytesToSample<$Ir, Byte, array::IntoIter<Byte, $N>> for [Byte; $N] {}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
impl_bts_for_array_of! {
|
||||
1, u8;
|
||||
2, u16;
|
||||
3, U24;
|
||||
4, u32;
|
||||
6, U48;
|
||||
8, u64
|
||||
}
|
||||
pub mod convert;
|
||||
|
|
Loading…
Reference in New Issue