From 8ac215ff79cd1233c01de3b33f20d1d40854c62b Mon Sep 17 00:00:00 2001 From: Dave Patrick Caberto Date: Sat, 25 Nov 2023 19:28:29 +0800 Subject: [PATCH] fix: use max of channels --- src/win.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/win.rs b/src/win.rs index 3ec4a720..7a96a4af 100644 --- a/src/win.rs +++ b/src/win.rs @@ -379,15 +379,12 @@ fn handle_level_message(message: &gst::Message, callback: impl Fn(f64)) -> glib: gst::MessageView::Element(e) => { if let Some(structure) = e.structure() { if structure.has_name("level") { - let peak = structure - .get::<&glib::ValueArray>("peak") - .unwrap() - .first() - .unwrap() - .get::() - .unwrap(); - let normalized_peak = 10_f64.powf(peak / 20.0); - callback(normalized_peak); + let peaks = structure.get::<&glib::ValueArray>("rms").unwrap(); + let left_peak = peaks.nth(0).unwrap().get::().unwrap(); + let right_peak = peaks.nth(1).unwrap().get::().unwrap(); + let max_peak = left_peak.max(right_peak); + let normalized_max_peak = 10_f64.powf(max_peak / 20.0); + callback(normalized_max_peak); } }