[Mplayer-cvslog] CVS: main/libao2 ao_sun.c,1.17,1.18

Jürgen Keil jkeil at mplayerhq.hu
Thu Sep 12 14:56:22 CEST 2002


Update of /cvsroot/mplayer/main/libao2
In directory mail:/var/tmp.root/cvs-serv12341

Modified Files:
	ao_sun.c 
Log Message:
- gui version of mplayer is using the audio 'control' function before(!) the
  audio-out module is initialized.  As a workaround, initialize the audio
  device pathnames in the control function, otherwise the mixer does not work
  in gmplayer.

- gui: Add support for left/right balance to the sun audio driver


Index: ao_sun.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_sun.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- ao_sun.c	3 Jul 2002 21:17:31 -0000	1.17
+++ ao_sun.c	12 Sep 2002 12:56:05 -0000	1.18
@@ -208,6 +208,24 @@
     return rtsc_ok;
 }
 
+static void setup_device_paths()
+{
+    if (audio_dev == NULL) {
+	if ((audio_dev = getenv("AUDIODEV")) == NULL)
+	    audio_dev = "/dev/audio";
+    }
+
+    if (sun_mixer_device == NULL) {
+	if ((sun_mixer_device = mixer_device) == NULL || !sun_mixer_device[0]) {
+	    sun_mixer_device = malloc(strlen(audio_dev) + 4);
+	    strcpy(sun_mixer_device, audio_dev);
+	    strcat(sun_mixer_device, "ctl");
+	}
+    }
+
+    if (ao_subdevice) audio_dev = ao_subdevice;
+}
+
 // to set/get/query special features/parameters
 static int control(int cmd,int arg){
     switch(cmd){
@@ -220,14 +238,27 @@
     {
         int fd,v,cmd,devs;
 
+	if ( !sun_mixer_device )    /* control function is used before init? */
+	    setup_device_paths();
+
 	fd=open( sun_mixer_device,O_RDONLY );
 	if ( fd != -1 )
 	{
 	    ao_control_vol_t *vol = (ao_control_vol_t *)arg;
+	    float volume;
 	    struct audio_info info;
 	    ioctl( fd,AUDIO_GETINFO,&info);
-	    vol->left=info.play.gain * 100. / AUDIO_MAX_GAIN;
-	    vol->right=info.play.gain * 100. / AUDIO_MAX_GAIN;
+	    volume = info.play.gain * 100. / AUDIO_MAX_GAIN;
+	    if ( info.play.balance == AUDIO_MID_BALANCE ) {
+		vol->right = vol->left = volume;
+	    } else if ( info.play.balance < AUDIO_MID_BALANCE ) {
+		vol->left  = volume;
+		vol->right = volume * info.play.balance / AUDIO_MID_BALANCE;
+	    } else {
+		vol->left  = volume * (AUDIO_RIGHT_BALANCE-info.play.balance)
+							/ AUDIO_MID_BALANCE;
+		vol->right = volume;
+	    }
 	    close( fd );
 	    return CONTROL_OK;
 	}	
@@ -238,12 +269,21 @@
 	ao_control_vol_t *vol = (ao_control_vol_t *)arg;
         int fd,v,cmd,devs;
 
+	if ( !sun_mixer_device )    /* control function is used before init? */
+	    setup_device_paths();
+
 	fd=open( sun_mixer_device,O_RDONLY );
 	if ( fd != -1 )
 	{
 	    struct audio_info info;
+	    float volume;
 	    AUDIO_INITINFO(&info);
-	    info.play.gain = (vol->right+vol->left) * AUDIO_MAX_GAIN / 100 / 2;
+	    volume = vol->right > vol->left ? vol->right : vol->left;
+	    info.play.gain = volume * AUDIO_MAX_GAIN / 100;
+	    if ( vol->right == vol->left )
+		info.play.balance = AUDIO_MID_BALANCE;
+	    else
+		info.play.balance = (vol->right - vol->left + volume) * AUDIO_RIGHT_BALANCE / (2*volume);
 	    ioctl( fd,AUDIO_SETINFO,&info );
 	    close( fd );
 	    return CONTROL_OK;
@@ -261,20 +301,7 @@
     audio_info_t info;
     int ok;
 
-    if (audio_dev == NULL) {
-	if ((audio_dev = getenv("AUDIODEV")) == NULL)
-	    audio_dev = "/dev/audio";
-    }
-
-    if (sun_mixer_device == NULL) {
-	if ((sun_mixer_device = mixer_device) == NULL) {
-	    sun_mixer_device = malloc(strlen(audio_dev) + 4);
-	    strcpy(sun_mixer_device, audio_dev);
-	    strcat(sun_mixer_device, "ctl");
-	}
-    }
-
-    if (ao_subdevice) audio_dev = ao_subdevice;
+    setup_device_paths();
 
     if (enable_sample_timing == RTSC_UNKNOWN
 	&& !getenv("AO_SUN_DISABLE_SAMPLE_TIMING")) {




More information about the MPlayer-cvslog mailing list