summaryrefslogtreecommitdiff
path: root/src/bin/loopbacker.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/loopbacker.rs')
-rw-r--r--src/bin/loopbacker.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/bin/loopbacker.rs b/src/bin/loopbacker.rs
new file mode 100644
index 0000000..ec3d136
--- /dev/null
+++ b/src/bin/loopbacker.rs
@@ -0,0 +1,48 @@
+use rustynotes::notes::{Notes, note_range, ProcerNotes};
+use rustynotes::proc::{Procer, ProcerData};
+use rustynotes::rfft::RFftProcer;
+use rustynotes::buf::{StaticBuffer, Procers};
+use rustynotes::outputers::{Outputers, SimpleOutputer};
+use rustynotes::args::SimpleArgs;
+use clap::{Parser, CommandFactory, FromArgMatches};
+
+fn main() {
+ const CHANNELS: u32 = 2;
+ const PERIOD_SIZE: usize = 800;
+ const PROC_SIZE: usize = 5600; //1 << 13; // 8k, 16k, 32k
+ //let disp_threshold: f32 = 0.07;
+ //let disp_t_str = "0.07";
+ let disp_t_str = "0.00526532149076897";
+ let sample_rate = 48000;
+ let notes = note_range((Notes::C, 2), (Notes::B, 10));
+ let rfproc: RFftProcer<f32, PERIOD_SIZE, PROC_SIZE> = RFftProcer::new(sample_rate);
+ let pnotes = rfproc.make_pnotes(&notes);
+ println!("notes len: {}, pnotes len: {}", notes.len(), pnotes.len());
+ for pnote in &pnotes {
+ println!("{}", pnote);
+ }
+ println!("{}", rfproc);
+
+ let mut cmd = SimpleArgs::command();
+ cmd = cmd.mut_arg("threshold", |ta| ta.default_value(disp_t_str));
+ let mut matches = cmd.get_matches();
+ let args = SimpleArgs::from_arg_matches_mut(&mut matches).unwrap();
+ let disp_threshold = args.threshold;
+ println!("Args: {:?}", args);
+
+ let rfpdata = ProcerData::new(&rfproc, ProcerNotes(pnotes, disp_threshold));
+ let outputer = args.get_outputer(&notes);
+ let mut buf: StaticBuffer<f32, PERIOD_SIZE, PROC_SIZE> = StaticBuffer::new(48000, CHANNELS,
+ vec![(Procers::Rfft(rfproc), rfpdata)], "mpd_c_snoop".to_string(), args.get_outdev(),
+ outputer);
+ println!("{}", buf);
+ let mut aout = alsa::Output::buffer_open().unwrap();
+ buf.adev.dump(&mut aout);
+ //buf.outdev.dump(&mut aout);
+ match &buf.outdev {
+ Some(outdev) => { outdev.dump(&mut aout); },
+ None => {},
+ }
+ println!("{}", aout);
+ buf.capture_loop();
+}