diff --git a/crates/bistortion/Cargo.toml b/crates/bistortion/Cargo.toml new file mode 100644 index 0000000..b2faa52 --- /dev/null +++ b/crates/bistortion/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "bistortion" +version = "0.1.0" +edition = "2018" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +baseplug = { git = "https://github.com/wrl/baseplug.git", rev = "9cec68f31cca9c0c7a1448379f75d92bbbc782a8" } +serde = "1.0.126" + +# utils = { path = "../utils" } diff --git a/crates/bistortion/src/lib.rs b/crates/bistortion/src/lib.rs new file mode 100644 index 0000000..00cf45b --- /dev/null +++ b/crates/bistortion/src/lib.rs @@ -0,0 +1,67 @@ +#![allow(incomplete_features)] +#![feature(generic_associated_types)] + +use baseplug::{Plugin, ProcessContext}; +use serde::{Deserialize, Serialize}; + +baseplug::model! { + #[derive(Debug, Serialize, Deserialize)] + struct BistortionModel { + #[model(min = 0.0, max = 10.0)] + #[parameter(name = "a")] + a: f32, + #[model(min = 0.0, max = 30.0)] + #[parameter(name = "b")] + b: f32, + } +} + +impl Default for BistortionModel { + fn default() -> Self { + Self { a: 1.0, b: 1.0 } + } +} + +struct Bistortion { + frame: usize, +} + +impl Plugin for Bistortion { + const NAME: &'static str = "bistortion"; + const PRODUCT: &'static str = "bistortion"; + const VENDOR: &'static str = "unnieversal"; + + const INPUT_CHANNELS: usize = 2; + const OUTPUT_CHANNELS: usize = 2; + + type Model = BistortionModel; + + #[inline] + fn new(_sample_rate: f32, _model: &BistortionModel) -> Self { + Self { frame: 0 } + } + + #[inline] + fn process(&mut self, model: &BistortionModelProcess, ctx: &mut ProcessContext) { + let input = &ctx.inputs[0].buffers; + let output = &mut ctx.outputs[0].buffers; + + for i in 0..ctx.nframes { + let a = model.a[i]; + let b = model.b[i]; + let p = self.frame as f32 / ctx.sample_rate; + + output[0][i] = process(input[0][i], p, a, b); + output[1][i] = process(input[1][i], p, a, b); + + self.frame += 1; + } + } +} + +// https://www.desmos.com/calculator/8gmb283p0v +fn process(v: f32, p: f32, a: f32, b: f32) -> f32 { + (v * a * (b * v).cos()).tanh() +} + +baseplug::vst2!(Bistortion, b"bist"); diff --git a/macos.sh b/macos.sh index a601719..499f405 100755 --- a/macos.sh +++ b/macos.sh @@ -1,6 +1,7 @@ #!/bin/bash -# Make sure we have the arguments we need +set -e + if [[ -z $1 ]]; then echo "Builds, bundles and copies to /Library/Audio/Plug-Ins/VST a package" echo "Example:"