Volume and Pan driver requests need to return success even though they
[wine/wine-kai.git] / dlls / winmm / wineaudioio / audio.c
blob0c30aad33aeda5b58756d7683b0d147541964d3b
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2 /*
3 * Wine Driver for Libaudioio
4 * Derived from the Wine OSS Sample Driver
5 * Copyright 1994 Martin Ayotte
6 * 1999 Eric Pouech (async playing in waveOut/waveIn)
7 * 2000 Eric Pouech (loops in waveOut)
8 * 2002 Robert Lunnon (Modifications for libaudioio)
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Note large hacks done to effectively disable DSound altogether
26 * Also Input is not yet working (Lots more work to be done there)
27 * But this does make a reasonable output driver for solaris untill the arts driver comes up to speed
31 * FIXME:
32 * pause in waveOut does not work correctly
33 * full duplex (in/out) is not working (device is opened twice for Out
34 * and In) (OSS is known for its poor duplex capabilities, alsa is
35 * better)
38 /*#define EMULATE_SB16*/
40 #include "config.h"
42 #include <stdlib.h>
43 #include <stdarg.h>
44 #include <stdio.h>
45 #include <string.h>
46 #ifdef HAVE_UNISTD_H
47 # include <unistd.h>
48 #endif
49 #include <errno.h>
50 #include <fcntl.h>
51 #ifdef HAVE_SYS_IOCTL_H
52 # include <sys/ioctl.h>
53 #endif
54 #ifdef HAVE_SYS_MMAN_H
55 # include <sys/mman.h>
56 #endif
57 #ifdef HAVE_LIBAUDIOIO_H
58 #include <libaudioio.h>
59 #endif
60 #include "windef.h"
61 #include "winbase.h"
62 #include "wingdi.h"
63 #include "winerror.h"
64 #include "wine/winuser16.h"
65 #include "mmddk.h"
66 #include "dsound.h"
67 #include "dsdriver.h"
68 #include "wine/debug.h"
70 WINE_DEFAULT_DEBUG_CHANNEL(wave);
72 #ifdef HAVE_LIBAUDIOIO
74 /* Allow 1% deviation for sample rates (some ES137x cards) */
75 #define NEAR_MATCH(rate1,rate2) (((100*((int)(rate1)-(int)(rate2)))/(rate1))==0)
77 #define SOUND_DEV "/dev/audio"
78 #define DEFAULT_FRAGMENT_SIZE 4096
82 #define MAX_WAVEOUTDRV (1)
83 #define MAX_WAVEINDRV (1)
85 /* state diagram for waveOut writing:
87 * +---------+-------------+---------------+---------------------------------+
88 * | state | function | event | new state |
89 * +---------+-------------+---------------+---------------------------------+
90 * | | open() | | STOPPED |
91 * | PAUSED | write() | | PAUSED |
92 * | STOPPED | write() | <thrd create> | PLAYING |
93 * | PLAYING | write() | HEADER | PLAYING |
94 * | (other) | write() | <error> | |
95 * | (any) | pause() | PAUSING | PAUSED |
96 * | PAUSED | restart() | RESTARTING | PLAYING (if no thrd => STOPPED) |
97 * | (any) | reset() | RESETTING | STOPPED |
98 * | (any) | close() | CLOSING | CLOSED |
99 * +---------+-------------+---------------+---------------------------------+
102 /* states of the playing device */
103 #define WINE_WS_PLAYING 0
104 #define WINE_WS_PAUSED 1
105 #define WINE_WS_STOPPED 2
106 #define WINE_WS_CLOSED 3
108 /* events to be send to device */
109 #define WINE_WM_PAUSING (WM_USER + 1)
110 #define WINE_WM_RESTARTING (WM_USER + 2)
111 #define WINE_WM_RESETTING (WM_USER + 3)
112 #define WINE_WM_CLOSING (WM_USER + 4)
113 #define WINE_WM_HEADER (WM_USER + 5)
115 #define WINE_WM_FIRST WINE_WM_PAUSING
116 #define WINE_WM_LAST WINE_WM_HEADER
118 typedef struct {
119 int msg;
120 DWORD param;
121 } WWO_MSG;
123 typedef struct {
124 int unixdev;
125 volatile int state; /* one of the WINE_WS_ manifest constants */
126 DWORD dwFragmentSize; /* size of OSS buffer fragment */
127 WAVEOPENDESC waveDesc;
128 WORD wFlags;
129 PCMWAVEFORMAT format;
130 LPWAVEHDR lpQueuePtr; /* start of queued WAVEHDRs (waiting to be notified) */
131 LPWAVEHDR lpPlayPtr; /* start of not yet fully played buffers */
132 LPWAVEHDR lpLoopPtr; /* pointer of first buffer in loop, if any */
133 DWORD dwLoops; /* private copy of loop counter */
135 DWORD dwLastFragDone; /* time in ms, when last played fragment will be actually played */
136 DWORD dwPlayedTotal; /* number of bytes played since opening */
138 /* info on current lpQueueHdr->lpWaveHdr */
139 DWORD dwOffCurrHdr; /* offset in lpPlayPtr->lpData for fragments */
140 DWORD dwRemain; /* number of bytes to write to end the current fragment */
142 /* synchronization stuff */
143 HANDLE hThread;
144 DWORD dwThreadID;
145 HANDLE hEvent;
146 #define WWO_RING_BUFFER_SIZE 30
147 WWO_MSG messages[WWO_RING_BUFFER_SIZE];
148 int msg_tosave;
149 int msg_toget;
150 HANDLE msg_event;
151 CRITICAL_SECTION msg_crst;
152 WAVEOUTCAPSA caps;
154 /* DirectSound stuff */
155 LPBYTE mapping;
156 DWORD maplen;
157 } WINE_WAVEOUT;
159 typedef struct {
160 int unixdev;
161 volatile int state;
162 DWORD dwFragmentSize; /* OpenSound '/dev/dsp' give us that size */
163 WAVEOPENDESC waveDesc;
164 WORD wFlags;
165 PCMWAVEFORMAT format;
166 LPWAVEHDR lpQueuePtr;
167 DWORD dwTotalRecorded;
168 WAVEINCAPSA caps;
169 BOOL bTriggerSupport;
171 /* synchronization stuff */
172 HANDLE hThread;
173 DWORD dwThreadID;
174 HANDLE hEvent;
175 } WINE_WAVEIN;
177 static WINE_WAVEOUT WOutDev [MAX_WAVEOUTDRV];
178 static WINE_WAVEIN WInDev [MAX_WAVEINDRV ];
180 static DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv);
181 static DWORD widDsCreate(UINT wDevID, PIDSCDRIVER* drv);
182 static DWORD wodDsDesc(UINT wDevID, PDSDRIVERDESC desc);
183 static DWORD widDsDesc(UINT wDevID, PDSDRIVERDESC desc);
184 static DWORD wodDsGuid(UINT wDevID, LPGUID pGuid);
185 static DWORD widDsGuid(UINT wDevID, LPGUID pGuid);
187 /*======================================================================*
188 * Low level WAVE implementation *
189 *======================================================================*/
190 SampleSpec_t spec[2];
194 LONG LIBAUDIOIO_WaveInit(void)
196 int audio;
197 int smplrate;
198 int samplesize = 16;
199 int dsp_stereo = 1;
200 int bytespersmpl;
201 int caps;
202 int mask;
203 int i;
205 int audio_fd;
206 int mode;
207 TRACE("Init ENTERED rate = %d\n",spec[PLAYBACK].rate);
208 spec[RECORD].channels=spec[PLAYBACK].channels=2;
209 spec[RECORD].max_blocks=spec[PLAYBACK].max_blocks=16;
210 spec[RECORD].rate=spec[PLAYBACK].rate=44100;
211 spec[RECORD].encoding=spec[PLAYBACK].encoding= ENCODE_PCM;
212 spec[RECORD].precision=spec[PLAYBACK].precision=16 ;
213 spec[RECORD].endian=spec[PLAYBACK].endian=ENDIAN_INTEL;
214 spec[RECORD].disable_threads=spec[PLAYBACK].disable_threads=1;
215 spec[RECORD].type=spec[PLAYBACK].type=TYPE_SIGNED; /* in 16 bit mode this is what typical PC hardware expects */
217 mode = O_WRONLY|O_NDELAY;
219 /* start with output device */
221 /* initialize all device handles to -1 */
222 for (i = 0; i < MAX_WAVEOUTDRV; ++i)
224 WOutDev[i].unixdev = -1;
227 /* FIXME: only one device is supported */
228 memset(&WOutDev[0].caps, 0, sizeof(WOutDev[0].caps));
232 /* FIXME: some programs compare this string against the content of the registry
233 * for MM drivers. The names have to match in order for the program to work
234 * (e.g. MS win9x mplayer.exe)
236 #ifdef EMULATE_SB16
237 WOutDev[0].caps.wMid = 0x0002;
238 WOutDev[0].caps.wPid = 0x0104;
239 strcpy(WOutDev[0].caps.szPname, "SB16 Wave Out");
240 #else
241 WOutDev[0].caps.wMid = 0x00FF; /* Manufac ID */
242 WOutDev[0].caps.wPid = 0x0001; /* Product ID */
243 /* strcpy(WOutDev[0].caps.szPname, "OpenSoundSystem WAVOUT Driver");*/
244 strcpy(WOutDev[0].caps.szPname, "CS4236/37/38");
245 #endif
246 WOutDev[0].caps.vDriverVersion = 0x0100;
247 WOutDev[0].caps.dwFormats = 0x00000000;
248 WOutDev[0].caps.dwSupport = WAVECAPS_VOLUME;
251 * Libaudioio works differently, you tell it what spec audio you want to write and it
252 * Guarantees to match it by converting to the final format on the fly
253 *So we dont need to read back and compare
256 bytespersmpl = spec[PLAYBACK].precision/8;
258 WOutDev[0].caps.wChannels = spec[PLAYBACK].channels;
261 /* Fixme: Libaudioio 0.2 doesn't support balance yet (Libaudioio 0.3 does so this must be fixed later)*/
263 /* if (WOutDev[0].caps.wChannels > 1) WOutDev[0].caps.dwSupport |= WAVECAPS_LRVOLUME;*/
264 TRACE("Init sammplerate= %d\n",spec[PLAYBACK].rate);
266 smplrate = spec[PLAYBACK].rate;
268 * We have set up the data format to be 16 bit signed in intel format
269 * For Big Endian machines libaudioio will convert the data to bigendian for us
272 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_4M16;
273 if (WOutDev[0].caps.wChannels > 1)
274 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_4S16;
276 /* Don't understand this yet, but I dont think this functionality is portable, leave here for future evaluation
277 * if (IOCTL(audio, SNDCTL_DSP_GETCAPS, caps) == 0) {
278 * TRACE("OSS dsp out caps=%08X\n", caps);
279 * if ((caps & DSP_CAP_REALTIME) && !(caps & DSP_CAP_BATCH)) {
280 * WOutDev[0].caps.dwSupport |= WAVECAPS_SAMPLEACCURATE;
282 */ /* well, might as well use the DirectSound cap flag for something */
283 /* if ((caps & DSP_CAP_TRIGGER) && (caps & DSP_CAP_MMAP) &&
284 * !(caps & DSP_CAP_BATCH))
285 * WOutDev[0].caps.dwSupport |= WAVECAPS_DIRECTSOUND;
291 * Note that libaudioio audio capture is not proven yet, in our open call
292 * set the spec for input audio the same as for output
294 TRACE("out dwFormats = %08lX, dwSupport = %08lX\n",
295 WOutDev[0].caps.dwFormats, WOutDev[0].caps.dwSupport);
297 for (i = 0; i < MAX_WAVEINDRV; ++i)
299 WInDev[i].unixdev = -1;
302 memset(&WInDev[0].caps, 0, sizeof(WInDev[0].caps));
306 #ifdef EMULATE_SB16
307 WInDev[0].caps.wMid = 0x0002;
308 WInDev[0].caps.wPid = 0x0004;
309 strcpy(WInDev[0].caps.szPname, "SB16 Wave In");
310 #else
311 WInDev[0].caps.wMid = 0x00FF; /* Manufac ID */
312 WInDev[0].caps.wPid = 0x0001; /* Product ID */
313 strcpy(WInDev[0].caps.szPname, "OpenSoundSystem WAVIN Driver");
314 #endif
315 WInDev[0].caps.dwFormats = 0x00000000;
316 WInDev[0].caps.wChannels = spec[RECORD].channels;
318 WInDev[0].bTriggerSupport = TRUE; /* Maybe :-) */
320 bytespersmpl = spec[RECORD].precision/8;
321 smplrate = spec[RECORD].rate;
323 WInDev[0].caps.dwFormats |= WAVE_FORMAT_4M16;
324 if (WInDev[0].caps.wChannels > 1)
325 WInDev[0].caps.dwFormats |= WAVE_FORMAT_4S16;
328 TRACE("in dwFormats = %08lX\n", WInDev[0].caps.dwFormats);
330 return 0;
333 /**************************************************************************
334 * LIBAUDIOIO_NotifyClient [internal]
336 static DWORD LIBAUDIOIO_NotifyClient(UINT wDevID, WORD wMsg, DWORD dwParam1, DWORD dwParam2)
338 TRACE("wDevID = %04X wMsg = 0x%04x dwParm1 = %04lX dwParam2 = %04lX\n",wDevID, wMsg, dwParam1, dwParam2);
340 switch (wMsg) {
341 case WOM_OPEN:
342 case WOM_CLOSE:
343 case WOM_DONE:
344 if (wDevID >= MAX_WAVEOUTDRV) return MCIERR_INTERNAL;
346 if (WOutDev[wDevID].wFlags != DCB_NULL &&
347 !DriverCallback(WOutDev[wDevID].waveDesc.dwCallback,
348 WOutDev[wDevID].wFlags,
349 WOutDev[wDevID].waveDesc.hWave,
350 wMsg,
351 WOutDev[wDevID].waveDesc.dwInstance,
352 dwParam1,
353 dwParam2)) {
354 WARN("can't notify client !\n");
355 return MMSYSERR_NOERROR;
357 break;
359 case WIM_OPEN:
360 case WIM_CLOSE:
361 case WIM_DATA:
362 if (wDevID >= MAX_WAVEINDRV) return MCIERR_INTERNAL;
364 if (WInDev[wDevID].wFlags != DCB_NULL &&
365 !DriverCallback(WInDev[wDevID].waveDesc.dwCallback,
366 WInDev[wDevID].wFlags,
367 WInDev[wDevID].waveDesc.hWave,
368 wMsg,
369 WInDev[wDevID].waveDesc.dwInstance,
370 dwParam1,
371 dwParam2)) {
372 WARN("can't notify client !\n");
373 return MMSYSERR_NOERROR;
375 break;
376 default:
377 FIXME("Unknown CB message %u\n", wMsg);
378 break;
380 return 0;
383 /*======================================================================*
384 * Low level WAVE OUT implementation *
385 *======================================================================*/
387 /**************************************************************************
388 * wodPlayer_WriteFragments [internal]
390 * wodPlayer helper. Writes as many fragments as it can to unixdev.
391 * Returns TRUE in case of buffer underrun.
393 static BOOL wodPlayer_WriteFragments(WINE_WAVEOUT* wwo)
395 LPWAVEHDR lpWaveHdr;
396 LPBYTE lpData;
397 int count;
399 TRACE("wodPlayer_WriteFragments sammplerate= %d\n",spec[PLAYBACK].rate);
400 for (;;) {
404 * Libaudioio doesn't buffer the same way as linux, you can write data is any block size
405 *And libaudioio just tracks the number of blocks in the streams queue to control latency
408 if (!AudioIOCheckWriteReady()) return FALSE; /* Returns false if you have execeeded your specified latency (No space left)*/
410 lpWaveHdr = wwo->lpPlayPtr;
411 if (!lpWaveHdr) {
412 if (wwo->dwRemain > 0 && /* still data to send to complete current fragment */
413 wwo->dwLastFragDone && /* first fragment has been played */
414 AudioIOCheckUnderrun()) { /* done with all waveOutWrite()' fragments */
415 /* FIXME: should do better handling here */
416 WARN("Oooch, buffer underrun !\n");
417 return TRUE; /* force resetting of waveOut device */
419 return FALSE; /* wait a bit */
422 if (wwo->dwOffCurrHdr == 0) {
423 TRACE("Starting a new wavehdr %p of %ld bytes\n", lpWaveHdr, lpWaveHdr->dwBufferLength);
424 if (lpWaveHdr->dwFlags & WHDR_BEGINLOOP) {
425 if (wwo->lpLoopPtr) {
426 WARN("Already in a loop. Discarding loop on this header (%p)\n", lpWaveHdr);
427 } else {
428 TRACE("Starting loop (%ldx) with %p\n", lpWaveHdr->dwLoops, lpWaveHdr);
429 wwo->lpLoopPtr = lpWaveHdr;
430 /* Windows does not touch WAVEHDR.dwLoops,
431 * so we need to make an internal copy */
432 wwo->dwLoops = lpWaveHdr->dwLoops;
437 lpData = lpWaveHdr->lpData;
439 /* finish current wave hdr ? */
440 if (wwo->dwOffCurrHdr + wwo->dwRemain >= lpWaveHdr->dwBufferLength) {
441 DWORD toWrite = lpWaveHdr->dwBufferLength - wwo->dwOffCurrHdr;
443 /* write end of current wave hdr */
444 count = AudioIOWrite(lpData + wwo->dwOffCurrHdr, toWrite);
445 TRACE("write(%p[%5lu], %5lu) => %d\n", lpData, wwo->dwOffCurrHdr, toWrite, count);
447 if (count > 0 || toWrite == 0) {
448 DWORD tc = GetTickCount();
450 if (wwo->dwLastFragDone /* + guard time ?? */ < tc)
451 wwo->dwLastFragDone = tc;
452 wwo->dwLastFragDone += (toWrite * 1000) / wwo->format.wf.nAvgBytesPerSec;
454 lpWaveHdr->reserved = wwo->dwLastFragDone;
455 TRACE("Tagging hdr %p with %08lx\n", lpWaveHdr, wwo->dwLastFragDone);
457 /* WAVEHDR written, go to next one */
458 if ((lpWaveHdr->dwFlags & WHDR_ENDLOOP) && wwo->lpLoopPtr) {
459 if (--wwo->dwLoops > 0) {
460 wwo->lpPlayPtr = wwo->lpLoopPtr;
461 } else {
462 /* last one played */
463 if (wwo->lpLoopPtr != lpWaveHdr && (lpWaveHdr->dwFlags & WHDR_BEGINLOOP)) {
464 FIXME("Correctly handled case ? (ending loop buffer also starts a new loop)\n");
465 /* shall we consider the END flag for the closing loop or for
466 * the opening one or for both ???
467 * code assumes for closing loop only
469 wwo->lpLoopPtr = lpWaveHdr;
470 } else {
471 wwo->lpLoopPtr = NULL;
473 wwo->lpPlayPtr = lpWaveHdr->lpNext;
475 } else {
476 wwo->lpPlayPtr = lpWaveHdr->lpNext;
478 wwo->dwOffCurrHdr = 0;
479 if ((wwo->dwRemain -= count) == 0) {
480 wwo->dwRemain = wwo->dwFragmentSize;
483 continue; /* try to go to use next wavehdr */
484 } else {
485 count = AudioIOWrite( lpData + wwo->dwOffCurrHdr, wwo->dwRemain);
486 TRACE("write(%p[%5lu], %5lu) => %d\n", lpData, wwo->dwOffCurrHdr, wwo->dwRemain, count);
487 if (count > 0) {
488 DWORD tc = GetTickCount();
490 if (wwo->dwLastFragDone /* + guard time ?? */ < tc)
491 wwo->dwLastFragDone = tc;
492 wwo->dwLastFragDone += (wwo->dwRemain * 1000) / wwo->format.wf.nAvgBytesPerSec;
494 TRACE("Tagging frag with %08lx\n", wwo->dwLastFragDone);
496 wwo->dwOffCurrHdr += count;
497 wwo->dwRemain = wwo->dwFragmentSize;
504 int wodPlayer_Message(WINE_WAVEOUT *wwo, int msg, DWORD param)
506 TRACE("wodPlayerMessage sammplerate= %d msg=%d\n",spec[PLAYBACK].rate,msg);
507 EnterCriticalSection(&wwo->msg_crst);
508 if ((wwo->msg_tosave == wwo->msg_toget) /* buffer overflow ? */
509 && (wwo->messages[wwo->msg_toget].msg))
511 ERR("buffer overflow !?\n");
512 LeaveCriticalSection(&wwo->msg_crst);
513 return 0;
516 wwo->messages[wwo->msg_tosave].msg = msg;
517 wwo->messages[wwo->msg_tosave].param = param;
518 wwo->msg_tosave++;
519 if (wwo->msg_tosave > WWO_RING_BUFFER_SIZE-1)
520 wwo->msg_tosave = 0;
521 LeaveCriticalSection(&wwo->msg_crst);
522 /* signal a new message */
523 SetEvent(wwo->msg_event);
524 return 1;
527 int wodPlayer_RetrieveMessage(WINE_WAVEOUT *wwo, int *msg, DWORD *param)
529 EnterCriticalSection(&wwo->msg_crst);
531 if (wwo->msg_toget == wwo->msg_tosave) /* buffer empty ? */
533 LeaveCriticalSection(&wwo->msg_crst);
534 return 0;
537 *msg = wwo->messages[wwo->msg_toget].msg;
538 wwo->messages[wwo->msg_toget].msg = 0;
539 *param = wwo->messages[wwo->msg_toget].param;
540 wwo->msg_toget++;
541 if (wwo->msg_toget > WWO_RING_BUFFER_SIZE-1)
542 wwo->msg_toget = 0;
543 LeaveCriticalSection(&wwo->msg_crst);
544 return 1;
547 /**************************************************************************
548 * wodPlayer_Notify [internal]
550 * wodPlayer helper. Notifies (and remove from queue) all the wavehdr which content
551 * have been played (actually to speaker, not to unixdev fd).
553 static void wodPlayer_Notify(WINE_WAVEOUT* wwo, WORD uDevID, BOOL force)
555 LPWAVEHDR lpWaveHdr;
556 DWORD tc = GetTickCount();
558 while (wwo->lpQueuePtr &&
559 (force ||
560 (wwo->lpQueuePtr != wwo->lpPlayPtr && wwo->lpQueuePtr != wwo->lpLoopPtr))) {
561 lpWaveHdr = wwo->lpQueuePtr;
563 if (lpWaveHdr->reserved > tc && !force) break;
565 wwo->dwPlayedTotal += lpWaveHdr->dwBufferLength;
566 wwo->lpQueuePtr = lpWaveHdr->lpNext;
568 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
569 lpWaveHdr->dwFlags |= WHDR_DONE;
571 TRACE("Notifying client with %p\n", lpWaveHdr);
572 if (LIBAUDIOIO_NotifyClient(uDevID, WOM_DONE, (DWORD)lpWaveHdr, 0) != MMSYSERR_NOERROR) {
573 WARN("can't notify client !\n");
578 /**************************************************************************
579 * wodPlayer_Reset [internal]
581 * wodPlayer helper. Resets current output stream.
583 static void wodPlayer_Reset(WINE_WAVEOUT* wwo, WORD uDevID, BOOL reset)
585 /* updates current notify list */
586 wodPlayer_Notify(wwo, uDevID, FALSE);
588 /* flush all possible output */
590 *FIXME In the original code I think this aborted IO. With Libaudioio you have to wait
591 * The following function just blocks untill I/O is complete
592 * There is possibly a way to abort the blocks buffered in streams
593 * but this approach seems to work OK
595 AudioIOFlush();
599 wwo->dwOffCurrHdr = 0;
600 wwo->dwRemain = wwo->dwFragmentSize;
601 if (reset) {
602 /* empty notify list */
603 wodPlayer_Notify(wwo, uDevID, TRUE);
605 wwo->lpPlayPtr = wwo->lpQueuePtr = wwo->lpLoopPtr = NULL;
606 wwo->state = WINE_WS_STOPPED;
607 wwo->dwPlayedTotal = 0;
608 } else {
609 /* FIXME: this is not accurate when looping, but can be do better ? */
610 wwo->lpPlayPtr = (wwo->lpLoopPtr) ? wwo->lpLoopPtr : wwo->lpQueuePtr;
611 wwo->state = WINE_WS_PAUSED;
615 /**************************************************************************
616 * wodPlayer [internal]
618 static DWORD CALLBACK wodPlayer(LPVOID pmt)
620 WORD uDevID = (DWORD)pmt;
621 WINE_WAVEOUT* wwo = (WINE_WAVEOUT*)&WOutDev[uDevID];
622 WAVEHDR* lpWaveHdr;
623 DWORD dwSleepTime;
624 int msg;
625 DWORD param;
626 DWORD tc;
627 BOOL had_msg;
629 wwo->state = WINE_WS_STOPPED;
631 wwo->dwLastFragDone = 0;
632 wwo->dwOffCurrHdr = 0;
633 wwo->dwRemain = wwo->dwFragmentSize;
634 wwo->lpQueuePtr = wwo->lpPlayPtr = wwo->lpLoopPtr = NULL;
635 wwo->dwPlayedTotal = 0;
637 TRACE("imhere[0]\n");
638 SetEvent(wwo->hEvent);
640 for (;;) {
641 /* wait for dwSleepTime or an event in thread's queue
642 * FIXME:
643 * - is wait time calculation optimal ?
644 * - these 100 ms parts should be changed, but Eric reports
645 * that the wodPlayer thread might lock up if we use INFINITE
646 * (strange !), so I better don't change that now... */
647 if (wwo->state != WINE_WS_PLAYING)
648 dwSleepTime = 100;
649 else
651 tc = GetTickCount();
652 if (tc < wwo->dwLastFragDone)
654 /* calculate sleep time depending on when the last fragment
655 will be played */
656 dwSleepTime = (wwo->dwLastFragDone - tc)*7/10;
657 if (dwSleepTime > 100)
658 dwSleepTime = 100;
660 else
661 dwSleepTime = 0;
664 TRACE("imhere[1] tc = %08lx\n", GetTickCount());
665 if (dwSleepTime)
666 WaitForSingleObject(wwo->msg_event, dwSleepTime);
667 TRACE("imhere[2] (q=%p p=%p) tc = %08lx\n", wwo->lpQueuePtr,
668 wwo->lpPlayPtr, GetTickCount());
669 had_msg = FALSE;
670 while (wodPlayer_RetrieveMessage(wwo, &msg, &param)) {
671 had_msg = TRUE;
672 switch (msg) {
673 case WINE_WM_PAUSING:
674 wodPlayer_Reset(wwo, uDevID, FALSE);
675 wwo->state = WINE_WS_PAUSED;
676 SetEvent(wwo->hEvent);
677 break;
678 case WINE_WM_RESTARTING:
679 wwo->state = WINE_WS_PLAYING;
680 SetEvent(wwo->hEvent);
681 break;
682 case WINE_WM_HEADER:
683 lpWaveHdr = (LPWAVEHDR)param;
685 /* insert buffer at the end of queue */
687 LPWAVEHDR* wh;
688 for (wh = &(wwo->lpQueuePtr); *wh; wh = &((*wh)->lpNext));
689 *wh = lpWaveHdr;
691 if (!wwo->lpPlayPtr) wwo->lpPlayPtr = lpWaveHdr;
692 if (wwo->state == WINE_WS_STOPPED)
693 wwo->state = WINE_WS_PLAYING;
694 break;
695 case WINE_WM_RESETTING:
696 wodPlayer_Reset(wwo, uDevID, TRUE);
697 SetEvent(wwo->hEvent);
698 break;
699 case WINE_WM_CLOSING:
700 /* sanity check: this should not happen since the device must have been reset before */
701 if (wwo->lpQueuePtr || wwo->lpPlayPtr) ERR("out of sync\n");
702 wwo->hThread = 0;
703 wwo->state = WINE_WS_CLOSED;
704 SetEvent(wwo->hEvent);
705 ExitThread(0);
706 /* shouldn't go here */
707 default:
708 FIXME("unknown message %d\n", msg);
709 break;
711 if (wwo->state == WINE_WS_PLAYING) {
712 wodPlayer_WriteFragments(wwo);
714 wodPlayer_Notify(wwo, uDevID, FALSE);
717 if (!had_msg) { /* if we've received a msg we've just done this so we
718 won't repeat it */
719 if (wwo->state == WINE_WS_PLAYING) {
720 wodPlayer_WriteFragments(wwo);
722 wodPlayer_Notify(wwo, uDevID, FALSE);
725 ExitThread(0);
726 /* just for not generating compilation warnings... should never be executed */
727 return 0;
730 /**************************************************************************
731 * wodGetDevCaps [internal]
733 static DWORD wodGetDevCaps(WORD wDevID, LPWAVEOUTCAPSA lpCaps, DWORD dwSize)
735 TRACE("(%u, %p, %lu);\n", wDevID, lpCaps, dwSize);
737 if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
739 if (wDevID >= MAX_WAVEOUTDRV) {
740 TRACE("MAX_WAVOUTDRV reached !\n");
741 return MMSYSERR_BADDEVICEID;
744 memcpy(lpCaps, &WOutDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
745 return MMSYSERR_NOERROR;
748 /**************************************************************************
749 * wodOpen [internal]
751 static DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
753 int audio;
754 int format;
755 int sample_rate;
756 int dsp_stereo;
757 int fragment_size;
758 int audio_fragment;
759 WINE_WAVEOUT* wwo;
761 TRACE("(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
762 if (lpDesc == NULL) {
763 WARN("Invalid Parameter !\n");
764 return MMSYSERR_INVALPARAM;
766 if (wDevID >= MAX_WAVEOUTDRV) {
767 TRACE("MAX_WAVOUTDRV reached !\n");
768 return MMSYSERR_BADDEVICEID;
771 /* only PCM format is supported so far... */
772 if (lpDesc->lpFormat->wFormatTag != WAVE_FORMAT_PCM ||
773 lpDesc->lpFormat->nChannels == 0 ||
774 lpDesc->lpFormat->nSamplesPerSec == 0) {
775 WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
776 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
777 lpDesc->lpFormat->nSamplesPerSec);
778 return WAVERR_BADFORMAT;
781 if (dwFlags & WAVE_FORMAT_QUERY) {
782 TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
783 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
784 lpDesc->lpFormat->nSamplesPerSec);
785 return MMSYSERR_NOERROR;
788 wwo = &WOutDev[wDevID];
790 if ((dwFlags & WAVE_DIRECTSOUND) && !(wwo->caps.dwSupport & WAVECAPS_DIRECTSOUND))
791 /* not supported, ignore it */
792 dwFlags &= ~WAVE_DIRECTSOUND;
794 if (access(SOUND_DEV, 0) != 0)
795 return MMSYSERR_NOTENABLED;
797 audio = AudioIOOpenX( O_WRONLY|O_NDELAY,&spec[PLAYBACK],&spec[PLAYBACK]);
799 if (audio == -1) {
800 WARN("can't open sound device %s (%s)!\n", SOUND_DEV, strerror(errno));
801 return MMSYSERR_ALLOCATED;
803 /* fcntl(audio, F_SETFD, 1); *//* set close on exec flag - Dunno about this (RL)*/
804 wwo->unixdev = audio;
805 wwo->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
807 memcpy(&wwo->waveDesc, lpDesc, sizeof(WAVEOPENDESC));
808 memcpy(&wwo->format, lpDesc->lpFormat, sizeof(PCMWAVEFORMAT));
810 if (wwo->format.wBitsPerSample == 0) {
811 WARN("Resetting zeroed wBitsPerSample\n");
812 wwo->format.wBitsPerSample = 8 *
813 (wwo->format.wf.nAvgBytesPerSec /
814 wwo->format.wf.nSamplesPerSec) /
815 wwo->format.wf.nChannels;
818 if (dwFlags & WAVE_DIRECTSOUND) {
819 if (wwo->caps.dwSupport & WAVECAPS_SAMPLEACCURATE)
820 /* we have realtime DirectSound, fragments just waste our time,
821 * but a large buffer is good, so choose 64KB (32 * 2^11) */
822 audio_fragment = 0x0020000B;
823 else
824 /* to approximate realtime, we must use small fragments,
825 * let's try to fragment the above 64KB (256 * 2^8) */
826 audio_fragment = 0x01000008;
827 } else {
828 /* shockwave player uses only 4 1k-fragments at a rate of 22050 bytes/sec
829 * thus leading to 46ms per fragment, and a turnaround time of 185ms
831 /* 16 fragments max, 2^10=1024 bytes per fragment */
832 audio_fragment = 0x000F000A;
834 sample_rate = wwo->format.wf.nSamplesPerSec;
835 dsp_stereo = (wwo->format.wf.nChannels > 1) ? 1 : 0;
839 /*Set the sample rate*/
840 spec[PLAYBACK].rate=sample_rate;
842 /*And the size and signedness*/
843 spec[PLAYBACK].precision=(wwo->format.wBitsPerSample );
844 if (spec[PLAYBACK].precision==16) spec[PLAYBACK].type=TYPE_SIGNED; else spec[PLAYBACK].type=TYPE_UNSIGNED;
845 spec[PLAYBACK].channels=(wwo->format.wf.nChannels);
846 spec[PLAYBACK].encoding=ENCODE_PCM;
847 spec[PLAYBACK].endian=ENDIAN_INTEL;
848 spec[PLAYBACK].max_blocks=16; /*FIXME This is the libaudioio equivalent to fragments, it controls latency*/
850 audio = AudioIOOpenX( O_WRONLY|O_NDELAY,&spec[PLAYBACK],&spec[PLAYBACK]);
852 if (audio == -1) {
853 WARN("can't open sound device %s (%s)!\n", SOUND_DEV, strerror(errno));
854 return MMSYSERR_ALLOCATED;
856 /* fcntl(audio, F_SETFD, 1); *//* set close on exec flag */
857 wwo->unixdev = audio;
860 /* even if we set fragment size above, read it again, just in case */
862 wwo->dwFragmentSize = DEFAULT_FRAGMENT_SIZE;
864 wwo->msg_toget = 0;
865 wwo->msg_tosave = 0;
866 wwo->msg_event = CreateEventA(NULL, FALSE, FALSE, NULL);
867 memset(wwo->messages, 0, sizeof(WWO_MSG)*WWO_RING_BUFFER_SIZE);
868 InitializeCriticalSection(&wwo->msg_crst);
870 if (!(dwFlags & WAVE_DIRECTSOUND)) {
871 wwo->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
872 wwo->hThread = CreateThread(NULL, 0, wodPlayer, (LPVOID)(DWORD)wDevID, 0, &(wwo->dwThreadID));
873 WaitForSingleObject(wwo->hEvent, INFINITE);
874 } else {
875 wwo->hEvent = INVALID_HANDLE_VALUE;
876 wwo->hThread = INVALID_HANDLE_VALUE;
877 wwo->dwThreadID = 0;
880 TRACE("fd=%d fragmentSize=%ld\n",
881 wwo->unixdev, wwo->dwFragmentSize);
882 if (wwo->dwFragmentSize % wwo->format.wf.nBlockAlign)
883 ERR("Fragment doesn't contain an integral number of data blocks\n");
885 TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
886 wwo->format.wBitsPerSample, wwo->format.wf.nAvgBytesPerSec,
887 wwo->format.wf.nSamplesPerSec, wwo->format.wf.nChannels,
888 wwo->format.wf.nBlockAlign);
890 if (LIBAUDIOIO_NotifyClient(wDevID, WOM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
891 WARN("can't notify client !\n");
892 return MMSYSERR_INVALPARAM;
894 return MMSYSERR_NOERROR;
897 /**************************************************************************
898 * wodClose [internal]
900 static DWORD wodClose(WORD wDevID)
902 DWORD ret = MMSYSERR_NOERROR;
903 WINE_WAVEOUT* wwo;
905 TRACE("(%u);\n", wDevID);
907 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
908 WARN("bad device ID !\n");
909 return MMSYSERR_BADDEVICEID;
912 wwo = &WOutDev[wDevID];
913 if (wwo->lpQueuePtr) {
914 WARN("buffers still playing !\n");
915 ret = WAVERR_STILLPLAYING;
916 } else {
917 TRACE("imhere[3-close]\n");
918 if (wwo->hEvent != INVALID_HANDLE_VALUE) {
919 wodPlayer_Message(wwo, WINE_WM_CLOSING, 0);
920 WaitForSingleObject(wwo->hEvent, INFINITE);
921 CloseHandle(wwo->hEvent);
923 if (wwo->mapping) {
924 munmap(wwo->mapping, wwo->maplen);
925 wwo->mapping = NULL;
928 AudioIOClose();
929 wwo->unixdev = -1;
930 wwo->dwFragmentSize = 0;
931 if (LIBAUDIOIO_NotifyClient(wDevID, WOM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
932 WARN("can't notify client !\n");
933 ret = MMSYSERR_INVALPARAM;
936 return ret;
939 /**************************************************************************
940 * wodWrite [internal]
943 static DWORD wodWrite(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
945 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
947 /* first, do the sanity checks... */
948 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
949 WARN("bad dev ID !\n");
950 return MMSYSERR_BADDEVICEID;
953 if (lpWaveHdr->lpData == NULL || !(lpWaveHdr->dwFlags & WHDR_PREPARED))
954 return WAVERR_UNPREPARED;
956 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
957 return WAVERR_STILLPLAYING;
959 lpWaveHdr->dwFlags &= ~WHDR_DONE;
960 lpWaveHdr->dwFlags |= WHDR_INQUEUE;
961 lpWaveHdr->lpNext = 0;
963 TRACE("imhere[3-HEADER]\n");
964 wodPlayer_Message(&WOutDev[wDevID], WINE_WM_HEADER, (DWORD)lpWaveHdr);
966 return MMSYSERR_NOERROR;
969 /**************************************************************************
970 * wodPrepare [internal]
972 static DWORD wodPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
974 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
976 if (wDevID >= MAX_WAVEOUTDRV) {
977 WARN("bad device ID !\n");
978 return MMSYSERR_BADDEVICEID;
981 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
982 return WAVERR_STILLPLAYING;
984 lpWaveHdr->dwFlags |= WHDR_PREPARED;
985 lpWaveHdr->dwFlags &= ~WHDR_DONE;
986 return MMSYSERR_NOERROR;
989 /**************************************************************************
990 * wodUnprepare [internal]
992 static DWORD wodUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
994 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
996 if (wDevID >= MAX_WAVEOUTDRV) {
997 WARN("bad device ID !\n");
998 return MMSYSERR_BADDEVICEID;
1001 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
1002 return WAVERR_STILLPLAYING;
1004 lpWaveHdr->dwFlags &= ~WHDR_PREPARED;
1005 lpWaveHdr->dwFlags |= WHDR_DONE;
1007 return MMSYSERR_NOERROR;
1010 /**************************************************************************
1011 * wodPause [internal]
1013 static DWORD wodPause(WORD wDevID)
1015 TRACE("(%u);!\n", wDevID);
1017 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1018 WARN("bad device ID !\n");
1019 return MMSYSERR_BADDEVICEID;
1022 TRACE("imhere[3-PAUSING]\n");
1023 wodPlayer_Message(&WOutDev[wDevID], WINE_WM_PAUSING, 0);
1024 WaitForSingleObject(WOutDev[wDevID].hEvent, INFINITE);
1026 return MMSYSERR_NOERROR;
1029 /**************************************************************************
1030 * wodRestart [internal]
1032 static DWORD wodRestart(WORD wDevID)
1034 TRACE("(%u);\n", wDevID);
1036 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1037 WARN("bad device ID !\n");
1038 return MMSYSERR_BADDEVICEID;
1041 if (WOutDev[wDevID].state == WINE_WS_PAUSED) {
1042 TRACE("imhere[3-RESTARTING]\n");
1043 wodPlayer_Message(&WOutDev[wDevID], WINE_WM_RESTARTING, 0);
1044 WaitForSingleObject(WOutDev[wDevID].hEvent, INFINITE);
1047 /* FIXME: is NotifyClient with WOM_DONE right ? (Comet Busters 1.3.3 needs this notification) */
1048 /* FIXME: Myst crashes with this ... hmm -MM
1049 if (LIBAUDIOIO_NotifyClient(wDevID, WOM_DONE, 0L, 0L) != MMSYSERR_NOERROR) {
1050 WARN("can't notify client !\n");
1051 return MMSYSERR_INVALPARAM;
1055 return MMSYSERR_NOERROR;
1058 /**************************************************************************
1059 * wodReset [internal]
1061 static DWORD wodReset(WORD wDevID)
1063 TRACE("(%u);\n", wDevID);
1065 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1066 WARN("bad device ID !\n");
1067 return MMSYSERR_BADDEVICEID;
1070 TRACE("imhere[3-RESET]\n");
1071 wodPlayer_Message(&WOutDev[wDevID], WINE_WM_RESETTING, 0);
1072 WaitForSingleObject(WOutDev[wDevID].hEvent, INFINITE);
1074 return MMSYSERR_NOERROR;
1078 /**************************************************************************
1079 * wodGetPosition [internal]
1081 static DWORD wodGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
1083 int time;
1084 DWORD val;
1085 WINE_WAVEOUT* wwo;
1087 TRACE("(%u, %p, %lu);\n", wDevID, lpTime, uSize);
1089 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1090 WARN("bad device ID !\n");
1091 return MMSYSERR_BADDEVICEID;
1094 if (lpTime == NULL) return MMSYSERR_INVALPARAM;
1096 wwo = &WOutDev[wDevID];
1097 val = wwo->dwPlayedTotal;
1099 TRACE("wType=%04X wBitsPerSample=%u nSamplesPerSec=%lu nChannels=%u nAvgBytesPerSec=%lu\n",
1100 lpTime->wType, wwo->format.wBitsPerSample,
1101 wwo->format.wf.nSamplesPerSec, wwo->format.wf.nChannels,
1102 wwo->format.wf.nAvgBytesPerSec);
1103 TRACE("dwTotalPlayed=%lu\n", val);
1105 switch (lpTime->wType) {
1106 case TIME_BYTES:
1107 lpTime->u.cb = val;
1108 TRACE("TIME_BYTES=%lu\n", lpTime->u.cb);
1109 break;
1110 case TIME_SAMPLES:
1111 lpTime->u.sample = val * 8 / wwo->format.wBitsPerSample;
1112 TRACE("TIME_SAMPLES=%lu\n", lpTime->u.sample);
1113 break;
1114 case TIME_SMPTE:
1115 time = val / (wwo->format.wf.nAvgBytesPerSec / 1000);
1116 lpTime->u.smpte.hour = time / 108000;
1117 time -= lpTime->u.smpte.hour * 108000;
1118 lpTime->u.smpte.min = time / 1800;
1119 time -= lpTime->u.smpte.min * 1800;
1120 lpTime->u.smpte.sec = time / 30;
1121 time -= lpTime->u.smpte.sec * 30;
1122 lpTime->u.smpte.frame = time;
1123 lpTime->u.smpte.fps = 30;
1124 TRACE("TIME_SMPTE=%02u:%02u:%02u:%02u\n",
1125 lpTime->u.smpte.hour, lpTime->u.smpte.min,
1126 lpTime->u.smpte.sec, lpTime->u.smpte.frame);
1127 break;
1128 default:
1129 FIXME("Format %d not supported ! use TIME_MS !\n", lpTime->wType);
1130 lpTime->wType = TIME_MS;
1131 case TIME_MS:
1132 lpTime->u.ms = val / (wwo->format.wf.nAvgBytesPerSec / 1000);
1133 TRACE("TIME_MS=%lu\n", lpTime->u.ms);
1134 break;
1136 return MMSYSERR_NOERROR;
1139 /**************************************************************************
1140 * wodGetVolume [internal]
1142 static DWORD wodGetVolume(WORD wDevID, LPDWORD lpdwVol)
1144 int mixer;
1145 int vol,bal;
1146 DWORD left, right;
1148 TRACE("(%u, %p);\n", wDevID, lpdwVol);
1150 if (lpdwVol == NULL)
1151 return MMSYSERR_NOTENABLED;
1153 vol=AudioIOGetPlaybackVolume();
1154 bal=AudioIOGetPlaybackBalance();
1157 if(bal<0) {
1158 left = vol;
1159 right=-(vol*(-100+bal)/100);
1161 else
1163 right = vol;
1164 left=(vol*(100-bal)/100);
1167 *lpdwVol = ((left * 0xFFFFl) / 100) + (((right * 0xFFFFl) / 100) << 16);
1168 return MMSYSERR_NOERROR;
1172 /**************************************************************************
1173 * wodSetVolume [internal]
1175 static DWORD wodSetVolume(WORD wDevID, DWORD dwParam)
1177 int mixer;
1178 int volume,bal;
1179 DWORD left, right;
1181 TRACE("(%u, %08lX);\n", wDevID, dwParam);
1183 left = (LOWORD(dwParam) * 100) / 0xFFFFl;
1184 right = (HIWORD(dwParam) * 100) / 0xFFFFl;
1185 volume = max(left , right );
1186 bal=min(left,right);
1187 bal=bal*100/volume;
1188 if(right>left) bal=-100+bal; else bal=100-bal;
1190 AudioIOSetPlaybackVolume(volume);
1191 AudioIOSetPlaybackBalance(bal);
1193 return MMSYSERR_NOERROR;
1196 /**************************************************************************
1197 * wodGetNumDevs [internal]
1199 static DWORD wodGetNumDevs(void)
1201 DWORD ret = 1;
1203 /* FIXME: For now, only one sound device (SOUND_DEV) is allowed */
1204 int audio = open(SOUND_DEV, O_WRONLY|O_NDELAY, 0);
1206 if (audio == -1) {
1207 if (errno != EBUSY)
1208 ret = 0;
1209 } else {
1210 close(audio);
1213 TRACE("NumDrivers = %d\n",ret);
1214 return ret;
1217 /**************************************************************************
1218 * wodMessage (WINEAUDIOIO.@)
1220 DWORD WINAPI LIBAUDIOIO_wodMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
1221 DWORD dwParam1, DWORD dwParam2)
1223 TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
1224 wDevID, wMsg, dwUser, dwParam1, dwParam2);
1226 switch (wMsg) {
1227 case DRVM_INIT:
1228 case DRVM_EXIT:
1229 case DRVM_ENABLE:
1230 case DRVM_DISABLE:
1231 /* FIXME: Pretend this is supported */
1232 return 0;
1233 case WODM_OPEN: return wodOpen (wDevID, (LPWAVEOPENDESC)dwParam1, dwParam2);
1234 case WODM_CLOSE: return wodClose (wDevID);
1235 case WODM_WRITE: return wodWrite (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
1236 case WODM_PAUSE: return wodPause (wDevID);
1237 case WODM_GETPOS: return wodGetPosition (wDevID, (LPMMTIME)dwParam1, dwParam2);
1238 case WODM_BREAKLOOP: return MMSYSERR_NOTSUPPORTED;
1239 case WODM_PREPARE: return wodPrepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
1240 case WODM_UNPREPARE: return wodUnprepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
1241 case WODM_GETDEVCAPS: return wodGetDevCaps (wDevID, (LPWAVEOUTCAPSA)dwParam1, dwParam2);
1242 case WODM_GETNUMDEVS: return wodGetNumDevs ();
1243 case WODM_GETPITCH: return MMSYSERR_NOTSUPPORTED;
1244 case WODM_SETPITCH: return MMSYSERR_NOTSUPPORTED;
1245 case WODM_GETPLAYBACKRATE: return MMSYSERR_NOTSUPPORTED;
1246 case WODM_SETPLAYBACKRATE: return MMSYSERR_NOTSUPPORTED;
1247 case WODM_GETVOLUME: return wodGetVolume (wDevID, (LPDWORD)dwParam1);
1248 case WODM_SETVOLUME: return wodSetVolume (wDevID, dwParam1);
1249 case WODM_RESTART: return wodRestart (wDevID);
1250 case WODM_RESET: return wodReset (wDevID);
1252 case DRV_QUERYDSOUNDIFACE: return wodDsCreate (wDevID, (PIDSDRIVER*)dwParam1);
1253 case DRV_QUERYDSOUNDDESC: return wodDsDesc (wDevID, (PDSDRIVERDESC)dwParam1);
1254 case DRV_QUERYDSOUNDGUID: return wodDsGuid (wDevID, (LPGUID)dwParam1);
1255 default:
1256 FIXME("unknown message %d!\n", wMsg);
1258 return MMSYSERR_NOTSUPPORTED;
1261 /*======================================================================*
1262 * Low level DSOUND implementation *
1263 * While I have tampered somewhat with this code it is wholely unlikely that it works
1264 * Elsewhere the driver returns Not Implemented for DIrectSound
1265 * While it may be possible to map the sound device on Solaris
1266 * Doing so would bypass the libaudioio library and therefore break any conversions
1267 * that the libaudioio sample specification converter is doing
1268 * **** All this is untested so far
1269 *======================================================================*/
1271 typedef struct IDsDriverImpl IDsDriverImpl;
1272 typedef struct IDsDriverBufferImpl IDsDriverBufferImpl;
1274 struct IDsDriverImpl
1276 /* IUnknown fields */
1277 ICOM_VFIELD(IDsDriver);
1278 DWORD ref;
1279 /* IDsDriverImpl fields */
1280 UINT wDevID;
1281 IDsDriverBufferImpl*primary;
1284 struct IDsDriverBufferImpl
1286 /* IUnknown fields */
1287 ICOM_VFIELD(IDsDriverBuffer);
1288 DWORD ref;
1289 /* IDsDriverBufferImpl fields */
1290 IDsDriverImpl* drv;
1291 DWORD buflen;
1294 static HRESULT DSDB_MapPrimary(IDsDriverBufferImpl *dsdb)
1296 WINE_WAVEOUT *wwo = &(WOutDev[dsdb->drv->wDevID]);
1297 if (!wwo->mapping) {
1298 wwo->mapping = mmap(NULL, wwo->maplen, PROT_WRITE, MAP_SHARED,
1299 wwo->unixdev, 0);
1300 if (wwo->mapping == (LPBYTE)-1) {
1301 ERR("(%p): Could not map sound device for direct access (errno=%d)\n", dsdb, errno);
1302 return DSERR_GENERIC;
1304 TRACE("(%p): sound device has been mapped for direct access at %p, size=%ld\n", dsdb, wwo->mapping, wwo->maplen);
1306 /* for some reason, es1371 and sblive! sometimes have junk in here. */
1307 memset(wwo->mapping,0,wwo->maplen); /* clear it, or we get junk noise */
1309 return DS_OK;
1312 static HRESULT DSDB_UnmapPrimary(IDsDriverBufferImpl *dsdb)
1314 WINE_WAVEOUT *wwo = &(WOutDev[dsdb->drv->wDevID]);
1315 if (wwo->mapping) {
1316 if (munmap(wwo->mapping, wwo->maplen) < 0) {
1317 ERR("(%p): Could not unmap sound device (errno=%d)\n", dsdb, errno);
1318 return DSERR_GENERIC;
1320 wwo->mapping = NULL;
1321 TRACE("(%p): sound device unmapped\n", dsdb);
1323 return DS_OK;
1326 static HRESULT WINAPI IDsDriverBufferImpl_QueryInterface(PIDSDRIVERBUFFER iface, REFIID riid, LPVOID *ppobj)
1328 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1329 FIXME("(): stub!\n");
1330 return DSERR_UNSUPPORTED;
1333 static ULONG WINAPI IDsDriverBufferImpl_AddRef(PIDSDRIVERBUFFER iface)
1335 ICOM_THIS(IDsDriverBufferImpl,iface);
1336 This->ref++;
1337 return This->ref;
1340 static ULONG WINAPI IDsDriverBufferImpl_Release(PIDSDRIVERBUFFER iface)
1342 ICOM_THIS(IDsDriverBufferImpl,iface);
1343 if (--This->ref)
1344 return This->ref;
1345 if (This == This->drv->primary)
1346 This->drv->primary = NULL;
1347 DSDB_UnmapPrimary(This);
1348 HeapFree(GetProcessHeap(),0,This);
1349 return 0;
1352 static HRESULT WINAPI IDsDriverBufferImpl_Lock(PIDSDRIVERBUFFER iface,
1353 LPVOID*ppvAudio1,LPDWORD pdwLen1,
1354 LPVOID*ppvAudio2,LPDWORD pdwLen2,
1355 DWORD dwWritePosition,DWORD dwWriteLen,
1356 DWORD dwFlags)
1358 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1359 /* since we (GetDriverDesc flags) have specified DSDDESC_DONTNEEDPRIMARYLOCK,
1360 * and that we don't support secondary buffers, this method will never be called */
1361 TRACE("(%p): stub\n",iface);
1362 return DSERR_UNSUPPORTED;
1365 static HRESULT WINAPI IDsDriverBufferImpl_Unlock(PIDSDRIVERBUFFER iface,
1366 LPVOID pvAudio1,DWORD dwLen1,
1367 LPVOID pvAudio2,DWORD dwLen2)
1369 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1370 TRACE("(%p): stub\n",iface);
1371 return DSERR_UNSUPPORTED;
1374 static HRESULT WINAPI IDsDriverBufferImpl_SetFormat(PIDSDRIVERBUFFER iface,
1375 LPWAVEFORMATEX pwfx)
1377 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1379 TRACE("(%p,%p)\n",iface,pwfx);
1380 /* On our request (GetDriverDesc flags), DirectSound has by now used
1381 * waveOutClose/waveOutOpen to set the format...
1382 * unfortunately, this means our mmap() is now gone...
1383 * so we need to somehow signal to our DirectSound implementation
1384 * that it should completely recreate this HW buffer...
1385 * this unexpected error code should do the trick... */
1386 return DSERR_BUFFERLOST;
1389 static HRESULT WINAPI IDsDriverBufferImpl_SetFrequency(PIDSDRIVERBUFFER iface, DWORD dwFreq)
1391 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1392 TRACE("(%p,%ld): stub\n",iface,dwFreq);
1393 return DSERR_UNSUPPORTED;
1396 static HRESULT WINAPI IDsDriverBufferImpl_SetVolumePan(PIDSDRIVERBUFFER iface, PDSVOLUMEPAN pVolPan)
1398 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1399 FIXME("(%p,%p): stub!\n",iface,pVolPan);
1400 return DS_OK;
1403 static HRESULT WINAPI IDsDriverBufferImpl_SetPosition(PIDSDRIVERBUFFER iface, DWORD dwNewPos)
1405 /* ICOM_THIS(IDsDriverImpl,iface); */
1406 TRACE("(%p,%ld): stub\n",iface,dwNewPos);
1407 return DSERR_UNSUPPORTED;
1410 static HRESULT WINAPI IDsDriverBufferImpl_GetPosition(PIDSDRIVERBUFFER iface,
1411 LPDWORD lpdwPlay, LPDWORD lpdwWrite)
1413 ICOM_THIS(IDsDriverBufferImpl,iface);
1414 #if 0
1415 count_info info;
1416 #endif
1417 DWORD ptr;
1419 TRACE("(%p)\n",iface);
1420 if (WOutDev[This->drv->wDevID].unixdev == -1) {
1421 ERR("device not open, but accessing?\n");
1422 return DSERR_UNINITIALIZED;
1424 /*Libaudioio doesn't support this (Yet anyway)*/
1425 return DSERR_UNSUPPORTED;
1429 static HRESULT WINAPI IDsDriverBufferImpl_Play(PIDSDRIVERBUFFER iface, DWORD dwRes1, DWORD dwRes2, DWORD dwFlags)
1431 ICOM_THIS(IDsDriverBufferImpl,iface);
1432 #if 0
1433 int enable = PCM_ENABLE_OUTPUT;
1434 TRACE("(%p,%lx,%lx,%lx)\n",iface,dwRes1,dwRes2,dwFlags);
1435 if (ioctl(WOutDev[This->drv->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1436 ERR("ioctl failed (%d)\n", errno);
1437 return DSERR_GENERIC;
1439 #endif
1440 return DS_OK;
1443 static HRESULT WINAPI IDsDriverBufferImpl_Stop(PIDSDRIVERBUFFER iface)
1445 ICOM_THIS(IDsDriverBufferImpl,iface);
1446 int enable = 0;
1447 #if 0
1448 TRACE("(%p)\n",iface);
1449 /* no more playing */
1450 if (ioctl(WOutDev[This->drv->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1451 ERR("ioctl failed (%d)\n", errno);
1452 return DSERR_GENERIC;
1454 #endif
1455 #if 0
1456 /* the play position must be reset to the beginning of the buffer */
1457 if (ioctl(WOutDev[This->drv->wDevID].unixdev, SNDCTL_DSP_RESET, 0) < 0) {
1458 ERR("ioctl failed (%d)\n", errno);
1459 return DSERR_GENERIC;
1461 #endif
1462 /* Most OSS drivers just can't stop the playback without closing the device...
1463 * so we need to somehow signal to our DirectSound implementation
1464 * that it should completely recreate this HW buffer...
1465 * this unexpected error code should do the trick... */
1466 return DSERR_BUFFERLOST;
1469 static ICOM_VTABLE(IDsDriverBuffer) dsdbvt =
1471 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1472 IDsDriverBufferImpl_QueryInterface,
1473 IDsDriverBufferImpl_AddRef,
1474 IDsDriverBufferImpl_Release,
1475 IDsDriverBufferImpl_Lock,
1476 IDsDriverBufferImpl_Unlock,
1477 IDsDriverBufferImpl_SetFormat,
1478 IDsDriverBufferImpl_SetFrequency,
1479 IDsDriverBufferImpl_SetVolumePan,
1480 IDsDriverBufferImpl_SetPosition,
1481 IDsDriverBufferImpl_GetPosition,
1482 IDsDriverBufferImpl_Play,
1483 IDsDriverBufferImpl_Stop
1486 static HRESULT WINAPI IDsDriverImpl_QueryInterface(PIDSDRIVER iface, REFIID riid, LPVOID *ppobj)
1488 /* ICOM_THIS(IDsDriverImpl,iface); */
1489 FIXME("(%p): stub!\n",iface);
1490 return DSERR_UNSUPPORTED;
1493 static ULONG WINAPI IDsDriverImpl_AddRef(PIDSDRIVER iface)
1495 ICOM_THIS(IDsDriverImpl,iface);
1496 This->ref++;
1497 return This->ref;
1500 static ULONG WINAPI IDsDriverImpl_Release(PIDSDRIVER iface)
1502 ICOM_THIS(IDsDriverImpl,iface);
1503 if (--This->ref)
1504 return This->ref;
1505 HeapFree(GetProcessHeap(),0,This);
1506 return 0;
1509 static HRESULT WINAPI IDsDriverImpl_GetDriverDesc(PIDSDRIVER iface, PDSDRIVERDESC pDesc)
1511 ICOM_THIS(IDsDriverImpl,iface);
1512 TRACE("(%p,%p)\n",iface,pDesc);
1513 pDesc->dwFlags = DSDDESC_DOMMSYSTEMOPEN | DSDDESC_DOMMSYSTEMSETFORMAT |
1514 DSDDESC_USESYSTEMMEMORY | DSDDESC_DONTNEEDPRIMARYLOCK;
1515 strcpy(pDesc->szDesc,"Wine AudioIO DirectSound Driver");
1516 strcpy(pDesc->szDrvName,"wineaudioio.drv");
1517 pDesc->dnDevNode = WOutDev[This->wDevID].waveDesc.dnDevNode;
1518 pDesc->wVxdId = 0;
1519 pDesc->wReserved = 0;
1520 pDesc->ulDeviceNum = This->wDevID;
1521 pDesc->dwHeapType = DSDHEAP_NOHEAP;
1522 pDesc->pvDirectDrawHeap = NULL;
1523 pDesc->dwMemStartAddress = 0;
1524 pDesc->dwMemEndAddress = 0;
1525 pDesc->dwMemAllocExtra = 0;
1526 pDesc->pvReserved1 = NULL;
1527 pDesc->pvReserved2 = NULL;
1528 return DS_OK;
1531 static HRESULT WINAPI IDsDriverImpl_Open(PIDSDRIVER iface)
1533 ICOM_THIS(IDsDriverImpl,iface);
1534 int enable = 0;
1536 TRACE("(%p)\n",iface);
1537 /* make sure the card doesn't start playing before we want it to */
1538 #if 0
1539 if (ioctl(WOutDev[This->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1540 ERR("ioctl failed (%d)\n", errno);
1541 return DSERR_GENERIC;
1543 #endif
1544 return DS_OK;
1547 static HRESULT WINAPI IDsDriverImpl_Close(PIDSDRIVER iface)
1549 ICOM_THIS(IDsDriverImpl,iface);
1550 TRACE("(%p)\n",iface);
1551 if (This->primary) {
1552 ERR("problem with DirectSound: primary not released\n");
1553 return DSERR_GENERIC;
1555 return DS_OK;
1558 static HRESULT WINAPI IDsDriverImpl_GetCaps(PIDSDRIVER iface, PDSDRIVERCAPS pCaps)
1560 /* ICOM_THIS(IDsDriverImpl,iface); */
1561 TRACE("(%p,%p)\n",iface,pCaps);
1562 memset(pCaps, 0, sizeof(*pCaps));
1563 /* FIXME: need to check actual capabilities */
1564 pCaps->dwFlags = DSCAPS_PRIMARYMONO | DSCAPS_PRIMARYSTEREO |
1565 DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARY16BIT;
1566 pCaps->dwPrimaryBuffers = 1;
1567 pCaps->dwMinSecondarySampleRate = DSBFREQUENCY_MIN;
1568 pCaps->dwMaxSecondarySampleRate = DSBFREQUENCY_MAX;
1569 /* the other fields only apply to secondary buffers, which we don't support
1570 * (unless we want to mess with wavetable synthesizers and MIDI) */
1571 return DS_OK;
1574 static HRESULT WINAPI IDsDriverImpl_CreateSoundBuffer(PIDSDRIVER iface,
1575 LPWAVEFORMATEX pwfx,
1576 DWORD dwFlags, DWORD dwCardAddress,
1577 LPDWORD pdwcbBufferSize,
1578 LPBYTE *ppbBuffer,
1579 LPVOID *ppvObj)
1581 ICOM_THIS(IDsDriverImpl,iface);
1582 IDsDriverBufferImpl** ippdsdb = (IDsDriverBufferImpl**)ppvObj;
1583 HRESULT err;
1584 #if 0
1585 audio_buf_info info;
1586 #endif
1587 int enable = 0;
1589 TRACE("(%p,%p,%lx,%lx)\n",iface,pwfx,dwFlags,dwCardAddress);
1590 /* we only support primary buffers */
1591 if (!(dwFlags & DSBCAPS_PRIMARYBUFFER))
1592 return DSERR_UNSUPPORTED;
1593 if (This->primary)
1594 return DSERR_ALLOCATED;
1595 if (dwFlags & (DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN))
1596 return DSERR_CONTROLUNAVAIL;
1598 *ippdsdb = (IDsDriverBufferImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDsDriverBufferImpl));
1599 if (*ippdsdb == NULL)
1600 return DSERR_OUTOFMEMORY;
1601 (*ippdsdb)->lpVtbl = &dsdbvt;
1602 (*ippdsdb)->ref = 1;
1603 (*ippdsdb)->drv = This;
1605 /* check how big the DMA buffer is now */
1606 #if 0
1607 if (ioctl(WOutDev[This->wDevID].unixdev, SNDCTL_DSP_GETOSPACE, &info) < 0) {
1608 ERR("ioctl failed (%d)\n", errno);
1609 HeapFree(GetProcessHeap(),0,*ippdsdb);
1610 *ippdsdb = NULL;
1611 return DSERR_GENERIC;
1613 #endif
1614 WOutDev[This->wDevID].maplen =64*1024; /* Map 64 K at a time */
1616 #if 0
1617 (*ippdsdb)->buflen = info.fragstotal * info.fragsize;
1618 #endif
1619 /* map the DMA buffer */
1620 err = DSDB_MapPrimary(*ippdsdb);
1621 if (err != DS_OK) {
1622 HeapFree(GetProcessHeap(),0,*ippdsdb);
1623 *ippdsdb = NULL;
1624 return err;
1627 /* primary buffer is ready to go */
1628 *pdwcbBufferSize = WOutDev[This->wDevID].maplen;
1629 *ppbBuffer = WOutDev[This->wDevID].mapping;
1631 /* some drivers need some extra nudging after mapping */
1632 #if 0
1633 if (ioctl(WOutDev[This->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1634 ERR("ioctl failed (%d)\n", errno);
1635 return DSERR_GENERIC;
1637 #endif
1639 This->primary = *ippdsdb;
1641 return DS_OK;
1644 static HRESULT WINAPI IDsDriverImpl_DuplicateSoundBuffer(PIDSDRIVER iface,
1645 PIDSDRIVERBUFFER pBuffer,
1646 LPVOID *ppvObj)
1648 /* ICOM_THIS(IDsDriverImpl,iface); */
1649 TRACE("(%p,%p): stub\n",iface,pBuffer);
1650 return DSERR_INVALIDCALL;
1653 static ICOM_VTABLE(IDsDriver) dsdvt =
1655 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1656 IDsDriverImpl_QueryInterface,
1657 IDsDriverImpl_AddRef,
1658 IDsDriverImpl_Release,
1659 IDsDriverImpl_GetDriverDesc,
1660 IDsDriverImpl_Open,
1661 IDsDriverImpl_Close,
1662 IDsDriverImpl_GetCaps,
1663 IDsDriverImpl_CreateSoundBuffer,
1664 IDsDriverImpl_DuplicateSoundBuffer
1667 static DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv)
1669 IDsDriverImpl** idrv = (IDsDriverImpl**)drv;
1671 /* the HAL isn't much better than the HEL if we can't do mmap() */
1672 if (!(WOutDev[wDevID].caps.dwSupport & WAVECAPS_DIRECTSOUND)) {
1673 ERR("DirectSound flag not set\n");
1674 MESSAGE("This sound card's driver does not support direct access\n");
1675 MESSAGE("The (slower) DirectSound HEL mode will be used instead.\n");
1676 return MMSYSERR_NOTSUPPORTED;
1679 *idrv = (IDsDriverImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDsDriverImpl));
1680 if (!*idrv)
1681 return MMSYSERR_NOMEM;
1682 (*idrv)->lpVtbl = &dsdvt;
1683 (*idrv)->ref = 1;
1685 (*idrv)->wDevID = wDevID;
1686 (*idrv)->primary = NULL;
1687 return MMSYSERR_NOERROR;
1690 static DWORD wodDsDesc(UINT wDevID, PDSDRIVERDESC desc)
1692 memset(desc, 0, sizeof(*desc));
1693 strcpy(desc->szDesc, "Wine LIBAUDIOIO DirectSound Driver");
1694 strcpy(desc->szDrvName, "wineaudioio.drv");
1695 return MMSYSERR_NOERROR;
1698 static DWORD wodDsGuid(UINT wDevID, LPGUID pGuid)
1700 memcpy(pGuid, &DSDEVID_DefaultPlayback, sizeof(GUID));
1701 return MMSYSERR_NOERROR;
1704 /*======================================================================*
1705 * Low level WAVE IN implementation *
1706 *======================================================================*/
1708 /**************************************************************************
1709 * widGetDevCaps [internal]
1711 static DWORD widGetDevCaps(WORD wDevID, LPWAVEINCAPSA lpCaps, DWORD dwSize)
1713 TRACE("(%u, %p, %lu);\n", wDevID, lpCaps, dwSize);
1715 if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
1717 if (wDevID >= MAX_WAVEINDRV) {
1718 TRACE("MAX_WAVINDRV reached !\n");
1719 return MMSYSERR_BADDEVICEID;
1722 memcpy(lpCaps, &WInDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
1723 return MMSYSERR_NOERROR;
1726 /**************************************************************************
1727 * widRecorder [internal]
1729 static DWORD CALLBACK widRecorder(LPVOID pmt)
1731 WORD uDevID = (DWORD)pmt;
1732 WINE_WAVEIN* wwi = (WINE_WAVEIN*)&WInDev[uDevID];
1733 WAVEHDR* lpWaveHdr;
1734 DWORD dwSleepTime;
1735 MSG msg;
1736 DWORD bytesRead;
1739 int fragments;
1740 int fragsize;
1741 int fragstotal;
1742 int bytes;
1745 int xs;
1747 LPVOID buffer = HeapAlloc(GetProcessHeap(),
1748 HEAP_ZERO_MEMORY,
1749 wwi->dwFragmentSize);
1751 LPVOID pOffset = buffer;
1753 PeekMessageA(&msg, 0, 0, 0, 0);
1754 wwi->state = WINE_WS_STOPPED;
1755 wwi->dwTotalRecorded = 0;
1757 SetEvent(wwi->hEvent);
1760 /* make sleep time to be # of ms to output a fragment */
1761 dwSleepTime = (wwi->dwFragmentSize * 1000) / wwi->format.wf.nAvgBytesPerSec;
1762 TRACE("sleeptime=%ld ms\n", dwSleepTime);
1764 for (; ; ) {
1765 /* wait for dwSleepTime or an event in thread's queue */
1766 /* FIXME: could improve wait time depending on queue state,
1767 * ie, number of queued fragments
1770 if (wwi->lpQueuePtr != NULL && wwi->state == WINE_WS_PLAYING)
1772 lpWaveHdr = wwi->lpQueuePtr;
1774 bytes=fragsize=AudioIORecordingAvailable();
1775 fragments=fragstotal=1;
1777 TRACE("info={frag=%d fsize=%d ftotal=%d bytes=%d}\n", fragments, fragsize, fragstotal, bytes);
1780 /* read all the fragments accumulated so far */
1781 while ((fragments > 0) && (wwi->lpQueuePtr))
1783 fragments --;
1785 if (lpWaveHdr->dwBufferLength - lpWaveHdr->dwBytesRecorded >= wwi->dwFragmentSize)
1787 /* directly read fragment in wavehdr */
1788 bytesRead = AudioIORead(
1789 lpWaveHdr->lpData + lpWaveHdr->dwBytesRecorded,
1790 wwi->dwFragmentSize);
1792 TRACE("bytesRead=%ld (direct)\n", bytesRead);
1793 if (bytesRead != (DWORD) -1)
1795 /* update number of bytes recorded in current buffer and by this device */
1796 lpWaveHdr->dwBytesRecorded += bytesRead;
1797 wwi->dwTotalRecorded += bytesRead;
1799 /* buffer is full. notify client */
1800 if (lpWaveHdr->dwBytesRecorded == lpWaveHdr->dwBufferLength)
1802 /* must copy the value of next waveHdr, because we have no idea of what
1803 * will be done with the content of lpWaveHdr in callback
1805 LPWAVEHDR lpNext = lpWaveHdr->lpNext;
1807 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
1808 lpWaveHdr->dwFlags |= WHDR_DONE;
1810 if (LIBAUDIOIO_NotifyClient(uDevID, WIM_DATA,
1811 (DWORD)lpWaveHdr, 0) != MMSYSERR_NOERROR)
1813 WARN("can't notify client !\n");
1815 lpWaveHdr = wwi->lpQueuePtr = lpNext;
1819 else
1821 /* read the fragment in a local buffer */
1822 bytesRead = AudioIORead( buffer, wwi->dwFragmentSize);
1823 pOffset = buffer;
1825 TRACE("bytesRead=%ld (local)\n", bytesRead);
1827 /* copy data in client buffers */
1828 while (bytesRead != (DWORD) -1 && bytesRead > 0)
1830 DWORD dwToCopy = min (bytesRead, lpWaveHdr->dwBufferLength - lpWaveHdr->dwBytesRecorded);
1832 memcpy(lpWaveHdr->lpData + lpWaveHdr->dwBytesRecorded,
1833 pOffset,
1834 dwToCopy);
1836 /* update number of bytes recorded in current buffer and by this device */
1837 lpWaveHdr->dwBytesRecorded += dwToCopy;
1838 wwi->dwTotalRecorded += dwToCopy;
1839 bytesRead -= dwToCopy;
1840 pOffset += dwToCopy;
1842 /* client buffer is full. notify client */
1843 if (lpWaveHdr->dwBytesRecorded == lpWaveHdr->dwBufferLength)
1845 /* must copy the value of next waveHdr, because we have no idea of what
1846 * will be done with the content of lpWaveHdr in callback
1848 LPWAVEHDR lpNext = lpWaveHdr->lpNext;
1849 TRACE("lpNext=%p\n", lpNext);
1851 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
1852 lpWaveHdr->dwFlags |= WHDR_DONE;
1854 if (LIBAUDIOIO_NotifyClient(uDevID, WIM_DATA,
1855 (DWORD)lpWaveHdr, 0) != MMSYSERR_NOERROR)
1857 WARN("can't notify client !\n");
1860 wwi->lpQueuePtr = lpWaveHdr = lpNext;
1861 if (!lpNext && bytesRead) {
1862 /* no more buffer to copy data to, but we did read more.
1863 * what hasn't been copied will be dropped
1865 WARN("buffer under run! %lu bytes dropped.\n", bytesRead);
1866 wwi->lpQueuePtr = NULL;
1867 break;
1875 MsgWaitForMultipleObjects(0, NULL, FALSE, dwSleepTime, QS_POSTMESSAGE);
1877 while (PeekMessageA(&msg, 0, WINE_WM_FIRST, WINE_WM_LAST, PM_REMOVE)) {
1879 TRACE("msg=0x%x wParam=0x%x lParam=0x%lx\n", msg.message, msg.wParam, msg.lParam);
1880 switch (msg.message) {
1881 case WINE_WM_PAUSING:
1882 wwi->state = WINE_WS_PAUSED;
1884 AudioIORecordingPause();
1885 SetEvent(wwi->hEvent);
1886 break;
1887 case WINE_WM_RESTARTING:
1890 wwi->state = WINE_WS_PLAYING;
1892 if (wwi->bTriggerSupport)
1894 /* start the recording */
1895 AudioIORecordingResume();
1897 else
1899 unsigned char data[4];
1900 /* read 4 bytes to start the recording */
1901 AudioIORead( data, 4);
1904 SetEvent(wwi->hEvent);
1905 break;
1907 case WINE_WM_HEADER:
1908 lpWaveHdr = (LPWAVEHDR)msg.lParam;
1909 lpWaveHdr->lpNext = 0;
1911 /* insert buffer at the end of queue */
1913 LPWAVEHDR* wh;
1914 for (wh = &(wwi->lpQueuePtr); *wh; wh = &((*wh)->lpNext));
1915 *wh = lpWaveHdr;
1917 break;
1918 case WINE_WM_RESETTING:
1919 wwi->state = WINE_WS_STOPPED;
1920 /* return all buffers to the app */
1921 for (lpWaveHdr = wwi->lpQueuePtr; lpWaveHdr; lpWaveHdr = lpWaveHdr->lpNext) {
1922 TRACE("reset %p %p\n", lpWaveHdr, lpWaveHdr->lpNext);
1923 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
1924 lpWaveHdr->dwFlags |= WHDR_DONE;
1926 if (LIBAUDIOIO_NotifyClient(uDevID, WIM_DATA,
1927 (DWORD)lpWaveHdr, 0) != MMSYSERR_NOERROR) {
1928 WARN("can't notify client !\n");
1931 wwi->lpQueuePtr = NULL;
1932 SetEvent(wwi->hEvent);
1933 break;
1934 case WINE_WM_CLOSING:
1935 wwi->hThread = 0;
1936 wwi->state = WINE_WS_CLOSED;
1937 SetEvent(wwi->hEvent);
1938 HeapFree(GetProcessHeap(), 0, buffer);
1939 ExitThread(0);
1940 /* shouldn't go here */
1941 default:
1942 FIXME("unknown message %d\n", msg.message);
1943 break;
1947 ExitThread(0);
1948 /* just for not generating compilation warnings... should never be executed */
1949 return 0;
1953 /**************************************************************************
1954 * widOpen [internal]
1956 static DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
1958 int audio;
1959 int fragment_size;
1960 int sample_rate;
1961 int format;
1962 int dsp_stereo;
1963 WINE_WAVEIN* wwi;
1964 int audio_fragment;
1966 TRACE("(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
1967 if (lpDesc == NULL) {
1968 WARN("Invalid Parameter !\n");
1969 return MMSYSERR_INVALPARAM;
1971 if (wDevID >= MAX_WAVEINDRV) return MMSYSERR_BADDEVICEID;
1973 /* only PCM format is supported so far... */
1974 if (lpDesc->lpFormat->wFormatTag != WAVE_FORMAT_PCM ||
1975 lpDesc->lpFormat->nChannels == 0 ||
1976 lpDesc->lpFormat->nSamplesPerSec == 0) {
1977 WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
1978 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
1979 lpDesc->lpFormat->nSamplesPerSec);
1980 return WAVERR_BADFORMAT;
1983 if (dwFlags & WAVE_FORMAT_QUERY) {
1984 TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
1985 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
1986 lpDesc->lpFormat->nSamplesPerSec);
1987 return MMSYSERR_NOERROR;
1990 if (access(SOUND_DEV,0) != 0) return MMSYSERR_NOTENABLED;
1991 audio = AudioIOOpenX( O_RDONLY|O_NDELAY, &spec[RECORD],&spec[RECORD]);
1992 if (audio == -1) {
1993 WARN("can't open sound device %s (%s)!\n", SOUND_DEV, strerror(errno));
1994 return MMSYSERR_ALLOCATED;
1996 fcntl(audio, F_SETFD, 1); /* set close on exec flag */
1998 wwi = &WInDev[wDevID];
1999 if (wwi->lpQueuePtr) {
2000 WARN("Should have an empty queue (%p)\n", wwi->lpQueuePtr);
2001 wwi->lpQueuePtr = NULL;
2003 wwi->unixdev = audio;
2004 wwi->dwTotalRecorded = 0;
2005 wwi->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
2007 memcpy(&wwi->waveDesc, lpDesc, sizeof(WAVEOPENDESC));
2008 memcpy(&wwi->format, lpDesc->lpFormat, sizeof(PCMWAVEFORMAT));
2010 if (wwi->format.wBitsPerSample == 0) {
2011 WARN("Resetting zeroed wBitsPerSample\n");
2012 wwi->format.wBitsPerSample = 8 *
2013 (wwi->format.wf.nAvgBytesPerSec /
2014 wwi->format.wf.nSamplesPerSec) /
2015 wwi->format.wf.nChannels;
2018 spec[RECORD].rate=sample_rate = wwi->format.wf.nSamplesPerSec;
2019 dsp_stereo = ((spec[RECORD].channels=wwi->format.wf.nChannels) > 1) ? TRUE : FALSE;
2020 spec[RECORD].precision= wwi->format.wBitsPerSample;
2021 spec[RECORD].type=(spec[RECORD].precision==16)?TYPE_SIGNED:TYPE_UNSIGNED;
2023 /* This is actually hand tuned to work so that my SB Live:
2024 * - does not skip
2025 * - does not buffer too much
2026 * when sending with the Shoutcast winamp plugin
2028 /* 7 fragments max, 2^10 = 1024 bytes per fragment */
2029 audio_fragment = 0x0007000A;
2030 fragment_size=4096;
2031 if (fragment_size == -1) {
2032 AudioIOClose();
2033 wwi->unixdev = -1;
2034 return MMSYSERR_NOTENABLED;
2036 wwi->dwFragmentSize = fragment_size;
2038 TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
2039 wwi->format.wBitsPerSample, wwi->format.wf.nAvgBytesPerSec,
2040 wwi->format.wf.nSamplesPerSec, wwi->format.wf.nChannels,
2041 wwi->format.wf.nBlockAlign);
2043 wwi->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
2044 wwi->hThread = CreateThread(NULL, 0, widRecorder, (LPVOID)(DWORD)wDevID, 0, &(wwi->dwThreadID));
2045 WaitForSingleObject(wwi->hEvent, INFINITE);
2047 if (LIBAUDIOIO_NotifyClient(wDevID, WIM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
2048 WARN("can't notify client !\n");
2049 return MMSYSERR_INVALPARAM;
2051 return MMSYSERR_NOERROR;
2054 /**************************************************************************
2055 * widClose [internal]
2057 static DWORD widClose(WORD wDevID)
2059 WINE_WAVEIN* wwi;
2061 TRACE("(%u);\n", wDevID);
2062 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2063 WARN("can't close !\n");
2064 return MMSYSERR_INVALHANDLE;
2067 wwi = &WInDev[wDevID];
2069 if (wwi->lpQueuePtr != NULL) {
2070 WARN("still buffers open !\n");
2071 return WAVERR_STILLPLAYING;
2074 PostThreadMessageA(wwi->dwThreadID, WINE_WM_CLOSING, 0, 0);
2075 WaitForSingleObject(wwi->hEvent, INFINITE);
2076 CloseHandle(wwi->hEvent);
2077 AudioIOClose();
2078 wwi->unixdev = -1;
2079 wwi->dwFragmentSize = 0;
2080 if (LIBAUDIOIO_NotifyClient(wDevID, WIM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
2081 WARN("can't notify client !\n");
2082 return MMSYSERR_INVALPARAM;
2084 return MMSYSERR_NOERROR;
2087 /**************************************************************************
2088 * widAddBuffer [internal]
2090 static DWORD widAddBuffer(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
2092 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
2094 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2095 WARN("can't do it !\n");
2096 return MMSYSERR_INVALHANDLE;
2098 if (!(lpWaveHdr->dwFlags & WHDR_PREPARED)) {
2099 TRACE("never been prepared !\n");
2100 return WAVERR_UNPREPARED;
2102 if (lpWaveHdr->dwFlags & WHDR_INQUEUE) {
2103 TRACE("header already in use !\n");
2104 return WAVERR_STILLPLAYING;
2107 lpWaveHdr->dwFlags |= WHDR_INQUEUE;
2108 lpWaveHdr->dwFlags &= ~WHDR_DONE;
2109 lpWaveHdr->dwBytesRecorded = 0;
2110 lpWaveHdr->lpNext = NULL;
2112 PostThreadMessageA(WInDev[wDevID].dwThreadID, WINE_WM_HEADER, 0, (DWORD)lpWaveHdr);
2113 return MMSYSERR_NOERROR;
2116 /**************************************************************************
2117 * widPrepare [internal]
2119 static DWORD widPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
2121 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
2123 if (wDevID >= MAX_WAVEINDRV) return MMSYSERR_INVALHANDLE;
2125 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
2126 return WAVERR_STILLPLAYING;
2128 lpWaveHdr->dwFlags |= WHDR_PREPARED;
2129 lpWaveHdr->dwFlags &= ~(WHDR_INQUEUE|WHDR_DONE);
2130 lpWaveHdr->dwBytesRecorded = 0;
2131 TRACE("header prepared !\n");
2132 return MMSYSERR_NOERROR;
2135 /**************************************************************************
2136 * widUnprepare [internal]
2138 static DWORD widUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
2140 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
2141 if (wDevID >= MAX_WAVEINDRV) return MMSYSERR_INVALHANDLE;
2143 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
2144 return WAVERR_STILLPLAYING;
2146 lpWaveHdr->dwFlags &= ~(WHDR_PREPARED|WHDR_INQUEUE);
2147 lpWaveHdr->dwFlags |= WHDR_DONE;
2149 return MMSYSERR_NOERROR;
2152 /**************************************************************************
2153 * widStart [internal]
2155 static DWORD widStart(WORD wDevID)
2157 TRACE("(%u);\n", wDevID);
2158 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2159 WARN("can't start recording !\n");
2160 return MMSYSERR_INVALHANDLE;
2163 PostThreadMessageA(WInDev[wDevID].dwThreadID, WINE_WM_RESTARTING, 0, 0);
2164 WaitForSingleObject(WInDev[wDevID].hEvent, INFINITE);
2165 return MMSYSERR_NOERROR;
2168 /**************************************************************************
2169 * widStop [internal]
2171 static DWORD widStop(WORD wDevID)
2173 TRACE("(%u);\n", wDevID);
2174 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2175 WARN("can't stop !\n");
2176 return MMSYSERR_INVALHANDLE;
2178 /* FIXME: reset aint stop */
2179 PostThreadMessageA(WInDev[wDevID].dwThreadID, WINE_WM_RESETTING, 0, 0);
2180 WaitForSingleObject(WInDev[wDevID].hEvent, INFINITE);
2182 return MMSYSERR_NOERROR;
2185 /**************************************************************************
2186 * widReset [internal]
2188 static DWORD widReset(WORD wDevID)
2190 TRACE("(%u);\n", wDevID);
2191 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2192 WARN("can't reset !\n");
2193 return MMSYSERR_INVALHANDLE;
2195 PostThreadMessageA(WInDev[wDevID].dwThreadID, WINE_WM_RESETTING, 0, 0);
2196 WaitForSingleObject(WInDev[wDevID].hEvent, INFINITE);
2197 return MMSYSERR_NOERROR;
2200 /**************************************************************************
2201 * widGetPosition [internal]
2203 static DWORD widGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
2205 int time;
2206 WINE_WAVEIN* wwi;
2208 TRACE("(%u, %p, %lu);\n", wDevID, lpTime, uSize);
2210 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2211 WARN("can't get pos !\n");
2212 return MMSYSERR_INVALHANDLE;
2214 if (lpTime == NULL) return MMSYSERR_INVALPARAM;
2216 wwi = &WInDev[wDevID];
2218 TRACE("wType=%04X !\n", lpTime->wType);
2219 TRACE("wBitsPerSample=%u\n", wwi->format.wBitsPerSample);
2220 TRACE("nSamplesPerSec=%lu\n", wwi->format.wf.nSamplesPerSec);
2221 TRACE("nChannels=%u\n", wwi->format.wf.nChannels);
2222 TRACE("nAvgBytesPerSec=%lu\n", wwi->format.wf.nAvgBytesPerSec);
2223 switch (lpTime->wType) {
2224 case TIME_BYTES:
2225 lpTime->u.cb = wwi->dwTotalRecorded;
2226 TRACE("TIME_BYTES=%lu\n", lpTime->u.cb);
2227 break;
2228 case TIME_SAMPLES:
2229 lpTime->u.sample = wwi->dwTotalRecorded * 8 /
2230 wwi->format.wBitsPerSample;
2231 TRACE("TIME_SAMPLES=%lu\n", lpTime->u.sample);
2232 break;
2233 case TIME_SMPTE:
2234 time = wwi->dwTotalRecorded /
2235 (wwi->format.wf.nAvgBytesPerSec / 1000);
2236 lpTime->u.smpte.hour = time / 108000;
2237 time -= lpTime->u.smpte.hour * 108000;
2238 lpTime->u.smpte.min = time / 1800;
2239 time -= lpTime->u.smpte.min * 1800;
2240 lpTime->u.smpte.sec = time / 30;
2241 time -= lpTime->u.smpte.sec * 30;
2242 lpTime->u.smpte.frame = time;
2243 lpTime->u.smpte.fps = 30;
2244 TRACE("TIME_SMPTE=%02u:%02u:%02u:%02u\n",
2245 lpTime->u.smpte.hour, lpTime->u.smpte.min,
2246 lpTime->u.smpte.sec, lpTime->u.smpte.frame);
2247 break;
2248 case TIME_MS:
2249 lpTime->u.ms = wwi->dwTotalRecorded /
2250 (wwi->format.wf.nAvgBytesPerSec / 1000);
2251 TRACE("TIME_MS=%lu\n", lpTime->u.ms);
2252 break;
2253 default:
2254 FIXME("format not supported (%u) ! use TIME_MS !\n", lpTime->wType);
2255 lpTime->wType = TIME_MS;
2257 return MMSYSERR_NOERROR;
2260 /**************************************************************************
2261 * widMessage (WINEAUDIOIO.@)
2263 DWORD WINAPI LIBAUDIOIO_widMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
2264 DWORD dwParam1, DWORD dwParam2)
2266 TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
2267 wDevID, wMsg, dwUser, dwParam1, dwParam2);
2269 switch (wMsg) {
2270 case DRVM_INIT:
2271 case DRVM_EXIT:
2272 case DRVM_ENABLE:
2273 case DRVM_DISABLE:
2274 /* FIXME: Pretend this is supported */
2275 return 0;
2276 case WIDM_OPEN: return widOpen (wDevID, (LPWAVEOPENDESC)dwParam1, dwParam2);
2277 case WIDM_CLOSE: return widClose (wDevID);
2278 case WIDM_ADDBUFFER: return widAddBuffer (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
2279 case WIDM_PREPARE: return widPrepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
2280 case WIDM_UNPREPARE: return widUnprepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
2281 case WIDM_GETDEVCAPS: return widGetDevCaps (wDevID, (LPWAVEINCAPSA)dwParam1, dwParam2);
2282 case WIDM_GETNUMDEVS: return wodGetNumDevs (); /* same number of devices in output as in input */
2283 case WIDM_GETPOS: return widGetPosition(wDevID, (LPMMTIME)dwParam1, dwParam2);
2284 case WIDM_RESET: return widReset (wDevID);
2285 case WIDM_START: return widStart (wDevID);
2286 case WIDM_STOP: return widStop (wDevID);
2287 case DRV_QUERYDSOUNDIFACE: return widDsCreate (wDevID, (PIDSCDRIVER*)dwParam1);
2288 case DRV_QUERYDSOUNDDESC: return widDsDesc (wDevID, (PDSDRIVERDESC)dwParam1);
2289 case DRV_QUERYDSOUNDGUID: return widDsGuid (wDevID, (LPGUID)dwParam1);
2290 default:
2291 FIXME("unknown message %u!\n", wMsg);
2293 return MMSYSERR_NOTSUPPORTED;
2296 /*======================================================================*
2297 * Low level DSOUND capture implementation *
2298 *======================================================================*/
2299 static DWORD widDsCreate(UINT wDevID, PIDSDRIVER* drv)
2301 /* we can't perform memory mapping as we don't have a file stream
2302 interface with arts like we do with oss */
2303 MESSAGE("This sound card's driver does not support direct access\n");
2304 MESSAGE("The (slower) DirectSound HEL mode will be used instead.\n");
2305 return MMSYSERR_NOTSUPPORTED;
2308 static DWORD widDsDesc(UINT wDevID, PDSDRIVERDESC desc)
2310 memset(desc, 0, sizeof(*desc));
2311 strcpy(desc->szDesc, "Wine LIBAUDIOIO DirectSound Driver");
2312 strcpy(desc->szDrvName, "wineaudioio.drv");
2313 return MMSYSERR_NOERROR;
2316 static DWORD wodDsGuid(UINT wDevID, LPGUID pGuid)
2318 memcpy(pGuid, &DSDEVID_DefaultCapture, sizeof(GUID));
2319 return MMSYSERR_NOERROR;
2322 #else /* HAVE_LIBAUDIOIO */
2324 /**************************************************************************
2325 * wodMessage (WINEAUDIOIO.@)
2327 DWORD WINAPI LIBAUDIOIO_wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
2328 DWORD dwParam1, DWORD dwParam2)
2330 FIXME("(%u, %04X, %08lX, %08lX, %08lX):stub\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
2331 return MMSYSERR_NOTENABLED;
2334 /**************************************************************************
2335 * widMessage (WINEAUDIOIO.@)
2337 DWORD WINAPI LIBAUDIOIO_widMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
2338 DWORD dwParam1, DWORD dwParam2)
2340 FIXME("(%u, %04X, %08lX, %08lX, %08lX):stub\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
2341 return MMSYSERR_NOTENABLED;
2344 #endif /* HAVE_LIBAUDIOIO */