oddio/constant.rs
1use crate::{Seek, Signal};
2
3/// A constant signal, useful for testing
4pub struct Constant<T>(pub T);
5
6impl<T> Constant<T> {
7 /// Construct a signal that always emits `frame`
8 pub fn new(frame: T) -> Self {
9 Self(frame)
10 }
11}
12
13impl<T: Clone> Signal for Constant<T> {
14 type Frame = T;
15
16 fn sample(&mut self, _interval: f32, out: &mut [T]) {
17 out.fill(self.0.clone());
18 }
19}
20
21impl<T: Clone> Seek for Constant<T> {
22 fn seek(&mut self, _: f32) {}
23}