zero cost abstraction
This commit is contained in:
25
src/fir.rs
25
src/fir.rs
@ -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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user