Mercurial > mplayer.hg
annotate mixer.c @ 2886:b5fde2e72aef
typo fix
author | gabucino |
---|---|
date | Tue, 13 Nov 2001 23:17:31 +0000 |
parents | d75b24bda7ce |
children | fb74b1540900 |
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 | |
1061 | 11 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
12 #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
|
13 |
1061 | 14 /* |
15 * Mixer interface using OSS style soundcard commands. | |
16 */ | |
17 | |
18 #include <sys/soundcard.h> | |
19 | |
20 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
21 char * mixer_device=DEV_MIXER; |
441 | 22 int mixer_usemaster=0; |
23 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
24 void mixer_getvolume( float *l,float *r ) |
441 | 25 { |
26 int fd,v,cmd,devs; | |
27 | |
512 | 28 fd=open( mixer_device,O_RDONLY ); |
441 | 29 if ( fd != -1 ) |
30 { | |
31 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs ); | |
32 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_READ_PCM; | |
33 else | |
34 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_READ_VOLUME; | |
35 else | |
36 { | |
37 close( fd ); | |
38 return; | |
39 } | |
40 ioctl( fd,cmd,&v ); | |
41 *r=( v & 0xFF00 ) >> 8; | |
42 *l=( v & 0x00FF ); | |
43 close( fd ); | |
44 } | |
45 } | |
46 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
47 void mixer_setvolume( float l,float r ) |
441 | 48 { |
49 int fd,v,cmd,devs; | |
50 | |
512 | 51 fd=open( mixer_device,O_RDONLY ); |
441 | 52 if ( fd != -1 ) |
53 { | |
54 ioctl( fd,SOUND_MIXER_READ_DEVMASK,&devs ); | |
55 if ( ( devs & SOUND_MASK_PCM ) && ( mixer_usemaster==0 ) ) cmd=SOUND_MIXER_WRITE_PCM; | |
56 else | |
57 if ( ( devs & SOUND_MASK_VOLUME ) && ( mixer_usemaster==1 ) ) cmd=SOUND_MIXER_WRITE_VOLUME; | |
58 else | |
59 { | |
60 close( fd ); | |
61 return; | |
62 } | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
63 v=( (int)r << 8 ) | (int)l; |
441 | 64 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
|
65 close( fd ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
66 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
67 } |
1061 | 68 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
69 #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
|
70 |
1061 | 71 /* |
72 * Mixer interface using Sun style soundcard commands. | |
73 */ | |
74 | |
75 #include <sys/audioio.h> | |
76 | |
77 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
78 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
|
79 int mixer_usemaster=0; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
80 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
81 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
|
82 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
83 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
|
84 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
85 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
|
86 if ( fd != -1 ) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
87 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
88 struct audio_info info; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
89 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
90 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
|
91 *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
|
92 *l=info.play.gain * 100. / AUDIO_MAX_GAIN; |
441 | 93 close( fd ); |
94 } | |
95 } | |
96 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
97 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
|
98 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
99 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
|
100 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
101 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
|
102 if ( fd != -1 ) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
103 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
104 struct audio_info info; |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
105 AUDIO_INITINFO(&info); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
106 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
|
107 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
|
108 close( fd ); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
109 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
110 } |
1061 | 111 |
112 #else | |
113 | |
114 /* | |
115 * No usable Mixer interface selected. | |
116 * Just some stub routines. | |
117 */ | |
118 | |
119 char * mixer_device=NULL; | |
120 int mixer_usemaster=0; | |
121 | |
122 void mixer_getvolume( float *l,float *r ){ | |
123 *l = *r = 50.0; | |
124 } | |
125 void mixer_setvolume( float l,float r ){ | |
126 } | |
127 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
128 #endif |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
129 |
1881
d75b24bda7ce
Applied fix for mixercontrol w/alsa ossemu by Christian Ohm.
atmos4
parents:
1061
diff
changeset
|
130 #define MIXER_CHANGE 3 |
441 | 131 |
132 void mixer_incvolume( void ) | |
133 { | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
134 float mixer_l, mixer_r; |
441 | 135 mixer_getvolume( &mixer_l,&mixer_r ); |
1881
d75b24bda7ce
Applied fix for mixercontrol w/alsa ossemu by Christian Ohm.
atmos4
parents:
1061
diff
changeset
|
136 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
|
137 if ( mixer_l > 100 ) mixer_l = 100; |
1881
d75b24bda7ce
Applied fix for mixercontrol w/alsa ossemu by Christian Ohm.
atmos4
parents:
1061
diff
changeset
|
138 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
|
139 if ( mixer_r > 100 ) mixer_r = 100; |
441 | 140 mixer_setvolume( mixer_l,mixer_r ); |
141 } | |
142 | |
143 void mixer_decvolume( void ) | |
144 { | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
145 float mixer_l, mixer_r; |
441 | 146 mixer_getvolume( &mixer_l,&mixer_r ); |
1881
d75b24bda7ce
Applied fix for mixercontrol w/alsa ossemu by Christian Ohm.
atmos4
parents:
1061
diff
changeset
|
147 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
|
148 if ( mixer_l < 0 ) mixer_l = 0; |
1881
d75b24bda7ce
Applied fix for mixercontrol w/alsa ossemu by Christian Ohm.
atmos4
parents:
1061
diff
changeset
|
149 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
|
150 if ( mixer_r < 0 ) mixer_r = 0; |
441 | 151 mixer_setvolume( mixer_l,mixer_r ); |
152 } | |
153 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
154 float mixer_getbothvolume( void ) |
441 | 155 { |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
156 float mixer_l, mixer_r; |
441 | 157 mixer_getvolume( &mixer_l,&mixer_r ); |
158 return ( mixer_l + mixer_r ) / 2; | |
159 } |