diff --git a/Cargo.toml b/Cargo.toml index bcf529e..42856bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,5 +12,5 @@ package.keywords = ["databending", "data-bending", "bending", "bend", "art"] fundsp = "0.18.2" image = "0.24.9" anyhow = "1.0.86" -dasp_sample = "0.11.0" bingus = { version = "0.1.0", path = "bingus" } +num-traits = "0.2.19" diff --git a/bent-funny-zone/Cargo.toml b/bent-funny-zone/Cargo.toml index 20f92ae..ccc2cda 100644 --- a/bent-funny-zone/Cargo.toml +++ b/bent-funny-zone/Cargo.toml @@ -14,5 +14,4 @@ keywords.workspace = true image = { workspace = true } fundsp = { workspace = true } anyhow = { workspace = true } -dasp_sample = { workspace = true } bingus = { workspace = true } diff --git a/bent-funny-zone/src/main.rs b/bent-funny-zone/src/main.rs index c7e6a80..16427a5 100644 --- a/bent-funny-zone/src/main.rs +++ b/bent-funny-zone/src/main.rs @@ -1,7 +1,39 @@ +use std::array; + use anyhow::Result; -use bingus::convert::samples::BytesToSample; +use fundsp::{ + hacker::{bell_hz, pipei, U12}, + math::db_amp, +}; +use image::io::Reader as ImageReader; fn main() -> Result<()> { - dbg!([1u8, 2, 3].to_sample::()); + let mut img = ImageReader::open("bmp/bigsample.bmp")?.decode()?.to_rgb8(); + let mut equalizer = + pipei::(|i| bell_hz(1000.0 + 1000.0 * i as f32, 1.0, db_amp(0.0))); + img.to_vec() + .chunks_exact(3) + .map(|px: &[u8]| f32::from_ne_bytes(array::from_fn(|i| px[i % px.len()]))) + .map(|x| equalizer.filter_mono(x)) + .flat_map(|px| -> [u8; 3] { + let px = px.to_ne_bytes(); + array::from_fn(move |i| px[i]) + }) + .zip(img.as_mut()) + .for_each(|(filtered, original)| *original = filtered); + img.save("bmp/out.bmp")?; + + // let bytes: Vec = (1u8..7).into_iter().collect(); + // assert_eq!( + // bytes, + // bytes + // .chunks_exact(3) + // .map(|px: &[u8]| f64::from_ne_bytes(array::from_fn(|i| px[i % px.len()]))) + // .flat_map(|px: f64| -> [u8; 3] { + // let px = px.to_ne_bytes(); + // array::from_fn(move |i| px[i]) + // }) + // .collect::>() + // ); Ok(()) } diff --git a/bingus/Cargo.toml b/bingus/Cargo.toml index 1548bfb..8ee8c05 100644 --- a/bingus/Cargo.toml +++ b/bingus/Cargo.toml @@ -11,4 +11,4 @@ keywords.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] fundsp = { workspace = true } -dasp_sample = { workspace = true } +num-traits = { workspace = true } diff --git a/bingus/src/convert.rs b/bingus/src/convert.rs deleted file mode 100644 index 6d13bdb..0000000 --- a/bingus/src/convert.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod samples; - -pub type Byte = u8; diff --git a/bingus/src/convert/samples.rs b/bingus/src/convert/samples.rs deleted file mode 100644 index bbbf6e7..0000000 --- a/bingus/src/convert/samples.rs +++ /dev/null @@ -1,6 +0,0 @@ -use super::Byte; - -mod from; -mod into; - -pub use into::BytesToSample; diff --git a/bingus/src/convert/samples/from.rs b/bingus/src/convert/samples/from.rs deleted file mode 100644 index 8b13789..0000000 --- a/bingus/src/convert/samples/from.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/bingus/src/convert/samples/into.rs b/bingus/src/convert/samples/into.rs deleted file mode 100644 index 0e626d6..0000000 --- a/bingus/src/convert/samples/into.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::{ - array, mem, - ops::{BitOr, Shl}, -}; - -use dasp_sample::{FromSample, Sample, U24, U48}; -use fundsp::Real; - -use super::Byte; - -pub trait BytesToSample -where - Self: IntoIterator + Sized, - Ii: Iterator, - Ir: FromSample - + Sample - + Default - + From - + Shl - + BitOr, - It: Sample, -{ - fn to_sample(self) -> S - where - S: Real + Sample + FromSample, - { - self.into_iter() - .map(|it| Ir::from_sample(it)) - .reduce(|acc, ir| (acc << Ir::from(mem::size_of::() as u8 * 8u8)) | ir) - .unwrap() - .to_sample() - } -} - -macro_rules! impl_bts_for_array_of { - ($($N:expr, $Ir:ty);*) => - { - $( - impl BytesToSample<$Ir, Byte, array::IntoIter> for [Byte; $N] {} - )* - } -} - -impl_bts_for_array_of! { - 1, u8; - 2, u16; - 3, U24; - 4, u32; - 6, U48; - 8, u64 -} diff --git a/bingus/src/lib.rs b/bingus/src/lib.rs index b5b6721..8b13789 100644 --- a/bingus/src/lib.rs +++ b/bingus/src/lib.rs @@ -1 +1 @@ -pub mod convert; +