summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorWavy Harp <wavyharp@gmail.com>2023-05-07 23:04:53 -0600
committerKyle McFarland <tfkyle@gmail.com>2023-05-07 23:04:53 -0600
commit991849b32acf83dd14a5096540bb053d2572502a (patch)
tree279b59d75d4ad6081f5242cf77d843ae6b37fc3d /src/bin
downloadrustynotes-991849b32acf83dd14a5096540bb053d2572502a.zip
rustynotes-991849b32acf83dd14a5096540bb053d2572502a.tar.gz
rustynotes-991849b32acf83dd14a5096540bb053d2572502a.tar.bz2
initial importHEADmaster
currently everything is very tied to alsa and my system, for the moment you'll need to manually change the device names and maybe channels/period_size in src/main.rs, src/bin/smolguitar.rs and src/bin/loopbacker.rs, i'll fix that and add runtime period size/updater allocation soon, (and probably make a cpal backend as well so it can work on other platforms), but doing this initial commit to play around with stereo for now~
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/loopbacker.rs48
-rw-r--r--src/bin/smolguitar.rs44
-rw-r--r--src/bin/test_serde.rs22
-rw-r--r--src/bin/testrfft.rs20
4 files changed, 134 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();
+}
diff --git a/src/bin/smolguitar.rs b/src/bin/smolguitar.rs
new file mode 100644
index 0000000..bb36b64
--- /dev/null
+++ b/src/bin/smolguitar.rs
@@ -0,0 +1,44 @@
+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, LineLayout};
+use rustynotes::args::SimpleArgs;
+use clap::Parser;
+
+fn main() {
+ const CHANNELS: u32 = 1;
+ const PERIOD_SIZE: usize = 480;
+ const PROC_SIZE: usize = 1 << 13; // 8k
+ //let disp_threshold = 0.00372314453125;
+ //let disp_threshold = 0.00526532149076897;
+ //let disp_threshold = 0.05;
+ let sample_rate = 48000;
+ let notes = note_range((Notes::C, 2), (Notes::E, 7));
+ let rfproc: RFftProcer<f32, PERIOD_SIZE, PROC_SIZE> = RFftProcer::new(sample_rate);
+ let pnotes = rfproc.make_pnotes(&notes);
+ for pnote in &pnotes {
+ println!("{}", pnote);
+ }
+ println!("{}", rfproc);
+ //let outputer = Outputers::Simple(SimpleOutputer);
+ //(2f32).sqrt()
+ //let outputer = Outputers::LineLayout(LineLayout::new(0.25, true, (60., 255., 220.), &notes));
+ let args = SimpleArgs::parse();
+ let disp_threshold = args.threshold;
+ let outputer = args.get_outputer(&notes);
+ let rfpdata = ProcerData::new(&rfproc, ProcerNotes(pnotes, disp_threshold));
+ let mut buf: StaticBuffer<f32, PERIOD_SIZE, PROC_SIZE> = StaticBuffer::new(48000, CHANNELS,
+ vec![(Procers::Rfft(rfproc), rfpdata)], "guitar_c".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();
+}
diff --git a/src/bin/test_serde.rs b/src/bin/test_serde.rs
new file mode 100644
index 0000000..02b42e4
--- /dev/null
+++ b/src/bin/test_serde.rs
@@ -0,0 +1,22 @@
+use crossterm::style::Color;
+use serde::{Serialize, Deserialize};
+use serde_json::{to_string_pretty, from_str};
+
+#[derive(Serialize, Deserialize, Debug)]
+struct cscheme {
+ a: Color,
+ asharp: Color,
+ b: Color,
+}
+
+fn main() {
+ let val = Color::Rgb {r: 110, g: 255, b: 220};
+ let val2 = Color::AnsiValue(51);
+ let val3 = Color::DarkMagenta;
+ let scheme = cscheme {a: val, asharp: val2, b: val3};
+ let json = to_string_pretty(&scheme).unwrap();
+ println!("{}", json);
+ let result: cscheme = from_str(&json).unwrap();
+ println!("{:?}", result);
+ //println!("{} {}", to_string_pretty
+}
diff --git a/src/bin/testrfft.rs b/src/bin/testrfft.rs
new file mode 100644
index 0000000..ee8c72f
--- /dev/null
+++ b/src/bin/testrfft.rs
@@ -0,0 +1,20 @@
+use realfft::{RealFftPlanner, FftNum, RealToComplex};
+
+fn main() {
+ let mut planner: RealFftPlanner<f32> = RealFftPlanner::new();
+ //let rfft = planner.plan_fft_forward(4);
+ let rfft = planner.plan_fft_forward(40);
+ let mut scratch = rfft.make_scratch_vec();
+ let mut out_data = rfft.make_output_vec();
+ //let mut in_data = [1., 0.4, 0.3, -1.];
+ let mut in_data = [1.; 40];
+ //let mut in_data = [
+ rfft.process_with_scratch(&mut in_data, &mut out_data, &mut scratch).unwrap();
+ println!("{:?}", &out_data);
+ let scale = 1./40.;
+ for elem in out_data {
+ println!("{}", elem.norm_sqr().sqrt() * scale);
+ println!("{}", elem.l1_norm() * scale);
+ //println!("{}", elem * scale);
+ }
+}