arduino-tnc

git clone https://git.bradleygannon.com/arduino-tnc.git
Log | Files | Refs

lib.rs (1136B)


      1 #![no_std]
      2 
      3 pub mod constants;
      4 pub mod demodulator;
      5 pub mod goertzel;
      6 
      7 #[cfg(test)]
      8 extern crate alloc;
      9 
     10 #[cfg(test)]
     11 mod test_utils {
     12     use alloc::vec;
     13     use alloc::vec::Vec;
     14     use core::f64::consts::TAU;
     15 
     16     use crate::constants::{MARK_HZ, SAMPLE_RATE_HZ, SYMBOL_RATE_HZ};
     17     use crate::demodulator::Symbol;
     18 
     19     /// Generate phase-continuous AFSK audio for the given symbol sequence
     20     pub fn generate_audio_phase_continuous(symbols: &[Symbol]) -> Vec<f32> {
     21         let samples_per_symbol = (SAMPLE_RATE_HZ / SYMBOL_RATE_HZ) as usize;
     22         let mut audio = vec![];
     23         audio.reserve(symbols.len() * samples_per_symbol);
     24 
     25         let mut phase = 0_f64;
     26         let dt = 1. / SAMPLE_RATE_HZ as f64;
     27 
     28         for sym in symbols {
     29             let freq = match sym {
     30                 Symbol::Mark => MARK_HZ as f64,
     31                 Symbol::Space => crate::constants::SPACE_HZ as f64,
     32             };
     33             let phase_inc = freq * dt * TAU;
     34 
     35             for _ in 0..samples_per_symbol {
     36                 audio.push((phase.sin()) as f32);
     37                 phase += phase_inc;
     38             }
     39         }
     40 
     41         audio
     42     }
     43 }