1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::{Seek, Signal};

/// A constant signal, useful for testing
pub struct Constant<T>(pub T);

impl<T> Constant<T> {
    /// Construct a signal that always emits `frame`
    pub fn new(frame: T) -> Self {
        Self(frame)
    }
}

impl<T: Clone> Signal for Constant<T> {
    type Frame = T;

    fn sample(&mut self, _interval: f32, out: &mut [T]) {
        out.fill(self.0.clone());
    }
}

impl<T: Clone> Seek for Constant<T> {
    fn seek(&mut self, _: f32) {}
}