Browse Source

UI: Add audio meter decay rate option

The decay rate of the audio meters can now be selected in the audio
settings.  The values are:

- "Fast"   (OBS default, 40 dB / 1.7s)
- "Medium" (Type I PPM,  20 dB / 1.7s)
- "Slow"   (Type II PPM, 24 dB / 2.8s)

Closes jp9000/obs-studio#1143
Shaolin 7 years ago
parent
commit
53d936c5dc

+ 4 - 0
UI/data/locale/en-US.ini

@@ -700,6 +700,10 @@ Basic.Settings.Video.DownscaleFilter.Lanczos="Lanczos (Sharpened scaling, 32 sam
 Basic.Settings.Audio="Audio"
 Basic.Settings.Audio.SampleRate="Sample Rate"
 Basic.Settings.Audio.Channels="Channels"
+Basic.Settings.Audio.MeterDecayRate="Audio Meter Decay Rate"
+Basic.Settings.Audio.MeterDecayRate.Fast="Fast"
+Basic.Settings.Audio.MeterDecayRate.Medium="Medium (Type I PPM)"
+Basic.Settings.Audio.MeterDecayRate.Slow="Slow (Type II PPM)"
 Basic.Settings.Audio.MultiChannelWarning.Enabled="WARNING: Surround sound audio is enabled."
 Basic.Settings.Audio.MultichannelWarning="If streaming, check to see if your streaming service supports both surround sound ingest and surround sound playback.  Twitch, Facebook 360 Live, Mixer RTMP, Smashcast are examples where surround sound is fully supported.  Although Facebook Live and YouTube Live both accept surround ingest, Facebook Live downmixes to stereo, and YouTube Live plays only two channels.\n\nOBS audio filters are compatible with surround sound, though VST plugin support isn't guaranteed."
 Basic.Settings.Audio.MultichannelWarning.Title="Enable surround sound audio?"

+ 0 - 1
UI/data/themes/Dark.qss

@@ -518,7 +518,6 @@ VolumeMeter {
     qproperty-magnitudeColor: rgb(0, 0, 0);
     qproperty-majorTickColor: rgb(225,224,225); /* veryLight */
     qproperty-minorTickColor: rgb(122,121,122); /* light */
-    qproperty-peakDecayRate: 23.4; /* Override of the standard PPM Type I rate. */
 }
 
 

+ 0 - 1
UI/data/themes/Default.qss

@@ -68,7 +68,6 @@ VolumeMeter {
     qproperty-magnitudeColor: rgb(0, 0, 0);
     qproperty-majorTickColor: rgb(0, 0, 0);
     qproperty-minorTickColor: rgb(50, 50, 50);
-    qproperty-peakDecayRate: 23.4; /* Override of the standard PPM Type I rate. */
 }
 
 

+ 0 - 1
UI/data/themes/Rachni.qss

@@ -729,7 +729,6 @@ VolumeMeter {
 	qproperty-magnitudeColor: rgb(49, 54, 59); /* Blue-gray */
 	qproperty-majorTickColor: rgb(239, 240, 241); /* White */
 	qproperty-minorTickColor: rgb(118, 121, 124); /* Light Gray */
-	qproperty-peakDecayRate: 23.4; /* Override of the standard PPM Type I rate. */
 }
 
 /*******************/

+ 44 - 9
UI/forms/OBSBasicSettings.ui

@@ -146,7 +146,7 @@
               <x>0</x>
               <y>0</y>
               <width>801</width>
-              <height>1044</height>
+              <height>741</height>
              </rect>
             </property>
             <layout class="QVBoxLayout" name="verticalLayout_19">
@@ -733,8 +733,8 @@
              <rect>
               <x>0</x>
               <y>0</y>
-              <width>601</width>
-              <height>640</height>
+              <width>818</width>
+              <height>697</height>
              </rect>
             </property>
             <layout class="QVBoxLayout" name="verticalLayout_21">
@@ -3362,7 +3362,7 @@
            </property>
           </widget>
          </item>
-         <item row="7" column="0" colspan="2">
+         <item row="8" column="0" colspan="2">
           <widget class="QScrollArea" name="audioSourceScrollArea">
            <property name="widgetResizable">
             <bool>true</bool>
@@ -3372,14 +3372,14 @@
              <rect>
               <x>0</x>
               <y>0</y>
-              <width>63</width>
-              <height>16</height>
+              <width>800</width>
+              <height>69</height>
              </rect>
             </property>
            </widget>
           </widget>
          </item>
-         <item row="8" column="1">
+         <item row="9" column="1">
           <widget class="QLabel" name="audioMsg">
            <property name="styleSheet">
             <string notr="true">color: rgb(255, 0, 4);</string>
