Mercurial > mplayer.hg
annotate mixer.c @ 1026:435feedf9f89
Did some cleanup around STREAMING defined.
author | bertrand |
---|---|
date | Tue, 05 Jun 2001 08:42:16 +0000 |
parents | 72cacd3b8f30 |
children | b36fb1ae4b53 |
rev | line source |
---|---|
441 | 1 |
2 #include <string.h> | |
3 #include <sys/ioctl.h> | |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
4 #ifdef __sun |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
5 #include <sys/audioio.h> |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
6 #else |
441 | 7 #include <sys/soundcard.h> |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
8 #endif |
441 | 9 #include <fcntl.h> |
10 #include <stdio.h> | |
605 | 11 #include <unistd.h> |
441 | 12 |
13 #include "mixer.h" | |
14 | |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
15 #ifdef __sun |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
16 char * mixer_device="/dev/audioctl"; |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
17 #else |
556 | 18 char * mixer_device="/dev/mixer"; |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
19 #endif |
441 | 20 int mixer_usemaster=0; |
21 | |
22 void mixer_getvolume( int *l,int *r ) | |
23 { | |
24 int fd,v,cmd,devs; | |
25 | |
512 | 26 fd=open( mixer_device,O_RDONLY ); |
441 | 27 if ( fd != -1 ) |
28 { | |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
29 #ifdef __sun |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
30 audio_info_t info; |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
31 ioctl( fd,AUDIO_GETINFO,&info ); |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
32 *r=*l=(info.play.gain * 100 + (AUDIO_MAX_GAIN-1))/AUDIO_MAX_GAIN; |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
33 #else |
441 | 34 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs ); |
35 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_READ_PCM; | |
36 else | |
37 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_READ_VOLUME; | |
38 else | |
39 { | |
40 close( fd ); | |
41 return; | |
42 } | |
43 ioctl( fd,cmd,&v ); | |
44 *r=( v & 0xFF00 ) >> 8; | |
45 *l=( v & 0x00FF ); | |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
46 #endif |
441 | 47 close( fd ); |
48 } | |
49 } | |
50 | |
51 void mixer_setvolume( int l,int r ) | |
52 { | |
53 int fd,v,cmd,devs; | |
54 | |
512 | 55 fd=open( mixer_device,O_RDONLY ); |
441 | 56 if ( fd != -1 ) |
57 { | |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
58 #ifdef __sun |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
59 audio_info_t info; |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
60 ioctl( fd,AUDIO_GETINFO,&info ); |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
61 info.play.gain = ((l+r)*AUDIO_MAX_GAIN+199)/200; |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
62 ioctl( fd,AUDIO_SETINFO,&info ); |
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
63 #else |
441 | 64 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs ); |
65 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_WRITE_PCM; | |
66 else | |
67 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_WRITE_VOLUME; | |
68 else | |
69 { | |
70 close( fd ); | |
71 return; | |
72 } | |
73 v=( r << 8 ) | l; | |
74 ioctl( fd,cmd,&v ); | |
1020
72cacd3b8f30
Solaris 8 support - patch by Marcus Comstedt <marcus@idonex.se>
arpi_esp
parents:
605
diff
changeset
|
75 #endif |
441 | 76 close( fd ); |
77 } | |
78 } | |
79 | |
80 int mixer_l=0; int mixer_r=0; | |
81 | |
82 void mixer_incvolume( void ) | |
83 { | |
84 mixer_getvolume( &mixer_l,&mixer_r ); | |
85 if ( mixer_l < 100 ) mixer_l++; | |
86 if ( mixer_r < 100 ) mixer_r++; | |
87 mixer_setvolume( mixer_l,mixer_r ); | |
88 } | |
89 | |
90 void mixer_decvolume( void ) | |
91 { | |
92 mixer_getvolume( &mixer_l,&mixer_r ); | |
93 if ( mixer_l > 0 ) mixer_l--; | |
94 if ( mixer_r > 0 ) mixer_r--; | |
95 mixer_setvolume( mixer_l,mixer_r ); | |
96 } | |
97 | |
98 int mixer_getbothvolume( void ) | |
99 { | |
100 mixer_getvolume( &mixer_l,&mixer_r ); | |
101 return ( mixer_l + mixer_r ) / 2; | |
102 } |