rasterwave 0.6.0

High-performance streaming SSTV, radiofax and RTTY encoders/decoders
Documentation
//! Streaming RTTY (ITA2 / Baudot FSK) modem for audio frequency-shift keying.
//!
//! [`RttyEncoder`] turns text typed while transmitting into continuous-phase
//! AFSK and reports when each character is committed to the waveform.
//! [`RttyDecoder`] demodulates mark and space with matched filters, makes soft
//! decisions with several rules in parallel (optimal ATC, Kahn, mark-only,
//! space-only, optionally reversed) and keeps the most confident framing of
//! each character.
//! [`RttyChannelScanner`] searches a whole audio passband for RTTY signals,
//! tracks them with stable identifiers and decodes a preview of each.
//!
//! Sideband handling belongs to the caller: [`RttyTones`] are audio
//! frequencies, so a caller on upper sideband passes the mark tone above the
//! space tone and a caller on lower sideband passes it below.

mod decoder;
mod dsp;
mod encoder;
mod ita2;
mod profile;
mod scanner;

pub use decoder::{
    RttyCharacter, RttyDecodeEvent, RttyDecoder, RttyDecoderConfig, RttyLane, RttyLaneSet,
    RttySignal, RttySink,
};
pub use encoder::{RttyCharRendered, RttyEncoder, RttyEncoderConfig, RttyIdle, RttyPushReport};
pub use ita2::Shift;
pub use profile::{CharacterSet, RttyProfile, RttyTones, StopBits};
pub use scanner::{RttyChannelScanner, RttyScanChannel, RttyScanEvent, RttyScannerConfig};

/// Encodes `text` into a complete transmission, including preamble and tail.
pub fn encode_rtty(
    text: &str,
    sample_rate: u32,
    config: RttyEncoderConfig,
) -> crate::Result<Vec<f32>> {
    let mut encoder = RttyEncoder::new(sample_rate, config)?;
    encoder.push_text(text)?;
    encoder.finish();
    let mut pcm = Vec::new();
    let mut chunk = vec![0.0_f32; 4_096];
    while !encoder.is_finished() {
        let written = encoder.read_samples(&mut chunk);
        pcm.extend_from_slice(&chunk[..written]);
    }
    Ok(pcm)
}

/// Decodes a complete recording and returns the events an incremental caller would observe.
pub fn decode_rtty(
    samples: &[f32],
    sample_rate: u32,
    config: RttyDecoderConfig,
) -> crate::Result<Vec<RttyDecodeEvent>> {
    let mut decoder = RttyDecoder::new(sample_rate, config)?;
    let mut events = Vec::new();
    decoder.push_f32(samples, &mut events)?;
    decoder.finish(&mut events);
    Ok(events)
}