From c62c23eff1ba994d5c10b9255f467704de4da148 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 11 Nov 2015 20:00:29 +0100 Subject: [PATCH] Rate-limit VU and LRA meter updates. --- mainwindow.cpp | 12 ++++++++++++ mainwindow.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/mainwindow.cpp b/mainwindow.cpp index de0b4da..34db733 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -151,6 +151,18 @@ void MainWindow::reset_meters_button_clicked() void MainWindow::audio_level_callback(float level_lufs, float peak_db, float global_level_lufs, float range_low_lufs, float range_high_lufs, float auto_gain_staging_db) { + timeval now; + gettimeofday(&now, nullptr); + + // The meters are somewhat inefficient to update. Only update them + // every 100 ms or so (we get updates every 5–20 ms). + double last_update_age = now.tv_sec - last_audio_level_callback.tv_sec + + 1e-6 * (now.tv_usec - last_audio_level_callback.tv_usec); + if (last_update_age < 0.100) { + return; + } + last_audio_level_callback = now; + post_to_main_thread([=]() { ui->vu_meter->set_level(level_lufs); ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs); diff --git a/mainwindow.h b/mainwindow.h index b88324a..4c4c3f0 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -4,6 +4,7 @@ #include #include #include +#include class GLWidget; class QResizeEvent; @@ -42,6 +43,7 @@ private: // Called from the mixer. void audio_level_callback(float level_lufs, float peak_db, float global_level_lufs, float range_low_lufs, float range_high_lufs, float auto_gain_staging_db); + timeval last_audio_level_callback{0, 0}; Ui::MainWindow *ui; QPushButton *transition_btn1, *transition_btn2, *transition_btn3; -- 2.39.2