bugfixes
This commit is contained in:
parent
3d7f17723c
commit
08c76db5a2
1 changed files with 16 additions and 3 deletions
19
src/main.rs
19
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<S: SerialPort> Iterator for PortIter<S> {
|
|||
Ok(_) => (),
|
||||
};
|
||||
|
||||
let num = match buf.parse::<usize>() {
|
||||
let num = match buf.trim().parse::<usize>() {
|
||||
Err(e) => return Some(Result::Err(e.into())),
|
||||
Ok(num) => num,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue