From 819171720cff5c28539d039da932ea8f296d70ad Mon Sep 17 00:00:00 2001 From: zeefaad Date: Thu, 11 Jun 2026 13:19:41 +0200 Subject: [PATCH] ring buffer init --- src/fir.rs | 32 ++++++++++++++++++++++++++++++++ src/main.rs | 2 ++ src/utils/mod.rs | 1 + src/utils/ring_buffer.rs | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 src/fir.rs create mode 100644 src/utils/mod.rs create mode 100644 src/utils/ring_buffer.rs diff --git a/src/fir.rs b/src/fir.rs new file mode 100644 index 0000000..a82faa6 --- /dev/null +++ b/src/fir.rs @@ -0,0 +1,32 @@ +// Finite Impulse response + Decimation +use num_complex::Complex32; +use crate::utils::ring_buffer::RingBuffer; + +pub struct Fir { + // Filter coefs + pub taps: Vec, + + // Ring Buffer of samples + pub history: RingBuffer, + + decimation_factor: usize, + + // When to keep a sample + decimator_counter: usize, +} + +impl Fir { + fn new(decimation_factor: usize) -> Self { + Self { + // TODO: precalulate filter coefs + ring buffer + taps: vec![], + history: + decimation_factor, + decimator_counter: 0, + } + } + + fn () { + + } +} diff --git a/src/main.rs b/src/main.rs index 5ceb870..ac8a70d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,9 @@ use crate::iq_reader::FileSource; use std::error::Error; mod agc; +mod fir; mod iq_reader; +mod utils; fn main() -> Result<(), Box> { let source = FileSource::new("test.iq", 32769)?; diff --git a/src/utils/mod.rs b/src/utils/mod.rs new file mode 100644 index 0000000..5fcb102 --- /dev/null +++ b/src/utils/mod.rs @@ -0,0 +1 @@ +pub mod ring_buffer; diff --git a/src/utils/ring_buffer.rs b/src/utils/ring_buffer.rs new file mode 100644 index 0000000..d28b714 --- /dev/null +++ b/src/utils/ring_buffer.rs @@ -0,0 +1,38 @@ +pub struct RingBuffer { + pub data: Vec, + pub head: usize, + pub tail: usize, + pub len: usize, +} + +impl RingBuffer { + fn new(capacity: usize) -> Self { + // TODO : add capacity to vec + Self { + data: Vec::new(), + head: 0, + tail: 0, + len: 0, + } + } + + fn push(&mut self, value: T) { + todo!(); + } + + fn pop(&mut self) -> bool { + todo!(); + } + + fn is_empty(&self) -> bool { + todo!(); + } + + fn is_full(&self) -> bool { + todo!(); + } + + fn len(&self) -> usize { + self.len + } +}