This commit is contained in:
_ 2020-10-26 20:12:21 +01:00
parent 3d7f17723c
commit 08c76db5a2

View file

@ -64,7 +64,7 @@ fn main() {
let mut sink = rodio::Sink::try_new(&stream_handle).expect("could not create sink"); let mut sink = rodio::Sink::try_new(&stream_handle).expect("could not create sink");
println!("audio output opened"); println!("audio output opened");
#[derive(Clone, Copy)] #[derive(Clone, Copy, Debug)]
struct Hyst { struct Hyst {
max: usize, max: usize,
prechoice: usize, prechoice: usize,
@ -96,26 +96,37 @@ fn main() {
.unwrap() .unwrap()
.map(|e| e.unwrap()) .map(|e| e.unwrap())
.scan(hyst, |hyst, el| { .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); hyst.max = hyst.max.max(el);
let absdiff = el.max(hyst.prechoice_val) - el.min(hyst.prechoice_val); let absdiff = el.max(hyst.prechoice_val) - el.min(hyst.prechoice_val);
if absdiff > equality_range { if absdiff > equality_range {
// build stability if value has not changed since last time
if hyst.preval == el { if hyst.preval == el {
hyst.stability += 1; hyst.stability += 1;
} else { } else {
hyst.stability = 0; hyst.stability = 0;
} }
hyst.preval = el;
// once we are stable
if hyst.stability > stability_tresh { if hyst.stability > stability_tresh {
let choice = (el * (musiclen - 1)) / hyst.max; let choice = (el * (musiclen - 1)) / hyst.max;
// make sure the choice actually changed
if choice != hyst.prechoice { if choice != hyst.prechoice {
hyst.prechoice = choice; hyst.prechoice = choice;
hyst.stability = 0; hyst.stability = 0;
hyst.preval = el; hyst.prechoice_val = el;
println!("pushing choice {}", choice);
return Some(Some((el, hyst.max))); return Some(Some((el, hyst.max)));
} }
} }
} }
Some(None) Some(None)
}); });
// next: turn de-noised into a decoder // next: turn de-noised into a decoder
let iter = iter let iter = iter
// skip thing the denoiser denoised // skip thing the denoiser denoised
@ -140,6 +151,7 @@ fn main() {
delta = (-delta) + 1; delta = (-delta) + 1;
c c
}; };
println!("trying {} next delta {}", modchoice, delta);
if let Some(Some(c)) = music.get(modchoice) { if let Some(Some(c)) = music.get(modchoice) {
choicef = c; choicef = c;
choice = modchoice; choice = modchoice;
@ -155,6 +167,7 @@ fn main() {
match (c)() { match (c)() {
Ok(d) => { Ok(d) => {
decoder = d; decoder = d;
println!("playing {:?}", choicef);
break; break;
} }
Err(()) => { Err(()) => {
@ -216,7 +229,7 @@ impl<S: SerialPort> Iterator for PortIter<S> {
Ok(_) => (), Ok(_) => (),
}; };
let num = match buf.parse::<usize>() { let num = match buf.trim().parse::<usize>() {
Err(e) => return Some(Result::Err(e.into())), Err(e) => return Some(Result::Err(e.into())),
Ok(num) => num, Ok(num) => num,
}; };