From eb15ac766b68cbb5fb563d6e1c73e4a58b2b80fb Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 9 Nov 2015 22:05:54 +0100 Subject: [PATCH] Add some GUI elements (hooked up) to help tuning the compressor. --- mainwindow.cpp | 28 ++++++++++ mainwindow.h | 2 + mixer.cpp | 8 +-- mixer.h | 26 +++++++++ ui_mainwindow.ui | 138 ++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 190 insertions(+), 12 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 854eb08..a19a456 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -93,6 +93,14 @@ void MainWindow::mixer_created(Mixer *mixer) } connect(ui->locut_cutoff_knob, &QDial::valueChanged, this, &MainWindow::cutoff_knob_changed); + connect(ui->limiter_threshold_knob, &QDial::valueChanged, this, &MainWindow::limiter_threshold_knob_changed); + connect(ui->compressor_threshold_knob, &QDial::valueChanged, this, &MainWindow::compressor_threshold_knob_changed); + connect(ui->limiter_enabled, &QCheckBox::stateChanged, [this](int state){ + global_mixer->set_limiter_enabled(state == Qt::Checked); + }); + connect(ui->compressor_enabled, &QCheckBox::stateChanged, [this](int state){ + global_mixer->set_compressor_enabled(state == Qt::Checked); + }); connect(ui->reset_meters_button, &QPushButton::clicked, this, &MainWindow::reset_meters_button_clicked); mixer->set_audio_level_callback(bind(&MainWindow::audio_level_callback, this, _1, _2, _3, _4, _5, _6)); } @@ -108,6 +116,26 @@ void MainWindow::cutoff_knob_changed(int value) ui->locut_cutoff_display->setText(buf); } +void MainWindow::limiter_threshold_knob_changed(int value) +{ + float threshold_dbfs = value * 0.1f; + global_mixer->set_limiter_threshold_dbfs(threshold_dbfs); + + char buf[256]; + snprintf(buf, sizeof(buf), "%.1f dB", threshold_dbfs); + ui->limiter_threshold_db_display->setText(buf); +} + +void MainWindow::compressor_threshold_knob_changed(int value) +{ + float threshold_dbfs = value * 0.1f; + global_mixer->set_compressor_threshold_dbfs(threshold_dbfs); + + char buf[256]; + snprintf(buf, sizeof(buf), "%.1f dB", threshold_dbfs); + ui->compressor_threshold_db_display->setText(buf); +} + void MainWindow::reset_meters_button_clicked() { global_mixer->reset_meters(); diff --git a/mainwindow.h b/mainwindow.h index 6b41b0a..b88324a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -31,6 +31,8 @@ public slots: void wb_button_clicked(int channel_number); void set_transition_names(std::vector transition_names); void cutoff_knob_changed(int value); + void limiter_threshold_knob_changed(int value); + void compressor_threshold_knob_changed(int value); void reset_meters_button_clicked(); void relayout(); diff --git a/mixer.cpp b/mixer.cpp index bc349be..861ea94 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -581,8 +581,8 @@ void Mixer::process_audio_one_frame() // Then a limiter at +0 dB (so, -14 dBFS) to take out the worst peaks only. // Note that since ratio is not infinite, we could go slightly higher than this. // Probably more tuning is warranted here. - { - float threshold = pow(10.0f, (ref_level_dbfs + 0.0f) / 20.0f); // +0 dB. + if (limiter_enabled) { + float threshold = pow(10.0f, limiter_threshold_dbfs / 20.0f); float ratio = 30.0f; float attack_time = 0.0f; // Instant. float release_time = 0.005f; @@ -592,8 +592,8 @@ void Mixer::process_audio_one_frame() } // Finally, the real compressor. - { - float threshold = pow(10.0f, (ref_level_dbfs - 12.0f) / 20.0f); // -12 dB. + if (compressor_enabled) { + float threshold = pow(10.0f, compressor_threshold_dbfs / 20.0f); float ratio = 20.0f; float attack_time = 0.005f; float release_time = 0.040f; diff --git a/mixer.h b/mixer.h index 0fd07ae..01712b8 100644 --- a/mixer.h +++ b/mixer.h @@ -137,6 +137,26 @@ public: locut_cutoff_hz = cutoff_hz; } + void set_limiter_threshold_dbfs(float threshold_dbfs) + { + limiter_threshold_dbfs = threshold_dbfs; + } + + void set_compressor_threshold_dbfs(float threshold_dbfs) + { + compressor_threshold_dbfs = threshold_dbfs; + } + + void set_limiter_enabled(bool enabled) + { + limiter_enabled = enabled; + } + + void set_compressor_enabled(bool enabled) + { + compressor_enabled = enabled; + } + void reset_meters(); private: @@ -224,8 +244,14 @@ private: StereoCompressor level_compressor; float last_gain_staging_db = 0.0f; + static constexpr float ref_level_dbfs = -14.0f; + StereoCompressor limiter; + std::atomic limiter_threshold_dbfs{ref_level_dbfs + 0.0f}; // 0 dB. + std::atomic limiter_enabled{true}; StereoCompressor compressor; + std::atomic compressor_threshold_dbfs{ref_level_dbfs - 12.0f}; // -12 dB. + std::atomic compressor_enabled{true}; }; extern Mixer *global_mixer; diff --git a/ui_mainwindow.ui b/ui_mainwindow.ui index 81b9b1a..be10d9b 100644 --- a/ui_mainwindow.ui +++ b/ui_mainwindow.ui @@ -395,7 +395,7 @@ - 65536 + 16777215 64 @@ -433,7 +433,7 @@ - + Qt::Horizontal @@ -451,6 +451,9 @@ Auto + + true + @@ -469,7 +472,7 @@ - 65536 + 16777215 64 @@ -481,8 +484,15 @@ + + + + + + + - + Lo-cut (24dB/oct) @@ -498,10 +508,122 @@ - - - - + + + + Enabled + + + true + + + + + + + + 64 + 64 + + + + + 16777215 + 64 + + + + -400 + + + 0 + + + -140 + + + 30.000000000000000 + + + true + + + + + + + Limiter threshold + + + Qt::AlignCenter + + + + + + + -14.0 dB + + + Qt::AlignCenter + + + + + + + + 64 + 64 + + + + + 16777215 + 64 + + + + -400 + + + 0 + + + -260 + + + 30.000000000000000 + + + true + + + + + + + Compr. threshold + + + + + + + -26.0 dB + + + Qt::AlignCenter + + + + + + + Enabled + + + true -- 2.39.2