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
22 #include "wine/port.h"
31 #ifdef HAVE_SYS_IOCTL_H
32 # include <sys/ioctl.h>
34 #ifdef HAVE_SYS_ERRNO_H
35 #include <sys/errno.h>
37 #include <sys/soundcard.h>
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(mmaux);
47 #define MIXER_DEV "/dev/mixer"
49 static int NumDev = 6;
51 /*-----------------------------------------------------------------------*/
53 static LRESULT OSS_AuxInit(void)
58 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
59 WARN("mixer device not available !\n");
68 /*-----------------------------------------------------------------------*/
70 static LRESULT OSS_AuxExit(void)
76 /**************************************************************************
77 * AUX_GetDevCaps [internal]
79 static DWORD AUX_GetDevCaps(WORD wDevID, LPAUXCAPSW lpCaps, DWORD dwSize)
82 static const WCHAR ini[] = {'O','S','S',' ','A','u','x',' ','#','0',0};
84 TRACE("(%04X, %p, %u);\n", wDevID, lpCaps, dwSize);
85 if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
86 if (wDevID >= NumDev) return MMSYSERR_BADDEVICEID;
87 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
88 WARN("mixer device not available !\n");
89 return MMSYSERR_NOTENABLED;
91 if (ioctl(mixer, SOUND_MIXER_READ_LINE, &volume) == -1) {
93 WARN("unable to read mixer !\n");
94 return MMSYSERR_NOTENABLED;
98 lpCaps->wPid = 0x55 + wDevID;
99 lpCaps->vDriverVersion = 0x0100;
100 strcpyW(lpCaps->szPname, ini);
101 lpCaps->szPname[9] = '0' + wDevID; /* 6 at max */
102 lpCaps->wTechnology = wDevID == 2 ? AUXCAPS_CDAUDIO : AUXCAPS_AUXIN;
103 lpCaps->dwSupport = AUXCAPS_VOLUME | AUXCAPS_LRVOLUME;
105 return MMSYSERR_NOERROR;
109 /**************************************************************************
110 * AUX_GetVolume [internal]
112 static DWORD AUX_GetVolume(WORD wDevID, LPDWORD lpdwVol)
114 int mixer, volume, left, right, cmd;
116 TRACE("(%04X, %p);\n", wDevID, lpdwVol);
117 if (lpdwVol == NULL) return MMSYSERR_NOTENABLED;
118 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
119 WARN("mixer device not available !\n");
120 return MMSYSERR_NOTENABLED;
124 TRACE("SOUND_MIXER_READ_PCM !\n");
125 cmd = SOUND_MIXER_READ_PCM;
128 TRACE("SOUND_MIXER_READ_SYNTH !\n");
129 cmd = SOUND_MIXER_READ_SYNTH;
132 TRACE("SOUND_MIXER_READ_CD !\n");
133 cmd = SOUND_MIXER_READ_CD;
136 TRACE("SOUND_MIXER_READ_LINE !\n");
137 cmd = SOUND_MIXER_READ_LINE;
140 TRACE("SOUND_MIXER_READ_MIC !\n");
141 cmd = SOUND_MIXER_READ_MIC;
144 TRACE("SOUND_MIXER_READ_VOLUME !\n");
145 cmd = SOUND_MIXER_READ_VOLUME;
148 WARN("invalid device id=%04X !\n", wDevID);
150 return MMSYSERR_NOTENABLED;
152 if (ioctl(mixer, cmd, &volume) == -1) {
153 WARN("unable to read mixer !\n");
155 return MMSYSERR_NOTENABLED;
158 left = LOBYTE(LOWORD(volume));
159 right = HIBYTE(LOWORD(volume));
160 TRACE("left=%d right=%d !\n", left, right);
161 *lpdwVol = MAKELONG((left * 0xFFFFL) / 100, (right * 0xFFFFL) / 100);
162 return MMSYSERR_NOERROR;
165 /**************************************************************************
166 * AUX_SetVolume [internal]
168 static DWORD AUX_SetVolume(WORD wDevID, DWORD dwParam)
171 int volume, left, right;
174 TRACE("(%04X, %08X);\n", wDevID, dwParam);
176 left = (LOWORD(dwParam) * 100) >> 16;
177 right = (HIWORD(dwParam) * 100) >> 16;
178 volume = (right << 8) | left;
180 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
181 WARN("mixer device not available !\n");
182 return MMSYSERR_NOTENABLED;
187 TRACE("SOUND_MIXER_WRITE_PCM !\n");
188 cmd = SOUND_MIXER_WRITE_PCM;
191 TRACE("SOUND_MIXER_WRITE_SYNTH !\n");
192 cmd = SOUND_MIXER_WRITE_SYNTH;
195 TRACE("SOUND_MIXER_WRITE_CD !\n");
196 cmd = SOUND_MIXER_WRITE_CD;
199 TRACE("SOUND_MIXER_WRITE_LINE !\n");
200 cmd = SOUND_MIXER_WRITE_LINE;
203 TRACE("SOUND_MIXER_WRITE_MIC !\n");
204 cmd = SOUND_MIXER_WRITE_MIC;
207 TRACE("SOUND_MIXER_WRITE_VOLUME !\n");
208 cmd = SOUND_MIXER_WRITE_VOLUME;
211 WARN("invalid device id=%04X !\n", wDevID);
213 return MMSYSERR_NOTENABLED;
215 if (ioctl(mixer, cmd, &volume) == -1) {
216 WARN("unable to set mixer !\n");
218 return MMSYSERR_NOTENABLED;
221 return MMSYSERR_NOERROR;
224 /**************************************************************************
225 * auxMessage (WINEOSS.2)
227 DWORD WINAPI OSS_auxMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
228 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
230 TRACE("(%04X, %04X, %08lX, %08lX, %08lX);\n",
231 wDevID, wMsg, dwUser, dwParam1, dwParam2);
235 return OSS_AuxInit();
237 return OSS_AuxExit();
240 /* FIXME: Pretend this is supported */
242 case AUXDM_GETDEVCAPS:
243 return AUX_GetDevCaps(wDevID, (LPAUXCAPSW)dwParam1, dwParam2);
244 case AUXDM_GETNUMDEVS:
245 TRACE("return %d;\n", NumDev);
247 case AUXDM_GETVOLUME:
248 return AUX_GetVolume(wDevID, (LPDWORD)dwParam1);
249 case AUXDM_SETVOLUME:
250 return AUX_SetVolume(wDevID, dwParam1);
252 WARN("unknown message !\n");
254 return MMSYSERR_NOTSUPPORTED;