1
mirror of https://github.com/mpv-player/mpv synced 2024-09-12 23:45:53 +02:00

audio: pretend muting doesn't set volume to 0

Muting audio is implemented by setting the volume controls to 0. This
has the annoying consequence that attempting to change the volume while
the audio is muted will reset the user's volume setting. E.g. increasing
the volume while muted will start from 0, instead from the volume that
was set before muting. Changing the volume while muted effectively resets
the volume to 0 (which is not very useful), with no possibility of
restoring the old voume.

This commit makes mplayer always report the volume that was set when mute
was enabled while mute is still active.

Caveat: this might be have confusing effects when the volume control is
directly connected with a system wide mixer setting. Now it's even less
obvious (and thus more confusing) that muting will set the mixer volume
to 0.

Also always clip input volumes, and remove some minor code duplication.
This commit is contained in:
wm4 2012-01-07 17:33:40 +01:00
parent aae97b7e25
commit 6afaf948cd

48
mixer.c
View File

@ -75,7 +75,7 @@ void mixer_uninit(mixer_t *mixer)
}
}
void mixer_getvolume(mixer_t *mixer, float *l, float *r)
static void internal_getvolume(mixer_t *mixer, float *l, float *r)
{
ao_control_vol_t vol;
*l = 0;
@ -102,8 +102,15 @@ void mixer_getvolume(mixer_t *mixer, float *l, float *r)
}
}
static float clip_vol(float v)
{
return v > 100 ? 100 : (v < 0 ? 0 : v);
}
void mixer_setvolume(mixer_t *mixer, float l, float r)
{
l = clip_vol(l);
r = clip_vol(r);
ao_control_vol_t vol;
vol.right = r;
vol.left = l;
@ -152,30 +159,35 @@ void mixer_setvolume(mixer_t *mixer, float l, float r)
mixer->muted = false;
}
void mixer_incvolume(mixer_t *mixer)
void mixer_getvolume(mixer_t *mixer, float *l, float *r)
{
*l = 0;
*r = 0;
if (mixer->ao) {
if (mixer->muted) {
*l = mixer->last_l;
*r = mixer->last_r;
} else {
internal_getvolume(mixer, l, r);
}
}
}
static void mixer_addvolume(mixer_t *mixer, float d)
{
float mixer_l, mixer_r;
mixer_getvolume(mixer, &mixer_l, &mixer_r);
mixer_l += mixer->volstep;
if (mixer_l > 100)
mixer_l = 100;
mixer_r += mixer->volstep;
if (mixer_r > 100)
mixer_r = 100;
mixer_setvolume(mixer, mixer_l, mixer_r);
mixer_setvolume(mixer, mixer_l + d, mixer_r + d);
}
void mixer_incvolume(mixer_t *mixer)
{
mixer_addvolume(mixer, +mixer->volstep);
}
void mixer_decvolume(mixer_t *mixer)
{
float mixer_l, mixer_r;
mixer_getvolume(mixer, &mixer_l, &mixer_r);
mixer_l -= mixer->volstep;
if (mixer_l < 0)
mixer_l = 0;
mixer_r -= mixer->volstep;
if (mixer_r < 0)
mixer_r = 0;
mixer_setvolume(mixer, mixer_l, mixer_r);
mixer_addvolume(mixer, -mixer->volstep);
}
void mixer_getbothvolume(mixer_t *mixer, float *b)