|
|
@ -12,35 +12,10 @@ use tui::{ |
|
|
|
|
|
|
|
use wizja::{
|
|
|
|
event::{Event, Events},
|
|
|
|
fourier::Fourier,
|
|
|
|
pulse::PARecorder,
|
|
|
|
window::Window,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct Window<'a> {
|
|
|
|
spectrum: Vec<(&'a str, u64)>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Window<'a> {
|
|
|
|
fn new() -> Window<'a> {
|
|
|
|
Window {
|
|
|
|
spectrum: vec![("", 0); 12],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn update(&mut self, rec: &mut PARecorder) -> Result<()> {
|
|
|
|
rec.update()?;
|
|
|
|
|
|
|
|
self.spectrum = Fourier::new(&rec.buf)
|
|
|
|
.normalize()
|
|
|
|
.phase_shift()
|
|
|
|
.cutoff_filter()
|
|
|
|
.analyze(12);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
let stdout = io::stdout().into_raw_mode()?;
|
|
|
|
let stdout = MouseTerminal::from(stdout);
|
|
|
@ -50,9 +25,9 @@ fn main() -> Result<()> { |
|
|
|
terminal.hide_cursor()?;
|
|
|
|
|
|
|
|
let events = Events::new();
|
|
|
|
let mut win = Window::new();
|
|
|
|
let mut win = Window::new(24);
|
|
|
|
|
|
|
|
let mut rec = PARecorder::new(256)?;
|
|
|
|
let mut rec = PARecorder::new(1024)?;
|
|
|
|
|
|
|
|
loop {
|
|
|
|
terminal.draw(|mut f| {
|
|
|
@ -65,7 +40,7 @@ fn main() -> Result<()> { |
|
|
|
.block(Block::default().title("wizja 0.1.0").borders(Borders::ALL))
|
|
|
|
.data(&win.spectrum)
|
|
|
|
.bar_width(4)
|
|
|
|
.max(100)
|
|
|
|
.max(500)
|
|
|
|
.style(Style::default().fg(Color::Blue))
|
|
|
|
.value_style(Style::default().fg(Color::Black).bg(Color::Blue));
|
|
|
|
f.render_widget(barchart, chunks[0]);
|
|
|
|