fn encode_byte(osc: &mut PhaseAccumulator, byte: &u8) -> Vec<f32> {
    let samples_per_bit = (BIT_DURATION_S * osc.sample_rate_hz).round() as usize;
    let mut samples = Vec::with_capacity(samples_per_bit * 8);
    // Encode one bit at a time (little-endian)
    for b in 0..8 {
        let mut s = Vec::with_capacity(samples_per_bit);
        let n_cycles = if byte & (1 << b) == 0 {
            osc.set_freq(ZERO_FREQ_HZ);
            6
        } else {
            osc.set_freq(ONE_FREQ_HZ);
            8
        };
        let mut n_zero_crossings = 0;
        let mut last_sample = 0f32;
        while n_zero_crossings < n_cycles {
            let next_sample = osc.next_sample();
            s.push(next_sample);
            if (last_sample < 0f32 && next_sample >= 0f32) || (last_sample > 0f32 && next_sample <= 0f32) {
                n_zero_crossings += 1;
            }
            last_sample = next_sample;
        }
        samples.append(&mut s);
    }
    samples
}
/// FSK-encode a byte for a SAME message
FSK-encode a byte for a SAME message
FSK - encode a byte for a SAME message
fn encode_byte(osc: &mut PhaseAccumulator, byte: &u8) -> Vec<f32> {
    let samples_per_bit = (BIT_DURATION_S * osc.sample_rate_hz).round() as usize;
    let mut samples = Vec::with_capacity(samples_per_bit * 8);
    // Encode one bit at a time (little-endian)
    for b in 0..8 {
        let mut s = Vec::with_capacity(samples_per_bit);
        let n_cycles = if byte & (1 << b) == 0 {
            osc.set_freq(ZERO_FREQ_HZ);
            6
        } else {
            osc.set_freq(ONE_FREQ_HZ);
            8
        };
        let mut n_zero_crossings = 0;
        let mut last_sample = 0f32;
        while n_zero_crossings < n_cycles {
            let next_sample = osc.next_sample();
            s.push(next_sample);
            if (last_sample < 0f32 && next_sample >= 0f32) || (last_sample > 0f32 && next_sample <= 0f32) {
                n_zero_crossings += 1;
            }
            last_sample = next_sample;
        }
        samples.append(&mut s);
    }
    samples
}
fn encode_byte ( osc : & mut PhaseAccumulator , byte : & u8 ) -> Vec < f32 > { let samples_per_bit = ( BIT_DURATION_S * osc . sample_rate_hz ) . round ( ) as usize ; let mut samples = Vec :: with_capacity ( samples_per_bit * 8 ) ; // Encode one bit at a time (little-endian) for b in 0 .. 8 { let mut s = Vec :: with_capacity ( samples_per_bit ) ; let n_cycles = if byte & ( 1 << b ) == 0 { osc . set_freq ( ZERO_FREQ_HZ ) ; 6 } else { osc . set_freq ( ONE_FREQ_HZ ) ; 8 } ; let mut n_zero_crossings = 0 ; let mut last_sample = 0f32 ; while n_zero_crossings < n_cycles { let next_sample = osc . next_sample ( ) ; s . push ( next_sample ) ; if ( last_sample < 0f32 && next_sample >= 0f32 ) || ( last_sample > 0f32 && next_sample <= 0f32 ) { n_zero_crossings += 1 ; } last_sample = next_sample ; } samples . append ( & mut s ) ; } samples }
FSK-encode a byte for a SAME message
FSK - encode a byte for a SAME message
osc
&mut PhaseAccumulator
byte
&u8