mshtml: Implement IHTMLDOMNode previousSibling.
[wine] / dlls / winealsa.drv / dscapture.c
1 /*
2  * Sample Wine Driver for Advanced Linux Sound System (ALSA)
3  *      Based on version <final> of the ALSA API
4  *
5  * Copyright 2007 - Maarten Lankhorst
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 /*======================================================================*
23  *              Low level dsound input implementation                   *
24  *======================================================================*/
25
26 #include "config.h"
27 #include "wine/port.h"
28
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <stdio.h>
32 #include <string.h>
33 #ifdef HAVE_UNISTD_H
34 # include <unistd.h>
35 #endif
36 #include <errno.h>
37 #include <limits.h>
38 #include <fcntl.h>
39 #ifdef HAVE_SYS_IOCTL_H
40 # include <sys/ioctl.h>
41 #endif
42 #ifdef HAVE_SYS_MMAN_H
43 # include <sys/mman.h>
44 #endif
45 #include "windef.h"
46 #include "winbase.h"
47 #include "wingdi.h"
48 #include "winerror.h"
49 #include "winuser.h"
50 #include "mmddk.h"
51
52 #include "alsa.h"
53 #include "wine/library.h"
54 #include "wine/unicode.h"
55 #include "wine/debug.h"
56
57 #ifdef HAVE_ALSA
58
59 /* Notify timer checks every 10 ms with a resolution of 2 ms */
60 #define DS_TIME_DEL 10
61 #define DS_TIME_RES 2
62
63 WINE_DEFAULT_DEBUG_CHANNEL(dsalsa);
64
65 typedef struct IDsCaptureDriverBufferImpl IDsCaptureDriverBufferImpl;
66
67 typedef struct IDsCaptureDriverImpl
68 {
69     const IDsCaptureDriverVtbl *lpVtbl;
70     LONG ref;
71     IDsCaptureDriverBufferImpl* capture_buffer;
72     UINT wDevID;
73 } IDsCaptureDriverImpl;
74
75 typedef struct IDsCaptureDriverNotifyImpl
76 {
77     const IDsDriverNotifyVtbl *lpVtbl;
78     LONG ref;
79     IDsCaptureDriverBufferImpl *buffer;
80     DSBPOSITIONNOTIFY *notifies;
81     DWORD nrofnotifies, playpos;
82     UINT timerID;
83 } IDsCaptureDriverNotifyImpl;
84
85 struct IDsCaptureDriverBufferImpl
86 {
87     const IDsCaptureDriverBufferVtbl *lpVtbl;
88     LONG ref;
89     IDsCaptureDriverImpl *drv;
90     IDsCaptureDriverNotifyImpl *notify;
91
92     CRITICAL_SECTION pcm_crst;
93     LPBYTE mmap_buffer, presented_buffer;
94     DWORD mmap_buflen_bytes, play_looping, mmap_ofs_bytes;
95     BOOL mmap;
96
97     /* Note: snd_pcm_frames_to_bytes(This->pcm, mmap_buflen_frames) != mmap_buflen_bytes */
98     /* The actual buffer may differ in size from the wanted buffer size */
99
100     snd_pcm_t *pcm;
101     snd_pcm_hw_params_t *hw_params;
102     snd_pcm_sw_params_t *sw_params;
103     snd_pcm_uframes_t mmap_buflen_frames, mmap_pos;
104 };
105
106 static void Capture_CheckNotify(IDsCaptureDriverNotifyImpl *This, DWORD from, DWORD len)
107 {
108     unsigned i;
109     for (i = 0; i < This->nrofnotifies; ++i) {
110         LPDSBPOSITIONNOTIFY event = This->notifies + i;
111         DWORD offset = event->dwOffset;
112         TRACE("checking %d, position %d, event = %p\n", i, offset, event->hEventNotify);
113
114         if (offset == DSBPN_OFFSETSTOP) {
115             if (!from && !len) {
116                 SetEvent(event->hEventNotify);
117                 TRACE("signalled event %p (%d)\n", event->hEventNotify, i);
118                 return;
119             }
120             else return;
121         }
122
123         if (offset >= from && offset < (from + len))
124         {
125             TRACE("signalled event %p (%d)\n", event->hEventNotify, i);
126             SetEvent(event->hEventNotify);
127         }
128     }
129 }
130
131 static void CALLBACK Capture_Notify(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
132 {
133     IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)dwUser;
134     DWORD last_playpos, playpos;
135     PIDSCDRIVERBUFFER iface = (PIDSCDRIVERBUFFER)This;
136
137     /* **** */
138     /* Don't deadlock since there is a critical section can be held by the timer api itself while running this code */
139     if (!TryEnterCriticalSection(&This->pcm_crst)) return;
140
141     IDsDriverBuffer_GetPosition(iface, &playpos, NULL);
142     last_playpos = This->notify->playpos;
143     This->notify->playpos = playpos;
144
145     if (snd_pcm_state(This->pcm) != SND_PCM_STATE_RUNNING || last_playpos == playpos || !This->notify->nrofnotifies || !This->notify->notifies)
146         goto done;
147
148     if (playpos < last_playpos)
149     {
150         Capture_CheckNotify(This->notify, last_playpos, This->mmap_buflen_bytes);
151         if (playpos)
152             Capture_CheckNotify(This->notify, 0, playpos);
153     }
154     else Capture_CheckNotify(This->notify, last_playpos, playpos - last_playpos);
155
156 done:
157     LeaveCriticalSection(&This->pcm_crst);
158     /* **** */
159 }
160
161 static HRESULT WINAPI IDsCaptureDriverNotifyImpl_QueryInterface(PIDSDRIVERNOTIFY iface, REFIID riid, LPVOID *ppobj)
162 {
163     IDsCaptureDriverNotifyImpl *This = (IDsCaptureDriverNotifyImpl *)iface;
164     TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
165
166     if ( IsEqualGUID(riid, &IID_IUnknown) ||
167          IsEqualGUID(riid, &IID_IDsDriverNotify) ) {
168         IDsDriverNotify_AddRef(iface);
169         *ppobj = This;
170         return DS_OK;
171     }
172
173     FIXME( "Unknown IID %s\n", debugstr_guid(riid));
174
175     *ppobj = 0;
176     return E_NOINTERFACE;
177 }
178
179 static ULONG WINAPI IDsCaptureDriverNotifyImpl_AddRef(PIDSDRIVERNOTIFY iface)
180 {
181     IDsCaptureDriverNotifyImpl *This = (IDsCaptureDriverNotifyImpl *)iface;
182     ULONG refCount = InterlockedIncrement(&This->ref);
183
184     TRACE("(%p) ref was %d\n", This, refCount - 1);
185
186     return refCount;
187 }
188
189 static ULONG WINAPI IDsCaptureDriverNotifyImpl_Release(PIDSDRIVERNOTIFY iface)
190 {
191     IDsCaptureDriverNotifyImpl *This = (IDsCaptureDriverNotifyImpl *)iface;
192     ULONG refCount = InterlockedDecrement(&This->ref);
193
194     TRACE("(%p) ref was %d\n", This, refCount + 1);
195
196     if (!refCount) {
197         This->buffer->notify = NULL;
198         if (This->timerID)
199         {
200             timeKillEvent(This->timerID);
201             timeEndPeriod(DS_TIME_RES);
202         }
203         HeapFree(GetProcessHeap(), 0, This->notifies);
204         HeapFree(GetProcessHeap(), 0, This);
205         TRACE("(%p) released\n", This);
206     }
207     return refCount;
208 }
209
210 static HRESULT WINAPI IDsCaptureDriverNotifyImpl_SetNotificationPositions(PIDSDRIVERNOTIFY iface, DWORD howmuch, LPCDSBPOSITIONNOTIFY notify)
211 {
212     DWORD len = howmuch * sizeof(DSBPOSITIONNOTIFY);
213     unsigned i;
214     LPVOID notifies;
215     IDsCaptureDriverNotifyImpl *This = (IDsCaptureDriverNotifyImpl *)iface;
216     TRACE("(%p,0x%08x,%p)\n",This,howmuch,notify);
217
218     if (!notify) {
219         WARN("invalid parameter\n");
220         return DSERR_INVALIDPARAM;
221     }
222
223     if (TRACE_ON(dsalsa))
224         for (i=0;i<howmuch; ++i)
225             TRACE("notify at %d to %p\n", notify[i].dwOffset, notify[i].hEventNotify);
226
227     /* **** */
228     EnterCriticalSection(&This->buffer->pcm_crst);
229
230     /* Make an internal copy of the caller-supplied array.
231      * Replace the existing copy if one is already present. */
232     if (This->notifies)
233         notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->notifies, len);
234     else
235         notifies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
236
237     if (!notifies)
238     {
239         LeaveCriticalSection(&This->buffer->pcm_crst);
240         /* **** */
241         return DSERR_OUTOFMEMORY;
242     }
243     This->notifies = notifies;
244     memcpy(This->notifies, notify, len);
245     This->nrofnotifies = howmuch;
246     IDsDriverBuffer_GetPosition((PIDSCDRIVERBUFFER)This->buffer, &This->playpos, NULL);
247
248     if (!This->timerID)
249     {
250         timeBeginPeriod(DS_TIME_RES);
251         This->timerID = timeSetEvent(DS_TIME_DEL, DS_TIME_RES, Capture_Notify, (DWORD_PTR)This->buffer, TIME_PERIODIC | TIME_KILL_SYNCHRONOUS);
252     }
253
254     LeaveCriticalSection(&This->buffer->pcm_crst);
255     /* **** */
256
257     return S_OK;
258 }
259
260 static const IDsDriverNotifyVtbl dscdnvt =
261 {
262     IDsCaptureDriverNotifyImpl_QueryInterface,
263     IDsCaptureDriverNotifyImpl_AddRef,
264     IDsCaptureDriverNotifyImpl_Release,
265     IDsCaptureDriverNotifyImpl_SetNotificationPositions,
266 };
267
268 #if 0
269 /** Convert the position an application sees into a position ALSA sees */
270 static snd_pcm_uframes_t fakepos_to_realpos(const IDsCaptureDriverBufferImpl* This, DWORD fakepos)
271 {
272     snd_pcm_uframes_t realpos;
273     if (fakepos < This->mmap_ofs_bytes)
274         realpos = This->mmap_buflen_bytes + fakepos - This->mmap_ofs_bytes;
275     else realpos = fakepos - This->mmap_ofs_bytes;
276     return snd_pcm_bytes_to_frames(This->pcm, realpos) % This->mmap_buflen_frames;
277 }
278 #endif
279
280 /** Convert the position ALSA sees into a position an application sees */
281 static DWORD realpos_to_fakepos(const IDsCaptureDriverBufferImpl* This, snd_pcm_uframes_t realpos)
282 {
283     DWORD realposb = snd_pcm_frames_to_bytes(This->pcm, realpos);
284     return (realposb + This->mmap_ofs_bytes) % This->mmap_buflen_bytes;
285 }
286
287 /** Raw copy data, with buffer wrap around */
288 static void CopyDataWrap(const IDsCaptureDriverBufferImpl* This, LPBYTE dest, DWORD fromwhere, DWORD copylen, DWORD buflen)
289 {
290     DWORD remainder = buflen - fromwhere;
291     if (remainder >= copylen)
292     {
293         CopyMemory(dest, This->mmap_buffer + fromwhere, copylen);
294     }
295     else
296     {
297         CopyMemory(dest, This->mmap_buffer + fromwhere, remainder);
298         copylen -= remainder;
299         CopyMemory(dest, This->mmap_buffer, copylen);
300     }
301 }
302
303 /** Copy data from the mmap buffer to backbuffer, taking into account all wraparounds that may occur */
304 static void CopyData(const IDsCaptureDriverBufferImpl* This, snd_pcm_uframes_t fromwhere, snd_pcm_uframes_t len)
305 {
306     DWORD dlen = snd_pcm_frames_to_bytes(This->pcm, len) % This->mmap_buflen_bytes;
307
308     /* Backbuffer */
309     DWORD ofs = realpos_to_fakepos(This, fromwhere);
310     DWORD remainder = This->mmap_buflen_bytes - ofs;
311
312     /* MMAP buffer */
313     DWORD realbuflen = snd_pcm_frames_to_bytes(This->pcm, This->mmap_buflen_frames);
314     DWORD realofs = snd_pcm_frames_to_bytes(This->pcm, fromwhere);
315
316     if (remainder >= dlen)
317     {
318        CopyDataWrap(This, This->presented_buffer + ofs, realofs, dlen, realbuflen);
319     }
320     else
321     {
322        CopyDataWrap(This, This->presented_buffer + ofs, realofs, remainder, realbuflen);
323        dlen -= remainder;
324        CopyDataWrap(This, This->presented_buffer, (realofs+remainder)%realbuflen, dlen, realbuflen);
325     }
326 }
327
328 /** Fill buffers, for starting and stopping
329  * Alsa won't start playing until everything is filled up
330  * This also updates mmap_pos
331  *
332  * Returns: Amount of periods in use so snd_pcm_avail_update
333  * doesn't have to be called up to 4x in GetPosition()
334  */
335 static snd_pcm_uframes_t CommitAll(IDsCaptureDriverBufferImpl *This, DWORD forced)
336 {
337     const snd_pcm_channel_area_t *areas;
338     snd_pcm_uframes_t used;
339     const snd_pcm_uframes_t commitahead = This->mmap_buflen_frames;
340
341     used = This->mmap_buflen_frames - snd_pcm_avail_update(This->pcm);
342     TRACE("%p needs to commit to %lu, used: %lu\n", This, commitahead, used);
343     if (used < commitahead && (forced || This->play_looping))
344     {
345         snd_pcm_uframes_t done, putin = commitahead - used;
346         if (This->mmap)
347         {
348             snd_pcm_mmap_begin(This->pcm, &areas, &This->mmap_pos, &putin);
349             CopyData(This, This->mmap_pos, putin);
350             done = snd_pcm_mmap_commit(This->pcm, This->mmap_pos, putin);
351
352             This->mmap_pos += done;
353             used += done;
354             putin = commitahead - used;
355
356             if (This->mmap_pos == This->mmap_buflen_frames && (snd_pcm_sframes_t)putin > 0 && This->play_looping)
357             {
358                 This->mmap_ofs_bytes += snd_pcm_frames_to_bytes(This->pcm, This->mmap_buflen_frames);
359                 This->mmap_ofs_bytes %= This->mmap_buflen_bytes;
360
361                 snd_pcm_mmap_begin(This->pcm, &areas, &This->mmap_pos, &putin);
362                 CopyData(This, This->mmap_pos, putin);
363                 done = snd_pcm_mmap_commit(This->pcm, This->mmap_pos, putin);
364
365                 This->mmap_pos += done;
366                 used += done;
367             }
368         }
369         else
370         {
371             DWORD pos;
372             snd_pcm_sframes_t ret;
373
374             snd_pcm_uframes_t cap = snd_pcm_bytes_to_frames(This->pcm, This->mmap_buflen_bytes);
375             pos = realpos_to_fakepos(This, This->mmap_pos);
376             if (This->mmap_pos + putin > cap)
377                 putin = cap - This->mmap_pos;
378             ret = snd_pcm_readi(This->pcm, This->presented_buffer + pos, putin);
379             if (ret == -EPIPE)
380             {
381                 WARN("Underrun occurred\n");
382                 snd_pcm_prepare(This->pcm);
383                 ret = snd_pcm_readi(This->pcm, This->presented_buffer + pos, putin);
384                 snd_pcm_start(This->pcm);
385             }
386             if (ret < 0)
387             {
388                 WARN("Committing data: %ld / %s (%ld)\n", ret, snd_strerror(ret), putin);
389                 ret = 0;
390             }
391             This->mmap_pos += ret;
392             used += ret;
393             /* At this point mmap_pos may be >= This->mmap_pos this is harmless
394              * realpos_to_fakepos handles it well, and below it is truncated
395              */
396
397             putin = commitahead - used;
398             if (putin > 0)
399             {
400                 pos = realpos_to_fakepos(This, This->mmap_pos);
401                 ret = snd_pcm_readi(This->pcm, This->presented_buffer + pos, putin);
402                 if (ret > 0)
403                 {
404                     This->mmap_pos += ret;
405                     used += ret;
406                 }
407             }
408         }
409
410     }
411
412     if (This->mmap_pos >= This->mmap_buflen_frames)
413     {
414         This->mmap_ofs_bytes += snd_pcm_frames_to_bytes(This->pcm, This->mmap_buflen_frames);
415         This->mmap_ofs_bytes %= This->mmap_buflen_bytes;
416         This->mmap_pos -= This->mmap_buflen_frames;
417     }
418
419     return used;
420 }
421
422 static void CheckXRUN(IDsCaptureDriverBufferImpl* This)
423 {
424     snd_pcm_state_t state = snd_pcm_state(This->pcm);
425     int err;
426
427     if ( state == SND_PCM_STATE_XRUN )
428     {
429         err = snd_pcm_prepare(This->pcm);
430         CommitAll(This, FALSE);
431         snd_pcm_start(This->pcm);
432         WARN("xrun occurred\n");
433         if ( err < 0 )
434             ERR("recovery from xrun failed, prepare failed: %s\n", snd_strerror(err));
435     }
436     else if ( state == SND_PCM_STATE_SUSPENDED )
437     {
438         int err = snd_pcm_resume(This->pcm);
439         TRACE("recovery from suspension occurred\n");
440         if (err < 0 && err != -EAGAIN){
441             err = snd_pcm_prepare(This->pcm);
442             if (err < 0)
443                 ERR("recovery from suspend failed, prepare failed: %s\n", snd_strerror(err));
444         }
445     }
446     else if ( state != SND_PCM_STATE_RUNNING)
447     {
448         WARN("Unhandled state: %d\n", state);
449     }
450 }
451
452 /**
453  * Allocate the memory-mapped buffer for direct sound, and set up the
454  * callback.
455  */
456 static int CreateMMAP(IDsCaptureDriverBufferImpl* pdbi)
457 {
458     snd_pcm_t *pcm = pdbi->pcm;
459     snd_pcm_format_t format;
460     snd_pcm_uframes_t frames, ofs, avail, psize, boundary;
461     unsigned int channels, bits_per_sample, bits_per_frame;
462     int err, mmap_mode;
463     const snd_pcm_channel_area_t *areas;
464     snd_pcm_hw_params_t *hw_params = pdbi->hw_params;
465     snd_pcm_sw_params_t *sw_params = pdbi->sw_params;
466
467     mmap_mode = snd_pcm_type(pcm);
468
469     if (mmap_mode == SND_PCM_TYPE_HW)
470         TRACE("mmap'd buffer is a direct hardware buffer.\n");
471     else if (mmap_mode == SND_PCM_TYPE_DMIX)
472         TRACE("mmap'd buffer is an ALSA dmix buffer\n");
473     else
474         TRACE("mmap'd buffer is an ALSA type %d buffer\n", mmap_mode);
475
476     err = snd_pcm_hw_params_get_period_size(hw_params, &psize, NULL);
477     err = snd_pcm_hw_params_get_format(hw_params, &format);
478     err = snd_pcm_hw_params_get_buffer_size(hw_params, &frames);
479     err = snd_pcm_hw_params_get_channels(hw_params, &channels);
480     bits_per_sample = snd_pcm_format_physical_width(format);
481     bits_per_frame = bits_per_sample * channels;
482
483     if (TRACE_ON(dsalsa))
484         ALSA_TraceParameters(hw_params, NULL, FALSE);
485
486     TRACE("format=%s  frames=%ld  channels=%d  bits_per_sample=%d  bits_per_frame=%d\n",
487           snd_pcm_format_name(format), frames, channels, bits_per_sample, bits_per_frame);
488
489     pdbi->mmap_buflen_frames = frames;
490     snd_pcm_sw_params_current(pcm, sw_params);
491     snd_pcm_sw_params_set_start_threshold(pcm, sw_params, 0);
492     snd_pcm_sw_params_get_boundary(sw_params, &boundary);
493     snd_pcm_sw_params_set_stop_threshold(pcm, sw_params, boundary);
494     snd_pcm_sw_params_set_silence_threshold(pcm, sw_params, INT_MAX);
495     snd_pcm_sw_params_set_silence_size(pcm, sw_params, 0);
496     snd_pcm_sw_params_set_avail_min(pcm, sw_params, 0);
497     err = snd_pcm_sw_params(pcm, sw_params);
498
499     pdbi->mmap_ofs_bytes = 0;
500     if (!pdbi->mmap)
501     {
502         pdbi->mmap_buffer = NULL;
503
504         frames = snd_pcm_bytes_to_frames(pdbi->pcm, pdbi->mmap_buflen_bytes);
505         snd_pcm_format_set_silence(format, pdbi->presented_buffer, frames);
506         pdbi->mmap_pos = 0;
507     }
508     else
509     {
510         err = snd_pcm_mmap_begin(pcm, &areas, &ofs, &avail);
511         if ( err < 0 )
512         {
513             ERR("Can't map sound device for direct access: %s/%d\n", snd_strerror(err), err);
514             return DSERR_GENERIC;
515         }
516         snd_pcm_format_set_silence(format, areas->addr, pdbi->mmap_buflen_frames);
517         pdbi->mmap_pos = ofs + snd_pcm_mmap_commit(pcm, ofs, 0);
518         pdbi->mmap_buffer = areas->addr;
519     }
520
521     TRACE("created mmap buffer of %ld frames (%d bytes) at %p\n",
522         pdbi->mmap_buflen_frames, pdbi->mmap_buflen_bytes, pdbi->mmap_buffer);
523
524     return DS_OK;
525 }
526
527 static HRESULT WINAPI IDsCaptureDriverBufferImpl_QueryInterface(PIDSCDRIVERBUFFER iface, REFIID riid, LPVOID *ppobj)
528 {
529     IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)iface;
530     if ( IsEqualGUID(riid, &IID_IUnknown) ||
531          IsEqualGUID(riid, &IID_IDsCaptureDriverBuffer) ) {
532         IDsCaptureDriverBuffer_AddRef(iface);
533         *ppobj = iface;
534         return DS_OK;
535     }
536
537     if ( IsEqualGUID( &IID_IDsDriverNotify, riid ) ) {
538         if (!This->notify)
539         {
540             This->notify = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDsCaptureDriverNotifyImpl));
541             if (!This->notify)
542                 return DSERR_OUTOFMEMORY;
543             This->notify->lpVtbl = &dscdnvt;
544             This->notify->buffer = This;
545
546             /* Keep a lock on IDsDriverNotify for ourself, so it is destroyed when the buffer is */
547             IDsDriverNotify_AddRef((PIDSDRIVERNOTIFY)This->notify);
548         }
549         IDsDriverNotify_AddRef((PIDSDRIVERNOTIFY)This->notify);
550         *ppobj = This->notify;
551         return DS_OK;
552     }
553
554     if ( IsEqualGUID( &IID_IDsDriverPropertySet, riid ) ) {
555         FIXME("Unsupported interface IID_IDsDriverPropertySet\n");
556         return E_FAIL;
557     }
558
559     FIXME("(): Unknown interface %s\n", debugstr_guid(riid));
560     return DSERR_UNSUPPORTED;
561 }
562
563 static ULONG WINAPI IDsCaptureDriverBufferImpl_AddRef(PIDSCDRIVERBUFFER iface)
564 {
565     IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)iface;
566     ULONG refCount = InterlockedIncrement(&This->ref);
567
568     TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
569
570     return refCount;
571 }
572
573 static ULONG WINAPI IDsCaptureDriverBufferImpl_Release(PIDSCDRIVERBUFFER iface)
574 {
575     IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)iface;
576     ULONG refCount = InterlockedDecrement(&This->ref);
577
578     TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
579
580     if (refCount)
581         return refCount;
582
583     EnterCriticalSection(&This->pcm_crst);
584     if (This->notify)
585         IDsDriverNotify_Release((PIDSDRIVERNOTIFY)This->notify);
586     TRACE("mmap buffer %p destroyed\n", This->mmap_buffer);
587
588     This->drv->capture_buffer = NULL;
589     LeaveCriticalSection(&This->pcm_crst);
590     This->pcm_crst.DebugInfo->Spare[0] = 0;
591     DeleteCriticalSection(&This->pcm_crst);
592
593     snd_pcm_drop(This->pcm);
594     snd_pcm_close(This->pcm);
595     This->pcm = NULL;
596     HeapFree(GetProcessHeap(), 0, This->presented_buffer);
597     HeapFree(GetProcessHeap(), 0, This->sw_params);
598     HeapFree(GetProcessHeap(), 0, This->hw_params);
599     HeapFree(GetProcessHeap(), 0, This);
600     return 0;
601 }
602
603 static HRESULT WINAPI IDsCaptureDriverBufferImpl_Lock(PIDSCDRIVERBUFFER iface, LPVOID*ppvAudio1,LPDWORD pdwLen1,LPVOID*ppvAudio2,LPDWORD pdwLen2, DWORD dwWritePosition,DWORD dwWriteLen, DWORD dwFlags)
604 {
605     IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)iface;
606     TRACE("(%p,%p,%p,%p,%p,%d,%d,0x%08x)\n", This, ppvAudio1, pdwLen1, ppvAudio2, pdwLen2, dwWritePosition, dwWriteLen, dwFlags);
607
608     if (ppvAudio1)
609         *ppvAudio1 = (LPBYTE)This->presented_buffer + dwWritePosition;
610
611     if (dwWritePosition + dwWriteLen <= This->mmap_buflen_bytes) {
612         if (pdwLen1)
613             *pdwLen1 = dwWriteLen;
614         if (ppvAudio2)
615             *ppvAudio2 = 0;
616         if (pdwLen2)
617             *pdwLen2 = 0;
618     } else {
619         if (pdwLen1)
620             *pdwLen1 = This->mmap_buflen_bytes - dwWritePosition;
621         if (ppvAudio2)
622             *ppvAudio2 = This->presented_buffer;
623         if (pdwLen2)
624             *pdwLen2 = dwWriteLen - (This->mmap_buflen_bytes - dwWritePosition);
625     }
626     return DS_OK;
627 }
628
629 static HRESULT WINAPI IDsCaptureDriverBufferImpl_Unlock(PIDSCDRIVERBUFFER iface, LPVOID pvAudio1,DWORD dwLen1, LPVOID pvAudio2,DWORD dwLen2)
630 {
631     IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)iface;
632     TRACE("(%p,%p,%d,%p,%d)\n",This,pvAudio1,dwLen1,pvAudio2,dwLen2);
633     return DS_OK;
634 }
635
636 static HRESULT WINAPI IDsCaptureDriverBufferImpl_SetFormat(PIDSCDRIVERBUFFER iface, LPWAVEFORMATEX pwfx)
637 {
638     IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)iface;
639     WINE_WAVEDEV *wwi = &WInDev[This->drv->wDevID];
640     snd_pcm_t *pcm = NULL;
641     snd_pcm_hw_params_t *hw_params = This->hw_params;
642     snd_pcm_format_t format = -1;
643     snd_pcm_uframes_t buffer_size;
644     DWORD rate = pwfx->nSamplesPerSec;
645     int err=0;
646     BOOL mmap;
647
648     TRACE("(%p, %p)\n", iface, pwfx);
649
650     switch (pwfx->wBitsPerSample)
651     {
652         case  8: format = SND_PCM_FORMAT_U8; break;
653         case 16: format = SND_PCM_FORMAT_S16_LE; break;
654         case 24: format = SND_PCM_FORMAT_S24_3LE; break;
655         case 32: format = SND_PCM_FORMAT_S32_LE; break;
656         default: FIXME("Unsupported bpp: %d\n", pwfx->wBitsPerSample); return DSERR_GENERIC;
657     }
658
659     /* **** */
660     EnterCriticalSection(&This->pcm_crst);
661
662     err = snd_pcm_open(&pcm, wwi->pcmname, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
663
664     if (err < 0)
665     {
666         if (errno != EBUSY || !This->pcm)
667         {
668             /* **** */
669             LeaveCriticalSection(&This->pcm_crst);
670             WARN("Cannot open sound device: %s\n", snd_strerror(err));
671             return DSERR_GENERIC;
672         }
673         snd_pcm_drop(This->pcm);
674         snd_pcm_close(This->pcm);
675         This->pcm = NULL;
676         err = snd_pcm_open(&pcm, wwi->pcmname, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
677         if (err < 0)
678         {
679             /* **** */
680             LeaveCriticalSection(&This->pcm_crst);
681             WARN("Cannot open sound device: %s\n", snd_strerror(err));
682             return DSERR_BUFFERLOST;
683         }
684     }
685
686     /* Set some defaults */
687     snd_pcm_hw_params_any(pcm, hw_params);
688
689     err = snd_pcm_hw_params_set_channels(pcm, hw_params, pwfx->nChannels);
690     if (err < 0) { WARN("Could not set channels to %d\n", pwfx->nChannels); goto err; }
691
692     err = snd_pcm_hw_params_set_format(pcm, hw_params, format);
693     if (err < 0) { WARN("Could not set format to %d bpp\n", pwfx->wBitsPerSample); goto err; }
694
695     err = snd_pcm_hw_params_set_rate_near(pcm, hw_params, &rate, NULL);
696     if (err < 0) { rate = pwfx->nSamplesPerSec; WARN("Could not set rate\n"); goto err; }
697
698     if (!ALSA_NearMatch(rate, pwfx->nSamplesPerSec))
699     {
700         WARN("Could not set sound rate to %d, but instead to %d\n", pwfx->nSamplesPerSec, rate);
701         pwfx->nSamplesPerSec = rate;
702         pwfx->nAvgBytesPerSec = rate * pwfx->nBlockAlign;
703         /* Let DirectSound detect this */
704     }
705
706     snd_pcm_hw_params_set_periods_integer(pcm, hw_params);
707     buffer_size = This->mmap_buflen_bytes / pwfx->nBlockAlign;
708     snd_pcm_hw_params_set_buffer_size_near(pcm, hw_params, &buffer_size);
709     buffer_size = 5000;
710     snd_pcm_hw_params_set_period_time_near(pcm, hw_params, (unsigned int*)&buffer_size, NULL);
711
712     err = snd_pcm_hw_params_set_access (pcm, hw_params, SND_PCM_ACCESS_MMAP_INTERLEAVED);
713     if (err < 0)
714     {
715         err = snd_pcm_hw_params_set_access (pcm, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
716         if (err < 0) { WARN("Could not set access\n"); goto err; }
717         mmap = 0;
718     }
719     else
720         mmap = 1;
721
722     err = snd_pcm_hw_params(pcm, hw_params);
723     if (err < 0) { WARN("Could not set hw parameters\n"); goto err; }
724
725     if (This->pcm)
726     {
727         snd_pcm_drop(This->pcm);
728         snd_pcm_close(This->pcm);
729     }
730     This->pcm = pcm;
731     This->mmap = mmap;
732
733     snd_pcm_prepare(This->pcm);
734     CreateMMAP(This);
735
736     /* **** */
737     LeaveCriticalSection(&This->pcm_crst);
738     return S_OK;
739
740     err:
741     if (err < 0)
742         WARN("Failed to apply changes: %s\n", snd_strerror(err));
743
744     if (!This->pcm)
745         This->pcm = pcm;
746     else
747         snd_pcm_close(pcm);
748
749     if (This->pcm)
750         snd_pcm_hw_params_current(This->pcm, This->hw_params);
751
752     /* **** */
753     LeaveCriticalSection(&This->pcm_crst);
754     return DSERR_BADFORMAT;
755 }
756
757 static HRESULT WINAPI IDsCaptureDriverBufferImpl_GetPosition(PIDSCDRIVERBUFFER iface, LPDWORD lpdwCappos, LPDWORD lpdwReadpos)
758 {
759     IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)iface;
760     snd_pcm_uframes_t hw_pptr, hw_wptr;
761
762     EnterCriticalSection(&This->pcm_crst);
763
764     if (!This->pcm)
765     {
766         FIXME("Bad pointer for pcm: %p\n", This->pcm);
767         LeaveCriticalSection(&This->pcm_crst);
768         return DSERR_GENERIC;
769     }
770
771     if (snd_pcm_state(This->pcm) != SND_PCM_STATE_RUNNING)
772     {
773         CheckXRUN(This);
774         hw_pptr = This->mmap_pos;
775     }
776     else
777     {
778         /* FIXME: Unused at the moment */
779         snd_pcm_uframes_t used = CommitAll(This, FALSE);
780
781         if (This->mmap_pos > used)
782             hw_pptr = This->mmap_pos - used;
783         else
784             hw_pptr = This->mmap_buflen_frames - used + This->mmap_pos;
785     }
786     hw_wptr = This->mmap_pos;
787
788     if (lpdwCappos)
789         *lpdwCappos = realpos_to_fakepos(This, hw_pptr);
790     if (lpdwReadpos)
791         *lpdwReadpos = realpos_to_fakepos(This, hw_wptr);
792
793     LeaveCriticalSection(&This->pcm_crst);
794
795     TRACE("hw_pptr=%u, hw_wptr=%u playpos=%u(%p), writepos=%u(%p)\n", (unsigned int)hw_pptr, (unsigned int)hw_wptr, realpos_to_fakepos(This, hw_pptr), lpdwCappos, realpos_to_fakepos(This, hw_wptr), lpdwReadpos);
796     return DS_OK;
797 }
798
799 static HRESULT WINAPI IDsCaptureDriverBufferImpl_GetStatus(PIDSCDRIVERBUFFER iface, LPDWORD lpdwStatus)
800 {
801     IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)iface;
802     snd_pcm_state_t state;
803     TRACE("(%p,%p)\n",iface,lpdwStatus);
804
805     state = snd_pcm_state(This->pcm);
806     switch (state)
807     {
808     case SND_PCM_STATE_XRUN:
809     case SND_PCM_STATE_SUSPENDED:
810     case SND_PCM_STATE_RUNNING:
811         *lpdwStatus = DSCBSTATUS_CAPTURING | (This->play_looping ? DSCBSTATUS_LOOPING : 0);
812         break;
813     default:
814         *lpdwStatus = 0;
815         break;
816     }
817
818     TRACE("State: %d, flags: 0x%08x\n", state, *lpdwStatus);
819     return DS_OK;
820 }
821
822 static HRESULT WINAPI IDsCaptureDriverBufferImpl_Start(PIDSCDRIVERBUFFER iface, DWORD dwFlags)
823 {
824     IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)iface;
825     TRACE("(%p,%x)\n",iface,dwFlags);
826
827     /* **** */
828     EnterCriticalSection(&This->pcm_crst);
829     snd_pcm_start(This->pcm);
830     This->play_looping = !!(dwFlags & DSCBSTART_LOOPING);
831     if (!This->play_looping)
832         /* Not well supported because of the difference in ALSA size and DSOUND's notion of size
833          * what it does right now is fill the buffer once.. ALSA size */
834         FIXME("Non-looping buffers are not properly supported!\n");
835     CommitAll(This, TRUE);
836
837     if (This->notify && This->notify->nrofnotifies && This->notify->notifies)
838     {
839         DWORD playpos = realpos_to_fakepos(This, This->mmap_pos);
840         if (playpos)
841             Capture_CheckNotify(This->notify, 0, playpos);
842         This->notify->playpos = playpos;
843     }
844
845     /* **** */
846     LeaveCriticalSection(&This->pcm_crst);
847     return DS_OK;
848 }
849
850 static HRESULT WINAPI IDsCaptureDriverBufferImpl_Stop(PIDSCDRIVERBUFFER iface)
851 {
852     IDsCaptureDriverBufferImpl *This = (IDsCaptureDriverBufferImpl *)iface;
853     TRACE("(%p)\n",iface);
854
855     /* **** */
856     EnterCriticalSection(&This->pcm_crst);
857     This->play_looping = FALSE;
858     snd_pcm_drop(This->pcm);
859     snd_pcm_prepare(This->pcm);
860
861     if (This->notify && This->notify->notifies && This->notify->nrofnotifies)
862         Capture_CheckNotify(This->notify, 0, 0);
863
864     /* **** */
865     LeaveCriticalSection(&This->pcm_crst);
866     return DS_OK;
867 }
868
869 static const IDsCaptureDriverBufferVtbl dsdbvt =
870 {
871     IDsCaptureDriverBufferImpl_QueryInterface,
872     IDsCaptureDriverBufferImpl_AddRef,
873     IDsCaptureDriverBufferImpl_Release,
874     IDsCaptureDriverBufferImpl_Lock,
875     IDsCaptureDriverBufferImpl_Unlock,
876     IDsCaptureDriverBufferImpl_SetFormat,
877     IDsCaptureDriverBufferImpl_GetPosition,
878     IDsCaptureDriverBufferImpl_GetStatus,
879     IDsCaptureDriverBufferImpl_Start,
880     IDsCaptureDriverBufferImpl_Stop
881 };
882
883 static HRESULT WINAPI IDsCaptureDriverImpl_QueryInterface(PIDSCDRIVER iface, REFIID riid, LPVOID *ppobj)
884 {
885     /* IDsCaptureDriverImpl *This = (IDsCaptureDriverImpl *)iface; */
886     FIXME("(%p): stub!\n",iface);
887     return DSERR_UNSUPPORTED;
888 }
889
890 static ULONG WINAPI IDsCaptureDriverImpl_AddRef(PIDSCDRIVER iface)
891 {
892     IDsCaptureDriverImpl *This = (IDsCaptureDriverImpl *)iface;
893     ULONG refCount = InterlockedIncrement(&This->ref);
894
895     TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
896
897     return refCount;
898 }
899
900 static ULONG WINAPI IDsCaptureDriverImpl_Release(PIDSCDRIVER iface)
901 {
902     IDsCaptureDriverImpl *This = (IDsCaptureDriverImpl *)iface;
903     ULONG refCount = InterlockedDecrement(&This->ref);
904
905     TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
906
907     if (refCount)
908         return refCount;
909
910     HeapFree(GetProcessHeap(), 0, This);
911     return 0;
912 }
913
914 static HRESULT WINAPI IDsCaptureDriverImpl_GetDriverDesc(PIDSCDRIVER iface, PDSDRIVERDESC pDesc)
915 {
916     IDsCaptureDriverImpl *This = (IDsCaptureDriverImpl *)iface;
917     TRACE("(%p,%p)\n",iface,pDesc);
918     *pDesc                      = WInDev[This->wDevID].ds_desc;
919     pDesc->dwFlags              = 0;
920     pDesc->dnDevNode            = WInDev[This->wDevID].waveDesc.dnDevNode;
921     pDesc->wVxdId               = 0;
922     pDesc->wReserved            = 0;
923     pDesc->ulDeviceNum          = This->wDevID;
924     pDesc->dwHeapType           = DSDHEAP_NOHEAP;
925     pDesc->pvDirectDrawHeap     = NULL;
926     pDesc->dwMemStartAddress    = 0xDEAD0000;
927     pDesc->dwMemEndAddress      = 0xDEAF0000;
928     pDesc->dwMemAllocExtra      = 0;
929     pDesc->pvReserved1          = NULL;
930     pDesc->pvReserved2          = NULL;
931     return DS_OK;
932 }
933
934 static HRESULT WINAPI IDsCaptureDriverImpl_Open(PIDSCDRIVER iface)
935 {
936     HRESULT hr = S_OK;
937     IDsCaptureDriverImpl *This = (IDsCaptureDriverImpl *)iface;
938     int err=0;
939     snd_pcm_t *pcm = NULL;
940     snd_pcm_hw_params_t *hw_params;
941
942     /* While this is not really needed, it is a good idea to do this,
943      * to see if sound can be initialized */
944
945     hw_params = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, snd_pcm_hw_params_sizeof());
946     if (!hw_params)
947     {
948         hr = DSERR_OUTOFMEMORY;
949         WARN("--> %08x\n", hr);
950         return hr;
951     }
952
953     err = snd_pcm_open(&pcm, WInDev[This->wDevID].pcmname, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
954     if (err < 0) goto err;
955     err = snd_pcm_hw_params_any(pcm, hw_params);
956     if (err < 0) goto err;
957     err = snd_pcm_hw_params_set_access (pcm, hw_params, SND_PCM_ACCESS_MMAP_INTERLEAVED);
958     if (err < 0)
959     {
960         err = snd_pcm_hw_params_set_access (pcm, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
961         if (err < 0) goto err;
962     }
963
964     TRACE("Success\n");
965     snd_pcm_close(pcm);
966     HeapFree(GetProcessHeap(), 0, hw_params);
967     return hr;
968
969     err:
970     hr = DSERR_GENERIC;
971     WARN("Failed to open device: %s\n", snd_strerror(err));
972     if (pcm)
973         snd_pcm_close(pcm);
974     HeapFree(GetProcessHeap(), 0, hw_params);
975     WARN("--> %08x\n", hr);
976     return hr;
977 }
978
979 static HRESULT WINAPI IDsCaptureDriverImpl_Close(PIDSCDRIVER iface)
980 {
981     IDsCaptureDriverImpl *This = (IDsCaptureDriverImpl *)iface;
982     TRACE("(%p) stub, harmless\n",This);
983     return DS_OK;
984 }
985
986 static HRESULT WINAPI IDsCaptureDriverImpl_GetCaps(PIDSCDRIVER iface, PDSCDRIVERCAPS pCaps)
987 {
988     IDsCaptureDriverImpl *This = (IDsCaptureDriverImpl *)iface;
989     WINE_WAVEDEV *wwi = &WInDev[This->wDevID];
990     TRACE("(%p,%p)\n",iface,pCaps);
991     pCaps->dwSize = sizeof(DSCDRIVERCAPS);
992     pCaps->dwFlags = wwi->ds_caps.dwFlags;
993     pCaps->dwFormats = wwi->incaps.dwFormats;
994     pCaps->dwChannels = wwi->incaps.wChannels;
995     return DS_OK;
996 }
997
998 static HRESULT WINAPI IDsCaptureDriverImpl_CreateCaptureBuffer(PIDSCDRIVER iface,
999                                                       LPWAVEFORMATEX pwfx,
1000                                                       DWORD dwFlags, DWORD dwCardAddress,
1001                                                       LPDWORD pdwcbBufferSize,
1002                                                       LPBYTE *ppbBuffer,
1003                                                       LPVOID *ppvObj)
1004 {
1005     IDsCaptureDriverImpl *This = (IDsCaptureDriverImpl *)iface;
1006     IDsCaptureDriverBufferImpl** ippdsdb = (IDsCaptureDriverBufferImpl**)ppvObj;
1007     HRESULT err;
1008
1009     TRACE("(%p,%p,%x,%x)\n",iface,pwfx,dwFlags,dwCardAddress);
1010
1011     if (This->capture_buffer)
1012         return DSERR_ALLOCATED;
1013
1014     This->capture_buffer = *ippdsdb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDsCaptureDriverBufferImpl));
1015     if (*ippdsdb == NULL)
1016         return DSERR_OUTOFMEMORY;
1017
1018     (*ippdsdb)->hw_params = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, snd_pcm_hw_params_sizeof());
1019     (*ippdsdb)->sw_params = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, snd_pcm_sw_params_sizeof());
1020     (*ippdsdb)->presented_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *pdwcbBufferSize);
1021     if (!(*ippdsdb)->hw_params || !(*ippdsdb)->sw_params || !(*ippdsdb)->presented_buffer)
1022     {
1023         HeapFree(GetProcessHeap(), 0, (*ippdsdb)->sw_params);
1024         HeapFree(GetProcessHeap(), 0, (*ippdsdb)->hw_params);
1025         HeapFree(GetProcessHeap(), 0, (*ippdsdb)->presented_buffer);
1026         return DSERR_OUTOFMEMORY;
1027     }
1028     (*ippdsdb)->lpVtbl = &dsdbvt;
1029     (*ippdsdb)->ref = 1;
1030     (*ippdsdb)->drv = This;
1031     (*ippdsdb)->mmap_buflen_bytes = *pdwcbBufferSize;
1032     InitializeCriticalSection(&(*ippdsdb)->pcm_crst);
1033     (*ippdsdb)->pcm_crst.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": ALSA_DSCAPTURE.pcm_crst");
1034
1035     /* SetFormat initialises pcm */
1036     err = IDsDriverBuffer_SetFormat((IDsDriverBuffer*)*ppvObj, pwfx);
1037     if (FAILED(err))
1038     {
1039         WARN("Error occurred: %08x\n", err);
1040         goto err;
1041     }
1042     *ppbBuffer = (*ippdsdb)->presented_buffer;
1043
1044     /* buffer is ready to go */
1045     TRACE("buffer created at %p\n", *ippdsdb);
1046     return err;
1047
1048     err:
1049     HeapFree(GetProcessHeap(), 0, (*ippdsdb)->presented_buffer);
1050     HeapFree(GetProcessHeap(), 0, (*ippdsdb)->sw_params);
1051     HeapFree(GetProcessHeap(), 0, (*ippdsdb)->hw_params);
1052     HeapFree(GetProcessHeap(), 0, *ippdsdb);
1053     *ippdsdb = NULL;
1054     return err;
1055 }
1056
1057 static const IDsCaptureDriverVtbl dscdvt =
1058 {
1059     IDsCaptureDriverImpl_QueryInterface,
1060     IDsCaptureDriverImpl_AddRef,
1061     IDsCaptureDriverImpl_Release,
1062     IDsCaptureDriverImpl_GetDriverDesc,
1063     IDsCaptureDriverImpl_Open,
1064     IDsCaptureDriverImpl_Close,
1065     IDsCaptureDriverImpl_GetCaps,
1066     IDsCaptureDriverImpl_CreateCaptureBuffer
1067 };
1068
1069 /**************************************************************************
1070  *                              widDsCreate                     [internal]
1071  */
1072 DWORD widDsCreate(UINT wDevID, PIDSCDRIVER* drv)
1073 {
1074     IDsCaptureDriverImpl** idrv = (IDsCaptureDriverImpl**)drv;
1075     TRACE("(%d,%p)\n",wDevID,drv);
1076
1077     *idrv = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDsCaptureDriverImpl));
1078     if (!*idrv)
1079         return MMSYSERR_NOMEM;
1080     (*idrv)->lpVtbl     = &dscdvt;
1081     (*idrv)->ref        = 1;
1082
1083     (*idrv)->wDevID     = wDevID;
1084     return MMSYSERR_NOERROR;
1085 }
1086
1087 /**************************************************************************
1088  *                              widDsDesc                       [internal]
1089  */
1090 DWORD widDsDesc(UINT wDevID, PDSDRIVERDESC desc)
1091 {
1092     *desc = WInDev[wDevID].ds_desc;
1093     return MMSYSERR_NOERROR;
1094 }
1095
1096 #endif /* HAVE_ALSA */