zero cost abstraction

This commit is contained in:
2026-06-12 15:15:11 +02:00
parent d3375c0e22
commit b4b2845321
4 changed files with 75 additions and 23 deletions

View File

@ -1,7 +1,8 @@
// Finite Impulse response + Decimation
use crate::{iq_reader::IqChunk, iq_reader::IqSample, utils::ring_buffer::RingBuffer};
pub struct Fir<const N: usize> {
pub struct Fir<I, const N: usize> {
inner: I,
// Filter coefs
pub taps: [f32; N],
@ -15,9 +16,10 @@ pub struct Fir<const N: usize> {
pub decimation_index: usize,
}
impl<const N: usize> Fir<N> {
pub fn new(taps: [f32; N], decimation_factor: usize) -> Self {
impl<I, const N: usize> Fir<I, N> {
pub fn new(inner: I, taps: [f32; N], decimation_factor: usize) -> Self {
Self {
inner,
taps,
history: RingBuffer::<IqSample>::new(N),
decimation_factor,
@ -39,3 +41,20 @@ impl<const N: usize> Fir<N> {
// TODO: Decimation
}
}
impl<I, E, const N: usize> Iterator for Fir<I, N>
where
I: Iterator<Item = Result<IqChunk, E>>,
{
type Item = Result<IqChunk, E>;
fn next(&mut self) -> Option<Self::Item> {
match self.inner.next()? {
Ok(mut chunk) => {
self.process_chunk(&mut chunk);
Some(Ok(chunk))
}
Err(e) => Some(Err(e)),
}
}
}