Starting to support arrays and tuples for inout

This commit is contained in:
2026-03-15 22:13:47 +01:00
parent 866a5dd501
commit 10e4509e8c
13 changed files with 653 additions and 212 deletions

View File

@ -0,0 +1,81 @@
use crate::units::DigitalFrequency;
use num::Complex;
use num::Float;
use oxydsp_flowgraph::BlockIO;
use oxydsp_flowgraph::block::Block;
use oxydsp_flowgraph::block::BlockResult;
use oxydsp_flowgraph::edge::In;
use oxydsp_flowgraph::edge::Out;
use oxydsp_flowgraph::edge::PopIterable;
use oxydsp_flowgraph::edge::stream;
#[derive(BlockIO)]
pub struct OscillatorSource<T: Float + From<f32> + 'static>
{
nco: crate::synthesis::oscillator::Nco<T>,
#[output]
output: Out<Complex<T>>,
}
impl<T: Float + From<f32> + 'static> OscillatorSource<T>
{
pub fn new(nco: crate::synthesis::oscillator::Nco<T>) -> (Self, In<Complex<T>>)
{
let (output, signal) = stream();
(Self { nco, output }, signal)
}
}
impl<T: Float + From<f32> + 'static> Block for OscillatorSource<T>
{
fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
{
self.output.push_iter(&mut self.nco);
BlockResult::Ok
}
}
#[derive(BlockIO)]
pub struct Nco<T: Float + From<f32> + 'static>
{
nco: crate::synthesis::oscillator::Nco<T>,
#[input]
frequency: In<DigitalFrequency>,
#[output]
output: Out<Complex<T>>,
}
impl<T: Float + From<f32> + 'static> Nco<T>
{
pub fn new(
input: In<DigitalFrequency>,
nco: crate::synthesis::oscillator::Nco<T>,
) -> (Self, In<Complex<T>>)
{
let (output, signal) = stream();
(
Self {
nco,
frequency: input,
output,
},
signal,
)
}
}
impl<T: Float + From<f32> + 'static> Block for Nco<T>
{
fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
{
self.output
.push_iter(&mut self.frequency.pop_iter().map(|f| {
self.nco.set_frequency(f);
self.nco.next().unwrap()
}));
BlockResult::Ok
}
}

View File

@ -1 +1,2 @@
pub mod adapters;
pub mod iter;

View File

@ -0,0 +1 @@