Commit a89517ca authored by Rémi Denis-Courmont's avatar 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.
parent 672bcaf6
......@@ -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));
......
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