1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 * Wine Driver for aRts Sound Server
4 * http://www.arts-project.org
6 * Copyright 1994 Martin Ayotte
7 * 1999 Eric Pouech (async playing in waveOut/waveIn)
8 * 2000 Eric Pouech (loops in waveOut)
9 * 2002 Chris Morgan (aRts version of this file)
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * with arts we cannot stop the audio that is already in
27 * the servers buffer, so to reduce delays during starting
28 * and stoppping of audio streams adjust the
29 * audio buffer size in the kde control center or in the
30 * artsd startup script
33 * pause in waveOut does not work correctly in loop mode
36 * implement wave-in support with artsc
39 /*#define EMULATE_SB16*/
52 #include "wine/winuser16.h"
57 #include "wine/debug.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(wave
);
65 #define BUFFER_SIZE 16 * 1024
66 #define SPACE_THRESHOLD 5 * 1024
68 #define MAX_WAVEOUTDRV (10)
70 /* state diagram for waveOut writing:
72 * +---------+-------------+---------------+---------------------------------+
73 * | state | function | event | new state |
74 * +---------+-------------+---------------+---------------------------------+
75 * | | open() | | STOPPED |
76 * | PAUSED | write() | | PAUSED |
77 * | STOPPED | write() | <thrd create> | PLAYING |
78 * | PLAYING | write() | HEADER | PLAYING |
79 * | (other) | write() | <error> | |
80 * | (any) | pause() | PAUSING | PAUSED |
81 * | PAUSED | restart() | RESTARTING | PLAYING (if no thrd => STOPPED) |
82 * | (any) | reset() | RESETTING | STOPPED |
83 * | (any) | close() | CLOSING | CLOSED |
84 * +---------+-------------+---------------+---------------------------------+
87 /* states of the playing device */
88 #define WINE_WS_PLAYING 0
89 #define WINE_WS_PAUSED 1
90 #define WINE_WS_STOPPED 2
91 #define WINE_WS_CLOSED 3
93 /* events to be send to device */
95 WINE_WM_PAUSING
= WM_USER
+ 1, WINE_WM_RESTARTING
, WINE_WM_RESETTING
, WINE_WM_HEADER
,
96 WINE_WM_UPDATE
, WINE_WM_BREAKLOOP
, WINE_WM_CLOSING
100 enum win_wm_message msg
; /* message identifier */
101 DWORD param
; /* parameter for this message */
102 HANDLE hEvent
; /* if message is synchronous, handle of event for synchro */
105 /* implement an in-process message ring for better performance
106 * (compared to passing thru the server)
107 * this ring will be used by the input (resp output) record (resp playback) routine
110 #define ARTS_RING_BUFFER_SIZE 30
111 RING_MSG messages
[ARTS_RING_BUFFER_SIZE
];
115 CRITICAL_SECTION msg_crst
;
119 volatile int state
; /* one of the WINE_WS_ manifest constants */
120 WAVEOPENDESC waveDesc
;
122 PCMWAVEFORMAT format
;
125 /* arts information */
126 arts_stream_t play_stream
; /* the stream structure we get from arts when opening a stream for playing */
127 DWORD dwBufferSize
; /* size of whole buffer in bytes */
133 DWORD volume_left
; /* volume control information */
136 LPWAVEHDR lpQueuePtr
; /* start of queued WAVEHDRs (waiting to be notified) */
137 LPWAVEHDR lpPlayPtr
; /* start of not yet fully played buffers */
138 DWORD dwPartialOffset
; /* Offset of not yet written bytes in lpPlayPtr */
140 LPWAVEHDR lpLoopPtr
; /* pointer of first buffer in loop, if any */
141 DWORD dwLoops
; /* private copy of loop counter */
143 DWORD dwPlayedTotal
; /* number of bytes actually played since opening */
144 DWORD dwWrittenTotal
; /* number of bytes written to the audio device since opening */
146 /* synchronization stuff */
147 HANDLE hStartUpEvent
;
150 ARTS_MSG_RING msgRing
;
153 static WINE_WAVEOUT WOutDev
[MAX_WAVEOUTDRV
];
155 static DWORD
wodDsCreate(UINT wDevID
, PIDSDRIVER
* drv
);
157 /* These strings used only for tracing */
158 static const char *wodPlayerCmdString
[] = {
160 "WINE_WM_RESTARTING",
168 /*======================================================================*
169 * Low level WAVE implementation *
170 *======================================================================*/
172 /* Volume functions derived from Alsaplayer source */
173 /* length is the number of 16 bit samples */
174 void volume_effect16(void *bufin
, void* bufout
, int length
, int left
,
175 int right
, int nChannels
)
177 short *d_out
= (short *)bufout
;
178 short *d_in
= (short *)bufin
;
182 TRACE("length == %d, nChannels == %d\n", length, nChannels);
185 if (right
== -1) right
= left
;
187 for(i
= 0; i
< length
; i
+=(nChannels
))
189 v
= (int) ((*(d_in
++) * left
) / 100);
190 *(d_out
++) = (v
>32767) ? 32767 : ((v
<-32768) ? -32768 : v
);
193 v
= (int) ((*(d_in
++) * right
) / 100);
194 *(d_out
++) = (v
>32767) ? 32767 : ((v
<-32768) ? -32768 : v
);
199 /* length is the number of 8 bit samples */
200 void volume_effect8(void *bufin
, void* bufout
, int length
, int left
,
201 int right
, int nChannels
)
203 char *d_out
= (char *)bufout
;
204 char *d_in
= (char *)bufin
;
208 TRACE("length == %d, nChannels == %d\n", length, nChannels);
211 if (right
== -1) right
= left
;
213 for(i
= 0; i
< length
; i
+=(nChannels
))
215 v
= (char) ((*(d_in
++) * left
) / 100);
216 *(d_out
++) = (v
>255) ? 255 : ((v
<0) ? 0 : v
);
219 v
= (char) ((*(d_in
++) * right
) / 100);
220 *(d_out
++) = (v
>255) ? 255 : ((v
<0) ? 0 : v
);
225 /******************************************************************
229 void ARTS_CloseDevice(WINE_WAVEOUT
* wwo
)
231 arts_close_stream(wwo
->play_stream
); /* close the arts stream */
232 wwo
->play_stream
= (arts_stream_t
*)-1;
234 /* free up the buffer we use for volume and reset the size */
235 if(wwo
->sound_buffer
)
236 HeapFree(GetProcessHeap(), 0, wwo
->sound_buffer
);
238 wwo
->buffer_size
= 0;
241 /******************************************************************
244 static int ARTS_Init(void)
246 return arts_init(); /* initialize arts and return errorcode */
249 /******************************************************************
252 LONG
ARTS_WaveClose(void)
256 /* close all open devices */
257 for(iDevice
= 0; iDevice
< MAX_WAVEOUTDRV
; iDevice
++)
259 if(WOutDev
[iDevice
].play_stream
!= (arts_stream_t
*)-1)
261 ARTS_CloseDevice(&WOutDev
[iDevice
]);
265 arts_free(); /* free up arts */
269 /******************************************************************
272 * Initialize internal structures from ARTS server info
274 LONG
ARTS_WaveInit(void)
281 if ((errorcode
= ARTS_Init()) < 0)
283 ERR("arts_init() failed (%d)\n", errorcode
);
287 /* initialize all device handles to -1 */
288 for (i
= 0; i
< MAX_WAVEOUTDRV
; ++i
)
290 WOutDev
[i
].play_stream
= (arts_stream_t
*)-1;
291 memset(&WOutDev
[i
].caps
, 0, sizeof(WOutDev
[i
].caps
)); /* zero out
293 /* FIXME: some programs compare this string against the content of the registry
294 * for MM drivers. The names have to match in order for the program to work
295 * (e.g. MS win9x mplayer.exe)
298 WOutDev
[i
].caps
.wMid
= 0x0002;
299 WOutDev
[i
].caps
.wPid
= 0x0104;
300 strcpy(WOutDev
[i
].caps
.szPname
, "SB16 Wave Out");
302 WOutDev
[i
].caps
.wMid
= 0x00FF; /* Manufac ID */
303 WOutDev
[i
].caps
.wPid
= 0x0001; /* Product ID */
304 /* strcpy(WOutDev[i].caps.szPname, "OpenSoundSystem WAVOUT Driver");*/
305 strcpy(WOutDev
[i
].caps
.szPname
, "CS4236/37/38");
307 WOutDev
[i
].caps
.vDriverVersion
= 0x0100;
308 WOutDev
[i
].caps
.dwFormats
= 0x00000000;
309 WOutDev
[i
].caps
.dwSupport
= WAVECAPS_VOLUME
;
311 WOutDev
[i
].caps
.wChannels
= 2;
312 WOutDev
[i
].caps
.dwSupport
|= WAVECAPS_LRVOLUME
;
314 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_4M08
;
315 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_4S08
;
316 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_4S16
;
317 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_4M16
;
318 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_2M08
;
319 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_2S08
;
320 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_2M16
;
321 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_2S16
;
322 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_1M08
;
323 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_1S08
;
324 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_1M16
;
325 WOutDev
[i
].caps
.dwFormats
|= WAVE_FORMAT_1S16
;
332 /******************************************************************
333 * ARTS_InitRingMessage
335 * Initialize the ring of messages for passing between driver's caller and playback/record
338 static int ARTS_InitRingMessage(ARTS_MSG_RING
* mr
)
342 mr
->msg_event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
343 memset(mr
->messages
, 0, sizeof(RING_MSG
) * ARTS_RING_BUFFER_SIZE
);
344 InitializeCriticalSection(&mr
->msg_crst
);
348 /******************************************************************
349 * ARTS_DestroyRingMessage
352 static int ARTS_DestroyRingMessage(ARTS_MSG_RING
* mr
)
354 CloseHandle(mr
->msg_event
);
355 DeleteCriticalSection(&mr
->msg_crst
);
359 /******************************************************************
360 * ARTS_AddRingMessage
362 * Inserts a new message into the ring (should be called from DriverProc derivated routines)
364 static int ARTS_AddRingMessage(ARTS_MSG_RING
* mr
, enum win_wm_message msg
, DWORD param
, BOOL wait
)
366 HANDLE hEvent
= INVALID_HANDLE_VALUE
;
368 EnterCriticalSection(&mr
->msg_crst
);
369 if ((mr
->msg_toget
== ((mr
->msg_tosave
+ 1) % ARTS_RING_BUFFER_SIZE
))) /* buffer overflow? */
371 ERR("buffer overflow !?\n");
372 LeaveCriticalSection(&mr
->msg_crst
);
377 hEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
378 if (hEvent
== INVALID_HANDLE_VALUE
)
380 ERR("can't create event !?\n");
381 LeaveCriticalSection(&mr
->msg_crst
);
384 if (mr
->msg_toget
!= mr
->msg_tosave
&& mr
->messages
[mr
->msg_toget
].msg
!= WINE_WM_HEADER
)
385 FIXME("two fast messages in the queue!!!!\n");
387 /* fast messages have to be added at the start of the queue */
388 mr
->msg_toget
= (mr
->msg_toget
+ ARTS_RING_BUFFER_SIZE
- 1) % ARTS_RING_BUFFER_SIZE
;
390 mr
->messages
[mr
->msg_toget
].msg
= msg
;
391 mr
->messages
[mr
->msg_toget
].param
= param
;
392 mr
->messages
[mr
->msg_toget
].hEvent
= hEvent
;
396 mr
->messages
[mr
->msg_tosave
].msg
= msg
;
397 mr
->messages
[mr
->msg_tosave
].param
= param
;
398 mr
->messages
[mr
->msg_tosave
].hEvent
= INVALID_HANDLE_VALUE
;
399 mr
->msg_tosave
= (mr
->msg_tosave
+ 1) % ARTS_RING_BUFFER_SIZE
;
402 LeaveCriticalSection(&mr
->msg_crst
);
404 SetEvent(mr
->msg_event
); /* signal a new message */
408 /* wait for playback/record thread to have processed the message */
409 WaitForSingleObject(hEvent
, INFINITE
);
416 /******************************************************************
417 * ARTS_RetrieveRingMessage
419 * Get a message from the ring. Should be called by the playback/record thread.
421 static int ARTS_RetrieveRingMessage(ARTS_MSG_RING
* mr
,
422 enum win_wm_message
*msg
, DWORD
*param
, HANDLE
*hEvent
)
424 EnterCriticalSection(&mr
->msg_crst
);
426 if (mr
->msg_toget
== mr
->msg_tosave
) /* buffer empty ? */
428 LeaveCriticalSection(&mr
->msg_crst
);
432 *msg
= mr
->messages
[mr
->msg_toget
].msg
;
433 mr
->messages
[mr
->msg_toget
].msg
= 0;
434 *param
= mr
->messages
[mr
->msg_toget
].param
;
435 *hEvent
= mr
->messages
[mr
->msg_toget
].hEvent
;
436 mr
->msg_toget
= (mr
->msg_toget
+ 1) % ARTS_RING_BUFFER_SIZE
;
437 LeaveCriticalSection(&mr
->msg_crst
);
441 /*======================================================================*
442 * Low level WAVE OUT implementation *
443 *======================================================================*/
445 /**************************************************************************
446 * wodNotifyClient [internal]
448 static DWORD
wodNotifyClient(WINE_WAVEOUT
* wwo
, WORD wMsg
, DWORD dwParam1
, DWORD dwParam2
)
450 TRACE("wMsg = 0x%04x dwParm1 = %04lX dwParam2 = %04lX\n", wMsg
, dwParam1
, dwParam2
);
456 if (wwo
->wFlags
!= DCB_NULL
&&
457 !DriverCallback(wwo
->waveDesc
.dwCallback
, wwo
->wFlags
, wwo
->waveDesc
.hWave
,
458 wMsg
, wwo
->waveDesc
.dwInstance
, dwParam1
, dwParam2
)) {
459 WARN("can't notify client !\n");
460 return MMSYSERR_ERROR
;
464 FIXME("Unknown callback message %u\n", wMsg
);
465 return MMSYSERR_INVALPARAM
;
467 return MMSYSERR_NOERROR
;
470 /**************************************************************************
471 * wodUpdatePlayedTotal [internal]
474 static BOOL
wodUpdatePlayedTotal(WINE_WAVEOUT
* wwo
)
476 /* total played is the bytes written less the bytes to write ;-) */
477 wwo
->dwPlayedTotal
= wwo
->dwWrittenTotal
-
479 arts_stream_get(wwo
->play_stream
, ARTS_P_BUFFER_SPACE
));
484 /**************************************************************************
485 * wodPlayer_BeginWaveHdr [internal]
487 * Makes the specified lpWaveHdr the currently playing wave header.
488 * If the specified wave header is a begin loop and we're not already in
489 * a loop, setup the loop.
491 static void wodPlayer_BeginWaveHdr(WINE_WAVEOUT
* wwo
, LPWAVEHDR lpWaveHdr
)
493 wwo
->lpPlayPtr
= lpWaveHdr
;
495 if (!lpWaveHdr
) return;
497 if (lpWaveHdr
->dwFlags
& WHDR_BEGINLOOP
) {
498 if (wwo
->lpLoopPtr
) {
499 WARN("Already in a loop. Discarding loop on this header (%p)\n", lpWaveHdr
);
500 TRACE("Already in a loop. Discarding loop on this header (%p)\n", lpWaveHdr
);
502 TRACE("Starting loop (%ldx) with %p\n", lpWaveHdr
->dwLoops
, lpWaveHdr
);
503 wwo
->lpLoopPtr
= lpWaveHdr
;
504 /* Windows does not touch WAVEHDR.dwLoops,
505 * so we need to make an internal copy */
506 wwo
->dwLoops
= lpWaveHdr
->dwLoops
;
509 wwo
->dwPartialOffset
= 0;
512 /**************************************************************************
513 * wodPlayer_PlayPtrNext [internal]
515 * Advance the play pointer to the next waveheader, looping if required.
517 static LPWAVEHDR
wodPlayer_PlayPtrNext(WINE_WAVEOUT
* wwo
)
519 LPWAVEHDR lpWaveHdr
= wwo
->lpPlayPtr
;
521 wwo
->dwPartialOffset
= 0;
522 if ((lpWaveHdr
->dwFlags
& WHDR_ENDLOOP
) && wwo
->lpLoopPtr
) {
523 /* We're at the end of a loop, loop if required */
524 if (--wwo
->dwLoops
> 0) {
525 wwo
->lpPlayPtr
= wwo
->lpLoopPtr
;
527 /* Handle overlapping loops correctly */
528 if (wwo
->lpLoopPtr
!= lpWaveHdr
&& (lpWaveHdr
->dwFlags
& WHDR_BEGINLOOP
)) {
529 FIXME("Correctly handled case ? (ending loop buffer also starts a new loop)\n");
530 /* shall we consider the END flag for the closing loop or for
531 * the opening one or for both ???
532 * code assumes for closing loop only
535 lpWaveHdr
= lpWaveHdr
->lpNext
;
537 wwo
->lpLoopPtr
= NULL
;
538 wodPlayer_BeginWaveHdr(wwo
, lpWaveHdr
);
541 /* We're not in a loop. Advance to the next wave header */
542 wodPlayer_BeginWaveHdr(wwo
, lpWaveHdr
= lpWaveHdr
->lpNext
);
548 /**************************************************************************
549 * wodPlayer_DSPWait [internal]
550 * Returns the number of milliseconds to wait for the DSP buffer to clear.
551 * This is based on the number of fragments we want to be clear before
552 * writing and the number of free fragments we already have.
554 static DWORD
wodPlayer_DSPWait(const WINE_WAVEOUT
*wwo
)
556 int waitvalue
= (wwo
->dwBufferSize
- arts_stream_get(wwo
->play_stream
,
557 ARTS_P_BUFFER_SPACE
)) / ((wwo
->format
.wf
.nSamplesPerSec
*
558 wwo
->format
.wBitsPerSample
* wwo
->format
.wf
.nChannels
)
561 TRACE("wait value of %d\n", waitvalue
);
563 /* return the time left to play the buffer */
567 /**************************************************************************
568 * wodPlayer_NotifyWait [internal]
569 * Returns the number of milliseconds to wait before attempting to notify
570 * completion of the specified wavehdr.
571 * This is based on the number of bytes remaining to be written in the
574 static DWORD
wodPlayer_NotifyWait(const WINE_WAVEOUT
* wwo
, LPWAVEHDR lpWaveHdr
)
578 if(lpWaveHdr
->reserved
< wwo
->dwPlayedTotal
)
584 dwMillis
= (lpWaveHdr
->reserved
- wwo
->dwPlayedTotal
) * 1000 / wwo
->format
.wf
.nAvgBytesPerSec
;
585 if(!dwMillis
) dwMillis
= 1;
588 TRACE("dwMillis = %ld\n", dwMillis
);
594 /**************************************************************************
595 * wodPlayer_WriteMaxFrags [internal]
596 * Writes the maximum number of bytes possible to the DSP and returns
597 * the number of bytes written.
599 static int wodPlayer_WriteMaxFrags(WINE_WAVEOUT
* wwo
, DWORD
* bytes
)
601 /* Only attempt to write to free bytes */
602 DWORD dwLength
= wwo
->lpPlayPtr
->dwBufferLength
- wwo
->dwPartialOffset
;
603 int toWrite
= min(dwLength
, *bytes
);
606 TRACE("Writing wavehdr %p.%lu[%lu]\n",
607 wwo
->lpPlayPtr
, wwo
->dwPartialOffset
, wwo
->lpPlayPtr
->dwBufferLength
);
609 /* see if our buffer isn't large enough for the data we are writing */
610 if(wwo
->buffer_size
< toWrite
)
612 if(wwo
->sound_buffer
)
613 HeapFree(GetProcessHeap(), 0, wwo
->sound_buffer
);
616 /* if we don't have a buffer then get one */
617 if(!wwo
->sound_buffer
)
619 /* allocate some memory for the buffer */
620 wwo
->sound_buffer
= HeapAlloc(GetProcessHeap(), 0, toWrite
);
621 wwo
->buffer_size
= toWrite
;
624 /* if we don't have a buffer then error out */
625 if(!wwo
->sound_buffer
)
627 ERR("error allocating sound_buffer memory\n");
631 TRACE("toWrite == %d\n", toWrite
);
633 /* apply volume to the bits */
634 /* for single channel audio streams we only use the LEFT volume */
635 if(wwo
->format
.wBitsPerSample
== 16)
637 /* apply volume to the buffer we are about to send */
638 /* divide toWrite(bytes) by 2 as volume processes by 16 bits */
639 volume_effect16(wwo
->lpPlayPtr
->lpData
+ wwo
->dwPartialOffset
,
640 wwo
->sound_buffer
, toWrite
>>1, wwo
->volume_left
,
641 wwo
->volume_right
, wwo
->format
.wf
.nChannels
);
642 } else if(wwo
->format
.wBitsPerSample
== 8)
644 /* apply volume to the buffer we are about to send */
645 volume_effect8(wwo
->lpPlayPtr
->lpData
+ wwo
->dwPartialOffset
,
646 wwo
->sound_buffer
, toWrite
>>1, wwo
->volume_left
,
647 wwo
->volume_right
, wwo
->format
.wf
.nChannels
);
650 FIXME("unsupported wwo->format.wBitsPerSample of %d\n",
651 wwo
->format
.wBitsPerSample
);
654 /* send the audio data to arts for playing */
655 written
= arts_write(wwo
->play_stream
, wwo
->sound_buffer
, toWrite
);
657 TRACE("written = %d\n", written
);
659 if (written
<= 0) return written
; /* if we wrote nothing just return */
661 if (written
>= dwLength
)
662 wodPlayer_PlayPtrNext(wwo
); /* If we wrote all current wavehdr, skip to the next one */
664 wwo
->dwPartialOffset
+= written
; /* Remove the amount written */
667 wwo
->dwWrittenTotal
+= written
; /* update stats on this wave device */
669 return written
; /* return the number of bytes written */
673 /**************************************************************************
674 * wodPlayer_NotifyCompletions [internal]
676 * Notifies and remove from queue all wavehdrs which have been played to
677 * the speaker (ie. they have cleared the audio device). If force is true,
678 * we notify all wavehdrs and remove them all from the queue even if they
679 * are unplayed or part of a loop.
681 static DWORD
wodPlayer_NotifyCompletions(WINE_WAVEOUT
* wwo
, BOOL force
)
685 /* Start from lpQueuePtr and keep notifying until:
686 * - we hit an unwritten wavehdr
687 * - we hit the beginning of a running loop
688 * - we hit a wavehdr which hasn't finished playing
690 while ((lpWaveHdr
= wwo
->lpQueuePtr
) &&
692 (lpWaveHdr
!= wwo
->lpPlayPtr
&&
693 lpWaveHdr
!= wwo
->lpLoopPtr
&&
694 lpWaveHdr
->reserved
<= wwo
->dwPlayedTotal
))) {
696 wwo
->lpQueuePtr
= lpWaveHdr
->lpNext
;
698 lpWaveHdr
->dwFlags
&= ~WHDR_INQUEUE
;
699 lpWaveHdr
->dwFlags
|= WHDR_DONE
;
701 wodNotifyClient(wwo
, WOM_DONE
, (DWORD
)lpWaveHdr
, 0);
703 return (lpWaveHdr
&& lpWaveHdr
!= wwo
->lpPlayPtr
&& lpWaveHdr
!= wwo
->lpLoopPtr
) ?
704 wodPlayer_NotifyWait(wwo
, lpWaveHdr
) : INFINITE
;
707 /**************************************************************************
708 * wodPlayer_Reset [internal]
710 * wodPlayer helper. Resets current output stream.
712 static void wodPlayer_Reset(WINE_WAVEOUT
* wwo
, BOOL reset
)
714 wodUpdatePlayedTotal(wwo
);
716 wodPlayer_NotifyCompletions(wwo
, FALSE
); /* updates current notify list */
718 /* we aren't able to flush any data that has already been written */
719 /* to arts, otherwise we would do the flushing here */
722 enum win_wm_message msg
;
726 /* remove any buffer */
727 wodPlayer_NotifyCompletions(wwo
, TRUE
);
729 wwo
->lpPlayPtr
= wwo
->lpQueuePtr
= wwo
->lpLoopPtr
= NULL
;
730 wwo
->state
= WINE_WS_STOPPED
;
731 wwo
->dwPlayedTotal
= wwo
->dwWrittenTotal
= 0;
733 wwo
->dwPartialOffset
= 0; /* Clear partial wavehdr */
735 /* remove any existing message in the ring */
736 EnterCriticalSection(&wwo
->msgRing
.msg_crst
);
738 /* return all pending headers in queue */
739 while (ARTS_RetrieveRingMessage(&wwo
->msgRing
, &msg
, ¶m
, &ev
))
741 TRACE("flushing msg\n");
742 if (msg
!= WINE_WM_HEADER
)
744 FIXME("shouldn't have headers left\n");
748 ((LPWAVEHDR
)param
)->dwFlags
&= ~WHDR_INQUEUE
;
749 ((LPWAVEHDR
)param
)->dwFlags
|= WHDR_DONE
;
751 wodNotifyClient(wwo
, WOM_DONE
, param
, 0);
753 ResetEvent(wwo
->msgRing
.msg_event
);
754 LeaveCriticalSection(&wwo
->msgRing
.msg_crst
);
756 if (wwo
->lpLoopPtr
) {
757 /* complicated case, not handled yet (could imply modifying the loop counter */
758 FIXME("Pausing while in loop isn't correctly handled yet, except strange results\n");
759 wwo
->lpPlayPtr
= wwo
->lpLoopPtr
;
760 wwo
->dwPartialOffset
= 0;
761 wwo
->dwWrittenTotal
= wwo
->dwPlayedTotal
; /* this is wrong !!! */
763 /* the data already written is going to be played, so take */
764 /* this fact into account here */
765 wwo
->dwPlayedTotal
= wwo
->dwWrittenTotal
;
767 wwo
->state
= WINE_WS_PAUSED
;
771 /**************************************************************************
772 * wodPlayer_ProcessMessages [internal]
774 static void wodPlayer_ProcessMessages(WINE_WAVEOUT
* wwo
)
777 enum win_wm_message msg
;
781 while (ARTS_RetrieveRingMessage(&wwo
->msgRing
, &msg
, ¶m
, &ev
)) {
782 TRACE("Received %s %lx\n", wodPlayerCmdString
[msg
- WM_USER
- 1], param
);
784 case WINE_WM_PAUSING
:
785 wodPlayer_Reset(wwo
, FALSE
);
788 case WINE_WM_RESTARTING
:
789 wwo
->state
= WINE_WS_PLAYING
;
793 lpWaveHdr
= (LPWAVEHDR
)param
;
795 /* insert buffer at the end of queue */
798 for (wh
= &(wwo
->lpQueuePtr
); *wh
; wh
= &((*wh
)->lpNext
));
802 wodPlayer_BeginWaveHdr(wwo
,lpWaveHdr
);
803 if (wwo
->state
== WINE_WS_STOPPED
)
804 wwo
->state
= WINE_WS_PLAYING
;
806 case WINE_WM_RESETTING
:
807 wodPlayer_Reset(wwo
, TRUE
);
811 wodUpdatePlayedTotal(wwo
);
814 case WINE_WM_BREAKLOOP
:
815 if (wwo
->state
== WINE_WS_PLAYING
&& wwo
->lpLoopPtr
!= NULL
) {
816 /* ensure exit at end of current loop */
821 case WINE_WM_CLOSING
:
822 /* sanity check: this should not happen since the device must have been reset before */
823 if (wwo
->lpQueuePtr
|| wwo
->lpPlayPtr
) ERR("out of sync\n");
825 wwo
->state
= WINE_WS_CLOSED
;
828 /* shouldn't go here */
830 FIXME("unknown message %d\n", msg
);
836 /**************************************************************************
837 * wodPlayer_FeedDSP [internal]
838 * Feed as much sound data as we can into the DSP and return the number of
839 * milliseconds before it will be necessary to feed the DSP again.
841 static DWORD
wodPlayer_FeedDSP(WINE_WAVEOUT
* wwo
)
845 wodUpdatePlayedTotal(wwo
);
846 availInQ
= arts_stream_get(wwo
->play_stream
, ARTS_P_BUFFER_SPACE
);
847 TRACE("availInQ = %ld\n", availInQ
);
849 /* input queue empty and output buffer with no space */
850 if (!wwo
->lpPlayPtr
&& availInQ
) {
851 TRACE("Run out of wavehdr:s... flushing\n");
852 wwo
->dwPlayedTotal
= wwo
->dwWrittenTotal
;
856 /* no more room... no need to try to feed */
859 TRACE("no more room, no need to try to feed\n");
860 return wodPlayer_DSPWait(wwo
);
863 /* Feed from partial wavehdr */
864 if (wwo
->lpPlayPtr
&& wwo
->dwPartialOffset
!= 0)
866 TRACE("feeding from partial wavehdr\n");
867 wodPlayer_WriteMaxFrags(wwo
, &availInQ
);
870 /* Feed wavehdrs until we run out of wavehdrs or DSP space */
871 if (!wwo
->dwPartialOffset
)
873 while(wwo
->lpPlayPtr
&& availInQ
> SPACE_THRESHOLD
)
875 TRACE("feeding waveheaders until we run out of space\n");
876 /* note the value that dwPlayedTotal will return when this wave finishes playing */
877 wwo
->lpPlayPtr
->reserved
= wwo
->dwWrittenTotal
+ wwo
->lpPlayPtr
->dwBufferLength
;
878 wodPlayer_WriteMaxFrags(wwo
, &availInQ
);
882 return wodPlayer_DSPWait(wwo
);
886 /**************************************************************************
887 * wodPlayer [internal]
889 static DWORD CALLBACK
wodPlayer(LPVOID pmt
)
891 WORD uDevID
= (DWORD
)pmt
;
892 WINE_WAVEOUT
* wwo
= (WINE_WAVEOUT
*)&WOutDev
[uDevID
];
893 DWORD dwNextFeedTime
= INFINITE
; /* Time before DSP needs feeding */
894 DWORD dwNextNotifyTime
= INFINITE
; /* Time before next wave completion */
897 wwo
->state
= WINE_WS_STOPPED
;
898 SetEvent(wwo
->hStartUpEvent
);
901 /** Wait for the shortest time before an action is required. If there
902 * are no pending actions, wait forever for a command.
904 dwSleepTime
= min(dwNextFeedTime
, dwNextNotifyTime
);
905 TRACE("waiting %lums (%lu,%lu)\n", dwSleepTime
, dwNextFeedTime
, dwNextNotifyTime
);
906 WaitForSingleObject(wwo
->msgRing
.msg_event
, dwSleepTime
);
907 wodPlayer_ProcessMessages(wwo
);
908 if (wwo
->state
== WINE_WS_PLAYING
) {
909 dwNextFeedTime
= wodPlayer_FeedDSP(wwo
);
910 dwNextNotifyTime
= wodPlayer_NotifyCompletions(wwo
, FALSE
);
912 dwNextFeedTime
= dwNextNotifyTime
= INFINITE
;
917 /**************************************************************************
918 * wodGetDevCaps [internal]
920 static DWORD
wodGetDevCaps(WORD wDevID
, LPWAVEOUTCAPSA lpCaps
, DWORD dwSize
)
922 TRACE("(%u, %p, %lu);\n", wDevID
, lpCaps
, dwSize
);
924 if (lpCaps
== NULL
) return MMSYSERR_NOTENABLED
;
926 if (wDevID
>= MAX_WAVEOUTDRV
) {
927 TRACE("MAX_WAVOUTDRV reached !\n");
928 return MMSYSERR_BADDEVICEID
;
931 memcpy(lpCaps
, &WOutDev
[wDevID
].caps
, min(dwSize
, sizeof(*lpCaps
)));
932 return MMSYSERR_NOERROR
;
935 /**************************************************************************
938 static DWORD
wodOpen(WORD wDevID
, LPWAVEOPENDESC lpDesc
, DWORD dwFlags
)
942 TRACE("(%u, %p, %08lX);\n", wDevID
, lpDesc
, dwFlags
);
943 if (lpDesc
== NULL
) {
944 WARN("Invalid Parameter !\n");
945 return MMSYSERR_INVALPARAM
;
947 if (wDevID
>= MAX_WAVEOUTDRV
) {
948 TRACE("MAX_WAVOUTDRV reached !\n");
949 return MMSYSERR_BADDEVICEID
;
952 /* if this device is already open tell the app that it is allocated */
953 if(WOutDev
[wDevID
].play_stream
!= (arts_stream_t
*)-1)
955 TRACE("device already allocated\n");
956 return MMSYSERR_ALLOCATED
;
959 /* only PCM format is supported so far... */
960 if (lpDesc
->lpFormat
->wFormatTag
!= WAVE_FORMAT_PCM
||
961 lpDesc
->lpFormat
->nChannels
== 0 ||
962 lpDesc
->lpFormat
->nSamplesPerSec
== 0) {
963 WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
964 lpDesc
->lpFormat
->wFormatTag
, lpDesc
->lpFormat
->nChannels
,
965 lpDesc
->lpFormat
->nSamplesPerSec
);
966 return WAVERR_BADFORMAT
;
969 if (dwFlags
& WAVE_FORMAT_QUERY
) {
970 TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
971 lpDesc
->lpFormat
->wFormatTag
, lpDesc
->lpFormat
->nChannels
,
972 lpDesc
->lpFormat
->nSamplesPerSec
);
973 return MMSYSERR_NOERROR
;
976 wwo
= &WOutDev
[wDevID
];
978 /* direct sound not supported, ignore the flag */
979 dwFlags
&= ~WAVE_DIRECTSOUND
;
981 wwo
->wFlags
= HIWORD(dwFlags
& CALLBACK_TYPEMASK
);
983 memcpy(&wwo
->waveDesc
, lpDesc
, sizeof(WAVEOPENDESC
));
984 memcpy(&wwo
->format
, lpDesc
->lpFormat
, sizeof(PCMWAVEFORMAT
));
986 if (wwo
->format
.wBitsPerSample
== 0) {
987 WARN("Resetting zeroed wBitsPerSample\n");
988 wwo
->format
.wBitsPerSample
= 8 *
989 (wwo
->format
.wf
.nAvgBytesPerSec
/
990 wwo
->format
.wf
.nSamplesPerSec
) /
991 wwo
->format
.wf
.nChannels
;
994 wwo
->play_stream
= arts_play_stream(wwo
->format
.wf
.nSamplesPerSec
,
995 wwo
->format
.wBitsPerSample
, wwo
->format
.wf
.nChannels
, "winearts");
997 /* clear these so we don't have any confusion ;-) */
998 wwo
->sound_buffer
= 0;
999 wwo
->buffer_size
= 0;
1001 arts_stream_set(wwo
->play_stream
, ARTS_P_BLOCKING
, 0); /* disable blocking on this stream */
1003 if(!wwo
->play_stream
) return MMSYSERR_ALLOCATED
;
1005 /* Try to set buffer size from constant and store the value that it
1006 was set to for future use */
1007 wwo
->dwBufferSize
= arts_stream_set(wwo
->play_stream
,
1008 ARTS_P_BUFFER_SIZE
, BUFFER_SIZE
);
1009 TRACE("Tried to set BUFFER_SIZE of %d, wwo->dwBufferSize is actually %ld\n", BUFFER_SIZE
, wwo
->dwBufferSize
);
1010 wwo
->dwPlayedTotal
= 0;
1011 wwo
->dwWrittenTotal
= 0;
1013 ARTS_InitRingMessage(&wwo
->msgRing
);
1015 /* create player thread */
1016 if (!(dwFlags
& WAVE_DIRECTSOUND
)) {
1017 wwo
->hStartUpEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
1018 wwo
->hThread
= CreateThread(NULL
, 0, wodPlayer
, (LPVOID
)(DWORD
)wDevID
, 0, &(wwo
->dwThreadID
));
1019 WaitForSingleObject(wwo
->hStartUpEvent
, INFINITE
);
1020 CloseHandle(wwo
->hStartUpEvent
);
1022 wwo
->hThread
= INVALID_HANDLE_VALUE
;
1023 wwo
->dwThreadID
= 0;
1025 wwo
->hStartUpEvent
= INVALID_HANDLE_VALUE
;
1027 TRACE("stream=0x%lx, dwBufferSize=%ld\n",
1028 (long)wwo
->play_stream
, wwo
->dwBufferSize
);
1030 TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
1031 wwo
->format
.wBitsPerSample
, wwo
->format
.wf
.nAvgBytesPerSec
,
1032 wwo
->format
.wf
.nSamplesPerSec
, wwo
->format
.wf
.nChannels
,
1033 wwo
->format
.wf
.nBlockAlign
);
1035 return wodNotifyClient(wwo
, WOM_OPEN
, 0L, 0L);
1038 /**************************************************************************
1039 * wodClose [internal]
1041 static DWORD
wodClose(WORD wDevID
)
1043 DWORD ret
= MMSYSERR_NOERROR
;
1046 TRACE("(%u);\n", wDevID
);
1048 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].play_stream
==
1051 WARN("bad device ID !\n");
1052 return MMSYSERR_BADDEVICEID
;
1055 wwo
= &WOutDev
[wDevID
];
1056 if (wwo
->lpQueuePtr
) {
1057 WARN("buffers still playing !\n");
1058 ret
= WAVERR_STILLPLAYING
;
1060 TRACE("imhere[3-close]\n");
1061 if (wwo
->hThread
!= INVALID_HANDLE_VALUE
) {
1062 ARTS_AddRingMessage(&wwo
->msgRing
, WINE_WM_CLOSING
, 0, TRUE
);
1065 ARTS_DestroyRingMessage(&wwo
->msgRing
);
1067 ARTS_CloseDevice(wwo
); /* close the stream and clean things up */
1069 ret
= wodNotifyClient(wwo
, WOM_CLOSE
, 0L, 0L);
1074 /**************************************************************************
1075 * wodWrite [internal]
1078 static DWORD
wodWrite(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
1080 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
1082 /* first, do the sanity checks... */
1083 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].play_stream
==
1086 WARN("bad dev ID !\n");
1087 return MMSYSERR_BADDEVICEID
;
1090 if (lpWaveHdr
->lpData
== NULL
|| !(lpWaveHdr
->dwFlags
& WHDR_PREPARED
))
1092 TRACE("unprepared\n");
1093 return WAVERR_UNPREPARED
;
1096 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
)
1098 TRACE("still playing\n");
1099 return WAVERR_STILLPLAYING
;
1102 lpWaveHdr
->dwFlags
&= ~WHDR_DONE
;
1103 lpWaveHdr
->dwFlags
|= WHDR_INQUEUE
;
1104 lpWaveHdr
->lpNext
= 0;
1106 TRACE("adding ring message\n");
1107 ARTS_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_HEADER
, (DWORD
)lpWaveHdr
, FALSE
);
1109 return MMSYSERR_NOERROR
;
1112 /**************************************************************************
1113 * wodPrepare [internal]
1115 static DWORD
wodPrepare(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
1117 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
1119 if (wDevID
>= MAX_WAVEOUTDRV
) {
1120 WARN("bad device ID !\n");
1121 return MMSYSERR_BADDEVICEID
;
1124 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
)
1125 return WAVERR_STILLPLAYING
;
1127 lpWaveHdr
->dwFlags
|= WHDR_PREPARED
;
1128 lpWaveHdr
->dwFlags
&= ~WHDR_DONE
;
1129 return MMSYSERR_NOERROR
;
1132 /**************************************************************************
1133 * wodUnprepare [internal]
1135 static DWORD
wodUnprepare(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
1137 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
1139 if (wDevID
>= MAX_WAVEOUTDRV
) {
1140 WARN("bad device ID !\n");
1141 return MMSYSERR_BADDEVICEID
;
1144 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
)
1145 return WAVERR_STILLPLAYING
;
1147 lpWaveHdr
->dwFlags
&= ~WHDR_PREPARED
;
1148 lpWaveHdr
->dwFlags
|= WHDR_DONE
;
1150 return MMSYSERR_NOERROR
;
1153 /**************************************************************************
1154 * wodPause [internal]
1156 static DWORD
wodPause(WORD wDevID
)
1158 TRACE("(%u);!\n", wDevID
);
1160 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].play_stream
==
1163 WARN("bad device ID !\n");
1164 return MMSYSERR_BADDEVICEID
;
1167 TRACE("imhere[3-PAUSING]\n");
1168 ARTS_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_PAUSING
, 0, TRUE
);
1170 return MMSYSERR_NOERROR
;
1173 /**************************************************************************
1174 * wodRestart [internal]
1176 static DWORD
wodRestart(WORD wDevID
)
1178 TRACE("(%u);\n", wDevID
);
1180 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].play_stream
==
1183 WARN("bad device ID !\n");
1184 return MMSYSERR_BADDEVICEID
;
1187 if (WOutDev
[wDevID
].state
== WINE_WS_PAUSED
) {
1188 TRACE("imhere[3-RESTARTING]\n");
1189 ARTS_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_RESTARTING
, 0, TRUE
);
1192 /* FIXME: is NotifyClient with WOM_DONE right ? (Comet Busters 1.3.3 needs this notification) */
1193 /* FIXME: Myst crashes with this ... hmm -MM
1194 return wodNotifyClient(wwo, WOM_DONE, 0L, 0L);
1197 return MMSYSERR_NOERROR
;
1200 /**************************************************************************
1201 * wodReset [internal]
1203 static DWORD
wodReset(WORD wDevID
)
1205 TRACE("(%u);\n", wDevID
);
1207 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].play_stream
==
1210 WARN("bad device ID !\n");
1211 return MMSYSERR_BADDEVICEID
;
1214 TRACE("imhere[3-RESET]\n");
1215 ARTS_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_RESETTING
, 0, TRUE
);
1217 return MMSYSERR_NOERROR
;
1220 /**************************************************************************
1221 * wodGetPosition [internal]
1223 static DWORD
wodGetPosition(WORD wDevID
, LPMMTIME lpTime
, DWORD uSize
)
1229 TRACE("(%u, %p, %lu);\n", wDevID
, lpTime
, uSize
);
1231 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].play_stream
==
1234 WARN("bad device ID !\n");
1235 return MMSYSERR_BADDEVICEID
;
1238 if (lpTime
== NULL
) return MMSYSERR_INVALPARAM
;
1240 wwo
= &WOutDev
[wDevID
];
1241 ARTS_AddRingMessage(&wwo
->msgRing
, WINE_WM_UPDATE
, 0, TRUE
);
1242 val
= wwo
->dwPlayedTotal
;
1244 TRACE("wType=%04X wBitsPerSample=%u nSamplesPerSec=%lu nChannels=%u nAvgBytesPerSec=%lu\n",
1245 lpTime
->wType
, wwo
->format
.wBitsPerSample
,
1246 wwo
->format
.wf
.nSamplesPerSec
, wwo
->format
.wf
.nChannels
,
1247 wwo
->format
.wf
.nAvgBytesPerSec
);
1248 TRACE("dwPlayedTotal=%lu\n", val
);
1250 switch (lpTime
->wType
) {
1253 TRACE("TIME_BYTES=%lu\n", lpTime
->u
.cb
);
1256 lpTime
->u
.sample
= val
* 8 / wwo
->format
.wBitsPerSample
/wwo
->format
.wf
.nChannels
;
1257 TRACE("TIME_SAMPLES=%lu\n", lpTime
->u
.sample
);
1260 time
= val
/ (wwo
->format
.wf
.nAvgBytesPerSec
/ 1000);
1261 lpTime
->u
.smpte
.hour
= time
/ 108000;
1262 time
-= lpTime
->u
.smpte
.hour
* 108000;
1263 lpTime
->u
.smpte
.min
= time
/ 1800;
1264 time
-= lpTime
->u
.smpte
.min
* 1800;
1265 lpTime
->u
.smpte
.sec
= time
/ 30;
1266 time
-= lpTime
->u
.smpte
.sec
* 30;
1267 lpTime
->u
.smpte
.frame
= time
;
1268 lpTime
->u
.smpte
.fps
= 30;
1269 TRACE("TIME_SMPTE=%02u:%02u:%02u:%02u\n",
1270 lpTime
->u
.smpte
.hour
, lpTime
->u
.smpte
.min
,
1271 lpTime
->u
.smpte
.sec
, lpTime
->u
.smpte
.frame
);
1274 FIXME("Format %d not supported ! use TIME_MS !\n", lpTime
->wType
);
1275 lpTime
->wType
= TIME_MS
;
1277 lpTime
->u
.ms
= val
/ (wwo
->format
.wf
.nAvgBytesPerSec
/ 1000);
1278 TRACE("TIME_MS=%lu\n", lpTime
->u
.ms
);
1281 return MMSYSERR_NOERROR
;
1284 /**************************************************************************
1285 * wodBreakLoop [internal]
1287 static DWORD
wodBreakLoop(WORD wDevID
)
1289 TRACE("(%u);\n", wDevID
);
1291 if (wDevID
>= MAX_WAVEOUTDRV
|| WOutDev
[wDevID
].play_stream
==
1294 WARN("bad device ID !\n");
1295 return MMSYSERR_BADDEVICEID
;
1297 ARTS_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_BREAKLOOP
, 0, TRUE
);
1298 return MMSYSERR_NOERROR
;
1301 /**************************************************************************
1302 * wodGetVolume [internal]
1304 static DWORD
wodGetVolume(WORD wDevID
, LPDWORD lpdwVol
)
1308 left
= WOutDev
[wDevID
].volume_left
;
1309 right
= WOutDev
[wDevID
].volume_right
;
1311 TRACE("(%u, %p);\n", wDevID
, lpdwVol
);
1313 *lpdwVol
= ((left
* 0xFFFFl
) / 100) + (((right
* 0xFFFFl
) / 100) <<
1316 return MMSYSERR_NOERROR
;
1319 /**************************************************************************
1320 * wodSetVolume [internal]
1322 static DWORD
wodSetVolume(WORD wDevID
, DWORD dwParam
)
1326 left
= (LOWORD(dwParam
) * 100) / 0xFFFFl
;
1327 right
= (HIWORD(dwParam
) * 100) / 0xFFFFl
;
1329 TRACE("(%u, %08lX);\n", wDevID
, dwParam
);
1331 WOutDev
[wDevID
].volume_left
= left
;
1332 WOutDev
[wDevID
].volume_right
= right
;
1334 return MMSYSERR_NOERROR
;
1337 /**************************************************************************
1338 * wodGetNumDevs [internal]
1340 static DWORD
wodGetNumDevs(void)
1342 return MAX_WAVEOUTDRV
;
1345 /**************************************************************************
1346 * wodMessage (WINEARTS.@)
1348 DWORD WINAPI
ARTS_wodMessage(UINT wDevID
, UINT wMsg
, DWORD dwUser
,
1349 DWORD dwParam1
, DWORD dwParam2
)
1351 TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
1352 wDevID
, wMsg
, dwUser
, dwParam1
, dwParam2
);
1359 /* FIXME: Pretend this is supported */
1361 case WODM_OPEN
: return wodOpen (wDevID
, (LPWAVEOPENDESC
)dwParam1
, dwParam2
);
1362 case WODM_CLOSE
: return wodClose (wDevID
);
1363 case WODM_WRITE
: return wodWrite (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
1364 case WODM_PAUSE
: return wodPause (wDevID
);
1365 case WODM_GETPOS
: return wodGetPosition (wDevID
, (LPMMTIME
)dwParam1
, dwParam2
);
1366 case WODM_BREAKLOOP
: return wodBreakLoop (wDevID
);
1367 case WODM_PREPARE
: return wodPrepare (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
1368 case WODM_UNPREPARE
: return wodUnprepare (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
1369 case WODM_GETDEVCAPS
: return wodGetDevCaps (wDevID
, (LPWAVEOUTCAPSA
)dwParam1
, dwParam2
);
1370 case WODM_GETNUMDEVS
: return wodGetNumDevs ();
1371 case WODM_GETPITCH
: return MMSYSERR_NOTSUPPORTED
;
1372 case WODM_SETPITCH
: return MMSYSERR_NOTSUPPORTED
;
1373 case WODM_GETPLAYBACKRATE
: return MMSYSERR_NOTSUPPORTED
;
1374 case WODM_SETPLAYBACKRATE
: return MMSYSERR_NOTSUPPORTED
;
1375 case WODM_GETVOLUME
: return wodGetVolume (wDevID
, (LPDWORD
)dwParam1
);
1376 case WODM_SETVOLUME
: return wodSetVolume (wDevID
, dwParam1
);
1377 case WODM_RESTART
: return wodRestart (wDevID
);
1378 case WODM_RESET
: return wodReset (wDevID
);
1380 case DRV_QUERYDSOUNDIFACE
: return wodDsCreate(wDevID
, (PIDSDRIVER
*)dwParam1
);
1382 FIXME("unknown message %d!\n", wMsg
);
1384 return MMSYSERR_NOTSUPPORTED
;
1387 /*======================================================================*
1388 * Low level DSOUND implementation *
1389 *======================================================================*/
1390 static DWORD
wodDsCreate(UINT wDevID
, PIDSDRIVER
* drv
)
1392 /* we can't perform memory mapping as we don't have a file stream
1393 interface with arts like we do with oss */
1394 MESSAGE("This sound card's driver does not support direct access\n");
1395 MESSAGE("The (slower) DirectSound HEL mode will be used instead.\n");
1396 return MMSYSERR_NOTSUPPORTED
;
1399 #else /* !HAVE_ARTS */
1401 /**************************************************************************
1402 * wodMessage (WINEARTS.@)
1404 DWORD WINAPI
ARTS_wodMessage(WORD wDevID
, WORD wMsg
, DWORD dwUser
,
1405 DWORD dwParam1
, DWORD dwParam2
)
1407 FIXME("(%u, %04X, %08lX, %08lX, %08lX):stub\n", wDevID
, wMsg
, dwUser
, dwParam1
, dwParam2
);
1408 return MMSYSERR_NOTENABLED
;
1411 #endif /* HAVE_ARTS */