Custom Modulation Tutorial
You can create your own Modulation
as well as Gain
.
Here, we try to create a Burst
that outputs only for a certain moment in a cycle.
The following is a sample of Burst
.
use autd3::prelude::*;
use autd3::core::derive::*;
#[derive(Modulation, Debug)]
pub struct Burst {
config: SamplingConfig,
loop_behavior: LoopBehavior,
}
impl Burst {
pub fn new() -> Self {
Self {
config: (4000 * Hz).try_into().unwrap(),
loop_behavior: LoopBehavior::infinite(),
}
}
}
impl Modulation for Burst {
fn calc(self) -> Result<Vec<u8>, ModulationError> {
Ok((0..4000)
.map(|i| if i == 3999 { u8::MAX } else { u8::MIN })
.collect())
}
}
#[allow(unused_variables)]
fn main() {
}
{{#include ../../../codes/Users_Manual/advanced/custom_modulation_0.cpp}}
{{#include ../../../codes/Users_Manual/advanced/custom_modulation_0.cs}}
{{#include ../../../codes/Users_Manual/advanced/custom_modulation_0.py}}