A few DSP blocks

This commit is contained in:
2026-03-06 19:55:31 +01:00
parent 5f86cb2cd6
commit af9308c070
19 changed files with 799 additions and 37 deletions

View File

@ -1,9 +1,9 @@
use crate::Block;
use crate::{Block, BlockWork, RunnableBlock};
use petgraph::graph::DiGraph;
pub struct Graph
{
blocks: Vec<Box<dyn Block>>,
blocks: Vec<Box<dyn RunnableBlock>>,
}
impl Graph
@ -13,7 +13,7 @@ impl Graph
Graph { blocks: vec![] }
}
pub fn add_block(&mut self, block: impl Block + 'static)
pub fn add_block(&mut self, block: impl Block + BlockWork + 'static)
{
block.set_block_index(self.blocks.len());
self.blocks.push(Box::new(block));
@ -23,14 +23,16 @@ impl Graph
{
// Compute the topo_order
let mut digraph = DiGraph::<(), (), usize>::with_capacity(self.blocks.len(), 1);
let len = self.blocks.len();
(0..len).for_each(|_| {
digraph.add_node(());
});
for block in self.blocks.iter()
for (i, block) in self.blocks.iter().enumerate()
{
let node = digraph.add_node(());
for next in block.get_successors()
{
digraph.add_edge(node, next.into(), ());
digraph.add_edge(i.into(), next.into(), ());
}
}

View File

@ -3,6 +3,7 @@ use ringbuf::SharedRb;
use ringbuf::consumer::PopIter;
use ringbuf::storage::Heap;
use ringbuf::traits::Consumer;
use ringbuf::traits::Observer;
use ringbuf::traits::Producer;
use ringbuf::traits::Split;
use ringbuf::wrap::caching::Caching;
@ -61,6 +62,11 @@ impl<T> In<T>
{
self.rb.pop_iter()
}
pub fn available_len(&self) -> usize
{
self.rb.occupied_len()
}
}
impl<T> Out<T>
@ -81,4 +87,9 @@ impl<T> Out<T>
{
self.rb.push_iter(iter)
}
pub fn vacant_len(&self) -> usize
{
self.rb.vacant_len()
}
}

View File

@ -4,11 +4,14 @@ pub mod inout;
pub trait BlockWork
{
fn work(&mut self);
fn ready(&self) -> bool;
fn ready(&mut self) -> bool;
}
pub trait Block: BlockWork
pub trait Block
{
fn set_block_index(&self, index: usize);
fn get_successors(&self) -> Vec<usize>;
}
pub trait RunnableBlock: Block + BlockWork {}
impl<T> RunnableBlock for T where T: Block + BlockWork {}