[pulseaudio-discuss] fix changing volume to 0% breaks channel ballance
Colin Guthrie
gmane at colin.guthr.ie
Mon Dec 6 01:30:49 PST 2010
Hello,
'Twas brillig, and chen rui at 06/12/10 05:50 did gyre and gimble:
> I fixed bug: #874 pulseaudio breaks per-channel volume config when
> restoring volume from 0%.
>
> I created arrayto record balance. When the volume change to 0%, I can
> use last balance to calculate new volume.
Thanks for looking at this. Sadly this wont work, but comments below.
> Here is the patch:
>
> Signed-off-by: Chen Rui <rui.chen at tieto.com>
> ---
> src/pulse/volume.c | 23 +++++++++++++++++++++--
> src/pulsecore/sink.c | 21 ++++++++++++++++++++-
> 2 files changed, 41 insertions(+), 3 deletions(-)
>
> diff --git a/src/pulse/volume.c b/src/pulse/volume.c
> index f74d720..a51af0b 100644
> --- a/src/pulse/volume.c
> +++ b/src/pulse/volume.c
> @@ -683,6 +683,8 @@ pa_cvolume* pa_cvolume_set_balance(pa_cvolume *v,
> const pa_channel_map *map, flo
>
> pa_cvolume* pa_cvolume_scale(pa_cvolume *v, pa_volume_t max) {
> unsigned c;
> + static float balance[PA_CHANNELS_MAX/2] = {0};
This is a general utility function and may be called several times for
several different purposes, including per-application volumes and not
just sink volumes. If you have several sinks on your system (e.g. built
in + USB + Bluetooth etc. etc.) then it may be called several times with
completely unrelated values.
Thus using a static variable to store the balance is sadly incorrect.
There would need to be "balance" stored along with the cvolume somehow
so that the balance specific to that cvolume can be restored. The
easiest way would be to include the balance in the pa_cvolume structure,
but that is likely to be rather complicated as that structure is often
passed over the protocol, so either you need to modify the protocol to
pass the new balance argument or simply ensure that you reset the
balance to 0 in pa_cvolume_init() and forget about passing this
information over the protocol. Of course in so doing, you'll likely end
up breaking the actual fix.
So the correct fix is really rather more involved and will ultimately
require storing a balance along with a cvolume for the entities that
need to have their balances restored (i.e. sinks, sink inputs, and sources).
An additional complication is that as you approach 0, the resolution of
the balance reduces. I believe a better structure representing balance
is needed, but that may complicate things further too.
So, all in all, solving this problem is not quite as simple as it seems.
All the best
Col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mageia Contributor [http://www.mageia.org/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
More information about the pulseaudio-discuss
mailing list