Working base
This commit is contained in:
7
oxydsp-dsp/Cargo.toml
Normal file
7
oxydsp-dsp/Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "oxydsp-dsp"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
oxydsp-flowgraph = {path = "../oxydsp-flowgraph/"}
|
||||
2
oxydsp-dsp/src/blocks.rs
Normal file
2
oxydsp-dsp/src/blocks.rs
Normal file
@ -0,0 +1,2 @@
|
||||
pub mod math;
|
||||
pub mod utilities;
|
||||
1
oxydsp-dsp/src/blocks/math.rs
Normal file
1
oxydsp-dsp/src/blocks/math.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod basic;
|
||||
61
oxydsp-dsp/src/blocks/math/basic.rs
Normal file
61
oxydsp-dsp/src/blocks/math/basic.rs
Normal file
@ -0,0 +1,61 @@
|
||||
use std::ops::Add;
|
||||
|
||||
use oxydsp_flowgraph::{
|
||||
BlockIO,
|
||||
block::{Block, BlockResult},
|
||||
edge::{In, Out, PopIterable, stream},
|
||||
};
|
||||
|
||||
#[derive(BlockIO)]
|
||||
pub struct Adder<Ia, Ib, O>
|
||||
where
|
||||
Ia: Add<Ib, Output = O> + 'static,
|
||||
Ib: 'static,
|
||||
O: 'static,
|
||||
{
|
||||
#[input]
|
||||
input_a: In<Ia>,
|
||||
|
||||
#[input]
|
||||
input_b: In<Ib>,
|
||||
|
||||
#[output]
|
||||
output: Out<O>,
|
||||
}
|
||||
|
||||
impl<Ia, Ib, O> Adder<Ia, Ib, O>
|
||||
where
|
||||
Ia: Add<Ib, Output = O> + 'static,
|
||||
Ib: 'static,
|
||||
O: 'static,
|
||||
{
|
||||
pub fn new(input_a: In<Ia>, input_b: In<Ib>) -> (Self, In<O>)
|
||||
{
|
||||
let (output, added) = stream();
|
||||
(
|
||||
Self {
|
||||
input_a,
|
||||
input_b,
|
||||
output,
|
||||
},
|
||||
added,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ia, Ib, O> Block for Adder<Ia, Ib, O>
|
||||
where
|
||||
Ia: Add<Ib, Output = O> + 'static,
|
||||
Ib: 'static,
|
||||
O: 'static,
|
||||
{
|
||||
fn work(&mut self) -> BlockResult
|
||||
{
|
||||
self.output.push_iter(
|
||||
(&mut self.input_a, &mut self.input_b)
|
||||
.pop_iter()
|
||||
.map(|(a, b)| a + b),
|
||||
);
|
||||
BlockResult::Ok
|
||||
}
|
||||
}
|
||||
1
oxydsp-dsp/src/blocks/utilities.rs
Normal file
1
oxydsp-dsp/src/blocks/utilities.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod iter;
|
||||
46
oxydsp-dsp/src/blocks/utilities/iter.rs
Normal file
46
oxydsp-dsp/src/blocks/utilities/iter.rs
Normal file
@ -0,0 +1,46 @@
|
||||
use oxydsp_flowgraph::{
|
||||
BlockIO,
|
||||
block::{Block, BlockResult},
|
||||
edge::{In, Out, stream},
|
||||
};
|
||||
|
||||
#[derive(BlockIO)]
|
||||
pub struct IterSource<I: Iterator>
|
||||
where
|
||||
I::Item: 'static,
|
||||
{
|
||||
iter: I,
|
||||
|
||||
#[output]
|
||||
output: Out<I::Item>,
|
||||
}
|
||||
|
||||
impl<I> IterSource<I>
|
||||
where
|
||||
I: Iterator,
|
||||
I::Item: 'static,
|
||||
{
|
||||
pub fn new(iter: I) -> (Self, In<I::Item>)
|
||||
{
|
||||
let (output, items) = stream();
|
||||
(Self { iter, output }, items)
|
||||
}
|
||||
}
|
||||
|
||||
impl<I> Block for IterSource<I>
|
||||
where
|
||||
I: Iterator,
|
||||
I::Item: 'static,
|
||||
{
|
||||
fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
|
||||
{
|
||||
if self.output.push_iter(&mut self.iter)
|
||||
{
|
||||
BlockResult::Ok
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockResult::Terminated
|
||||
}
|
||||
}
|
||||
}
|
||||
1
oxydsp-dsp/src/lib.rs
Normal file
1
oxydsp-dsp/src/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod blocks;
|
||||
1
oxydsp-dsp/src/main.rs
Normal file
1
oxydsp-dsp/src/main.rs
Normal file
@ -0,0 +1 @@
|
||||
fn main() {}
|
||||
Reference in New Issue
Block a user