From 38b2c97fd6b59b923ad309c19c457cbc0210da17 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 19 Sep 2013 14:32:09 +0200 Subject: mixer: refactor, fix some aspects of --volume handling Refactor how mixer.c does volume/mute restoration and initialization. Move to handling of --volume and --mute to mixer.c. Simplify the implementation of these and hopefully fix bugs/strange behavior related to using them as file-local options (this uses a somewhat dirty trick: the option values are reverted to "auto" after initialization). Put most code related to initialization and volume restoring in probe_softvol() and restore_volume(). Having this code all in one place is less confusing. Instead of trying to detect whether to use softvol at runtime, detect it at initialization time using AOCONTROL_GET_VOLUME (same with mute, AOCONTROL_GET_MUTE). This implies we expect SET_VOLUME/SET_MUTE to work if the GET variants work. Hopefully this is always the case. This is also preparation for being able to change volume/mute settings if audio is disabled, and for allowing restoring value with playback resume. --- audio/mixer.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'audio/mixer.h') diff --git a/audio/mixer.h b/audio/mixer.h index b22bba0310..6761be5da4 100644 --- a/audio/mixer.h +++ b/audio/mixer.h @@ -21,6 +21,7 @@ #include +// Values of MPOpts.softvol enum { SOFTVOL_NO = 0, SOFTVOL_YES = 1, @@ -31,19 +32,22 @@ typedef struct mixer { struct MPOpts *opts; struct ao *ao; struct af_stream *af; - int softvol; + // Static, dependent on ao/softvol settings + bool softvol; // use AO (true) or af_volume (false) + bool emulate_mute; // if true, emulate mute with volume=0 + // Last known values (possibly out of sync with reality) + float vol_l, vol_r; bool muted; + // Used to decide whether we should unmute on uninit bool muted_by_us; - bool muted_using_volume; - float vol_l, vol_r; /* 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; + const char *driver; + // Other stuff float balance; - bool user_set_mute; - bool user_set_volume; } mixer_t; +void mixer_init(struct mixer *mixer, struct MPOpts *opts); void mixer_reinit_audio(struct mixer *mixer, struct ao *ao, struct af_stream *af); void mixer_uninit_audio(struct mixer *mixer); void mixer_getvolume(mixer_t *mixer, float *l, float *r); -- cgit v1.2.3