]> git.sesse.net Git - nageru/commitdiff
Rate-limit VU and LRA meter updates.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 11 Nov 2015 19:00:29 +0000 (20:00 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 11 Nov 2015 19:00:29 +0000 (20:00 +0100)
mainwindow.cpp
mainwindow.h

index de0b4da2ef507103da245fae47285a1daec44538..34db733bababc8b0e4f63b1233432fe2aab377e6 100644 (file)
@@ -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);
index b88324aa0961a8380fa9423f779e843f2cdba7f9..4c4c3f0a2c7290c7b8e1c12ef37720d685985398 100644 (file)
@@ -4,6 +4,7 @@
 #include <QMainWindow>
 #include <string>
 #include <vector>
+#include <sys/time.h>
 
 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;