Enable the DirectSound HAL for sound drivers that do not report
[wine/wine-kai.git] / dlls / winmm / wineoss / audio.c
blob3beb71b024f5e270180424b7f9afdce221ec12a9
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2 /*
3 * Sample Wine Driver for Open Sound System (featured in Linux and FreeBSD)
5 * Copyright 1994 Martin Ayotte
6 * 1999 Eric Pouech (async playing in waveOut/waveIn)
7 * 2000 Eric Pouech (loops in waveOut)
8 */
9 /*
10 * FIXME:
11 * pause in waveOut does not work correctly
12 * full duplex (in/out) is not working (device is opened twice for Out
13 * and In) (OSS is known for its poor duplex capabilities, alsa is
14 * better)
17 /*#define EMULATE_SB16*/
19 #include "config.h"
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <sys/ioctl.h>
28 #ifdef HAVE_SYS_MMAN_H
29 # include <sys/mman.h>
30 #endif
31 #include "windef.h"
32 #include "wingdi.h"
33 #include "winerror.h"
34 #include "wine/winuser16.h"
35 #include "mmddk.h"
36 #include "dsound.h"
37 #include "dsdriver.h"
38 #include "oss.h"
39 #include "heap.h"
40 #include "debugtools.h"
42 DEFAULT_DEBUG_CHANNEL(wave);
44 /* Allow 1% deviation for sample rates (some ES137x cards) */
45 #define NEAR_MATCH(rate1,rate2) (((100*((int)(rate1)-(int)(rate2)))/(rate1))==0)
47 #ifdef HAVE_OSS
49 #define SOUND_DEV "/dev/dsp"
50 #define MIXER_DEV "/dev/mixer"
52 #define MAX_WAVEOUTDRV (1)
53 #define MAX_WAVEINDRV (1)
55 /* state diagram for waveOut writing:
57 * +---------+-------------+---------------+---------------------------------+
58 * | state | function | event | new state |
59 * +---------+-------------+---------------+---------------------------------+
60 * | | open() | | STOPPED |
61 * | PAUSED | write() | | PAUSED |
62 * | STOPPED | write() | <thrd create> | PLAYING |
63 * | PLAYING | write() | HEADER | PLAYING |
64 * | (other) | write() | <error> | |
65 * | (any) | pause() | PAUSING | PAUSED |
66 * | PAUSED | restart() | RESTARTING | PLAYING (if no thrd => STOPPED) |
67 * | (any) | reset() | RESETTING | STOPPED |
68 * | (any) | close() | CLOSING | CLOSED |
69 * +---------+-------------+---------------+---------------------------------+
72 /* states of the playing device */
73 #define WINE_WS_PLAYING 0
74 #define WINE_WS_PAUSED 1
75 #define WINE_WS_STOPPED 2
76 #define WINE_WS_CLOSED 3
78 /* events to be send to device */
79 #define WINE_WM_PAUSING (WM_USER + 1)
80 #define WINE_WM_RESTARTING (WM_USER + 2)
81 #define WINE_WM_RESETTING (WM_USER + 3)
82 #define WINE_WM_CLOSING (WM_USER + 4)
83 #define WINE_WM_HEADER (WM_USER + 5)
85 #define WINE_WM_FIRST WINE_WM_PAUSING
86 #define WINE_WM_LAST WINE_WM_HEADER
88 typedef struct {
89 int msg;
90 DWORD param;
91 } WWO_MSG;
93 typedef struct {
94 int unixdev;
95 volatile int state; /* one of the WINE_WS_ manifest constants */
96 DWORD dwFragmentSize; /* size of OSS buffer fragment */
97 WAVEOPENDESC waveDesc;
98 WORD wFlags;
99 PCMWAVEFORMAT format;
100 LPWAVEHDR lpQueuePtr; /* start of queued WAVEHDRs (waiting to be notified) */
101 LPWAVEHDR lpPlayPtr; /* start of not yet fully played buffers */
102 LPWAVEHDR lpLoopPtr; /* pointer of first buffer in loop, if any */
104 DWORD dwLastFragDone; /* time in ms, when last played fragment will be actually played */
105 DWORD dwPlayedTotal; /* number of bytes played since opening */
107 /* info on current lpQueueHdr->lpWaveHdr */
108 DWORD dwOffCurrHdr; /* offset in lpPlayPtr->lpData for fragments */
109 DWORD dwRemain; /* number of bytes to write to end the current fragment */
111 /* synchronization stuff */
112 HANDLE hThread;
113 DWORD dwThreadID;
114 HANDLE hEvent;
115 #define WWO_RING_BUFFER_SIZE 30
116 WWO_MSG messages[WWO_RING_BUFFER_SIZE];
117 int msg_tosave;
118 int msg_toget;
119 HANDLE msg_event;
120 CRITICAL_SECTION msg_crst;
121 WAVEOUTCAPSA caps;
123 /* DirectSound stuff */
124 LPBYTE mapping;
125 DWORD maplen;
126 } WINE_WAVEOUT;
128 typedef struct {
129 int unixdev;
130 volatile int state;
131 DWORD dwFragmentSize; /* OpenSound '/dev/dsp' give us that size */
132 WAVEOPENDESC waveDesc;
133 WORD wFlags;
134 PCMWAVEFORMAT format;
135 LPWAVEHDR lpQueuePtr;
136 DWORD dwTotalRecorded;
137 WAVEINCAPSA caps;
138 BOOL bTriggerSupport;
140 /* synchronization stuff */
141 HANDLE hThread;
142 DWORD dwThreadID;
143 HANDLE hEvent;
144 } WINE_WAVEIN;
146 static WINE_WAVEOUT WOutDev [MAX_WAVEOUTDRV];
147 static WINE_WAVEIN WInDev [MAX_WAVEINDRV ];
149 static DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv);
151 /*======================================================================*
152 * Low level WAVE implementation *
153 *======================================================================*/
155 LONG OSS_WaveInit(void)
157 int audio;
158 int smplrate;
159 int samplesize = 16;
160 int dsp_stereo = 1;
161 int bytespersmpl;
162 int caps;
163 int mask;
164 int i;
167 /* start with output device */
169 /* initialize all device handles to -1 */
170 for (i = 0; i < MAX_WAVEOUTDRV; ++i)
172 WOutDev[i].unixdev = -1;
175 /* FIXME: only one device is supported */
176 memset(&WOutDev[0].caps, 0, sizeof(WOutDev[0].caps));
178 if (access(SOUND_DEV,0) != 0 ||
179 (audio = open(SOUND_DEV, O_WRONLY|O_NDELAY, 0)) == -1) {
180 WARN("Couldn't open out %s (%s)\n", SOUND_DEV, strerror(errno));
181 return -1;
184 ioctl(audio, SNDCTL_DSP_RESET, 0);
186 /* FIXME: some programs compare this string against the content of the registry
187 * for MM drivers. The names have to match in order for the program to work
188 * (e.g. MS win9x mplayer.exe)
190 #ifdef EMULATE_SB16
191 WOutDev[0].caps.wMid = 0x0002;
192 WOutDev[0].caps.wPid = 0x0104;
193 strcpy(WOutDev[0].caps.szPname, "SB16 Wave Out");
194 #else
195 WOutDev[0].caps.wMid = 0x00FF; /* Manufac ID */
196 WOutDev[0].caps.wPid = 0x0001; /* Product ID */
197 /* strcpy(WOutDev[0].caps.szPname, "OpenSoundSystem WAVOUT Driver");*/
198 strcpy(WOutDev[0].caps.szPname, "CS4236/37/38");
199 #endif
200 WOutDev[0].caps.vDriverVersion = 0x0100;
201 WOutDev[0].caps.dwFormats = 0x00000000;
202 WOutDev[0].caps.dwSupport = WAVECAPS_VOLUME;
204 IOCTL(audio, SNDCTL_DSP_GETFMTS, mask);
205 TRACE("OSS dsp out mask=%08x\n", mask);
207 /* First bytespersampl, then stereo */
208 bytespersmpl = (IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize) != 0) ? 1 : 2;
210 WOutDev[0].caps.wChannels = (IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo) != 0) ? 1 : 2;
211 if (WOutDev[0].caps.wChannels > 1) WOutDev[0].caps.dwSupport |= WAVECAPS_LRVOLUME;
213 smplrate = 44100;
214 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
215 if (mask & AFMT_U8) {
216 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_4M08;
217 if (WOutDev[0].caps.wChannels > 1)
218 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_4S08;
220 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
221 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_4M16;
222 if (WOutDev[0].caps.wChannels > 1)
223 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_4S16;
226 smplrate = 22050;
227 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
228 if (mask & AFMT_U8) {
229 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_2M08;
230 if (WOutDev[0].caps.wChannels > 1)
231 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_2S08;
233 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
234 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_2M16;
235 if (WOutDev[0].caps.wChannels > 1)
236 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_2S16;
239 smplrate = 11025;
240 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
241 if (mask & AFMT_U8) {
242 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_1M08;
243 if (WOutDev[0].caps.wChannels > 1)
244 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_1S08;
246 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
247 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_1M16;
248 if (WOutDev[0].caps.wChannels > 1)
249 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_1S16;
252 if (IOCTL(audio, SNDCTL_DSP_GETCAPS, caps) == 0) {
253 TRACE("OSS dsp out caps=%08X\n", caps);
254 if ((caps & DSP_CAP_REALTIME) && !(caps & DSP_CAP_BATCH)) {
255 WOutDev[0].caps.dwSupport |= WAVECAPS_SAMPLEACCURATE;
257 /* well, might as well use the DirectSound cap flag for something */
258 if ((caps & DSP_CAP_TRIGGER) && (caps & DSP_CAP_MMAP) &&
259 !(caps & DSP_CAP_BATCH))
260 WOutDev[0].caps.dwSupport |= WAVECAPS_DIRECTSOUND;
262 close(audio);
263 TRACE("out dwFormats = %08lX, dwSupport = %08lX\n",
264 WOutDev[0].caps.dwFormats, WOutDev[0].caps.dwSupport);
266 /* then do input device */
267 samplesize = 16;
268 dsp_stereo = 1;
270 for (i = 0; i < MAX_WAVEINDRV; ++i)
272 WInDev[i].unixdev = -1;
275 memset(&WInDev[0].caps, 0, sizeof(WInDev[0].caps));
277 if (access(SOUND_DEV,0) != 0 ||
278 (audio = open(SOUND_DEV, O_RDONLY|O_NDELAY, 0)) == -1) {
279 WARN("Couldn't open in %s (%s)\n", SOUND_DEV, strerror(errno));
280 return -1;
283 ioctl(audio, SNDCTL_DSP_RESET, 0);
285 #ifdef EMULATE_SB16
286 WInDev[0].caps.wMid = 0x0002;
287 WInDev[0].caps.wPid = 0x0004;
288 strcpy(WInDev[0].caps.szPname, "SB16 Wave In");
289 #else
290 WInDev[0].caps.wMid = 0x00FF; /* Manufac ID */
291 WInDev[0].caps.wPid = 0x0001; /* Product ID */
292 strcpy(WInDev[0].caps.szPname, "OpenSoundSystem WAVIN Driver");
293 #endif
294 WInDev[0].caps.dwFormats = 0x00000000;
295 WInDev[0].caps.wChannels = (IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo) != 0) ? 1 : 2;
297 WInDev[0].bTriggerSupport = FALSE;
298 if (IOCTL(audio, SNDCTL_DSP_GETCAPS, caps) == 0) {
299 TRACE("OSS dsp in caps=%08X\n", caps);
300 if (caps & DSP_CAP_TRIGGER)
301 WInDev[0].bTriggerSupport = TRUE;
304 IOCTL(audio, SNDCTL_DSP_GETFMTS, mask);
305 TRACE("OSS in dsp mask=%08x\n", mask);
307 bytespersmpl = (IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize) != 0) ? 1 : 2;
308 smplrate = 44100;
309 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
310 if (mask & AFMT_U8) {
311 WInDev[0].caps.dwFormats |= WAVE_FORMAT_4M08;
312 if (WInDev[0].caps.wChannels > 1)
313 WInDev[0].caps.dwFormats |= WAVE_FORMAT_4S08;
315 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
316 WInDev[0].caps.dwFormats |= WAVE_FORMAT_4M16;
317 if (WInDev[0].caps.wChannels > 1)
318 WInDev[0].caps.dwFormats |= WAVE_FORMAT_4S16;
321 smplrate = 22050;
322 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
323 if (mask & AFMT_U8) {
324 WInDev[0].caps.dwFormats |= WAVE_FORMAT_2M08;
325 if (WInDev[0].caps.wChannels > 1)
326 WInDev[0].caps.dwFormats |= WAVE_FORMAT_2S08;
328 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
329 WInDev[0].caps.dwFormats |= WAVE_FORMAT_2M16;
330 if (WInDev[0].caps.wChannels > 1)
331 WInDev[0].caps.dwFormats |= WAVE_FORMAT_2S16;
334 smplrate = 11025;
335 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
336 if (mask & AFMT_U8) {
337 WInDev[0].caps.dwFormats |= WAVE_FORMAT_1M08;
338 if (WInDev[0].caps.wChannels > 1)
339 WInDev[0].caps.dwFormats |= WAVE_FORMAT_1S08;
341 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
342 WInDev[0].caps.dwFormats |= WAVE_FORMAT_1M16;
343 if (WInDev[0].caps.wChannels > 1)
344 WInDev[0].caps.dwFormats |= WAVE_FORMAT_1S16;
347 close(audio);
348 TRACE("in dwFormats = %08lX\n", WInDev[0].caps.dwFormats);
350 return 0;
353 /**************************************************************************
354 * OSS_NotifyClient [internal]
356 static DWORD OSS_NotifyClient(UINT wDevID, WORD wMsg, DWORD dwParam1,
357 DWORD dwParam2)
359 TRACE("wDevID = %04X wMsg = %d dwParm1 = %04lX dwParam2 = %04lX\n",wDevID, wMsg, dwParam1, dwParam2);
361 switch (wMsg) {
362 case WOM_OPEN:
363 case WOM_CLOSE:
364 case WOM_DONE:
365 if (wDevID >= MAX_WAVEOUTDRV) return MCIERR_INTERNAL;
367 if (WOutDev[wDevID].wFlags != DCB_NULL &&
368 !DriverCallback(WOutDev[wDevID].waveDesc.dwCallback,
369 WOutDev[wDevID].wFlags,
370 WOutDev[wDevID].waveDesc.hWave,
371 wMsg,
372 WOutDev[wDevID].waveDesc.dwInstance,
373 dwParam1,
374 dwParam2)) {
375 WARN("can't notify client !\n");
376 return MMSYSERR_NOERROR;
378 break;
380 case WIM_OPEN:
381 case WIM_CLOSE:
382 case WIM_DATA:
383 if (wDevID >= MAX_WAVEINDRV) return MCIERR_INTERNAL;
385 if (WInDev[wDevID].wFlags != DCB_NULL &&
386 !DriverCallback(WInDev[wDevID].waveDesc.dwCallback,
387 WInDev[wDevID].wFlags,
388 WInDev[wDevID].waveDesc.hWave,
389 wMsg,
390 WInDev[wDevID].waveDesc.dwInstance,
391 dwParam1,
392 dwParam2)) {
393 WARN("can't notify client !\n");
394 return MMSYSERR_NOERROR;
396 break;
397 default:
398 FIXME("Unknown CB message %u\n", wMsg);
399 break;
401 return 0;
404 /*======================================================================*
405 * Low level WAVE OUT implementation *
406 *======================================================================*/
408 /**************************************************************************
409 * wodPlayer_WriteFragments [internal]
411 * wodPlayer helper. Writes as many fragments as it can to unixdev.
412 * Returns TRUE in case of buffer underrun.
414 static BOOL wodPlayer_WriteFragments(WINE_WAVEOUT* wwo)
416 LPWAVEHDR lpWaveHdr;
417 LPBYTE lpData;
418 int count;
419 audio_buf_info info;
421 for (;;) {
422 if (ioctl(wwo->unixdev, SNDCTL_DSP_GETOSPACE, &info) < 0) {
423 ERR("ioctl failed (%s)\n", strerror(errno));
424 return FALSE;
427 TRACE("info={frag=%d fsize=%d ftotal=%d bytes=%d}\n", info.fragments, info.fragsize, info.fragstotal, info.bytes);
429 if (!info.fragments) /* output queue is full, wait a bit */
430 return FALSE;
432 lpWaveHdr = wwo->lpPlayPtr;
433 if (!lpWaveHdr) {
434 if (wwo->dwRemain > 0 && /* still data to send to complete current fragment */
435 wwo->dwLastFragDone && /* first fragment has been played */
436 info.fragments + 2 > info.fragstotal) { /* done with all waveOutWrite()' fragments */
437 /* FIXME: should do better handling here */
438 WARN("Oooch, buffer underrun !\n");
439 return TRUE; /* force resetting of waveOut device */
441 return FALSE; /* wait a bit */
444 if (wwo->dwOffCurrHdr == 0) {
445 TRACE("Starting a new wavehdr %p of %ld bytes\n", lpWaveHdr, lpWaveHdr->dwBufferLength);
446 if (lpWaveHdr->dwFlags & WHDR_BEGINLOOP) {
447 if (wwo->lpLoopPtr) {
448 WARN("Already in a loop. Discarding loop on this header (%p)\n", lpWaveHdr);
449 } else {
450 wwo->lpLoopPtr = lpWaveHdr;
455 lpData = lpWaveHdr->lpData;
457 /* finish current wave hdr ? */
458 if (wwo->dwOffCurrHdr + wwo->dwRemain >= lpWaveHdr->dwBufferLength) {
459 DWORD toWrite = lpWaveHdr->dwBufferLength - wwo->dwOffCurrHdr;
461 /* write end of current wave hdr */
462 count = write(wwo->unixdev, lpData + wwo->dwOffCurrHdr, toWrite);
463 TRACE("write(%p[%5lu], %5lu) => %d\n", lpData, wwo->dwOffCurrHdr, toWrite, count);
465 if (count > 0 || toWrite == 0) {
466 DWORD tc = GetTickCount();
468 if (wwo->dwLastFragDone /* + guard time ?? */ < tc)
469 wwo->dwLastFragDone = tc;
470 wwo->dwLastFragDone += (toWrite * 1000) / wwo->format.wf.nAvgBytesPerSec;
472 lpWaveHdr->reserved = wwo->dwLastFragDone;
473 TRACE("Tagging hdr %p with %08lx\n", lpWaveHdr, wwo->dwLastFragDone);
475 /* WAVEHDR written, go to next one */
476 if ((lpWaveHdr->dwFlags & WHDR_ENDLOOP) && wwo->lpLoopPtr) {
477 if (--wwo->lpLoopPtr->dwLoops > 0) {
478 wwo->lpPlayPtr = wwo->lpLoopPtr;
479 } else {
480 /* last one played */
481 if (wwo->lpLoopPtr != lpWaveHdr && (lpWaveHdr->dwFlags & WHDR_BEGINLOOP)) {
482 FIXME("Correctly handled case ? (ending loop buffer also starts a new loop)\n");
483 /* shall we consider the END flag for the closing loop or for
484 * the opening one or for both ???
485 * code assumes for closing loop only
487 wwo->lpLoopPtr = lpWaveHdr;
488 } else {
489 wwo->lpLoopPtr = NULL;
491 wwo->lpPlayPtr = lpWaveHdr->lpNext;
493 } else {
494 wwo->lpPlayPtr = lpWaveHdr->lpNext;
496 wwo->dwOffCurrHdr = 0;
497 if ((wwo->dwRemain -= count) == 0) {
498 wwo->dwRemain = wwo->dwFragmentSize;
501 continue; /* try to go to use next wavehdr */
502 } else {
503 count = write(wwo->unixdev, lpData + wwo->dwOffCurrHdr, wwo->dwRemain);
504 TRACE("write(%p[%5lu], %5lu) => %d\n", lpData, wwo->dwOffCurrHdr, wwo->dwRemain, count);
505 if (count > 0) {
506 DWORD tc = GetTickCount();
508 if (wwo->dwLastFragDone /* + guard time ?? */ < tc)
509 wwo->dwLastFragDone = tc;
510 wwo->dwLastFragDone += (wwo->dwRemain * 1000) / wwo->format.wf.nAvgBytesPerSec;
512 TRACE("Tagging frag with %08lx\n", wwo->dwLastFragDone);
514 wwo->dwOffCurrHdr += count;
515 wwo->dwRemain = wwo->dwFragmentSize;
522 int wodPlayer_Message(WINE_WAVEOUT *wwo, int msg, DWORD param)
524 EnterCriticalSection(&wwo->msg_crst);
525 if ((wwo->msg_tosave == wwo->msg_toget) /* buffer overflow ? */
526 && (wwo->messages[wwo->msg_toget].msg))
528 ERR("buffer overflow !?\n");
529 LeaveCriticalSection(&wwo->msg_crst);
530 return 0;
533 wwo->messages[wwo->msg_tosave].msg = msg;
534 wwo->messages[wwo->msg_tosave].param = param;
535 wwo->msg_tosave++;
536 if (wwo->msg_tosave > WWO_RING_BUFFER_SIZE-1)
537 wwo->msg_tosave = 0;
538 LeaveCriticalSection(&wwo->msg_crst);
539 /* signal a new message */
540 SetEvent(wwo->msg_event);
541 return 1;
544 int wodPlayer_RetrieveMessage(WINE_WAVEOUT *wwo, int *msg, DWORD *param)
546 EnterCriticalSection(&wwo->msg_crst);
548 if (wwo->msg_toget == wwo->msg_tosave) /* buffer empty ? */
550 LeaveCriticalSection(&wwo->msg_crst);
551 return 0;
554 *msg = wwo->messages[wwo->msg_toget].msg;
555 wwo->messages[wwo->msg_toget].msg = 0;
556 *param = wwo->messages[wwo->msg_toget].param;
557 wwo->msg_toget++;
558 if (wwo->msg_toget > WWO_RING_BUFFER_SIZE-1)
559 wwo->msg_toget = 0;
560 LeaveCriticalSection(&wwo->msg_crst);
561 return 1;
564 /**************************************************************************
565 * wodPlayer_Notify [internal]
567 * wodPlayer helper. Notifies (and remove from queue) all the wavehdr which content
568 * have been played (actually to speaker, not to unixdev fd).
570 static void wodPlayer_Notify(WINE_WAVEOUT* wwo, WORD uDevID, BOOL force)
572 LPWAVEHDR lpWaveHdr;
573 DWORD tc = GetTickCount();
575 while (wwo->lpQueuePtr &&
576 (force ||
577 (wwo->lpQueuePtr != wwo->lpPlayPtr && wwo->lpQueuePtr != wwo->lpLoopPtr))) {
578 lpWaveHdr = wwo->lpQueuePtr;
580 if (lpWaveHdr->reserved > tc && !force) break;
582 wwo->dwPlayedTotal += lpWaveHdr->dwBufferLength;
583 wwo->lpQueuePtr = lpWaveHdr->lpNext;
585 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
586 lpWaveHdr->dwFlags |= WHDR_DONE;
588 TRACE("Notifying client with %p\n", lpWaveHdr);
589 if (OSS_NotifyClient(uDevID, WOM_DONE, (DWORD)lpWaveHdr, 0) != MMSYSERR_NOERROR) {
590 WARN("can't notify client !\n");
595 /**************************************************************************
596 * wodPlayer_Reset [internal]
598 * wodPlayer helper. Resets current output stream.
600 static void wodPlayer_Reset(WINE_WAVEOUT* wwo, WORD uDevID, BOOL reset)
602 /* updates current notify list */
603 wodPlayer_Notify(wwo, uDevID, FALSE);
605 /* flush all possible output */
606 if (ioctl(wwo->unixdev, SNDCTL_DSP_RESET, 0) == -1) {
607 perror("ioctl SNDCTL_DSP_RESET");
608 wwo->hThread = 0;
609 wwo->state = WINE_WS_STOPPED;
610 ExitThread(-1);
613 wwo->dwOffCurrHdr = 0;
614 wwo->dwRemain = wwo->dwFragmentSize;
615 if (reset) {
616 /* empty notify list */
617 wodPlayer_Notify(wwo, uDevID, TRUE);
619 wwo->lpPlayPtr = wwo->lpQueuePtr = wwo->lpLoopPtr = NULL;
620 wwo->state = WINE_WS_STOPPED;
621 wwo->dwPlayedTotal = 0;
622 } else {
623 /* FIXME: this is not accurate when looping, but can be do better ? */
624 wwo->lpPlayPtr = (wwo->lpLoopPtr) ? wwo->lpLoopPtr : wwo->lpQueuePtr;
625 wwo->state = WINE_WS_PAUSED;
629 /**************************************************************************
630 * wodPlayer [internal]
632 static DWORD CALLBACK wodPlayer(LPVOID pmt)
634 WORD uDevID = (DWORD)pmt;
635 WINE_WAVEOUT* wwo = (WINE_WAVEOUT*)&WOutDev[uDevID];
636 WAVEHDR* lpWaveHdr;
637 DWORD dwSleepTime;
638 int msg;
639 DWORD param;
640 DWORD tc;
642 wwo->state = WINE_WS_STOPPED;
644 wwo->dwLastFragDone = 0;
645 wwo->dwOffCurrHdr = 0;
646 wwo->dwRemain = wwo->dwFragmentSize;
647 wwo->lpQueuePtr = wwo->lpPlayPtr = wwo->lpLoopPtr = NULL;
648 wwo->dwPlayedTotal = 0;
650 TRACE("imhere[0]\n");
651 SetEvent(wwo->hEvent);
653 for (;;) {
654 /* wait for dwSleepTime or an event in thread's queue
655 * FIXME:
656 * - is wait time calculation optimal ?
657 * - these 100 ms parts should be changed, but Eric reports
658 * that the wodPlayer thread might lock up if we use INFINITE
659 * (strange !), so I better don't change that now... */
660 if (wwo->state != WINE_WS_PLAYING)
661 dwSleepTime = 100;
662 else
664 tc = GetTickCount();
665 if (tc < wwo->dwLastFragDone)
667 /* calculate sleep time depending on when the last fragment
668 will be played */
669 dwSleepTime = (wwo->dwLastFragDone - tc)*7/10;
670 if (dwSleepTime > 100)
671 dwSleepTime = 100;
673 else
674 dwSleepTime = 0;
677 TRACE("imhere[1]\n");
678 if (dwSleepTime)
679 WaitForSingleObject(wwo->msg_event, dwSleepTime);
680 TRACE("imhere[2] (q=%p p=%p)\n", wwo->lpQueuePtr, wwo->lpPlayPtr);
681 while (wodPlayer_RetrieveMessage(wwo, &msg, &param)) {
682 switch (msg) {
683 case WINE_WM_PAUSING:
684 wodPlayer_Reset(wwo, uDevID, FALSE);
685 wwo->state = WINE_WS_PAUSED;
686 SetEvent(wwo->hEvent);
687 break;
688 case WINE_WM_RESTARTING:
689 wwo->state = WINE_WS_PLAYING;
690 SetEvent(wwo->hEvent);
691 break;
692 case WINE_WM_HEADER:
693 lpWaveHdr = (LPWAVEHDR)param;
695 /* insert buffer at the end of queue */
697 LPWAVEHDR* wh;
698 for (wh = &(wwo->lpQueuePtr); *wh; wh = &((*wh)->lpNext));
699 *wh = lpWaveHdr;
701 if (!wwo->lpPlayPtr) wwo->lpPlayPtr = lpWaveHdr;
702 if (wwo->state == WINE_WS_STOPPED)
703 wwo->state = WINE_WS_PLAYING;
704 break;
705 case WINE_WM_RESETTING:
706 wodPlayer_Reset(wwo, uDevID, TRUE);
707 SetEvent(wwo->hEvent);
708 break;
709 case WINE_WM_CLOSING:
710 /* sanity check: this should not happen since the device must have been reset before */
711 if (wwo->lpQueuePtr || wwo->lpPlayPtr) ERR("out of sync\n");
712 wwo->hThread = 0;
713 wwo->state = WINE_WS_CLOSED;
714 SetEvent(wwo->hEvent);
715 ExitThread(0);
716 /* shouldn't go here */
717 default:
718 FIXME("unknown message %d\n", msg);
719 break;
722 if (wwo->state == WINE_WS_PLAYING) {
723 wodPlayer_WriteFragments(wwo);
725 wodPlayer_Notify(wwo, uDevID, FALSE);
727 ExitThread(0);
728 /* just for not generating compilation warnings... should never be executed */
729 return 0;
732 /**************************************************************************
733 * wodGetDevCaps [internal]
735 static DWORD wodGetDevCaps(WORD wDevID, LPWAVEOUTCAPSA lpCaps, DWORD dwSize)
737 TRACE("(%u, %p, %lu);\n", wDevID, lpCaps, dwSize);
739 if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
741 if (wDevID >= MAX_WAVEOUTDRV) {
742 TRACE("MAX_WAVOUTDRV reached !\n");
743 return MMSYSERR_BADDEVICEID;
746 memcpy(lpCaps, &WOutDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
747 return MMSYSERR_NOERROR;
750 /**************************************************************************
751 * wodOpen [internal]
753 static DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
755 int audio;
756 int format;
757 int sample_rate;
758 int dsp_stereo;
759 int fragment_size;
760 int audio_fragment;
761 WINE_WAVEOUT* wwo;
763 TRACE("(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
764 if (lpDesc == NULL) {
765 WARN("Invalid Parameter !\n");
766 return MMSYSERR_INVALPARAM;
768 if (wDevID >= MAX_WAVEOUTDRV) {
769 TRACE("MAX_WAVOUTDRV reached !\n");
770 return MMSYSERR_BADDEVICEID;
773 /* only PCM format is supported so far... */
774 if (lpDesc->lpFormat->wFormatTag != WAVE_FORMAT_PCM ||
775 lpDesc->lpFormat->nChannels == 0 ||
776 lpDesc->lpFormat->nSamplesPerSec == 0) {
777 WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
778 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
779 lpDesc->lpFormat->nSamplesPerSec);
780 return WAVERR_BADFORMAT;
783 if (dwFlags & WAVE_FORMAT_QUERY) {
784 TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
785 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
786 lpDesc->lpFormat->nSamplesPerSec);
787 return MMSYSERR_NOERROR;
790 wwo = &WOutDev[wDevID];
792 if ((dwFlags & WAVE_DIRECTSOUND) && !(wwo->caps.dwSupport & WAVECAPS_DIRECTSOUND))
793 /* not supported, ignore it */
794 dwFlags &= ~WAVE_DIRECTSOUND;
796 if (access(SOUND_DEV, 0) != 0)
797 return MMSYSERR_NOTENABLED;
798 if (dwFlags & WAVE_DIRECTSOUND)
799 /* we want to be able to mmap() the device, which means it must be opened readable,
800 * otherwise mmap() will fail (at least under Linux) */
801 audio = open(SOUND_DEV, O_RDWR|O_NDELAY, 0);
802 else
803 audio = open(SOUND_DEV, O_WRONLY|O_NDELAY, 0);
804 if (audio == -1) {
805 WARN("can't open sound device %s (%s)!\n", SOUND_DEV, strerror(errno));
806 return MMSYSERR_ALLOCATED;
808 fcntl(audio, F_SETFD, 1); /* set close on exec flag */
809 wwo->unixdev = audio;
810 wwo->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
812 memcpy(&wwo->waveDesc, lpDesc, sizeof(WAVEOPENDESC));
813 memcpy(&wwo->format, lpDesc->lpFormat, sizeof(PCMWAVEFORMAT));
815 if (wwo->format.wBitsPerSample == 0) {
816 WARN("Resetting zeroed wBitsPerSample\n");
817 wwo->format.wBitsPerSample = 8 *
818 (wwo->format.wf.nAvgBytesPerSec /
819 wwo->format.wf.nSamplesPerSec) /
820 wwo->format.wf.nChannels;
823 if (dwFlags & WAVE_DIRECTSOUND) {
824 if (wwo->caps.dwSupport & WAVECAPS_SAMPLEACCURATE)
825 /* we have realtime DirectSound, fragments just waste our time,
826 * but a large buffer is good, so choose 64KB (32 * 2^11) */
827 audio_fragment = 0x0020000B;
828 else
829 /* to approximate realtime, we must use small fragments,
830 * let's try to fragment the above 64KB (256 * 2^8) */
831 audio_fragment = 0x01000008;
832 } else {
833 /* shockwave player uses only 4 1k-fragments at a rate of 22050 bytes/sec
834 * thus leading to 46ms per fragment, and a turnaround time of 185ms
836 /* 16 fragments max, 2^10=1024 bytes per fragment */
837 audio_fragment = 0x000F000A;
839 sample_rate = wwo->format.wf.nSamplesPerSec;
840 dsp_stereo = (wwo->format.wf.nChannels > 1) ? 1 : 0;
841 format = (wwo->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8;
843 IOCTL(audio, SNDCTL_DSP_SETFRAGMENT, audio_fragment);
844 /* First size and stereo then samplerate */
845 IOCTL(audio, SNDCTL_DSP_SETFMT, format);
846 IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo);
847 IOCTL(audio, SNDCTL_DSP_SPEED, sample_rate);
849 /* paranoid checks */
850 if (format != ((wwo->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8))
851 ERR("Can't set format to %d (%d)\n",
852 (wwo->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8, format);
853 if (dsp_stereo != (wwo->format.wf.nChannels > 1) ? 1 : 0)
854 ERR("Can't set stereo to %u (%d)\n",
855 (wwo->format.wf.nChannels > 1) ? 1 : 0, dsp_stereo);
856 if (!NEAR_MATCH(sample_rate,wwo->format.wf.nSamplesPerSec))
857 ERR("Can't set sample_rate to %lu (%d)\n",
858 wwo->format.wf.nSamplesPerSec, sample_rate);
860 /* even if we set fragment size above, read it again, just in case */
861 IOCTL(audio, SNDCTL_DSP_GETBLKSIZE, fragment_size);
862 if (fragment_size == -1) {
863 WARN("IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n");
864 close(audio);
865 wwo->unixdev = -1;
866 return MMSYSERR_NOTENABLED;
868 wwo->dwFragmentSize = fragment_size;
870 wwo->msg_toget = 0;
871 wwo->msg_tosave = 0;
872 wwo->msg_event = CreateEventA(NULL, FALSE, FALSE, NULL);
873 memset(wwo->messages, 0, sizeof(WWO_MSG)*WWO_RING_BUFFER_SIZE);
874 InitializeCriticalSection(&wwo->msg_crst);
876 if (!(dwFlags & WAVE_DIRECTSOUND)) {
877 wwo->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
878 wwo->hThread = CreateThread(NULL, 0, wodPlayer, (LPVOID)(DWORD)wDevID, 0, &(wwo->dwThreadID));
879 WaitForSingleObject(wwo->hEvent, INFINITE);
880 } else {
881 wwo->hEvent = INVALID_HANDLE_VALUE;
882 wwo->hThread = INVALID_HANDLE_VALUE;
883 wwo->dwThreadID = 0;
886 TRACE("fd=%d fragmentSize=%ld\n",
887 wwo->unixdev, wwo->dwFragmentSize);
888 if (wwo->dwFragmentSize % wwo->format.wf.nBlockAlign)
889 ERR("Fragment doesn't contain an integral number of data blocks\n");
891 TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
892 wwo->format.wBitsPerSample, wwo->format.wf.nAvgBytesPerSec,
893 wwo->format.wf.nSamplesPerSec, wwo->format.wf.nChannels,
894 wwo->format.wf.nBlockAlign);
896 if (OSS_NotifyClient(wDevID, WOM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
897 WARN("can't notify client !\n");
898 return MMSYSERR_INVALPARAM;
900 return MMSYSERR_NOERROR;
903 /**************************************************************************
904 * wodClose [internal]
906 static DWORD wodClose(WORD wDevID)
908 DWORD ret = MMSYSERR_NOERROR;
909 WINE_WAVEOUT* wwo;
911 TRACE("(%u);\n", wDevID);
913 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
914 WARN("bad device ID !\n");
915 return MMSYSERR_BADDEVICEID;
918 wwo = &WOutDev[wDevID];
919 if (wwo->lpQueuePtr) {
920 WARN("buffers still playing !\n");
921 ret = WAVERR_STILLPLAYING;
922 } else {
923 TRACE("imhere[3-close]\n");
924 if (wwo->hEvent != INVALID_HANDLE_VALUE) {
925 wodPlayer_Message(wwo, WINE_WM_CLOSING, 0);
926 WaitForSingleObject(wwo->hEvent, INFINITE);
927 CloseHandle(wwo->hEvent);
929 if (wwo->mapping) {
930 munmap(wwo->mapping, wwo->maplen);
931 wwo->mapping = NULL;
934 close(wwo->unixdev);
935 wwo->unixdev = -1;
936 wwo->dwFragmentSize = 0;
937 if (OSS_NotifyClient(wDevID, WOM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
938 WARN("can't notify client !\n");
939 ret = MMSYSERR_INVALPARAM;
942 return ret;
945 /**************************************************************************
946 * wodWrite [internal]
949 static DWORD wodWrite(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
951 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
953 /* first, do the sanity checks... */
954 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
955 WARN("bad dev ID !\n");
956 return MMSYSERR_BADDEVICEID;
959 if (lpWaveHdr->lpData == NULL || !(lpWaveHdr->dwFlags & WHDR_PREPARED))
960 return WAVERR_UNPREPARED;
962 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
963 return WAVERR_STILLPLAYING;
965 lpWaveHdr->dwFlags &= ~WHDR_DONE;
966 lpWaveHdr->dwFlags |= WHDR_INQUEUE;
967 lpWaveHdr->lpNext = 0;
969 TRACE("imhere[3-HEADER]\n");
970 wodPlayer_Message(&WOutDev[wDevID], WINE_WM_HEADER, (DWORD)lpWaveHdr);
972 return MMSYSERR_NOERROR;
975 /**************************************************************************
976 * wodPrepare [internal]
978 static DWORD wodPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
980 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
982 if (wDevID >= MAX_WAVEOUTDRV) {
983 WARN("bad device ID !\n");
984 return MMSYSERR_BADDEVICEID;
987 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
988 return WAVERR_STILLPLAYING;
990 lpWaveHdr->dwFlags |= WHDR_PREPARED;
991 lpWaveHdr->dwFlags &= ~WHDR_DONE;
992 return MMSYSERR_NOERROR;
995 /**************************************************************************
996 * wodUnprepare [internal]
998 static DWORD wodUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
1000 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
1002 if (wDevID >= MAX_WAVEOUTDRV) {
1003 WARN("bad device ID !\n");
1004 return MMSYSERR_BADDEVICEID;
1007 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
1008 return WAVERR_STILLPLAYING;
1010 lpWaveHdr->dwFlags &= ~WHDR_PREPARED;
1011 lpWaveHdr->dwFlags |= WHDR_DONE;
1013 return MMSYSERR_NOERROR;
1016 /**************************************************************************
1017 * wodPause [internal]
1019 static DWORD wodPause(WORD wDevID)
1021 TRACE("(%u);!\n", wDevID);
1023 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1024 WARN("bad device ID !\n");
1025 return MMSYSERR_BADDEVICEID;
1028 TRACE("imhere[3-PAUSING]\n");
1029 wodPlayer_Message(&WOutDev[wDevID], WINE_WM_PAUSING, 0);
1030 WaitForSingleObject(WOutDev[wDevID].hEvent, INFINITE);
1032 return MMSYSERR_NOERROR;
1035 /**************************************************************************
1036 * wodRestart [internal]
1038 static DWORD wodRestart(WORD wDevID)
1040 TRACE("(%u);\n", wDevID);
1042 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1043 WARN("bad device ID !\n");
1044 return MMSYSERR_BADDEVICEID;
1047 if (WOutDev[wDevID].state == WINE_WS_PAUSED) {
1048 TRACE("imhere[3-RESTARTING]\n");
1049 wodPlayer_Message(&WOutDev[wDevID], WINE_WM_RESTARTING, 0);
1050 WaitForSingleObject(WOutDev[wDevID].hEvent, INFINITE);
1053 /* FIXME: is NotifyClient with WOM_DONE right ? (Comet Busters 1.3.3 needs this notification) */
1054 /* FIXME: Myst crashes with this ... hmm -MM
1055 if (OSS_NotifyClient(wDevID, WOM_DONE, 0L, 0L) != MMSYSERR_NOERROR) {
1056 WARN("can't notify client !\n");
1057 return MMSYSERR_INVALPARAM;
1061 return MMSYSERR_NOERROR;
1064 /**************************************************************************
1065 * wodReset [internal]
1067 static DWORD wodReset(WORD wDevID)
1069 TRACE("(%u);\n", wDevID);
1071 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1072 WARN("bad device ID !\n");
1073 return MMSYSERR_BADDEVICEID;
1076 TRACE("imhere[3-RESET]\n");
1077 wodPlayer_Message(&WOutDev[wDevID], WINE_WM_RESETTING, 0);
1078 WaitForSingleObject(WOutDev[wDevID].hEvent, INFINITE);
1080 return MMSYSERR_NOERROR;
1084 /**************************************************************************
1085 * wodGetPosition [internal]
1087 static DWORD wodGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
1089 int time;
1090 DWORD val;
1091 WINE_WAVEOUT* wwo;
1093 TRACE("(%u, %p, %lu);\n", wDevID, lpTime, uSize);
1095 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1096 WARN("bad device ID !\n");
1097 return MMSYSERR_BADDEVICEID;
1100 if (lpTime == NULL) return MMSYSERR_INVALPARAM;
1102 wwo = &WOutDev[wDevID];
1103 val = wwo->dwPlayedTotal;
1105 TRACE("wType=%04X wBitsPerSample=%u nSamplesPerSec=%lu nChannels=%u nAvgBytesPerSec=%lu\n",
1106 lpTime->wType, wwo->format.wBitsPerSample,
1107 wwo->format.wf.nSamplesPerSec, wwo->format.wf.nChannels,
1108 wwo->format.wf.nAvgBytesPerSec);
1109 TRACE("dwTotalPlayed=%lu\n", val);
1111 switch (lpTime->wType) {
1112 case TIME_BYTES:
1113 lpTime->u.cb = val;
1114 TRACE("TIME_BYTES=%lu\n", lpTime->u.cb);
1115 break;
1116 case TIME_SAMPLES:
1117 lpTime->u.sample = val * 8 / wwo->format.wBitsPerSample;
1118 TRACE("TIME_SAMPLES=%lu\n", lpTime->u.sample);
1119 break;
1120 case TIME_SMPTE:
1121 time = val / (wwo->format.wf.nAvgBytesPerSec / 1000);
1122 lpTime->u.smpte.hour = time / 108000;
1123 time -= lpTime->u.smpte.hour * 108000;
1124 lpTime->u.smpte.min = time / 1800;
1125 time -= lpTime->u.smpte.min * 1800;
1126 lpTime->u.smpte.sec = time / 30;
1127 time -= lpTime->u.smpte.sec * 30;
1128 lpTime->u.smpte.frame = time;
1129 lpTime->u.smpte.fps = 30;
1130 TRACE("TIME_SMPTE=%02u:%02u:%02u:%02u\n",
1131 lpTime->u.smpte.hour, lpTime->u.smpte.min,
1132 lpTime->u.smpte.sec, lpTime->u.smpte.frame);
1133 break;
1134 default:
1135 FIXME("Format %d not supported ! use TIME_MS !\n", lpTime->wType);
1136 lpTime->wType = TIME_MS;
1137 case TIME_MS:
1138 lpTime->u.ms = val / (wwo->format.wf.nAvgBytesPerSec / 1000);
1139 TRACE("TIME_MS=%lu\n", lpTime->u.ms);
1140 break;
1142 return MMSYSERR_NOERROR;
1145 /**************************************************************************
1146 * wodGetVolume [internal]
1148 static DWORD wodGetVolume(WORD wDevID, LPDWORD lpdwVol)
1150 int mixer;
1151 int volume;
1152 DWORD left, right;
1154 TRACE("(%u, %p);\n", wDevID, lpdwVol);
1156 if (lpdwVol == NULL)
1157 return MMSYSERR_NOTENABLED;
1158 if ((mixer = open(MIXER_DEV, O_RDONLY|O_NDELAY)) < 0) {
1159 WARN("mixer device not available !\n");
1160 return MMSYSERR_NOTENABLED;
1162 if (ioctl(mixer, SOUND_MIXER_READ_PCM, &volume) == -1) {
1163 WARN("unable read mixer !\n");
1164 return MMSYSERR_NOTENABLED;
1166 close(mixer);
1167 left = LOBYTE(volume);
1168 right = HIBYTE(volume);
1169 TRACE("left=%ld right=%ld !\n", left, right);
1170 *lpdwVol = ((left * 0xFFFFl) / 100) + (((right * 0xFFFFl) / 100) << 16);
1171 return MMSYSERR_NOERROR;
1175 /**************************************************************************
1176 * wodSetVolume [internal]
1178 static DWORD wodSetVolume(WORD wDevID, DWORD dwParam)
1180 int mixer;
1181 int volume;
1182 DWORD left, right;
1184 TRACE("(%u, %08lX);\n", wDevID, dwParam);
1186 left = (LOWORD(dwParam) * 100) / 0xFFFFl;
1187 right = (HIWORD(dwParam) * 100) / 0xFFFFl;
1188 volume = left + (right << 8);
1190 if ((mixer = open(MIXER_DEV, O_WRONLY|O_NDELAY)) < 0) {
1191 WARN("mixer device not available !\n");
1192 return MMSYSERR_NOTENABLED;
1194 if (ioctl(mixer, SOUND_MIXER_WRITE_PCM, &volume) == -1) {
1195 WARN("unable set mixer !\n");
1196 return MMSYSERR_NOTENABLED;
1197 } else {
1198 TRACE("volume=%04x\n", (unsigned)volume);
1200 close(mixer);
1201 return MMSYSERR_NOERROR;
1204 /**************************************************************************
1205 * wodGetNumDevs [internal]
1207 static DWORD wodGetNumDevs(void)
1209 DWORD ret = 1;
1211 /* FIXME: For now, only one sound device (SOUND_DEV) is allowed */
1212 int audio = open(SOUND_DEV, O_WRONLY|O_NDELAY, 0);
1214 if (audio == -1) {
1215 if (errno != EBUSY)
1216 ret = 0;
1217 } else {
1218 close(audio);
1220 return ret;
1223 /**************************************************************************
1224 * OSS_wodMessage [sample driver]
1226 DWORD WINAPI OSS_wodMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
1227 DWORD dwParam1, DWORD dwParam2)
1229 TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
1230 wDevID, wMsg, dwUser, dwParam1, dwParam2);
1232 switch (wMsg) {
1233 case DRVM_INIT:
1234 case DRVM_EXIT:
1235 case DRVM_ENABLE:
1236 case DRVM_DISABLE:
1237 /* FIXME: Pretend this is supported */
1238 return 0;
1239 case WODM_OPEN: return wodOpen (wDevID, (LPWAVEOPENDESC)dwParam1, dwParam2);
1240 case WODM_CLOSE: return wodClose (wDevID);
1241 case WODM_WRITE: return wodWrite (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
1242 case WODM_PAUSE: return wodPause (wDevID);
1243 case WODM_GETPOS: return wodGetPosition (wDevID, (LPMMTIME)dwParam1, dwParam2);
1244 case WODM_BREAKLOOP: return MMSYSERR_NOTSUPPORTED;
1245 case WODM_PREPARE: return wodPrepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
1246 case WODM_UNPREPARE: return wodUnprepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
1247 case WODM_GETDEVCAPS: return wodGetDevCaps (wDevID, (LPWAVEOUTCAPSA)dwParam1, dwParam2);
1248 case WODM_GETNUMDEVS: return wodGetNumDevs ();
1249 case WODM_GETPITCH: return MMSYSERR_NOTSUPPORTED;
1250 case WODM_SETPITCH: return MMSYSERR_NOTSUPPORTED;
1251 case WODM_GETPLAYBACKRATE: return MMSYSERR_NOTSUPPORTED;
1252 case WODM_SETPLAYBACKRATE: return MMSYSERR_NOTSUPPORTED;
1253 case WODM_GETVOLUME: return wodGetVolume (wDevID, (LPDWORD)dwParam1);
1254 case WODM_SETVOLUME: return wodSetVolume (wDevID, dwParam1);
1255 case WODM_RESTART: return wodRestart (wDevID);
1256 case WODM_RESET: return wodReset (wDevID);
1257 case 0x810: return wodDsCreate(wDevID, (PIDSDRIVER*)dwParam1);
1258 default:
1259 FIXME("unknown message %d!\n", wMsg);
1261 return MMSYSERR_NOTSUPPORTED;
1264 /*======================================================================*
1265 * Low level DSOUND implementation *
1266 *======================================================================*/
1268 typedef struct IDsDriverImpl IDsDriverImpl;
1269 typedef struct IDsDriverBufferImpl IDsDriverBufferImpl;
1271 struct IDsDriverImpl
1273 /* IUnknown fields */
1274 ICOM_VFIELD(IDsDriver);
1275 DWORD ref;
1276 /* IDsDriverImpl fields */
1277 UINT wDevID;
1278 IDsDriverBufferImpl*primary;
1281 struct IDsDriverBufferImpl
1283 /* IUnknown fields */
1284 ICOM_VFIELD(IDsDriverBuffer);
1285 DWORD ref;
1286 /* IDsDriverBufferImpl fields */
1287 IDsDriverImpl* drv;
1288 DWORD buflen;
1291 static HRESULT DSDB_MapPrimary(IDsDriverBufferImpl *dsdb)
1293 WINE_WAVEOUT *wwo = &(WOutDev[dsdb->drv->wDevID]);
1294 if (!wwo->mapping) {
1295 wwo->mapping = mmap(NULL, wwo->maplen, PROT_WRITE, MAP_SHARED,
1296 wwo->unixdev, 0);
1297 if (wwo->mapping == (LPBYTE)-1) {
1298 ERR("(%p): Could not map sound device for direct access (errno=%d)\n", dsdb, errno);
1299 return DSERR_GENERIC;
1301 TRACE("(%p): sound device has been mapped for direct access at %p, size=%ld\n", dsdb, wwo->mapping, wwo->maplen);
1303 /* for some reason, es1371 and sblive! sometimes have junk in here. */
1304 memset(wwo->mapping,0,wwo->maplen); /* clear it, or we get junk noise */
1306 return DS_OK;
1309 static HRESULT DSDB_UnmapPrimary(IDsDriverBufferImpl *dsdb)
1311 WINE_WAVEOUT *wwo = &(WOutDev[dsdb->drv->wDevID]);
1312 if (wwo->mapping) {
1313 if (munmap(wwo->mapping, wwo->maplen) < 0) {
1314 ERR("(%p): Could not unmap sound device (errno=%d)\n", dsdb, errno);
1315 return DSERR_GENERIC;
1317 wwo->mapping = NULL;
1318 TRACE("(%p): sound device unmapped\n", dsdb);
1320 return DS_OK;
1323 static HRESULT WINAPI IDsDriverBufferImpl_QueryInterface(PIDSDRIVERBUFFER iface, REFIID riid, LPVOID *ppobj)
1325 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1326 FIXME("(): stub!\n");
1327 return DSERR_UNSUPPORTED;
1330 static ULONG WINAPI IDsDriverBufferImpl_AddRef(PIDSDRIVERBUFFER iface)
1332 ICOM_THIS(IDsDriverBufferImpl,iface);
1333 This->ref++;
1334 return This->ref;
1337 static ULONG WINAPI IDsDriverBufferImpl_Release(PIDSDRIVERBUFFER iface)
1339 ICOM_THIS(IDsDriverBufferImpl,iface);
1340 if (--This->ref)
1341 return This->ref;
1342 if (This == This->drv->primary)
1343 This->drv->primary = NULL;
1344 DSDB_UnmapPrimary(This);
1345 HeapFree(GetProcessHeap(),0,This);
1346 return 0;
1349 static HRESULT WINAPI IDsDriverBufferImpl_Lock(PIDSDRIVERBUFFER iface,
1350 LPVOID*ppvAudio1,LPDWORD pdwLen1,
1351 LPVOID*ppvAudio2,LPDWORD pdwLen2,
1352 DWORD dwWritePosition,DWORD dwWriteLen,
1353 DWORD dwFlags)
1355 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1356 /* since we (GetDriverDesc flags) have specified DSDDESC_DONTNEEDPRIMARYLOCK,
1357 * and that we don't support secondary buffers, this method will never be called */
1358 TRACE("(%p): stub\n",iface);
1359 return DSERR_UNSUPPORTED;
1362 static HRESULT WINAPI IDsDriverBufferImpl_Unlock(PIDSDRIVERBUFFER iface,
1363 LPVOID pvAudio1,DWORD dwLen1,
1364 LPVOID pvAudio2,DWORD dwLen2)
1366 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1367 TRACE("(%p): stub\n",iface);
1368 return DSERR_UNSUPPORTED;
1371 static HRESULT WINAPI IDsDriverBufferImpl_SetFormat(PIDSDRIVERBUFFER iface,
1372 LPWAVEFORMATEX pwfx)
1374 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1376 TRACE("(%p,%p)\n",iface,pwfx);
1377 /* On our request (GetDriverDesc flags), DirectSound has by now used
1378 * waveOutClose/waveOutOpen to set the format...
1379 * unfortunately, this means our mmap() is now gone...
1380 * so we need to somehow signal to our DirectSound implementation
1381 * that it should completely recreate this HW buffer...
1382 * this unexpected error code should do the trick... */
1383 return DSERR_BUFFERLOST;
1386 static HRESULT WINAPI IDsDriverBufferImpl_SetFrequency(PIDSDRIVERBUFFER iface, DWORD dwFreq)
1388 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1389 TRACE("(%p,%ld): stub\n",iface,dwFreq);
1390 return DSERR_UNSUPPORTED;
1393 static HRESULT WINAPI IDsDriverBufferImpl_SetVolumePan(PIDSDRIVERBUFFER iface, PDSVOLUMEPAN pVolPan)
1395 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1396 FIXME("(%p,%p): stub!\n",iface,pVolPan);
1397 return DSERR_UNSUPPORTED;
1400 static HRESULT WINAPI IDsDriverBufferImpl_SetPosition(PIDSDRIVERBUFFER iface, DWORD dwNewPos)
1402 /* ICOM_THIS(IDsDriverImpl,iface); */
1403 TRACE("(%p,%ld): stub\n",iface,dwNewPos);
1404 return DSERR_UNSUPPORTED;
1407 static HRESULT WINAPI IDsDriverBufferImpl_GetPosition(PIDSDRIVERBUFFER iface,
1408 LPDWORD lpdwPlay, LPDWORD lpdwWrite)
1410 ICOM_THIS(IDsDriverBufferImpl,iface);
1411 count_info info;
1412 DWORD ptr;
1414 TRACE("(%p)\n",iface);
1415 if (ioctl(WOutDev[This->drv->wDevID].unixdev, SNDCTL_DSP_GETOPTR, &info) < 0) {
1416 ERR("ioctl failed (%d)\n", errno);
1417 return DSERR_GENERIC;
1419 ptr = info.ptr & ~3; /* align the pointer, just in case */
1420 if (lpdwPlay) *lpdwPlay = ptr;
1421 if (lpdwWrite) {
1422 /* add some safety margin (not strictly necessary, but...) */
1423 if (WOutDev[This->drv->wDevID].caps.dwSupport & WAVECAPS_SAMPLEACCURATE)
1424 *lpdwWrite = ptr + 32;
1425 else
1426 *lpdwWrite = ptr + WOutDev[This->drv->wDevID].dwFragmentSize;
1427 while (*lpdwWrite > This->buflen)
1428 *lpdwWrite -= This->buflen;
1430 TRACE("playpos=%ld, writepos=%ld\n", lpdwPlay?*lpdwPlay:0, lpdwWrite?*lpdwWrite:0);
1431 return DS_OK;
1434 static HRESULT WINAPI IDsDriverBufferImpl_Play(PIDSDRIVERBUFFER iface, DWORD dwRes1, DWORD dwRes2, DWORD dwFlags)
1436 ICOM_THIS(IDsDriverBufferImpl,iface);
1437 int enable = PCM_ENABLE_OUTPUT;
1438 TRACE("(%p,%lx,%lx,%lx)\n",iface,dwRes1,dwRes2,dwFlags);
1439 if (ioctl(WOutDev[This->drv->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1440 ERR("ioctl failed (%d)\n", errno);
1441 return DSERR_GENERIC;
1443 return DS_OK;
1446 static HRESULT WINAPI IDsDriverBufferImpl_Stop(PIDSDRIVERBUFFER iface)
1448 ICOM_THIS(IDsDriverBufferImpl,iface);
1449 int enable = 0;
1450 TRACE("(%p)\n",iface);
1451 /* no more playing */
1452 if (ioctl(WOutDev[This->drv->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1453 ERR("ioctl failed (%d)\n", errno);
1454 return DSERR_GENERIC;
1456 #if 0
1457 /* the play position must be reset to the beginning of the buffer */
1458 if (ioctl(WOutDev[This->drv->wDevID].unixdev, SNDCTL_DSP_RESET, 0) < 0) {
1459 ERR("ioctl failed (%d)\n", errno);
1460 return DSERR_GENERIC;
1462 #endif
1463 return DS_OK;
1466 static ICOM_VTABLE(IDsDriverBuffer) dsdbvt =
1468 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1469 IDsDriverBufferImpl_QueryInterface,
1470 IDsDriverBufferImpl_AddRef,
1471 IDsDriverBufferImpl_Release,
1472 IDsDriverBufferImpl_Lock,
1473 IDsDriverBufferImpl_Unlock,
1474 IDsDriverBufferImpl_SetFormat,
1475 IDsDriverBufferImpl_SetFrequency,
1476 IDsDriverBufferImpl_SetVolumePan,
1477 IDsDriverBufferImpl_SetPosition,
1478 IDsDriverBufferImpl_GetPosition,
1479 IDsDriverBufferImpl_Play,
1480 IDsDriverBufferImpl_Stop
1483 static HRESULT WINAPI IDsDriverImpl_QueryInterface(PIDSDRIVER iface, REFIID riid, LPVOID *ppobj)
1485 /* ICOM_THIS(IDsDriverImpl,iface); */
1486 FIXME("(%p): stub!\n",iface);
1487 return DSERR_UNSUPPORTED;
1490 static ULONG WINAPI IDsDriverImpl_AddRef(PIDSDRIVER iface)
1492 ICOM_THIS(IDsDriverImpl,iface);
1493 This->ref++;
1494 return This->ref;
1497 static ULONG WINAPI IDsDriverImpl_Release(PIDSDRIVER iface)
1499 ICOM_THIS(IDsDriverImpl,iface);
1500 if (--This->ref)
1501 return This->ref;
1502 HeapFree(GetProcessHeap(),0,This);
1503 return 0;
1506 static HRESULT WINAPI IDsDriverImpl_GetDriverDesc(PIDSDRIVER iface, PDSDRIVERDESC pDesc)
1508 ICOM_THIS(IDsDriverImpl,iface);
1509 TRACE("(%p,%p)\n",iface,pDesc);
1510 pDesc->dwFlags = DSDDESC_DOMMSYSTEMOPEN | DSDDESC_DOMMSYSTEMSETFORMAT |
1511 DSDDESC_USESYSTEMMEMORY | DSDDESC_DONTNEEDPRIMARYLOCK;
1512 strcpy(pDesc->szDesc,"WineOSS DirectSound Driver");
1513 strcpy(pDesc->szDrvName,"wineoss.drv");
1514 pDesc->dnDevNode = WOutDev[This->wDevID].waveDesc.dnDevNode;
1515 pDesc->wVxdId = 0;
1516 pDesc->wReserved = 0;
1517 pDesc->ulDeviceNum = This->wDevID;
1518 pDesc->dwHeapType = DSDHEAP_NOHEAP;
1519 pDesc->pvDirectDrawHeap = NULL;
1520 pDesc->dwMemStartAddress = 0;
1521 pDesc->dwMemEndAddress = 0;
1522 pDesc->dwMemAllocExtra = 0;
1523 pDesc->pvReserved1 = NULL;
1524 pDesc->pvReserved2 = NULL;
1525 return DS_OK;
1528 static HRESULT WINAPI IDsDriverImpl_Open(PIDSDRIVER iface)
1530 ICOM_THIS(IDsDriverImpl,iface);
1531 int enable = 0;
1533 TRACE("(%p)\n",iface);
1534 /* make sure the card doesn't start playing before we want it to */
1535 if (ioctl(WOutDev[This->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1536 ERR("ioctl failed (%d)\n", errno);
1537 return DSERR_GENERIC;
1539 return DS_OK;
1542 static HRESULT WINAPI IDsDriverImpl_Close(PIDSDRIVER iface)
1544 ICOM_THIS(IDsDriverImpl,iface);
1545 TRACE("(%p)\n",iface);
1546 if (This->primary) {
1547 ERR("problem with DirectSound: primary not released\n");
1548 return DSERR_GENERIC;
1550 return DS_OK;
1553 static HRESULT WINAPI IDsDriverImpl_GetCaps(PIDSDRIVER iface, PDSDRIVERCAPS pCaps)
1555 /* ICOM_THIS(IDsDriverImpl,iface); */
1556 TRACE("(%p,%p)\n",iface,pCaps);
1557 memset(pCaps, 0, sizeof(*pCaps));
1558 /* FIXME: need to check actual capabilities */
1559 pCaps->dwFlags = DSCAPS_PRIMARYMONO | DSCAPS_PRIMARYSTEREO |
1560 DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARY16BIT;
1561 pCaps->dwPrimaryBuffers = 1;
1562 /* the other fields only apply to secondary buffers, which we don't support
1563 * (unless we want to mess with wavetable synthesizers and MIDI) */
1564 return DS_OK;
1567 static HRESULT WINAPI IDsDriverImpl_CreateSoundBuffer(PIDSDRIVER iface,
1568 LPWAVEFORMATEX pwfx,
1569 DWORD dwFlags, DWORD dwCardAddress,
1570 LPDWORD pdwcbBufferSize,
1571 LPBYTE *ppbBuffer,
1572 LPVOID *ppvObj)
1574 ICOM_THIS(IDsDriverImpl,iface);
1575 IDsDriverBufferImpl** ippdsdb = (IDsDriverBufferImpl**)ppvObj;
1576 HRESULT err;
1577 audio_buf_info info;
1578 int enable = 0;
1580 TRACE("(%p,%p,%lx,%lx)\n",iface,pwfx,dwFlags,dwCardAddress);
1581 /* we only support primary buffers */
1582 if (!(dwFlags & DSBCAPS_PRIMARYBUFFER))
1583 return DSERR_UNSUPPORTED;
1584 if (This->primary)
1585 return DSERR_ALLOCATED;
1586 if (dwFlags & (DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN))
1587 return DSERR_CONTROLUNAVAIL;
1589 *ippdsdb = (IDsDriverBufferImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDsDriverBufferImpl));
1590 if (*ippdsdb == NULL)
1591 return DSERR_OUTOFMEMORY;
1592 ICOM_VTBL(*ippdsdb) = &dsdbvt;
1593 (*ippdsdb)->ref = 1;
1594 (*ippdsdb)->drv = This;
1596 /* check how big the DMA buffer is now */
1597 if (ioctl(WOutDev[This->wDevID].unixdev, SNDCTL_DSP_GETOSPACE, &info) < 0) {
1598 ERR("ioctl failed (%d)\n", errno);
1599 HeapFree(GetProcessHeap(),0,*ippdsdb);
1600 *ippdsdb = NULL;
1601 return DSERR_GENERIC;
1603 WOutDev[This->wDevID].maplen = (*ippdsdb)->buflen = info.fragstotal * info.fragsize;
1605 /* map the DMA buffer */
1606 err = DSDB_MapPrimary(*ippdsdb);
1607 if (err != DS_OK) {
1608 HeapFree(GetProcessHeap(),0,*ippdsdb);
1609 *ippdsdb = NULL;
1610 return err;
1613 /* primary buffer is ready to go */
1614 *pdwcbBufferSize = WOutDev[This->wDevID].maplen;
1615 *ppbBuffer = WOutDev[This->wDevID].mapping;
1617 /* some drivers need some extra nudging after mapping */
1618 if (ioctl(WOutDev[This->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1619 ERR("ioctl failed (%d)\n", errno);
1620 return DSERR_GENERIC;
1623 This->primary = *ippdsdb;
1625 return DS_OK;
1628 static HRESULT WINAPI IDsDriverImpl_DuplicateSoundBuffer(PIDSDRIVER iface,
1629 PIDSDRIVERBUFFER pBuffer,
1630 LPVOID *ppvObj)
1632 /* ICOM_THIS(IDsDriverImpl,iface); */
1633 TRACE("(%p,%p): stub\n",iface,pBuffer);
1634 return DSERR_INVALIDCALL;
1637 static ICOM_VTABLE(IDsDriver) dsdvt =
1639 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1640 IDsDriverImpl_QueryInterface,
1641 IDsDriverImpl_AddRef,
1642 IDsDriverImpl_Release,
1643 IDsDriverImpl_GetDriverDesc,
1644 IDsDriverImpl_Open,
1645 IDsDriverImpl_Close,
1646 IDsDriverImpl_GetCaps,
1647 IDsDriverImpl_CreateSoundBuffer,
1648 IDsDriverImpl_DuplicateSoundBuffer
1651 static DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv)
1653 IDsDriverImpl** idrv = (IDsDriverImpl**)drv;
1655 /* the HAL isn't much better than the HEL if we can't do mmap() */
1656 if (!(WOutDev[wDevID].caps.dwSupport & WAVECAPS_DIRECTSOUND)) {
1657 ERR("DirectSound flag not set\n");
1658 MESSAGE("This sound card's driver does not support direct access\n");
1659 MESSAGE("The (slower) DirectSound HEL mode will be used instead.\n");
1660 return MMSYSERR_NOTSUPPORTED;
1663 *idrv = (IDsDriverImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDsDriverImpl));
1664 if (!*idrv)
1665 return MMSYSERR_NOMEM;
1666 ICOM_VTBL(*idrv) = &dsdvt;
1667 (*idrv)->ref = 1;
1669 (*idrv)->wDevID = wDevID;
1670 (*idrv)->primary = NULL;
1671 return MMSYSERR_NOERROR;
1674 /*======================================================================*
1675 * Low level WAVE IN implementation *
1676 *======================================================================*/
1678 /**************************************************************************
1679 * widGetDevCaps [internal]
1681 static DWORD widGetDevCaps(WORD wDevID, LPWAVEINCAPSA lpCaps, DWORD dwSize)
1683 TRACE("(%u, %p, %lu);\n", wDevID, lpCaps, dwSize);
1685 if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
1687 if (wDevID >= MAX_WAVEINDRV) {
1688 TRACE("MAX_WAVINDRV reached !\n");
1689 return MMSYSERR_BADDEVICEID;
1692 memcpy(lpCaps, &WInDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
1693 return MMSYSERR_NOERROR;
1696 /**************************************************************************
1697 * widRecorder [internal]
1699 static DWORD CALLBACK widRecorder(LPVOID pmt)
1701 WORD uDevID = (DWORD)pmt;
1702 WINE_WAVEIN* wwi = (WINE_WAVEIN*)&WInDev[uDevID];
1703 WAVEHDR* lpWaveHdr;
1704 DWORD dwSleepTime;
1705 MSG msg;
1706 DWORD bytesRead;
1708 audio_buf_info info;
1710 LPVOID buffer = HeapAlloc(GetProcessHeap(),
1711 HEAP_ZERO_MEMORY,
1712 wwi->dwFragmentSize);
1714 LPVOID pOffset = buffer;
1716 PeekMessageA(&msg, 0, 0, 0, 0);
1717 wwi->state = WINE_WS_STOPPED;
1718 wwi->dwTotalRecorded = 0;
1720 SetEvent(wwi->hEvent);
1722 /* make sleep time to be # of ms to output a fragment */
1723 dwSleepTime = (wwi->dwFragmentSize * 1000) / wwi->format.wf.nAvgBytesPerSec;
1724 TRACE("sleeptime=%ld ms\n", dwSleepTime);
1726 for (; ; ) {
1727 /* wait for dwSleepTime or an event in thread's queue */
1728 /* FIXME: could improve wait time depending on queue state,
1729 * ie, number of queued fragments
1732 if (wwi->lpQueuePtr != NULL && wwi->state == WINE_WS_PLAYING)
1734 lpWaveHdr = wwi->lpQueuePtr;
1737 ioctl(wwi->unixdev, SNDCTL_DSP_GETISPACE, &info);
1738 TRACE("info={frag=%d fsize=%d ftotal=%d bytes=%d}\n", info.fragments, info.fragsize, info.fragstotal, info.bytes);
1741 /* read all the fragments accumulated so far */
1742 while ((info.fragments > 0) && (wwi->lpQueuePtr))
1744 info.fragments --;
1746 if (lpWaveHdr->dwBufferLength - lpWaveHdr->dwBytesRecorded > wwi->dwFragmentSize)
1748 /* directly read fragment in wavehdr */
1749 bytesRead = read(wwi->unixdev,
1750 lpWaveHdr->lpData + lpWaveHdr->dwBytesRecorded,
1751 wwi->dwFragmentSize);
1753 TRACE("bytesRead=%ld (direct)\n", bytesRead);
1754 if (bytesRead != (DWORD) -1)
1756 /* update number of bytes recorded in current buffer and by this device */
1757 lpWaveHdr->dwBytesRecorded += bytesRead;
1758 wwi->dwTotalRecorded += bytesRead;
1760 /* buffer is full. notify client */
1761 if (lpWaveHdr->dwBytesRecorded == lpWaveHdr->dwBufferLength)
1763 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
1764 lpWaveHdr->dwFlags |= WHDR_DONE;
1766 if (OSS_NotifyClient(uDevID,
1767 WIM_DATA,
1768 (DWORD)lpWaveHdr,
1769 lpWaveHdr->dwBytesRecorded) != MMSYSERR_NOERROR)
1771 WARN("can't notify client !\n");
1773 lpWaveHdr = wwi->lpQueuePtr = lpWaveHdr->lpNext;
1777 else
1779 /* read the fragment in a local buffer */
1780 bytesRead = read(wwi->unixdev, buffer, wwi->dwFragmentSize);
1781 pOffset = buffer;
1783 TRACE("bytesRead=%ld (local)\n", bytesRead);
1785 /* copy data in client buffers */
1786 while (bytesRead != (DWORD) -1 && bytesRead > 0)
1788 DWORD dwToCopy = min (bytesRead, lpWaveHdr->dwBufferLength - lpWaveHdr->dwBytesRecorded);
1790 memcpy(lpWaveHdr->lpData + lpWaveHdr->dwBytesRecorded,
1791 pOffset,
1792 dwToCopy);
1794 /* update number of bytes recorded in current buffer and by this device */
1795 lpWaveHdr->dwBytesRecorded += dwToCopy;
1796 wwi->dwTotalRecorded += dwToCopy;
1797 bytesRead -= dwToCopy;
1798 pOffset += dwToCopy;
1800 /* client buffer is full. notify client */
1801 if (lpWaveHdr->dwBytesRecorded == lpWaveHdr->dwBufferLength)
1803 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
1804 lpWaveHdr->dwFlags |= WHDR_DONE;
1806 if (OSS_NotifyClient(uDevID,
1807 WIM_DATA,
1808 (DWORD)lpWaveHdr,
1809 lpWaveHdr->dwBytesRecorded) != MMSYSERR_NOERROR)
1811 WARN("can't notify client !\n");
1814 if (lpWaveHdr->lpNext)
1816 lpWaveHdr = lpWaveHdr->lpNext;
1817 wwi->lpQueuePtr = lpWaveHdr;
1819 else
1821 /* no more buffer to copy data to, but we did read more.
1822 * what hasn't been copied will be dropped
1824 if (bytesRead) WARN("buffer over run! %lu bytes dropped.\n", bytesRead);
1825 wwi->lpQueuePtr = NULL;
1826 break;
1834 MsgWaitForMultipleObjects(0, NULL, FALSE, dwSleepTime, QS_POSTMESSAGE);
1836 while (PeekMessageA(&msg, 0, WINE_WM_FIRST, WINE_WM_LAST, PM_REMOVE)) {
1838 TRACE("msg=0x%x wParam=0x%x lParam=0x%lx\n", msg.message, msg.wParam, msg.lParam);
1839 switch (msg.message) {
1840 case WINE_WM_PAUSING:
1841 wwi->state = WINE_WS_PAUSED;
1842 /*FIXME("Device should stop recording");*/
1843 SetEvent(wwi->hEvent);
1844 break;
1845 case WINE_WM_RESTARTING:
1847 int enable = PCM_ENABLE_INPUT;
1848 wwi->state = WINE_WS_PLAYING;
1850 if (wwi->bTriggerSupport)
1852 /* start the recording */
1853 if (ioctl(wwi->unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0)
1855 ERR("ioctl(SNDCTL_DSP_SETTRIGGER) failed (%d)\n", errno);
1858 else
1860 unsigned char data[4];
1861 /* read 4 bytes to start the recording */
1862 read(wwi->unixdev, data, 4);
1865 SetEvent(wwi->hEvent);
1866 break;
1868 case WINE_WM_HEADER:
1869 lpWaveHdr = (LPWAVEHDR)msg.lParam;
1870 lpWaveHdr->lpNext = 0;
1872 /* insert buffer at the end of queue */
1874 LPWAVEHDR* wh;
1875 for (wh = &(wwi->lpQueuePtr); *wh; wh = &((*wh)->lpNext));
1876 *wh = lpWaveHdr;
1878 break;
1879 case WINE_WM_RESETTING:
1880 wwi->state = WINE_WS_STOPPED;
1881 /* return all buffers to the app */
1882 for (lpWaveHdr = wwi->lpQueuePtr; lpWaveHdr; lpWaveHdr = lpWaveHdr->lpNext) {
1883 TRACE("reset %p %p\n", lpWaveHdr, lpWaveHdr->lpNext);
1884 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
1885 lpWaveHdr->dwFlags |= WHDR_DONE;
1887 if (OSS_NotifyClient(uDevID, WIM_DATA, (DWORD)lpWaveHdr,
1888 lpWaveHdr->dwBytesRecorded) != MMSYSERR_NOERROR) {
1889 WARN("can't notify client !\n");
1892 wwi->lpQueuePtr = NULL;
1893 SetEvent(wwi->hEvent);
1894 break;
1895 case WINE_WM_CLOSING:
1896 wwi->hThread = 0;
1897 wwi->state = WINE_WS_CLOSED;
1898 SetEvent(wwi->hEvent);
1899 HeapFree(GetProcessHeap(), 0, buffer);
1900 ExitThread(0);
1901 /* shouldn't go here */
1902 default:
1903 FIXME("unknown message %d\n", msg.message);
1904 break;
1908 ExitThread(0);
1909 /* just for not generating compilation warnings... should never be executed */
1910 return 0;
1914 /**************************************************************************
1915 * widOpen [internal]
1917 static DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
1919 int audio;
1920 int fragment_size;
1921 int sample_rate;
1922 int format;
1923 int dsp_stereo;
1924 WINE_WAVEIN* wwi;
1926 TRACE("(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
1927 if (lpDesc == NULL) {
1928 WARN("Invalid Parameter !\n");
1929 return MMSYSERR_INVALPARAM;
1931 if (wDevID >= MAX_WAVEINDRV) return MMSYSERR_BADDEVICEID;
1933 /* only PCM format is supported so far... */
1934 if (lpDesc->lpFormat->wFormatTag != WAVE_FORMAT_PCM ||
1935 lpDesc->lpFormat->nChannels == 0 ||
1936 lpDesc->lpFormat->nSamplesPerSec == 0) {
1937 WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
1938 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
1939 lpDesc->lpFormat->nSamplesPerSec);
1940 return WAVERR_BADFORMAT;
1943 if (dwFlags & WAVE_FORMAT_QUERY) {
1944 TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
1945 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
1946 lpDesc->lpFormat->nSamplesPerSec);
1947 return MMSYSERR_NOERROR;
1950 if (access(SOUND_DEV,0) != 0) return MMSYSERR_NOTENABLED;
1951 audio = open(SOUND_DEV, O_RDONLY|O_NDELAY, 0);
1952 if (audio == -1) {
1953 WARN("can't open sound device %s (%s)!\n", SOUND_DEV, strerror(errno));
1954 return MMSYSERR_ALLOCATED;
1956 fcntl(audio, F_SETFD, 1); /* set close on exec flag */
1958 wwi = &WInDev[wDevID];
1959 if (wwi->lpQueuePtr) {
1960 WARN("Should have an empty queue (%p)\n", wwi->lpQueuePtr);
1961 wwi->lpQueuePtr = NULL;
1963 wwi->unixdev = audio;
1964 wwi->dwTotalRecorded = 0;
1965 wwi->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
1967 memcpy(&wwi->waveDesc, lpDesc, sizeof(WAVEOPENDESC));
1968 memcpy(&wwi->format, lpDesc->lpFormat, sizeof(PCMWAVEFORMAT));
1970 if (wwi->format.wBitsPerSample == 0) {
1971 WARN("Resetting zeroed wBitsPerSample\n");
1972 wwi->format.wBitsPerSample = 8 *
1973 (wwi->format.wf.nAvgBytesPerSec /
1974 wwi->format.wf.nSamplesPerSec) /
1975 wwi->format.wf.nChannels;
1978 sample_rate = wwi->format.wf.nSamplesPerSec;
1979 dsp_stereo = (wwi->format.wf.nChannels > 1) ? TRUE : FALSE;
1980 format = (wwi->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8;
1982 IOCTL(audio, SNDCTL_DSP_SETFMT, format);
1983 IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo);
1984 IOCTL(audio, SNDCTL_DSP_SPEED, sample_rate);
1986 /* paranoid checks */
1987 if (format != ((wwi->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8))
1988 ERR("Can't set format to %d (%d)\n",
1989 (wwi->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8, format);
1990 if (dsp_stereo != (wwi->format.wf.nChannels > 1) ? 1 : 0)
1991 ERR("Can't set stereo to %u (%d)\n",
1992 (wwi->format.wf.nChannels > 1) ? 1 : 0, dsp_stereo);
1993 if (!NEAR_MATCH(sample_rate, wwi->format.wf.nSamplesPerSec))
1994 ERR("Can't set sample_rate to %lu (%d)\n",
1995 wwi->format.wf.nSamplesPerSec, sample_rate);
1997 IOCTL(audio, SNDCTL_DSP_GETBLKSIZE, fragment_size);
1998 if (fragment_size == -1) {
1999 WARN("IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n");
2000 close(audio);
2001 wwi->unixdev = -1;
2002 return MMSYSERR_NOTENABLED;
2004 wwi->dwFragmentSize = fragment_size;
2006 TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
2007 wwi->format.wBitsPerSample, wwi->format.wf.nAvgBytesPerSec,
2008 wwi->format.wf.nSamplesPerSec, wwi->format.wf.nChannels,
2009 wwi->format.wf.nBlockAlign);
2011 wwi->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
2012 wwi->hThread = CreateThread(NULL, 0, widRecorder, (LPVOID)(DWORD)wDevID, 0, &(wwi->dwThreadID));
2013 WaitForSingleObject(wwi->hEvent, INFINITE);
2015 if (OSS_NotifyClient(wDevID, WIM_OPEN, 0L, 0L) != MMSYSERR_NOERROR) {
2016 WARN("can't notify client !\n");
2017 return MMSYSERR_INVALPARAM;
2019 return MMSYSERR_NOERROR;
2022 /**************************************************************************
2023 * widClose [internal]
2025 static DWORD widClose(WORD wDevID)
2027 WINE_WAVEIN* wwi;
2029 TRACE("(%u);\n", wDevID);
2030 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2031 WARN("can't close !\n");
2032 return MMSYSERR_INVALHANDLE;
2035 wwi = &WInDev[wDevID];
2037 if (wwi->lpQueuePtr != NULL) {
2038 WARN("still buffers open !\n");
2039 return WAVERR_STILLPLAYING;
2042 PostThreadMessageA(wwi->dwThreadID, WINE_WM_CLOSING, 0, 0);
2043 WaitForSingleObject(wwi->hEvent, INFINITE);
2044 CloseHandle(wwi->hEvent);
2045 close(wwi->unixdev);
2046 wwi->unixdev = -1;
2047 wwi->dwFragmentSize = 0;
2048 if (OSS_NotifyClient(wDevID, WIM_CLOSE, 0L, 0L) != MMSYSERR_NOERROR) {
2049 WARN("can't notify client !\n");
2050 return MMSYSERR_INVALPARAM;
2052 return MMSYSERR_NOERROR;
2055 /**************************************************************************
2056 * widAddBuffer [internal]
2058 static DWORD widAddBuffer(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
2060 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
2062 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2063 WARN("can't do it !\n");
2064 return MMSYSERR_INVALHANDLE;
2066 if (!(lpWaveHdr->dwFlags & WHDR_PREPARED)) {
2067 TRACE("never been prepared !\n");
2068 return WAVERR_UNPREPARED;
2070 if (lpWaveHdr->dwFlags & WHDR_INQUEUE) {
2071 TRACE("header already in use !\n");
2072 return WAVERR_STILLPLAYING;
2075 lpWaveHdr->dwFlags |= WHDR_INQUEUE;
2076 lpWaveHdr->dwFlags &= ~WHDR_DONE;
2077 lpWaveHdr->dwBytesRecorded = 0;
2078 lpWaveHdr->lpNext = NULL;
2080 PostThreadMessageA(WInDev[wDevID].dwThreadID, WINE_WM_HEADER, 0, (DWORD)lpWaveHdr);
2081 return MMSYSERR_NOERROR;
2084 /**************************************************************************
2085 * widPrepare [internal]
2087 static DWORD widPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
2089 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
2091 if (wDevID >= MAX_WAVEINDRV) return MMSYSERR_INVALHANDLE;
2093 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
2094 return WAVERR_STILLPLAYING;
2096 lpWaveHdr->dwFlags |= WHDR_PREPARED;
2097 lpWaveHdr->dwFlags &= ~(WHDR_INQUEUE|WHDR_DONE);
2098 lpWaveHdr->dwBytesRecorded = 0;
2099 TRACE("header prepared !\n");
2100 return MMSYSERR_NOERROR;
2103 /**************************************************************************
2104 * widUnprepare [internal]
2106 static DWORD widUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
2108 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
2109 if (wDevID >= MAX_WAVEINDRV) return MMSYSERR_INVALHANDLE;
2111 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
2112 return WAVERR_STILLPLAYING;
2114 lpWaveHdr->dwFlags &= ~(WHDR_PREPARED|WHDR_INQUEUE);
2115 lpWaveHdr->dwFlags |= WHDR_DONE;
2117 return MMSYSERR_NOERROR;
2120 /**************************************************************************
2121 * widStart [internal]
2123 static DWORD widStart(WORD wDevID)
2125 TRACE("(%u);\n", wDevID);
2126 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2127 WARN("can't start recording !\n");
2128 return MMSYSERR_INVALHANDLE;
2131 PostThreadMessageA(WInDev[wDevID].dwThreadID, WINE_WM_RESTARTING, 0, 0);
2132 WaitForSingleObject(WInDev[wDevID].hEvent, INFINITE);
2133 return MMSYSERR_NOERROR;
2136 /**************************************************************************
2137 * widStop [internal]
2139 static DWORD widStop(WORD wDevID)
2141 TRACE("(%u);\n", wDevID);
2142 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2143 WARN("can't stop !\n");
2144 return MMSYSERR_INVALHANDLE;
2146 /* FIXME: reset aint stop */
2147 PostThreadMessageA(WInDev[wDevID].dwThreadID, WINE_WM_RESETTING, 0, 0);
2148 WaitForSingleObject(WInDev[wDevID].hEvent, INFINITE);
2150 return MMSYSERR_NOERROR;
2153 /**************************************************************************
2154 * widReset [internal]
2156 static DWORD widReset(WORD wDevID)
2158 TRACE("(%u);\n", wDevID);
2159 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2160 WARN("can't reset !\n");
2161 return MMSYSERR_INVALHANDLE;
2163 PostThreadMessageA(WInDev[wDevID].dwThreadID, WINE_WM_RESETTING, 0, 0);
2164 WaitForSingleObject(WInDev[wDevID].hEvent, INFINITE);
2165 return MMSYSERR_NOERROR;
2168 /**************************************************************************
2169 * widGetPosition [internal]
2171 static DWORD widGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
2173 int time;
2174 WINE_WAVEIN* wwi;
2176 TRACE("(%u, %p, %lu);\n", wDevID, lpTime, uSize);
2178 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2179 WARN("can't get pos !\n");
2180 return MMSYSERR_INVALHANDLE;
2182 if (lpTime == NULL) return MMSYSERR_INVALPARAM;
2184 wwi = &WInDev[wDevID];
2186 TRACE("wType=%04X !\n", lpTime->wType);
2187 TRACE("wBitsPerSample=%u\n", wwi->format.wBitsPerSample);
2188 TRACE("nSamplesPerSec=%lu\n", wwi->format.wf.nSamplesPerSec);
2189 TRACE("nChannels=%u\n", wwi->format.wf.nChannels);
2190 TRACE("nAvgBytesPerSec=%lu\n", wwi->format.wf.nAvgBytesPerSec);
2191 switch (lpTime->wType) {
2192 case TIME_BYTES:
2193 lpTime->u.cb = wwi->dwTotalRecorded;
2194 TRACE("TIME_BYTES=%lu\n", lpTime->u.cb);
2195 break;
2196 case TIME_SAMPLES:
2197 lpTime->u.sample = wwi->dwTotalRecorded * 8 /
2198 wwi->format.wBitsPerSample;
2199 TRACE("TIME_SAMPLES=%lu\n", lpTime->u.sample);
2200 break;
2201 case TIME_SMPTE:
2202 time = wwi->dwTotalRecorded /
2203 (wwi->format.wf.nAvgBytesPerSec / 1000);
2204 lpTime->u.smpte.hour = time / 108000;
2205 time -= lpTime->u.smpte.hour * 108000;
2206 lpTime->u.smpte.min = time / 1800;
2207 time -= lpTime->u.smpte.min * 1800;
2208 lpTime->u.smpte.sec = time / 30;
2209 time -= lpTime->u.smpte.sec * 30;
2210 lpTime->u.smpte.frame = time;
2211 lpTime->u.smpte.fps = 30;
2212 TRACE("TIME_SMPTE=%02u:%02u:%02u:%02u\n",
2213 lpTime->u.smpte.hour, lpTime->u.smpte.min,
2214 lpTime->u.smpte.sec, lpTime->u.smpte.frame);
2215 break;
2216 case TIME_MS:
2217 lpTime->u.ms = wwi->dwTotalRecorded /
2218 (wwi->format.wf.nAvgBytesPerSec / 1000);
2219 TRACE("TIME_MS=%lu\n", lpTime->u.ms);
2220 break;
2221 default:
2222 FIXME("format not supported (%u) ! use TIME_MS !\n", lpTime->wType);
2223 lpTime->wType = TIME_MS;
2225 return MMSYSERR_NOERROR;
2228 /**************************************************************************
2229 * OSS_widMessage [sample driver]
2231 DWORD WINAPI OSS_widMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
2232 DWORD dwParam1, DWORD dwParam2)
2234 TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
2235 wDevID, wMsg, dwUser, dwParam1, dwParam2);
2237 switch (wMsg) {
2238 case DRVM_INIT:
2239 case DRVM_EXIT:
2240 case DRVM_ENABLE:
2241 case DRVM_DISABLE:
2242 /* FIXME: Pretend this is supported */
2243 return 0;
2244 case WIDM_OPEN: return widOpen (wDevID, (LPWAVEOPENDESC)dwParam1, dwParam2);
2245 case WIDM_CLOSE: return widClose (wDevID);
2246 case WIDM_ADDBUFFER: return widAddBuffer (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
2247 case WIDM_PREPARE: return widPrepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
2248 case WIDM_UNPREPARE: return widUnprepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
2249 case WIDM_GETDEVCAPS: return widGetDevCaps (wDevID, (LPWAVEINCAPSA)dwParam1, dwParam2);
2250 case WIDM_GETNUMDEVS: return wodGetNumDevs (); /* same number of devices in output as in input */
2251 case WIDM_GETPOS: return widGetPosition(wDevID, (LPMMTIME)dwParam1, dwParam2);
2252 case WIDM_RESET: return widReset (wDevID);
2253 case WIDM_START: return widStart (wDevID);
2254 case WIDM_STOP: return widStop (wDevID);
2255 default:
2256 FIXME("unknown message %u!\n", wMsg);
2258 return MMSYSERR_NOTSUPPORTED;
2261 #else /* !HAVE_OSS */
2263 /**************************************************************************
2264 * OSS_wodMessage [sample driver]
2266 DWORD WINAPI OSS_wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
2267 DWORD dwParam1, DWORD dwParam2)
2269 FIXME("(%u, %04X, %08lX, %08lX, %08lX):stub\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
2270 return MMSYSERR_NOTENABLED;
2273 /**************************************************************************
2274 * OSS_widMessage [sample driver]
2276 DWORD WINAPI OSS_widMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
2277 DWORD dwParam1, DWORD dwParam2)
2279 FIXME("(%u, %04X, %08lX, %08lX, %08lX):stub\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
2280 return MMSYSERR_NOTENABLED;
2283 #endif /* HAVE_OSS */