audio_processor_traits/lib.rs
1// Augmented Audio: Audio libraries and applications
2// Copyright (c) 2022 Pedro Tacla Yamada
3//
4// The MIT License (MIT)
5//
6// Permission is hereby granted, free of charge, to any person obtaining a copy
7// of this software and associated documentation files (the "Software"), to deal
8// in the Software without restriction, including without limitation the rights
9// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10// copies of the Software, and to permit persons to whom the Software is
11// furnished to do so, subject to the following conditions:
12//
13// The above copyright notice and this permission notice shall be included in
14// all copies or substantial portions of the Software.
15//
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22// THE SOFTWARE.
23
24pub use num;
25pub use num::Float;
26pub use num::Zero;
27
28pub use atomic_float::{AtomicF32, AtomicF64};
29pub use audio_buffer::AudioBuffer;
30pub use context::AudioContext;
31pub use midi::{MidiEventHandler, MidiMessageLike, NoopMidiEventHandler};
32pub use noop_processors::*;
33pub use settings::*;
34
35/// Atomic F32 implementation with `num` trait implementations
36pub mod atomic_float;
37/// Provides an abstraction for audio buffers that works for [`cpal`] and [`vst`] layouts
38pub mod audio_buffer;
39/// The "staged context" for audio processors
40pub mod context;
41/// Provides an abstraction for MIDI processing that works for stand-alone and [`vst`] events
42pub mod midi;
43/// Parameters for [`AudioProcessor`]
44pub mod parameters;
45/// Simpler audio processor trait, ingesting sample by sample
46pub mod simple_processor;
47
48mod noop_processors;
49mod settings;
50
51/// Represents an audio processing node.
52///
53/// Implementors should define the SampleType the node will work over. See some [examples here](https://github.com/yamadapc/augmented-audio/tree/master/crates/augmented/application/audio-processor-standalone/examples).
54pub trait AudioProcessor {
55 type SampleType: Sized;
56
57 /// Prepare for playback based on current audio settings
58 fn prepare(&mut self, _context: &mut AudioContext) {}
59
60 /// Process a block of samples by mutating the input `AudioBuffer`
61 fn process(&mut self, _context: &mut AudioContext, data: &mut AudioBuffer<Self::SampleType>);
62}