diff options
author | Wavy Harp <wavyharp@gmail.com> | 2023-05-07 23:04:53 -0600 |
---|---|---|
committer | Kyle McFarland <tfkyle@gmail.com> | 2023-05-07 23:04:53 -0600 |
commit | 991849b32acf83dd14a5096540bb053d2572502a (patch) | |
tree | 279b59d75d4ad6081f5242cf77d843ae6b37fc3d /src/main.rs | |
download | rustynotes-991849b32acf83dd14a5096540bb053d2572502a.zip rustynotes-991849b32acf83dd14a5096540bb053d2572502a.tar.gz rustynotes-991849b32acf83dd14a5096540bb053d2572502a.tar.bz2 |
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/main.rs')
-rw-r--r-- | src/main.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..022b6ce --- /dev/null +++ b/src/main.rs @@ -0,0 +1,66 @@ +mod notes; +mod proc; +mod outputers; +mod buf; +mod rfft; +mod args; + +use crate::notes::{Notes, note_range, ProcerNotes}; +use crate::proc::{Procer, ProcerData}; +use crate::rfft::RFftProcer; +use crate::buf::{StaticBuffer, Procers}; +use crate::outputers::{Outputers, SimpleOutputer, LineLayout}; +use crate::args::SimpleArgs; +use clap::{Parser, CommandFactory, FromArgMatches}; + +//use std::collections::VecDeque; + +fn main() { + const CHANNELS: u32 = 2; + const PERIOD_SIZE: usize = 240; // 1024 frames + const PROC_SIZE: usize = 1 << 14; // 16k frames (so about .3413_ of a second) + //let disp_threshold = 0.00372314453125; + //let disp_threshold = 0.00526532149076897; + //let disp_threshold = 50. / (i16::MAX as f32); + //const PERIOD_SIZE: usize = 480; + //const PROC_SIZE: usize = 1 << 13; // 8k + //let period_size = 1024; + let sample_rate = 48000; + //let proc_size = 1 << 14; // 16k (so about .3413_ of a second) + // we update every period_size so it updates every 21.3_ms but we keep a running average of the + // last 341.3_ms so low frequencies can be interpreted with the fft (using fir or iir filters + // or wavelets or inner product spaces and frames is something to do in the future, but for now i'm just + // porting older python code over for performance that used ffts, and maybe messing with dct + // but it'll have the same limitations of ffts mostly probably) + let notes = note_range((Notes::C, 2), (Notes::E, 7)); + // US and prob BS here should be *2 when dealing with stereo, but going with mono rn + let rfproc: RFftProcer<f32, PERIOD_SIZE, PROC_SIZE> = RFftProcer::new(sample_rate); + let pnotes = rfproc.make_pnotes(¬es); + //println!("{:#?}", pnotes); + for pnote in &pnotes { + println!("{}", pnote); + } + println!("{}", rfproc); + let args = SimpleArgs::parse(); + println!("Args: {:?}", args); + // TODO: having an app-specific default threshold might be a good idea for smolguitar, + // not sure how to do that yet, maybe there's an API for changing the default of an arg in clap + let disp_threshold = args.threshold; + //let outputer = Outputers::Simple(SimpleOutputer); + //let outputer = Outputers::LineLayout(LineLayout::new(0.2, true, (0., 255., 220.), ¬es)); + let outputer = args.get_outputer(¬es); + 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)], "Microphone_c".to_string(), args.get_outdev(), + outputer); + println!("{}", buf); + let mut aout = alsa::Output::buffer_open().unwrap(); + buf.adev.dump(&mut aout); + match &buf.outdev { + Some(outdev) => { outdev.dump(&mut aout); }, + None => {}, + } + println!("{}", aout); + buf.capture_loop(); + //println!("{:#?}", pdata); +} |