441
|
1
|
|
2 #include <string.h>
|
|
3 #include <sys/ioctl.h>
|
|
4 #include <sys/soundcard.h>
|
|
5 #include <fcntl.h>
|
|
6 #include <stdio.h>
|
605
|
7 #include <unistd.h>
|
441
|
8
|
|
9 #include "mixer.h"
|
|
10
|
556
|
11 char * mixer_device="/dev/mixer";
|
441
|
12 int mixer_usemaster=0;
|
|
13
|
|
14 void mixer_getvolume( int *l,int *r )
|
|
15 {
|
|
16 int fd,v,cmd,devs;
|
|
17
|
512
|
18 fd=open( mixer_device,O_RDONLY );
|
441
|
19 if ( fd != -1 )
|
|
20 {
|
|
21 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
|
|
22 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_READ_PCM;
|
|
23 else
|
|
24 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_READ_VOLUME;
|
|
25 else
|
|
26 {
|
|
27 close( fd );
|
|
28 return;
|
|
29 }
|
|
30 ioctl( fd,cmd,&v );
|
|
31 *r=( v & 0xFF00 ) >> 8;
|
|
32 *l=( v & 0x00FF );
|
|
33 close( fd );
|
|
34 }
|
|
35 }
|
|
36
|
|
37 void mixer_setvolume( int l,int r )
|
|
38 {
|
|
39 int fd,v,cmd,devs;
|
|
40
|
512
|
41 fd=open( mixer_device,O_RDONLY );
|
441
|
42 if ( fd != -1 )
|
|
43 {
|
|
44 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs );
|
|
45 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_WRITE_PCM;
|
|
46 else
|
|
47 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_WRITE_VOLUME;
|
|
48 else
|
|
49 {
|
|
50 close( fd );
|
|
51 return;
|
|
52 }
|
|
53 v=( r << 8 ) | l;
|
|
54 ioctl( fd,cmd,&v );
|
|
55 close( fd );
|
|
56 }
|
|
57 }
|
|
58
|
|
59 int mixer_l=0; int mixer_r=0;
|
|
60
|
|
61 void mixer_incvolume( void )
|
|
62 {
|
|
63 mixer_getvolume( &mixer_l,&mixer_r );
|
|
64 if ( mixer_l < 100 ) mixer_l++;
|
|
65 if ( mixer_r < 100 ) mixer_r++;
|
|
66 mixer_setvolume( mixer_l,mixer_r );
|
|
67 }
|
|
68
|
|
69 void mixer_decvolume( void )
|
|
70 {
|
|
71 mixer_getvolume( &mixer_l,&mixer_r );
|
|
72 if ( mixer_l > 0 ) mixer_l--;
|
|
73 if ( mixer_r > 0 ) mixer_r--;
|
|
74 mixer_setvolume( mixer_l,mixer_r );
|
|
75 }
|
|
76
|
|
77 int mixer_getbothvolume( void )
|
|
78 {
|
|
79 mixer_getvolume( &mixer_l,&mixer_r );
|
|
80 return ( mixer_l + mixer_r ) / 2;
|
|
81 }
|