Skip to main content

wavecraft_dsp/builtins/
passthrough.rs

1//! Passthrough processor - does nothing (useful for testing and placeholders).
2
3use crate::traits::{Processor, ProcessorParams, Transport};
4
5/// Empty parameter struct for passthrough processor.
6#[derive(Debug, Default, Clone)]
7pub struct PassthroughParams;
8
9impl ProcessorParams for PassthroughParams {
10    fn param_specs() -> &'static [crate::traits::ParamSpec] {
11        &[] // No parameters
12    }
13}
14
15/// Passthrough processor - does not modify the audio signal.
16///
17/// This processor is useful for:
18/// - Testing signal chain composition
19/// - Placeholder in development
20/// - Bypass functionality
21#[derive(Debug, Default)]
22pub struct PassthroughDsp;
23
24impl Processor for PassthroughDsp {
25    type Params = PassthroughParams;
26
27    fn process(
28        &mut self,
29        _buffer: &mut [&mut [f32]],
30        _transport: &Transport,
31        _params: &Self::Params,
32    ) {
33        // No-op: audio passes through unchanged
34    }
35
36    fn set_sample_rate(&mut self, _sample_rate: f32) {
37        // No state dependent on sample rate
38    }
39
40    fn reset(&mut self) {
41        // No state to reset
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_passthrough() {
51        let mut processor = PassthroughDsp;
52        let original = [0.5, -0.5, 0.25, -0.25];
53        let mut data = original;
54        let mut buffer = [&mut data[..]];
55
56        let params = PassthroughParams;
57        let transport = Transport::default();
58
59        processor.process(&mut buffer, &transport, &params);
60
61        // Data should be unchanged
62        for (i, &sample) in data.iter().enumerate() {
63            assert_eq!(sample, original[i]);
64        }
65    }
66
67    #[test]
68    fn test_no_params() {
69        let specs = PassthroughParams::param_specs();
70        assert_eq!(specs.len(), 0);
71    }
72}