summaryrefslogtreecommitdiffstats
path: root/mixer.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@mplayer2.org>2012-04-09 21:06:10 +0300
committerUoti Urpala <uau@mplayer2.org>2012-04-11 03:50:33 +0300
commite29cb8f323031b32369bc2104ea1fd4422dd2945 (patch)
tree5fc5905fa066fb5abfab0d712589da711ffd0490 /mixer.c
parent87dad2a4704b2fb0f983d5cb665a065437288d35 (diff)
downloadmpv-e29cb8f323031b32369bc2104ea1fd4422dd2945.tar.bz2
mpv-e29cb8f323031b32369bc2104ea1fd4422dd2945.tar.xz
audio: restore balance setting after reinit
Restore the audio balance setting when the audio chain is reinitialized (also after switching to another file). Also add a note about the balance code being seriously buggy.
Diffstat (limited to 'mixer.c')
-rw-r--r--mixer.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/mixer.c b/mixer.c
index b231563026..e694253b11 100644
--- a/mixer.c
+++ b/mixer.c
@@ -161,13 +161,24 @@ void mixer_decvolume(mixer_t *mixer)
void mixer_getbalance(mixer_t *mixer, float *val)
{
- *val = 0.f;
- if (!mixer->afilter)
- return;
- af_control_any_rev(mixer->afilter, AF_CONTROL_PAN_BALANCE | AF_CONTROL_GET,
- val);
+ if (mixer->afilter)
+ af_control_any_rev(mixer->afilter,
+ AF_CONTROL_PAN_BALANCE | AF_CONTROL_GET,
+ &mixer->balance);
+ *val = mixer->balance;
}
+/* NOTE: Currently the balance code is seriously buggy: it always changes
+ * the af_pan mapping between the first two input channels and first two
+ * output channels to particular values. These values make sense for an
+ * af_pan instance that was automatically inserted for balance control
+ * only and is otherwise an identity transform, but if the filter was
+ * there for another reason, then ignoring and overriding the original
+ * values is completely wrong. In particular, this will break
+ * automatically inserted downmix filters; the original coefficients that
+ * are significantly below 1 will be overwritten with much higher values.
+ */
+
void mixer_setbalance(mixer_t *mixer, float val)
{
float level[AF_NCH];
@@ -175,6 +186,8 @@ void mixer_setbalance(mixer_t *mixer, float val)
af_control_ext_t arg_ext = { .arg = level };
af_instance_t *af_pan_balance;
+ mixer->balance = val;
+
if (!mixer->afilter)
return;
@@ -182,6 +195,9 @@ void mixer_setbalance(mixer_t *mixer, float val)
AF_CONTROL_PAN_BALANCE | AF_CONTROL_SET, &val))
return;
+ if (val == 0 || mixer->ao->channels < 2)
+ return;
+
if (!(af_pan_balance = af_add(mixer->afilter, "pan"))) {
mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
"[Mixer] No balance control available.\n");
@@ -223,4 +239,6 @@ void mixer_reinit(struct mixer *mixer, struct ao *ao)
mixer_setvolume(mixer, left, right);
mixer_setmute(mixer, muted);
}
+ if (mixer->balance != 0)
+ mixer_setbalance(mixer, mixer->balance);
}