unnieversal/crates/double_reverse_delta_inverter/src/lib.rs

62 lines
1.5 KiB
Rust

#![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<Self>) {
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");