start lib

This commit is contained in:
Ponj 2024-06-29 14:08:50 +02:00
parent 453dda5111
commit 50572b3d88
Signed by: p6nj
GPG Key ID: 6FED68D87C479A59
5 changed files with 62 additions and 10 deletions

View File

@ -7,3 +7,6 @@ package.description = "databending made easy"
package.authors = ["Breval Ferrari <breee@duck.com>"]
package.repository = "https://codeberg.org/p6nj/bent"
package.keywords = ["databending", "data-bending", "bending", "bend", "art"]
[workspace.dependencies]
dasp_sample = "0.11.0"

View File

@ -9,5 +9,5 @@ repository.workspace = true
keywords.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dasp_sample = { workspace = true }

View File

@ -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
View File

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

View File

@ -7,6 +7,7 @@ description.workspace = true
authors.workspace = true
repository.workspace = true
keywords.workspace = true
dependencies.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html