mirror of
https://github.com/mpv-player/mpv
synced 2025-01-18 13:14:36 +00:00
mixer, af_volume: use linear values instead of dB
Softvol always used a linear multiplier for volume control. This was converted to dB, and then back to linear in af_volume. Remove this non- sense. We still try to keep the command line argument to af_volume in dB, though.
This commit is contained in:
parent
296531ad00
commit
4ba52a9e82
@ -81,17 +81,22 @@ static int control(struct af_instance* af, int cmd, void* arg)
|
||||
}
|
||||
return af_test_output(af,(struct mp_audio*)arg);
|
||||
case AF_CONTROL_COMMAND_LINE:{
|
||||
float v=0.0;
|
||||
float v=1000.0;
|
||||
float vol[AF_NCH];
|
||||
int i;
|
||||
sscanf((char*)arg,"%f:%i:%i", &v, &s->soft, &s->fast);
|
||||
for(i=0;i<AF_NCH;i++) vol[i]=v;
|
||||
float dest = 0.0;
|
||||
if (v < 1000)
|
||||
af_from_dB(1,&v,&dest,20.0,-200.0,60.0);
|
||||
for(i=0;i<AF_NCH;i++) vol[i]=dest;
|
||||
return control(af,AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, vol);
|
||||
}
|
||||
case AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET:
|
||||
return af_from_dB(AF_NCH,(float*)arg,s->level,20.0,-200.0,60.0);
|
||||
memcpy(s->level, arg, sizeof(float) * AF_NCH);
|
||||
return AF_OK;
|
||||
case AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_GET:
|
||||
return af_to_dB(AF_NCH,s->level,(float*)arg,20.0);
|
||||
memcpy(arg, s->level, sizeof(float) * AF_NCH);
|
||||
return AF_OK;
|
||||
case AF_CONTROL_PRE_DESTROY:{
|
||||
float m = 0.0;
|
||||
int i;
|
||||
|
@ -44,14 +44,12 @@ static void checkvolume(struct mixer *mixer)
|
||||
mixer->softvol = SOFTVOL_YES;
|
||||
if (!mixer->af)
|
||||
return;
|
||||
float db_vals[AF_NCH];
|
||||
float vals[AF_NCH];
|
||||
if (!af_control_any_rev(mixer->af,
|
||||
AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_GET, db_vals))
|
||||
db_vals[0] = db_vals[1] = 1.0;
|
||||
else
|
||||
af_from_dB(2, db_vals, db_vals, 20.0, -200.0, 60.0);
|
||||
vol.left = (db_vals[0] / (mixer->opts->softvol_max / 100.0)) * 100.0;
|
||||
vol.right = (db_vals[1] / (mixer->opts->softvol_max / 100.0)) * 100.0;
|
||||
AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_GET, vals))
|
||||
vals[0] = vals[1] = 1.0;
|
||||
vol.left = (vals[0] / (mixer->opts->softvol_max / 100.0)) * 100.0;
|
||||
vol.right = (vals[1] / (mixer->opts->softvol_max / 100.0)) * 100.0;
|
||||
}
|
||||
float l = mixer->vol_l;
|
||||
float r = mixer->vol_r;
|
||||
@ -99,24 +97,21 @@ static void setvolume_internal(mixer_t *mixer, float l, float r)
|
||||
mixer->restore_volume = "softvol";
|
||||
if (!mixer->af)
|
||||
return;
|
||||
// af_volume uses values in dB
|
||||
float db_vals[AF_NCH];
|
||||
int i;
|
||||
db_vals[0] = (l / 100.0) * (mixer->opts->softvol_max / 100.0);
|
||||
db_vals[1] = (r / 100.0) * (mixer->opts->softvol_max / 100.0);
|
||||
for (i = 2; i < AF_NCH; i++)
|
||||
db_vals[i] = ((l + r) / 100.0) * (mixer->opts->softvol_max / 100.0) / 2.0;
|
||||
af_to_dB(AF_NCH, db_vals, db_vals, 20.0);
|
||||
float vals[AF_NCH];
|
||||
vals[0] = l / 100.0 * mixer->opts->softvol_max / 100.0;
|
||||
vals[1] = r / 100.0 * mixer->opts->softvol_max / 100.0;
|
||||
for (int i = 2; i < AF_NCH; i++)
|
||||
vals[i] = (vals[0] + vals[1]) / 2.0;
|
||||
if (!af_control_any_rev(mixer->af,
|
||||
AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET,
|
||||
db_vals))
|
||||
vals))
|
||||
{
|
||||
mp_tmsg(MSGT_GLOBAL, mixer->softvol ? MSGL_V : MSGL_WARN,
|
||||
"[Mixer] No hardware mixing, inserting volume filter.\n");
|
||||
if (!(af_add(mixer->af, "volume", NULL)
|
||||
&& af_control_any_rev(mixer->af,
|
||||
AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET,
|
||||
db_vals)))
|
||||
vals)))
|
||||
mp_tmsg(MSGT_GLOBAL, MSGL_ERR,
|
||||
"[Mixer] No volume control available.\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user