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
48
49
/*
 * File: modulation.rs
 * Project: src
 * Created Date: 28/04/2022
 * Author: Shun Suzuki
 * -----
 * Last Modified: 05/12/2022
 * Modified By: Shun Suzuki (suzuki@hapis.k.u-tokyo.ac.jp)
 * -----
 * Copyright (c) 2022 Shun Suzuki. All rights reserved.
 *
 */

use anyhow::Result;

use crate::datagram::DatagramHeader;

pub struct ModProps {
    pub buffer: Vec<u8>,
    pub freq_div: u32,
    pub built: bool,
    pub sent: usize,
}

impl ModProps {
    pub fn new() -> Self {
        Self {
            buffer: vec![],
            freq_div: 40960,
            built: false,
            sent: 0,
        }
    }
}

impl Default for ModProps {
    fn default() -> Self {
        Self::new()
    }
}

/// Modulation contains the amplitude modulation data.
pub trait Modulation: DatagramHeader {
    fn build(&mut self) -> Result<()>;
    fn rebuild(&mut self) -> Result<()>;
    fn buffer(&self) -> &[u8];
    fn sampling_frequency_division(&mut self) -> &mut u32;
    fn sampling_freq(&self) -> f64;
}