[vlc-commits] PulseAudio: fix VLC <-> PulseAudio volume conversion

Rémi Denis-Courmont git at videolan.org
Tue Jul 26 17:05:40 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jul 26 17:53:34 2011 +0300| [fa91d584ed5759d8347eacdc01b27ff67166527a] | committer: Rémi Denis-Courmont

PulseAudio: fix VLC <-> PulseAudio volume conversion

VLC (like PulseAudio) stores the software volume i.e. the position of
the volume UI slider, rather than the linear amplification multiplier.

So do not use PulseAudio linear to volume conversion. Otherwise the
VLC volume gets wrongly cube-rooted.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fa91d584ed5759d8347eacdc01b27ff67166527a
---

 modules/audio_output/Modules.am |    2 +-
 modules/audio_output/pulse.c    |   16 ++++++++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/modules/audio_output/Modules.am b/modules/audio_output/Modules.am
index 761ae4e..50a50b7 100644
--- a/modules/audio_output/Modules.am
+++ b/modules/audio_output/Modules.am
@@ -35,7 +35,7 @@ endif
 libpulse_plugin_la_SOURCES = pulse.c
 libpulse_plugin_la_CFLAGS = $(AM_CFLAGS) $(PULSE_CFLAGS)
 libpulse_plugin_la_LIBADD = $(AM_LIBADD) $(PULSE_LIBS) \
-	../../src/libvlcpulse.la
+	$(LIBM) ../../src/libvlcpulse.la
 libpulse_plugin_la_DEPENDENCIES =
 if HAVE_PULSE
 libvlc_LTLIBRARIES += libpulse_plugin.la
diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index c7bd67d..875c647 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -147,7 +147,7 @@ static void sink_info_cb(pa_context *c, const pa_sink_info *i, int eol,
         sys->base_volume = i->base_volume;
     else
         sys->base_volume = PA_VOLUME_NORM;
-    msg_Dbg(aout, "base volume: %f", pa_sw_volume_to_linear(sys->base_volume));
+    msg_Dbg(aout, "base volume: %"PRIu32, sys->base_volume);
 }
 
 /*** Stream helpers ***/
@@ -349,7 +349,7 @@ static void sink_input_info_cb(pa_context *ctx, const pa_sink_input_info *i,
     (void) ctx;
 
     sys->cvolume = i->volume;
-    volume = pa_sw_volume_to_linear(pa_cvolume_max(&i->volume));
+    volume = pa_cvolume_max(&i->volume) / (float)PA_VOLUME_NORM;
     aout_VolumeHardSet(aout, volume, i->mute);
 }
 
@@ -497,11 +497,19 @@ static int VolumeSet(audio_output_t *aout, float vol, bool mute)
     uint32_t idx = pa_stream_get_index(sys->stream);
 
     pa_cvolume cvolume = sys->cvolume;
-    pa_volume_t volume = pa_sw_volume_multiply(pa_sw_volume_from_linear(vol),
-                                               sys->base_volume);
+    pa_volume_t volume = sys->base_volume;
 
     pa_cvolume_scale(&cvolume, PA_VOLUME_NORM); /* preserve balance */
+
+    /* VLC provides the software volume so convert directly to PulseAudio
+     * software volume, pa_volume_t. This is not a linear amplification factor
+     * so do not use PulseAudio linear amplification! */
+    vol *= PA_VOLUME_NORM;
+    if (unlikely(vol >= PA_VOLUME_MAX))
+        vol = PA_VOLUME_MAX;
+    volume = pa_sw_volume_multiply(volume, lround(vol));
     pa_sw_cvolume_multiply_scalar(&cvolume, &cvolume, volume);
+
     assert(pa_cvolume_valid(&cvolume));
 
     vlc_pa_lock();



More information about the vlc-commits mailing list