@@ -3392,7 +3392,7 @@
            </property>
           </widget>
          </item>
-         <item row="9" column="1">
+         <item row="10" column="1">
           <widget class="QLabel" name="audioMsg_2">
            <property name="text">
             <string notr="true"/>
@@ -3405,6 +3405,41 @@
            </property>
           </widget>
          </item>
+         <item row="7" column="0">
+          <widget class="QLabel" name="label_65">
+           <property name="text">
+            <string>Basic.Settings.Audio.MeterDecayRate</string>
+           </property>
+           <property name="buddy">
+            <cstring>meterDecayRate</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="7" column="1">
+          <widget class="QComboBox" name="meterDecayRate">
+           <property name="currentText">
+            <string>Basic.Settings.Audio.MeterDecayRate.Fast</string>
+           </property>
+           <property name="currentIndex">
+            <number>0</number>
+           </property>
+           <item>
+            <property name="text">
+             <string>Basic.Settings.Audio.MeterDecayRate.Fast</string>
+            </property>
+           </item>
+           <item>
+            <property name="text">
+             <string>Basic.Settings.Audio.MeterDecayRate.Medium</string>
+            </property>
+           </item>
+           <item>
+            <property name="text">
+             <string>Basic.Settings.Audio.MeterDecayRate.Slow</string>
+            </property>
+           </item>
+          </widget>
+         </item>
         </layout>
        </widget>
        <widget class="QWidget" name="videoPage">
@@ -3756,7 +3791,7 @@
              <rect>
               <x>0</x>
               <y>0</y>
-              <width>803</width>
+              <width>593</width>
               <height>761</height>
              </rect>
             </property>

+ 10 - 3
UI/volume-control.cpp

@@ -56,7 +56,7 @@ void VolControl::VolumeChanged()
 	slider->blockSignals(true);
 	slider->setValue((int) (obs_fader_get_deflection(obs_fader) * 100.0f));
 	slider->blockSignals(false);
-	
+
 	updateText();
 }
 
@@ -109,6 +109,11 @@ void VolControl::EmitConfigClicked()
 	emit ConfigClicked();
 }
 
+void VolControl::SetMeterDecayRate(qreal q)
+{
+	volMeter->setPeakDecayRate(q);
+}
+
 VolControl::VolControl(OBSSource source_, bool showConfig)
 	: source        (source_),
 	  levelTotal    (0.0f),
@@ -430,7 +435,7 @@ VolumeMeter::VolumeMeter(QWidget *parent, obs_volmeter_t *obs_volmeter)
 	errorLevel = -9.0;                                  //  -9 dB
 	clipLevel = -0.5;                                   //  -0.5 dB
 	minimumInputLevel = -50.0;                          // -50 dB
-	peakDecayRate = 11.7;                               //  20 dB / 1.7 sec
+	peakDecayRate = 11.76;                              //  20 dB / 1.7 sec
 	magnitudeIntegrationTime = 0.3;                     //  99% in 300 ms
 	peakHoldDuration = 20.0;                            //  20 seconds
 	inputPeakHoldDuration = 1.0;                        //  1 second
@@ -524,7 +529,9 @@ inline void VolumeMeter::calculateBallisticsForChannel(int channelNr,
 		// Attack of peak is immediate.
 		displayPeak[channelNr] = currentPeak[channelNr];
 	} else {
-		// Decay of peak is 20 dB / 1.7 seconds.
+		// Decay of peak is 40 dB / 1.7 seconds for Fast Profile
+		// 20 dB / 1.7 seconds for Medium Profile (Type I PPM)
+		// 24 dB / 2.8 seconds for Slow Profile (Type II PPM)
 		qreal decay = peakDecayRate * timeSinceLastRedraw;
 		displayPeak[channelNr] = CLAMP(displayPeak[channelNr] - decay,
 			currentPeak[channelNr], 0);

+ 2 - 0
UI/volume-control.hpp

@@ -253,4 +253,6 @@ public:
 
 	QString GetName() const;
 	void SetName(const QString &newName);
+
+	void SetMeterDecayRate(qreal q);
 };

+ 15 - 0
UI/window-basic-main.cpp

@@ -400,6 +400,16 @@ void OBSBasic::copyActionsDynamicProperties()
 	}
 }
 
+void OBSBasic::UpdateVolumeControlsDecayRate()
+{
+	double meterDecayRate = config_get_double(basicConfig, "Audio",
+			"MeterDecayRate");
+
+	for (size_t i = 0; i < volumes.size(); i++) {
+		volumes[i]->SetMeterDecayRate(meterDecayRate);
+	}
+}
+
 void OBSBasic::ClearVolumeControls()
 {
 	VolControl *control;
@@ -1235,6 +1245,8 @@ bool OBSBasic::InitBasicConfigDefaults()
 	config_set_default_uint  (basicConfig, "Audio", "SampleRate", 44100);
 	config_set_default_string(basicConfig, "Audio", "ChannelSetup",
 			"Stereo");
+	config_set_default_double(basicConfig, "Audio", "MeterDecayRate",
+			VOLUME_METER_DECAY_FAST);
 
 	return true;
 }
