Mercurial > mplayer.hg
view mixer.c @ 1032:e34336f4feaf
add esd support and disabled default.
author | pontscho |
---|---|
date | Tue, 05 Jun 2001 10:37:50 +0000 |
parents | 72cacd3b8f30 |
children | b36fb1ae4b53 |
line wrap: on
line source
#include <string.h> #include <sys/ioctl.h> #ifdef __sun #include <sys/audioio.h> #else #include <sys/soundcard.h> #endif #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include "mixer.h" #ifdef __sun char * mixer_device="/dev/audioctl"; #else char * mixer_device="/dev/mixer"; #endif int mixer_usemaster=0; void mixer_getvolume( int *l,int *r ) { int fd,v,cmd,devs; fd=open( mixer_device,O_RDONLY ); if ( fd != -1 ) { #ifdef __sun audio_info_t info; ioctl( fd,AUDIO_GETINFO,&info ); *r=*l=(info.play.gain * 100 + (AUDIO_MAX_GAIN-1))/AUDIO_MAX_GAIN; #else 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 ); #endif close( fd ); } } void mixer_setvolume( int l,int r ) { int fd,v,cmd,devs; fd=open( mixer_device,O_RDONLY ); if ( fd != -1 ) { #ifdef __sun audio_info_t info; ioctl( fd,AUDIO_GETINFO,&info ); info.play.gain = ((l+r)*AUDIO_MAX_GAIN+199)/200; ioctl( fd,AUDIO_SETINFO,&info ); #else 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 ); #endif close( fd ); } } int mixer_l=0; int mixer_r=0; void mixer_incvolume( void ) { 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 ) { 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; }