dfpworm start
This commit is contained in:
parent
ac98cbe6c7
commit
30c6bf5f6f
7 changed files with 280 additions and 21 deletions
|
@ -1,14 +1,161 @@
|
|||
pub fn add(left: u64, right: u64) -> u64 {
|
||||
left + right
|
||||
use std::sync::Arc;
|
||||
|
||||
use nih_plug::prelude::*;
|
||||
|
||||
mod dfpwm;
|
||||
|
||||
pub struct Worm {
|
||||
params: Arc<WormParams>,
|
||||
|
||||
compress_contexts: Vec<dfpwm::Context>,
|
||||
decompress_contexts: Vec<dfpwm::Context>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[derive(Params)]
|
||||
struct WormParams {
|
||||
#[id = "response-increase"]
|
||||
response_increase: FloatParam,
|
||||
#[id = "response-decrease"]
|
||||
response_decrease: FloatParam,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
impl Default for Worm {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
params: Arc::new(WormParams::default()),
|
||||
|
||||
compress_contexts: Vec::new(),
|
||||
decompress_contexts: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for WormParams {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
response_increase: FloatParam::new(
|
||||
"Response Increase",
|
||||
dfpwm::DEFAULT_RESPONSE_INCREASE,
|
||||
FloatRange::Linear { min: 0.0, max: 1.0 },
|
||||
),
|
||||
|
||||
response_decrease: FloatParam::new(
|
||||
"Response Decrease",
|
||||
dfpwm::DEFAULT_RESPONSE_DECREASE,
|
||||
FloatRange::Linear { min: 0.0, max: 1.0 },
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Plugin for Worm {
|
||||
const NAME: &'static str = "Dirty Frying Pan Worm";
|
||||
|
||||
const VENDOR: &'static str = "fogwaves";
|
||||
|
||||
const URL: &'static str = "https://example.com";
|
||||
|
||||
const EMAIL: &'static str = "info@example.com";
|
||||
|
||||
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
const AUDIO_IO_LAYOUTS: &'static [AudioIOLayout] = &[
|
||||
AudioIOLayout {
|
||||
main_input_channels: NonZeroU32::new(2),
|
||||
main_output_channels: NonZeroU32::new(2),
|
||||
..AudioIOLayout::const_default()
|
||||
},
|
||||
AudioIOLayout {
|
||||
main_input_channels: NonZeroU32::new(1),
|
||||
main_output_channels: NonZeroU32::new(1),
|
||||
..AudioIOLayout::const_default()
|
||||
},
|
||||
];
|
||||
|
||||
const SAMPLE_ACCURATE_AUTOMATION: bool = true;
|
||||
|
||||
type SysExMessage = ();
|
||||
|
||||
type BackgroundTask = ();
|
||||
|
||||
fn params(&self) -> Arc<dyn Params> {
|
||||
self.params.clone()
|
||||
}
|
||||
|
||||
fn initialize(
|
||||
&mut self,
|
||||
audio_io_layout: &AudioIOLayout,
|
||||
_buffer_config: &BufferConfig,
|
||||
_context: &mut impl InitContext<Self>,
|
||||
) -> bool {
|
||||
if let Some(n) = audio_io_layout.main_input_channels {
|
||||
for _i in 0..n.into() {
|
||||
self.compress_contexts.push(dfpwm::Context::new());
|
||||
self.decompress_contexts.push(dfpwm::Context::new());
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
fn reset(&mut self) {
|
||||
for ctx in self.compress_contexts.iter_mut() {
|
||||
ctx.reset();
|
||||
}
|
||||
for ctx in self.decompress_contexts.iter_mut() {
|
||||
ctx.reset();
|
||||
}
|
||||
}
|
||||
|
||||
fn deactivate(&mut self) {}
|
||||
|
||||
fn process(
|
||||
&mut self,
|
||||
buffer: &mut Buffer,
|
||||
_aux: &mut AuxiliaryBuffers,
|
||||
_context: &mut impl ProcessContext<Self>,
|
||||
) -> ProcessStatus {
|
||||
for channel_samples in buffer.iter_samples() {
|
||||
let response_increase = self.params.response_increase.smoothed.next();
|
||||
let response_decrease = self.params.response_decrease.smoothed.next();
|
||||
|
||||
for (i, sample) in channel_samples.into_iter().enumerate() {
|
||||
self.compress_contexts[i].response_increase = response_increase;
|
||||
self.decompress_contexts[i].response_decrease = response_decrease;
|
||||
|
||||
let bit = self.compress_contexts[i].compress(*sample);
|
||||
*sample = self.decompress_contexts[i].decompress(bit);
|
||||
}
|
||||
}
|
||||
|
||||
ProcessStatus::Normal
|
||||
}
|
||||
}
|
||||
|
||||
impl ClapPlugin for Worm {
|
||||
const CLAP_ID: &'static str = "fogwaves.dfpworm";
|
||||
|
||||
const CLAP_DESCRIPTION: Option<&'static str> =
|
||||
Some("Runs audio through the DFPWM 1-bit audio codec by Ben \"GreaseMonkey\" Russel.");
|
||||
|
||||
const CLAP_MANUAL_URL: Option<&'static str> = Some(Self::URL);
|
||||
|
||||
const CLAP_SUPPORT_URL: Option<&'static str> = None;
|
||||
|
||||
const CLAP_FEATURES: &'static [ClapFeature] = &[
|
||||
ClapFeature::AudioEffect,
|
||||
ClapFeature::Stereo,
|
||||
ClapFeature::Mono,
|
||||
ClapFeature::Distortion,
|
||||
];
|
||||
}
|
||||
|
||||
impl Vst3Plugin for Worm {
|
||||
const VST3_CLASS_ID: [u8; 16] = *b"FogwavesDFPWormC";
|
||||
|
||||
const VST3_SUBCATEGORIES: &'static [Vst3SubCategory] =
|
||||
&[Vst3SubCategory::Fx, Vst3SubCategory::Distortion];
|
||||
}
|
||||
|
||||
nih_export_clap!(Worm);
|
||||
nih_export_vst3!(Worm);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue