Add a processing status for handling reverb tails
This commit is contained in:
parent
b5636ef556
commit
c11abdc77d
|
@ -19,7 +19,7 @@ extern crate nih_plug;
|
|||
|
||||
use nih_plug::{
|
||||
params::{FloatParam, Params, Range},
|
||||
plugin::{BufferConfig, BusConfig, Plugin},
|
||||
plugin::{BufferConfig, BusConfig, Plugin, ProcessStatus},
|
||||
util,
|
||||
};
|
||||
use std::pin::Pin;
|
||||
|
@ -88,9 +88,9 @@ impl Plugin for Gain {
|
|||
true
|
||||
}
|
||||
|
||||
fn process(&mut self, samples: &mut [&mut [f32]]) {
|
||||
fn process(&mut self, samples: &mut [&mut [f32]]) -> ProcessStatus {
|
||||
if samples.is_empty() {
|
||||
return;
|
||||
return ProcessStatus::Error("Empty buffers");
|
||||
}
|
||||
|
||||
// TODO: The wrapper should set FTZ if not yet enabled, mention ths in the process fuctnion
|
||||
|
@ -100,7 +100,7 @@ impl Plugin for Gain {
|
|||
for channel in &samples[1..] {
|
||||
nih_debug_assert_eq!(channel.len(), num_samples);
|
||||
if channel.len() != num_samples {
|
||||
return;
|
||||
return ProcessStatus::Error("Mismatching channel buffer sizes");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,8 @@ impl Plugin for Gain {
|
|||
*sample *= util::db_to_gain(self.params.gain.value);
|
||||
}
|
||||
}
|
||||
|
||||
ProcessStatus::Normal
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,12 +88,12 @@ pub trait Plugin: Default + Sync {
|
|||
/// TODO: &mut [&mut [f32]] may not be the correct type here
|
||||
/// TODO: Provide a way to access auxiliary input channels if the IO configuration is
|
||||
/// assymetric
|
||||
/// TODO: Add a process result to handle tails
|
||||
/// TODO: Handle FTZ stuff on the wrapper side and mention that this has been handled
|
||||
fn process(&mut self, samples: &mut [&mut [f32]]);
|
||||
fn process(&mut self, samples: &mut [&mut [f32]]) -> ProcessStatus;
|
||||
}
|
||||
|
||||
/// We only support a single main input and output bus at the moment.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct BusConfig {
|
||||
/// The number of input channels for the plugin.
|
||||
pub num_input_channels: u32,
|
||||
|
@ -102,6 +102,7 @@ pub struct BusConfig {
|
|||
}
|
||||
|
||||
/// Configuration for (the host's) audio buffers.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct BufferConfig {
|
||||
/// The current sample rate.
|
||||
pub sample_rate: f32,
|
||||
|
@ -109,3 +110,19 @@ pub struct BufferConfig {
|
|||
/// sized buffers up to this size.
|
||||
pub max_buffer_size: u32,
|
||||
}
|
||||
|
||||
/// Indicates the current situation after the plugin has processed audio.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ProcessStatus {
|
||||
/// Something went wrong while processing audio.
|
||||
Error(&'static str),
|
||||
/// The plugin has finished processing audio. When the input is silent, the most may suspend the
|
||||
/// plugin to save resources as it sees fit.
|
||||
Normal,
|
||||
/// The plugin has a (reverb) tail with a specific length in samples.
|
||||
Tail(u32),
|
||||
/// This plugin will continue to produce sound regardless of whether or not the input is silent,
|
||||
/// and should thus not be deactivated by the host. This is essentially the same as having an
|
||||
/// infite tail.
|
||||
KeepAlive,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue