autd3_core/modulation/
mod.rs

1mod error;
2
3use std::sync::Arc;
4
5use crate::{
6    datagram::{LoopBehavior, Segment, TransitionMode},
7    derive::FirmwareLimits,
8    sampling_config::SamplingConfig,
9};
10pub use error::ModulationError;
11
12/// Trait for applying amplitude modulation.
13///
14/// See also [`Modulation`] derive macro.
15///
16/// [`Modulation`]: autd3_derive::Modulation
17pub trait Modulation: std::fmt::Debug {
18    /// Calculate the modulation data.
19    fn calc(self, limits: &FirmwareLimits) -> Result<Vec<u8>, ModulationError>;
20
21    /// The sampling configuration.
22    #[must_use]
23    fn sampling_config(&self) -> SamplingConfig;
24}
25
26#[doc(hidden)]
27pub struct ModulationOperationGenerator {
28    pub g: Arc<Vec<u8>>,
29    pub config: SamplingConfig,
30    pub limits: FirmwareLimits,
31    pub loop_behavior: LoopBehavior,
32    pub segment: Segment,
33    pub transition_mode: Option<TransitionMode>,
34}
35
36#[derive(Debug, Clone, PartialEq)]
37/// The result of the [`Modulation`] inspection.
38pub struct ModulationInspectionResult {
39    /// The type name of the modulation.
40    pub name: String,
41    /// The data of the modulation.
42    pub data: Vec<u8>,
43    /// The sampling configuration.
44    pub config: SamplingConfig,
45    /// The loop behavior.
46    pub loop_behavior: LoopBehavior,
47    /// The segment of the modulation.
48    pub segment: Segment,
49    /// The transition mode of the modulation.
50    pub transition_mode: Option<TransitionMode>,
51}