Commit fa91d584 authored by Rémi Denis-Courmont's avatar 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.
parent 82f58f32
...@@ -35,7 +35,7 @@ endif ...@@ -35,7 +35,7 @@ endif
libpulse_plugin_la_SOURCES = pulse.c libpulse_plugin_la_SOURCES = pulse.c
libpulse_plugin_la_CFLAGS = $(AM_CFLAGS) $(PULSE_CFLAGS) libpulse_plugin_la_CFLAGS = $(AM_CFLAGS) $(PULSE_CFLAGS)
libpulse_plugin_la_LIBADD = $(AM_LIBADD) $(PULSE_LIBS) \ libpulse_plugin_la_LIBADD = $(AM_LIBADD) $(PULSE_LIBS) \
../../src/libvlcpulse.la $(LIBM) ../../src/libvlcpulse.la
libpulse_plugin_la_DEPENDENCIES = libpulse_plugin_la_DEPENDENCIES =
if HAVE_PULSE if HAVE_PULSE
libvlc_LTLIBRARIES += libpulse_plugin.la libvlc_LTLIBRARIES += libpulse_plugin.la
......
...@@ -147,7 +147,7 @@ static void sink_info_cb(pa_context *c, const pa_sink_info *i, int eol, ...@@ -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; sys->base_volume = i->base_volume;
else else
sys->base_volume = PA_VOLUME_NORM; 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 ***/ /*** Stream helpers ***/
...@@ -349,7 +349,7 @@ static void sink_input_info_cb(pa_context *ctx, const pa_sink_input_info *i, ...@@ -349,7 +349,7 @@ static void sink_input_info_cb(pa_context *ctx, const pa_sink_input_info *i,
(void) ctx; (void) ctx;
sys->cvolume = i->volume; 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); aout_VolumeHardSet(aout, volume, i->mute);
} }
...@@ -497,11 +497,19 @@ static int VolumeSet(audio_output_t *aout, float vol, bool 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); uint32_t idx = pa_stream_get_index(sys->stream);
pa_cvolume cvolume = sys->cvolume; pa_cvolume cvolume = sys->cvolume;
pa_volume_t volume = pa_sw_volume_multiply(pa_sw_volume_from_linear(vol), pa_volume_t volume = sys->base_volume;
sys->base_volume);
pa_cvolume_scale(&cvolume, PA_VOLUME_NORM); /* preserve balance */ 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); pa_sw_cvolume_multiply_scalar(&cvolume, &cvolume, volume);
assert(pa_cvolume_valid(&cvolume)); assert(pa_cvolume_valid(&cvolume));
vlc_pa_lock(); vlc_pa_lock();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment