1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use autd3_driver::derive::*;

#[derive(Modulation, Clone, PartialEq, Debug)]
pub struct Custom {
    buffer: Vec<u8>,
    config: SamplingConfig,
    loop_behavior: LoopBehavior,
}

impl Custom {
    pub fn new(buffer: Vec<u8>, config: SamplingConfig) -> Self {
        Self {
            buffer,
            config,
            loop_behavior: LoopBehavior::infinite(),
        }
    }
}
impl Modulation for Custom {
    fn calc(&self, _: &Geometry) -> ModulationCalcResult {
        Ok(self.buffer.clone())
    }
}

#[cfg(test)]
mod tests {
    use rand::Rng;

    use crate::tests::create_geometry;

    use super::*;

    #[test]
    fn test_custom() -> anyhow::Result<()> {
        let mut rng = rand::thread_rng();

        let geometry = create_geometry(2);

        let test_buf = (0..2).map(|_| rng.gen()).collect::<Vec<_>>();
        let custom = Custom::new(test_buf.clone(), SamplingConfig::Division(5120));

        let d = custom.calc(&geometry)?;
        assert_eq!(d, test_buf);

        Ok(())
    }
}