summaryrefslogtreecommitdiffstats
path: root/mixer.c
diff options
context:
space:
mode:
authorgabucino <gabucino@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-04-15 18:37:07 +0000
committergabucino <gabucino@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-04-15 18:37:07 +0000
commit005b7e2844ddf1e855f5e423760319b7612a2605 (patch)
treea177bc994a975336f6afe3a0092e38254b53db5d /mixer.c
parent6ead487b065fb66adad951f585919a8258c6bf10 (diff)
downloadmpv-005b7e2844ddf1e855f5e423760319b7612a2605.tar.bz2
mpv-005b7e2844ddf1e855f5e423760319b7612a2605.tar.xz
ups, I missed'em..
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@442 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'mixer.c')
-rw-r--r--mixer.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/mixer.c b/mixer.c
new file mode 100644
index 0000000000..7b3206e0e5
--- /dev/null
+++ b/mixer.c
@@ -0,0 +1,91 @@
+
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/soundcard.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+#include "mixer.h"
+
+#define DEV_MIXER "/dev/mixer"
+
+char * mixer_device=NULL;
+char * devname=NULL;
+int mixer_usemaster=0;
+
+void mixer_getvolume( int *l,int *r )
+{
+ int fd,v,cmd,devs;
+
+ if ( !mixer_device ) devname=strdup( DEV_MIXER );
+ else devname=strdup( mixer_device );
+ fd=open( devname,O_RDONLY );
+ free( devname );
+ if ( fd != -1 )
+ {
+ ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
+ if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_READ_PCM;
+ else
+ if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_READ_VOLUME;
+ else
+ {
+ close( fd );
+ return;
+ }
+ ioctl( fd,cmd,&v );
+ *r=( v & 0xFF00 ) >> 8;
+ *l=( v & 0x00FF );
+ close( fd );
+ }
+}
+
+void mixer_setvolume( int l,int r )
+{
+ int fd,v,cmd,devs;
+
+ if ( !mixer_device ) devname=strdup( DEV_MIXER );
+ else devname=strdup( mixer_device );
+ fd=open( devname,O_RDONLY );
+ free( devname );
+ if ( fd != -1 )
+ {
+ ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
+ if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_WRITE_PCM;
+ else
+ if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_WRITE_VOLUME;
+ else
+ {
+ close( fd );
+ return;
+ }
+ v=( r << 8 ) | l;
+ ioctl( fd,cmd,&v );
+ close( fd );
+ }
+}
+
+int mixer_l=0; int mixer_r=0;
+
+void mixer_incvolume( void )
+{
+ fprintf( stderr,"[mixer] inc.\n" );
+ mixer_getvolume( &mixer_l,&mixer_r );
+ if ( mixer_l < 100 ) mixer_l++;
+ if ( mixer_r < 100 ) mixer_r++;
+ mixer_setvolume( mixer_l,mixer_r );
+}
+
+void mixer_decvolume( void )
+{
+ fprintf( stderr,"[mixer] dec.\n" );
+ mixer_getvolume( &mixer_l,&mixer_r );
+ if ( mixer_l > 0 ) mixer_l--;
+ if ( mixer_r > 0 ) mixer_r--;
+ mixer_setvolume( mixer_l,mixer_r );
+}
+
+int mixer_getbothvolume( void )
+{
+ mixer_getvolume( &mixer_l,&mixer_r );
+ return ( mixer_l + mixer_r ) / 2;
+}