Browse Source

UI: Fix display of mono source with surround output

A mono input with surround output is upmixed by swresampler by routing
it to FC (front center) by default which corresponds to third channel
for 3.0, 4.0, 4.1, 5.0, 5.1, 7.1. (The other channels are muted.)
But the volume meters are set to show the first channel for mono sources.
Therefore although audio is processed, it would not show on the meter.
This fixes this display issue.

Closes obsproject/obs-studio#1540
pkviet 7 years ago
parent
commit
736b7f0d35
2 changed files with 17 additions and 8 deletions
  1. 16 8
      UI/volume-control.cpp
  2. 1 0
      UI/volume-control.hpp

+ 16 - 8
UI/volume-control.cpp

@@ -528,6 +528,8 @@ VolumeMeter::VolumeMeter(QWidget *parent, obs_volmeter_t *obs_volmeter,
 	peakHoldDuration = 20.0;                            //  20 seconds
 	peakHoldDuration = 20.0;                            //  20 seconds
 	inputPeakHoldDuration = 1.0;                        //  1 second
 	inputPeakHoldDuration = 1.0;                        //  1 second
 
 
+	channels = (int)audio_output_get_channels(obs_get_audio());
+
 	handleChannelCofigurationChange();
 	handleChannelCofigurationChange();
 	updateTimerRef = updateTimer.toStrongRef();
 	updateTimerRef = updateTimer.toStrongRef();
 	if (!updateTimerRef) {
 	if (!updateTimerRef) {
@@ -1007,16 +1009,22 @@ void VolumeMeter::paintEvent(QPaintEvent *event)
 
 
 	for (int channelNr = 0; channelNr < displayNrAudioChannels;
 	for (int channelNr = 0; channelNr < displayNrAudioChannels;
 		channelNr++) {
 		channelNr++) {
+
+		int channelNrFixed = (displayNrAudioChannels == 1 &&
+		                      channels > 2)
+			? 2
+			: channelNr;
+
 		if (vertical)
 		if (vertical)
 			paintVMeter(painter, channelNr * 4, 8, 3, height - 10,
 			paintVMeter(painter, channelNr * 4, 8, 3, height - 10,
-					displayMagnitude[channelNr],
-					displayPeak[channelNr],
-					displayPeakHold[channelNr]);
+					displayMagnitude[channelNrFixed],
+					displayPeak[channelNrFixed],
+					displayPeakHold[channelNrFixed]);
 		else
 		else
 			paintHMeter(painter, 5, channelNr * 4, width - 5, 3,
 			paintHMeter(painter, 5, channelNr * 4, width - 5, 3,
-					displayMagnitude[channelNr],
-					displayPeak[channelNr],
-					displayPeakHold[channelNr]);
+					displayMagnitude[channelNrFixed],
+					displayPeak[channelNrFixed],
+					displayPeakHold[channelNrFixed]);
 
 
 		if (idle)
 		if (idle)
 			continue;
 			continue;
@@ -1026,10 +1034,10 @@ void VolumeMeter::paintEvent(QPaintEvent *event)
 		// having too much visual impact.
 		// having too much visual impact.
 		if (vertical)
 		if (vertical)
 			paintInputMeter(painter, channelNr * 4, 3, 3, 3,
 			paintInputMeter(painter, channelNr * 4, 3, 3, 3,
-					displayInputPeakHold[channelNr]);
+					displayInputPeakHold[channelNrFixed]);
 		else
 		else
 			paintInputMeter(painter, 0, channelNr * 4, 3, 3,
 			paintInputMeter(painter, 0, channelNr * 4, 3, 3,
-					displayInputPeakHold[channelNr]);
+					displayInputPeakHold[channelNrFixed]);
 	}
 	}
 
 
 	lastRedrawTime = ts;
 	lastRedrawTime = ts;

+ 1 - 0
UI/volume-control.hpp

@@ -144,6 +144,7 @@ private:
 	qreal inputPeakHoldDuration;
 	qreal inputPeakHoldDuration;
 
 
 	uint64_t lastRedrawTime = 0;
 	uint64_t lastRedrawTime = 0;
+	int channels = 0;
 	bool clipping = false;
 	bool clipping = false;
 	bool vertical;
 	bool vertical;