Mercurial > mplayer.hg
annotate mixer.c @ 4763:b85890a5b0e5
Added comments support in input.conf (comments lines with #)
And fixed a possible bug
author | albeu |
---|---|
date | Wed, 20 Feb 2002 14:45:18 +0000 |
parents | fb74b1540900 |
children | d678ce495a75 |
rev | line source |
---|---|
441 | 1 |
2 #include <string.h> | |
3 #include <sys/ioctl.h> | |
4 #include <fcntl.h> | |
5 #include <stdio.h> | |
605 | 6 #include <unistd.h> |
441 | 7 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
8 #include "config.h" |
441 | 9 #include "mixer.h" |
10 | |
4749 | 11 #ifdef HAVE_DVB |
12 #include <ost/audio.h> | |
13 audioMixer_t dvb_mixer={255,255}; | |
14 extern int vo_mpegpes_fd; | |
15 extern int vo_mpegpes_fd2; | |
16 #endif | |
1061 | 17 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
18 #if defined(USE_OSS_AUDIO) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
19 |
1061 | 20 /* |
21 * Mixer interface using OSS style soundcard commands. | |
22 */ | |
23 | |
24 #include <sys/soundcard.h> | |
25 | |
26 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
27 char * mixer_device=DEV_MIXER; |
441 | 28 int mixer_usemaster=0; |
29 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
30 void mixer_getvolume( float *l,float *r ) |
441 | 31 { |
32 int fd,v,cmd,devs; | |
33 | |
4749 | 34 #ifdef HAVE_DVB |
35 if(vo_mpegpes_fd2>=0){ | |
36 // DVB card | |
37 *l=dvb_mixer.volume_left/2.56; | |
38 *r=dvb_mixer.volume_right/2.56; | |
39 return; | |
40 } | |
41 #endif | |
42 | |
512 | 43 fd=open( mixer_device,O_RDONLY ); |
441 | 44 if ( fd != -1 ) |
45 { | |
46 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs ); | |
47 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_READ_PCM; | |
48 else | |
49 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_READ_VOLUME; | |
50 else | |
51 { | |
52 close( fd ); | |
53 return; | |
54 } | |
55 ioctl( fd,cmd,&v ); | |
56 *r=( v & 0xFF00 ) >> 8; | |
57 *l=( v & 0x00FF ); | |
58 close( fd ); | |
59 } | |
60 } | |
61 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
62 void mixer_setvolume( float l,float r ) |
441 | 63 { |
64 int fd,v,cmd,devs; | |
4749 | 65 |
66 #ifdef HAVE_DVB | |
67 if(vo_mpegpes_fd2>=0){ | |
68 // DVB card | |
69 dvb_mixer.volume_left=l*2.56; | |
70 dvb_mixer.volume_right=r*2.56; | |
71 if(dvb_mixer.volume_left>255) dvb_mixer.volume_left=255; | |
72 if(dvb_mixer.volume_right>255) dvb_mixer.volume_right=255; | |
73 // printf("Setting DVB volume: %d ; %d \n",dvb_mixer.volume_left,dvb_mixer.volume_right); | |
74 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SET_MIXER, &dvb_mixer) < 0)){ | |
75 perror("DVB AUDIO SET MIXER: "); | |
76 return -1; | |
77 } | |
78 return; | |
79 } | |
80 #endif | |
441 | 81 |
512 | 82 fd=open( mixer_device,O_RDONLY ); |
441 | 83 if ( fd != -1 ) |
84 { | |
85 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs ); | |
86 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_WRITE_PCM; | |
87 else | |
88 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_WRITE_VOLUME; | |
89 else | |
90 { | |
91 close( fd ); | |
92 return; | |
93 } | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
94 v=( (int)r << 8 ) | (int)l; |
441 | 95 ioctl( fd,cmd,&v ); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
96 close( fd ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
97 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
98 } |
1061 | 99 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
100 #elif defined(USE_SUN_AUDIO) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
101 |
1061 | 102 /* |
103 * Mixer interface using Sun style soundcard commands. | |
104 */ | |
105 | |
106 #include <sys/audioio.h> | |
107 | |
108 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
109 char * mixer_device="/dev/audioctl"; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
110 int mixer_usemaster=0; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
111 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
112 void mixer_getvolume( float *l,float *r ) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
113 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
114 int fd,v,cmd,devs; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
115 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
116 fd=open( mixer_device,O_RDONLY ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
117 if ( fd != -1 ) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
118 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
119 struct audio_info info; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
120 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
121 ioctl( fd,AUDIO_GETINFO,&info); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
122 *r=info.play.gain * 100. / AUDIO_MAX_GAIN; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
123 *l=info.play.gain * 100. / AUDIO_MAX_GAIN; |
441 | 124 close( fd ); |
125 } | |
126 } | |
127 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
128 void mixer_setvolume( float l,float r ) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
129 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
130 int fd,v,cmd,devs; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
131 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
132 fd=open( mixer_device,O_RDONLY ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
133 if ( fd != -1 ) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
134 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
135 struct audio_info info; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
136 AUDIO_INITINFO(&info); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
137 info.play.gain = (r+l) * AUDIO_MAX_GAIN / 100 / 2; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
138 ioctl( fd,AUDIO_SETINFO,&info ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
139 close( fd ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
140 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
141 } |
1061 | 142 |
143 #else | |
144 | |
145 /* | |
146 * No usable Mixer interface selected. | |
147 * Just some stub routines. | |
148 */ | |
149 | |
150 char * mixer_device=NULL; | |
151 int mixer_usemaster=0; | |
152 | |
153 void mixer_getvolume( float *l,float *r ){ | |
154 *l = *r = 50.0; | |
155 } | |
156 void mixer_setvolume( float l,float r ){ | |
157 } | |
158 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
159 #endif |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
160 |
1881
d75b24bda7ce
Applied fix for mixercontrol w/alsa ossemu by Christian Ohm.
atmos4
parents:
1061
diff
changeset
|
161 #define MIXER_CHANGE 3 |
441 | 162 |
163 void mixer_incvolume( void ) | |
164 { | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
165 float mixer_l, mixer_r; |
441 | 166 mixer_getvolume( &mixer_l,&mixer_r ); |
1881
d75b24bda7ce
Applied fix for mixercontrol w/alsa ossemu by Christian Ohm.
atmos4
parents:
1061
diff
changeset
|
167 mixer_l += MIXER_CHANGE; |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
168 if ( mixer_l > 100 ) mixer_l = 100; |
1881
d75b24bda7ce
Applied fix for mixercontrol w/alsa ossemu by Christian Ohm.
atmos4
parents:
1061
diff
changeset
|
169 mixer_r += MIXER_CHANGE; |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
170 if ( mixer_r > 100 ) mixer_r = 100; |
441 | 171 mixer_setvolume( mixer_l,mixer_r ); |
172 } | |
173 | |
174 void mixer_decvolume( void ) | |
175 { | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
176 float mixer_l, mixer_r; |
441 | 177 mixer_getvolume( &mixer_l,&mixer_r ); |
1881
d75b24bda7ce
Applied fix for mixercontrol w/alsa ossemu by Christian Ohm.
atmos4
parents:
1061
diff
changeset
|
178 mixer_l -= MIXER_CHANGE; |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
179 if ( mixer_l < 0 ) mixer_l = 0; |
1881
d75b24bda7ce
Applied fix for mixercontrol w/alsa ossemu by Christian Ohm.
atmos4
parents:
1061
diff
changeset
|
180 mixer_r -= MIXER_CHANGE; |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
181 if ( mixer_r < 0 ) mixer_r = 0; |
441 | 182 mixer_setvolume( mixer_l,mixer_r ); |
183 } | |
184 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
185 float mixer_getbothvolume( void ) |
441 | 186 { |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
187 float mixer_l, mixer_r; |
441 | 188 mixer_getvolume( &mixer_l,&mixer_r ); |
189 return ( mixer_l + mixer_r ) / 2; | |
190 } |