]> git.sesse.net Git - nageru/commitdiff
Display auto-gain-staging in the UI.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 8 Nov 2015 15:32:51 +0000 (16:32 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 8 Nov 2015 15:32:51 +0000 (16:32 +0100)
mainwindow.cpp
mixer.cpp
mixer.h

index 0e96a8a4cdd95c57dd2ac0e037559fc5455a2d00..01baef5c903d2461a8960328a379368cfc332161 100644 (file)
@@ -90,7 +90,7 @@ void MainWindow::mixer_created(Mixer *mixer)
                connect(ui_display->wb_button, &QPushButton::clicked, std::bind(&MainWindow::wb_button_clicked, this, i));
        }
 
-       mixer->set_audio_level_callback([this](float level_lufs, float peak_db, float global_level_lufs, float range_low_lufs, float range_high_lufs){
+       mixer->set_audio_level_callback([this](float level_lufs, float peak_db, float global_level_lufs, float range_low_lufs, float range_high_lufs, float auto_gain_staging_db){
                ui->vu_meter->set_level(level_lufs);
                ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs);
 
@@ -102,6 +102,10 @@ void MainWindow::mixer_created(Mixer *mixer)
                } else {
                        ui->peak_display->setStyleSheet("");
                }
+
+               ui->gainstaging_knob->setValue(lrintf(auto_gain_staging_db * 10.0f));
+               snprintf(buf, sizeof(buf), "%+.1f dB", auto_gain_staging_db);
+               ui->gainstaging_db_display->setText(buf);
        });
 }
 
index 03cf99d3435969891ccc1961d7f71c1b479861a5..7584751b9725c15b4b3a7202d39ea403d343c7a4 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -384,7 +384,8 @@ void Mixer::thread_func()
                        double loudness_range_high = r128.range_max();
 
                        audio_level_callback(loudness_s, 20.0 * log10(peak),
-                                            loudness_i, loudness_range_low, loudness_range_high);
+                                            loudness_i, loudness_range_low, loudness_range_high,
+                                            last_gain_staging_db);
                }
 
                for (unsigned card_index = 1; card_index < num_cards; ++card_index) {
@@ -564,12 +565,13 @@ void Mixer::process_audio_one_frame()
        float release_time = 10.0f;
        float makeup_gain = pow(10.0f, 28.0f / 20.0f);  // +28 dB takes us to -12 dBFS.
        level_compressor.process(samples_out.data(), samples_out.size() / 2, threshold, ratio, attack_time, release_time, makeup_gain);
+       last_gain_staging_db = 20.0 * log10(level_compressor.get_attenuation() * makeup_gain);
 
 #if 0
        printf("level=%f (%+5.2f dBFS) attenuation=%f (%+5.2f dB) end_result=%+5.2f dB\n",
-               compressor.get_level(), 20.0 * log10(compressor.get_level()),
-               compressor.get_attenuation(), 20.0 * log10(compressor.get_attenuation()),
-               20.0 * log10(compressor.get_level() * compressor.get_attenuation() * makeup_gain));
+               level_compressor.get_level(), 20.0 * log10(level_compressor.get_level()),
+               level_compressor.get_attenuation(), 20.0 * log10(level_compressor.get_attenuation()),
+               20.0 * log10(level_compressor.get_level() * level_compressor.get_attenuation() * makeup_gain));
 #endif
 
        // Find peak and R128 levels.
diff --git a/mixer.h b/mixer.h
index 3e5aa68cf2c8c6e31065647436e2eec0f7faaf3c..312566d891e0371eac7ebf765299480fec074f42 100644 (file)
--- a/mixer.h
+++ b/mixer.h
@@ -97,7 +97,9 @@ public:
                output_channel[output].set_frame_ready_callback(callback);
        }
 
-       typedef std::function<void(float level_lufs, float peak_db, float global_level_lufs, float range_low_lufs, float range_high_lufs)> audio_level_callback_t;
+       typedef std::function<void(float level_lufs, float peak_db,
+                                  float global_level_lufs, float range_low_lufs, float range_high_lufs,
+                                  float auto_gain_staging_db)> audio_level_callback_t;
        void set_audio_level_callback(audio_level_callback_t callback)
        {
                audio_level_callback = callback;
@@ -210,6 +212,7 @@ private:
 
        // First compressor; takes us up to about -12 dBFS.
        StereoCompressor level_compressor;
+       float last_gain_staging_db = 0.0f;
 };
 
 extern Mixer *global_mixer;