summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--command.c3
-rw-r--r--mixer.c28
-rw-r--r--mixer.h1
3 files changed, 24 insertions, 8 deletions
diff --git a/command.c b/command.c
index 3c1805b412..e4ce53f87a 100644
--- a/command.c
+++ b/command.c
@@ -871,9 +871,6 @@ static int mp_property_balance(m_option_t *prop, int action, void *arg,
{
float bal;
- if (!mpctx->sh_audio || mpctx->sh_audio->channels < 2)
- return M_PROPERTY_UNAVAILABLE;
-
switch (action) {
case M_PROPERTY_GET:
if (!arg)
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);
}
diff --git a/mixer.h b/mixer.h
index fc5b6c1e71..e626237539 100644
--- a/mixer.h
+++ b/mixer.h
@@ -35,6 +35,7 @@ typedef struct mixer {
/* Contains ao driver name or "softvol" if volume is not persistent
* and needs to be restored after the driver is reinitialized. */
const char *restore_volume;
+ float balance;
} mixer_t;
void mixer_reinit(struct mixer *mixer, struct ao *ao);