diff --git a/crates/double_reverse_delta_inverter/Cargo.toml b/crates/double_reverse_delta_inverter/Cargo.toml new file mode 100644 index 0000000..a55b6b1 --- /dev/null +++ b/crates/double_reverse_delta_inverter/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "double_reverse_delta_inverter" +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" diff --git a/crates/double_reverse_delta_inverter/src/lib.rs b/crates/double_reverse_delta_inverter/src/lib.rs new file mode 100644 index 0000000..b81cb9f --- /dev/null +++ b/crates/double_reverse_delta_inverter/src/lib.rs @@ -0,0 +1,61 @@ +#![allow(incomplete_features)] +#![feature(generic_associated_types)] + +use baseplug::{Plugin, ProcessContext}; +use serde::{Deserialize, Serialize}; + +baseplug::model! { + #[derive(Debug, Serialize, Deserialize)] + struct InverterModel { + #[model(min = 0.0, max = 1.0)] + #[parameter(name = "dry/wet")] + dry_wet: f32, + } +} + +impl Default for InverterModel { + fn default() -> Self { + Self { dry_wet: 1.0 } + } +} + +struct Inverter; + +impl Plugin for Inverter { + const NAME: &'static str = "double-reverse delta inverter"; + const PRODUCT: &'static str = "double-reverse delta inverter"; + const VENDOR: &'static str = "unnieversal"; + + const INPUT_CHANNELS: usize = 2; + const OUTPUT_CHANNELS: usize = 2; + + type Model = InverterModel; + + #[inline] + fn new(_sample_rate: f32, _model: &InverterModel) -> Self { + Self + } + + #[inline] + fn process(&mut self, model: &InverterModelProcess, ctx: &mut ProcessContext) { + let input = &ctx.inputs[0].buffers; + let output = &mut ctx.outputs[0].buffers; + + for i in 0..ctx.nframes { + let dw = model.dry_wet[i]; + + output[0][i] = inv(input[0][i]) * dw + (1.0 - dw) * input[0][i]; + output[1][i] = inv(input[1][i]) * dw + (1.0 - dw) * input[1][i]; + } + } +} + +// https://www.desmos.com/calculator/dbjrrevmp0 +// this is what the function does +// it's like a mirroring of sorts + +fn inv(x: f32) -> f32 { + (1.0 - x.abs()) * x.signum() +} + +baseplug::vst2!(Inverter, b"drdi");