bbx_dsp/context.rs
1//! DSP processing context.
2//!
3//! This module provides [`DspContext`], which carries audio processing parameters
4//! through the DSP graph during block processing.
5
6use crate::channel::ChannelLayout;
7
8/// Default buffer size for DSP graphs (512 samples).
9pub const DEFAULT_BUFFER_SIZE: usize = 512;
10
11/// Default sample rate for DSP graphs (44100 Hz).
12pub const DEFAULT_SAMPLE_RATE: f64 = 44100.0;
13
14/// Runtime context passed to blocks during audio processing.
15///
16/// Contains the audio specification (sample rate, channels, buffer size) and
17/// the current playback position. This context is passed to every block's
18/// `process()` method, allowing time-dependent calculations.
19#[derive(Clone)]
20pub struct DspContext {
21 /// The audio sample rate in Hz (e.g., 44100.0, 48000.0).
22 pub sample_rate: f64,
23
24 /// The number of output channels (e.g., 2 for stereo).
25 pub num_channels: usize,
26
27 /// The number of samples processed per block.
28 pub buffer_size: usize,
29
30 /// The absolute sample position since playback started.
31 /// Increments by `buffer_size` after each process cycle.
32 pub current_sample: u64,
33
34 /// The channel layout for audio processing.
35 /// Describes the speaker/channel configuration (stereo, surround, ambisonics).
36 pub channel_layout: ChannelLayout,
37}