diff --git a/example/src/main.rs b/example/src/main.rs index 377dbdf..d70505e 100644 --- a/example/src/main.rs +++ b/example/src/main.rs @@ -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 +pub struct Printer { #[input] input: In, - #[input] - input_b: In, - - #[output] - output_a: Out, - n: usize, } -impl<'view, T> SyncBlock<'view> for Printer +impl<'view, T: 'static + Display> SyncBlock<'view> for Printer { fn sync_work(state: Self::StateView, input: Self::Input) -> Option { - None - } -} + *state.n += 1; -impl Block for Printer -{ - 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 = ::sync_work(state, (input_el, input_b_el)); - - output_a_write.push((output_a_el, new_tag)); - }, - ); - - todo!() + Some(()) } } @@ -93,7 +70,7 @@ impl Block for Printer // } // } -impl Printer +impl Printer { pub fn new(input: In) -> Self { @@ -101,26 +78,18 @@ impl Printer } } -impl Block for Printer -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;