use num_complex::Complex;
pub mod afc;
pub mod ais;
pub mod cic5;
pub mod ema;
pub mod fir;
pub mod rotate;
pub mod sample_rate;
pub mod scatter;
pub mod upsampler;
#[derive(Debug, Clone, Default)]
pub struct Tag {
pub sample_idx: usize,
pub sample_lvl: f32,
pub ppm: f32,
pub mode: u32,
pub group: u64,
pub level: f32,
}
pub trait Stream<TIn, TOut> {
fn receive(&mut self, data: &[TIn], tag: &mut Tag) -> Vec<TOut>;
fn reset(&mut self) {}
}
pub trait StreamStateless<TIn, TOut> {
fn process(&self, data: &[TIn], tag: &mut Tag) -> Vec<TOut>;
}
impl<T, TIn, TOut> Stream<TIn, TOut> for T
where
T: StreamStateless<TIn, TOut>,
{
fn receive(&mut self, data: &[TIn], tag: &mut Tag) -> Vec<TOut> {
self.process(data, tag)
}
}
pub fn convert_samples_cu8(samples: &[u8]) -> Vec<Complex<f32>> {
samples
.chunks_exact(2)
.map(|chunk| {
let i = (chunk[0] as f32 - 127.5) / 128.0;
let q = (chunk[1] as f32 - 127.5) / 128.0;
Complex::new(i, q)
})
.collect()
}
pub fn convert_samples_cs8(samples: &[i8]) -> Vec<Complex<f32>> {
samples
.chunks_exact(2)
.map(|chunk| {
let i = chunk[0] as f32 / 128.0;
let q = chunk[1] as f32 / 128.0;
Complex::new(i, q)
})
.collect()
}
pub fn convert_samples_cs16(samples: &[i16]) -> Vec<Complex<f32>> {
samples
.chunks_exact(2)
.map(|chunk| {
let i = chunk[0] as f32 / 32768.0;
let q = chunk[1] as f32 / 32768.0;
Complex::new(i, q)
})
.collect()
}
pub fn convert_samples_cf32(samples: &[f32]) -> Vec<Complex<f32>> {
samples
.chunks_exact(2)
.map(|chunk| Complex::new(chunk[0], chunk[1]))
.collect()
}