2001-04-15 18:37:07 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
2001-04-23 23:46:24 +00:00
|
|
|
#include <unistd.h>
|
2001-04-15 18:37:07 +00:00
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
#include "config.h"
|
2001-06-08 23:36:58 +00:00
|
|
|
#include "mixer.h"
|
2001-04-15 18:37:07 +00:00
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
|
2001-06-08 23:36:58 +00:00
|
|
|
#if defined(USE_OSS_AUDIO)
|
2001-06-05 18:40:44 +00:00
|
|
|
|
2001-06-08 23:36:58 +00:00
|
|
|
/*
|
|
|
|
* Mixer interface using OSS style soundcard commands.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/soundcard.h>
|
2001-06-05 18:40:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
char * mixer_device=DEV_MIXER;
|
2001-04-15 18:37:07 +00:00
|
|
|
int mixer_usemaster=0;
|
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
void mixer_getvolume( float *l,float *r )
|
2001-04-15 18:37:07 +00:00
|
|
|
{
|
|
|
|
int fd,v,cmd,devs;
|
|
|
|
|
2001-04-18 20:39:04 +00:00
|
|
|
fd=open( mixer_device,O_RDONLY );
|
2001-04-15 18:37:07 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
void mixer_setvolume( float l,float r )
|
2001-04-15 18:37:07 +00:00
|
|
|
{
|
|
|
|
int fd,v,cmd,devs;
|
|
|
|
|
2001-04-18 20:39:04 +00:00
|
|
|
fd=open( mixer_device,O_RDONLY );
|
2001-04-15 18:37:07 +00:00
|
|
|
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;
|
|
|
|
}
|
2001-06-05 18:40:44 +00:00
|
|
|
v=( (int)r << 8 ) | (int)l;
|
2001-04-15 18:37:07 +00:00
|
|
|
ioctl( fd,cmd,&v );
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
}
|
2001-06-08 23:36:58 +00:00
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
#elif defined(USE_SUN_AUDIO)
|
|
|
|
|
2001-06-08 23:36:58 +00:00
|
|
|
/*
|
|
|
|
* Mixer interface using Sun style soundcard commands.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/audioio.h>
|
|
|
|
|
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
char * mixer_device="/dev/audioctl";
|
|
|
|
int mixer_usemaster=0;
|
|
|
|
|
|
|
|
void mixer_getvolume( float *l,float *r )
|
|
|
|
{
|
|
|
|
int fd,v,cmd,devs;
|
|
|
|
|
|
|
|
fd=open( mixer_device,O_RDONLY );
|
|
|
|
if ( fd != -1 )
|
|
|
|
{
|
|
|
|
struct audio_info info;
|
|
|
|
|
|
|
|
ioctl( fd,AUDIO_GETINFO,&info);
|
|
|
|
*r=info.play.gain * 100. / AUDIO_MAX_GAIN;
|
|
|
|
*l=info.play.gain * 100. / AUDIO_MAX_GAIN;
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mixer_setvolume( float l,float r )
|
|
|
|
{
|
|
|
|
int fd,v,cmd,devs;
|
|
|
|
|
|
|
|
fd=open( mixer_device,O_RDONLY );
|
|
|
|
if ( fd != -1 )
|
|
|
|
{
|
|
|
|
struct audio_info info;
|
|
|
|
AUDIO_INITINFO(&info);
|
|
|
|
info.play.gain = (r+l) * AUDIO_MAX_GAIN / 100 / 2;
|
|
|
|
ioctl( fd,AUDIO_SETINFO,&info );
|
|
|
|
close( fd );
|
|
|
|
}
|
|
|
|
}
|
2001-06-08 23:36:58 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No usable Mixer interface selected.
|
|
|
|
* Just some stub routines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char * mixer_device=NULL;
|
|
|
|
int mixer_usemaster=0;
|
|
|
|
|
|
|
|
void mixer_getvolume( float *l,float *r ){
|
|
|
|
*l = *r = 50.0;
|
|
|
|
}
|
|
|
|
void mixer_setvolume( float l,float r ){
|
|
|
|
}
|
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
#endif
|
2001-04-15 18:37:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
void mixer_incvolume( void )
|
|
|
|
{
|
2001-06-05 18:40:44 +00:00
|
|
|
float mixer_l, mixer_r;
|
2001-04-15 18:37:07 +00:00
|
|
|
mixer_getvolume( &mixer_l,&mixer_r );
|
2001-06-05 18:40:44 +00:00
|
|
|
mixer_l++;
|
|
|
|
if ( mixer_l > 100 ) mixer_l = 100;
|
|
|
|
mixer_r++;
|
|
|
|
if ( mixer_r > 100 ) mixer_r = 100;
|
2001-04-15 18:37:07 +00:00
|
|
|
mixer_setvolume( mixer_l,mixer_r );
|
|
|
|
}
|
|
|
|
|
|
|
|
void mixer_decvolume( void )
|
|
|
|
{
|
2001-06-05 18:40:44 +00:00
|
|
|
float mixer_l, mixer_r;
|
2001-04-15 18:37:07 +00:00
|
|
|
mixer_getvolume( &mixer_l,&mixer_r );
|
2001-06-05 18:40:44 +00:00
|
|
|
mixer_l--;
|
|
|
|
if ( mixer_l < 0 ) mixer_l = 0;
|
|
|
|
mixer_r--;
|
|
|
|
if ( mixer_r < 0 ) mixer_r = 0;
|
2001-04-15 18:37:07 +00:00
|
|
|
mixer_setvolume( mixer_l,mixer_r );
|
|
|
|
}
|
|
|
|
|
2001-06-05 18:40:44 +00:00
|
|
|
float mixer_getbothvolume( void )
|
2001-04-15 18:37:07 +00:00
|
|
|
{
|
2001-06-05 18:40:44 +00:00
|
|
|
float mixer_l, mixer_r;
|
2001-04-15 18:37:07 +00:00
|
|
|
mixer_getvolume( &mixer_l,&mixer_r );
|
|
|
|
return ( mixer_l + mixer_r ) / 2;
|
|
|
|
}
|