[Mplayer-cvslog] CVS: main mplayer.c, 1.756, 1.757 mixer.c, 1.15, 1.16 mixer.h, 1.5, 1.6

Alex Beregszaszi syncmail at mplayerhq.hu
Sat Jun 26 11:14:22 CEST 2004


CVS change done by Alex Beregszaszi

Update of /cvsroot/mplayer/main
In directory mail:/var2/tmp/cvs-serv6074

Modified Files:
	mplayer.c mixer.c mixer.h 
Log Message:
New 'Mixer API' with ability to change volume through libaf (this part was written by Reimar Doffinger) and lesser global variables

Index: mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.756
retrieving revision 1.757
diff -u -r1.756 -r1.757
--- mplayer.c	10 Jun 2004 11:16:44 -0000	1.756
+++ mplayer.c	26 Jun 2004 09:14:20 -0000	1.757
@@ -524,6 +524,8 @@
 extern void mp_input_register_options(m_config_t* cfg);
 
 #include "mixer.h"
+static mixer_t mixer;
+
 #include "cfg-mplayer.h"
 
 void parse_cfgfiles( m_config_t* conf )
@@ -1902,6 +1904,9 @@
     }
 #endif
   }
+  mixer.audio_out = audio_out;
+  mixer.afilter = sh_audio->afilter;
+  mixer.volstep = 3;
 }
 
 current_module="av_init";
@@ -2488,7 +2493,7 @@
        edl_decision = 1;
        next_edl_record = next_edl_record->next;
      } else if( next_edl_record->action == EDL_MUTE ) {
-       mixer_mute();
+       mixer_mute(&mixer);
 #ifdef DEBUG_EDL
        printf( "\nEDL_MUTE: [%f]\n", next_edl_record->start_sec );
 #endif
@@ -2657,25 +2662,27 @@
 		
 		if( abs )
 		{
-			mixer_setvolume( (float)v, (float)v );
+			mixer_setvolume(&mixer, (float)v, (float)v );
 		} else {
       if(v > 0)
-	mixer_incvolume();
+	mixer_incvolume(&mixer);
       else
-	mixer_decvolume();
+	mixer_decvolume(&mixer);
 		}
 	  
 #ifdef USE_OSD
       if(osd_level && sh_video){
+        float vol;
 	osd_visible=sh_video->fps; // 1 sec
 	vo_osd_progbar_type=OSD_VOLUME;
-	vo_osd_progbar_value=(mixer_getbothvolume()*256.0)/100.0;
+	mixer_getbothvolume(&mixer, &vol);
+	vo_osd_progbar_value=(vol*256.0)/100.0;
 	vo_osd_changed(OSDTYPE_PROGBAR);
       }
 #endif
     } break;
     case MP_CMD_MUTE:
