[bistortion] create and implement crate
This commit is contained in:
parent
2aaad403d1
commit
e1b2004dcd
3 changed files with 82 additions and 1 deletions
13
crates/bistortion/Cargo.toml
Normal file
13
crates/bistortion/Cargo.toml
Normal 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" }
|
67
crates/bistortion/src/lib.rs
Normal file
67
crates/bistortion/src/lib.rs
Normal 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");
|
3
macos.sh
3
macos.sh
|
@ -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:"
|
||||
|
|
Loading…
Reference in a new issue