[vlc-commits] PulseAudio: correct volume reporting from PA to VLC (fix #6759)
Rémi Denis-Courmont
git at videolan.org
Sun May 6 14:11:49 CEST 2012
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun May 6 15:09:51 2012 +0300| [a89517ca4be10847d17db539ed6acf5302fb65dd] | committer: Rémi Denis-Courmont
PulseAudio: correct volume reporting from PA to VLC (fix #6759)
The proper reciprocal formula to that of VLC to PA conversion must be
used. Otherwise, we get an inconsistent value in the "volume" variable.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a89517ca4be10847d17db539ed6acf5302fb65dd
---
modules/audio_output/pulse.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index a0622f0..4d12ae9 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -473,15 +473,16 @@ static void sink_input_info_cb(pa_context *ctx, const pa_sink_input_info *i,
{
audio_output_t *aout = userdata;
aout_sys_t *sys = aout->sys;
- float volume;
if (eol)
return;
(void) ctx;
- sys->cvolume = i->volume;
- volume = pa_cvolume_max(&i->volume) / (float)PA_VOLUME_NORM;
- aout_VolumeHardSet(aout, volume, i->mute);
+ sys->cvolume = i->volume; /* cache volume for balance preservation */
+
+ pa_volume_t volume = pa_cvolume_max(&i->volume);
+ volume = pa_sw_volume_divide(volume, sys->base_volume);
+ aout_VolumeHardSet(aout, (float)volume / PA_VOLUME_NORM, i->mute);
}
@@ -607,18 +608,17 @@ static int VolumeSet(audio_output_t *aout, float vol, bool mute)
pa_operation *op;
uint32_t idx = pa_stream_get_index(sys->stream);
- pa_cvolume cvolume = sys->cvolume;
- 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_volume_t volume = pa_sw_volume_multiply(lround(vol), sys->base_volume);
+
+ /* Preserve the balance (VLC does not support it). */
+ pa_cvolume cvolume = sys->cvolume;
+ pa_cvolume_scale(&cvolume, PA_VOLUME_NORM);
pa_sw_cvolume_multiply_scalar(&cvolume, &cvolume, volume);
assert(pa_cvolume_valid(&cvolume));
More information about the vlc-commits
mailing list