Browse Source

Fix audio meters so that volume is applied linearly.

HomeWorld 11 years ago
parent
commit
6b284d9e58
2 changed files with 13 additions and 5 deletions
  1. 9 2
      libobs/obs-source.c
  2. 4 3
      obs/volume-control.cpp

+ 9 - 2
libobs/obs-source.c

@@ -565,8 +565,15 @@ static void calc_volume_levels(struct obs_source *source, float *array,
 		max_val  = fmaxf(max_val, val_pow2);
 	}
 
-	rms_val = to_db(sqrtf(sum_val / (float)count) * volume);
-	max_val = to_db(sqrtf(max_val) * volume);
+	/*
+	  We want the volume meters scale linearly in respect to current
+	  volume, so, no need to apply volume here.
+	*/
+
+	UNUSED_PARAMETER(volume);
+
+	rms_val = to_db(sqrtf(sum_val / (float)count));
+	max_val = to_db(sqrtf(max_val));
 
 	if (max_val > source->vol_max)
 		source->vol_max = max_val;

+ 4 - 3
obs/volume-control.cpp

@@ -74,10 +74,11 @@ void VolControl::VolumeLevel(float mag, float peak, float peakHold)
 
 	/* only update after a certain amount of time */
 	if ((curMeterTime - lastMeterTime) > UPDATE_INTERVAL_MS) {
+		float vol = (float)slider->value() * 0.01f;
 		lastMeterTime = curMeterTime;
-		volMeter->setLevels(DBToLinear(mag),
-				    DBToLinear(peak),
-				    DBToLinear(peakHold));
+		volMeter->setLevels(DBToLinear(mag) * vol,
+				    DBToLinear(peak) * vol,
+				    DBToLinear(peakHold) * vol);
 	}
 }