Skip to main content

rill_core_dsp/
context.rs

1//! DSP algorithm execution context
2
3use rill_core::Transcendental;
4
5/// DSP processing context
6///
7/// Provides information about the current processing state:
8/// - timestamps
9/// - sample rate
10/// - block size
11/// - etc.
12#[derive(Debug, Clone)]
13pub struct DspContext<T: Transcendental> {
14    /// Current sample rate
15    pub sample_rate: f32,
16
17    /// Current block size
18    pub block_size: usize,
19
20    /// Absolute position of the current block (in samples)
21    pub block_position: usize,
22
23    /// Data type for current processing
24    pub _phantom: std::marker::PhantomData<T>,
25}
26
27impl<T: Transcendental> DspContext<T> {
28    /// Create a new context
29    pub fn new(sample_rate: f32, block_size: usize, block_position: usize) -> Self {
30        Self {
31            sample_rate,
32            block_size,
33            block_position,
34            _phantom: std::marker::PhantomData,
35        }
36    }
37
38    /// Get current position in seconds
39    pub fn seconds(&self) -> f64 {
40        self.block_position as f64 / self.sample_rate as f64
41    }
42}