]> git.sesse.net Git - nageru/commitdiff
Add some GUI elements (hooked up) to help tuning the compressor.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 9 Nov 2015 21:05:54 +0000 (22:05 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 9 Nov 2015 21:05:54 +0000 (22:05 +0100)
mainwindow.cpp
mainwindow.h
mixer.cpp
mixer.h
ui_mainwindow.ui

index 854eb08663176a4a1e1a1fcf627e48d30c2edf98..a19a4560ab1c69b5bae9f42d871d16fff511d47f 100644 (file)
@@ -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();
index 6b41b0aceb987a4f9b7ff24299eacff36de3a9e0..b88324aa0961a8380fa9423f779e843f2cdba7f9 100644 (file)
@@ -31,6 +31,8 @@ public slots:
        void wb_button_clicked(int channel_number);
        void set_transition_names(std::vector<std::string> 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();
 
index bc349bef275304a57533281667cc5a892b80feee..861ea94d221bae78c93c06ec41f203aa30cd0905 100644 (file)
--- 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 0fd07aea05598f82ee0c1a3e2a46aeda821741f0..01712b8f136a0b116cc27c3d603b2c3b2613e348 100644 (file)
--- 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<float> limiter_threshold_dbfs{ref_level_dbfs + 0.0f};   // 0 dB.
+       std::atomic<bool> limiter_enabled{true};
        StereoCompressor compressor;
+       std::atomic<float> compressor_threshold_dbfs{ref_level_dbfs - 12.0f};  // -12 dB.
+       std::atomic<bool> compressor_enabled{true};
 };
 
 extern Mixer *global_mixer;
index 81b9b1a4aa47736b9ca6a24f819246f3d172b131..be10d9bf6d9a17b854f63db9dab45f0d9e32b3db 100644 (file)
           </property>
           <property name="maximumSize">
            <size>
-            <width>65536</width>
+            <width>16777215</width>
             <height>64</height>
            </size>
           </property>
           </property>
          </widget>
         </item>
-        <item row="1" column="2">
+        <item row="1" column="4">
          <spacer name="horizontalSpacer_2">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
           <property name="text">
            <string>Auto</string>
           </property>
+          <property name="checked">
+           <bool>true</bool>
+          </property>
          </widget>
         </item>
         <item row="1" column="0">
           </property>
           <property name="maximumSize">
            <size>
-            <width>65536</width>
+            <width>16777215</width>
             <height>64</height>
            </size>
           </property>
           </property>
          </widget>
         </item>
+        <item row="3" column="0">
+         <widget class="QComboBox" name="comboBox">
+          <property name="currentText">
+           <string/>
+          </property>
+         </widget>
+        </item>
         <item row="0" column="0">
-         <widget class="QLabel" name="label_3">
+         <widget class="QLabel" name="locut_cutoff_label">
           <property name="text">
            <string>Lo-cut (24dB/oct)</string>
           </property>
           </property>
          </widget>
         </item>
-        <item row="3" column="0">
-         <widget class="QComboBox" name="comboBox">
-          <property name="currentText">
-           <string/>
+        <item row="3" column="2">
+         <widget class="QCheckBox" name="limiter_enabled">
+          <property name="text">
+           <string>Enabled</string>
+          </property>
+          <property name="checked">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="2">
+         <widget class="QDial" name="limiter_threshold_knob">
+          <property name="minimumSize">
+           <size>
+            <width>64</width>
+            <height>64</height>
+           </size>
+          </property>
+          <property name="maximumSize">
+           <size>
+            <width>16777215</width>
+            <height>64</height>
+           </size>
+          </property>
+          <property name="minimum">
+           <number>-400</number>
+          </property>
+          <property name="maximum">
+           <number>0</number>
+          </property>
+          <property name="value">
+           <number>-140</number>
+          </property>
+          <property name="notchTarget">
+           <double>30.000000000000000</double>
+          </property>
+          <property name="notchesVisible">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="2">
+         <widget class="QLabel" name="limiter_threshold_label">
+          <property name="text">
+           <string>Limiter threshold</string>
+          </property>
+          <property name="alignment">
+           <set>Qt::AlignCenter</set>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="2">
+         <widget class="QLabel" name="limiter_threshold_db_display">
+          <property name="text">
+           <string>-14.0 dB</string>
+          </property>
+          <property name="alignment">
+           <set>Qt::AlignCenter</set>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="3">
+         <widget class="QDial" name="compressor_threshold_knob">
+          <property name="minimumSize">
+           <size>
+            <width>64</width>
+            <height>64</height>
+           </size>
+          </property>
+          <property name="maximumSize">
+           <size>
+            <width>16777215</width>
+            <height>64</height>
+           </size>
+          </property>
+          <property name="minimum">
+           <number>-400</number>
+          </property>
+          <property name="maximum">
+           <number>0</number>
+          </property>
+          <property name="value">
+           <number>-260</number>
+          </property>
+          <property name="notchTarget">
+           <double>30.000000000000000</double>
+          </property>
+          <property name="notchesVisible">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="3">
+         <widget class="QLabel" name="compressor_threshold_label">
+          <property name="text">
+           <string>Compr. threshold</string>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="3">
+         <widget class="QLabel" name="compressor_threshold_db_display">
+          <property name="text">
+           <string>-26.0 dB</string>
+          </property>
+          <property name="alignment">
+           <set>Qt::AlignCenter</set>
+          </property>
+         </widget>
+        </item>
+        <item row="3" column="3">
+         <widget class="QCheckBox" name="compressor_enabled">
+          <property name="text">
+           <string>Enabled</string>
+          </property>
+          <property name="checked">
+           <bool>true</bool>
           </property>
          </widget>
         </item>