Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / wineoss.drv / mmaux.c
blobff62107f32d24c0fe9f409c8f1a0de94745151db
1 /*
2 * Sample AUXILIARY Wine Driver
4 * Copyright 1994 Martin Ayotte
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #include <fcntl.h>
31 #ifdef HAVE_SYS_IOCTL_H
32 # include <sys/ioctl.h>
33 #endif
35 #include "windef.h"
36 #include "winbase.h"
37 #include "mmddk.h"
38 #include "oss.h"
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(mmaux);
44 #ifdef HAVE_OSS
46 #define MIXER_DEV "/dev/mixer"
48 static int NumDev = 6;
50 /*-----------------------------------------------------------------------*/
52 LRESULT OSS_AuxInit(void)
54 int mixer;
55 TRACE("()\n");
57 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
58 WARN("mixer device not available !\n");
59 NumDev = 0;
60 } else {
61 close(mixer);
62 NumDev = 6;
64 return 0;
67 /*-----------------------------------------------------------------------*/
69 LRESULT OSS_AuxExit(void)
71 TRACE("()\n");
72 return 0;
75 /**************************************************************************
76 * AUX_GetDevCaps [internal]
78 static DWORD AUX_GetDevCaps(WORD wDevID, LPAUXCAPSW lpCaps, DWORD dwSize)
80 int mixer, volume;
81 static const WCHAR ini[] = {'O','S','S',' ','A','u','x',0};
83 TRACE("(%04X, %p, %u);\n", wDevID, lpCaps, dwSize);
84 if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
85 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
86 WARN("mixer device not available !\n");
87 return MMSYSERR_NOTENABLED;
89 if (ioctl(mixer, SOUND_MIXER_READ_LINE, &volume) == -1) {
90 close(mixer);
91 WARN("unable to read mixer !\n");
92 return MMSYSERR_NOTENABLED;
94 close(mixer);
95 lpCaps->wMid = 0xAA;
96 lpCaps->wPid = 0x55;
97 lpCaps->vDriverVersion = 0x0100;
98 strcpyW(lpCaps->szPname, ini);
99 lpCaps->wTechnology = AUXCAPS_CDAUDIO;
100 lpCaps->dwSupport = AUXCAPS_VOLUME | AUXCAPS_LRVOLUME;
102 return MMSYSERR_NOERROR;
106 /**************************************************************************
107 * AUX_GetVolume [internal]
109 static DWORD AUX_GetVolume(WORD wDevID, LPDWORD lpdwVol)
111 int mixer, volume, left, right, cmd;
113 TRACE("(%04X, %p);\n", wDevID, lpdwVol);
114 if (lpdwVol == NULL) return MMSYSERR_NOTENABLED;
115 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
116 WARN("mixer device not available !\n");
117 return MMSYSERR_NOTENABLED;
119 switch(wDevID) {
120 case 0:
121 TRACE("SOUND_MIXER_READ_PCM !\n");
122 cmd = SOUND_MIXER_READ_PCM;
123 break;
124 case 1:
125 TRACE("SOUND_MIXER_READ_SYNTH !\n");
126 cmd = SOUND_MIXER_READ_SYNTH;
127 break;
128 case 2:
129 TRACE("SOUND_MIXER_READ_CD !\n");
130 cmd = SOUND_MIXER_READ_CD;
131 break;
132 case 3:
133 TRACE("SOUND_MIXER_READ_LINE !\n");
134 cmd = SOUND_MIXER_READ_LINE;
135 break;
136 case 4:
137 TRACE("SOUND_MIXER_READ_MIC !\n");
138 cmd = SOUND_MIXER_READ_MIC;
139 break;
140 case 5:
141 TRACE("SOUND_MIXER_READ_VOLUME !\n");
142 cmd = SOUND_MIXER_READ_VOLUME;
143 break;
144 default:
145 WARN("invalid device id=%04X !\n", wDevID);
146 close(mixer);
147 return MMSYSERR_NOTENABLED;
149 if (ioctl(mixer, cmd, &volume) == -1) {
150 WARN("unable to read mixer !\n");
151 close(mixer);
152 return MMSYSERR_NOTENABLED;
154 close(mixer);
155 left = LOBYTE(LOWORD(volume));
156 right = HIBYTE(LOWORD(volume));
157 TRACE("left=%d right=%d !\n", left, right);
158 *lpdwVol = MAKELONG((left * 0xFFFFL) / 100, (right * 0xFFFFL) / 100);
159 return MMSYSERR_NOERROR;
162 /**************************************************************************
163 * AUX_SetVolume [internal]
165 static DWORD AUX_SetVolume(WORD wDevID, DWORD dwParam)
167 int mixer;
168 int volume, left, right;
169 int cmd;
171 TRACE("(%04X, %08X);\n", wDevID, dwParam);
173 left = (LOWORD(dwParam) * 100) >> 16;
174 right = (HIWORD(dwParam) * 100) >> 16;
175 volume = (right << 8) | left;
177 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
178 WARN("mixer device not available !\n");
179 return MMSYSERR_NOTENABLED;
182 switch(wDevID) {
183 case 0:
184 TRACE("SOUND_MIXER_WRITE_PCM !\n");
185 cmd = SOUND_MIXER_WRITE_PCM;
186 break;
187 case 1:
188 TRACE("SOUND_MIXER_WRITE_SYNTH !\n");
189 cmd = SOUND_MIXER_WRITE_SYNTH;
190 break;
191 case 2:
192 TRACE("SOUND_MIXER_WRITE_CD !\n");
193 cmd = SOUND_MIXER_WRITE_CD;
194 break;
195 case 3:
196 TRACE("SOUND_MIXER_WRITE_LINE !\n");
197 cmd = SOUND_MIXER_WRITE_LINE;
198 break;
199 case 4:
200 TRACE("SOUND_MIXER_WRITE_MIC !\n");
201 cmd = SOUND_MIXER_WRITE_MIC;
202 break;
203 case 5:
204 TRACE("SOUND_MIXER_WRITE_VOLUME !\n");
205 cmd = SOUND_MIXER_WRITE_VOLUME;
206 break;
207 default:
208 WARN("invalid device id=%04X !\n", wDevID);
209 close(mixer);
210 return MMSYSERR_NOTENABLED;
212 if (ioctl(mixer, cmd, &volume) == -1) {
213 WARN("unable to set mixer !\n");
214 close(mixer);
215 return MMSYSERR_NOTENABLED;
217 close(mixer);
218 return MMSYSERR_NOERROR;
221 #endif
223 /**************************************************************************
224 * auxMessage (WINEOSS.2)
226 DWORD WINAPI OSS_auxMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
227 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
229 TRACE("(%04X, %04X, %08lX, %08lX, %08lX);\n",
230 wDevID, wMsg, dwUser, dwParam1, dwParam2);
232 #ifdef HAVE_OSS
233 switch (wMsg) {
234 case DRVM_INIT:
235 case DRVM_EXIT:
236 case DRVM_ENABLE:
237 case DRVM_DISABLE:
238 /* FIXME: Pretend this is supported */
239 return 0;
240 case AUXDM_GETDEVCAPS:
241 return AUX_GetDevCaps(wDevID, (LPAUXCAPSW)dwParam1, dwParam2);
242 case AUXDM_GETNUMDEVS:
243 TRACE("return %d;\n", NumDev);
244 return NumDev;
245 case AUXDM_GETVOLUME:
246 return AUX_GetVolume(wDevID, (LPDWORD)dwParam1);
247 case AUXDM_SETVOLUME:
248 return AUX_SetVolume(wDevID, dwParam1);
249 default:
250 WARN("unknown message !\n");
252 return MMSYSERR_NOTSUPPORTED;
253 #else
254 return MMSYSERR_NOTENABLED;
255 #endif