mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-26 21:00:21 +00:00
audio: change range of volume option/property
Now --volume takes an absolute volume, meaning it doesn't depend on --softvol-max. 0 is still silence, and 100 now always means unchanged volume. The OSD and the "volume" property are changed accordingly. Also raise the minimum value of --softvol-max. A value below 100 makes no sense and breaks the OSD.
This commit is contained in:
@@ -1132,7 +1132,7 @@ Property list
|
||||
See ``--hr-seek``.
|
||||
|
||||
``volume`` (RW)
|
||||
Current volume (0-100).
|
||||
Current volume (see ``--volume`` for details).
|
||||
|
||||
``mute`` (RW)
|
||||
Current mute status (``yes``/``no``).
|
||||
|
||||
@@ -882,9 +882,15 @@ Audio
|
||||
``--ad=help``
|
||||
List all available decoders.
|
||||
|
||||
``--volume=<-1-100>``
|
||||
Set the startup volume. A value of -1 (the default) will not change the
|
||||
volume. See also ``--softvol``.
|
||||
``--volume=<value>``
|
||||
Set the startup volume. 0 means silence, 100 means no volume reduction or
|
||||
amplification. A value of -1 (the default) will not change the volume. See
|
||||
also ``--softvol``.
|
||||
|
||||
.. note::
|
||||
|
||||
This was changed after the mpv 0.9 release. Before that, 100 actually
|
||||
meant maximum volume.
|
||||
|
||||
``--audio-delay=<sec>``
|
||||
Audio delay in seconds (positive or negative float value). Positive values
|
||||
@@ -1053,19 +1059,10 @@ Audio
|
||||
their start timestamps differ, and then video timing is gradually adjusted
|
||||
if necessary to reach correct synchronization later.
|
||||
|
||||
``--softvol-max=<10.0-10000.0>``
|
||||
``--softvol-max=<100.0-10000.0>``
|
||||
Set the maximum amplification level in percent (default: 200). A value of
|
||||
200 will allow you to adjust the volume up to a maximum of double the
|
||||
current level. With values below 100 the initial volume (which is 100%)
|
||||
will be above the maximum, which e.g. the OSD cannot display correctly.
|
||||
|
||||
.. admonition:: Note
|
||||
|
||||
The maximum value of ``--volume`` as well as the ``volume`` property
|
||||
is always 100. Likewise, the volume OSD bar always goes from 0 to 100.
|
||||
This means that with ``--softvol-max=200``, ``--volume=100`` sets
|
||||
maximum amplification, i.e. amplify by 200%. The default volume (no
|
||||
change in volume) will be ``50`` in this case.
|
||||
current level.
|
||||
|
||||
``--audio-file-auto=<no|exact|fuzzy|all>``, ``--no-audio-file-auto``
|
||||
Load additional audio files matching the video filename. The parameter
|
||||
|
||||
@@ -69,10 +69,10 @@ bool mixer_audio_initialized(struct mixer *mixer)
|
||||
return !!mixer->ao;
|
||||
}
|
||||
|
||||
float mixer_getneutralvolume(struct mixer *mixer)
|
||||
float mixer_getmaxvolume(struct mixer *mixer)
|
||||
{
|
||||
// gain == 1
|
||||
return mixer->softvol ? 1.0 / mixer->opts->softvol_max * 100.0 * 100.0 : 100;
|
||||
return mixer->softvol ? mixer->opts->softvol_max : 100;
|
||||
}
|
||||
|
||||
static void checkvolume(struct mixer *mixer)
|
||||
@@ -85,8 +85,8 @@ static void checkvolume(struct mixer *mixer)
|
||||
float gain;
|
||||
if (!af_control_any_rev(mixer->af, AF_CONTROL_GET_VOLUME, &gain))
|
||||
gain = 1.0;
|
||||
vol.left = (gain / (mixer->opts->softvol_max / 100.0)) * 100.0;
|
||||
vol.right = (gain / (mixer->opts->softvol_max / 100.0)) * 100.0;
|
||||
vol.left = gain * 100.0;
|
||||
vol.right = gain * 100.0;
|
||||
} else {
|
||||
MP_DBG(mixer, "Reading volume from AO.\n");
|
||||
// Rely on the values not changing if the query is not supported
|
||||
@@ -122,14 +122,14 @@ void mixer_getvolume(struct mixer *mixer, float *l, float *r)
|
||||
|
||||
static void setvolume_internal(struct mixer *mixer, float l, float r)
|
||||
{
|
||||
struct ao_control_vol vol = {.left = l, .right = r};
|
||||
if (!mixer->softvol) {
|
||||
MP_DBG(mixer, "Setting volume on AO.\n");
|
||||
struct ao_control_vol vol = {.left = l, .right = r};
|
||||
if (ao_control(mixer->ao, AOCONTROL_SET_VOLUME, &vol) != CONTROL_OK)
|
||||
MP_ERR(mixer, "Failed to change audio output volume.\n");
|
||||
return;
|
||||
}
|
||||
float gain = (l + r) / 2.0 / 100.0 * mixer->opts->softvol_max / 100.0;
|
||||
float gain = (l + r) / 2.0 / 100.0;
|
||||
if (!af_control_any_rev(mixer->af, AF_CONTROL_SET_VOLUME, &gain)) {
|
||||
if (gain == 1.0)
|
||||
return;
|
||||
@@ -144,8 +144,9 @@ void mixer_setvolume(struct mixer *mixer, float l, float r)
|
||||
{
|
||||
checkvolume(mixer); // to check mute status
|
||||
|
||||
mixer->vol_l = av_clipf(l, 0, 100);
|
||||
mixer->vol_r = av_clipf(r, 0, 100);
|
||||
float max = mixer_getmaxvolume(mixer);
|
||||
mixer->vol_l = MPCLAMP(l, 0, max);
|
||||
mixer->vol_r = MPCLAMP(r, 0, max);
|
||||
if (mixer->ao && !(mixer->emulate_mute && mixer->muted))
|
||||
setvolume_internal(mixer, mixer->vol_l, mixer->vol_r);
|
||||
}
|
||||
@@ -242,9 +243,8 @@ char *mixer_get_volume_restore_data(struct mixer *mixer)
|
||||
{
|
||||
if (!mixer->driver[0])
|
||||
return NULL;
|
||||
return talloc_asprintf(NULL, "%s:%f:%f:%d:%f", mixer->driver, mixer->vol_l,
|
||||
mixer->vol_r, mixer->muted_by_us,
|
||||
mixer->opts->softvol_max);
|
||||
return talloc_asprintf(NULL, "%s:%f:%f:%d", mixer->driver, mixer->vol_l,
|
||||
mixer->vol_r, mixer->muted_by_us);
|
||||
}
|
||||
|
||||
static void probe_softvol(struct mixer *mixer)
|
||||
@@ -315,11 +315,10 @@ static void restore_volume(struct mixer *mixer)
|
||||
char *data = mixer->opts->mixer_restore_volume_data;
|
||||
if (!mixer->persistent_volume && data && data[0]) {
|
||||
char drv[40];
|
||||
float v_l, v_r, s;
|
||||
float v_l, v_r;
|
||||
int m;
|
||||
if (sscanf(data, "%39[^:]:%f:%f:%d:%f", drv, &v_l, &v_r, &m, &s) == 5) {
|
||||
float diff = fabs(mixer->opts->softvol_max - s);
|
||||
if (strcmp(mixer->driver, drv) == 0 && diff < 0.01) {
|
||||
if (sscanf(data, "%39[^:]:%f:%f:%d", drv, &v_l, &v_r, &m) == 5) {
|
||||
if (strcmp(mixer->driver, drv) == 0) {
|
||||
force_vol_l = v_l;
|
||||
force_vol_r = v_r;
|
||||
force_mute = !!m;
|
||||
|
||||
@@ -44,7 +44,7 @@ void mixer_setmute(struct mixer *mixer, bool mute);
|
||||
bool mixer_getmute(struct mixer *mixer);
|
||||
void mixer_getbalance(struct mixer *mixer, float *bal);
|
||||
void mixer_setbalance(struct mixer *mixer, float bal);
|
||||
float mixer_getneutralvolume(struct mixer *mixer);
|
||||
float mixer_getmaxvolume(struct mixer *mixer);
|
||||
char *mixer_get_volume_restore_data(struct mixer *mixer);
|
||||
|
||||
#endif /* MPLAYER_MIXER_H */
|
||||
|
||||
@@ -379,8 +379,8 @@ const m_option_t mp_opts[] = {
|
||||
({"no", SOFTVOL_NO},
|
||||
{"yes", SOFTVOL_YES},
|
||||
{"auto", SOFTVOL_AUTO})),
|
||||
OPT_FLOATRANGE("softvol-max", softvol_max, 0, 10, 10000),
|
||||
OPT_FLOATRANGE("volume", mixer_init_volume, 0, -1, 100),
|
||||
OPT_FLOATRANGE("softvol-max", softvol_max, 0, 100, 10000),
|
||||
OPT_FLOATRANGE("volume", mixer_init_volume, 0, -1, 10000),
|
||||
OPT_CHOICE("mute", mixer_init_mute, 0,
|
||||
({"auto", -1},
|
||||
{"no", 0},
|
||||
|
||||
@@ -1480,11 +1480,11 @@ static int mp_property_volume(void *ctx, struct m_property *prop,
|
||||
.type = CONF_TYPE_FLOAT,
|
||||
.flags = M_OPT_RANGE,
|
||||
.min = 0,
|
||||
.max = 100,
|
||||
.max = mixer_getmaxvolume(mpctx->mixer),
|
||||
};
|
||||
return M_PROPERTY_OK;
|
||||
case M_PROPERTY_GET_NEUTRAL:
|
||||
*(float *)arg = mixer_getneutralvolume(mpctx->mixer);
|
||||
*(float *)arg = 100;
|
||||
return M_PROPERTY_OK;
|
||||
case M_PROPERTY_PRINT: {
|
||||
float val;
|
||||
|
||||
Reference in New Issue
Block a user