1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 * Sample Wine Driver for Advanced Linux Sound System (ALSA)
4 * Based on version 0.5 of the ALSA API
6 * Copyright 2002 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #ifdef HAVE_SYS_IOCTL_H
36 # include <sys/ioctl.h>
38 #ifdef HAVE_SYS_MMAN_H
39 # include <sys/mman.h>
50 #include "wine/debug.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(wave
);
55 #if defined(HAVE_ALSA) && (SND_LIB_MAJOR == 0) && (SND_LIB_MINOR == 5)
57 #define MAX_WAVEOUTDRV (1)
58 #define MAX_WAVEINDRV (1)
60 /* state diagram for waveOut writing:
62 * +---------+-------------+---------------+---------------------------------+
63 * | state | function | event | new state |
64 * +---------+-------------+---------------+---------------------------------+
65 * | | open() | | STOPPED |
66 * | PAUSED | write() | | PAUSED |
67 * | STOPPED | write() | <thrd create> | PLAYING |
68 * | PLAYING | write() | HEADER | PLAYING |
69 * | (other) | write() | <error> | |
70 * | (any) | pause() | PAUSING | PAUSED |
71 * | PAUSED | restart() | RESTARTING | PLAYING (if no thrd => STOPPED) |
72 * | (any) | reset() | RESETTING | STOPPED |
73 * | (any) | close() | CLOSING | CLOSED |
74 * +---------+-------------+---------------+---------------------------------+
77 /* states of the playing device */
78 #define WINE_WS_PLAYING 0
79 #define WINE_WS_PAUSED 1
80 #define WINE_WS_STOPPED 2
81 #define WINE_WS_CLOSED 3
83 /* events to be send to device */
85 WINE_WM_PAUSING
= WM_USER
+ 1, WINE_WM_RESTARTING
, WINE_WM_RESETTING
, WINE_WM_HEADER
,
86 WINE_WM_UPDATE
, WINE_WM_BREAKLOOP
, WINE_WM_CLOSING
90 enum win_wm_message msg
; /* message identifier */
91 DWORD param
; /* parameter for this message */
92 HANDLE hEvent
; /* if message is synchronous, handle of event for synchro */
95 /* implement an in-process message ring for better performance
96 * (compared to passing thru the server)
97 * this ring will be used by the input (resp output) record (resp playback) routine
100 /* FIXME: this could be made a dynamically growing array (if needed) */
101 #define ALSA_RING_BUFFER_SIZE 30
102 ALSA_MSG messages
[ALSA_RING_BUFFER_SIZE
];
106 CRITICAL_SECTION msg_crst
;
110 /* Windows information */
111 volatile int state
; /* one of the WINE_WS_ manifest constants */
112 WAVEOPENDESC waveDesc
;
114 PCMWAVEFORMAT format
;
117 /* ALSA information */
118 snd_pcm_t
* handle
; /* handle to ALSA device */
119 DWORD dwFragmentSize
; /* size of ALSA buffer fragment */
120 DWORD dwBufferSize
; /* size of whole ALSA buffer in bytes */
121 LPWAVEHDR lpQueuePtr
; /* start of queued WAVEHDRs (waiting to be notified) */
122 LPWAVEHDR lpPlayPtr
; /* start of not yet fully played buffers */
123 DWORD dwPartialOffset
; /* Offset of not yet written bytes in lpPlayPtr */
125 LPWAVEHDR lpLoopPtr
; /* pointer of first buffer in loop, if any */
126 DWORD dwLoops
; /* private copy of loop counter */
128 DWORD dwPlayedTotal
; /* number of bytes actually played since opening */
129 DWORD dwWrittenTotal
; /* number of bytes written to ALSA buffer since opening */
131 /* synchronization stuff */
132 HANDLE hStartUpEvent
;
135 ALSA_MSG_RING msgRing
;
137 /* DirectSound stuff */
139 snd_pcm_mmap_control_t
* mmap_control
;
140 unsigned mmap_block_size
;
141 unsigned mmap_block_number
;
144 static WINE_WAVEOUT WOutDev
[MAX_WAVEOUTDRV
];
145 static DWORD ALSA_WodNumDevs
;
147 static DWORD
wodDsCreate(UINT wDevID
, PIDSDRIVER
* drv
);
149 /* These strings used only for tracing */
150 static const char *wodPlayerCmdString
[] = {
152 "WINE_WM_RESTARTING",
160 /*======================================================================*
161 * Low level WAVE implementation *
162 *======================================================================*/
164 /******************************************************************
167 * Initialize internal structures from ALSA information
169 LONG
ALSA_WaveInit(void)
173 snd_pcm_channel_info_t chn_info
;
175 static const WCHAR ini_out
[] = {'A','L','S','A',' ','W','a','v','e','O','u','t',' ','D','r','i','v','e','r',0};
177 TRACE("There are %d cards\n", snd_cards());
180 if (snd_pcm_open(&h
, 0, 0, SND_PCM_OPEN_DUPLEX
|SND_PCM_OPEN_NONBLOCK
))
182 ERR("Error open: %s\n", snd_strerror(errno
));
185 if (snd_pcm_info(h
, &info
))
187 ERR("Error info: %s\n", snd_strerror(errno
));
191 TRACE("type=%u, flags=%s%s%s name=%s #pb=%d cp=%d\n",
192 info
.type
, (info
.flags
& SND_PCM_INFO_PLAYBACK
) ? "playback " : "",
193 (info
.flags
& SND_PCM_INFO_PLAYBACK
) ? "capture " : "",
194 (info
.flags
& SND_PCM_INFO_DUPLEX
) ? "duplex " : "",
195 info
.name
, info
.playback
, info
.capture
);
196 memset(&chn_info
, 0, sizeof(chn_info
));
197 if (snd_pcm_channel_info(h
, &chn_info
))
199 ERR("Error chn info: %s\n", snd_strerror(errno
));
202 #define X(f,s) ((chn_info.flags & (f)) ? #s " " : "")
203 #define Y(f,s) ((chn_info.rates & (f)) ? #s " " : "")
204 TRACE("subdevice=%d name=%s chn=%d mode=%d\n"
205 "\tflags=%s%s%s%s%s%s%s%s%s%s%s\n"
206 "\tfmts=%u rates=%s%s%s%s%s%s%s%s%s%s%s%s%s\n"
207 "\trates=[%d,%d] voices=[%d,%d] buf_size=%d fg_size=[%d,%d] fg_align=%u\n",
208 chn_info
.subdevice
, chn_info
.subname
, chn_info
.channel
,
210 X(SND_PCM_CHNINFO_MMAP
,MMAP
),
211 X(SND_PCM_CHNINFO_STREAM
,STREAM
),
212 X(SND_PCM_CHNINFO_BLOCK
,BLOCK
),
213 X(SND_PCM_CHNINFO_BATCH
,BATCH
),
214 X(SND_PCM_CHNINFO_INTERLEAVE
,INTERLEAVE
),
215 X(SND_PCM_CHNINFO_NONINTERLEAVE
,NONINTERLEAVE
),
216 X(SND_PCM_CHNINFO_BLOCK_TRANSFER
,BLOCK_TRANSFER
),
217 X(SND_PCM_CHNINFO_OVERRANGE
,OVERRANGE
),
218 X(SND_PCM_CHNINFO_MMAP_VALID
,MMAP_VALID
),
219 X(SND_PCM_CHNINFO_PAUSE
,PAUSE
),
220 X(SND_PCM_CHNINFO_GLOBAL_PARAMS
,GLOBAL_PARAMS
),
222 Y(SND_PCM_RATE_CONTINUOUS
,CONTINUOUS
),
223 Y(SND_PCM_RATE_KNOT
,KNOT
),
224 Y(SND_PCM_RATE_8000
,8000),
225 Y(SND_PCM_RATE_11025
,11025),
226 Y(SND_PCM_RATE_16000
,16000),
227 Y(SND_PCM_RATE_22050
,22050),
228 Y(SND_PCM_RATE_32000
,32000),
229 Y(SND_PCM_RATE_44100
,44100),
230 Y(SND_PCM_RATE_48000
,48000),
231 Y(SND_PCM_RATE_88200
,88200),
232 Y(SND_PCM_RATE_96000
,96000),
233 Y(SND_PCM_RATE_176400
,176400),
234 Y(SND_PCM_RATE_192000
,192000),
235 chn_info
.min_rate
, chn_info
.max_rate
,
236 chn_info
.min_voices
, chn_info
.max_voices
,
237 chn_info
.buffer_size
,
238 chn_info
.min_fragment_size
, chn_info
.max_fragment_size
,
239 chn_info
.fragment_align
);
243 /* FIXME: use better values */
244 WOutDev
[0].caps
.wMid
= 0x0002;
245 WOutDev
[0].caps
.wPid
= 0x0104;
246 strcpyW(WOutDev
[0].caps
.szPname
, ini
);
247 WOutDev
[0].caps
.vDriverVersion
= 0x0100;
248 WOutDev
[0].caps
.dwFormats
= 0x00000000;
249 WOutDev
[0].caps
.dwSupport
= WAVECAPS_VOLUME
;
251 if (chn_info.rates & SND_PCM_RATE_##r) \
253 if (chn_info.formats & SND_PCM_FMT_U8) \
255 if (chn_info.min_voices <= 1 && 1 <= chn_info.max_voices) \
256 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_##v##S08; \
257 if (chn_info.min_voices <= 2 && 2 <= chn_info.max_voices) \
258 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_##v##S08; \
260 if (chn_info.formats & SND_PCM_FMT_S16_LE) \
262 if (chn_info.min_voices <= 1 && 1 <= chn_info.max_voices) \
263 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_##v##S16; \
264 if (chn_info.min_voices <= 2 && 2 <= chn_info.max_voices) \
265 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_##v##S16; \
272 if (chn_info
.min_voices
> 1) FIXME("-\n");
273 WOutDev
[0].caps
.wChannels
= (chn_info
.max_voices
>= 2) ? 2 : 1;
274 if (chn_info
.min_voices
<= 2 && 2 <= chn_info
.max_voices
)
275 WOutDev
[0].caps
.dwSupport
|= WAVECAPS_LRVOLUME
;
277 /* FIXME: always true ? */
278 WOutDev
[0].caps
.dwSupport
|= WAVECAPS_SAMPLEACCURATE
;
280 /* FIXME: is test sufficient ? */
281 if (chn_info
.flags
& SND_PCM_CHNINFO_MMAP
)
282 WOutDev
[0].caps
.dwSupport
|= WAVECAPS_DIRECTSOUND
;
284 TRACE("Configured with dwFmts=%08lx dwSupport=%08lx\n",
285 WOutDev
[0].caps
.dwFormats
, WOutDev
[0].caps
.dwSupport
);
292 /******************************************************************
293 * ALSA_InitRingMessage
295 * Initialize the ring of messages for passing between driver's caller and playback/record
298 static int ALSA_InitRingMessage(ALSA_MSG_RING
* omr
)
302 omr
->msg_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
303 memset(omr
->messages
, 0, sizeof(ALSA_MSG
) * ALSA_RING_BUFFER_SIZE
);
304 InitializeCriticalSection(&omr
->msg_crst
);
308 /******************************************************************
309 * ALSA_DestroyRingMessage
312 static int ALSA_DestroyRingMessage(ALSA_MSG_RING
* omr
)
314 CloseHandle(omr
->msg_event
);
315 DeleteCriticalSection(&omr
->msg_crst
);
319 /******************************************************************
320 * ALSA_AddRingMessage
322 * Inserts a new message into the ring (should be called from DriverProc derivated routines)
324 static int ALSA_AddRingMessage(ALSA_MSG_RING
* omr
, enum win_wm_message msg
, DWORD param
, BOOL wait
)
326 HANDLE hEvent
= INVALID_HANDLE_VALUE
;
328 EnterCriticalSection(&omr
->msg_crst
);
329 if ((omr
->msg_toget
== ((omr
->msg_tosave
+ 1) % ALSA_RING_BUFFER_SIZE
))) /* buffer overflow ? */
331 ERR("buffer overflow !?\n");
332 LeaveCriticalSection(&omr
->msg_crst
);
337 hEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
338 if (hEvent
== INVALID_HANDLE_VALUE
)
340 ERR("can't create event !?\n");
341 LeaveCriticalSection(&omr
->msg_crst
);
344 if (omr
->msg_toget
!= omr
->msg_tosave
&& omr
->messages
[omr
->msg_toget
].msg
!= WINE_WM_HEADER
)
345 FIXME("two fast messages in the queue!!!!\n");
347 /* fast messages have to be added at the start of the queue */
348 omr
->msg_toget
= (omr
->msg_toget
+ ALSA_RING_BUFFER_SIZE
- 1) % ALSA_RING_BUFFER_SIZE
;
350 omr
->messages
[omr
->msg_toget
].msg
= msg
;
351 omr
->messages
[omr
->msg_toget
].param
= param
;
352 omr
->messages
[omr
->msg_toget
].hEvent
= hEvent
;
356 omr
->messages
[omr
->msg_tosave
].msg
= msg
;
357 omr
->messages
[omr
->msg_tosave
].param
= param
;
358 omr
->messages
[omr
->msg_tosave
].hEvent
= INVALID_HANDLE_VALUE
;
359 omr
->msg_tosave
= (omr
->msg_tosave
+ 1) % ALSA_RING_BUFFER_SIZE
;
361 LeaveCriticalSection(&omr
->msg_crst
);
362 /* signal a new message */
363 SetEvent(omr
->msg_event
);
366 /* wait for playback/record thread to have processed the message */
367 WaitForSingleObject(hEvent
, INFINITE
);
373 /******************************************************************
374 * ALSA_RetrieveRingMessage
376 * Get a message from the ring. Should be called by the playback/record thread.
378 static int ALSA_RetrieveRingMessage(ALSA_MSG_RING
* omr
,
379 enum win_wm_message
*msg
, DWORD
*param
, HANDLE
*hEvent
)
381 EnterCriticalSection(&omr
->msg_crst
);
383 if (omr
->msg_toget
== omr
->msg_tosave
) /* buffer empty ? */
385 LeaveCriticalSection(&omr
->msg_crst
);
389 *msg
= omr
->messages
[omr
->msg_toget
].msg
;
390 omr
->messages
[omr
->msg_toget
].msg
= 0;
391 *param
= omr
->messages
[omr
->msg_toget
].param
;
392 *hEvent
= omr
->messages
[omr
->msg_toget
].hEvent
;
393 omr
->msg_toget
= (omr
->msg_toget
+ 1) % ALSA_RING_BUFFER_SIZE
;
394 LeaveCriticalSection(&omr
->msg_crst
);
398 /*======================================================================*
399 * Low level WAVE OUT implementation *
400 *======================================================================*/
402 /**************************************************************************
403 * wodNotifyClient [internal]
405 static DWORD
wodNotifyClient(WINE_WAVEOUT
* wwo
, WORD wMsg
, DWORD dwParam1
, DWORD dwParam2
)
407 TRACE("wMsg = 0x%04x dwParm1 = %04lX dwParam2 = %04lX\n", wMsg
, dwParam1
, dwParam2
);
413 if (wwo
->wFlags
!= DCB_NULL
&&
414 !DriverCallback(wwo
->waveDesc
.dwCallback
, wwo
->wFlags
,
415 (HDRVR
)wwo
->waveDesc
.hWave
,
416 wMsg
, wwo
->waveDesc
.dwInstance
, dwParam1
, dwParam2
)) {
417 WARN("can't notify client !\n");
418 return MMSYSERR_ERROR
;
422 FIXME("Unknown callback message %u\n", wMsg
);
423 return MMSYSERR_INVALPARAM
;
425 return MMSYSERR_NOERROR
;
428 /**************************************************************************
429 * wodUpdatePlayedTotal [internal]
432 static BOOL
wodUpdatePlayedTotal(WINE_WAVEOUT
* wwo
, snd_pcm_channel_status_t
* ps
)
434 snd_pcm_channel_status_t s
;
435 snd_pcm_channel_status_t
* status
= (ps
) ? ps
: &s
;
437 if (snd_pcm_channel_status(wwo
->handle
, status
))
439 ERR("Can't get channel status: %s\n", snd_strerror(errno
));
442 wwo
->dwPlayedTotal
= wwo
->dwWrittenTotal
- (wwo
->dwBufferSize
- status
->count
);
443 if (wwo
->dwPlayedTotal
!= status
->scount
)
445 FIXME("Ooch: %u played by ALSA, %lu counted by driver\n",
446 status
->scount
, wwo
->dwPlayedTotal
);
447 if (wwo
->dwPlayedTotal
& 0x8000000) wwo
->dwPlayedTotal
= 0;
452 /**************************************************************************
453 * wodPlayer_BeginWaveHdr [internal]
455 * Makes the specified lpWaveHdr the currently playing wave header.
456 * If the specified wave header is a begin loop and we're not already in
457 * a loop, setup the loop.
459 static void wodPlayer_BeginWaveHdr(WINE_WAVEOUT
* wwo
, LPWAVEHDR lpWaveHdr
)
461 wwo
->lpPlayPtr
= lpWaveHdr
;
463 if (!lpWaveHdr
) return;
465 if (lpWaveHdr
->dwFlags
& WHDR_BEGINLOOP
) {
466 if (wwo
->lpLoopPtr
) {
467 WARN("Already in a loop. Discarding loop on this header (%p)\n", lpWaveHdr
);
469 TRACE("Starting loop (%ldx) with %p\n", lpWaveHdr
->dwLoops
, lpWaveHdr
);
470 wwo
->lpLoopPtr
= lpWaveHdr
;
471 /* Windows does not touch WAVEHDR.dwLoops,
472 * so we need to make an internal copy */
473 wwo
->dwLoops
= lpWaveHdr
->dwLoops
;
476 wwo
->dwPartialOffset
= 0;
479 /**************************************************************************
480 * wodPlayer_PlayPtrNext [internal]
482 * Advance the play pointer to the next waveheader, looping if required.
484 static LPWAVEHDR
wodPlayer_PlayPtrNext(WINE_WAVEOUT
* wwo
)
486 LPWAVEHDR lpWaveHdr
= wwo
->lpPlayPtr
;
488 wwo
->dwPartialOffset
= 0;
489 if ((lpWaveHdr
->dwFlags
& WHDR_ENDLOOP
) && wwo
->lpLoopPtr
) {
490 /* We're at the end of a loop, loop if required */
491 if (--wwo
->dwLoops
> 0) {
492 wwo
->lpPlayPtr
= wwo
->lpLoopPtr
;
494 /* Handle overlapping loops correctly */
495 if (wwo
->lpLoopPtr
!= lpWaveHdr
&& (lpWaveHdr
->dwFlags
& WHDR_BEGINLOOP
)) {
496 FIXME("Correctly handled case ? (ending loop buffer also starts a new loop)\n");
497 /* shall we consider the END flag for the closing loop or for
498 * the opening one or for both ???
499 * code assumes for closing loop only
502 lpWaveHdr
= lpWaveHdr
->lpNext
;
504 wwo
->lpLoopPtr
= NULL
;
505 wodPlayer_BeginWaveHdr(wwo
, lpWaveHdr
);
508 /* We're not in a loop. Advance to the next wave header */
509 wodPlayer_BeginWaveHdr(wwo
, lpWaveHdr
= lpWaveHdr
->lpNext
);
515 /**************************************************************************
516 * wodPlayer_DSPWait [internal]
517 * Returns the number of milliseconds to wait for the DSP buffer to write
520 static DWORD
wodPlayer_DSPWait(const WINE_WAVEOUT
*wwo
)
522 /* time for one fragment to be played */
523 return wwo
->dwFragmentSize
* 1000 / wwo
->format
.wf
.nAvgBytesPerSec
;
526 /**************************************************************************
527 * wodPlayer_NotifyWait [internal]
528 * Returns the number of milliseconds to wait before attempting to notify
529 * completion of the specified wavehdr.
530 * This is based on the number of bytes remaining to be written in the
533 static DWORD
wodPlayer_NotifyWait(const WINE_WAVEOUT
* wwo
, LPWAVEHDR lpWaveHdr
)
537 if (lpWaveHdr
->reserved
< wwo
->dwPlayedTotal
) {
540 dwMillis
= (lpWaveHdr
->reserved
- wwo
->dwPlayedTotal
) * 1000 / wwo
->format
.wf
.nAvgBytesPerSec
;
541 if (!dwMillis
) dwMillis
= 1;
548 /**************************************************************************
549 * wodPlayer_WriteMaxFrags [internal]
550 * Writes the maximum number of bytes palsaible to the DSP and returns
551 * the number of bytes written.
553 static int wodPlayer_WriteMaxFrags(WINE_WAVEOUT
* wwo
, DWORD
* bytes
)
555 /* Only attempt to write to free bytes */
556 DWORD dwLength
= wwo
->lpPlayPtr
->dwBufferLength
- wwo
->dwPartialOffset
;
557 int toWrite
= min(dwLength
, *bytes
);
560 TRACE("Writing wavehdr %p.%lu[%lu]\n",
561 wwo
->lpPlayPtr
, wwo
->dwPartialOffset
, wwo
->lpPlayPtr
->dwBufferLength
);
562 written
= snd_pcm_write(wwo
->handle
, wwo
->lpPlayPtr
->lpData
+ wwo
->dwPartialOffset
, toWrite
);
565 ERR("Wrote: %d bytes (%s)\n", written
, snd_strerror(errno
));
569 if (written
>= dwLength
) {
570 /* If we wrote all current wavehdr, skip to the next one */
571 wodPlayer_PlayPtrNext(wwo
);
573 /* Remove the amount written */
574 wwo
->dwPartialOffset
+= written
;
577 wwo
->dwWrittenTotal
+= written
;
583 /**************************************************************************
584 * wodPlayer_NotifyCompletions [internal]
586 * Notifies and remove from queue all wavehdrs which have been played to
587 * the speaker (ie. they have cleared the ALSA buffer). If force is true,
588 * we notify all wavehdrs and remove them all from the queue even if they
589 * are unplayed or part of a loop.
591 static DWORD
wodPlayer_NotifyCompletions(WINE_WAVEOUT
* wwo
, BOOL force
)
595 /* Start from lpQueuePtr and keep notifying until:
596 * - we hit an unwritten wavehdr
597 * - we hit the beginning of a running loop
598 * - we hit a wavehdr which hasn't finished playing
600 while ((lpWaveHdr
= wwo
->lpQueuePtr
) &&
602 (lpWaveHdr
!= wwo
->lpPlayPtr
&&
603 lpWaveHdr
!= wwo
->lpLoopPtr
&&
604 lpWaveHdr
->reserved
<= wwo
->dwPlayedTotal
))) {
606 wwo
->lpQueuePtr
= lpWaveHdr
->lpNext
;
608 lpWaveHdr
->dwFlags
&= ~WHDR_INQUEUE
;
609 lpWaveHdr
->dwFlags
|= WHDR_DONE
;
611 wodNotifyClient(wwo
, WOM_DONE
, (DWORD
)lpWaveHdr
, 0);
613 return (lpWaveHdr
&& lpWaveHdr
!= wwo
->lpPlayPtr
&& lpWaveHdr
!= wwo
->lpLoopPtr
) ?
614 wodPlayer_NotifyWait(wwo
, lpWaveHdr
) : INFINITE
;
617 /**************************************************************************
618 * wodPlayer_Reset [internal]
620 * wodPlayer helper. Resets current output stream.
622 static void wodPlayer_Reset(WINE_WAVEOUT
* wwo
, BOOL reset
)
624 wodUpdatePlayedTotal(wwo
, NULL
);
625 /* updates current notify list */
626 wodPlayer_NotifyCompletions(wwo
, FALSE
);
628 if (snd_pcm_playback_flush(wwo
->handle
) != 0) {
629 FIXME("flush: %s\n", snd_strerror(errno
));
631 wwo
->state
= WINE_WS_STOPPED
;
636 enum win_wm_message msg
;
640 /* remove any buffer */
641 wodPlayer_NotifyCompletions(wwo
, TRUE
);
643 wwo
->lpPlayPtr
= wwo
->lpQueuePtr
= wwo
->lpLoopPtr
= NULL
;
644 wwo
->state
= WINE_WS_STOPPED
;
645 wwo
->dwPlayedTotal
= wwo
->dwWrittenTotal
= 0;
646 /* Clear partial wavehdr */
647 wwo
->dwPartialOffset
= 0;
649 /* remove any existing message in the ring */
650 EnterCriticalSection(&wwo
->msgRing
.msg_crst
);
651 /* return all pending headers in queue */
652 while (ALSA_RetrieveRingMessage(&wwo
->msgRing
, &msg
, ¶m
, &ev
))
654 if (msg
!= WINE_WM_HEADER
)
656 FIXME("shouldn't have headers left\n");
660 ((LPWAVEHDR
)param
)->dwFlags
&= ~WHDR_INQUEUE
;
661 ((LPWAVEHDR
)param
)->dwFlags
|= WHDR_DONE
;
663 wodNotifyClient(wwo
, WOM_DONE
, param
, 0);
665 ResetEvent(wwo
->msgRing
.msg_event
);
666 LeaveCriticalSection(&wwo
->msgRing
.msg_crst
);
668 if (wwo
->lpLoopPtr
) {
669 /* complicated case, not handled yet (could imply modifying the loop counter */
670 FIXME("Pausing while in loop isn't correctly handled yet, except strange results\n");
671 wwo
->lpPlayPtr
= wwo
->lpLoopPtr
;
672 wwo
->dwPartialOffset
= 0;
673 wwo
->dwWrittenTotal
= wwo
->dwPlayedTotal
; /* this is wrong !!! */
676 DWORD sz
= wwo
->dwPartialOffset
;
678 /* reset all the data as if we had written only up to lpPlayedTotal bytes */
679 /* compute the max size playable from lpQueuePtr */
680 for (ptr
= wwo
->lpQueuePtr
; ptr
!= wwo
->lpPlayPtr
; ptr
= ptr
->lpNext
) {
681 sz
+= ptr
->dwBufferLength
;
683 /* because the reset lpPlayPtr will be lpQueuePtr */
684 if (wwo
->dwWrittenTotal
> wwo
->dwPlayedTotal
+ sz
) ERR("grin\n");
685 wwo
->dwPartialOffset
= sz
- (wwo
->dwWrittenTotal
- wwo
->dwPlayedTotal
);
686 wwo
->dwWrittenTotal
= wwo
->dwPlayedTotal
;
687 wwo
->lpPlayPtr
= wwo
->lpQueuePtr
;
689 wwo
->state
= WINE_WS_PAUSED
;
693 /**************************************************************************
694 * wodPlayer_ProcessMessages [internal]
696 static void wodPlayer_ProcessMessages(WINE_WAVEOUT
* wwo
)
699 enum win_wm_message msg
;
703 while (ALSA_RetrieveRingMessage(&wwo
->msgRing
, &msg
, ¶m
, &ev
)) {
704 TRACE("Received %s %lx\n", wodPlayerCmdString
[msg
- WM_USER
- 1], param
);
707 case WINE_WM_PAUSING
:
708 wodPlayer_Reset(wwo
, FALSE
);
711 case WINE_WM_RESTARTING
:
712 if (wwo
->state
== WINE_WS_PAUSED
)
714 snd_pcm_playback_prepare(wwo
->handle
);
715 wwo
->state
= WINE_WS_PLAYING
;
720 lpWaveHdr
= (LPWAVEHDR
)param
;
722 /* insert buffer at the end of queue */
725 for (wh
= &(wwo
->lpQueuePtr
); *wh
; wh
= &((*wh
)->lpNext
));
729 wodPlayer_BeginWaveHdr(wwo
,lpWaveHdr
);
730 if (wwo
->state
== WINE_WS_STOPPED
)
731 wwo
->state
= WINE_WS_PLAYING
;
733 case WINE_WM_RESETTING
:
734 wodPlayer_Reset(wwo
, TRUE
);
738 wodUpdatePlayedTotal(wwo
, NULL
);
741 case WINE_WM_BREAKLOOP
:
742 if (wwo
->state
== WINE_WS_PLAYING
&& wwo
->lpLoopPtr
!= NULL
) {
743 /* ensure exit at end of current loop */
748 case WINE_WM_CLOSING
:
749 /* sanity check: this should not happen since the device must have been reset before */
750 if (wwo
->lpQueuePtr
|| wwo
->lpPlayPtr
) ERR("out of sync\n");
752 wwo
->state
= WINE_WS_CLOSED
;
755 /* shouldn't go here */
757 FIXME("unknown message %d\n", msg
);
763 /**************************************************************************
764 * wodPlayer_FeedDSP [internal]
765 * Feed as much sound data as we can into the DSP and return the number of
766 * milliseconds before it will be necessary to feed the DSP again.
768 static DWORD
wodPlayer_FeedDSP(WINE_WAVEOUT
* wwo
)
770 snd_pcm_channel_status_t status
;
773 wodUpdatePlayedTotal(wwo
, &status
);
774 availInQ
= status
.free
;
778 TRACE("fragments=%d/%d, fragsize=%d, bytes=%d\n",
779 dspspace
.fragments
, dspspace
.fragstotal
, dspspace
.fragsize
, dspspace
.bytes
);
782 /* input queue empty and output buffer with less than one fragment to play */
783 /* FIXME: we should be able to catch OVERRUN errors */
784 if (!wwo
->lpPlayPtr
&& wwo
->dwBufferSize
< availInQ
+ 2 * wwo
->dwFragmentSize
) {
785 TRACE("Run out of wavehdr:s... flushing\n");
786 snd_pcm_playback_drain(wwo
->handle
);
787 wwo
->dwPlayedTotal
= wwo
->dwWrittenTotal
;
791 /* no more room... no need to try to feed */
792 if (status
.free
> 0) {
793 /* Feed from partial wavehdr */
794 if (wwo
->lpPlayPtr
&& wwo
->dwPartialOffset
!= 0) {
795 wodPlayer_WriteMaxFrags(wwo
, &availInQ
);
798 /* Feed wavehdrs until we run out of wavehdrs or DSP space */
799 if (wwo
->dwPartialOffset
== 0) {
800 while (wwo
->lpPlayPtr
&& availInQ
> 0) {
801 /* note the value that dwPlayedTotal will return when this wave finishes playing */
802 wwo
->lpPlayPtr
->reserved
= wwo
->dwWrittenTotal
+ wwo
->lpPlayPtr
->dwBufferLength
;
803 wodPlayer_WriteMaxFrags(wwo
, &availInQ
);
807 return wodPlayer_DSPWait(wwo
);
811 /**************************************************************************
812 * wodPlayer [internal]
814 static DWORD CALLBACK
wodPlayer(LPVOID pmt
)
816 WORD uDevID
= (DWORD
)pmt
;
817 WINE_WAVEOUT
* wwo
= (WINE_WAVEOUT
*)&WOutDev
[uDevID
];
818 DWORD dwNextFeedTime
= INFINITE
; /* Time before DSP needs feeding */
819 DWORD dwNextNotifyTime
= INFINITE
; /* Time before next wave completion */
822 wwo
->state
= WINE_WS_STOPPED
;
823 SetEvent(wwo
->hStartUpEvent
);
826 /** Wait for the shortest time before an action is required. If there
827 * are no pending actions, wait forever for a command.
829 dwSleepTime
= min(dwNextFeedTime
, dwNextNotifyTime
);
830 TRACE("waiting %lums (%lu,%lu)\n", dwSleepTime
, dwNextFeedTime
, dwNextNotifyTime
);
831 WaitForSingleObject(wwo
->msgRing
.msg_event
, dwSleepTime
);
832 wodPlayer_ProcessMessages(wwo
);
833 if (wwo
->state
== WINE_WS_PLAYING
) {
834 dwNextFeedTime
= wodPlayer_FeedDSP(wwo
);
835 dwNextNotifyTime
= wodPlayer_NotifyCompletions(wwo
, FALSE
);
837 dwNextFeedTime
= dwNextNotifyTime
= INFINITE
;
842 /**************************************************************************
843 * wodGetDevCaps [internal]
845 static DWORD
wodGetDevCaps(WORD wDevID
, LPWAVEOUTCAPSW lpCaps
, DWORD dwSize
)
847 TRACE("(%u, %p, %lu);\n", wDevID
, lpCaps
, dwSize
);
849 if (lpCaps
== NULL
) return MMSYSERR_NOTENABLED
;
851 if (wDevID
>= MAX_WAVEOUTDRV
) {
852 TRACE("MAX_WAVOUTDRV reached !\n");
853 return MMSYSERR_BADDEVICEID
;
856 memcpy(lpCaps
, &WOutDev
[wDevID
].caps
, min(dwSize
, sizeof(*lpCaps
)));
857 return MMSYSERR_NOERROR
;
860 /**************************************************************************
863 static DWORD
wodOpen(WORD wDevID
, LPWAVEOPENDESC lpDesc
, DWORD dwFlags
)
866 snd_pcm_channel_params_t params
;
868 TRACE("(%u, %p, %08lX);\n", wDevID
, lpDesc
, dwFlags
);
869 if (lpDesc
== NULL
) {
870 WARN("Invalid Parameter !\n");
871 return MMSYSERR_INVALPARAM
;
873 if (wDevID
>= MAX_WAVEOUTDRV
) {
874 TRACE("MAX_WAVOUTDRV reached !\n");
875 return MMSYSERR_BADDEVICEID
;
878 /* only PCM format is supported so far... */
879 if (lpDesc
->lpFormat
->wFormatTag
!= WAVE_FORMAT_PCM
||
880 lpDesc
->lpFormat
->nChannels
== 0 ||
881 lpDesc
->lpFormat
->nSamplesPerSec
== 0) {
882 WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
883 lpDesc
->lpFormat
->wFormatTag
, lpDesc
->lpFormat
->nChannels
,
884 lpDesc
->lpFormat
->nSamplesPerSec
);
885 return WAVERR_BADFORMAT
;
888 if (dwFlags
& WAVE_FORMAT_QUERY
) {
889 TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
890 lpDesc
->lpFormat
->wFormatTag
, lpDesc
->lpFormat
->nChannels
,
891 lpDesc
->lpFormat
->nSamplesPerSec
);
892 return MMSYSERR_NOERROR
;
895 wwo
= &WOutDev
[wDevID
];
897 if ((dwFlags
& WAVE_DIRECTSOUND
) && !(wwo
->caps
.dwSupport
& WAVECAPS_DIRECTSOUND
))
898 /* not supported, ignore it */
899 dwFlags
&= ~WAVE_DIRECTSOUND
;
902 if (snd_pcm_open(&wwo
->handle
, wDevID
, 0, SND_PCM_OPEN_DUPLEX
|SND_PCM_OPEN_NONBLOCK
))
904 ERR("Error open: %s\n", snd_strerror(errno
));
905 return MMSYSERR_NOTENABLED
;
908 memset(¶ms
, 0, sizeof(params
));
909 params
.channel
= SND_PCM_CHANNEL_PLAYBACK
;
910 params
.start_mode
= SND_PCM_START_DATA
;
911 params
.stop_mode
= SND_PCM_STOP_STOP
;
912 params
.mode
= SND_PCM_MODE_STREAM
;
913 params
.buf
.stream
.queue_size
= 0x1000;
914 params
.buf
.stream
.fill
= SND_PCM_FILL_SILENCE
;
915 params
.buf
.stream
.max_fill
= 0x800;
917 wwo
->wFlags
= HIWORD(dwFlags
& CALLBACK_TYPEMASK
);
919 memcpy(&wwo
->waveDesc
, lpDesc
, sizeof(WAVEOPENDESC
));
920 memcpy(&wwo
->format
, lpDesc
->lpFormat
, sizeof(PCMWAVEFORMAT
));
922 if (wwo
->format
.wBitsPerSample
== 0) {
923 WARN("Resetting zeroed wBitsPerSample\n");
924 wwo
->format
.wBitsPerSample
= 8 *
925 (wwo
->format
.wf
.nAvgBytesPerSec
/
926 wwo
->format
.wf
.nSamplesPerSec
) /
927 wwo
->format
.wf
.nChannels
;
929 params
.format
.interleave
= 1;
930 params
.format
.format
= (wwo
->format
.wBitsPerSample
== 16) ?
931 SND_PCM_SFMT_S16_LE
: SND_PCM_SFMT_U8
;
932 params
.format
.rate
= wwo
->format
.wf
.nSamplesPerSec
;
933 params
.format
.voices
= (wwo
->format
.wf
.nChannels
> 1) ? 2 : 1;
934 params
.format
.special
= 0;
936 if (snd_pcm_channel_params(wwo
->handle
, ¶ms
))
938 ERR("Can't set params: %s\n", snd_strerror(errno
));
939 snd_pcm_close(wwo
->handle
);
941 return MMSYSERR_INVALPARAM
;
945 if (params
.format
.rate
!= format
!= ((wwo
->format
.wBitsPerSample
== 16) ? AFMT_S16_LE
: AFMT_U8
))
946 ERR("Can't set format to %d (%d)\n",
947 (wwo
->format
.wBitsPerSample
== 16) ? AFMT_S16_LE
: AFMT_U8
, format
);
948 if (dsp_stereo
!= (wwo
->format
.wf
.nChannels
> 1) ? 1 : 0)
949 ERR("Can't set stereo to %u (%d)\n",
950 (wwo
->format
.wf
.nChannels
> 1) ? 1 : 0, dsp_stereo
);
951 if (!NEAR_MATCH(sample_rate
, wwo
->format
.wf
.nSamplesPerSec
))
952 ERR("Can't set sample_rate to %lu (%d)\n",
953 wwo
->format
.wf
.nSamplesPerSec
, sample_rate
);
956 snd_pcm_playback_prepare(wwo
->handle
);
958 /* Remember fragsize and total buffer size for future use */
959 wwo
->dwBufferSize
= params
.buf
.stream
.queue_size
;
960 /* FIXME: should get rid off fragment size */
961 wwo
->dwFragmentSize
= wwo
->dwBufferSize
>> 4; /* why not */
962 wwo
->dwPlayedTotal
= 0;
963 wwo
->dwWrittenTotal
= 0;
964 wwo
->lpQueuePtr
= wwo
->lpPlayPtr
= wwo
->lpLoopPtr
= NULL
;
966 ALSA_InitRingMessage(&wwo
->msgRing
);
968 if (!(dwFlags
& WAVE_DIRECTSOUND
)) {
969 wwo
->hStartUpEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
970 wwo
->hThread
= CreateThread(NULL
, 0, wodPlayer
, (LPVOID
)(DWORD
)wDevID
, 0, &(wwo
->dwThreadID
));
971 WaitForSingleObject(wwo
->hStartUpEvent
, INFINITE
);
972 CloseHandle(wwo
->hStartUpEvent
);
974 wwo
->hThread
= INVALID_HANDLE_VALUE
;
977 wwo
->hStartUpEvent
= INVALID_HANDLE_VALUE
;
979 TRACE("handle=%08lx fragmentSize=%ld\n",
980 (DWORD
)wwo
->handle
, wwo
->dwFragmentSize
);
981 if (wwo
->dwFragmentSize
% wwo
->format
.wf
.nBlockAlign
)
982 ERR("Fragment doesn't contain an integral number of data blocks\n");
984 TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
985 wwo
->format
.wBitsPerSample
, wwo
->format
.wf
.nAvgBytesPerSec
,
986 wwo
->format
.wf
.nSamplesPerSec
, wwo
->format
.wf
.nChannels
,
987 wwo
->format
.wf
.nBlockAlign
);
989 return wodNotifyClient(wwo
, WOM_OPEN
, 0L, 0L);
992 /**************************************************************************
993 * wodClose [internal]
995 static DWORD
wodClose(WORD wDevID
)
997 DWORD ret
= MMSYSERR_NOERROR
;
1000 TRACE("(%u);\n", wDevID
);
1002 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].handle
== NULL
) {
1003 WARN("bad device ID !\n");
1004 return MMSYSERR_BADDEVICEID
;
1007 wwo
= &WOutDev
[wDevID
];
1008 if (wwo
->lpQueuePtr
) {
1009 WARN("buffers still playing !\n");
1010 ret
= WAVERR_STILLPLAYING
;
1012 if (wwo
->hThread
!= INVALID_HANDLE_VALUE
) {
1013 ALSA_AddRingMessage(&wwo
->msgRing
, WINE_WM_CLOSING
, 0, TRUE
);
1015 if (wwo
->mmap_buffer
) {
1016 snd_pcm_munmap(wwo
->handle
, SND_PCM_CHANNEL_PLAYBACK
);
1017 wwo
->mmap_buffer
= wwo
->mmap_control
= NULL
;
1020 ALSA_DestroyRingMessage(&wwo
->msgRing
);
1022 snd_pcm_close(wwo
->handle
);
1024 wwo
->dwFragmentSize
= 0;
1025 ret
= wodNotifyClient(wwo
, WOM_CLOSE
, 0L, 0L);
1030 /**************************************************************************
1031 * wodWrite [internal]
1034 static DWORD
wodWrite(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
1036 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
1038 /* first, do the sanity checks... */
1039 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].handle
== NULL
) {
1040 WARN("bad dev ID !\n");
1041 return MMSYSERR_BADDEVICEID
;
1044 if (lpWaveHdr
->lpData
== NULL
|| !(lpWaveHdr
->dwFlags
& WHDR_PREPARED
))
1045 return WAVERR_UNPREPARED
;
1047 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
)
1048 return WAVERR_STILLPLAYING
;
1050 lpWaveHdr
->dwFlags
&= ~WHDR_DONE
;
1051 lpWaveHdr
->dwFlags
|= WHDR_INQUEUE
;
1052 lpWaveHdr
->lpNext
= 0;
1054 ALSA_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_HEADER
, (DWORD
)lpWaveHdr
, FALSE
);
1056 return MMSYSERR_NOERROR
;
1059 /**************************************************************************
1060 * wodPrepare [internal]
1062 static DWORD
wodPrepare(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
1064 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
1066 if (wDevID
>= MAX_WAVEOUTDRV
) {
1067 WARN("bad device ID !\n");
1068 return MMSYSERR_BADDEVICEID
;
1071 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
)
1072 return WAVERR_STILLPLAYING
;
1074 lpWaveHdr
->dwFlags
|= WHDR_PREPARED
;
1075 lpWaveHdr
->dwFlags
&= ~WHDR_DONE
;
1076 return MMSYSERR_NOERROR
;
1079 /**************************************************************************
1080 * wodUnprepare [internal]
1082 static DWORD
wodUnprepare(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
1084 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
1086 if (wDevID
>= MAX_WAVEOUTDRV
) {
1087 WARN("bad device ID !\n");
1088 return MMSYSERR_BADDEVICEID
;
1091 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
)
1092 return WAVERR_STILLPLAYING
;
1094 lpWaveHdr
->dwFlags
&= ~WHDR_PREPARED
;
1095 lpWaveHdr
->dwFlags
|= WHDR_DONE
;
1097 return MMSYSERR_NOERROR
;
1100 /**************************************************************************
1101 * wodPause [internal]
1103 static DWORD
wodPause(WORD wDevID
)
1105 TRACE("(%u);!\n", wDevID
);
1107 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].handle
== NULL
) {
1108 WARN("bad device ID !\n");
1109 return MMSYSERR_BADDEVICEID
;
1112 ALSA_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_PAUSING
, 0, TRUE
);
1114 return MMSYSERR_NOERROR
;
1117 /**************************************************************************
1118 * wodRestart [internal]
1120 static DWORD
wodRestart(WORD wDevID
)
1122 TRACE("(%u);\n", wDevID
);
1124 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].handle
== NULL
) {
1125 WARN("bad device ID !\n");
1126 return MMSYSERR_BADDEVICEID
;
1129 if (WOutDev
[wDevID
].state
== WINE_WS_PAUSED
) {
1130 ALSA_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_RESTARTING
, 0, TRUE
);
1133 /* FIXME: is NotifyClient with WOM_DONE right ? (Comet Busters 1.3.3 needs this notification) */
1134 /* FIXME: Myst crashes with this ... hmm -MM
1135 return wodNotifyClient(wwo, WOM_DONE, 0L, 0L);
1138 return MMSYSERR_NOERROR
;
1141 /**************************************************************************
1142 * wodReset [internal]
1144 static DWORD
wodReset(WORD wDevID
)
1146 TRACE("(%u);\n", wDevID
);
1148 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].handle
== NULL
) {
1149 WARN("bad device ID !\n");
1150 return MMSYSERR_BADDEVICEID
;
1153 ALSA_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_RESETTING
, 0, TRUE
);
1155 return MMSYSERR_NOERROR
;
1158 /**************************************************************************
1159 * wodGetPosition [internal]
1161 static DWORD
wodGetPosition(WORD wDevID
, LPMMTIME lpTime
, DWORD uSize
)
1167 TRACE("(%u, %p, %lu);\n", wDevID
, lpTime
, uSize
);
1169 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].handle
== NULL
) {
1170 WARN("bad device ID !\n");
1171 return MMSYSERR_BADDEVICEID
;
1174 if (lpTime
== NULL
) return MMSYSERR_INVALPARAM
;
1176 wwo
= &WOutDev
[wDevID
];
1177 ALSA_AddRingMessage(&wwo
->msgRing
, WINE_WM_UPDATE
, 0, TRUE
);
1178 val
= wwo
->dwPlayedTotal
;
1180 TRACE("wType=%04X wBitsPerSample=%u nSamplesPerSec=%lu nChannels=%u nAvgBytesPerSec=%lu\n",
1181 lpTime
->wType
, wwo
->format
.wBitsPerSample
,
1182 wwo
->format
.wf
.nSamplesPerSec
, wwo
->format
.wf
.nChannels
,
1183 wwo
->format
.wf
.nAvgBytesPerSec
);
1184 TRACE("dwPlayedTotal=%lu\n", val
);
1186 switch (lpTime
->wType
) {
1189 TRACE("TIME_BYTES=%lu\n", lpTime
->u
.cb
);
1192 lpTime
->u
.sample
= val
* 8 / wwo
->format
.wBitsPerSample
/wwo
->format
.wf
.nChannels
;
1193 TRACE("TIME_SAMPLES=%lu\n", lpTime
->u
.sample
);
1196 time
= val
/ (wwo
->format
.wf
.nAvgBytesPerSec
/ 1000);
1197 lpTime
->u
.smpte
.hour
= time
/ 108000;
1198 time
-= lpTime
->u
.smpte
.hour
* 108000;
1199 lpTime
->u
.smpte
.min
= time
/ 1800;
1200 time
-= lpTime
->u
.smpte
.min
* 1800;
1201 lpTime
->u
.smpte
.sec
= time
/ 30;
1202 time
-= lpTime
->u
.smpte
.sec
* 30;
1203 lpTime
->u
.smpte
.frame
= time
;
1204 lpTime
->u
.smpte
.fps
= 30;
1205 TRACE("TIME_SMPTE=%02u:%02u:%02u:%02u\n",
1206 lpTime
->u
.smpte
.hour
, lpTime
->u
.smpte
.min
,
1207 lpTime
->u
.smpte
.sec
, lpTime
->u
.smpte
.frame
);
1210 FIXME("Format %d not supported ! use TIME_MS !\n", lpTime
->wType
);
1211 lpTime
->wType
= TIME_MS
;
1213 lpTime
->u
.ms
= val
/ (wwo
->format
.wf
.nAvgBytesPerSec
/ 1000);
1214 TRACE("TIME_MS=%lu\n", lpTime
->u
.ms
);
1217 return MMSYSERR_NOERROR
;
1220 /**************************************************************************
1221 * wodBreakLoop [internal]
1223 static DWORD
wodBreakLoop(WORD wDevID
)
1225 TRACE("(%u);\n", wDevID
);
1227 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].handle
== NULL
) {
1228 WARN("bad device ID !\n");
1229 return MMSYSERR_BADDEVICEID
;
1231 ALSA_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_BREAKLOOP
, 0, TRUE
);
1232 return MMSYSERR_NOERROR
;
1235 /**************************************************************************
1236 * wodGetVolume [internal]
1238 static DWORD
wodGetVolume(WORD wDevID
, LPDWORD lpdwVol
)
1246 TRACE("(%u, %p);\n", wDevID
, lpdwVol
);
1248 if (lpdwVol
== NULL
)
1249 return MMSYSERR_NOTENABLED
;
1252 if ((mixer
= open(MIXER_DEV
, O_RDONLY
|O_NDELAY
)) < 0) {
1253 WARN("mixer device not available !\n");
1254 return MMSYSERR_NOTENABLED
;
1256 if (ioctl(mixer
, SOUND_MIXER_READ_PCM
, &volume
) == -1) {
1257 WARN("unable to read mixer !\n");
1258 return MMSYSERR_NOTENABLED
;
1264 left
= LOBYTE(volume
);
1265 right
= HIBYTE(volume
);
1266 TRACE("left=%ld right=%ld !\n", left
, right
);
1267 *lpdwVol
= ((left
* 0xFFFFl
) / 100) + (((right
* 0xFFFFl
) / 100) << 16);
1268 return MMSYSERR_NOERROR
;
1271 /**************************************************************************
1272 * wodSetVolume [internal]
1274 static DWORD
wodSetVolume(WORD wDevID
, DWORD dwParam
)
1282 TRACE("(%u, %08lX);\n", wDevID
, dwParam
);
1284 left
= (LOWORD(dwParam
) * 100) / 0xFFFFl
;
1285 right
= (HIWORD(dwParam
) * 100) / 0xFFFFl
;
1286 volume
= left
+ (right
<< 8);
1290 if ((mixer
= open(MIXER_DEV
, O_WRONLY
|O_NDELAY
)) < 0) {
1291 WARN("mixer device not available !\n");
1292 return MMSYSERR_NOTENABLED
;
1294 if (ioctl(mixer
, SOUND_MIXER_WRITE_PCM
, &volume
) == -1) {
1295 WARN("unable to set mixer !\n");
1296 return MMSYSERR_NOTENABLED
;
1298 TRACE("volume=%04x\n", (unsigned)volume
);
1302 return MMSYSERR_NOERROR
;
1305 /**************************************************************************
1306 * wodGetNumDevs [internal]
1308 static DWORD
wodGetNumDevs(void)
1310 return ALSA_WodNumDevs
;
1313 /**************************************************************************
1314 * wodMessage (WINEALSA.@)
1316 DWORD WINAPI
ALSA_wodMessage(UINT wDevID
, UINT wMsg
, DWORD dwUser
,
1317 DWORD dwParam1
, DWORD dwParam2
)
1319 TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
1320 wDevID
, wMsg
, dwUser
, dwParam1
, dwParam2
);
1327 /* FIXME: Pretend this is supported */
1329 case WODM_OPEN
: return wodOpen (wDevID
, (LPWAVEOPENDESC
)dwParam1
, dwParam2
);
1330 case WODM_CLOSE
: return wodClose (wDevID
);
1331 case WODM_WRITE
: return wodWrite (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
1332 case WODM_PAUSE
: return wodPause (wDevID
);
1333 case WODM_GETPOS
: return wodGetPosition (wDevID
, (LPMMTIME
)dwParam1
, dwParam2
);
1334 case WODM_BREAKLOOP
: return wodBreakLoop (wDevID
);
1335 case WODM_PREPARE
: return wodPrepare (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
1336 case WODM_UNPREPARE
: return wodUnprepare (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
1337 case WODM_GETDEVCAPS
: return wodGetDevCaps (wDevID
, (LPWAVEOUTCAPSW
)dwParam1
, dwParam2
);
1338 case WODM_GETNUMDEVS
: return wodGetNumDevs ();
1339 case WODM_GETPITCH
: return MMSYSERR_NOTSUPPORTED
;
1340 case WODM_SETPITCH
: return MMSYSERR_NOTSUPPORTED
;
1341 case WODM_GETPLAYBACKRATE
: return MMSYSERR_NOTSUPPORTED
;
1342 case WODM_SETPLAYBACKRATE
: return MMSYSERR_NOTSUPPORTED
;
1343 case WODM_GETVOLUME
: return wodGetVolume (wDevID
, (LPDWORD
)dwParam1
);
1344 case WODM_SETVOLUME
: return wodSetVolume (wDevID
, dwParam1
);
1345 case WODM_RESTART
: return wodRestart (wDevID
);
1346 case WODM_RESET
: return wodReset (wDevID
);
1348 case DRV_QUERYDSOUNDIFACE
: return wodDsCreate(wDevID
, (PIDSDRIVER
*)dwParam1
);
1350 FIXME("unknown message %d!\n", wMsg
);
1352 return MMSYSERR_NOTSUPPORTED
;
1355 /*======================================================================*
1356 * Low level DSOUND implementation *
1357 *======================================================================*/
1359 typedef struct IDsDriverImpl IDsDriverImpl
;
1360 typedef struct IDsDriverBufferImpl IDsDriverBufferImpl
;
1362 struct IDsDriverImpl
1364 /* IUnknown fields */
1365 IDsDriverVtbl
*lpVtbl
;
1367 /* IDsDriverImpl fields */
1369 IDsDriverBufferImpl
*primary
;
1372 struct IDsDriverBufferImpl
1374 /* IUnknown fields */
1375 IDsDriverBufferVtbl
*lpVtbl
;
1377 /* IDsDriverBufferImpl fields */
1382 static HRESULT
DSDB_UnmapPrimary(IDsDriverBufferImpl
*dsdb
)
1384 WINE_WAVEOUT
*wwo
= &(WOutDev
[dsdb
->drv
->wDevID
]);
1385 if (wwo
->mmap_buffer
) {
1386 if (snd_pcm_munmap(wwo
->handle
, SND_PCM_CHANNEL_PLAYBACK
) < 0) {
1387 ERR("(%p): Could not unmap sound device (errno=%d)\n", dsdb
, errno
);
1388 return DSERR_GENERIC
;
1390 wwo
->mmap_buffer
= wwo
->mmap_control
= NULL
;
1391 TRACE("(%p): sound device unmapped\n", dsdb
);
1396 static HRESULT WINAPI
IDsDriverBufferImpl_QueryInterface(PIDSDRIVERBUFFER iface
, REFIID riid
, LPVOID
*ppobj
)
1398 /* IDsDriverBufferImpl *This = (IDsDriverBufferImpl *)iface; */
1399 FIXME("(): stub!\n");
1400 return DSERR_UNSUPPORTED
;
1403 static ULONG WINAPI
IDsDriverBufferImpl_AddRef(PIDSDRIVERBUFFER iface
)
1405 IDsDriverBufferImpl
*This
= (IDsDriverBufferImpl
*)iface
;
1410 static ULONG WINAPI
IDsDriverBufferImpl_Release(PIDSDRIVERBUFFER iface
)
1412 IDsDriverBufferImpl
*This
= (IDsDriverBufferImpl
*)iface
;
1415 if (This
== This
->drv
->primary
)
1416 This
->drv
->primary
= NULL
;
1417 DSDB_UnmapPrimary(This
);
1418 HeapFree(GetProcessHeap(),0,This
);
1422 static HRESULT WINAPI
IDsDriverBufferImpl_Lock(PIDSDRIVERBUFFER iface
,
1423 LPVOID
*ppvAudio1
,LPDWORD pdwLen1
,
1424 LPVOID
*ppvAudio2
,LPDWORD pdwLen2
,
1425 DWORD dwWritePosition
,DWORD dwWriteLen
,
1428 /* IDsDriverBufferImpl *This = (IDsDriverBufferImpl *)iface; */
1429 /* FIXME: we need to implement it */
1430 TRACE("(%p)\n",iface
);
1431 return DSERR_UNSUPPORTED
;
1434 static HRESULT WINAPI
IDsDriverBufferImpl_Unlock(PIDSDRIVERBUFFER iface
,
1435 LPVOID pvAudio1
,DWORD dwLen1
,
1436 LPVOID pvAudio2
,DWORD dwLen2
)
1438 /* IDsDriverBufferImpl *This = (IDsDriverBufferImpl *)iface; */
1439 TRACE("(%p)\n",iface
);
1440 return DSERR_UNSUPPORTED
;
1443 static HRESULT WINAPI
IDsDriverBufferImpl_SetFormat(PIDSDRIVERBUFFER iface
,
1444 LPWAVEFORMATEX pwfx
)
1446 /* IDsDriverBufferImpl *This = (IDsDriverBufferImpl *)iface; */
1448 TRACE("(%p,%p)\n",iface
,pwfx
);
1449 /* On our request (GetDriverDesc flags), DirectSound has by now used
1450 * waveOutClose/waveOutOpen to set the format...
1451 * unfortunately, this means our mmap() is now gone...
1452 * so we need to somehow signal to our DirectSound implementation
1453 * that it should completely recreate this HW buffer...
1454 * this unexpected error code should do the trick... */
1455 return DSERR_BUFFERLOST
;
1458 static HRESULT WINAPI
IDsDriverBufferImpl_SetFrequency(PIDSDRIVERBUFFER iface
, DWORD dwFreq
)
1460 /* IDsDriverBufferImpl *This = (IDsDriverBufferImpl *)iface; */
1461 TRACE("(%p,%ld): stub\n",iface
,dwFreq
);
1462 return DSERR_UNSUPPORTED
;
1465 static HRESULT WINAPI
IDsDriverBufferImpl_SetVolumePan(PIDSDRIVERBUFFER iface
, PDSVOLUMEPAN pVolPan
)
1467 /* IDsDriverBufferImpl *This = (IDsDriverBufferImpl *)iface; */
1468 FIXME("(%p,%p): stub!\n",iface
,pVolPan
);
1469 return DSERR_UNSUPPORTED
;
1472 static HRESULT WINAPI
IDsDriverBufferImpl_SetPosition(PIDSDRIVERBUFFER iface
, DWORD dwNewPos
)
1474 /* IDsDriverImpl *This = (IDsDriverImpl *)iface; */
1475 TRACE("(%p,%ld): stub\n",iface
,dwNewPos
);
1476 return DSERR_UNSUPPORTED
;
1479 static HRESULT WINAPI
IDsDriverBufferImpl_GetPosition(PIDSDRIVERBUFFER iface
,
1480 LPDWORD lpdwPlay
, LPDWORD lpdwWrite
)
1483 IDsDriverBufferImpl
*This
= (IDsDriverBufferImpl
*)iface
;
1488 TRACE("(%p)\n",iface
);
1489 if (WOutDev
[This
->drv
->wDevID
].handle
== NULL
) {
1490 ERR("device not open, but accessing?\n");
1491 return DSERR_UNINITIALIZED
;
1493 if (ioctl(WOutDev
[This
->drv
->wDevID
].unixdev
, SNDCTL_DSP_GETOPTR
, &info
) < 0) {
1494 ERR("ioctl failed (%d)\n", errno
);
1495 return DSERR_GENERIC
;
1497 ptr
= info
.ptr
& ~3; /* align the pointer, just in case */
1498 if (lpdwPlay
) *lpdwPlay
= ptr
;
1500 /* add some safety margin (not strictly necessary, but...) */
1501 if (WOutDev
[This
->drv
->wDevID
].caps
.dwSupport
& WAVECAPS_SAMPLEACCURATE
)
1502 *lpdwWrite
= ptr
+ 32;
1504 *lpdwWrite
= ptr
+ WOutDev
[This
->drv
->wDevID
].dwFragmentSize
;
1505 while (*lpdwWrite
> This
->buflen
)
1506 *lpdwWrite
-= This
->buflen
;
1510 TRACE("playpos=%ld, writepos=%ld\n", lpdwPlay
?*lpdwPlay
:0, lpdwWrite
?*lpdwWrite
:0);
1514 static HRESULT WINAPI
IDsDriverBufferImpl_Play(PIDSDRIVERBUFFER iface
, DWORD dwRes1
, DWORD dwRes2
, DWORD dwFlags
)
1516 IDsDriverBufferImpl
*This
= (IDsDriverBufferImpl
*)iface
;
1518 TRACE("(%p,%lx,%lx,%lx)\n",iface
,dwRes1
,dwRes2
,dwFlags
);
1520 /* FIXME: error handling */
1521 snd_pcm_playback_go(WOutDev
[This
->drv
->wDevID
].handle
);
1526 static HRESULT WINAPI
IDsDriverBufferImpl_Stop(PIDSDRIVERBUFFER iface
)
1528 IDsDriverBufferImpl
*This
= (IDsDriverBufferImpl
*)iface
;
1530 TRACE("(%p)\n",iface
);
1532 /* no more playing */
1533 /* FIXME: error handling */
1534 snd_pcm_playback_drain(WOutDev
[This
->drv
->wDevID
].handle
);
1536 /* Most ALSA drivers just can't stop the playback without closing the device...
1537 * so we need to somehow signal to our DirectSound implementation
1538 * that it should completely recreate this HW buffer...
1539 * this unexpected error code should do the trick... */
1540 return DSERR_BUFFERLOST
;
1543 static IDsDriverBufferVtbl dsdbvt
=
1545 IDsDriverBufferImpl_QueryInterface
,
1546 IDsDriverBufferImpl_AddRef
,
1547 IDsDriverBufferImpl_Release
,
1548 IDsDriverBufferImpl_Lock
,
1549 IDsDriverBufferImpl_Unlock
,
1550 IDsDriverBufferImpl_SetFormat
,
1551 IDsDriverBufferImpl_SetFrequency
,
1552 IDsDriverBufferImpl_SetVolumePan
,
1553 IDsDriverBufferImpl_SetPosition
,
1554 IDsDriverBufferImpl_GetPosition
,
1555 IDsDriverBufferImpl_Play
,
1556 IDsDriverBufferImpl_Stop
1559 static HRESULT WINAPI
IDsDriverImpl_QueryInterface(PIDSDRIVER iface
, REFIID riid
, LPVOID
*ppobj
)
1561 /* IDsDriverImpl *This = (IDsDriverImpl *)iface; */
1562 FIXME("(%p): stub!\n",iface
);
1563 return DSERR_UNSUPPORTED
;
1566 static ULONG WINAPI
IDsDriverImpl_AddRef(PIDSDRIVER iface
)
1568 IDsDriverImpl
*This
= (IDsDriverImpl
*)iface
;
1573 static ULONG WINAPI
IDsDriverImpl_Release(PIDSDRIVER iface
)
1575 IDsDriverImpl
*This
= (IDsDriverImpl
*)iface
;
1578 HeapFree(GetProcessHeap(),0,This
);
1582 static HRESULT WINAPI
IDsDriverImpl_GetDriverDesc(PIDSDRIVER iface
, PDSDRIVERDESC pDesc
)
1584 IDsDriverImpl
*This
= (IDsDriverImpl
*)iface
;
1585 TRACE("(%p,%p)\n",iface
,pDesc
);
1586 pDesc
->dwFlags
= DSDDESC_DOMMSYSTEMOPEN
| DSDDESC_DOMMSYSTEMSETFORMAT
|
1587 DSDDESC_USESYSTEMMEMORY
;
1588 strcpy(pDesc
->szDesc
,"WineALSA DirectSound Driver");
1589 strcpy(pDesc
->szDrvName
,"winealsa.drv");
1590 pDesc
->dnDevNode
= WOutDev
[This
->wDevID
].waveDesc
.dnDevNode
;
1592 pDesc
->wReserved
= 0;
1593 pDesc
->ulDeviceNum
= This
->wDevID
;
1594 pDesc
->dwHeapType
= DSDHEAP_NOHEAP
;
1595 pDesc
->pvDirectDrawHeap
= NULL
;
1596 pDesc
->dwMemStartAddress
= 0;
1597 pDesc
->dwMemEndAddress
= 0;
1598 pDesc
->dwMemAllocExtra
= 0;
1599 pDesc
->pvReserved1
= NULL
;
1600 pDesc
->pvReserved2
= NULL
;
1604 static HRESULT WINAPI
IDsDriverImpl_Open(PIDSDRIVER iface
)
1606 IDsDriverImpl
*This
= (IDsDriverImpl
*)iface
;
1608 TRACE("(%p)\n",iface
);
1609 /* FIXME: error handling */
1610 snd_pcm_channel_prepare(WOutDev
[This
->wDevID
].handle
, SND_PCM_CHANNEL_PLAYBACK
);
1615 static HRESULT WINAPI
IDsDriverImpl_Close(PIDSDRIVER iface
)
1617 IDsDriverImpl
*This
= (IDsDriverImpl
*)iface
;
1618 TRACE("(%p)\n",iface
);
1619 if (This
->primary
) {
1620 ERR("problem with DirectSound: primary not released\n");
1621 return DSERR_GENERIC
;
1626 static HRESULT WINAPI
IDsDriverImpl_GetCaps(PIDSDRIVER iface
, PDSDRIVERCAPS pCaps
)
1628 /* IDsDriverImpl *This = (IDsDriverImpl *)iface; */
1629 TRACE("(%p,%p)\n",iface
,pCaps
);
1630 memset(pCaps
, 0, sizeof(*pCaps
));
1631 /* FIXME: need to check actual capabilities */
1632 pCaps
->dwFlags
= DSCAPS_PRIMARYMONO
| DSCAPS_PRIMARYSTEREO
|
1633 DSCAPS_PRIMARY8BIT
| DSCAPS_PRIMARY16BIT
;
1634 pCaps
->dwPrimaryBuffers
= 1;
1635 /* the other fields only apply to secondary buffers, which we don't support
1636 * (unless we want to mess with wavetable synthesizers and MIDI) */
1640 static HRESULT WINAPI
IDsDriverImpl_CreateSoundBuffer(PIDSDRIVER iface
,
1641 LPWAVEFORMATEX pwfx
,
1642 DWORD dwFlags
, DWORD dwCardAddress
,
1643 LPDWORD pdwcbBufferSize
,
1647 IDsDriverImpl
*This
= (IDsDriverImpl
*)iface
;
1648 IDsDriverBufferImpl
** ippdsdb
= (IDsDriverBufferImpl
**)ppvObj
;
1649 WINE_WAVEOUT
*wwo
= &(WOutDev
[This
->wDevID
]);
1650 struct snd_pcm_channel_setup setup
;
1652 TRACE("(%p,%p,%lx,%lx)\n",iface
,pwfx
,dwFlags
,dwCardAddress
);
1653 /* we only support primary buffers */
1654 if (!(dwFlags
& DSBCAPS_PRIMARYBUFFER
))
1655 return DSERR_UNSUPPORTED
;
1657 return DSERR_ALLOCATED
;
1658 if (dwFlags
& (DSBCAPS_CTRLFREQUENCY
| DSBCAPS_CTRLPAN
))
1659 return DSERR_CONTROLUNAVAIL
;
1661 *ippdsdb
= (IDsDriverBufferImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDsDriverBufferImpl
));
1662 if (*ippdsdb
== NULL
)
1663 return DSERR_OUTOFMEMORY
;
1664 (*ippdsdb
)->lpVtbl
= &dsdbvt
;
1665 (*ippdsdb
)->ref
= 1;
1666 (*ippdsdb
)->drv
= This
;
1668 if (!wwo
->mmap_buffer
) {
1669 if (snd_pcm_mmap(wwo
->handle
, SND_PCM_CHANNEL_PLAYBACK
, &wwo
->mmap_control
, &wwo
->mmap_buffer
))
1671 ERR("(%p): Could not map sound device for direct access (%s)\n", *ippdsdb
, snd_strerror(errno
));
1672 return DSERR_GENERIC
;
1675 setup
.mode
= SND_PCM_MODE_BLOCK
;
1676 setup
.channel
= SND_PCM_CHANNEL_PLAYBACK
;
1677 if (snd_pcm_channel_setup(wwo
->handle
, &setup
) < 0) {
1678 ERR("Unable to obtain setup\n");
1679 /* FIXME: resource cleanup */
1680 return DSERR_GENERIC
;
1682 wwo
->mmap_block_size
= setup
.buf
.block
.frag_size
;
1683 wwo
->mmap_block_number
= setup
.buf
.block
.frags
;
1685 TRACE("(%p): sound device has been mapped for direct access at %p, size=%d\n",
1686 *ippdsdb
, wwo
->mmap_buffer
, setup
.buf
.block
.frags
* setup
.buf
.block
.frag_size
);
1688 /* for some reason, es1371 and sblive! sometimes have junk in here.
1689 * clear it, or we get junk noise */
1690 /* some libc implementations are buggy: their memset reads from the buffer...
1691 * to work around it, we have to zero the block by hand. We don't do the expected:
1692 * memset(wwo->mapping, 0, wwo->maplen);
1695 char* p1
= wwo
->mapping
;
1696 unsigned len
= wwo
->maplen
;
1698 if (len
>= 16) /* so we can have at least a 4 long area to store... */
1700 /* the mmap:ed value is (at least) dword aligned
1701 * so, start filling the complete unsigned long:s
1704 unsigned long* p4
= (unsigned long*)p1
;
1706 while (b
--) *p4
++ = 0;
1707 /* prepare for filling the rest */
1709 p1
= (unsigned char*)p4
;
1711 /* in all cases, fill the remaining bytes */
1712 while (len
-- != 0) *p1
++ = 0;
1717 /* primary buffer is ready to go */
1718 *pdwcbBufferSize
= wwo
->mmap_block_size
* wwo
->mmap_block_number
;
1719 *ppbBuffer
= wwo
->mmap_buffer
;
1721 This
->primary
= *ippdsdb
;
1726 static HRESULT WINAPI
IDsDriverImpl_DuplicateSoundBuffer(PIDSDRIVER iface
,
1727 PIDSDRIVERBUFFER pBuffer
,
1730 /* IDsDriverImpl *This = (IDsDriverImpl *)iface; */
1731 TRACE("(%p,%p): stub\n",iface
,pBuffer
);
1732 return DSERR_INVALIDCALL
;
1735 static IDsDriverVtbl dsdvt
=
1737 IDsDriverImpl_QueryInterface
,
1738 IDsDriverImpl_AddRef
,
1739 IDsDriverImpl_Release
,
1740 IDsDriverImpl_GetDriverDesc
,
1742 IDsDriverImpl_Close
,
1743 IDsDriverImpl_GetCaps
,
1744 IDsDriverImpl_CreateSoundBuffer
,
1745 IDsDriverImpl_DuplicateSoundBuffer
1748 static DWORD
wodDsCreate(UINT wDevID
, PIDSDRIVER
* drv
)
1750 IDsDriverImpl
** idrv
= (IDsDriverImpl
**)drv
;
1752 /* the HAL isn't much better than the HEL if we can't do mmap() */
1753 if (!(WOutDev
[wDevID
].caps
.dwSupport
& WAVECAPS_DIRECTSOUND
)) {
1754 ERR("DirectSound flag not set\n");
1755 MESSAGE("This sound card's driver does not support direct access\n");
1756 MESSAGE("The (slower) DirectSound HEL mode will be used instead.\n");
1757 return MMSYSERR_NOTSUPPORTED
;
1760 *idrv
= (IDsDriverImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDsDriverImpl
));
1762 return MMSYSERR_NOMEM
;
1763 (*idrv
)->lpVtbl
= &dsdvt
;
1766 (*idrv
)->wDevID
= wDevID
;
1767 (*idrv
)->primary
= NULL
;
1768 return MMSYSERR_NOERROR
;
1771 /* we don't need a default wodMessage for audio when we don't have ALSA, the
1772 * audio.c file will provide it for us
1774 #endif /* HAVE_ALSA && interface == 0.5 */