2 * Sample MIXER Wine Driver for Mac OS X (based on OSS mixer)
4 * Copyright 1997 Marcus Meissner
5 * 1999,2001 Eric Pouech
6 * 2006,2007 Emmanuel Maillard
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
40 #include "coreaudio.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(mixer);
46 #if defined(HAVE_COREAUDIO_COREAUDIO_H)
47 #include <CoreAudio/CoreAudio.h>
48 #include <CoreFoundation/CoreFoundation.h>
50 #define WINE_MIXER_NAME "CoreAudio Mixer"
52 #define InputDevice (1 << 0)
53 #define OutputDevice (1 << 1)
55 #define IsInput(dir) ((dir) & InputDevice)
56 #define IsOutput(dir) ((dir) & OutputDevice)
58 #define ControlsPerLine 2 /* number of control per line : volume & (mute | onoff) */
60 #define IDControlVolume 0
61 #define IDControlMute 1
63 typedef struct tagMixerLine
69 AudioDeviceID deviceID;
72 typedef struct tagMixerCtrl
78 typedef struct tagCoreAudio_Mixer
82 MixerCtrl *mixerCtrls;
87 static CoreAudio_Mixer mixer;
88 static int numMixers = 1;
90 /**************************************************************************
93 static const char * getMessage(UINT uMsg)
96 #define MSG_TO_STR(x) case x: return #x;
98 MSG_TO_STR(DRVM_INIT);
99 MSG_TO_STR(DRVM_EXIT);
100 MSG_TO_STR(DRVM_ENABLE);
101 MSG_TO_STR(DRVM_DISABLE);
102 MSG_TO_STR(MXDM_GETDEVCAPS);
103 MSG_TO_STR(MXDM_GETLINEINFO);
104 MSG_TO_STR(MXDM_GETNUMDEVS);
105 MSG_TO_STR(MXDM_OPEN);
106 MSG_TO_STR(MXDM_CLOSE);
107 MSG_TO_STR(MXDM_GETLINECONTROLS);
108 MSG_TO_STR(MXDM_GETCONTROLDETAILS);
109 MSG_TO_STR(MXDM_SETCONTROLDETAILS);
112 sprintf(str, "UNKNOWN(%08x)", uMsg);
116 static const char * getControlType(DWORD dwControlType)
119 #define TYPE_TO_STR(x) case x: return #x;
120 switch (dwControlType) {
121 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_CUSTOM);
122 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BOOLEANMETER);
123 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SIGNEDMETER);
124 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PEAKMETER);
125 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_UNSIGNEDMETER);
126 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BOOLEAN);
127 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_ONOFF);
128 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MUTE);
129 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MONO);
130 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_LOUDNESS);
131 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_STEREOENH);
132 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BASS_BOOST);
133 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BUTTON);
134 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_DECIBELS);
135 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SIGNED);
136 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_UNSIGNED);
137 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PERCENT);
138 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SLIDER);
139 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_PAN);
140 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_QSOUNDPAN);
141 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_FADER);
142 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_VOLUME);
143 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_BASS);
144 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_TREBLE);
145 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_EQUALIZER);
146 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_SINGLESELECT);
147 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MUX);
148 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MULTIPLESELECT);
149 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MIXER);
150 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MICROTIME);
151 TYPE_TO_STR(MIXERCONTROL_CONTROLTYPE_MILLITIME);
154 sprintf(str, "UNKNOWN(%08x)", dwControlType);
158 static const char * getComponentType(DWORD dwComponentType)
161 #define TYPE_TO_STR(x) case x: return #x;
162 switch (dwComponentType) {
163 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_UNDEFINED);
164 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_DIGITAL);
165 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_LINE);
166 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_MONITOR);
167 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
168 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_HEADPHONES);
169 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_TELEPHONE);
170 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_WAVEIN);
171 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_DST_VOICEIN);
172 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED);
173 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_DIGITAL);
174 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_LINE);
175 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE);
176 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER);
177 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC);
178 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE);
179 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER);
180 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT);
181 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY);
182 TYPE_TO_STR(MIXERLINE_COMPONENTTYPE_SRC_ANALOG);
185 sprintf(str, "UNKNOWN(%08x)", dwComponentType);
189 static const char * getTargetType(DWORD dwType)
192 #define TYPE_TO_STR(x) case x: return #x;
194 TYPE_TO_STR(MIXERLINE_TARGETTYPE_UNDEFINED);
195 TYPE_TO_STR(MIXERLINE_TARGETTYPE_WAVEOUT);
196 TYPE_TO_STR(MIXERLINE_TARGETTYPE_WAVEIN);
197 TYPE_TO_STR(MIXERLINE_TARGETTYPE_MIDIOUT);
198 TYPE_TO_STR(MIXERLINE_TARGETTYPE_MIDIIN);
199 TYPE_TO_STR(MIXERLINE_TARGETTYPE_AUX);
202 sprintf(str, "UNKNOWN(%08x)", dwType);
206 /* FIXME is there a better way ? */
207 static DWORD DeviceComponentType(char *name)
209 if (strcmp(name, "Built-in Microphone") == 0)
210 return MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE;
212 if (strcmp(name, "Built-in Line Input") == 0)
213 return MIXERLINE_COMPONENTTYPE_SRC_LINE;
215 if (strcmp(name, "Built-in Output") == 0)
216 return MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
218 return MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED;
221 static BOOL DeviceHasMute(AudioDeviceID deviceID, Boolean isInput)
223 Boolean writable = false;
224 OSStatus err = noErr;
225 err = AudioDeviceGetPropertyInfo(deviceID, 0, isInput, kAudioDevicePropertyMute, NULL, NULL);
228 /* check if we can set it */
229 err = AudioDeviceGetPropertyInfo(deviceID, 0, isInput, kAudioDevicePropertyMute, NULL, &writable);
239 static BOOL MIX_LineGetVolume(DWORD lineID, DWORD channels, Float32 *left, Float32 *right)
241 MixerLine *line = &mixer.lines[lineID];
242 UInt32 size = sizeof(Float32);
243 OSStatus err = noErr;
244 *left = *right = 0.0;
246 err = AudioDeviceGetProperty(line->deviceID, 1, IsInput(line->direction), kAudioDevicePropertyVolumeScalar, &size, left);
252 size = sizeof(Float32);
253 err = AudioDeviceGetProperty(line->deviceID, 2, IsInput(line->direction), kAudioDevicePropertyVolumeScalar, &size, right);
258 TRACE("lineID %d channels %d return left %f right %f\n", lineID, channels, *left, *right);
259 return (err == noErr);
262 static BOOL MIX_LineGetMute(DWORD lineID, BOOL *muted)
264 MixerLine *line = &mixer.lines[lineID];
265 UInt32 size = sizeof(UInt32);
267 OSStatus err = noErr;
268 err = AudioDeviceGetProperty(line->deviceID, 0, IsInput(line->direction), kAudioDevicePropertyMute, &size, &val);
271 return (err == noErr);
277 static BOOL MIX_LineSetVolume(DWORD lineID, DWORD channels, Float32 left, Float32 right)
279 MixerLine *line = &mixer.lines[lineID];
280 UInt32 size = sizeof(Float32);
281 OSStatus err = noErr;
282 TRACE("lineID %d channels %d left %f right %f\n", lineID, channels, left, right);
286 err = AudioDeviceSetProperty(line->deviceID, NULL, 1, IsInput(line->direction), kAudioDevicePropertyVolumeScalar, size, &left);
290 err = AudioDeviceSetProperty(line->deviceID, NULL, 2, IsInput(line->direction), kAudioDevicePropertyVolumeScalar, size, &right);
295 FIXME Using master channel failed ?? return kAudioHardwareUnknownPropertyError
296 err = AudioDeviceSetProperty(line->deviceID, NULL, 0, IsInput(line->direction), kAudioDevicePropertyVolumeScalar, size, &left);
299 err = AudioDeviceSetProperty(line->deviceID, NULL, 1, IsInput(line->direction), kAudioDevicePropertyVolumeScalar, size, &left);
302 err = AudioDeviceSetProperty(line->deviceID, NULL, 2, IsInput(line->direction), kAudioDevicePropertyVolumeScalar, size, &right);
304 return (err == noErr);
307 static BOOL MIX_LineSetMute(DWORD lineID, BOOL mute)
309 MixerLine *line = &mixer.lines[lineID];
311 UInt32 size = sizeof(UInt32);
312 OSStatus err = noErr;
314 err = AudioDeviceSetProperty(line->deviceID, 0, 0, IsInput(line->direction), kAudioDevicePropertyMute, size, &val);
315 return (err == noErr);
318 static void MIX_FillControls(void)
323 for (i = 0; i < mixer.caps.cDestinations; i++)
325 line = &mixer.lines[i];
326 mixer.mixerCtrls[ctrl].dwLineID = i;
327 mixer.mixerCtrls[ctrl].ctrl.cbStruct = sizeof(MIXERCONTROLW);
328 mixer.mixerCtrls[ctrl].ctrl.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
329 mixer.mixerCtrls[ctrl].ctrl.dwControlID = ctrl;
330 mixer.mixerCtrls[ctrl].ctrl.Bounds.s1.dwMinimum = 0;
331 mixer.mixerCtrls[ctrl].ctrl.Bounds.s1.dwMaximum = 65535;
332 mixer.mixerCtrls[ctrl].ctrl.Metrics.cSteps = 656;
335 mixer.mixerCtrls[ctrl].dwLineID = i;
336 if ( !DeviceHasMute(line->deviceID, IsInput(line->direction)) )
337 mixer.mixerCtrls[ctrl].ctrl.fdwControl |= MIXERCONTROL_CONTROLF_DISABLED;
339 mixer.mixerCtrls[ctrl].ctrl.cbStruct = sizeof(MIXERCONTROLW);
340 mixer.mixerCtrls[ctrl].ctrl.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE;
341 mixer.mixerCtrls[ctrl].ctrl.dwControlID = ctrl;
342 mixer.mixerCtrls[ctrl].ctrl.Bounds.s1.dwMinimum = 0;
343 mixer.mixerCtrls[ctrl].ctrl.Bounds.s1.dwMaximum = 1;
346 assert(ctrl == mixer.numCtrl);
349 /**************************************************************************
350 * CoreAudio_MixerInit
352 LONG CoreAudio_MixerInit(void)
356 AudioDeviceID *deviceArray = NULL;
357 char name[MAXPNAMELEN];
361 AudioStreamBasicDescription streamDescription;
363 /* Find number of lines */
364 status = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &propertySize, NULL);
367 ERR("AudioHardwareGetPropertyInfo for kAudioHardwarePropertyDevices return %s\n", wine_dbgstr_fourcc(status));
371 numLines = propertySize / sizeof(AudioDeviceID);
373 mixer.mixerCtrls = NULL;
377 mixer.caps.cDestinations = numLines;
378 mixer.caps.wMid = 0xAA;
379 mixer.caps.wPid = 0x55;
380 mixer.caps.vDriverVersion = 0x0100;
382 MultiByteToWideChar(CP_ACP, 0, WINE_MIXER_NAME, -1, mixer.caps.szPname, sizeof(mixer.caps.szPname) / sizeof(WCHAR));
384 mixer.caps.fdwSupport = 0; /* No bits defined yet */
386 mixer.lines = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MixerLine) * numLines);
390 deviceArray = HeapAlloc(GetProcessHeap(), 0, sizeof(AudioDeviceID) * numLines);
392 propertySize = sizeof(AudioDeviceID) * numLines;
393 status = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &propertySize, deviceArray);
396 ERR("AudioHardwareGetProperty for kAudioHardwarePropertyDevices return %s\n", wine_dbgstr_fourcc(status));
400 for (i = 0; i < numLines; i++)
403 MixerLine *line = &mixer.lines[i];
405 line->deviceID = deviceArray[i];
407 propertySize = MAXPNAMELEN;
408 status = AudioDeviceGetProperty(line->deviceID, 0 , FALSE, kAudioDevicePropertyDeviceName, &propertySize, name);
410 ERR("AudioHardwareGetProperty for kAudioDevicePropertyDeviceName return %s\n", wine_dbgstr_fourcc(status));
414 line->name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, strlen(name) + 1);
418 memcpy(line->name, name, strlen(name));
420 line->componentType = DeviceComponentType(line->name);
422 /* check for directions */
424 propertySize = sizeof(UInt32);
425 status = AudioDeviceGetPropertyInfo(line->deviceID, 0, FALSE, kAudioDevicePropertyStreams, &propertySize, &write );
427 ERR("AudioDeviceGetPropertyInfo for kAudioDevicePropertyDataSource return %s\n", wine_dbgstr_fourcc(status));
431 if ( (propertySize / sizeof(AudioStreamID)) != 0)
433 line->direction |= OutputDevice;
435 /* Check the number of channel for the stream */
436 propertySize = sizeof(streamDescription);
437 status = AudioDeviceGetProperty(line->deviceID, 0, FALSE , kAudioDevicePropertyStreamFormat, &propertySize, &streamDescription);
438 if (status != noErr) {
439 ERR("AudioHardwareGetProperty for kAudioDevicePropertyStreamFormat return %s\n", wine_dbgstr_fourcc(status));
442 line->numChannels = streamDescription.mChannelsPerFrame;
447 propertySize = sizeof(UInt32);
448 status = AudioDeviceGetPropertyInfo(line->deviceID, 0, TRUE, kAudioDevicePropertyStreams, &propertySize, &write );
450 ERR("AudioDeviceGetPropertyInfo for kAudioDevicePropertyStreams return %s\n", wine_dbgstr_fourcc(status));
453 if ( (propertySize / sizeof(AudioStreamID)) != 0)
455 line->direction |= InputDevice;
457 /* Check the number of channel for the stream */
458 propertySize = sizeof(streamDescription);
459 status = AudioDeviceGetProperty(line->deviceID, 0, TRUE, kAudioDevicePropertyStreamFormat, &propertySize, &streamDescription);
460 if (status != noErr) {
461 ERR("AudioHardwareGetProperty for kAudioDevicePropertyStreamFormat return %s\n", wine_dbgstr_fourcc(status));
464 line->numChannels = streamDescription.mChannelsPerFrame;
468 mixer.numCtrl += ControlsPerLine; /* volume & (mute | onoff) */
470 mixer.mixerCtrls = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MixerCtrl) * mixer.numCtrl);
471 if (!mixer.mixerCtrls)
476 HeapFree(GetProcessHeap(), 0, deviceArray);
483 for (i = 0; i < mixer.caps.cDestinations; i++)
485 HeapFree(GetProcessHeap(), 0, mixer.lines[i].name);
487 HeapFree(GetProcessHeap(), 0, mixer.lines);
489 HeapFree(GetProcessHeap(), 0, deviceArray);
490 if (mixer.mixerCtrls)
491 HeapFree(GetProcessHeap(), 0, mixer.mixerCtrls);
495 /**************************************************************************
496 * CoreAudio_MixerRelease
498 void CoreAudio_MixerRelease(void)
505 for (i = 0; i < mixer.caps.cDestinations; i++)
507 HeapFree(GetProcessHeap(), 0, mixer.lines[i].name);
509 HeapFree(GetProcessHeap(), 0, mixer.lines);
511 if (mixer.mixerCtrls)
512 HeapFree(GetProcessHeap(), 0, mixer.mixerCtrls);
515 /**************************************************************************
516 * MIX_Open [internal]
518 static DWORD MIX_Open(WORD wDevID, LPMIXEROPENDESC lpMod, DWORD_PTR flags)
520 TRACE("wDevID=%d lpMod=%p dwSize=%08lx\n", wDevID, lpMod, flags);
522 WARN("invalid parameter: lpMod == NULL\n");
523 return MMSYSERR_INVALPARAM;
526 if (wDevID >= numMixers) {
527 WARN("bad device ID: %04X\n", wDevID);
528 return MMSYSERR_BADDEVICEID;
530 return MMSYSERR_NOERROR;
533 /**************************************************************************
534 * MIX_GetNumDevs [internal]
536 static DWORD MIX_GetNumDevs(void)
542 static DWORD MIX_GetDevCaps(WORD wDevID, LPMIXERCAPSW lpCaps, DWORD_PTR dwSize)
544 TRACE("wDevID=%d lpCaps=%p\n", wDevID, lpCaps);
546 if (lpCaps == NULL) {
547 WARN("Invalid Parameter\n");
548 return MMSYSERR_INVALPARAM;
551 if (wDevID >= numMixers) {
552 WARN("bad device ID : %d\n", wDevID);
553 return MMSYSERR_BADDEVICEID;
555 memcpy(lpCaps, &mixer.caps, min(dwSize, sizeof(*lpCaps)));
556 return MMSYSERR_NOERROR;
559 /**************************************************************************
560 * MIX_GetLineInfo [internal]
562 static DWORD MIX_GetLineInfo(WORD wDevID, LPMIXERLINEW lpMl, DWORD_PTR fdwInfo)
565 DWORD ret = MMSYSERR_ERROR;
566 MixerLine *line = NULL;
568 TRACE("%04X, %p, %08lx\n", wDevID, lpMl, fdwInfo);
571 WARN("invalid parameter: lpMl = NULL\n");
572 return MMSYSERR_INVALPARAM;
575 if (lpMl->cbStruct != sizeof(*lpMl)) {
576 WARN("invalid parameter: lpMl->cbStruct\n");
577 return MMSYSERR_INVALPARAM;
580 if (wDevID >= numMixers) {
581 WARN("bad device ID: %04X\n", wDevID);
582 return MMSYSERR_BADDEVICEID;
585 /* FIXME: set all the variables correctly... the lines below
590 switch (fdwInfo & MIXER_GETLINEINFOF_QUERYMASK)
592 case MIXER_GETLINEINFOF_DESTINATION:
593 TRACE("MIXER_GETLINEINFOF_DESTINATION %d\n", lpMl->dwDestination);
594 if ( (lpMl->dwDestination >= 0) && (lpMl->dwDestination < mixer.caps.cDestinations) )
596 lpMl->dwLineID = lpMl->dwDestination;
597 line = &mixer.lines[lpMl->dwDestination];
599 else ret = MIXERR_INVALLINE;
601 case MIXER_GETLINEINFOF_COMPONENTTYPE:
602 TRACE("MIXER_GETLINEINFOF_COMPONENTTYPE %s\n", getComponentType(lpMl->dwComponentType));
603 for (i = 0; i < mixer.caps.cDestinations; i++)
605 if (mixer.lines[i].componentType == lpMl->dwComponentType)
607 lpMl->dwDestination = lpMl->dwLineID = i;
608 line = &mixer.lines[i];
614 WARN("can't find component type %s\n", getComponentType(lpMl->dwComponentType));
615 ret = MIXERR_INVALVALUE;
618 case MIXER_GETLINEINFOF_SOURCE:
619 FIXME("MIXER_GETLINEINFOF_SOURCE %d dst=%d\n", lpMl->dwSource, lpMl->dwDestination);
621 case MIXER_GETLINEINFOF_LINEID:
622 TRACE("MIXER_GETLINEINFOF_LINEID %d\n", lpMl->dwLineID);
623 if ( (lpMl->dwLineID >= 0) && (lpMl->dwLineID < mixer.caps.cDestinations) )
625 lpMl->dwDestination = lpMl->dwLineID;
626 line = &mixer.lines[lpMl->dwLineID];
628 else ret = MIXERR_INVALLINE;
630 case MIXER_GETLINEINFOF_TARGETTYPE:
631 FIXME("MIXER_GETLINEINFOF_TARGETTYPE (%s)\n", getTargetType(lpMl->Target.dwType));
632 switch (lpMl->Target.dwType) {
633 case MIXERLINE_TARGETTYPE_UNDEFINED:
634 case MIXERLINE_TARGETTYPE_WAVEOUT:
635 case MIXERLINE_TARGETTYPE_WAVEIN:
636 case MIXERLINE_TARGETTYPE_MIDIOUT:
637 case MIXERLINE_TARGETTYPE_MIDIIN:
638 case MIXERLINE_TARGETTYPE_AUX:
640 FIXME("Unhandled target type (%s)\n",
641 getTargetType(lpMl->Target.dwType));
642 return MMSYSERR_INVALPARAM;
646 WARN("Unknown flag (%08lx)\n", fdwInfo & MIXER_GETLINEINFOF_QUERYMASK);
652 lpMl->dwComponentType = line->componentType;
653 lpMl->cChannels = line->numChannels;
654 lpMl->cControls = ControlsPerLine;
656 /* FIXME check there with CoreAudio */
657 lpMl->cConnections = 1;
658 lpMl->fdwLine = MIXERLINE_LINEF_ACTIVE;
660 MultiByteToWideChar(CP_ACP, 0, line->name, -1, lpMl->szShortName, sizeof(lpMl->szShortName) / sizeof(WCHAR));
661 MultiByteToWideChar(CP_ACP, 0, line->name, -1, lpMl->szName, sizeof(lpMl->szName) / sizeof(WCHAR));
663 if ( IsInput(line->direction) )
664 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_WAVEIN;
666 lpMl->Target.dwType = MIXERLINE_TARGETTYPE_WAVEOUT;
668 lpMl->Target.dwDeviceID = line->deviceID;
669 lpMl->Target.wMid = mixer.caps.wMid;
670 lpMl->Target.wPid = mixer.caps.wPid;
671 lpMl->Target.vDriverVersion = mixer.caps.vDriverVersion;
673 MultiByteToWideChar(CP_ACP, 0, WINE_MIXER_NAME, -1, lpMl->Target.szPname, sizeof(lpMl->Target.szPname) / sizeof(WCHAR));
674 ret = MMSYSERR_NOERROR;
679 /**************************************************************************
680 * MIX_GetLineControls [internal]
682 static DWORD MIX_GetLineControls(WORD wDevID, LPMIXERLINECONTROLSW lpMlc, DWORD_PTR flags)
684 DWORD ret = MMSYSERR_NOTENABLED;
686 TRACE("%04X, %p, %08lX\n", wDevID, lpMlc, flags);
689 WARN("invalid parameter: lpMlc == NULL\n");
690 return MMSYSERR_INVALPARAM;
693 if (lpMlc->cbStruct < sizeof(*lpMlc)) {
694 WARN("invalid parameter: lpMlc->cbStruct = %d\n", lpMlc->cbStruct);
695 return MMSYSERR_INVALPARAM;
698 if (lpMlc->cbmxctrl < sizeof(MIXERCONTROLW)) {
699 WARN("invalid parameter: lpMlc->cbmxctrl = %d\n", lpMlc->cbmxctrl);
700 return MMSYSERR_INVALPARAM;
703 if (wDevID >= numMixers) {
704 WARN("bad device ID: %04X\n", wDevID);
705 return MMSYSERR_BADDEVICEID;
708 switch (flags & MIXER_GETLINECONTROLSF_QUERYMASK)
710 case MIXER_GETLINECONTROLSF_ALL:
711 FIXME("dwLineID=%d MIXER_GETLINECONTROLSF_ALL (%d)\n", lpMlc->dwLineID, lpMlc->cControls);
712 if (lpMlc->cControls != ControlsPerLine)
714 WARN("invalid parameter lpMlc->cControls %d\n", lpMlc->cControls);
715 ret = MMSYSERR_INVALPARAM;
719 if ( (lpMlc->dwLineID >= 0) && (lpMlc->dwLineID < mixer.caps.cDestinations) )
722 for (i = 0; i < lpMlc->cControls; i++)
724 lpMlc->pamxctrl[i] = mixer.mixerCtrls[lpMlc->dwLineID * i].ctrl;
726 ret = MMSYSERR_NOERROR;
728 else ret = MIXERR_INVALLINE;
731 case MIXER_GETLINECONTROLSF_ONEBYID:
732 TRACE("dwLineID=%d MIXER_GETLINECONTROLSF_ONEBYID (%d)\n", lpMlc->dwLineID, lpMlc->u.dwControlID);
733 if ( lpMlc->u.dwControlID >= 0 && lpMlc->u.dwControlID < mixer.numCtrl )
735 lpMlc->pamxctrl[0] = mixer.mixerCtrls[lpMlc->u.dwControlID].ctrl;
736 ret = MMSYSERR_NOERROR;
738 else ret = MIXERR_INVALVALUE;
740 case MIXER_GETLINECONTROLSF_ONEBYTYPE:
741 TRACE("dwLineID=%d MIXER_GETLINECONTROLSF_ONEBYTYPE (%s)\n", lpMlc->dwLineID, getControlType(lpMlc->u.dwControlType));
742 if ( (lpMlc->dwLineID < 0) || (lpMlc->dwLineID >= mixer.caps.cDestinations) )
744 ret = MIXERR_INVALLINE;
747 if (lpMlc->u.dwControlType == MIXERCONTROL_CONTROLTYPE_VOLUME)
749 ctrl = (lpMlc->dwLineID * ControlsPerLine) + IDControlVolume;
750 lpMlc->pamxctrl[0] = mixer.mixerCtrls[ctrl].ctrl;
751 ret = MMSYSERR_NOERROR;
754 if (lpMlc->u.dwControlType == MIXERCONTROL_CONTROLTYPE_MUTE)
756 ctrl = (lpMlc->dwLineID * ControlsPerLine) + IDControlMute;
757 lpMlc->pamxctrl[0] = mixer.mixerCtrls[ctrl].ctrl;
758 ret = MMSYSERR_NOERROR;
762 ERR("Unknown flag %08lx\n", flags & MIXER_GETLINECONTROLSF_QUERYMASK);
763 ret = MMSYSERR_INVALPARAM;
769 /**************************************************************************
770 * MIX_GetControlDetails [internal]
772 static DWORD MIX_GetControlDetails(WORD wDevID, LPMIXERCONTROLDETAILS lpmcd, DWORD_PTR fdwDetails)
774 DWORD ret = MMSYSERR_NOTSUPPORTED;
777 TRACE("%04X, %p, %08lx\n", wDevID, lpmcd, fdwDetails);
780 TRACE("invalid parameter: lpmcd == NULL\n");
781 return MMSYSERR_INVALPARAM;
784 if (wDevID >= numMixers) {
785 WARN("bad device ID: %04X\n", wDevID);
786 return MMSYSERR_BADDEVICEID;
789 if ( (fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK) != MIXER_GETCONTROLDETAILSF_VALUE )
791 WARN("Unknown/unimplement GetControlDetails flag (%08lx)\n", fdwDetails & MIXER_GETCONTROLDETAILSF_QUERYMASK);
792 return MMSYSERR_NOTSUPPORTED;
795 if ( lpmcd->dwControlID < 0 || lpmcd->dwControlID >= mixer.numCtrl )
797 WARN("bad control ID: %d\n", lpmcd->dwControlID);
798 return MIXERR_INVALVALUE;
801 TRACE("MIXER_GETCONTROLDETAILSF_VALUE %d\n", lpmcd->dwControlID);
803 dwControlType = mixer.mixerCtrls[lpmcd->dwControlID].ctrl.dwControlType;
804 switch (dwControlType)
806 case MIXERCONTROL_CONTROLTYPE_VOLUME:
807 FIXME("controlType : %s channels %d\n", getControlType(dwControlType), lpmcd->cChannels);
809 LPMIXERCONTROLDETAILS_UNSIGNED mcdu;
812 if (lpmcd->cbDetails != sizeof(MIXERCONTROLDETAILS_UNSIGNED)) {
813 WARN("invalid parameter: lpmcd->cbDetails == %d\n", lpmcd->cbDetails);
814 return MMSYSERR_INVALPARAM;
817 if ( MIX_LineGetVolume(mixer.mixerCtrls[lpmcd->dwControlID].dwLineID, lpmcd->cChannels, &left, &right) )
819 mcdu = (LPMIXERCONTROLDETAILS_UNSIGNED)lpmcd->paDetails;
821 switch (lpmcd->cChannels)
824 /* mono... so R = L */
825 mcdu->dwValue = left * 65535;
826 TRACE("Reading RL = %d\n", mcdu->dwValue);
829 /* stereo, left is paDetails[0] */
830 mcdu->dwValue = left * 65535;
831 TRACE("Reading L = %d\n", mcdu->dwValue);
833 mcdu->dwValue = right * 65535;
834 TRACE("Reading R = %d\n", mcdu->dwValue);
837 WARN("Unsupported cChannels (%d)\n", lpmcd->cChannels);
838 return MMSYSERR_INVALPARAM;
840 TRACE("=> %08x\n", mcdu->dwValue);
841 ret = MMSYSERR_NOERROR;
845 case MIXERCONTROL_CONTROLTYPE_MUTE:
846 case MIXERCONTROL_CONTROLTYPE_ONOFF:
847 FIXME("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n", getControlType(dwControlType), lpmcd->cChannels);
849 LPMIXERCONTROLDETAILS_BOOLEAN mcdb;
851 if (lpmcd->cbDetails != sizeof(MIXERCONTROLDETAILS_BOOLEAN)) {
852 WARN("invalid parameter: lpmcd->cbDetails = %d\n", lpmcd->cbDetails);
853 return MMSYSERR_INVALPARAM;
855 mcdb = (LPMIXERCONTROLDETAILS_BOOLEAN)lpmcd->paDetails;
857 if ( MIX_LineGetMute(mixer.mixerCtrls[lpmcd->dwControlID].dwLineID, &muted) )
859 mcdb->fValue = muted;
860 TRACE("=> %s\n", mcdb->fValue ? "on" : "off");
861 ret = MMSYSERR_NOERROR;
865 case MIXERCONTROL_CONTROLTYPE_MIXER:
866 case MIXERCONTROL_CONTROLTYPE_MUX:
868 FIXME("controlType : %s\n", getControlType(dwControlType));
874 /**************************************************************************
875 * MIX_SetControlDetails [internal]
877 static DWORD MIX_SetControlDetails(WORD wDevID, LPMIXERCONTROLDETAILS lpmcd, DWORD_PTR fdwDetails)
879 DWORD ret = MMSYSERR_NOTSUPPORTED;
882 TRACE("%04X, %p, %08lx\n", wDevID, lpmcd, fdwDetails);
885 TRACE("invalid parameter: lpmcd == NULL\n");
886 return MMSYSERR_INVALPARAM;
889 if (wDevID >= numMixers) {
890 WARN("bad device ID: %04X\n", wDevID);
891 return MMSYSERR_BADDEVICEID;
894 if ( (fdwDetails & MIXER_SETCONTROLDETAILSF_QUERYMASK) != MIXER_GETCONTROLDETAILSF_VALUE )
896 WARN("Unknown SetControlDetails flag (%08lx)\n", fdwDetails & MIXER_SETCONTROLDETAILSF_QUERYMASK);
897 return MMSYSERR_NOTSUPPORTED;
900 TRACE("MIXER_SETCONTROLDETAILSF_VALUE dwControlID=%d\n", lpmcd->dwControlID);
901 dwControlType = mixer.mixerCtrls[lpmcd->dwControlID].ctrl.dwControlType;
902 switch (dwControlType)
904 case MIXERCONTROL_CONTROLTYPE_VOLUME:
905 FIXME("controlType : %s\n", getControlType(dwControlType));
907 LPMIXERCONTROLDETAILS_UNSIGNED mcdu;
908 Float32 left, right = 0;
910 if (lpmcd->cbDetails != sizeof(MIXERCONTROLDETAILS_UNSIGNED)) {
911 WARN("invalid parameter: lpmcd->cbDetails == %d\n", lpmcd->cbDetails);
912 return MMSYSERR_INVALPARAM;
915 mcdu = (LPMIXERCONTROLDETAILS_UNSIGNED)lpmcd->paDetails;
917 switch (lpmcd->cChannels)
920 /* mono... so R = L */
921 TRACE("Setting RL to %d\n", mcdu->dwValue);
922 left = (Float32) mcdu->dwValue / 65535.0;
925 /* stereo, left is paDetails[0] */
926 TRACE("Setting L to %d\n", mcdu->dwValue);
927 left = (Float32) mcdu->dwValue / 65535.0;
929 TRACE("Setting R to %d\n", mcdu->dwValue);
930 right = (Float32) mcdu->dwValue / 65535.0;
933 WARN("Unsupported cChannels (%d)\n", lpmcd->cChannels);
934 return MMSYSERR_INVALPARAM;
936 if ( MIX_LineSetVolume(mixer.mixerCtrls[lpmcd->dwControlID].dwLineID, lpmcd->cChannels, left, right) )
937 ret = MMSYSERR_NOERROR;
940 case MIXERCONTROL_CONTROLTYPE_MUTE:
941 case MIXERCONTROL_CONTROLTYPE_ONOFF:
942 TRACE("%s MIXERCONTROLDETAILS_BOOLEAN[%u]\n", getControlType(dwControlType), lpmcd->cChannels);
944 LPMIXERCONTROLDETAILS_BOOLEAN mcdb;
946 if (lpmcd->cbDetails != sizeof(MIXERCONTROLDETAILS_BOOLEAN)) {
947 WARN("invalid parameter: cbDetails\n");
948 return MMSYSERR_INVALPARAM;
950 mcdb = (LPMIXERCONTROLDETAILS_BOOLEAN)lpmcd->paDetails;
951 if ( MIX_LineSetMute(mixer.mixerCtrls[lpmcd->dwControlID].dwLineID, mcdb->fValue) )
952 ret = MMSYSERR_NOERROR;
955 case MIXERCONTROL_CONTROLTYPE_MIXER:
956 case MIXERCONTROL_CONTROLTYPE_MUX:
958 FIXME("controlType : %s\n", getControlType(dwControlType));
959 ret = MMSYSERR_NOTSUPPORTED;
965 /**************************************************************************
968 DWORD WINAPI CoreAudio_mxdMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
969 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
971 TRACE("(%04X, %s, %08lX, %08lX, %08lX);\n", wDevID, getMessage(wMsg),
972 dwUser, dwParam1, dwParam2);
980 /* FIXME: Pretend this is supported */
983 return MIX_Open(wDevID, (LPMIXEROPENDESC)dwParam1, dwParam2);
985 return MMSYSERR_NOERROR;
986 case MXDM_GETNUMDEVS:
987 return MIX_GetNumDevs();
988 case MXDM_GETDEVCAPS:
989 return MIX_GetDevCaps(wDevID, (LPMIXERCAPSW)dwParam1, dwParam2);
990 case MXDM_GETLINEINFO:
991 return MIX_GetLineInfo(wDevID, (LPMIXERLINEW)dwParam1, dwParam2);
992 case MXDM_GETLINECONTROLS:
993 return MIX_GetLineControls(wDevID, (LPMIXERLINECONTROLSW)dwParam1, dwParam2);
994 case MXDM_GETCONTROLDETAILS:
995 return MIX_GetControlDetails(wDevID, (LPMIXERCONTROLDETAILS)dwParam1, dwParam2);
996 case MXDM_SETCONTROLDETAILS:
997 return MIX_SetControlDetails(wDevID, (LPMIXERCONTROLDETAILS)dwParam1, dwParam2);
999 WARN("unknown message %d!\n", wMsg);
1000 return MMSYSERR_NOTSUPPORTED;
1006 DWORD WINAPI CoreAudio_mxdMessage(UINT wDevID, UINT wMsg, DWORD_PTR dwUser,
1007 DWORD_PTR dwParam1, DWORD_PTR dwParam2)
1009 TRACE("(%04X, %04x, %08lX, %08lX, %08lX);\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
1010 return MMSYSERR_NOTENABLED;
1012 #endif /* HAVE_COREAUDIO_COREAUDIO_H */