From e2f2ca1cbb6fc68f67a2bcd3c76237be77f3e04e Mon Sep 17 00:00:00 2001 From: reimar Date: Sun, 14 Nov 2004 11:27:58 +0000 Subject: [PATCH] allow forcing of software volume control and setting maximum amplification. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@13934 b3059339-0415-0410-9bf9-f77b7e298cf2 --- DOCS/man/en/mplayer.1 | 12 ++++++++++++ cfg-mplayer.h | 3 +++ mixer.c | 20 +++++++++++--------- mixer.h | 2 ++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1 index 35ac530d9d..b05ad14154 100644 --- a/DOCS/man/en/mplayer.1 +++ b/DOCS/man/en/mplayer.1 @@ -1738,6 +1738,18 @@ ALSA mixer channel names followed by a number must be specified in the format, i.e.\& a channel labeled 'PCM 1' in alsamixer must be converted to .BR PCM,1 . +.TP +.B \-softvol +Force the use of the software mixer, instead of using the soundcard +mixer. +. +.TP +.B \-softvol-max <10.0\-10000.0> +Set the maximum amplification level in percent (default: 110). +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 starting volume (which is 100%) will be above +the maximum, which e.g. the OSD cannot display correctly. . .TP .B \-nowaveheader (\-ao pcm only) diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 53ec4e0d1a..5eb10c4922 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -174,6 +174,9 @@ m_option_t mplayer_opts[]={ {"dsp", "Use -ao oss:dsp_path.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL}, {"mixer", &mixer_device, CONF_TYPE_STRING, 0, 0, 0, NULL}, {"mixer-channel", &mixer_channel, CONF_TYPE_STRING, 0, 0, 0, NULL}, + {"softvol", &soft_vol, CONF_TYPE_FLAG, 0, 0, 1, NULL}, + {"nosoftvol", &soft_vol, CONF_TYPE_FLAG, 0, 1, 0, NULL}, + {"softvol-max", &soft_vol_max, CONF_TYPE_FLOAT, CONF_RANGE, 10, 10000, NULL}, {"volstep", &volstep, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL}, {"master", "Option -master has been removed, use -aop list=volume instead.\n", CONF_TYPE_PRINT, 0, 0, 0, NULL}, // override audio buffer size (used only by -ao oss, anyway obsolete...) diff --git a/mixer.c b/mixer.c index 388aadb2b3..f3de6cdeb7 100644 --- a/mixer.c +++ b/mixer.c @@ -15,13 +15,16 @@ char * mixer_device=NULL; char * mixer_channel=NULL; +int soft_vol = 0; +float soft_vol_max = 110.0; void mixer_getvolume(mixer_t *mixer, float *l, float *r) { ao_control_vol_t vol; *l=0; *r=0; if(mixer->audio_out){ - if(CONTROL_OK != mixer->audio_out->control(AOCONTROL_GET_VOLUME,&vol)) { + if(soft_vol || + CONTROL_OK != mixer->audio_out->control(AOCONTROL_GET_VOLUME,&vol)) { if (!mixer->afilter) return; else { @@ -31,8 +34,8 @@ void mixer_getvolume(mixer_t *mixer, float *l, float *r) 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] * 90.0; - vol.right = db_vals[1] * 90.0; + vol.left = (db_vals[0] / (soft_vol_max / 100.0)) * 100.0; + vol.right = (db_vals[1] / (soft_vol_max / 100.0)) * 100.0; } } *r=vol.right; @@ -45,19 +48,18 @@ void mixer_setvolume(mixer_t *mixer, float l, float r) ao_control_vol_t vol; vol.right=r; vol.left=l; if(mixer->audio_out){ - if(CONTROL_OK != mixer->audio_out->control(AOCONTROL_SET_VOLUME,&vol)) { + if(soft_vol || + CONTROL_OK != mixer->audio_out->control(AOCONTROL_SET_VOLUME,&vol)) { if (!mixer->afilter) return; else { // af_volume uses values in dB float db_vals[AF_NCH]; int i; - // a volume of 90% will give 0 dB (no change) - // like this, amplification is possible as well - db_vals[0] = l / 90.0; - db_vals[1] = r / 90.0; + db_vals[0] = (l / 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++) { - db_vals[i] = (l + r) / 180.0; + db_vals[i] = ((l + r) / 100.0) * (soft_vol_max / 100.0) / 2.0; } af_to_dB (AF_NCH, db_vals, db_vals, 20.0); if (!af_control_any_rev(mixer->afilter, diff --git a/mixer.h b/mixer.h index 6c8bfdcc2a..26a9be18bd 100644 --- a/mixer.h +++ b/mixer.h @@ -6,6 +6,8 @@ extern char * mixer_device; extern char * mixer_channel; +extern int soft_vol; +extern float soft_vol_max; typedef struct mixer_s { ao_functions_t *audio_out;