@@ -2549,6 +2561,9 @@ void OBSBasic::ActivateAudioSource(OBSSource source)
 
 	VolControl *vol = new VolControl(source, true);
 
+	double meterDecayRate = config_get_double(basicConfig, "Audio",
+			"MeterDecayRate");
+	vol->SetMeterDecayRate(meterDecayRate);
 	vol->setContextMenuPolicy(Qt::CustomContextMenu);
 
 	connect(vol, &QWidget::customContextMenuRequested,

+ 1 - 0
UI/window-basic-main.hpp

@@ -193,6 +193,7 @@ private:
 	void          CreateFirstRunSources();
 	void          CreateDefaultScene(bool firstStart);
 
+	void          UpdateVolumeControlsDecayRate();
 	void          ClearVolumeControls();
 
 	void          UploadLog(const char *file);

+ 32 - 0
UI/window-basic-settings.cpp

@@ -400,6 +400,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
 	HookWidget(ui->advRBMegsMax,         SCROLL_CHANGED, OUTPUTS_CHANGED);
 	HookWidget(ui->channelSetup,         COMBO_CHANGED,  AUDIO_RESTART);
 	HookWidget(ui->sampleRate,           COMBO_CHANGED,  AUDIO_RESTART);
+	HookWidget(ui->meterDecayRate,       COMBO_CHANGED,  AUDIO_CHANGED);
 	HookWidget(ui->desktopAudioDevice1,  COMBO_CHANGED,  AUDIO_CHANGED);
 	HookWidget(ui->desktopAudioDevice2,  COMBO_CHANGED,  AUDIO_CHANGED);
 	HookWidget(ui->auxAudioDevice1,      COMBO_CHANGED,  AUDIO_CHANGED);
@@ -2119,6 +2120,8 @@ void OBSBasicSettings::LoadAudioSettings()
 			"SampleRate");
 	const char *speakers = config_get_string(main->Config(), "Audio",
 			"ChannelSetup");
+	double meterDecayRate = config_get_double(main->Config(), "Audio",
+			"MeterDecayRate");
 
 	loading = true;
 
@@ -2147,6 +2150,13 @@ void OBSBasicSettings::LoadAudioSettings()
 	else
 		ui->channelSetup->setCurrentIndex(1);
 
+	if (meterDecayRate == VOLUME_METER_DECAY_MEDIUM)
+		ui->meterDecayRate->setCurrentIndex(1);
+	else if (meterDecayRate == VOLUME_METER_DECAY_SLOW)
+		ui->meterDecayRate->setCurrentIndex(2);
+	else
+		ui->meterDecayRate->setCurrentIndex(0);
+
 	LoadAudioDevices();
 	LoadAudioSources();
 
@@ -3079,6 +3089,28 @@ void OBSBasicSettings::SaveAudioSettings()
 		config_set_string(main->Config(), "Audio", "ChannelSetup",
 				channelSetup);
 
+	if (WidgetChanged(ui->meterDecayRate)) {
+		double meterDecayRate;
+		switch (ui->meterDecayRate->currentIndex()) {
+		case 0:
+			meterDecayRate = VOLUME_METER_DECAY_FAST;
+			break;
+		case 1:
+			meterDecayRate = VOLUME_METER_DECAY_MEDIUM;
+			break;
+		case 2:
+			meterDecayRate = VOLUME_METER_DECAY_SLOW;
+			break;
+		default:
+			meterDecayRate = VOLUME_METER_DECAY_FAST;
+			break;
+		}
+		config_set_double(main->Config(), "Audio", "MeterDecayRate",
+				meterDecayRate);
+
+		main->UpdateVolumeControlsDecayRate();
+	}
+
 	for (auto &audioSource : audioSources) {
 		auto source  = OBSGetStrongRef(get<0>(audioSource));
 		if (!source)

+ 4 - 0
UI/window-basic-settings.hpp

@@ -37,6 +37,10 @@ class OBSHotkeyWidget;
 
 #include "ui_OBSBasicSettings.h"
 
+#define VOLUME_METER_DECAY_FAST        23.53
+#define VOLUME_METER_DECAY_MEDIUM      11.76
+#define VOLUME_METER_DECAY_SLOW        8.57
+
 class SilentUpdateCheckBox : public QCheckBox {
 	Q_OBJECT