rasapi32: Update spec file.
[wine/zf.git] / dlls / wineoss.drv / mmaux.c
blob9554ee72dbccb1e6ff20be5b2a0e9e01f7c051fd
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
34 #include <sys/soundcard.h>
36 #include "windef.h"
37 #include "winbase.h"
38 #include "mmddk.h"
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(mmaux);
44 #define MIXER_DEV "/dev/mixer"
46 static int NumDev = 6;
48 /*-----------------------------------------------------------------------*/
50 static LRESULT OSS_AuxInit(void)
52 int mixer;
53 TRACE("()\n");
55 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
56 WARN("mixer device not available !\n");
57 NumDev = 0;
58 } else {
59 close(mixer);
60 NumDev = 6;
62 return 0;
65 /*-----------------------------------------------------------------------*/
67 static LRESULT OSS_AuxExit(void)
69 TRACE("()\n");
70 return 0;
73 /**************************************************************************
74 * AUX_GetDevCaps [internal]
76 static DWORD AUX_GetDevCaps(WORD wDevID, LPAUXCAPSW lpCaps, DWORD dwSize)
78 int mixer, volume;
79 static const WCHAR ini[] = {'O','S','S',' ','A','u','x',' ','#','0',0};
81 TRACE("(%04X, %p, %u);\n", wDevID, lpCaps, dwSize);
82 if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
83 if (wDevID >= NumDev) return MMSYSERR_BADDEVICEID;
84 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
85 WARN("mixer device not available !\n");
86 return MMSYSERR_NOTENABLED;
88 if (ioctl(mixer, SOUND_MIXER_READ_LINE, &volume) == -1) {
89 close(mixer);
90 WARN("unable to read mixer !\n");
91 return MMSYSERR_NOTENABLED;
93 close(mixer);
94 lpCaps->wMid = 0xAA;
95 lpCaps->wPid = 0x55 + wDevID;
96 lpCaps->vDriverVersion = 0x0100;
97 strcpyW(lpCaps->szPname, ini);
98 lpCaps->szPname[9] = '0' + wDevID; /* 6 at max */
99 lpCaps->wTechnology = wDevID == 2 ? AUXCAPS_CDAUDIO : AUXCAPS_AUXIN;
100 lpCaps->wReserved1 = 0;
101 lpCaps->dwSupport = AUXCAPS_VOLUME | AUXCAPS_LRVOLUME;
103 return MMSYSERR_NOERROR;
107 /**************************************************************************
108 * AUX_GetVolume [internal]
110 static DWORD AUX_GetVolume(WORD wDevID, LPDWORD lpdwVol)
112 int mixer, volume, left, right, cmd;
114 TRACE("(%04X, %p);\n", wDevID, lpdwVol);
115 if (lpdwVol == NULL) return MMSYSERR_NOTENABLED;
116 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
117 WARN("mixer device not available !\n");
118 return MMSYSERR_NOTENABLED;
120 switch(wDevID) {
121 case 0:
122 TRACE("SOUND_MIXER_READ_PCM !\n");
123 cmd = SOUND_MIXER_READ_PCM;
124 break;
125 case 1:
126 TRACE("SOUND_MIXER_READ_SYNTH !\n");
127 cmd = SOUND_MIXER_READ_SYNTH;
128 break;
129 case 2:
130 TRACE("SOUND_MIXER_READ_CD !\n");
131 cmd = SOUND_MIXER_READ_CD;
132 break;
133 case 3:
134 TRACE("SOUND_MIXER_READ_LINE !\n");
135 cmd = SOUND_MIXER_READ_LINE;
136 break;
137 case 4:
138 TRACE("SOUND_MIXER_READ_MIC !\n");
139 cmd = SOUND_MIXER_READ_MIC;
140 break;
141 case 5:
142 TRACE("SOUND_MIXER_READ_VOLUME !\n");
143 cmd = SOUND_MIXER_READ_VOLUME;
144 break;
145 default:
146 WARN("invalid device id=%04X !\n", wDevID);
147 close(mixer);
148 return MMSYSERR_NOTENABLED;
150 if (ioctl(mixer, cmd, &volume) == -1) {
151 WARN("unable to read mixer !\n");
152 close(mixer);
153 return MMSYSERR_NOTENABLED;
155 close(mixer);
156 left = LOBYTE(LOWORD(volume));
157 right = HIBYTE(LOWORD(volume));
158 TRACE("left=%d right=%d !\n", left, right);
159 *lpdwVol = MAKELONG((left * 0xFFFFL) / 100, (right * 0xFFFFL) / 100);
160 return MMSYSERR_NOERROR;
163 /**************************************************************************
164 * AUX_SetVolume [internal]
166 static DWORD AUX_SetVolume(WORD wDevID, DWORD dwParam)
168 int mixer;
169 int volume, left, right;
170 int cmd;
172 TRACE("(%04X, %08X);\n", wDevID, dwParam);
174 left = (LOWORD(dwParam) * 100) >> 16;
175 right = (HIWORD(dwParam) * 100) >> 16;
176 volume = (right << 8) | left;
178 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
179 WARN("mixer device not available !\n");
180 return MMSYSERR_NOTENABLED;
183 switch(wDevID) {
184 case 0:
185 TRACE("SOUND_MIXER_WRITE_PCM !\n");
186 cmd = SOUND_MIXER_WRITE_PCM;
187 break;
188 case 1:
189 TRACE("SOUND_MIXER_WRITE_SYNTH !\n");
190 cmd = SOUND_MIXER_WRITE_SYNTH;
191 break;
192 case 2:
193 TRACE("SOUND_MIXER_WRITE_CD !\n");
194 cmd = SOUND_MIXER_WRITE_CD;
195 break;
196 case 3:
197 TRACE("SOUND_MIXER_WRITE_LINE !\n");
198 cmd = SOUND_MIXER_WRITE_LINE;
199 break;
200 case 4:
201 TRACE("SOUND_MIXER_WRITE_MIC !\n");
202 cmd = SOUND_MIXER_WRITE_MIC;
203 break;
204 case 5:
205 TRACE("SOUND_MIXER_WRITE_VOLUME !\n");
206 cmd = SOUND_MIXER_WRITE_VOLUME;
207 break;
208 default:
209 WARN("invalid device id=%04X !\n", wDevID);
210 close(mixer);
211 return MMSYSERR_NOTENABLED;
213 if (ioctl(mixer, cmd, &volume) == -1) {
214 WARN("unable to set mixer !\n");
215 close(mixer);
216 return MMSYSERR_NOTENABLED;
218 close(mixer);
219 return MMSYSERR_NOERROR;
222 /**************************************************************************
223 * auxMessage (WINEOSS.2)
225 DWORD WINAPI OSS_auxMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
226 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
228 TRACE("(%04X, %04X, %08lX, %08lX, %08lX);\n",
229 wDevID, wMsg, dwUser, dwParam1, dwParam2);
231 switch (wMsg) {
232 case DRVM_INIT:
233 return OSS_AuxInit();
234 case DRVM_EXIT:
235 return OSS_AuxExit();
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;