From 08c76db5a2424c46042280c37da36d6dadc39552 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Mon, 26 Oct 2020 20:12:21 +0100 Subject: [PATCH] bugfixes --- src/main.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 19cbcdb..9ae8e1f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,7 +64,7 @@ fn main() { let mut sink = rodio::Sink::try_new(&stream_handle).expect("could not create sink"); println!("audio output opened"); - #[derive(Clone, Copy)] + #[derive(Clone, Copy, Debug)] struct Hyst { max: usize, prechoice: usize, @@ -96,26 +96,37 @@ fn main() { .unwrap() .map(|e| e.unwrap()) .scan(hyst, |hyst, el| { + // 8888 is empty screen, 69696969 is EEEE + if el == 8888 || el == 69_69_69_69 { + return Some(None) + } hyst.max = hyst.max.max(el); let absdiff = el.max(hyst.prechoice_val) - el.min(hyst.prechoice_val); if absdiff > equality_range { + // build stability if value has not changed since last time if hyst.preval == el { hyst.stability += 1; } else { hyst.stability = 0; } + hyst.preval = el; + + // once we are stable if hyst.stability > stability_tresh { let choice = (el * (musiclen - 1)) / hyst.max; + // make sure the choice actually changed if choice != hyst.prechoice { hyst.prechoice = choice; hyst.stability = 0; - hyst.preval = el; + hyst.prechoice_val = el; + println!("pushing choice {}", choice); return Some(Some((el, hyst.max))); } } } Some(None) }); + // next: turn de-noised into a decoder let iter = iter // skip thing the denoiser denoised @@ -140,6 +151,7 @@ fn main() { delta = (-delta) + 1; c }; + println!("trying {} next delta {}", modchoice, delta); if let Some(Some(c)) = music.get(modchoice) { choicef = c; choice = modchoice; @@ -155,6 +167,7 @@ fn main() { match (c)() { Ok(d) => { decoder = d; + println!("playing {:?}", choicef); break; } Err(()) => { @@ -216,7 +229,7 @@ impl Iterator for PortIter { Ok(_) => (), }; - let num = match buf.parse::() { + let num = match buf.trim().parse::() { Err(e) => return Some(Result::Err(e.into())), Ok(num) => num, };