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 #include <sys/soundcard.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)
55 if ((mixer = open(MIXER_DEV, O_RDWR)) < 0) {
56 WARN("mixer device not available !\n");
65 /*-----------------------------------------------------------------------*/
67 static LRESULT OSS_AuxExit(void)
73 /**************************************************************************
74 * AUX_GetDevCaps [internal]
76 static DWORD AUX_GetDevCaps(WORD wDevID, LPAUXCAPSW lpCaps, DWORD dwSize)
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) {
90 WARN("unable to read mixer !\n");
91 return MMSYSERR_NOTENABLED;
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->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;
121 TRACE("SOUND_MIXER_READ_PCM !\n");
122 cmd = SOUND_MIXER_READ_PCM;
125 TRACE("SOUND_MIXER_READ_SYNTH !\n");
126 cmd = SOUND_MIXER_READ_SYNTH;
129 TRACE("SOUND_MIXER_READ_CD !\n");
130 cmd = SOUND_MIXER_READ_CD;
133 TRACE("SOUND_MIXER_READ_LINE !\n");
134 cmd = SOUND_MIXER_READ_LINE;
137 TRACE("SOUND_MIXER_READ_MIC !\n");
138 cmd = SOUND_MIXER_READ_MIC;
141 TRACE("SOUND_MIXER_READ_VOLUME !\n");
142 cmd = SOUND_MIXER_READ_VOLUME;
145 WARN("invalid device id=%04X !\n", wDevID);
147 return MMSYSERR_NOTENABLED;
149 if (ioctl(mixer, cmd, &volume) == -1) {
150 WARN("unable to read mixer !\n");
152 return MMSYSERR_NOTENABLED;
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)
168 int volume, left, right;
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;
184 TRACE("SOUND_MIXER_WRITE_PCM !\n");
185 cmd = SOUND_MIXER_WRITE_PCM;
188 TRACE("SOUND_MIXER_WRITE_SYNTH !\n");
189 cmd = SOUND_MIXER_WRITE_SYNTH;
192 TRACE("SOUND_MIXER_WRITE_CD !\n");
193 cmd = SOUND_MIXER_WRITE_CD;
196 TRACE("SOUND_MIXER_WRITE_LINE !\n");
197 cmd = SOUND_MIXER_WRITE_LINE;
200 TRACE("SOUND_MIXER_WRITE_MIC !\n");
201 cmd = SOUND_MIXER_WRITE_MIC;
204 TRACE("SOUND_MIXER_WRITE_VOLUME !\n");
205 cmd = SOUND_MIXER_WRITE_VOLUME;
208 WARN("invalid device id=%04X !\n", wDevID);
210 return MMSYSERR_NOTENABLED;
212 if (ioctl(mixer, cmd, &volume) == -1) {
213 WARN("unable to set mixer !\n");
215 return MMSYSERR_NOTENABLED;
218 return MMSYSERR_NOERROR;
221 /**************************************************************************
222 * auxMessage (WINEOSS.2)
224 DWORD WINAPI OSS_auxMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
225 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
227 TRACE("(%04X, %04X, %08lX, %08lX, %08lX);\n",
228 wDevID, wMsg, dwUser, dwParam1, dwParam2);
232 return OSS_AuxInit();
234 return OSS_AuxExit();
237 /* FIXME: Pretend this is supported */
239 case AUXDM_GETDEVCAPS:
240 return AUX_GetDevCaps(wDevID, (LPAUXCAPSW)dwParam1, dwParam2);
241 case AUXDM_GETNUMDEVS:
242 TRACE("return %d;\n", NumDev);
244 case AUXDM_GETVOLUME:
245 return AUX_GetVolume(wDevID, (LPDWORD)dwParam1);
246 case AUXDM_SETVOLUME:
247 return AUX_SetVolume(wDevID, dwParam1);
249 WARN("unknown message !\n");
251 return MMSYSERR_NOTSUPPORTED;