1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-09 08:29:36 +00:00

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.
This commit is contained in:
Uoti Urpala 2012-04-09 21:06:10 +03:00
parent 87dad2a470
commit e29cb8f323
3 changed files with 24 additions and 8 deletions

View File

@ -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)

28
mixer.c
View File

@ -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);
}

View File

@ -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);