1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
4 * Sample MIXER Wine Driver for Linux
6 * Copyright 1997 Marcus Meissner
7 * 1999,2001 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * + implement notification mechanism when state of mixer's controls
29 #include "wine/port.h"
41 #ifdef HAVE_SYS_IOCTL_H
42 # include <sys/ioctl.h>
44 #ifdef HAVE_SYS_ERRNO_H
45 #include <sys/errno.h>
47 #include <sys/soundcard.h>
49 #define NONAMELESSUNION
50 #define NONAMELESSSTRUCT
55 #include "wine/unicode.h"
56 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(mixer);
60 #define MAX_MIXERDRV (6)
62 #define WINE_MIXER_MANUF_ID 0xAA
63 #define WINE_MIXER_PRODUCT_ID 0x55
64 #define WINE_MIXER_VERSION 0x0100
65 #define WINE_MIXER_NAME "WINE OSS Mixer"
67 #define WINE_CHN_MASK(_x) (1L << (_x))
68 #define WINE_CHN_SUPPORTS(_c, _x) ((_c) & WINE_CHN_MASK(_x))
69 /* Bass and Treble are no longer in the mask as Windows does not handle them */
70 #define WINE_MIXER_MASK_SPEAKER (WINE_CHN_MASK(SOUND_MIXER_SYNTH) | \
71 WINE_CHN_MASK(SOUND_MIXER_PCM) | \
72 WINE_CHN_MASK(SOUND_MIXER_LINE) | \
73 WINE_CHN_MASK(SOUND_MIXER_MIC) | \
74 WINE_CHN_MASK(SOUND_MIXER_CD) )
76 #define WINE_MIXER_MASK_RECORD (WINE_CHN_MASK(SOUND_MIXER_SYNTH) | \
77 WINE_CHN_MASK(SOUND_MIXER_LINE) | \
78 WINE_CHN_MASK(SOUND_MIXER_MIC) | \
79 WINE_CHN_MASK(SOUND_MIXER_IMIX) )
81 /* FIXME: the two following string arrays should be moved to a resource file in a string table */
82 /* if it's done, better use a struct to hold labels, name, and muted channel volume cache */
83 static const char * const MIX_Labels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS;
84 static const char * const MIX_Names [SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
96 int volume[SOUND_MIXER_NRDEVICES];
100 BOOL singleRecChannel;
101 struct mixerCtrl* ctrl;
105 #define LINEID_DST 0xFFFF
106 #define LINEID_SPEAKER 0x0000
107 #define LINEID_RECORD 0x0001
109 static int MIX_NumMixers;
110 static struct mixer MIX_Mixers[MAX_MIXERDRV];
112 /**************************************************************************
115 static const char * getMessage(UINT uMsg)
117 #define MSG_TO_STR(x) case x: return #x;
119 MSG_TO_STR(DRVM_INIT);
120 MSG_TO_STR(DRVM_EXIT);
121 MSG_TO_STR(DRVM_ENABLE);
122 MSG_TO_STR(DRVM_DISABLE);
123 MSG_TO_STR(MXDM_GETDEVCAPS);
124 MSG_TO_STR(MXDM_GETLINEINFO);
125 MSG_TO_STR(MXDM_GETNUMDEVS);
126 MSG_TO_STR(MXDM_OPEN);
127 MSG_TO_STR(MXDM_CLOSE);
128 MSG_TO_STR(MXDM_GETLINECONTROLS);
129 MSG_TO_STR(MXDM_GETCONTROLDETAILS);
130 MSG_TO_STR(MXDM_SETCONTROLDETAILS);
133 return wine_dbg_sprintf("UNKNOWN(%08x)", uMsg);
136 static const char * getIoctlCommand(int command)
138 #define IOCTL_TO_STR(x) case x: return #x;
140 IOCTL_TO_STR(SOUND_MIXER_VOLUME);
141 IOCTL_TO_STR(SOUND_MIXER_BASS);
142 IOCTL_TO_STR(SOUND_MIXER_TREBLE);
143 IOCTL_TO_STR(SOUND_MIXER_SYNTH);
144 IOCTL_TO_STR(SOUND_MIXER_PCM);
145 IOCTL_TO_STR(SOUND_MIXER_SPEAKER);
146 IOCTL_TO_STR(SOUND_MIXER_LINE);
147 IOCTL_TO_STR(SOUND_MIXER_MIC);
148 IOCTL_TO_STR(SOUND_MIXER_CD);
149 IOCTL_TO_STR(SOUND_MIXER_IMIX);
150 IOCTL_TO_STR(SOUND_MIXER_ALTPCM);
151 IOCTL_TO_STR(SOUND_MIXER_RECLEV);
152 IOCTL_TO_STR(SOUND_MIXER_IGAIN);
153 IOCTL_TO_STR(SOUND_MIXER_OGAIN);
154 IOCTL_TO_STR(SOUND_MIXER_LINE1);
155 IOCTL_TO_STR(SOUND_MIXER_LINE2);
156 IOCTL_TO_STR(SOUND_MIXER_LINE3);
157 IOCTL_TO_STR(SOUND_MIXER_DIGITAL1);
158 IOCTL_TO_STR(SOUND_MIXER_DIGITAL2);
159 IOCTL_TO_STR(SOUND_MIXER_DIGITAL3);
160 #ifdef SOUND_MIXER_PHONEIN
161 IOCTL_TO_STR(SOUND_MIXER_PHONEIN);
163 #ifdef SOUND_MIXER_PHONEOUT
164 IOCTL_TO_STR(SOUND_MIXER_PHONEOUT);
166 IOCTL_TO_STR(SOUND_MIXER_VIDEO);
167 IOCTL_TO_STR(SOUND_MIXER_RADIO);
168 #ifdef SOUND_MIXER_MONITOR
169 IOCTL_TO_STR(SOUND_MIXER_MONITOR);
173 return wine_dbg_sprintf("UNKNOWN(%08x)", command);
176 static const char * getControlType(DWORD dwControlType)
178 #define TYPE_TO_STR(x) case x: return #x
179 switch (dwControlType) {
180 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_CUSTOM);
181 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BOOLEANMETER);
182 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SIGNEDMETER);
183 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PEAKMETER);
184 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER);
185 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BOOLEAN);
186 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_ONOFF);
187 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MUTE);
188 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MONO);
189 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_LOUDNESS);
190 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_STEREOENH);
191 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BASS_BOOST);
192 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BUTTON);
193 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_DECIBELS);
194 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SIGNED);
195 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_UNSIGNED);
196 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PERCENT);
197 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SLIDER);
198 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PAN);
199 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_QSOUNDPAN);
200 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_FADER);
201 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_VOLUME);
202 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BASS);
203 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_TREBLE);
204 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_EQUALIZER);
205 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SINGLESELECT);
206 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MUX);
207 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT);
208 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MIXER);
209 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MICROTIME);
210 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MILLITIME);
213 return wine_dbg_sprintf("UNKNOWN(%08x)", dwControlType);
216 static const char * getComponentType(DWORD dwComponentType)
218 #define TYPE_TO_STR(x) case x: return #x;
219 switch (dwComponentType) {
220 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_UNDEFINED);
221 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_DIGITAL);
222 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_LINE);
223 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_MONITOR);
224 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
225 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_HEADPHONES);
226 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_TELEPHONE);
227 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_WAVEIN);
228 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_VOICEIN);
229 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED);
230 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_DIGITAL);
231 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_LINE);
232 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE);
233 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER);
234 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC);
235 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE);
236 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER);
237 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT);
238 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY);
239 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_ANALOG);
242 return wine_dbg_sprintf("UNKNOWN(%08x)", dwComponentType);
245 static const char * getTargetType(DWORD dwType)
247 #define TYPE_TO_STR(x) case x: return #x;
249 TYPE_TO_STR(MIXERLINE_TARGETTYPE_UNDEFINED);
250 TYPE_TO_STR(MIXERLINE_TARGETTYPE_WAVEOUT);
251 TYPE_TO_STR(MIXERLINE_TARGETTYPE_WAVEIN);
252 TYPE_TO_STR(MIXERLINE_TARGETTYPE_MIDIOUT);
253 TYPE_TO_STR(MIXERLINE_TARGETTYPE_MIDIIN);
254 TYPE_TO_STR(MIXERLINE_TARGETTYPE_AUX);
257 return wine_dbg_sprintf("UNKNOWN(%08x)", dwType);
260 static const WCHAR sz_short_volume [] = {'V','o','l',0};
261 static const WCHAR sz_long_volume [] = {'V','o','l','u','m','e',0};
262 static const WCHAR sz_shrtlng_mute [] = {'M','u','t','e',0};
263 static const WCHAR sz_shrtlng_mixer[] = {'M','i','x','e','r',0};
265 /**************************************************************************
266 * MIX_FillLineControls [internal]
268 static void MIX_FillLineControls(struct mixer* mix, int c, DWORD lineID,
271 struct mixerCtrl* mc = &mix->ctrl[c];
274 TRACE("(%p, %d, %08x, %s)\n", mix, c, lineID,
275 getControlType(dwControlType));
277 mc->dwLineID = lineID;
278 mc->ctrl.cbStruct = sizeof(MIXERCONTROLW);
279 mc->ctrl.dwControlID = c + 1;
280 mc->ctrl.dwControlType = dwControlType;
282 switch (dwControlType)
284 case MIXERCONTROL_CONTROLTYPE_VOLUME:
285 mc->ctrl.fdwControl = 0;
286 mc->ctrl.cMultipleItems = 0;
287 strcpyW(mc->ctrl.szShortName, sz_short_volume);
288 strcpyW(mc->ctrl.szName, sz_long_volume);
289 memset(&mc->ctrl.Bounds, 0, sizeof(mc->ctrl.Bounds));
290 /* CONTROLTYPE_VOLUME uses the MIXER_CONTROLDETAILS_UNSIGNED struct,
291 * [0, 100] is the range supported by OSS
292 * whatever the min and max values are they must match
293 * conversions done in (Get|Set)ControlDetails to stay in [0, 100] range
295 mc->ctrl.Bounds.s1.dwMinimum = 0;
296 mc->ctrl.Bounds.s1.dwMaximum = 65535;
297 memset(&mc->ctrl.Metrics, 0, sizeof(mc->ctrl.Metrics));
298 mc->ctrl.Metrics.cSteps = 656;
300 case MIXERCONTROL_CONTROLTYPE_MUTE:
301 case MIXERCONTROL_CONTROLTYPE_ONOFF:
302 mc->ctrl.fdwControl = 0;
303 mc->ctrl.cMultipleItems = 0;
304 strcpyW(mc->ctrl.szShortName, sz_shrtlng_mute);
305 strcpyW(mc->ctrl.szName, sz_shrtlng_mute);
306 memset(&mc->ctrl.Bounds, 0, sizeof(mc->ctrl.Bounds));
307 mc->ctrl.Bounds.s1.dwMinimum = 0;
308 mc->ctrl.Bounds.s1.dwMaximum = 1;
309 memset(&mc->ctrl.Metrics, 0, sizeof(mc->ctrl.Metrics));
311 case MIXERCONTROL_CONTROLTYPE_MUX:
312 case MIXERCONTROL_CONTROLTYPE_MIXER:
313 mc->ctrl.fdwControl = MIXERCONTROL_CONTROLF_MULTIPLE;
314 mc->ctrl.cMultipleItems = 0;
315 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++)
316 if (WINE_CHN_SUPPORTS(mix->recMask, j))
317 mc->ctrl.cMultipleItems++;
318 strcpyW(mc->ctrl.szShortName, sz_shrtlng_mixer);
319 strcpyW(mc->ctrl.szName, sz_shrtlng_mixer);
320 memset(&mc->ctrl.Bounds, 0, sizeof(mc->ctrl.Bounds));
321 mc->ctrl.Bounds.s1.dwMaximum = mc->ctrl.cMultipleItems - 1;
322 memset(&mc->ctrl.Metrics, 0, sizeof(mc->ctrl.Metrics));
323 mc->ctrl.Metrics.cSteps = mc->ctrl.cMultipleItems;
327 FIXME("Internal error: unknown type: %08x\n", dwControlType);
329 TRACE("ctrl[%2d]: typ=%08x lin=%08x\n", c + 1, dwControlType, lineID);
332 /******************************************************************
337 static struct mixer* MIX_Get(WORD wDevID)
339 TRACE("(%04x)\n", wDevID);
341 if (wDevID >= MIX_NumMixers || MIX_Mixers[wDevID].dev_name == NULL)
344 return &MIX_Mixers[wDevID];
347 /**************************************************************************
348 * MIX_Open [internal]
350 static DWORD MIX_Open(WORD wDevID, LPMIXEROPENDESC lpMod, DWORD flags)
355 DWORD ret = MMSYSERR_NOERROR;
357 TRACE("(%04X, %p, %u);\n", wDevID, lpMod, flags);
359 /* as we partly init the mixer with MIX_Open, we can allow null open decs
360 * EPP if (lpMod == NULL) return MMSYSERR_INVALPARAM;
361 * anyway, it seems that WINMM/MMSYSTEM doesn't always open the mixer
362 * device before sending messages to it... it seems to be linked to all
363 * the equivalent of mixer identification
364 * (with a reference to a wave, midi.. handle
366 if ((mix = MIX_Get(wDevID)) == NULL) {
367 WARN("bad device ID: %04X\n", wDevID);
368 return MMSYSERR_BADDEVICEID;
371 if ((mixer = open(mix->dev_name, O_RDWR)) < 0)
373 ERR("open(%s, O_RDWR) failed (%s)\n",
374 mix->dev_name, strerror(errno));
376 if (errno == ENODEV || errno == ENXIO)
378 /* no driver present */
380 return MMSYSERR_NODRIVER;
382 return MMSYSERR_ERROR;
385 if (ioctl(mixer, SOUND_MIXER_READ_DEVMASK, &mix->devMask) == -1)
387 ERR("ioctl(%s, SOUND_MIXER_DEVMASK) failed (%s)\n",
388 mix->dev_name, strerror(errno));
389 ret = MMSYSERR_ERROR;
393 mix->devMask &= WINE_MIXER_MASK_SPEAKER;
394 if (mix->devMask == 0)
397 ret = MMSYSERR_NODRIVER;
401 if (ioctl(mixer, SOUND_MIXER_READ_STEREODEVS, &mix->stereoMask) == -1)
403 ERR("ioctl(%s, SOUND_MIXER_STEREODEVS) failed (%s)\n",
404 mix->dev_name, strerror(errno));
405 ret = MMSYSERR_ERROR;
408 mix->stereoMask &= WINE_MIXER_MASK_SPEAKER;
410 if (ioctl(mixer, SOUND_MIXER_READ_RECMASK, &mix->recMask) == -1)
412 ERR("ioctl(%s, SOUND_MIXER_RECMASK) failed (%s)\n",
413 mix->dev_name, strerror(errno));
414 ret = MMSYSERR_ERROR;
417 mix->recMask &= WINE_MIXER_MASK_RECORD;
418 /* FIXME: we may need to support both rec lev & igain */
419 if (!WINE_CHN_SUPPORTS(mix->recMask, SOUND_MIXER_RECLEV))
421 WARN("The sound card doesn't support rec level\n");
422 if (WINE_CHN_SUPPORTS(mix->recMask, SOUND_MIXER_IGAIN))
423 WARN("but it does support IGain, please report\n");
425 if (ioctl(mixer, SOUND_MIXER_READ_CAPS, &caps) == -1)
427 ERR("ioctl(%s, SOUND_MIXER_READ_CAPS) failed (%s)\n",
428 mix->dev_name, strerror(errno));
429 ret = MMSYSERR_ERROR;
432 mix->singleRecChannel = caps & SOUND_CAP_EXCL_INPUT;
433 TRACE("dev=%04x rec=%04x stereo=%04x %s\n",
434 mix->devMask, mix->recMask, mix->stereoMask,
435 mix->singleRecChannel ? "single" : "multiple");
436 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
440 mix->numCtrl = 4; /* dst lines... vol&mute on speakers, vol&onoff on rec */
441 /* FIXME: do we always have RECLEV on all cards ??? */
442 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
444 if (WINE_CHN_SUPPORTS(mix->devMask, i))
445 mix->numCtrl += 2; /* volume & mute */
446 if (WINE_CHN_SUPPORTS(mix->recMask, i))
447 mix->numCtrl += 2; /* volume & onoff */
450 if (!(mix->ctrl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
451 sizeof(mix->ctrl[0]) * mix->numCtrl)))
453 ret = MMSYSERR_NOMEM;
458 MIX_FillLineControls(mix, j++, MAKELONG(0, LINEID_DST),
459 MIXERCONTROL_CONTROLTYPE_VOLUME);
460 MIX_FillLineControls(mix, j++, MAKELONG(0, LINEID_DST),
461 MIXERCONTROL_CONTROLTYPE_MUTE);
462 MIX_FillLineControls(mix, j++, MAKELONG(1, LINEID_DST),
463 mix->singleRecChannel ?
464 MIXERCONTROL_CONTROLTYPE_MUX :
465 MIXERCONTROL_CONTROLTYPE_MIXER);
466 MIX_FillLineControls(mix, j++, MAKELONG(1, LINEID_DST),
467 MIXERCONTROL_CONTROLTYPE_MUTE/*EPP*/);
468 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
470 if (WINE_CHN_SUPPORTS(mix->devMask, i))
472 MIX_FillLineControls(mix, j++, MAKELONG(LINEID_SPEAKER, i),
473 MIXERCONTROL_CONTROLTYPE_VOLUME);
474 MIX_FillLineControls(mix, j++, MAKELONG(LINEID_SPEAKER, i),
475 MIXERCONTROL_CONTROLTYPE_MUTE);
478 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
480 if (WINE_CHN_SUPPORTS(mix->recMask, i))
482 MIX_FillLineControls(mix, j++, MAKELONG(LINEID_RECORD, i),
483 MIXERCONTROL_CONTROLTYPE_VOLUME);
484 MIX_FillLineControls(mix, j++, MAKELONG(LINEID_RECORD, i),
485 MIXERCONTROL_CONTROLTYPE_MUTE/*EPP*/);
488 assert(j == mix->numCtrl);
494 /**************************************************************************
495 * MIX_GetVal [internal]
497 static BOOL MIX_GetVal(struct mixer* mix, int chn, int* val)
502 TRACE("(%p, %s, %p\n", mix, getIoctlCommand(chn), val);
504 if ((mixer = open(mix->dev_name, O_RDWR)) < 0) {
505 /* FIXME: ENXIO => no mixer installed */
506 WARN("mixer device not available !\n");
508 if (ioctl(mixer, MIXER_READ(chn), val) >= 0) {
509 TRACE("Reading %04x for %s\n", *val, getIoctlCommand(chn));
512 ERR("ioctl(%s, MIXER_READ(%s)) failed (%s)\n",
513 mix->dev_name, getIoctlCommand(chn), strerror(errno));
520 /**************************************************************************
521 * MIX_SetVal [internal]
523 static BOOL MIX_SetVal(struct mixer* mix, int chn, int val)
528 TRACE("(%p, %s, %x)\n", mix, getIoctlCommand(chn), val);
530 if ((mixer = open(mix->dev_name, O_RDWR)) < 0) {
531 /* FIXME: ENXIO => no mixer installed */
532 WARN("mixer device not available !\n");
534 if (ioctl(mixer, MIXER_WRITE(chn), &val) >= 0) {
535 TRACE("Set %s to %04x\n", getIoctlCommand(chn), val);
538 ERR("ioctl(%s, MIXER_WRITE(%s)) failed (%s)\n",
539 mix->dev_name, getIoctlCommand(chn), strerror(errno));
546 /******************************************************************
551 static BOOL MIX_GetRecSrc(struct mixer* mix, unsigned* mask)
556 TRACE("(%p, %p)\n", mix, mask);
558 if ((mixer = open(mix->dev_name, O_RDWR)) >= 0) {
559 if (ioctl(mixer, SOUND_MIXER_READ_RECSRC, &mask) >= 0) {
562 ERR("ioctl(%s, SOUND_MIXER_READ_RECSRC) failed (%s)\n",
563 mix->dev_name, strerror(errno));
570 /******************************************************************
575 static BOOL MIX_SetRecSrc(struct mixer* mix, unsigned mask)
580 TRACE("(%p, %08x)\n", mix, mask);
582 if ((mixer = open(mix->dev_name, O_RDWR)) >= 0) {
583 if (ioctl(mixer, SOUND_MIXER_WRITE_RECSRC, &mask) >= 0) {
586 ERR("ioctl(%s, SOUND_MIXER_WRITE_RECSRC) failed (%s)\n",
587 mix->dev_name, strerror(errno));
594 /**************************************************************************
595 * MIX_GetDevCaps [internal]
597 static DWORD MIX_GetDevCaps(WORD wDevID, LPMIXERCAPSW lpCaps, DWORD dwSize)
603 TRACE("(%04X, %p, %u);\n", wDevID, lpCaps, dwSize);
605 if (lpCaps == NULL) {
606 WARN("invalid parameter: lpCaps == NULL\n");
607 return MMSYSERR_INVALPARAM;
610 if ((mix = MIX_Get(wDevID)) == NULL) {
611 WARN("bad device ID: %04X\n", wDevID);
612 return MMSYSERR_BADDEVICEID;
615 capsW.wMid = WINE_MIXER_MANUF_ID;
616 capsW.wPid = WINE_MIXER_PRODUCT_ID;
617 capsW.vDriverVersion = WINE_MIXER_VERSION;
618 if (!(name = mix->name)) name = WINE_MIXER_NAME;
619 MultiByteToWideChar(CP_UNIXCP, 0, name, -1, capsW.szPname, sizeof(capsW.szPname) / sizeof(WCHAR));
620 capsW.cDestinations = 2; /* speakers & record */
621 capsW.fdwSupport = 0; /* No bits defined yet */
623 memcpy(lpCaps, &capsW, min(dwSize, sizeof(capsW)));
625 return MMSYSERR_NOERROR;
628 /**************************************************************************
629 * MIX_GetLineInfoDst [internal]
631 static DWORD MIX_GetLineInfoDst(struct mixer* mix, LPMIXERLINEW lpMl,
637 TRACE("(%p, %p, %08x)\n", mix, lpMl, dst);
639 lpMl->dwDestination = dst;
643 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
645 j = SOUND_MIXER_VOLUME;
646 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_WAVEOUT;
649 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
651 j = SOUND_MIXER_RECLEV;
652 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_WAVEIN;
655 FIXME("shouldn't happen\n");
656 return MMSYSERR_ERROR;
658 lpMl->dwSource = 0xFFFFFFFF;
659 MultiByteToWideChar(CP_UNIXCP, 0, MIX_Labels[j], -1, lpMl->szShortName, sizeof(lpMl->szShortName) / sizeof(WCHAR));
660 MultiByteToWideChar(CP_UNIXCP, 0, MIX_Names[j], -1, lpMl->szName, sizeof(lpMl->szName) / sizeof(WCHAR));
662 /* we have all connections found in the MIX_DevMask */
663 lpMl->cConnections = 0;
664 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++)
665 if (WINE_CHN_SUPPORTS(mask, j))
666 lpMl->cConnections++;
668 if (WINE_CHN_SUPPORTS(mix->stereoMask, lpMl->dwLineID))
670 lpMl->dwLineID = MAKELONG(dst, LINEID_DST);
672 for (j = 0; j < mix->numCtrl; j++)
673 if (mix->ctrl[j].dwLineID == lpMl->dwLineID)
676 return MMSYSERR_NOERROR;
679 /**************************************************************************
680 * MIX_GetLineInfoSrc [internal]
682 static DWORD MIX_GetLineInfoSrc(struct mixer* mix, LPMIXERLINEW lpMl,
683 DWORD idx, DWORD dst)
686 unsigned mask = (dst) ? mix->recMask : mix->devMask;
688 TRACE("(%p, %p, %d, %08x)\n", mix, lpMl, idx, dst);
690 MultiByteToWideChar(CP_UNIXCP, 0, MIX_Labels[idx], -1, lpMl->szShortName, sizeof(lpMl->szShortName) / sizeof(WCHAR));
691 MultiByteToWideChar(CP_UNIXCP, 0, MIX_Names[idx], -1, lpMl->szName, sizeof(lpMl->szName) / sizeof(WCHAR));
692 lpMl->dwLineID = MAKELONG(dst, idx);
693 lpMl->dwDestination = dst;
694 lpMl->cConnections = 1;
696 for (i = 0; i < mix->numCtrl; i++)
697 if (mix->ctrl[i].dwLineID == lpMl->dwLineID)
702 case SOUND_MIXER_SYNTH:
703 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;
704 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
705 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_MIDIOUT;
708 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;
709 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
710 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_UNDEFINED;
712 case SOUND_MIXER_LINE:
713 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_LINE;
714 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
715 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_UNDEFINED;
717 case SOUND_MIXER_MIC:
718 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
719 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
720 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_WAVEIN;
722 case SOUND_MIXER_PCM:
723 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
724 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
725 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_WAVEOUT;
727 case SOUND_MIXER_IMIX:
728 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED;
729 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
730 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_UNDEFINED;
733 WARN("Index %d not handled.\n", idx);
734 return MIXERR_INVALLINE;
737 if (dst == 0 && WINE_CHN_SUPPORTS(mix->stereoMask, idx))
739 for (i = j = 0; j < SOUND_MIXER_NRDEVICES; j++)
741 if (WINE_CHN_SUPPORTS(mask, j))
748 return MMSYSERR_NOERROR;
751 /******************************************************************
754 static BOOL MIX_CheckLine(DWORD lineID)
756 TRACE("(%08x)\n",lineID);
758 return ((HIWORD(lineID) < SOUND_MIXER_NRDEVICES && LOWORD(lineID) < 2) ||
759 (HIWORD(lineID) == LINEID_DST &&
760 LOWORD(lineID) < SOUND_MIXER_NRDEVICES));
763 /**************************************************************************
764 * MIX_GetLineInfo [internal]
766 static DWORD MIX_GetLineInfo(WORD wDevID, LPMIXERLINEW lpMl, DWORD fdwInfo)
769 DWORD ret = MMSYSERR_NOERROR;
773 TRACE("(%04X, %p, %u);\n", wDevID, lpMl, fdwInfo);
776 WARN("invalid parameter: lpMl = NULL\n");
777 return MMSYSERR_INVALPARAM;
780 if (lpMl->cbStruct != sizeof(*lpMl)) {
781 WARN("invalid parameter: lpMl->cbStruct = %d\n",
783 return MMSYSERR_INVALPARAM;
786 if ((mix = MIX_Get(wDevID)) == NULL) {
787 WARN("bad device ID: %04X\n", wDevID);
788 return MMSYSERR_BADDEVICEID;
791 /* FIXME: set all the variables correctly... the lines below
794 lpMl->fdwLine = MIXERLINE_LINEF_ACTIVE;
797 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK)
799 case MIXER_GETLINEINFOF_DESTINATION:
800 TRACE("MIXER_GETLINEINFOF_DESTINATION (%08x)\n", lpMl->dwDestination);
801 if (lpMl->dwDestination >= 2) {
802 WARN("invalid parameter: lpMl->dwDestination = %d >= 2\n",
803 lpMl->dwDestination);
804 return MMSYSERR_INVALPARAM;
806 ret = MIX_GetLineInfoDst(mix, lpMl, lpMl->dwDestination);
807 if (ret != MMSYSERR_NOERROR) {
812 case MIXER_GETLINEINFOF_SOURCE:
813 TRACE("MIXER_GETLINEINFOF_SOURCE (%08x), dst=%08x\n", lpMl->dwSource,
814 lpMl->dwDestination);
815 switch (lpMl->dwDestination)
817 case LINEID_SPEAKER: mask = mix->devMask; break;
818 case LINEID_RECORD: mask = mix->recMask; break;
820 WARN("invalid parameter\n");
821 return MMSYSERR_INVALPARAM;
824 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++)
826 if (WINE_CHN_SUPPORTS(mask, j) && (i-- == 0))
829 if (j >= SOUND_MIXER_NRDEVICES) {
830 WARN("invalid line\n");
831 return MIXERR_INVALLINE;
833 ret = MIX_GetLineInfoSrc(mix, lpMl, j, lpMl->dwDestination);
834 if (ret != MMSYSERR_NOERROR) {
839 case MIXER_GETLINEINFOF_LINEID:
840 TRACE("MIXER_GETLINEINFOF_LINEID (%08x)\n", lpMl->dwLineID);
842 if (!MIX_CheckLine(lpMl->dwLineID)) {
843 WARN("invalid line\n");
844 return MIXERR_INVALLINE;
846 if (HIWORD(lpMl->dwLineID) == LINEID_DST)
847 ret = MIX_GetLineInfoDst(mix, lpMl, LOWORD(lpMl->dwLineID));
849 ret = MIX_GetLineInfoSrc(mix, lpMl, HIWORD(lpMl->dwLineID),
850 LOWORD(lpMl->dwLineID));
851 if (ret != MMSYSERR_NOERROR) {
856 case MIXER_GETLINEINFOF_COMPONENTTYPE:
857 TRACE("MIXER_GETLINEINFOF_COMPONENTTYPE (%s)\n",
858 getComponentType(lpMl->dwComponentType));
859 switch (lpMl->dwComponentType)
861 case MIXERLINE_COMPONENTTYPE_DST_HEADPHONES:
862 case MIXERLINE_COMPONENTTYPE_DST_SPEAKERS:
863 ret = MIX_GetLineInfoDst(mix, lpMl, LINEID_SPEAKER);
865 case MIXERLINE_COMPONENTTYPE_DST_LINE:
866 case MIXERLINE_COMPONENTTYPE_DST_VOICEIN:
867 case MIXERLINE_COMPONENTTYPE_DST_WAVEIN:
868 ret = MIX_GetLineInfoDst(mix, lpMl, LINEID_RECORD);
870 case MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER:
871 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_SYNTH, 0);
873 case MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC:
874 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_CD, 0);
876 case MIXERLINE_COMPONENTTYPE_SRC_LINE:
877 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_LINE, 0);
879 case MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE:
880 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_MIC, 1);
882 case MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT:
883 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_PCM, 0);
885 case MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED:
886 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_IMIX, 1);
889 FIXME("Unhandled component type (%s)\n",
890 getComponentType(lpMl->dwComponentType));
891 return MMSYSERR_INVALPARAM;
894 case MIXER_GETLINEINFOF_TARGETTYPE:
895 FIXME("MIXER_GETLINEINFOF_TARGETTYPE not implemented yet.\n");
896 TRACE("MIXER_GETLINEINFOF_TARGETTYPE (%s)\n",
897 getTargetType(lpMl->Target.dwType));
898 switch (lpMl->Target.dwType) {
899 case MIXERLINE_TARGETTYPE_UNDEFINED:
900 case MIXERLINE_TARGETTYPE_WAVEOUT:
901 case MIXERLINE_TARGETTYPE_WAVEIN:
902 case MIXERLINE_TARGETTYPE_MIDIOUT:
903 case MIXERLINE_TARGETTYPE_MIDIIN:
904 case MIXERLINE_TARGETTYPE_AUX:
906 FIXME("Unhandled target type (%s)\n",
907 getTargetType(lpMl->Target.dwType));
908 return MMSYSERR_INVALPARAM;
912 WARN("Unknown flag (%08lx)\n", fdwInfo & MIXER_GETLINEINFOF_QUERYMASK);
916 if ((fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) != MIXER_GETLINEINFOF_TARGETTYPE) {
918 lpMl->Target.dwDeviceID = 0xFFFFFFFF;
919 lpMl->Target.wMid = WINE_MIXER_MANUF_ID;
920 lpMl->Target.wPid = WINE_MIXER_PRODUCT_ID;
921 lpMl->Target.vDriverVersion = WINE_MIXER_VERSION;
922 if (!(name = mix->name)) name = WINE_MIXER_NAME;
923 MultiByteToWideChar(CP_UNIXCP, 0, name, -1, lpMl->Target.szPname, sizeof(lpMl->Target.szPname) / sizeof(WCHAR));
929 /******************************************************************
933 static BOOL MIX_CheckControl(struct mixer* mix, DWORD ctrlID)
935 TRACE("(%p, %08x)\n", mix, ctrlID);
937 return (ctrlID >= 1 && ctrlID <= mix->numCtrl);
940 /**************************************************************************
941 * MIX_GetLineControls [internal]
943 static DWORD MIX_GetLineControls(WORD wDevID, LPMIXERLINECONTROLSW lpMlc,
946 DWORD dwRet = MMSYSERR_NOERROR;
949 TRACE("(%04X, %p, %u);\n", wDevID, lpMlc, flags);
952 WARN("invalid parameter: lpMlc == NULL\n");
953 return MMSYSERR_INVALPARAM;
956 if (lpMlc->cbStruct < sizeof(*lpMlc)) {
957 WARN("invalid parameter: lpMlc->cbStruct = %d\n",
959 return MMSYSERR_INVALPARAM;
962 if (lpMlc->cbmxctrl < sizeof(MIXERCONTROLW)) {
963 WARN("invalid parameter: lpMlc->cbmxctrl = %d\n",
965 return MMSYSERR_INVALPARAM;
968 if ((mix = MIX_Get(wDevID)) == NULL) {
969 WARN("bad device ID: %04X\n", wDevID);
970 return MMSYSERR_BADDEVICEID;
973 switch (flags & MIXER_GETLINECONTROLSF_QUERYMASK)
975 case MIXER_GETLINECONTROLSF_ALL:
979 TRACE("line=%08x MIXER_GETLINECONTROLSF_ALL (%d)\n",
980 lpMlc->dwLineID, lpMlc->cControls);
982 for (i = j = 0; i < mix->numCtrl; i++)
984 if (mix->ctrl[i].dwLineID == lpMlc->dwLineID)
988 if (!j || lpMlc->cControls != j) {
989 WARN("invalid parameter\n");
990 dwRet = MMSYSERR_INVALPARAM;
991 } else if (!MIX_CheckLine(lpMlc->dwLineID)) {
992 WARN("invalid line\n");
993 dwRet = MIXERR_INVALLINE;
995 for (i = j = 0; i < mix->numCtrl; i++)
997 if (mix->ctrl[i].dwLineID == lpMlc->dwLineID)
999 TRACE("[%d] => [%2d]: typ=%08x\n", j, i + 1,
1000 mix->ctrl[i].ctrl.dwControlType);
1001 lpMlc->pamxctrl[j++] = mix->ctrl[i].ctrl;
1007 case MIXER_GETLINECONTROLSF_ONEBYID:
1008 TRACE("line=%08x MIXER_GETLINECONTROLSF_ONEBYID (%x)\n",
1009 lpMlc->dwLineID, lpMlc->u.dwControlID);
1011 if (!MIX_CheckControl(mix, lpMlc->u.dwControlID) ||
1012 mix->ctrl[lpMlc->u.dwControlID - 1].dwLineID != lpMlc->dwLineID) {
1013 WARN("invalid parameter\n");
1014 dwRet = MMSYSERR_INVALPARAM;
1016 lpMlc->pamxctrl[0] = mix->ctrl[lpMlc->u.dwControlID - 1].ctrl;
1018 case MIXER_GETLINECONTROLSF_ONEBYTYPE:
1019 TRACE("line=%08x MIXER_GETLINECONTROLSF_ONEBYTYPE (%s)\n",
1020 lpMlc->dwLineID, getControlType(lpMlc->u.dwControlType));
1021 if (!MIX_CheckLine(lpMlc->dwLineID)) {
1022 WARN("invalid line\n");
1023 dwRet = MIXERR_INVALLINE;
1026 DWORD ct = lpMlc->u.dwControlType & MIXERCONTROL_CT_CLASS_MASK;
1027 for (i = 0; i < mix->numCtrl; i++) {
1028 if (mix->ctrl[i].dwLineID == lpMlc->dwLineID &&
1029 ct == (mix->ctrl[i].ctrl.dwControlType &
1030 MIXERCONTROL_CT_CLASS_MASK)) {
1031 lpMlc->pamxctrl[0] = mix->ctrl[i].ctrl;
1036 if (i == mix->numCtrl) {
1037 WARN("invalid parameter: control not found\n");
1038 dwRet = MMSYSERR_INVALPARAM;
1043 ERR("Unknown flag %08lx\n", flags & MIXER_GETLINECONTROLSF_QUERYMASK);
1044 dwRet = MMSYSERR_INVALPARAM;
1050 /**************************************************************************
1051 * MIX_GetControlDetails [internal]
1053 static DWORD MIX_GetControlDetails(WORD wDevID, LPMIXERCONTROLDETAILS lpmcd,
1056 DWORD ret = MMSYSERR_NOTSUPPORTED;
1060 TRACE("(%04X, %p, %u);\n", wDevID, lpmcd, fdwDetails);
1062 if (lpmcd == NULL) {
1063 WARN("invalid parameter: lpmcd == NULL\n");
1064 return MMSYSERR_INVALPARAM;
1067 if ((mix = MIX_Get(wDevID)) == NULL) {
1068 WARN("bad device ID: %04X\n", wDevID);
1069 return MMSYSERR_BADDEVICEID;
1072 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK)
1074 case MIXER_GETCONTROLDETAILSF_VALUE:
1075 TRACE("MIXER_GETCONTROLDETAILSF_VALUE (%08x)\n", lpmcd->dwControlID);
1076 if (MIX_CheckControl(mix, lpmcd->dwControlID))
1078 DWORD c = lpmcd->dwControlID - 1;
1079 chnl = HIWORD(mix->ctrl[c].dwLineID);
1080 if (chnl == LINEID_DST)
1081 chnl = LOWORD(mix->ctrl[c].dwLineID) ? SOUND_MIXER_RECLEV :
1083 switch (mix->ctrl[c].ctrl.dwControlType)
1085 case MIXERCONTROL_CONTROLTYPE_VOLUME:
1087 LPMIXERCONTROLDETAILS_UNSIGNED mcdu;
1090 if (lpmcd->cbDetails !=
1091 sizeof(MIXERCONTROLDETAILS_UNSIGNED)) {
1092 WARN("invalid parameter: cbDetails = %d\n",
1094 return MMSYSERR_INVALPARAM;
1097 TRACE("%s MIXERCONTROLDETAILS_UNSIGNED[%u]\n",
1098 getControlType(mix->ctrl[c].ctrl.dwControlType),
1101 mcdu = lpmcd->paDetails;
1103 /* return value is 00RL (4 bytes)... */
1104 if ((val = mix->volume[chnl]) == -1 &&
1105 !MIX_GetVal(mix, chnl, &val)) {
1106 WARN("invalid parameter\n");
1107 return MMSYSERR_INVALPARAM;
1110 switch (lpmcd->cChannels)
1113 /* mono... so R = L */
1114 mcdu->dwValue = ((LOBYTE(LOWORD(val)) * 65536.0) / 100.0) + 0.5;
1115 TRACE("Reading RL = %d\n", mcdu->dwValue);
1118 /* stereo, left is paDetails[0] */
1119 mcdu->dwValue = ((LOBYTE(LOWORD(val)) * 65536.0) / 100.0) + 0.5;
1120 TRACE("Reading L = %d\n", mcdu->dwValue);
1122 mcdu->dwValue = ((HIBYTE(LOWORD(val)) * 65536.0) / 100.0) + 0.5;
1123 TRACE("Reading R = %d\n", mcdu->dwValue);
1126 WARN("Unsupported cChannels (%d)\n", lpmcd->cChannels);
1127 return MMSYSERR_INVALPARAM;
1129 TRACE("=> %08x\n", mcdu->dwValue);
1132 case MIXERCONTROL_CONTROLTYPE_MUTE:
1133 case MIXERCONTROL_CONTROLTYPE_ONOFF:
1135 LPMIXERCONTROLDETAILS_BOOLEAN mcdb;
1137 if (lpmcd->cbDetails !=
1138 sizeof(MIXERCONTROLDETAILS_BOOLEAN)) {
1139 WARN("invalid parameter: cbDetails = %d\n",
1141 return MMSYSERR_INVALPARAM;
1144 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n",
1145 getControlType(mix->ctrl[c].ctrl.dwControlType),
1148 /* we mute both channels at the same time */
1149 mcdb = lpmcd->paDetails;
1150 mcdb->fValue = (mix->volume[chnl] != -1);
1151 TRACE("=> %s\n", mcdb->fValue ? "on" : "off");
1154 case MIXERCONTROL_CONTROLTYPE_MIXER:
1155 case MIXERCONTROL_CONTROLTYPE_MUX:
1159 if (lpmcd->cbDetails !=
1160 sizeof(MIXERCONTROLDETAILS_BOOLEAN)) {
1161 WARN("invalid parameter: cbDetails = %d\n",
1163 return MMSYSERR_INVALPARAM;
1166 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n",
1167 getControlType(mix->ctrl[c].ctrl.dwControlType),
1170 if (!MIX_GetRecSrc(mix, &mask))
1172 /* FIXME: ENXIO => no mixer installed */
1173 WARN("mixer device not available !\n");
1174 ret = MMSYSERR_ERROR;
1178 LPMIXERCONTROLDETAILS_BOOLEAN mcdb;
1181 /* we mute both channels at the same time */
1182 mcdb = lpmcd->paDetails;
1184 for (i = j = 0; j < SOUND_MIXER_NRDEVICES; j++)
1186 if (WINE_CHN_SUPPORTS(mix->recMask, j))
1188 if (i >= lpmcd->u.cMultipleItems)
1189 return MMSYSERR_INVALPARAM;
1190 mcdb[i++].fValue = WINE_CHN_SUPPORTS(mask, j);
1197 WARN("%s Unsupported\n",
1198 getControlType(mix->ctrl[c].ctrl.dwControlType));
1200 ret = MMSYSERR_NOERROR;
1204 WARN("invalid parameter\n");
1205 ret = MMSYSERR_INVALPARAM;
1208 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
1209 TRACE("MIXER_GETCONTROLDETAILSF_LISTTEXT (%08x)\n",
1210 lpmcd->dwControlID);
1212 ret = MMSYSERR_INVALPARAM;
1213 if (MIX_CheckControl(mix, lpmcd->dwControlID))
1215 DWORD c = lpmcd->dwControlID - 1;
1217 if (mix->ctrl[c].ctrl.dwControlType == MIXERCONTROL_CONTROLTYPE_MUX ||
1218 mix->ctrl[c].ctrl.dwControlType == MIXERCONTROL_CONTROLTYPE_MIXER)
1220 LPMIXERCONTROLDETAILS_LISTTEXTW mcdlt;
1223 mcdlt = lpmcd->paDetails;
1224 for (i = j = 0; j < SOUND_MIXER_NRDEVICES; j++)
1226 if (WINE_CHN_SUPPORTS(mix->recMask, j))
1228 mcdlt[i].dwParam1 = MAKELONG(LINEID_RECORD, j);
1229 mcdlt[i].dwParam2 = 0;
1230 MultiByteToWideChar(CP_UNIXCP, 0, MIX_Names[j], -1,
1231 mcdlt[i].szName, sizeof(mcdlt[i]) / sizeof(WCHAR));
1235 if (i != lpmcd->u.cMultipleItems) FIXME("bad count\n");
1236 ret = MMSYSERR_NOERROR;
1241 WARN("Unknown flag (%08lx)\n",
1242 fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK);
1247 /**************************************************************************
1248 * MIX_SetControlDetails [internal]
1250 static DWORD MIX_SetControlDetails(WORD wDevID, LPMIXERCONTROLDETAILS lpmcd,
1253 DWORD ret = MMSYSERR_NOTSUPPORTED;
1258 TRACE("(%04X, %p, %u);\n", wDevID, lpmcd, fdwDetails);
1260 if (lpmcd == NULL) {
1261 TRACE("invalid parameter: lpmcd == NULL\n");
1262 return MMSYSERR_INVALPARAM;
1265 if ((mix = MIX_Get(wDevID)) == NULL) {
1266 WARN("bad device ID: %04X\n", wDevID);
1267 return MMSYSERR_BADDEVICEID;
1270 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK)
1272 case MIXER_GETCONTROLDETAILSF_VALUE:
1273 TRACE("MIXER_GETCONTROLDETAILSF_VALUE (%08x)\n", lpmcd->dwControlID);
1274 if (MIX_CheckControl(mix, lpmcd->dwControlID))
1276 c = lpmcd->dwControlID - 1;
1278 TRACE("dwLineID=%08x\n",mix->ctrl[c].dwLineID);
1280 chnl = HIWORD(mix->ctrl[c].dwLineID);
1281 if (chnl == LINEID_DST)
1282 chnl = LOWORD(mix->ctrl[c].dwLineID) ?
1283 SOUND_MIXER_RECLEV : SOUND_MIXER_VOLUME;
1285 switch (mix->ctrl[c].ctrl.dwControlType)
1287 case MIXERCONTROL_CONTROLTYPE_VOLUME:
1289 LPMIXERCONTROLDETAILS_UNSIGNED mcdu;
1291 if (lpmcd->cbDetails !=
1292 sizeof(MIXERCONTROLDETAILS_UNSIGNED)) {
1293 WARN("invalid parameter: cbDetails = %d\n",
1295 return MMSYSERR_INVALPARAM;
1298 TRACE("%s MIXERCONTROLDETAILS_UNSIGNED[%u]\n",
1299 getControlType(mix->ctrl[c].ctrl.dwControlType),
1302 mcdu = lpmcd->paDetails;
1303 /* val should contain 00RL */
1304 switch (lpmcd->cChannels)
1307 /* mono... so R = L */
1308 TRACE("Setting RL to %d\n", mcdu->dwValue);
1309 val = 0x101 * ((mcdu->dwValue * 100) >> 16);
1312 /* stereo, left is paDetails[0] */
1313 TRACE("Setting L to %d\n", mcdu->dwValue);
1314 val = ((mcdu->dwValue * 100.0) / 65536.0) + 0.5;
1316 TRACE("Setting R to %d\n", mcdu->dwValue);
1317 val += (int)(((mcdu->dwValue * 100) / 65536.0) + 0.5) << 8;
1320 WARN("Unsupported cChannels (%d)\n", lpmcd->cChannels);
1321 return MMSYSERR_INVALPARAM;
1324 if (mix->volume[chnl] == -1)
1326 if (!MIX_SetVal(mix, chnl, val)) {
1327 WARN("invalid parameter\n");
1328 return MMSYSERR_INVALPARAM;
1333 mix->volume[chnl] = val;
1336 ret = MMSYSERR_NOERROR;
1338 case MIXERCONTROL_CONTROLTYPE_MUTE:
1339 case MIXERCONTROL_CONTROLTYPE_ONOFF:
1341 LPMIXERCONTROLDETAILS_BOOLEAN mcdb;
1343 if (lpmcd->cbDetails !=
1344 sizeof(MIXERCONTROLDETAILS_BOOLEAN)) {
1345 WARN("invalid parameter: cbDetails = %d\n",
1347 return MMSYSERR_INVALPARAM;
1350 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n",
1351 getControlType(mix->ctrl[c].ctrl.dwControlType),
1354 mcdb = lpmcd->paDetails;
1357 /* save the volume and then set it to 0 */
1358 if (!MIX_GetVal(mix, chnl, &mix->volume[chnl]) ||
1359 !MIX_SetVal(mix, chnl, 0)) {
1360 WARN("invalid parameter\n");
1361 return MMSYSERR_INVALPARAM;
1366 if (mix->volume[chnl] == -1)
1368 ret = MMSYSERR_NOERROR;
1371 if (!MIX_SetVal(mix, chnl, mix->volume[chnl])) {
1372 WARN("invalid parameter\n");
1373 return MMSYSERR_INVALPARAM;
1375 mix->volume[chnl] = -1;
1378 ret = MMSYSERR_NOERROR;
1380 case MIXERCONTROL_CONTROLTYPE_MIXER:
1381 case MIXERCONTROL_CONTROLTYPE_MUX:
1383 LPMIXERCONTROLDETAILS_BOOLEAN mcdb;
1387 if (lpmcd->cbDetails !=
1388 sizeof(MIXERCONTROLDETAILS_BOOLEAN)) {
1389 WARN("invalid parameter: cbDetails = %d\n",
1391 return MMSYSERR_INVALPARAM;
1394 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n",
1395 getControlType(mix->ctrl[c].ctrl.dwControlType),
1398 /* we mute both channels at the same time */
1399 mcdb = lpmcd->paDetails;
1401 for (i = j = 0; j < SOUND_MIXER_NRDEVICES; j++)
1403 if (WINE_CHN_SUPPORTS(mix->recMask, j) &&
1406 /* a mux can only select one line at a time... */
1407 if (mix->singleRecChannel && mask != 0)
1410 return MMSYSERR_INVALPARAM;
1412 mask |= WINE_CHN_MASK(j);
1415 if (i != lpmcd->u.cMultipleItems)
1416 FIXME("bad count\n");
1417 TRACE("writing %04x as rec src\n", mask);
1418 if (!MIX_SetRecSrc(mix, mask))
1419 ERR("Can't write new mixer settings\n");
1421 ret = MMSYSERR_NOERROR;
1428 WARN("Unknown SetControlDetails flag (%08lx)\n",
1429 fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK);
1434 /**************************************************************************
1435 * MIX_Init [internal]
1437 static LRESULT OSS_MixerInit(void)
1445 for (i = 0; i < MAX_MIXERDRV; i++) {
1449 sprintf(name, "/dev/mixer");
1451 sprintf(name, "/dev/mixer%d", i);
1453 if ((mixer = open(name, O_RDWR)) >= 0) {
1454 #ifdef SOUND_MIXER_INFO
1456 if (ioctl(mixer, SOUND_MIXER_INFO, &info) >= 0) {
1457 MIX_Mixers[MIX_NumMixers].name = HeapAlloc(GetProcessHeap(),0,strlen(info.name) + 1);
1458 strcpy(MIX_Mixers[MIX_NumMixers].name, info.name);
1460 /* FreeBSD up to at least 5.2 provides this ioctl, but does not
1461 * implement it properly, and there are probably similar issues
1462 * on other platforms, so we warn but try to go ahead.
1464 WARN("%s: cannot read SOUND_MIXER_INFO!\n", name);
1469 MIX_Mixers[MIX_NumMixers].dev_name = HeapAlloc(GetProcessHeap(),0,strlen(name) + 1);
1470 strcpy(MIX_Mixers[MIX_NumMixers].dev_name, name);
1472 MIX_Open(MIX_NumMixers - 1, NULL, 0); /* FIXME */
1474 WARN("couldn't open %s\n", name);
1478 if (MIX_NumMixers == 0) {
1479 WARN("no driver\n");
1480 return MMSYSERR_NODRIVER;
1483 return MMSYSERR_NOERROR;
1486 /**************************************************************************
1487 * MIX_Exit [internal]
1489 static LRESULT OSS_MixerExit(void)
1495 for (i = 0; i < MIX_NumMixers; i++) {
1496 HeapFree(GetProcessHeap(),0,MIX_Mixers[i].name);
1497 HeapFree(GetProcessHeap(),0,MIX_Mixers[i].dev_name);
1500 return MMSYSERR_NOERROR;
1503 /**************************************************************************
1504 * MIX_GetNumDevs [internal]
1506 static DWORD MIX_GetNumDevs(void)
1510 return MIX_NumMixers;
1513 /**************************************************************************
1514 * mxdMessage (WINEOSS.3)
1516 DWORD WINAPI OSS_mxdMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
1517 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1519 TRACE("(%04X, %s, %08lX, %08lX, %08lX);\n", wDevID, getMessage(wMsg),
1520 dwUser, dwParam1, dwParam2);
1525 return OSS_MixerInit();
1527 return OSS_MixerExit();
1530 /* FIXME: Pretend this is supported */
1532 case MXDM_GETDEVCAPS:
1533 return MIX_GetDevCaps(wDevID, (LPMIXERCAPSW)dwParam1, dwParam2);
1534 case MXDM_GETLINEINFO:
1535 return MIX_GetLineInfo(wDevID, (LPMIXERLINEW)dwParam1, dwParam2);
1536 case MXDM_GETNUMDEVS:
1537 return MIX_GetNumDevs();
1539 return MMSYSERR_NOERROR;
1540 /* MIX_Open(wDevID, (LPMIXEROPENDESC)dwParam1, dwParam2); */
1542 return MMSYSERR_NOERROR;
1543 case MXDM_GETLINECONTROLS:
1544 return MIX_GetLineControls(wDevID, (LPMIXERLINECONTROLSW)dwParam1, dwParam2);
1545 case MXDM_GETCONTROLDETAILS:
1546 return MIX_GetControlDetails(wDevID, (LPMIXERCONTROLDETAILS)dwParam1, dwParam2);
1547 case MXDM_SETCONTROLDETAILS:
1548 return MIX_SetControlDetails(wDevID, (LPMIXERCONTROLDETAILS)dwParam1, dwParam2);
1550 WARN("unknown message %d!\n", wMsg);
1551 return MMSYSERR_NOTSUPPORTED;