summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@mplayer2.org>2012-01-07 17:33:40 +0100
committerwm4 <wm4@mplayer2.org>2012-01-18 04:21:45 +0100
commit6afaf948cd80e348c4ff93f44baae362d4423793 (patch)
tree774acf7b7f69ec14019820b53e156bf1f10dfcf9
parentaae97b7e254f312e5c7bfbe940cb8515a25bf11d (diff)
downloadmpv-6afaf948cd80e348c4ff93f44baae362d4423793.tar.bz2
mpv-6afaf948cd80e348c4ff93f44baae362d4423793.tar.xz
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.
-rw-r--r--mixer.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/mixer.c b/mixer.c
index d0e6423e6f..4b99a6e967 100644
--- a/mixer.c
+++ b/mixer.c
@@ -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)