summaryrefslogtreecommitdiff
path: root/src/bin/smolguitar.rs
blob: bb36b648e17f529699f6387afa5307a26cd61962 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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();
}