[bistortion] create and implement crate

main
annieversary 2021-08-31 23:37:02 +02:00
parent 2aaad403d1
commit e1b2004dcd
3 changed files with 82 additions and 1 deletions

View File

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

View File

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

View File

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