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