Starting to support arrays and tuples for inout
This commit is contained in:
81
oxydsp-dsp/src/blocks/synthesis.rs
Normal file
81
oxydsp-dsp/src/blocks/synthesis.rs
Normal 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
|
||||
}
|
||||
}
|
||||
@ -1 +1,2 @@
|
||||
pub mod adapters;
|
||||
pub mod iter;
|
||||
|
||||
1
oxydsp-dsp/src/blocks/utilities/adapters.rs
Normal file
1
oxydsp-dsp/src/blocks/utilities/adapters.rs
Normal file
@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user