Skip to main content

PluginAudioProcessor

Trait PluginAudioProcessor 

Source
pub trait PluginAudioProcessor<'a, S: PluginShared<'a>, M: PluginMainThread<'a, S>>:
    Sized
    + Send
    + 'a {
    // Required methods
    fn activate(
        host: HostAudioProcessorHandle<'a>,
        main_thread: &M,
        shared: &'a S,
        audio_config: PluginAudioConfiguration,
    ) -> Result<Self, PluginError>;
    fn process(
        &mut self,
        process: Process<'_>,
        audio: Audio<'_>,
        events: Events<'_>,
    ) -> Result<ProcessStatus, PluginError>;

    // Provided methods
    fn deactivate(self, main_thread: &M) { ... }
    fn reset(&mut self) { ... }
    fn start_processing(&mut self) -> Result<(), PluginError> { ... }
    fn stop_processing(&mut self) { ... }
}
Expand description

The audio processor and main part of a plugin.

This type implements all DSP-related operations, most notably process, which processes all input and output audio and events.

The associated lifetime 'a represents the lifetime of the plugin itself, as well as the lifetime of the data exposed by the host.

This type requires to be Send but not Sync: it can be sent between any of the host’s threads, but none of its operations will be performed on multiple threads simultaneously.

The audio processor can also define two associated types, Shared and MainThread, allowing to execute operations in and hold data belonging to other threads. If they are not needed, the empty () type can be used instead, for convenience.

See the module documentation for more information on the thread model.

Required Methods§

Source

fn activate( host: HostAudioProcessorHandle<'a>, main_thread: &M, shared: &'a S, audio_config: PluginAudioConfiguration, ) -> Result<Self, PluginError>

Creates and activates the audio processor.

This method serves as a constructor for the audio processor, in which it can perform non-realtime-safe initialization operations, such as allocating audio buffers using the provided PluginAudioConfiguration.

This method is always executed on the main thread, allowing it to temporarily access main thread data.

§Arguments
  • host: an exclusive host handle that can be stored for the lifetime of the plugin.
  • main_thread: a temporary exclusive reference to the plugin’s main thread data.
  • shared: a reference to the plugin’s shared data, that can be stored for the lifetime of the plugin.
  • audio_config: the PluginAudioConfiguration, valid throughout the audio processor’s lifetime.
§Errors

This operation may fail for any reason, in which case Err is returned and the plugin is not activated.

§Realtime Safety

This method is not realtime-safe: it may perform memory allocations of audio buffers, or any other initialization the plugin may deem necessary.

Source

fn process( &mut self, process: Process<'_>, audio: Audio<'_>, events: Events<'_>, ) -> Result<ProcessStatus, PluginError>

Processes a chunk of audio samples and events.

This method returns a ProcessStatus as a hint towards whether the host can set this plugin to sleep, or if the plugin wants to process more audio or events. This is only a hint however, and the host is free to ignore it.

§Arguments
  • process contains metadata about the current process call, including transport information and a steady sample counter.
  • audio contains references to all the audio buffers for this block.
  • events contains both the InputEvents list and the OutputEvents queue.
§Realtime Safety

This method MUST be realtime-safe, and is in fact the most performance-sensitive part of the whole plugin implementation.

§Errors

This method may fail for any reason, depending on the plugin’s implementation.

Provided Methods§

Source

fn deactivate(self, main_thread: &M)

Deactivates the audio processor.

This method can serve as a destructor for the audio processor.

This method is always executed on the main thread, allowing it to temporarily access main thread data.

§Arguments
  • main_thread: a temporary exclusive reference to the plugin’s main thread data.
§Realtime Safety

This method is not realtime-safe: it may perform memory de-allocations of audio buffers, or any other un-initialization the plugin may deem necessary.

Source

fn reset(&mut self)

Resets the plugin’s audio processing state.

This clears all the plugin’s internal buffers, kills all voices, and resets all processing state such as envelopes, LFOs, oscillators, filters, etc.

Calling this method allows the steady_time parameter passed to process to jump backwards.

Source

fn start_processing(&mut self) -> Result<(), PluginError>

Starts the plugin’s continuous audio processing.

This is called when the plugin needs to wake up from sleep, or after it was activated.

§Errors

This method may fail for any reason, depending on the plugin’s implementation.

Source

fn stop_processing(&mut self)

Stops the plugin’s continuous audio processing, indicating it is being sent to sleep.

When this is called, the plugin’s audio processor cannot assume that the next block of audio and events it receives (if any) is contiguous to the last one it processed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'a, M: PluginMainThread<'a, S>, S: PluginShared<'a>> PluginAudioProcessor<'a, S, M> for ()

Source§

fn activate( _host: HostAudioProcessorHandle<'a>, _main_thread: &M, _shared: &'a S, _audio_config: PluginAudioConfiguration, ) -> Result<Self, PluginError>

Source§

fn process( &mut self, _process: Process<'_>, _audio: Audio<'_>, _events: Events<'_>, ) -> Result<ProcessStatus, PluginError>

Implementors§