From 0f56d9a9c88b7b3bc103315a001e86dbda60c6fc Mon Sep 17 00:00:00 2001 From: annieversary Date: Sun, 25 Jul 2021 11:27:21 +0200 Subject: [PATCH] [tritu] create and implement crate --- README.md | 14 ++++++++ crates/tritu/Cargo.toml | 11 ++++++ crates/tritu/src/lib.rs | 75 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 crates/tritu/Cargo.toml create mode 100644 crates/tritu/src/lib.rs diff --git a/README.md b/README.md index 33d4737..844a385 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ the following is the current list of plugins - hysteria: hysteresis nonlinear effect - threebandeq: 3 band eq - threebandwidth: 3 band stereo widener +- tritu: say-goodbye-to-your-audio distortion ### basic_gain @@ -159,6 +160,19 @@ parameters: bands work as they do in `threebandeq`. the width parameters control how wide an audio signal should be in the stereo field. `width` of 1 leaves the audio as is, `width` of 0 makes it mono, values between 0 and 1 decrease the stereo width, values over 1 increase it. +### tritu + +hard limiter followed by a soft limiter with distortion + +parameters: +- `pregain`: pregain for the hard limiter +- `drive`: drive for the soft limiter +- `distortion`: amount of distortion on the soft limiter + +distortion affects lower volumes more than higher volumes, so if you crank up `drive` a lot, there will be less distortion (this is a good thing for high values of `distortion`!). if you leave `drive` low and set `distortion` to max, your audio will turn to almost white noise + +i like this plugin a lot + ## contributing issues and prs are welcome, but please open an issue before making any big pr, i don't wanna have to reject a pr where you have put a lot of effort on diff --git a/crates/tritu/Cargo.toml b/crates/tritu/Cargo.toml new file mode 100644 index 0000000..4e917d2 --- /dev/null +++ b/crates/tritu/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "tritu" +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/tritu/src/lib.rs b/crates/tritu/src/lib.rs new file mode 100644 index 0000000..702c014 --- /dev/null +++ b/crates/tritu/src/lib.rs @@ -0,0 +1,75 @@ +#![allow(incomplete_features)] +#![feature(generic_associated_types)] + +use baseplug::{Plugin, ProcessContext}; +use serde::{Deserialize, Serialize}; + +baseplug::model! { + #[derive(Debug, Serialize, Deserialize)] + struct TrituModel { + #[model(min = 1.0, max = 100.0)] + #[parameter(name = "pregain")] + pregain: f32, + #[model(min = 0.0, max = 20.0)] + #[parameter(name = "drive")] + drive: f32, + #[model(min = 0.0, max = 3.0)] + #[parameter(name = "distortion")] + distortion: f32, + } +} + +impl Default for TrituModel { + fn default() -> Self { + Self { + pregain: 1.0, + drive: 1.0, + distortion: 0.0, + } + } +} + +struct Tritu; + +impl Plugin for Tritu { + const NAME: &'static str = "tritu"; + const PRODUCT: &'static str = "tritu"; + const VENDOR: &'static str = "unnieversal"; + + const INPUT_CHANNELS: usize = 2; + const OUTPUT_CHANNELS: usize = 2; + + type Model = TrituModel; + + #[inline] + fn new(_sample_rate: f32, _model: &TrituModel) -> Self { + Self + } + + #[inline] + fn process(&mut self, model: &TrituModelProcess, ctx: &mut ProcessContext) { + let input = &ctx.inputs[0].buffers; + let output = &mut ctx.outputs[0].buffers; + + for i in 0..ctx.nframes { + let pregain = model.pregain[i]; + let drive = model.drive[i]; + let distortion = model.distortion[i]; + + output[0][i] = trituradora(input[0][i], pregain, drive, distortion); + output[1][i] = trituradora(input[1][i], pregain, drive, distortion); + } + } +} + +fn trituradora(input: f32, pregain: f32, drive: f32, distortion: f32) -> f32 { + // multiply by pregain and hard clip + let hard = (input * pregain).clamp(-1.0, 1.0); + // multiply by drive + let val = hard * drive; + + // weird thingy i made up: https://www.desmos.com/calculator/bzprjqhudd + val.tanh() * (distortion / val).cos() +} + +baseplug::vst2!(Tritu, b"tri2");