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>
45 #define NONAMELESSUNION
46 #define NONAMELESSSTRUCT
52 #include "wine/unicode.h"
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(mixer);
59 #define MAX_MIXERDRV (6)
61 #define WINE_MIXER_MANUF_ID 0xAA
62 #define WINE_MIXER_PRODUCT_ID 0x55
63 #define WINE_MIXER_VERSION 0x0100
64 #define WINE_MIXER_NAME "WINE OSS Mixer"
66 #define WINE_CHN_MASK(_x) (1L << (_x))
67 #define WINE_CHN_SUPPORTS(_c, _x) ((_c) & WINE_CHN_MASK(_x))
68 /* Bass and Treble are no longer in the mask as Windows does not handle them */
69 #define WINE_MIXER_MASK_SPEAKER (WINE_CHN_MASK(SOUND_MIXER_SYNTH) | \
70 WINE_CHN_MASK(SOUND_MIXER_PCM) | \
71 WINE_CHN_MASK(SOUND_MIXER_LINE) | \
72 WINE_CHN_MASK(SOUND_MIXER_MIC) | \
73 WINE_CHN_MASK(SOUND_MIXER_CD) )
75 #define WINE_MIXER_MASK_RECORD (WINE_CHN_MASK(SOUND_MIXER_SYNTH) | \
76 WINE_CHN_MASK(SOUND_MIXER_LINE) | \
77 WINE_CHN_MASK(SOUND_MIXER_MIC) | \
78 WINE_CHN_MASK(SOUND_MIXER_IMIX) )
80 /* FIXME: the two following string arrays should be moved to a resource file in a string table */
81 /* if it's done, better use a struct to hold labels, name, and muted channel volume cache */
82 static const char * const MIX_Labels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS;
83 static const char * const MIX_Names [SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES;
95 int volume[SOUND_MIXER_NRDEVICES];
99 BOOL singleRecChannel;
100 struct mixerCtrl* ctrl;
104 #define LINEID_DST 0xFFFF
105 #define LINEID_SPEAKER 0x0000
106 #define LINEID_RECORD 0x0001
108 static int MIX_NumMixers;
109 static struct mixer MIX_Mixers[MAX_MIXERDRV];
111 /**************************************************************************
114 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 sprintf(str, "UNKNOWN(%08x)", uMsg);
137 static const char * getIoctlCommand(int command)
140 #define IOCTL_TO_STR(x) case x: return #x;
142 IOCTL_TO_STR(SOUND_MIXER_VOLUME);
143 IOCTL_TO_STR(SOUND_MIXER_BASS);
144 IOCTL_TO_STR(SOUND_MIXER_TREBLE);
145 IOCTL_TO_STR(SOUND_MIXER_SYNTH);
146 IOCTL_TO_STR(SOUND_MIXER_PCM);
147 IOCTL_TO_STR(SOUND_MIXER_SPEAKER);
148 IOCTL_TO_STR(SOUND_MIXER_LINE);
149 IOCTL_TO_STR(SOUND_MIXER_MIC);
150 IOCTL_TO_STR(SOUND_MIXER_CD);
151 IOCTL_TO_STR(SOUND_MIXER_IMIX);
152 IOCTL_TO_STR(SOUND_MIXER_ALTPCM);
153 IOCTL_TO_STR(SOUND_MIXER_RECLEV);
154 IOCTL_TO_STR(SOUND_MIXER_IGAIN);
155 IOCTL_TO_STR(SOUND_MIXER_OGAIN);
156 IOCTL_TO_STR(SOUND_MIXER_LINE1);
157 IOCTL_TO_STR(SOUND_MIXER_LINE2);
158 IOCTL_TO_STR(SOUND_MIXER_LINE3);
159 IOCTL_TO_STR(SOUND_MIXER_DIGITAL1);
160 IOCTL_TO_STR(SOUND_MIXER_DIGITAL2);
161 IOCTL_TO_STR(SOUND_MIXER_DIGITAL3);
162 IOCTL_TO_STR(SOUND_MIXER_PHONEIN);
163 IOCTL_TO_STR(SOUND_MIXER_PHONEOUT);
164 IOCTL_TO_STR(SOUND_MIXER_VIDEO);
165 IOCTL_TO_STR(SOUND_MIXER_RADIO);
166 IOCTL_TO_STR(SOUND_MIXER_MONITOR);
169 sprintf(str, "UNKNOWN(%08x)", command);
173 static const char * getControlType(DWORD dwControlType)
176 #define TYPE_TO_STR(x) case x: return #x;
177 switch (dwControlType) {
178 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_CUSTOM);
179 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BOOLEANMETER);
180 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SIGNEDMETER);
181 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PEAKMETER);
182 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER);
183 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BOOLEAN);
184 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_ONOFF);
185 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MUTE);
186 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MONO);
187 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_LOUDNESS);
188 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_STEREOENH);
189 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BASS_BOOST);
190 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BUTTON);
191 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_DECIBELS);
192 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SIGNED);
193 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_UNSIGNED);
194 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PERCENT);
195 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SLIDER);
196 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PAN);
197 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_QSOUNDPAN);
198 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_FADER);
199 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_VOLUME);
200 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BASS);
201 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_TREBLE);
202 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_EQUALIZER);
203 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SINGLESELECT);
204 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MUX);
205 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT);
206 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MIXER);
207 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MICROTIME);
208 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MILLITIME);
211 sprintf(str, "UNKNOWN(%08x)", dwControlType);
215 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 sprintf(str, "UNKNOWN(%08x)", dwComponentType);
246 static const char * getTargetType(DWORD dwType)
249 #define TYPE_TO_STR(x) case x: return #x;
251 TYPE_TO_STR(MIXERLINE_TARGETTYPE_UNDEFINED);
252 TYPE_TO_STR(MIXERLINE_TARGETTYPE_WAVEOUT);
253 TYPE_TO_STR(MIXERLINE_TARGETTYPE_WAVEIN);
254 TYPE_TO_STR(MIXERLINE_TARGETTYPE_MIDIOUT);
255 TYPE_TO_STR(MIXERLINE_TARGETTYPE_MIDIIN);
256 TYPE_TO_STR(MIXERLINE_TARGETTYPE_AUX);
259 sprintf(str, "UNKNOWN(%08x)", dwType);
263 static const WCHAR sz_short_volume [] = {'V','o','l',0};
264 static const WCHAR sz_long_volume [] = {'V','o','l','u','m','e',0};
265 static const WCHAR sz_shrtlng_mute [] = {'M','u','t','e',0};
266 static const WCHAR sz_shrtlng_mixer[] = {'M','i','x','e','r',0};
268 /**************************************************************************
269 * MIX_FillLineControls [internal]
271 static void MIX_FillLineControls(struct mixer* mix, int c, DWORD lineID,
274 struct mixerCtrl* mc = &mix->ctrl[c];
277 TRACE("(%p, %d, %08x, %s)\n", mix, c, lineID,
278 getControlType(dwControlType));
280 mc->dwLineID = lineID;
281 mc->ctrl.cbStruct = sizeof(MIXERCONTROLW);
282 mc->ctrl.dwControlID = c + 1;
283 mc->ctrl.dwControlType = dwControlType;
285 switch (dwControlType)
287 case MIXERCONTROL_CONTROLTYPE_VOLUME:
288 mc->ctrl.fdwControl = 0;
289 mc->ctrl.cMultipleItems = 0;
290 strcpyW(mc->ctrl.szShortName, sz_short_volume);
291 strcpyW(mc->ctrl.szName, sz_long_volume);
292 memset(&mc->ctrl.Bounds, 0, sizeof(mc->ctrl.Bounds));
293 /* CONTROLTYPE_VOLUME uses the MIXER_CONTROLDETAILS_UNSIGNED struct,
294 * [0, 100] is the range supported by OSS
295 * whatever the min and max values are they must match
296 * conversions done in (Get|Set)ControlDetails to stay in [0, 100] range
298 mc->ctrl.Bounds.s1.dwMinimum = 0;
299 mc->ctrl.Bounds.s1.dwMaximum = 65535;
300 memset(&mc->ctrl.Metrics, 0, sizeof(mc->ctrl.Metrics));
301 mc->ctrl.Metrics.cSteps = 656;
303 case MIXERCONTROL_CONTROLTYPE_MUTE:
304 case MIXERCONTROL_CONTROLTYPE_ONOFF:
305 mc->ctrl.fdwControl = 0;
306 mc->ctrl.cMultipleItems = 0;
307 strcpyW(mc->ctrl.szShortName, sz_shrtlng_mute);
308 strcpyW(mc->ctrl.szName, sz_shrtlng_mute);
309 memset(&mc->ctrl.Bounds, 0, sizeof(mc->ctrl.Bounds));
310 mc->ctrl.Bounds.s1.dwMinimum = 0;
311 mc->ctrl.Bounds.s1.dwMaximum = 1;
312 memset(&mc->ctrl.Metrics, 0, sizeof(mc->ctrl.Metrics));
314 case MIXERCONTROL_CONTROLTYPE_MUX:
315 case MIXERCONTROL_CONTROLTYPE_MIXER:
316 mc->ctrl.fdwControl = MIXERCONTROL_CONTROLF_MULTIPLE;
317 mc->ctrl.cMultipleItems = 0;
318 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++)
319 if (WINE_CHN_SUPPORTS(mix->recMask, j))
320 mc->ctrl.cMultipleItems++;
321 strcpyW(mc->ctrl.szShortName, sz_shrtlng_mixer);
322 strcpyW(mc->ctrl.szName, sz_shrtlng_mixer);
323 memset(&mc->ctrl.Bounds, 0, sizeof(mc->ctrl.Bounds));
324 mc->ctrl.Bounds.s1.dwMaximum = mc->ctrl.cMultipleItems - 1;
325 memset(&mc->ctrl.Metrics, 0, sizeof(mc->ctrl.Metrics));
326 mc->ctrl.Metrics.cSteps = mc->ctrl.cMultipleItems;
330 FIXME("Internal error: unknown type: %08x\n", dwControlType);
332 TRACE("ctrl[%2d]: typ=%08x lin=%08x\n", c + 1, dwControlType, lineID);
335 /******************************************************************
340 static struct mixer* MIX_Get(WORD wDevID)
342 TRACE("(%04x)\n", wDevID);
344 if (wDevID >= MIX_NumMixers || MIX_Mixers[wDevID].dev_name == NULL)
347 return &MIX_Mixers[wDevID];
350 /**************************************************************************
351 * MIX_Open [internal]
353 static DWORD MIX_Open(WORD wDevID, LPMIXEROPENDESC lpMod, DWORD flags)
358 DWORD ret = MMSYSERR_NOERROR;
360 TRACE("(%04X, %p, %u);\n", wDevID, lpMod, flags);
362 /* as we partly init the mixer with MIX_Open, we can allow null open decs
363 * EPP if (lpMod == NULL) return MMSYSERR_INVALPARAM;
364 * anyway, it seems that WINMM/MMSYSTEM doesn't always open the mixer
365 * device before sending messages to it... it seems to be linked to all
366 * the equivalent of mixer identification
367 * (with a reference to a wave, midi.. handle
369 if ((mix = MIX_Get(wDevID)) == NULL) {
370 WARN("bad device ID: %04X\n", wDevID);
371 return MMSYSERR_BADDEVICEID;
374 if ((mixer = open(mix->dev_name, O_RDWR)) < 0)
376 ERR("open(%s, O_RDWR) failed (%s)\n",
377 mix->dev_name, strerror(errno));
379 if (errno == ENODEV || errno == ENXIO)
381 /* no driver present */
383 return MMSYSERR_NODRIVER;
385 return MMSYSERR_ERROR;
388 if (ioctl(mixer, SOUND_MIXER_READ_DEVMASK, &mix->devMask) == -1)
390 ERR("ioctl(%s, SOUND_MIXER_DEVMASK) failed (%s)\n",
391 mix->dev_name, strerror(errno));
392 ret = MMSYSERR_ERROR;
396 mix->devMask &= WINE_MIXER_MASK_SPEAKER;
397 if (mix->devMask == 0)
400 ret = MMSYSERR_NODRIVER;
404 if (ioctl(mixer, SOUND_MIXER_READ_STEREODEVS, &mix->stereoMask) == -1)
406 ERR("ioctl(%s, SOUND_MIXER_STEREODEVS) failed (%s)\n",
407 mix->dev_name, strerror(errno));
408 ret = MMSYSERR_ERROR;
411 mix->stereoMask &= WINE_MIXER_MASK_SPEAKER;
413 if (ioctl(mixer, SOUND_MIXER_READ_RECMASK, &mix->recMask) == -1)
415 ERR("ioctl(%s, SOUND_MIXER_RECMASK) failed (%s)\n",
416 mix->dev_name, strerror(errno));
417 ret = MMSYSERR_ERROR;
420 mix->recMask &= WINE_MIXER_MASK_RECORD;
421 /* FIXME: we may need to support both rec lev & igain */
422 if (!WINE_CHN_SUPPORTS(mix->recMask, SOUND_MIXER_RECLEV))
424 WARN("The sound card doesn't support rec level\n");
425 if (WINE_CHN_SUPPORTS(mix->recMask, SOUND_MIXER_IGAIN))
426 WARN("but it does support IGain, please report\n");
428 if (ioctl(mixer, SOUND_MIXER_READ_CAPS, &caps) == -1)
430 ERR("ioctl(%s, SOUND_MIXER_READ_CAPS) failed (%s)\n",
431 mix->dev_name, strerror(errno));
432 ret = MMSYSERR_ERROR;
435 mix->singleRecChannel = caps & SOUND_CAP_EXCL_INPUT;
436 TRACE("dev=%04x rec=%04x stereo=%04x %s\n",
437 mix->devMask, mix->recMask, mix->stereoMask,
438 mix->singleRecChannel ? "single" : "multiple");
439 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
443 mix->numCtrl = 4; /* dst lines... vol&mute on speakers, vol&onoff on rec */
444 /* FIXME: do we always have RECLEV on all cards ??? */
445 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
447 if (WINE_CHN_SUPPORTS(mix->devMask, i))
448 mix->numCtrl += 2; /* volume & mute */
449 if (WINE_CHN_SUPPORTS(mix->recMask, i))
450 mix->numCtrl += 2; /* volume & onoff */
453 if (!(mix->ctrl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
454 sizeof(mix->ctrl[0]) * mix->numCtrl)))
456 ret = MMSYSERR_NOMEM;
461 MIX_FillLineControls(mix, j++, MAKELONG(0, LINEID_DST),
462 MIXERCONTROL_CONTROLTYPE_VOLUME);
463 MIX_FillLineControls(mix, j++, MAKELONG(0, LINEID_DST),
464 MIXERCONTROL_CONTROLTYPE_MUTE);
465 MIX_FillLineControls(mix, j++, MAKELONG(1, LINEID_DST),
466 mix->singleRecChannel ?
467 MIXERCONTROL_CONTROLTYPE_MUX :
468 MIXERCONTROL_CONTROLTYPE_MIXER);
469 MIX_FillLineControls(mix, j++, MAKELONG(1, LINEID_DST),
470 MIXERCONTROL_CONTROLTYPE_MUTE/*EPP*/);
471 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
473 if (WINE_CHN_SUPPORTS(mix->devMask, i))
475 MIX_FillLineControls(mix, j++, MAKELONG(LINEID_SPEAKER, i),
476 MIXERCONTROL_CONTROLTYPE_VOLUME);
477 MIX_FillLineControls(mix, j++, MAKELONG(LINEID_SPEAKER, i),
478 MIXERCONTROL_CONTROLTYPE_MUTE);
481 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
483 if (WINE_CHN_SUPPORTS(mix->recMask, i))
485 MIX_FillLineControls(mix, j++, MAKELONG(LINEID_RECORD, i),
486 MIXERCONTROL_CONTROLTYPE_VOLUME);
487 MIX_FillLineControls(mix, j++, MAKELONG(LINEID_RECORD, i),
488 MIXERCONTROL_CONTROLTYPE_MUTE/*EPP*/);
491 assert(j == mix->numCtrl);
497 /**************************************************************************
498 * MIX_GetVal [internal]
500 static BOOL MIX_GetVal(struct mixer* mix, int chn, int* val)
505 TRACE("(%p, %s, %p\n", mix, getIoctlCommand(chn), val);
507 if ((mixer = open(mix->dev_name, O_RDWR)) < 0) {
508 /* FIXME: ENXIO => no mixer installed */
509 WARN("mixer device not available !\n");
511 if (ioctl(mixer, MIXER_READ(chn), val) >= 0) {
512 TRACE("Reading %04x for %s\n", *val, getIoctlCommand(chn));
515 ERR("ioctl(%s, MIXER_READ(%s)) failed (%s)\n",
516 mix->dev_name, getIoctlCommand(chn), strerror(errno));
523 /**************************************************************************
524 * MIX_SetVal [internal]
526 static BOOL MIX_SetVal(struct mixer* mix, int chn, int val)
531 TRACE("(%p, %s, %x)\n", mix, getIoctlCommand(chn), val);
533 if ((mixer = open(mix->dev_name, O_RDWR)) < 0) {
534 /* FIXME: ENXIO => no mixer installed */
535 WARN("mixer device not available !\n");
537 if (ioctl(mixer, MIXER_WRITE(chn), &val) >= 0) {
538 TRACE("Set %s to %04x\n", getIoctlCommand(chn), val);
541 ERR("ioctl(%s, MIXER_WRITE(%s)) failed (%s)\n",
542 mix->dev_name, getIoctlCommand(chn), strerror(errno));
549 /******************************************************************
554 static BOOL MIX_GetRecSrc(struct mixer* mix, unsigned* mask)
559 TRACE("(%p, %p)\n", mix, mask);
561 if ((mixer = open(mix->dev_name, O_RDWR)) >= 0) {
562 if (ioctl(mixer, SOUND_MIXER_READ_RECSRC, &mask) >= 0) {
565 ERR("ioctl(%s, SOUND_MIXER_READ_RECSRC) failed (%s)\n",
566 mix->dev_name, strerror(errno));
573 /******************************************************************
578 static BOOL MIX_SetRecSrc(struct mixer* mix, unsigned mask)
583 TRACE("(%p, %08x)\n", mix, mask);
585 if ((mixer = open(mix->dev_name, O_RDWR)) >= 0) {
586 if (ioctl(mixer, SOUND_MIXER_WRITE_RECSRC, &mask) >= 0) {
589 ERR("ioctl(%s, SOUND_MIXER_WRITE_RECSRC) failed (%s)\n",
590 mix->dev_name, strerror(errno));
597 /**************************************************************************
598 * MIX_GetDevCaps [internal]
600 static DWORD MIX_GetDevCaps(WORD wDevID, LPMIXERCAPSW lpCaps, DWORD dwSize)
606 TRACE("(%04X, %p, %u);\n", wDevID, lpCaps, dwSize);
608 if (lpCaps == NULL) {
609 WARN("invalid parameter: lpCaps == NULL\n");
610 return MMSYSERR_INVALPARAM;
613 if ((mix = MIX_Get(wDevID)) == NULL) {
614 WARN("bad device ID: %04X\n", wDevID);
615 return MMSYSERR_BADDEVICEID;
618 capsW.wMid = WINE_MIXER_MANUF_ID;
619 capsW.wPid = WINE_MIXER_PRODUCT_ID;
620 capsW.vDriverVersion = WINE_MIXER_VERSION;
621 if (!(name = mix->name)) name = WINE_MIXER_NAME;
622 MultiByteToWideChar(CP_ACP, 0, name, -1, capsW.szPname, sizeof(capsW.szPname) / sizeof(WCHAR));
623 capsW.cDestinations = 2; /* speakers & record */
624 capsW.fdwSupport = 0; /* No bits defined yet */
626 memcpy(lpCaps, &capsW, min(dwSize, sizeof(capsW)));
628 return MMSYSERR_NOERROR;
631 /**************************************************************************
632 * MIX_GetLineInfoDst [internal]
634 static DWORD MIX_GetLineInfoDst(struct mixer* mix, LPMIXERLINEW lpMl,
640 TRACE("(%p, %p, %08x)\n", mix, lpMl, dst);
642 lpMl->dwDestination = dst;
646 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
648 j = SOUND_MIXER_VOLUME;
649 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_WAVEOUT;
652 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
654 j = SOUND_MIXER_RECLEV;
655 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_WAVEIN;
658 FIXME("shouldn't happen\n");
659 return MMSYSERR_ERROR;
661 lpMl->dwSource = 0xFFFFFFFF;
662 MultiByteToWideChar(CP_ACP, 0, MIX_Labels[j], -1, lpMl->szShortName, sizeof(lpMl->szShortName) / sizeof(WCHAR));
663 MultiByteToWideChar(CP_ACP, 0, MIX_Names[j], -1, lpMl->szName, sizeof(lpMl->szName) / sizeof(WCHAR));
665 /* we have all connections found in the MIX_DevMask */
666 lpMl->cConnections = 0;
667 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++)
668 if (WINE_CHN_SUPPORTS(mask, j))
669 lpMl->cConnections++;
671 if (WINE_CHN_SUPPORTS(mix->stereoMask, lpMl->dwLineID))
673 lpMl->dwLineID = MAKELONG(dst, LINEID_DST);
675 for (j = 0; j < mix->numCtrl; j++)
676 if (mix->ctrl[j].dwLineID == lpMl->dwLineID)
679 return MMSYSERR_NOERROR;
682 /**************************************************************************
683 * MIX_GetLineInfoSrc [internal]
685 static DWORD MIX_GetLineInfoSrc(struct mixer* mix, LPMIXERLINEW lpMl,
686 DWORD idx, DWORD dst)
689 unsigned mask = (dst) ? mix->recMask : mix->devMask;
691 TRACE("(%p, %p, %d, %08x)\n", mix, lpMl, idx, dst);
693 MultiByteToWideChar(CP_ACP, 0, MIX_Labels[idx], -1, lpMl->szShortName, sizeof(lpMl->szShortName) / sizeof(WCHAR));
694 MultiByteToWideChar(CP_ACP, 0, MIX_Names[idx], -1, lpMl->szName, sizeof(lpMl->szName) / sizeof(WCHAR));
695 lpMl->dwLineID = MAKELONG(dst, idx);
696 lpMl->dwDestination = dst;
697 lpMl->cConnections = 1;
699 for (i = 0; i < mix->numCtrl; i++)
700 if (mix->ctrl[i].dwLineID == lpMl->dwLineID)
705 case SOUND_MIXER_SYNTH:
706 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER;
707 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
708 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_MIDIOUT;
711 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC;
712 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
713 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_UNDEFINED;
715 case SOUND_MIXER_LINE:
716 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_LINE;
717 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
718 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_UNDEFINED;
720 case SOUND_MIXER_MIC:
721 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
722 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
723 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_WAVEIN;
725 case SOUND_MIXER_PCM:
726 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
727 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
728 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_WAVEOUT;
730 case SOUND_MIXER_IMIX:
731 lpMl->dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED;
732 lpMl->fdwLine |= MIXERLINE_LINEF_SOURCE;
733 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_UNDEFINED;
736 WARN("Index %d not handled.\n", idx);
737 return MIXERR_INVALLINE;
740 if (dst == 0 && WINE_CHN_SUPPORTS(mix->stereoMask, idx))
742 for (i = j = 0; j < SOUND_MIXER_NRDEVICES; j++)
744 if (WINE_CHN_SUPPORTS(mask, j))
751 return MMSYSERR_NOERROR;
754 /******************************************************************
757 static BOOL MIX_CheckLine(DWORD lineID)
759 TRACE("(%08x)\n",lineID);
761 return ((HIWORD(lineID) < SOUND_MIXER_NRDEVICES && LOWORD(lineID) < 2) ||
762 (HIWORD(lineID) == LINEID_DST &&
763 LOWORD(lineID) < SOUND_MIXER_NRDEVICES));
766 /**************************************************************************
767 * MIX_GetLineInfo [internal]
769 static DWORD MIX_GetLineInfo(WORD wDevID, LPMIXERLINEW lpMl, DWORD fdwInfo)
772 DWORD ret = MMSYSERR_NOERROR;
776 TRACE("(%04X, %p, %u);\n", wDevID, lpMl, fdwInfo);
779 WARN("invalid parameter: lpMl = NULL\n");
780 return MMSYSERR_INVALPARAM;
783 if (lpMl->cbStruct != sizeof(*lpMl)) {
784 WARN("invalid parameter: lpMl->cbStruct = %d != %d\n",
785 lpMl->cbStruct, sizeof(*lpMl));
786 return MMSYSERR_INVALPARAM;
789 if ((mix = MIX_Get(wDevID)) == NULL) {
790 WARN("bad device ID: %04X\n", wDevID);
791 return MMSYSERR_BADDEVICEID;
794 /* FIXME: set all the variables correctly... the lines below
797 lpMl->fdwLine = MIXERLINE_LINEF_ACTIVE;
800 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK)
802 case MIXER_GETLINEINFOF_DESTINATION:
803 TRACE("MIXER_GETLINEINFOF_DESTINATION (%08x)\n", lpMl->dwDestination);
804 if (lpMl->dwDestination >= 2) {
805 WARN("invalid parameter: lpMl->dwDestination = %d >= 2\n",
806 lpMl->dwDestination);
807 return MMSYSERR_INVALPARAM;
809 ret = MIX_GetLineInfoDst(mix, lpMl, lpMl->dwDestination);
810 if (ret != MMSYSERR_NOERROR) {
815 case MIXER_GETLINEINFOF_SOURCE:
816 TRACE("MIXER_GETLINEINFOF_SOURCE (%08x), dst=%08x\n", lpMl->dwSource,
817 lpMl->dwDestination);
818 switch (lpMl->dwDestination)
820 case LINEID_SPEAKER: mask = mix->devMask; break;
821 case LINEID_RECORD: mask = mix->recMask; break;
823 WARN("invalid parameter\n");
824 return MMSYSERR_INVALPARAM;
827 for (j = 0; j < SOUND_MIXER_NRDEVICES; j++)
829 if (WINE_CHN_SUPPORTS(mask, j) && (i-- == 0))
832 if (j >= SOUND_MIXER_NRDEVICES) {
833 WARN("invalid line\n");
834 return MIXERR_INVALLINE;
836 ret = MIX_GetLineInfoSrc(mix, lpMl, j, lpMl->dwDestination);
837 if (ret != MMSYSERR_NOERROR) {
842 case MIXER_GETLINEINFOF_LINEID:
843 TRACE("MIXER_GETLINEINFOF_LINEID (%08x)\n", lpMl->dwLineID);
845 if (!MIX_CheckLine(lpMl->dwLineID)) {
846 WARN("invalid line\n");
847 return MIXERR_INVALLINE;
849 if (HIWORD(lpMl->dwLineID) == LINEID_DST)
850 ret = MIX_GetLineInfoDst(mix, lpMl, LOWORD(lpMl->dwLineID));
852 ret = MIX_GetLineInfoSrc(mix, lpMl, HIWORD(lpMl->dwLineID),
853 LOWORD(lpMl->dwLineID));
854 if (ret != MMSYSERR_NOERROR) {
859 case MIXER_GETLINEINFOF_COMPONENTTYPE:
860 TRACE("MIXER_GETLINEINFOF_COMPONENTTYPE (%s)\n",
861 getComponentType(lpMl->dwComponentType));
862 switch (lpMl->dwComponentType)
864 case MIXERLINE_COMPONENTTYPE_DST_HEADPHONES:
865 case MIXERLINE_COMPONENTTYPE_DST_SPEAKERS:
866 ret = MIX_GetLineInfoDst(mix, lpMl, LINEID_SPEAKER);
868 case MIXERLINE_COMPONENTTYPE_DST_LINE:
869 case MIXERLINE_COMPONENTTYPE_DST_VOICEIN:
870 case MIXERLINE_COMPONENTTYPE_DST_WAVEIN:
871 ret = MIX_GetLineInfoDst(mix, lpMl, LINEID_RECORD);
873 case MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER:
874 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_SYNTH, 0);
876 case MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC:
877 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_CD, 0);
879 case MIXERLINE_COMPONENTTYPE_SRC_LINE:
880 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_LINE, 0);
882 case MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE:
883 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_MIC, 1);
885 case MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT:
886 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_PCM, 0);
888 case MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED:
889 ret = MIX_GetLineInfoSrc(mix, lpMl, SOUND_MIXER_IMIX, 1);
892 FIXME("Unhandled component type (%s)\n",
893 getComponentType(lpMl->dwComponentType));
894 return MMSYSERR_INVALPARAM;
897 case MIXER_GETLINEINFOF_TARGETTYPE:
898 FIXME("MIXER_GETLINEINFOF_TARGETTYPE not implemented yet.\n");
899 TRACE("MIXER_GETLINEINFOF_TARGETTYPE (%s)\n",
900 getTargetType(lpMl->Target.dwType));
901 switch (lpMl->Target.dwType) {
902 case MIXERLINE_TARGETTYPE_UNDEFINED:
903 case MIXERLINE_TARGETTYPE_WAVEOUT:
904 case MIXERLINE_TARGETTYPE_WAVEIN:
905 case MIXERLINE_TARGETTYPE_MIDIOUT:
906 case MIXERLINE_TARGETTYPE_MIDIIN:
907 case MIXERLINE_TARGETTYPE_AUX:
909 FIXME("Unhandled target type (%s)\n",
910 getTargetType(lpMl->Target.dwType));
911 return MMSYSERR_INVALPARAM;
915 WARN("Unknown flag (%08lx)\n", fdwInfo & MIXER_GETLINEINFOF_QUERYMASK);
919 if ((fdwInfo & MIXER_GETLINEINFOF_QUERYMASK) != MIXER_GETLINEINFOF_TARGETTYPE) {
921 lpMl->Target.dwDeviceID = 0xFFFFFFFF;
922 lpMl->Target.wMid = WINE_MIXER_MANUF_ID;
923 lpMl->Target.wPid = WINE_MIXER_PRODUCT_ID;
924 lpMl->Target.vDriverVersion = WINE_MIXER_VERSION;
925 if (!(name = mix->name)) name = WINE_MIXER_NAME;
926 MultiByteToWideChar(CP_ACP, 0, name, -1, lpMl->Target.szPname, sizeof(lpMl->Target.szPname) / sizeof(WCHAR));
932 /******************************************************************
936 static BOOL MIX_CheckControl(struct mixer* mix, DWORD ctrlID)
938 TRACE("(%p, %08x)\n", mix, ctrlID);
940 return (ctrlID >= 1 && ctrlID <= mix->numCtrl);
943 /**************************************************************************
944 * MIX_GetLineControls [internal]
946 static DWORD MIX_GetLineControls(WORD wDevID, LPMIXERLINECONTROLSW lpMlc,
949 DWORD dwRet = MMSYSERR_NOERROR;
952 TRACE("(%04X, %p, %u);\n", wDevID, lpMlc, flags);
955 WARN("invalid parameter: lpMlc == NULL\n");
956 return MMSYSERR_INVALPARAM;
959 if (lpMlc->cbStruct < sizeof(*lpMlc)) {
960 WARN("invalid parameter: lpMlc->cbStruct = %d < %d\n",
961 lpMlc->cbStruct, sizeof(*lpMlc));
962 return MMSYSERR_INVALPARAM;
965 if (lpMlc->cbmxctrl < sizeof(MIXERCONTROLW)) {
966 WARN("invalid parameter: lpMlc->cbmxctrl = %d < %d\n",
967 lpMlc->cbmxctrl, sizeof(MIXERCONTROLW));
968 return MMSYSERR_INVALPARAM;
971 if ((mix = MIX_Get(wDevID)) == NULL) {
972 WARN("bad device ID: %04X\n", wDevID);
973 return MMSYSERR_BADDEVICEID;
976 switch (flags & MIXER_GETLINECONTROLSF_QUERYMASK)
978 case MIXER_GETLINECONTROLSF_ALL:
982 TRACE("line=%08x MIXER_GETLINECONTROLSF_ALL (%d)\n",
983 lpMlc->dwLineID, lpMlc->cControls);
985 for (i = j = 0; i < mix->numCtrl; i++)
987 if (mix->ctrl[i].dwLineID == lpMlc->dwLineID)
991 if (!j || lpMlc->cControls != j) {
992 WARN("invalid parameter\n");
993 dwRet = MMSYSERR_INVALPARAM;
994 } else if (!MIX_CheckLine(lpMlc->dwLineID)) {
995 WARN("invalid line\n");
996 dwRet = MIXERR_INVALLINE;
998 for (i = j = 0; i < mix->numCtrl; i++)
1000 if (mix->ctrl[i].dwLineID == lpMlc->dwLineID)
1002 TRACE("[%d] => [%2d]: typ=%08x\n", j, i + 1,
1003 mix->ctrl[i].ctrl.dwControlType);
1004 lpMlc->pamxctrl[j++] = mix->ctrl[i].ctrl;
1010 case MIXER_GETLINECONTROLSF_ONEBYID:
1011 TRACE("line=%08x MIXER_GETLINECONTROLSF_ONEBYID (%x)\n",
1012 lpMlc->dwLineID, lpMlc->u.dwControlID);
1014 if (!MIX_CheckControl(mix, lpMlc->u.dwControlID) ||
1015 mix->ctrl[lpMlc->u.dwControlID - 1].dwLineID != lpMlc->dwLineID) {
1016 WARN("invalid parameter\n");
1017 dwRet = MMSYSERR_INVALPARAM;
1019 lpMlc->pamxctrl[0] = mix->ctrl[lpMlc->u.dwControlID - 1].ctrl;
1021 case MIXER_GETLINECONTROLSF_ONEBYTYPE:
1022 TRACE("line=%08x MIXER_GETLINECONTROLSF_ONEBYTYPE (%s)\n",
1023 lpMlc->dwLineID, getControlType(lpMlc->u.dwControlType));
1024 if (!MIX_CheckLine(lpMlc->dwLineID)) {
1025 WARN("invalid line\n");
1026 dwRet = MIXERR_INVALLINE;
1029 DWORD ct = lpMlc->u.dwControlType & MIXERCONTROL_CT_CLASS_MASK;
1030 for (i = 0; i < mix->numCtrl; i++) {
1031 if (mix->ctrl[i].dwLineID == lpMlc->dwLineID &&
1032 ct == (mix->ctrl[i].ctrl.dwControlType &
1033 MIXERCONTROL_CT_CLASS_MASK)) {
1034 lpMlc->pamxctrl[0] = mix->ctrl[i].ctrl;
1039 if (i == mix->numCtrl) {
1040 WARN("invalid parameter: control not found\n");
1041 dwRet = MMSYSERR_INVALPARAM;
1046 ERR("Unknown flag %08lx\n", flags & MIXER_GETLINECONTROLSF_QUERYMASK);
1047 dwRet = MMSYSERR_INVALPARAM;
1053 /**************************************************************************
1054 * MIX_GetControlDetails [internal]
1056 static DWORD MIX_GetControlDetails(WORD wDevID, LPMIXERCONTROLDETAILS lpmcd,
1059 DWORD ret = MMSYSERR_NOTSUPPORTED;
1063 TRACE("(%04X, %p, %u);\n", wDevID, lpmcd, fdwDetails);
1065 if (lpmcd == NULL) {
1066 WARN("invalid parameter: lpmcd == NULL\n");
1067 return MMSYSERR_INVALPARAM;
1070 if ((mix = MIX_Get(wDevID)) == NULL) {
1071 WARN("bad device ID: %04X\n", wDevID);
1072 return MMSYSERR_BADDEVICEID;
1075 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK)
1077 case MIXER_GETCONTROLDETAILSF_VALUE:
1078 TRACE("MIXER_GETCONTROLDETAILSF_VALUE (%08x)\n", lpmcd->dwControlID);
1079 if (MIX_CheckControl(mix, lpmcd->dwControlID))
1081 c = lpmcd->dwControlID - 1;
1082 chnl = HIWORD(mix->ctrl[c].dwLineID);
1083 if (chnl == LINEID_DST)
1084 chnl = LOWORD(mix->ctrl[c].dwLineID) ? SOUND_MIXER_RECLEV :
1086 switch (mix->ctrl[c].ctrl.dwControlType)
1088 case MIXERCONTROL_CONTROLTYPE_VOLUME:
1090 LPMIXERCONTROLDETAILS_UNSIGNED mcdu;
1093 if (lpmcd->cbDetails !=
1094 sizeof(MIXERCONTROLDETAILS_UNSIGNED)) {
1095 WARN("invalid parameter: cbDetails != %d\n",
1096 sizeof(MIXERCONTROLDETAILS_UNSIGNED));
1097 return MMSYSERR_INVALPARAM;
1100 TRACE("%s MIXERCONTROLDETAILS_UNSIGNED[%u]\n",
1101 getControlType(mix->ctrl[c].ctrl.dwControlType),
1104 mcdu = (LPMIXERCONTROLDETAILS_UNSIGNED)lpmcd->paDetails;
1106 /* return value is 00RL (4 bytes)... */
1107 if ((val = mix->volume[chnl]) == -1 &&
1108 !MIX_GetVal(mix, chnl, &val)) {
1109 WARN("invalid parameter\n");
1110 return MMSYSERR_INVALPARAM;
1113 switch (lpmcd->cChannels)
1116 /* mono... so R = L */
1117 mcdu->dwValue = ((LOBYTE(LOWORD(val)) * 65536.0) / 100.0) + 0.5;
1118 TRACE("Reading RL = %d\n", mcdu->dwValue);
1121 /* stereo, left is paDetails[0] */
1122 mcdu->dwValue = ((LOBYTE(LOWORD(val)) * 65536.0) / 100.0) + 0.5;
1123 TRACE("Reading L = %d\n", mcdu->dwValue);
1125 mcdu->dwValue = ((HIBYTE(LOWORD(val)) * 65536.0) / 100.0) + 0.5;
1126 TRACE("Reading R = %d\n", mcdu->dwValue);
1129 WARN("Unsupported cChannels (%d)\n", lpmcd->cChannels);
1130 return MMSYSERR_INVALPARAM;
1132 TRACE("=> %08x\n", mcdu->dwValue);
1135 case MIXERCONTROL_CONTROLTYPE_MUTE:
1136 case MIXERCONTROL_CONTROLTYPE_ONOFF:
1138 LPMIXERCONTROLDETAILS_BOOLEAN mcdb;
1140 if (lpmcd->cbDetails !=
1141 sizeof(MIXERCONTROLDETAILS_BOOLEAN)) {
1142 WARN("invalid parameter: cbDetails != %d\n",
1143 sizeof(MIXERCONTROLDETAILS_BOOLEAN));
1144 return MMSYSERR_INVALPARAM;
1147 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n",
1148 getControlType(mix->ctrl[c].ctrl.dwControlType),
1151 /* we mute both channels at the same time */
1152 mcdb = (LPMIXERCONTROLDETAILS_BOOLEAN)lpmcd->paDetails;
1153 mcdb->fValue = (mix->volume[chnl] != -1);
1154 TRACE("=> %s\n", mcdb->fValue ? "on" : "off");
1157 case MIXERCONTROL_CONTROLTYPE_MIXER:
1158 case MIXERCONTROL_CONTROLTYPE_MUX:
1162 if (lpmcd->cbDetails !=
1163 sizeof(MIXERCONTROLDETAILS_BOOLEAN)) {
1164 WARN("invalid parameter: cbDetails != %d\n",
1165 sizeof(MIXERCONTROLDETAILS_BOOLEAN));
1166 return MMSYSERR_INVALPARAM;
1169 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n",
1170 getControlType(mix->ctrl[c].ctrl.dwControlType),
1173 if (!MIX_GetRecSrc(mix, &mask))
1175 /* FIXME: ENXIO => no mixer installed */
1176 WARN("mixer device not available !\n");
1177 ret = MMSYSERR_ERROR;
1181 LPMIXERCONTROLDETAILS_BOOLEAN mcdb;
1184 /* we mute both channels at the same time */
1185 mcdb = (LPMIXERCONTROLDETAILS_BOOLEAN)lpmcd->paDetails;
1187 for (i = j = 0; j < SOUND_MIXER_NRDEVICES; j++)
1189 if (WINE_CHN_SUPPORTS(mix->recMask, j))
1191 if (i >= lpmcd->u.cMultipleItems)
1192 return MMSYSERR_INVALPARAM;
1193 mcdb[i++].fValue = WINE_CHN_SUPPORTS(mask, j);
1200 WARN("%s Unsupported\n",
1201 getControlType(mix->ctrl[c].ctrl.dwControlType));
1203 ret = MMSYSERR_NOERROR;
1207 WARN("invalid parameter\n");
1208 ret = MMSYSERR_INVALPARAM;
1211 case MIXER_GETCONTROLDETAILSF_LISTTEXT:
1212 TRACE("MIXER_GETCONTROLDETAILSF_LISTTEXT (%08x)\n",
1213 lpmcd->dwControlID);
1215 ret = MMSYSERR_INVALPARAM;
1216 if (MIX_CheckControl(mix, lpmcd->dwControlID))
1218 int c = lpmcd->dwControlID - 1;
1220 if (mix->ctrl[c].ctrl.dwControlType == MIXERCONTROL_CONTROLTYPE_MUX ||
1221 mix->ctrl[c].ctrl.dwControlType == MIXERCONTROL_CONTROLTYPE_MIXER)
1223 LPMIXERCONTROLDETAILS_LISTTEXTW mcdlt;
1226 mcdlt = (LPMIXERCONTROLDETAILS_LISTTEXTW)lpmcd->paDetails;
1227 for (i = j = 0; j < SOUND_MIXER_NRDEVICES; j++)
1229 if (WINE_CHN_SUPPORTS(mix->recMask, j))
1231 mcdlt[i].dwParam1 = MAKELONG(LINEID_RECORD, j);
1232 mcdlt[i].dwParam2 = 0;
1233 MultiByteToWideChar(CP_ACP, 0, MIX_Names[j], -1,
1234 mcdlt[i].szName, sizeof(mcdlt[i]) / sizeof(WCHAR));
1238 if (i != lpmcd->u.cMultipleItems) FIXME("bad count\n");
1239 ret = MMSYSERR_NOERROR;
1244 WARN("Unknown flag (%08lx)\n",
1245 fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK);
1250 /**************************************************************************
1251 * MIX_SetControlDetails [internal]
1253 static DWORD MIX_SetControlDetails(WORD wDevID, LPMIXERCONTROLDETAILS lpmcd,
1256 DWORD ret = MMSYSERR_NOTSUPPORTED;
1261 TRACE("(%04X, %p, %u);\n", wDevID, lpmcd, fdwDetails);
1263 if (lpmcd == NULL) {
1264 TRACE("invalid parameter: lpmcd == NULL\n");
1265 return MMSYSERR_INVALPARAM;
1268 if ((mix = MIX_Get(wDevID)) == NULL) {
1269 WARN("bad device ID: %04X\n", wDevID);
1270 return MMSYSERR_BADDEVICEID;
1273 switch (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK)
1275 case MIXER_GETCONTROLDETAILSF_VALUE:
1276 TRACE("MIXER_GETCONTROLDETAILSF_VALUE (%08x)\n", lpmcd->dwControlID);
1277 if (MIX_CheckControl(mix, lpmcd->dwControlID))
1279 c = lpmcd->dwControlID - 1;
1281 TRACE("dwLineID=%08x\n",mix->ctrl[c].dwLineID);
1283 chnl = HIWORD(mix->ctrl[c].dwLineID);
1284 if (chnl == LINEID_DST)
1285 chnl = LOWORD(mix->ctrl[c].dwLineID) ?
1286 SOUND_MIXER_RECLEV : SOUND_MIXER_VOLUME;
1288 switch (mix->ctrl[c].ctrl.dwControlType)
1290 case MIXERCONTROL_CONTROLTYPE_VOLUME:
1292 LPMIXERCONTROLDETAILS_UNSIGNED mcdu;
1294 if (lpmcd->cbDetails !=
1295 sizeof(MIXERCONTROLDETAILS_UNSIGNED)) {
1296 WARN("invalid parameter: cbDetails != %d\n",
1297 sizeof(MIXERCONTROLDETAILS_UNSIGNED));
1298 return MMSYSERR_INVALPARAM;
1301 TRACE("%s MIXERCONTROLDETAILS_UNSIGNED[%u]\n",
1302 getControlType(mix->ctrl[c].ctrl.dwControlType),
1305 mcdu = (LPMIXERCONTROLDETAILS_UNSIGNED)lpmcd->paDetails;
1306 /* val should contain 00RL */
1307 switch (lpmcd->cChannels)
1310 /* mono... so R = L */
1311 TRACE("Setting RL to %d\n", mcdu->dwValue);
1312 val = 0x101 * ((mcdu->dwValue * 100) >> 16);
1315 /* stereo, left is paDetails[0] */
1316 TRACE("Setting L to %d\n", mcdu->dwValue);
1317 val = ((mcdu->dwValue * 100.0) / 65536.0) + 0.5;
1319 TRACE("Setting R to %d\n", mcdu->dwValue);
1320 val += (int)(((mcdu->dwValue * 100) / 65536.0) + 0.5) << 8;
1323 WARN("Unsupported cChannels (%d)\n", lpmcd->cChannels);
1324 return MMSYSERR_INVALPARAM;
1327 if (mix->volume[chnl] == -1)
1329 if (!MIX_SetVal(mix, chnl, val)) {
1330 WARN("invalid parameter\n");
1331 return MMSYSERR_INVALPARAM;
1336 mix->volume[chnl] = val;
1339 ret = MMSYSERR_NOERROR;
1341 case MIXERCONTROL_CONTROLTYPE_MUTE:
1342 case MIXERCONTROL_CONTROLTYPE_ONOFF:
1344 LPMIXERCONTROLDETAILS_BOOLEAN mcdb;
1346 if (lpmcd->cbDetails !=
1347 sizeof(MIXERCONTROLDETAILS_BOOLEAN)) {
1348 WARN("invalid parameter: cbDetails != %d\n",
1349 sizeof(MIXERCONTROLDETAILS_BOOLEAN));
1350 return MMSYSERR_INVALPARAM;
1353 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n",
1354 getControlType(mix->ctrl[c].ctrl.dwControlType),
1357 mcdb = (LPMIXERCONTROLDETAILS_BOOLEAN)lpmcd->paDetails;
1360 /* save the volume and then set it to 0 */
1361 if (!MIX_GetVal(mix, chnl, &mix->volume[chnl]) ||
1362 !MIX_SetVal(mix, chnl, 0)) {
1363 WARN("invalid parameter\n");
1364 return MMSYSERR_INVALPARAM;
1369 if (mix->volume[chnl] == -1)
1371 ret = MMSYSERR_NOERROR;
1374 if (!MIX_SetVal(mix, chnl, mix->volume[chnl])) {
1375 WARN("invalid parameter\n");
1376 return MMSYSERR_INVALPARAM;
1378 mix->volume[chnl] = -1;
1381 ret = MMSYSERR_NOERROR;
1383 case MIXERCONTROL_CONTROLTYPE_MIXER:
1384 case MIXERCONTROL_CONTROLTYPE_MUX:
1386 LPMIXERCONTROLDETAILS_BOOLEAN mcdb;
1390 if (lpmcd->cbDetails !=
1391 sizeof(MIXERCONTROLDETAILS_BOOLEAN)) {
1392 WARN("invalid parameter: cbDetails != %d\n",
1393 sizeof(MIXERCONTROLDETAILS_BOOLEAN));
1394 return MMSYSERR_INVALPARAM;
1397 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n",
1398 getControlType(mix->ctrl[c].ctrl.dwControlType),
1401 /* we mute both channels at the same time */
1402 mcdb = (LPMIXERCONTROLDETAILS_BOOLEAN)lpmcd->paDetails;
1404 for (i = j = 0; j < SOUND_MIXER_NRDEVICES; j++)
1406 if (WINE_CHN_SUPPORTS(mix->recMask, j) &&
1409 /* a mux can only select one line at a time... */
1410 if (mix->singleRecChannel && mask != 0)
1413 return MMSYSERR_INVALPARAM;
1415 mask |= WINE_CHN_MASK(j);
1418 if (i != lpmcd->u.cMultipleItems)
1419 FIXME("bad count\n");
1420 TRACE("writing %04x as rec src\n", mask);
1421 if (!MIX_SetRecSrc(mix, mask))
1422 ERR("Can't write new mixer settings\n");
1424 ret = MMSYSERR_NOERROR;
1431 WARN("Unknown SetControlDetails flag (%08lx)\n",
1432 fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK);
1437 /**************************************************************************
1438 * MIX_Init [internal]
1440 LRESULT OSS_MixerInit(void)
1448 for (i = 0; i < MAX_MIXERDRV; i++) {
1452 sprintf(name, "/dev/mixer");
1454 sprintf(name, "/dev/mixer%d", i);
1456 if ((mixer = open(name, O_RDWR)) >= 0) {
1457 #ifdef SOUND_MIXER_INFO
1459 if (ioctl(mixer, SOUND_MIXER_INFO, &info) >= 0) {
1460 MIX_Mixers[MIX_NumMixers].name = HeapAlloc(GetProcessHeap(),0,strlen(info.name) + 1);
1461 strcpy(MIX_Mixers[MIX_NumMixers].name, info.name);
1463 /* FreeBSD up to at least 5.2 provides this ioctl, but does not
1464 * implement it properly, and there are probably similar issues
1465 * on other platforms, so we warn but try to go ahead.
1467 WARN("%s: cannot read SOUND_MIXER_INFO!\n", name);
1472 MIX_Mixers[MIX_NumMixers].dev_name = HeapAlloc(GetProcessHeap(),0,strlen(name) + 1);
1473 strcpy(MIX_Mixers[MIX_NumMixers].dev_name, name);
1475 MIX_Open(MIX_NumMixers - 1, NULL, 0); /* FIXME */
1477 WARN("couldn't open %s\n", name);
1481 if (MIX_NumMixers == 0) {
1482 WARN("no driver\n");
1483 return MMSYSERR_NODRIVER;
1486 return MMSYSERR_NOERROR;
1489 /**************************************************************************
1490 * MIX_Exit [internal]
1492 LRESULT OSS_MixerExit(void)
1498 for (i = 0; i < MIX_NumMixers; i++) {
1499 HeapFree(GetProcessHeap(),0,MIX_Mixers[i].name);
1500 HeapFree(GetProcessHeap(),0,MIX_Mixers[i].dev_name);
1503 return MMSYSERR_NOERROR;
1506 /**************************************************************************
1507 * MIX_GetNumDevs [internal]
1509 static DWORD MIX_GetNumDevs(void)
1513 return MIX_NumMixers;
1516 #endif /* HAVE_OSS */
1518 /**************************************************************************
1519 * mxdMessage (WINEOSS.3)
1521 DWORD WINAPI OSS_mxdMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
1522 DWORD dwParam1, DWORD dwParam2)
1525 TRACE("(%04X, %s, %08X, %08X, %08X);\n", wDevID, getMessage(wMsg),
1526 dwUser, dwParam1, dwParam2);
1534 /* FIXME: Pretend this is supported */
1536 case MXDM_GETDEVCAPS:
1537 return MIX_GetDevCaps(wDevID, (LPMIXERCAPSW)dwParam1, dwParam2);
1538 case MXDM_GETLINEINFO:
1539 return MIX_GetLineInfo(wDevID, (LPMIXERLINEW)dwParam1, dwParam2);
1540 case MXDM_GETNUMDEVS:
1541 return MIX_GetNumDevs();
1543 return MMSYSERR_NOERROR;
1544 /* MIX_Open(wDevID, (LPMIXEROPENDESC)dwParam1, dwParam2); */
1546 return MMSYSERR_NOERROR;
1547 case MXDM_GETLINECONTROLS:
1548 return MIX_GetLineControls(wDevID, (LPMIXERLINECONTROLSW)dwParam1, dwParam2);
1549 case MXDM_GETCONTROLDETAILS:
1550 return MIX_GetControlDetails(wDevID, (LPMIXERCONTROLDETAILS)dwParam1, dwParam2);
1551 case MXDM_SETCONTROLDETAILS:
1552 return MIX_SetControlDetails(wDevID, (LPMIXERCONTROLDETAILS)dwParam1, dwParam2);
1554 WARN("unknown message %d!\n", wMsg);
1555 return MMSYSERR_NOTSUPPORTED;
1558 TRACE("(%04X, %04X, %08X, %08X, %08X);\n", wDevID, wMsg,
1559 dwUser, dwParam1, dwParam2);
1561 return MMSYSERR_NOTENABLED;