conformal_component/
effect.rs

1//! Abstractions for processors that effect audio.
2
3use crate::audio::{Buffer, BufferMut};
4use crate::{Processor, parameters, parameters::BufferStates};
5
6/// A trait for audio effects
7///
8/// An effect is a processor that processes audio, and has both an input and an output
9/// audio stream. It will receive information about the current state of the parameters
10/// specified by the [`crate::Component`] that created it.
11pub trait Effect: Processor {
12    /// Handle parameter changes without processing any audio data.
13    ///
14    /// Must not allocate or block.
15    fn handle_parameters<P: parameters::States>(&mut self, parameters: P);
16
17    /// Actually process audio data.
18    ///
19    /// Must not allocate or block.
20    ///
21    /// `input` and `output` will be the same length.
22    ///
23    /// `output` will be received in an undetermined state and must
24    /// be filled with audio by the processor during this call.
25    ///
26    /// In addition to recieving the audio, this function also receives
27    /// information about the state of the parameters throughout the buffer
28    /// being processed.
29    ///
30    /// In order to consume the parameters, you can use the [`crate::pzip`] macro
31    /// to convert the parameters into an iterator of tuples that represent
32    /// the state of the parameters at each sample.
33    ///
34    /// The sample rate of the audio was provided in `environment.sampling_rate`
35    /// in the call to `crate::Component::create_processor`.
36    ///
37    /// Note that it's guaranteed that `output` will be no longer than
38    /// `environment.max_samples_per_process_call` provided in the call to
39    /// `crate::Component::create_processor`.
40    fn process<P: BufferStates, I: Buffer, O: BufferMut>(
41        &mut self,
42        parameters: P,
43        input: &I,
44        output: &mut O,
45    );
46}