Kinda working sync block system

This commit is contained in:
2026-03-19 22:44:29 +01:00
parent 6e2283755a
commit 822cdc1587

View File

@ -1,14 +1,13 @@
use std::collections::VecDeque;
use std::fmt::Display;
use std::fs::File;
use std::io::Write;
use std::sync::mpmc::sync_channel;
use std::sync::mpsc;
use eframe::NativeOptions;
use egui_plot::Line;
use egui_plot::PlotPoints;
use num::Complex;
use oxydsp_dsp::blocks::math::basic::Adder;
use oxydsp_dsp::blocks::math::basic::Multiplier;
use oxydsp_dsp::blocks::synthesis::Nco;
use oxydsp_dsp::blocks::synthesis::OscillatorSource;
@ -33,48 +32,26 @@ use crate::printer_synchronous_block::PrinterView;
#[derive(BlockIO)]
#[sync_block]
pub struct Printer<T: 'static>
pub struct Printer<T: 'static + Display>
{
#[input]
input: In<T>,
#[input]
input_b: In<u32>,
#[output]
output_a: Out<u32>,
n: usize,
}
impl<'view, T> SyncBlock<'view> for Printer<T>
impl<'view, T: 'static + Display> SyncBlock<'view> for Printer<T>
{
fn sync_work(state: Self::StateView, input: Self::Input) -> Option<Self::Output>
{
None
}
}
*state.n += 1;
impl<T: 'static> Block for Printer<T>
{
fn work(&mut self) -> BlockResult
{
let state = PrinterView {
n: &mut self.n,
_sync_block_phantom: Default::default(),
};
if state.n.is_multiple_of(1_000_000)
{
println!("{}", input);
}
let output_a_write = self.output_a.write();
(&mut self.input, &mut self.input_b).pop_iter().for_each(
|((input_el, input_tag), (input_b_el, input_b_tag))| {
let new_tag = Tag::from([input_tag, input_b_tag]);
let output_a_el = <Self as SyncBlock>::sync_work(state, (input_el, input_b_el));
output_a_write.push((output_a_el, new_tag));
},
);
todo!()
Some(())
}
}
@ -93,7 +70,7 @@ impl<T: 'static> Block for Printer<T>
// }
// }
impl<T: 'static> Printer<T>
impl<T: 'static + Display> Printer<T>
{
pub fn new(input: In<T>) -> Self
{
@ -101,26 +78,18 @@ impl<T: 'static> Printer<T>
}
}
impl<T: 'static> Block for Printer<T>
where
T: Display,
fn main()
{
fn work(&mut self) -> oxydsp_flowgraph::block::BlockResult
{
for x in self.input.pop_iter()
{
if self.n.is_multiple_of(2usize.pow(20))
{
println!("{}", x);
self.n = 0;
}
self.n += 1;
}
BlockResult::Ok
}
let (iter_source_a, a) = IterSource::new(0..);
let (iter_source_b, b) = IterSource::new(0..);
let (adder, a) = Adder::new(a, b);
let printer = Printer::new(a);
let fg = flowgraph![iter_source_a, iter_source_b, adder, printer];
let _ = fg.run().join();
}
fn main()
fn main_fsk()
{
let sample_rate = 48_000;
let sample_per_symbol = 96;