[MPlayer-dev-eng] [PATCH] forceable software volume control

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Thu Nov 4 17:31:40 CET 2004


Hi,
this patch allows to force the volume to be changed via af_volume
instead of hardware mixer. This should remove the last reason for
keeping aop (and I _really_ want that outdated crap out of CVS).

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: mixer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mixer.c,v
retrieving revision 1.18
diff -u -r1.18 mixer.c
--- mixer.c	28 Jul 2004 12:17:48 -0000	1.18
+++ mixer.c	4 Nov 2004 19:26:28 -0000
@@ -15,13 +15,16 @@
 
 char * mixer_device=NULL;
 char * mixer_channel=NULL;
+int soft_vol = 0;
+float soft_vol_normal = 90.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 @@
           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_normal;
+        vol.right = db_vals[1] * soft_vol_normal;
       }
     }
     *r=vol.right;
@@ -45,7 +48,8 @@
   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 {
@@ -54,10 +58,10 @@
         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 / soft_vol_normal;
+        db_vals[1] = r / soft_vol_normal;
         for (i = 2; i < AF_NCH; i++) {
-          db_vals[i] = (l + r) / 180.0;
+          db_vals[i] = (l + r) / (2 * soft_vol_normal);
         }
         af_to_dB (AF_NCH, db_vals, db_vals, 20.0);
         if (!af_control_any_rev(mixer->afilter,
Index: mixer.h
===================================================================
RCS file: /cvsroot/mplayer/main/mixer.h,v
retrieving revision 1.6
diff -u -r1.6 mixer.h
--- mixer.h	26 Jun 2004 09:14:20 -0000	1.6
+++ mixer.h	4 Nov 2004 19:26:28 -0000
@@ -6,6 +6,8 @@
 
 extern char * mixer_device;
 extern char * mixer_channel;
+extern int soft_vol;
+extern float soft_vol_normal;
 
 typedef struct mixer_s {
     ao_functions_t *audio_out;
Index: cfg-mplayer.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfg-mplayer.h,v
retrieving revision 1.230
diff -u -r1.230 cfg-mplayer.h
--- cfg-mplayer.h	28 Oct 2004 23:25:17 -0000	1.230
+++ cfg-mplayer.h	4 Nov 2004 19:26:29 -0000
@@ -174,6 +174,9 @@
 	{"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-normal", &soft_vol_normal, CONF_TYPE_FLOAT, CONF_RANGE, 10, 200, 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...)
Index: DOCS/man/en/mplayer.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/man/en/mplayer.1,v
retrieving revision 1.800
diff -u -r1.800 mplayer.1
--- DOCS/man/en/mplayer.1	2 Nov 2004 17:22:23 -0000	1.800
+++ DOCS/man/en/mplayer.1	4 Nov 2004 19:26:51 -0000
@@ -1738,6 +1738,18 @@
 <name,number> 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-norm <10.0\-200.0>
+Set volume bar position at which volume will not be changed (in percent)
+(default: 90).
+A value of 50 will allow you to adjust the volume up to a maximum of
+double the current level.
+Values above 100 can cause some weird behavior.
 .
 .TP
 .B \-nowaveheader (\-ao pcm only)


More information about the MPlayer-dev-eng mailing list