[double-reverse delta inverter] make and implement crate

main
annieversary 2021-08-02 16:04:26 +02:00
parent 66772aca19
commit 7f6ee9a828
2 changed files with 72 additions and 0 deletions

View File

@ -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"

View File

@ -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<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");