mirror of https://github.com/mpv-player/mpv
mixer: keep user volume setting when --softvol is used
When --softvol is enabled, the volume set by the "volume" property is reset when changing to a new file or crossing ordered chapter boundaries. Fix this by explicitly restoring the volume on audio reinitialization. Now the behavior with --softvol should be the same as if a system mixer is used, and the volume should be persistent across file changes. This also works around an inconsistency with the mute flag. The frontend assumed the mute flag is persistent across file changes, which was not true with --softvol. If not resetting the volume on playing new files is undesired, it can be avoided by putting volume=100 in the mplayer config file.
This commit is contained in:
parent
670e72506a
commit
685fbf25fe
13
mixer.c
13
mixer.c
|
@ -35,6 +35,16 @@ char *mixer_channel = NULL;
|
||||||
int soft_vol = 0;
|
int soft_vol = 0;
|
||||||
float soft_vol_max = 110.0;
|
float soft_vol_max = 110.0;
|
||||||
|
|
||||||
|
// Called after the audio filter chain is built or rebuilt.
|
||||||
|
void mixer_reinit(mixer_t *mixer)
|
||||||
|
{
|
||||||
|
if (mixer->restore_softvol) {
|
||||||
|
int muted = mixer->muted;
|
||||||
|
mixer_setvolume(mixer, mixer->softvol_l, mixer->softvol_r);
|
||||||
|
mixer->muted = muted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void mixer_getvolume(mixer_t *mixer, float *l, float *r)
|
void mixer_getvolume(mixer_t *mixer, float *l, float *r)
|
||||||
{
|
{
|
||||||
ao_control_vol_t vol;
|
ao_control_vol_t vol;
|
||||||
|
@ -76,6 +86,9 @@ void mixer_setvolume(mixer_t *mixer, float l, float r)
|
||||||
// af_volume uses values in dB
|
// af_volume uses values in dB
|
||||||
float db_vals[AF_NCH];
|
float db_vals[AF_NCH];
|
||||||
int i;
|
int i;
|
||||||
|
mixer->softvol_l = l;
|
||||||
|
mixer->softvol_r = r;
|
||||||
|
mixer->restore_softvol = 1;
|
||||||
db_vals[0] = (l / 100.0) * (soft_vol_max / 100.0);
|
db_vals[0] = (l / 100.0) * (soft_vol_max / 100.0);
|
||||||
db_vals[1] = (r / 100.0) * (soft_vol_max / 100.0);
|
db_vals[1] = (r / 100.0) * (soft_vol_max / 100.0);
|
||||||
for (i = 2; i < AF_NCH; i++)
|
for (i = 2; i < AF_NCH; i++)
|
||||||
|
|
3
mixer.h
3
mixer.h
|
@ -33,8 +33,11 @@ typedef struct mixer_s {
|
||||||
int volstep;
|
int volstep;
|
||||||
int muted;
|
int muted;
|
||||||
float last_l, last_r;
|
float last_l, last_r;
|
||||||
|
float softvol_l, softvol_r;
|
||||||
|
int restore_softvol;
|
||||||
} mixer_t;
|
} mixer_t;
|
||||||
|
|
||||||
|
void mixer_reinit(mixer_t *mixer);
|
||||||
void mixer_getvolume(mixer_t *mixer, float *l, float *r);
|
void mixer_getvolume(mixer_t *mixer, float *l, float *r);
|
||||||
void mixer_setvolume(mixer_t *mixer, float l, float r);
|
void mixer_setvolume(mixer_t *mixer, float l, float r);
|
||||||
void mixer_incvolume(mixer_t *mixer);
|
void mixer_incvolume(mixer_t *mixer);
|
||||||
|
|
|
@ -1448,6 +1448,7 @@ static int build_afilter_chain(struct MPContext *mpctx)
|
||||||
result = init_audio_filters(sh_audio, new_srate,
|
result = init_audio_filters(sh_audio, new_srate,
|
||||||
&ao->samplerate, &ao->channels, &ao->format);
|
&ao->samplerate, &ao->channels, &ao->format);
|
||||||
mpctx->mixer.afilter = sh_audio->afilter;
|
mpctx->mixer.afilter = sh_audio->afilter;
|
||||||
|
mixer_reinit(&mpctx->mixer);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue