fix: bug where visualizer remained displaying audio after audio finished
This commit is contained in:
+16
-2
@@ -248,14 +248,28 @@ impl AudioVisualizer {
|
|||||||
thread::sleep(std::time::Duration::from_millis(16));
|
thread::sleep(std::time::Duration::from_millis(16));
|
||||||
|
|
||||||
let samples = {
|
let samples = {
|
||||||
let buf = match audio_buffer.lock() {
|
let mut buf = match audio_buffer.lock() {
|
||||||
Ok(b) => b,
|
Ok(b) => b,
|
||||||
Err(_) => continue,
|
Err(_) => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// decay heights smoothly
|
||||||
if buf.len() < chunk_size {
|
if buf.len() < chunk_size {
|
||||||
|
for val in prev_heights.iter_mut() {
|
||||||
|
*val = (*val - falloff).max(0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(mut bars) = bar_data.lock() {
|
||||||
|
for (i, val) in prev_heights.iter().enumerate() {
|
||||||
|
bars[i] = ((*val * 10.0).clamp(0.0, 100.0)) as u64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
buf[buf.len() - chunk_size..].to_vec()
|
|
||||||
|
// drain the consumed samples
|
||||||
|
buf.drain(0..chunk_size).collect::<Vec<f32>>()
|
||||||
};
|
};
|
||||||
|
|
||||||
Self::apply_hann_window(&samples, &mut windowed_buffer);
|
Self::apply_hann_window(&samples, &mut windowed_buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user