-      mixer_mute();
+      mixer_mute(&mixer);
       break;
     case MP_CMD_LOADFILE : {
       play_tree_t* e = play_tree_new();

Index: mixer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mixer.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- mixer.c	24 Jan 2004 11:53:52 -0000	1.15
+++ mixer.c	26 Jun 2004 09:14:20 -0000	1.16
@@ -1,4 +1,3 @@
-
 #include <string.h>
 #ifndef __MINGW32__
 #include <sys/ioctl.h>
@@ -8,82 +7,105 @@
 #include <unistd.h>
 
 #include "config.h"
-#include "mixer.h"
 #include "libao2/audio_out.h"
+#include "libaf/af.h"
+#include "mixer.h"
 
-extern ao_functions_t *audio_out;
+#include "help_mp.h"
 
 char * mixer_device=NULL;
 char * mixer_channel=NULL;
 
-int muted = 0;
-float mute_l = 0.0f;
-float mute_r = 0.0f;
-
-void mixer_getvolume( float *l,float *r )
+void mixer_getvolume(mixer_t *mixer, float *l, float *r)
 {
   ao_control_vol_t vol;
   *l=0; *r=0;
-  if(audio_out){
-    if(CONTROL_OK != audio_out->control(AOCONTROL_GET_VOLUME,&vol))
-      return;
+  if(mixer->audio_out){
+    if(CONTROL_OK != mixer->audio_out->control(AOCONTROL_GET_VOLUME,&vol)) {
+      if (!mixer->afilter)
+        return;
+      else {
+        float db_vals[AF_NCH];
+        if (!af_control_any_rev(mixer->afilter,
+               AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_GET, db_vals))
+          return;
+        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;
+      }
+    }
     *r=vol.right;
     *l=vol.left;
   }
 }
 
-void mixer_setvolume( float l,float r )
+void mixer_setvolume(mixer_t *mixer, float l, float r)
 {
   ao_control_vol_t vol;
   vol.right=r; vol.left=l;
-  if(audio_out){
-    if(CONTROL_OK != audio_out->control(AOCONTROL_SET_VOLUME,&vol))
-      return;
+  if(mixer->audio_out){
+    if(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;
+        for (i = 2; i < AF_NCH; i++) {
+          db_vals[i] = (l + r) / 180.0;
+        }
+        af_to_dB (AF_NCH, db_vals, db_vals, 20.0);
+        if (!af_control_any_rev(mixer->afilter,
+               AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, db_vals)) {
+          mp_msg(MSGT_GLOBAL, MSGL_HINT, MSGTR_NeedAfVolume);
+          return;
+	}
+      }
+    }
   }
- muted=0;
+ mixer->muted=0;
 }
 
-#define MIXER_CHANGE 3
-
-void mixer_incvolume( void )
+void mixer_incvolume(mixer_t *mixer)
 {
  float mixer_l, mixer_r;
- mixer_getvolume( &mixer_l,&mixer_r );
- mixer_l += MIXER_CHANGE;
+ mixer_getvolume(mixer, &mixer_l, &mixer_r);
+ mixer_l += mixer->volstep;
  if ( mixer_l > 100 ) mixer_l = 100;
- mixer_r += MIXER_CHANGE;
+ mixer_r += mixer->volstep;
  if ( mixer_r > 100 ) mixer_r = 100;
- mixer_setvolume( mixer_l,mixer_r );
+ mixer_setvolume(mixer, mixer_l, mixer_r);
 }
 
-void mixer_decvolume( void )
+void mixer_decvolume(mixer_t *mixer)
 {
  float mixer_l, mixer_r;
- mixer_getvolume( &mixer_l,&mixer_r );
- mixer_l -= MIXER_CHANGE;
+ mixer_getvolume(mixer, &mixer_l, &mixer_r);
+ mixer_l -= mixer->volstep;
  if ( mixer_l < 0 ) mixer_l = 0;
- mixer_r -= MIXER_CHANGE;
+ mixer_r -= mixer->volstep;
  if ( mixer_r < 0 ) mixer_r = 0;
- mixer_setvolume( mixer_l,mixer_r );
+ mixer_setvolume(mixer, mixer_l, mixer_r);
 }
 
-float mixer_getbothvolume( void )
+void mixer_getbothvolume(mixer_t *mixer, float *b)
 {
  float mixer_l, mixer_r;
- mixer_getvolume( &mixer_l,&mixer_r );
- return ( mixer_l + mixer_r ) / 2;
+ mixer_getvolume(mixer, &mixer_l, &mixer_r);
+ *b = ( mixer_l + mixer_r ) / 2;
 }
 
-void mixer_mute( void )
+void mixer_mute(mixer_t *mixer)
 {
- if ( muted ) mixer_setvolume( mute_l,mute_r );
+ if (mixer->muted) mixer_setvolume(mixer, mixer->last_l, mixer->last_r);
   else
    { 
-    mixer_getvolume( &mute_l,&mute_r );
-    mixer_setvolume( 0,0 );
-    muted=1;
+    mixer_getvolume(mixer, &mixer->last_l, &mixer->last_r);
+    mixer_setvolume(mixer, 0, 0);
+    mixer->muted=1;
    }
 }
-
-
-

Index: mixer.h
===================================================================
RCS file: /cvsroot/mplayer/main/mixer.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- mixer.h	24 Jan 2004 11:53:52 -0000	1.5
+++ mixer.h	26 Jun 2004 09:14:20 -0000	1.6
@@ -1,19 +1,28 @@
-
 #ifndef __MPLAYER_MIXER
 #define __MPLAYER_MIXER
 
+#include "libaf/af.h"
+#include "libao2/audio_out.h"
+
 extern char * mixer_device;
 extern char * mixer_channel;
-extern int    muted;
 
-extern void mixer_getvolume( float *l,float *r );
-extern void mixer_setvolume( float l,float r );
-extern void mixer_incvolume( void );
-extern void mixer_decvolume( void );
-extern float mixer_getbothvolume( void );
-void mixer_mute( void );
+typedef struct mixer_s {
+    ao_functions_t *audio_out;
+    af_stream_t *afilter;
+    int volstep;
+    int muted;
+    float last_l, last_r;
+} mixer_t;
+
+void mixer_getvolume(mixer_t *mixer, float *l, float *r);
+void mixer_setvolume(mixer_t *mixer, float l, float r);
+void mixer_incvolume(mixer_t *mixer);
+void mixer_decvolume(mixer_t *mixer);
+void mixer_getbothvolume(mixer_t *mixer, float *b);
+void mixer_mute(mixer_t *mixer);
 
 //extern void mixer_setbothvolume( int v );
-#define mixer_setbothvolume( v ) mixer_setvolume( v,v )
+#define mixer_setbothvolume(m, v) mixer_setvolume(m, v, v)
 
 #endif




More information about the MPlayer-cvslog mailing list