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
->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
;
122 TRACE("SOUND_MIXER_READ_PCM !\n");
123 cmd
= SOUND_MIXER_READ_PCM
;
126 TRACE("SOUND_MIXER_READ_SYNTH !\n");
127 cmd
= SOUND_MIXER_READ_SYNTH
;
130 TRACE("SOUND_MIXER_READ_CD !\n");
131 cmd
= SOUND_MIXER_READ_CD
;
134 TRACE("SOUND_MIXER_READ_LINE !\n");
135 cmd
= SOUND_MIXER_READ_LINE
;
138 TRACE("SOUND_MIXER_READ_MIC !\n");
139 cmd
= SOUND_MIXER_READ_MIC
;
142 TRACE("SOUND_MIXER_READ_VOLUME !\n");
143 cmd
= SOUND_MIXER_READ_VOLUME
;
146 WARN("invalid device id=%04X !\n", wDevID
);
148 return MMSYSERR_NOTENABLED
;
150 if (ioctl(mixer
, cmd
, &volume
) == -1) {
151 WARN("unable to read mixer !\n");
153 return MMSYSERR_NOTENABLED
;
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
)
169 int volume
, left
, right
;
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
;
185 TRACE("SOUND_MIXER_WRITE_PCM !\n");
186 cmd
= SOUND_MIXER_WRITE_PCM
;
189 TRACE("SOUND_MIXER_WRITE_SYNTH !\n");
190 cmd
= SOUND_MIXER_WRITE_SYNTH
;
193 TRACE("SOUND_MIXER_WRITE_CD !\n");
194 cmd
= SOUND_MIXER_WRITE_CD
;
197 TRACE("SOUND_MIXER_WRITE_LINE !\n");
198 cmd
= SOUND_MIXER_WRITE_LINE
;
201 TRACE("SOUND_MIXER_WRITE_MIC !\n");
202 cmd
= SOUND_MIXER_WRITE_MIC
;
205 TRACE("SOUND_MIXER_WRITE_VOLUME !\n");
206 cmd
= SOUND_MIXER_WRITE_VOLUME
;
209 WARN("invalid device id=%04X !\n", wDevID
);
211 return MMSYSERR_NOTENABLED
;
213 if (ioctl(mixer
, cmd
, &volume
) == -1) {
214 WARN("unable to set mixer !\n");
216 return MMSYSERR_NOTENABLED
;
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
);
233 return OSS_AuxInit();
235 return OSS_AuxExit();
238 /* FIXME: Pretend this is supported */
240 case AUXDM_GETDEVCAPS
:
241 return AUX_GetDevCaps(wDevID
, (LPAUXCAPSW
)dwParam1
, dwParam2
);
242 case AUXDM_GETNUMDEVS
:
243 TRACE("return %d;\n", NumDev
);
245 case AUXDM_GETVOLUME
:
246 return AUX_GetVolume(wDevID
, (LPDWORD
)dwParam1
);
247 case AUXDM_SETVOLUME
:
248 return AUX_SetVolume(wDevID
, dwParam1
);
250 WARN("unknown message !\n");
252 return MMSYSERR_NOTSUPPORTED
;