source: trunk/src/winmm/waveoutdart.cpp@ 8568

Last change on this file since 8568 was 8568, checked in by sandervl, 23 years ago

Updates for wave playback

File size: 23.1 KB
Line 
1/* $Id: waveoutdart.cpp,v 1.8 2002-06-04 17:36:55 sandervl Exp $ */
2
3/*
4 * Wave playback class (DART)
5 *
6 * Copyright 1998-2001 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 * Note:
12 * 2000/11/24 PH MCI_MIXSETUP_PARMS->pMixWrite does alter FS: selector!
13 *
14 */
15
16
17/****************************************************************************
18 * Includes *
19 ****************************************************************************/
20
21
22
23#define INCL_BASE
24#define INCL_OS2MM
25#define INCL_DOSPROCESS
26#include <os2wrap.h> //Odin32 OS/2 api wrappers
27#include <os2mewrap.h> //Odin32 OS/2 MMPM/2 api wrappers
28#include <stdlib.h>
29#include <stddef.h>
30#include <string.h>
31#define OS2_ONLY
32#include <win32api.h>
33#include <wprocess.h>
34
35#include "misc.h"
36#include "waveoutdart.h"
37#include "initwinmm.h"
38
39#define DBG_LOCALLOG DBG_waveoutdart
40#include "dbglocal.h"
41
42#ifndef min
43#define min(a, b) ((a > b) ? b : a)
44#endif
45
46#ifndef max
47#define max(a, b) ((a > b) ? a : b)
48#endif
49
50LONG APIENTRY WaveOutHandler(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags);
51
52//TODO: mulaw, alaw & adpcm
53/******************************************************************************/
54/******************************************************************************/
55DartWaveOut::DartWaveOut(LPWAVEFORMATEX pwfx, ULONG fdwOpen, ULONG nCallback, ULONG dwInstance)
56 : WaveOut(pwfx, fdwOpen, nCallback, dwInstance)
57{
58 MCI_GENERIC_PARMS GenericParms;
59 MCI_AMP_OPEN_PARMS AmpOpenParms;
60 APIRET rc;
61
62 curPlayBuf = curFillBuf = curFillPos = curPlayPos = 0;
63 fMixerSetup = FALSE;
64 fUnderrun = FALSE;
65
66 ulBufSize = DART_BUFSIZE;
67
68 MixBuffer = (MCI_MIX_BUFFER *)malloc(PREFILLBUF_DART*sizeof(MCI_MIX_BUFFER));
69 MixSetupParms = (MCI_MIXSETUP_PARMS *)malloc(sizeof(MCI_MIXSETUP_PARMS));
70 BufferParms = (MCI_BUFFER_PARMS *)malloc(sizeof(MCI_BUFFER_PARMS));
71 if(!MixBuffer || !MixSetupParms || !BufferParms) {
72 dprintf(("ERROR: malloc failed!!"));
73 ulError = MMSYSERR_NOMEM;
74 return;
75 }
76
77 // Setup the open structure, pass the playlist and tell MCI_OPEN to use it
78 memset(&AmpOpenParms,0,sizeof(AmpOpenParms));
79
80 AmpOpenParms.usDeviceID = ( USHORT ) 0;
81 AmpOpenParms.pszDeviceType = ( PSZ ) MCI_DEVTYPE_AUDIO_AMPMIX;
82
83 rc = mymciSendCommand(0, MCI_OPEN, MCI_WAIT | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE,
84 (PVOID) &AmpOpenParms, 0);
85
86 DeviceId = AmpOpenParms.usDeviceID;
87 if(rc) {
88 dprintf(("MCI_OPEN failed\n"));
89 mciError(rc);
90 ulError = MMSYSERR_NODRIVER;
91 }
92 if(rc == 0) {
93 //Grab exclusive rights to device instance (NOT entire device)
94 GenericParms.hwndCallback = 0; //Not needed, so set to 0
95 rc = mymciSendCommand(DeviceId, MCI_ACQUIREDEVICE, MCI_EXCLUSIVE_INSTANCE,
96 (PVOID)&GenericParms, 0);
97 if(rc) {
98 dprintf(("MCI_ACQUIREDEVICE failed\n"));
99 mciError(rc);
100 ulError = MMSYSERR_NOTENABLED;
101 }
102 }
103 setVolume(volume);
104
105 if(!ulError)
106 callback(WOM_OPEN, 0, 0);
107}
108/******************************************************************************/
109/******************************************************************************/
110DartWaveOut::~DartWaveOut()
111{
112 MCI_GENERIC_PARMS GenericParms;
113
114 State = STATE_STOPPED;
115
116 if(!ulError) {
117 // Generic parameters
118 GenericParms.hwndCallback = 0; //hwndFrame
119
120 // Stop the playback.
121 mymciSendCommand(DeviceId, MCI_STOP,MCI_WAIT, (PVOID)&GenericParms,0);
122
123 mymciSendCommand(DeviceId, MCI_BUFFER,
124 MCI_WAIT | MCI_DEALLOCATE_MEMORY,
125 (PVOID)&BufferParms, 0);
126
127 // Generic parameters
128 GenericParms.hwndCallback = 0; //hwndFrame
129
130 // Close the device
131 mymciSendCommand(DeviceId, MCI_CLOSE, MCI_WAIT, (PVOID)&GenericParms, 0);
132 }
133
134 if(!ulError)
135 {
136 callback(WOM_CLOSE, 0, 0);
137 }
138
139 if(MixBuffer)
140 free(MixBuffer);
141 if(MixSetupParms)
142 free(MixSetupParms);
143 if(BufferParms)
144 free(BufferParms);
145}
146/******************************************************************************/
147/******************************************************************************/
148MMRESULT DartWaveOut::write(LPWAVEHDR pwh, UINT cbwh)
149{
150 MCI_GENERIC_PARMS GenericParms = {0};
151 APIRET rc;
152 int i, buflength;
153
154 queuedbuffers++;
155 if(fMixerSetup == FALSE)
156 {
157 dprintf(("device acquired\n"));
158 /* Set the MixSetupParms data structure to match the loaded file.
159 * This is a global that is used to setup the mixer.
160 */
161 memset(MixSetupParms, 0, sizeof( MCI_MIXSETUP_PARMS ) );
162
163 MixSetupParms->ulBitsPerSample = BitsPerSample;
164 MixSetupParms->ulSamplesPerSec = SampleRate;
165 MixSetupParms->ulFormatTag = MCI_WAVE_FORMAT_PCM;
166 MixSetupParms->ulChannels = nChannels;
167
168 dprintf(("bps %d, sps %d chan %d\n", BitsPerSample, SampleRate, nChannels));
169
170 /* Setup the mixer for playback of wave data
171 */
172 MixSetupParms->ulFormatMode = MCI_PLAY;
173 MixSetupParms->ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
174 MixSetupParms->pmixEvent = WaveOutHandler;
175
176 rc = mymciSendCommand(DeviceId,
177 MCI_MIXSETUP,
178 MCI_WAIT | MCI_MIXSETUP_INIT,
179 (PVOID)MixSetupParms,
180 0);
181
182 if ( rc != MCIERR_SUCCESS ) {
183 mciError(rc);
184 mymciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT,
185 (PVOID)&GenericParms, 0);
186 return(MMSYSERR_NOTSUPPORTED);
187 }
188
189 /*
190 * Set up the BufferParms data structure and allocate
191 * device buffers from the Amp-Mixer
192 */
193 dprintf(("mix setup %d, %d\n", pwh->dwBufferLength, pwh->dwBufferLength));
194
195#if 1
196 int consumerate = getAvgBytesPerSecond();
197 int minbufsize = consumerate/32;
198
199 if(pwh->dwBufferLength > minbufsize) {
200 ulBufSize = pwh->dwBufferLength/2;
201 if(ulBufSize < minbufsize) {
202 dprintf(("set buffer size to %d bytes (org size = %d)", minbufsize, pwh->dwBufferLength));
203 ulBufSize = minbufsize;
204 }
205 }
206 else {
207 //assume application knows what it's doing and use the first buffersize
208 ulBufSize = pwh->dwBufferLength;
209 }
210#else
211 if(pwh->dwBufferLength >= 512 && pwh->dwBufferLength <= 1024)
212 ulBufSize = pwh->dwBufferLength;
213 else ulBufSize = 1024;
214#endif
215
216 MixSetupParms->ulBufferSize = ulBufSize;
217
218 BufferParms->ulNumBuffers = PREFILLBUF_DART;
219 BufferParms->ulBufferSize = MixSetupParms->ulBufferSize;
220 BufferParms->pBufList = MixBuffer;
221
222 for(i=0;i<PREFILLBUF_DART;i++) {
223 MixBuffer[i].ulUserParm = (ULONG)this;
224 }
225
226 rc = mymciSendCommand(DeviceId,
227 MCI_BUFFER,
228 MCI_WAIT | MCI_ALLOCATE_MEMORY,
229 (PVOID)BufferParms,
230 0);
231
232 if(ULONG_LOWD(rc) != MCIERR_SUCCESS) {
233 mciError(rc);
234 mymciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT,
235 (PVOID)&GenericParms, 0);
236 return(MMSYSERR_NOTSUPPORTED);
237 }
238
239 wmutex.enter();
240 fMixerSetup = TRUE;
241
242 curPlayBuf = curFillBuf = curFillPos = curPlayPos = 0;
243 bytesPlayed = bytesCopied = bytesReturned = 0;
244
245 for(i=0;i<PREFILLBUF_DART;i++) {
246 memset(MixBuffer[i].pBuffer, 0, MixBuffer[i].ulBufferLength);
247 }
248 dprintf(("Dart opened, bufsize = %d\n", MixBuffer[0].ulBufferLength));
249
250 wavehdr = pwh;
251 curhdr = pwh;
252 pwh->lpNext = NULL;
253 pwh->reserved = 0;
254
255 if(State != STATE_STOPPED) {//don't start playback if paused
256 wmutex.leave();
257 return(MMSYSERR_NOERROR);
258 }
259
260 writeBuffer(); //must be called before (re)starting playback
261
262 dprintf(("MixSetupParms = %X\n", MixSetupParms));
263 State = STATE_PLAYING;
264 fUnderrun = FALSE;
265 wmutex.leave();
266
267 //write buffers to DART; starts playback
268 // MCI_MIXSETUP_PARMS->pMixWrite does alter FS: selector!
269 USHORT selTIB = RestoreOS2FS(); // save current FS selector
270
271 MixSetupParms->pmixWrite(MixSetupParms->ulMixHandle,
272 MixBuffer,
273 PREFILLBUF_DART);
274 SetFS(selTIB); // switch back to the saved FS selector
275 dprintf(("Dart playing\n"));
276 }
277 else
278 {
279 pwh->lpNext = NULL;
280 pwh->reserved = 0;
281 wmutex.enter();
282 if(wavehdr) {
283 WAVEHDR *chdr = wavehdr;
284 while(chdr->lpNext) {
285 chdr = chdr->lpNext;
286 }
287 chdr->lpNext = pwh;
288 }
289 else wavehdr = pwh;
290
291 if(!fUnderrun && State != STATE_STOPPED) {//don't start playback if paused
292 wmutex.leave();
293 return(MMSYSERR_NOERROR);
294 }
295
296 writeBuffer(); //must be called before (re)starting playback
297
298 State = STATE_PLAYING;
299 fUnderrun = FALSE;
300 wmutex.leave();
301
302 //write buffers to DART; starts playback
303 // MCI_MIXSETUP_PARMS->pMixWrite does alter FS: selector!
304 USHORT selTIB = RestoreOS2FS(); // save current FS selector
305
306 MixSetupParms->pmixWrite(MixSetupParms->ulMixHandle,
307 MixBuffer,
308 PREFILLBUF_DART);
309 SetFS(selTIB); // switch back to the saved FS selector
310
311 dprintf(("Dart playing\n"));
312 }
313 return(MMSYSERR_NOERROR);
314}
315/******************************************************************************/
316/******************************************************************************/
317MMRESULT DartWaveOut::pause()
318{
319 MCI_GENERIC_PARMS Params;
320
321 dprintf(("WINMM: DartWaveOut::pause"));
322
323 wmutex.enter();
324 if(State != STATE_PLAYING) {
325 State = STATE_PAUSED;
326 wmutex.leave();
327 return(MMSYSERR_NOERROR);
328 }
329
330 State = STATE_PAUSED;
331 wmutex.leave();
332
333 memset(&Params, 0, sizeof(Params));
334
335 // Pause the playback.
336 mymciSendCommand(DeviceId, MCI_PAUSE, MCI_WAIT, (PVOID)&Params, 0);
337
338 return(MMSYSERR_NOERROR);
339}
340/******************************************************************************/
341/******************************************************************************/
342MMRESULT DartWaveOut::resume()
343{
344 MCI_GENERIC_PARMS Params;
345
346 dprintf(("DartWaveOut::resume"));
347
348 wmutex.enter();
349 if(State != STATE_PAUSED) {
350 wmutex.leave();
351 return(MMSYSERR_NOERROR);
352 }
353
354 State = STATE_PLAYING;
355 wmutex.leave();
356
357 memset(&Params, 0, sizeof(Params));
358
359 // Resume the playback.
360 mymciSendCommand(DeviceId, MCI_RESUME, MCI_WAIT, (PVOID)&Params, 0);
361
362 return(MMSYSERR_NOERROR);
363}
364/******************************************************************************/
365/******************************************************************************/
366MMRESULT DartWaveOut::stop()
367{
368 MCI_GENERIC_PARMS Params;
369
370 dprintf(("DartWaveOut::stop %s", (State == STATE_PLAYING) ? "playing" : "stopped"));
371 if(State != STATE_PLAYING)
372 return(MMSYSERR_HANDLEBUSY);
373
374 memset(&Params, 0, sizeof(Params));
375
376 // Stop the playback.
377 mymciSendCommand(DeviceId, MCI_STOP, MCI_WAIT, (PVOID)&Params, 0);
378
379 State = STATE_STOPPED;
380 fUnderrun = FALSE;
381
382 curPlayBuf = curFillBuf = curFillPos = curPlayPos = 0;
383 bytesPlayed = bytesCopied = bytesReturned = 0;
384
385 return(MMSYSERR_NOERROR);
386}
387/******************************************************************************/
388/******************************************************************************/
389MMRESULT DartWaveOut::reset()
390{
391 MCI_GENERIC_PARMS Params;
392 LPWAVEHDR tmpwavehdr;
393
394 dprintf(("DartWaveOut::reset %s", (State == STATE_PLAYING) ? "playing" : "stopped"));
395 if(State != STATE_PLAYING)
396 return(MMSYSERR_HANDLEBUSY);
397
398 memset(&Params, 0, sizeof(Params));
399
400 // Stop the playback.
401 mymciSendCommand(DeviceId, MCI_STOP, MCI_WAIT, (PVOID)&Params, 0);
402
403 wmutex.enter();
404 while(wavehdr)
405 {
406 wavehdr->dwFlags |= WHDR_DONE;
407 wavehdr->dwFlags &= ~WHDR_INQUEUE;
408 wavehdr->reserved = 0;
409 tmpwavehdr = wavehdr;
410 wavehdr = wavehdr->lpNext;
411 tmpwavehdr->lpNext = NULL;
412 wmutex.leave();
413
414 callback(WOM_DONE, (ULONG)tmpwavehdr, 0);
415 wmutex.enter();
416 }
417 wavehdr = NULL;
418 State = STATE_STOPPED;
419 fUnderrun = FALSE;
420
421 curPlayBuf = curFillBuf = curFillPos = curPlayPos = 0;
422 bytesPlayed = bytesCopied = bytesReturned = 0;
423 queuedbuffers = 0;
424
425 wmutex.leave();
426 return(MMSYSERR_NOERROR);
427}
428/******************************************************************************/
429/******************************************************************************/
430ULONG DartWaveOut::getPosition()
431{
432 MCI_STATUS_PARMS mciStatus = {0};
433 ULONG rc, nrbytes;
434
435 mciStatus.ulItem = MCI_STATUS_POSITION;
436 rc = mymciSendCommand(DeviceId, MCI_STATUS, MCI_STATUS_ITEM|MCI_WAIT, (PVOID)&mciStatus, 0);
437 if((rc & 0xFFFF) == MCIERR_SUCCESS) {
438 nrbytes = (mciStatus.ulReturn * (getAvgBytesPerSecond()/1000));
439 return nrbytes;;
440 }
441 mciError(rc);
442 return 0xFFFFFFFF;
443}
444/******************************************************************************/
445/******************************************************************************/
446BOOL DartWaveOut::queryFormat(ULONG formatTag, ULONG nChannels,
447 ULONG nSamplesPerSec, ULONG wBitsPerSample)
448{
449 MCI_WAVE_GETDEVCAPS_PARMS mciAudioCaps;
450 MCI_GENERIC_PARMS GenericParms;
451 MCI_OPEN_PARMS mciOpenParms; /* open parms for MCI_OPEN */
452 int i, freqbits = 0;
453 ULONG rc, DeviceId;
454 BOOL winrc;
455
456 dprintf(("DartWaveOut::queryFormat %x srate=%d, nchan=%d, bps=%d", formatTag, nSamplesPerSec, nChannels, wBitsPerSample));
457
458 memset(&mciOpenParms, /* Object to fill with zeros. */
459 0, /* Value to place into the object. */
460 sizeof( mciOpenParms ) ); /* How many zero's to use. */
461
462 mciOpenParms.pszDeviceType = (PSZ)MCI_DEVTYPE_WAVEFORM_AUDIO;
463
464 rc = mymciSendCommand( (USHORT) 0,
465 MCI_OPEN,
466 MCI_WAIT | MCI_OPEN_TYPE_ID,
467 (PVOID) &mciOpenParms,
468 0);
469 if((rc & 0xFFFF) != MCIERR_SUCCESS) {
470 mciError(rc);
471 return(FALSE);
472 }
473 DeviceId = mciOpenParms.usDeviceID;
474
475 memset( &mciAudioCaps , 0, sizeof(MCI_WAVE_GETDEVCAPS_PARMS));
476
477 mciAudioCaps.ulBitsPerSample = wBitsPerSample;
478 mciAudioCaps.ulFormatTag = DATATYPE_WAVEFORM;
479 mciAudioCaps.ulSamplesPerSec = nSamplesPerSec;
480 mciAudioCaps.ulChannels = nChannels;
481 mciAudioCaps.ulFormatMode = MCI_PLAY;
482 mciAudioCaps.ulItem = MCI_GETDEVCAPS_WAVE_FORMAT;
483
484 rc = mymciSendCommand(DeviceId, /* Device ID */
485 MCI_GETDEVCAPS,
486 MCI_WAIT | MCI_GETDEVCAPS_EXTENDED | MCI_GETDEVCAPS_ITEM,
487 (PVOID) &mciAudioCaps,
488 0);
489 if((rc & 0xFFFF) != MCIERR_SUCCESS) {
490 mciError(rc);
491 winrc = FALSE;
492 }
493 else winrc = TRUE;
494
495 // Close the device
496 mymciSendCommand(DeviceId,MCI_CLOSE,MCI_WAIT,(PVOID)&GenericParms,0);
497 return(winrc);
498}
499/******************************************************************************/
500/******************************************************************************/
501void DartWaveOut::mciError(ULONG ulError)
502{
503#ifdef DEBUG
504 char szError[256] = "";
505
506 mymciGetErrorString(ulError, szError, sizeof(szError));
507 dprintf(("WINMM: DartWaveOut: %s\n", szError));
508#endif
509}
510//******************************************************************************
511//******************************************************************************
512void DartWaveOut::handler(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags)
513{
514 ULONG buflength;
515 WAVEHDR *whdr, *prevhdr = NULL;
516
517 dprintf2(("WINMM: handler %d; buffers left %d", curPlayBuf, queuedbuffers));
518 if(ulFlags == MIX_STREAM_ERROR) {
519 if(ulStatus == ERROR_DEVICE_UNDERRUN) {
520 dprintf(("WINMM: WaveOut handler UNDERRUN! state %s", (State == STATE_PLAYING) ? "playing" : "stopped"));
521 if(State == STATE_PLAYING) {
522 fUnderrun = TRUE;
523 stop(); //out of buffers, so stop playback
524 }
525 return;
526 }
527 dprintf(("WINMM: WaveOut handler, Unknown error %X\n", ulStatus));
528 return;
529 }
530 if(State != STATE_PLAYING) {
531 return;
532 }
533
534 wmutex.enter();
535
536 bytesPlayed += MixBuffer[curPlayBuf].ulBufferLength;
537
538 if(curPlayBuf == PREFILLBUF_DART-1)
539 curPlayBuf = 0;
540 else curPlayBuf++;
541
542 fUnderrun = FALSE;
543
544 whdr = wavehdr;
545 while(whdr) {
546 if(whdr->reserved == WHDR_DONE)
547 {
548 if(bytesPlayed < bytesReturned + whdr->dwBufferLength) {
549 dprintf2(("Buffer marked done, but not yet played completely (play %d/%d, cop %d, ret %d)", bytesPlayed, getPosition(), bytesCopied, bytesReturned));
550 break; //not yet done
551 }
552
553 dprintf2(("WINMM: handler buf %X done (play %d/%d, cop %d, ret %d)", whdr, bytesPlayed, getPosition(), bytesCopied, bytesReturned));
554 queuedbuffers--;
555
556 whdr->dwFlags &= ~WHDR_INQUEUE;
557 whdr->dwFlags |= WHDR_DONE;
558 whdr->reserved = 0;
559
560 if(prevhdr == NULL)
561 wavehdr = whdr->lpNext;
562 else prevhdr->lpNext = whdr->lpNext;
563
564 whdr->lpNext = NULL;
565
566 bytesReturned += whdr->dwBufferLength;
567 wmutex.leave();
568
569 callback(WOM_DONE, (ULONG)whdr, 0);
570
571 wmutex.enter();
572 }
573 else break;
574
575 prevhdr = whdr;
576 whdr = whdr->lpNext;
577 }
578
579 if(wavehdr == NULL) {
580 //last buffer played -> no new ones -> silence buffer & continue
581 dprintf(("WINMM: WaveOut handler LAST BUFFER PLAYED! state %s (play %d (%d), cop %d, ret %d)", (State == STATE_PLAYING) ? "playing" : "stopped", bytesPlayed, getPosition(), bytesCopied, bytesReturned));
582 if(State == STATE_PLAYING) {
583 fUnderrun = TRUE;
584 pause();
585//// memset(MixBuffer[curPlayBuf].pBuffer, 0, MixBuffer[curPlayBuf].ulBufferLength);
586//// goto sendbuffer;
587 }
588 wmutex.leave();
589 return;
590 }
591
592 writeBuffer();
593
594sendbuffer:
595 wmutex.leave();
596
597 //Transfer buffer to DART
598 // MCI_MIXSETUP_PARMS->pMixWrite does alter FS: selector!
599 USHORT selTIB = RestoreOS2FS(); // save current FS selector
600 MixSetupParms->pmixWrite(MixSetupParms->ulMixHandle, &MixBuffer[curPlayBuf], 1);
601 SetFS(selTIB); // switch back to the saved FS selector
602
603 dprintf2(("WINMM: handler DONE"));
604}
605/******************************************************************************/
606/******************************************************************************/
607void DartWaveOut::writeBuffer()
608{
609 ULONG buflength;
610
611 if(!fUnderrun && State == STATE_PLAYING && curFillBuf == curPlayBuf) {
612 dprintf2(("writeBuffer: no more room for more audio data"));
613 return; //no room left
614 }
615
616 if(curhdr == NULL)
617 curhdr = wavehdr;
618
619 while(curhdr && (curhdr->reserved == WHDR_DONE)) {
620 curhdr = curhdr->lpNext;
621 }
622
623 if(curhdr == NULL) {
624 return; //no unprocessed buffers left
625 }
626
627 dprintf2(("WINMM: handler cur (%d,%d), fill (%d,%d)\n", curPlayBuf, curPlayPos, curFillBuf, curFillPos));
628
629 while(curhdr) {
630 buflength = min((ULONG)MixBuffer[curFillBuf].ulBufferLength - curPlayPos,
631 (ULONG)curhdr->dwBufferLength - curFillPos);
632 dprintf2(("WINMM: copied %d bytes, cufFillPos = %d, curPlayPos = %d, dwBufferLength = %d\n", buflength, curFillPos, curPlayPos, curhdr->dwBufferLength));
633
634 memcpy((char *)MixBuffer[curFillBuf].pBuffer + curPlayPos,
635 curhdr->lpData + curFillPos, buflength);
636 curPlayPos += buflength;
637 curFillPos += buflength;
638 bytesCopied += buflength;
639
640 if(curFillPos == curhdr->dwBufferLength) {
641 dprintf2(("Buffer %d done ptr %x size %d %x %x %x %x %x %x", curFillBuf, curhdr->lpData, curhdr->dwBufferLength, curhdr->dwBytesRecorded, curhdr->dwUser, curhdr->dwFlags, curhdr->dwLoops, curhdr->lpNext, curhdr->reserved));
642
643 curFillPos = 0;
644 curhdr->reserved = WHDR_DONE;
645 //search for next unprocessed buffer
646 while(curhdr && (curhdr->reserved == WHDR_DONE))
647 curhdr = curhdr->lpNext;
648 }
649 if(curPlayPos == MixBuffer[curFillBuf].ulBufferLength) {
650 curPlayPos = 0;
651 if(++curFillBuf == PREFILLBUF_DART) {
652 curFillBuf = 0;
653 }
654 if(curFillBuf == curPlayBuf)
655 break; //no more room left
656 }
657 }
658}
659/******************************************************************************/
660/******************************************************************************/
661LONG APIENTRY WaveOutHandler(ULONG ulStatus,
662 PMCI_MIX_BUFFER pBuffer,
663 ULONG ulFlags)
664{
665 PTIB2 ptib2;
666 DartWaveOut *dwave;
667
668 dprintf2(("WaveOutHandler %x %x %x", ulStatus, pBuffer, ulFlags));
669
670 ptib2 = (PTIB2)_getTIBvalue(offsetof(TIB, tib_ptib2));
671 if(ptib2 && HIBYTE(ptib2->tib2_ulpri) != PRTYC_TIMECRITICAL) {
672 dprintf(("Setting priority of DART thread to PRTYC_TIMECRITICAL"));
673 DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
674 }
675 if(pBuffer && pBuffer->ulUserParm)
676 {
677 dwave = (DartWaveOut *)pBuffer->ulUserParm;
678 dwave->handler(ulStatus, pBuffer, ulFlags);
679 }
680 return(TRUE);
681}
682
683/******************************************************************************/
684/******************************************************************************/
685MMRESULT DartWaveOut::setVolume(ULONG ulVol)
686{
687 ULONG ulVolR = (((ulVol & 0xffff0000) >> 16 )*100)/0xFFFF; // Right Volume
688 ULONG ulVolL = ((ulVol& 0x0000ffff)*100)/0xFFFF; // Left Volume
689 MCI_SET_PARMS msp = {0};
690
691 dprintf(("DartWaveOut::setVolume %d %d", ulVolL, ulVolR));
692 volume = ulVol;
693
694// PD: My card (ESS 1868 PnP) driver can't change only
695// one channel Left or Right :-(
696//
697#ifdef GOOD_AUDIO_CARD_DRIVER
698
699 msp.ulAudio = MCI_SET_AUDIO_LEFT;
700 msp.ulLevel = ulVolL;
701
702 mymciSendCommand(DeviceId, MCI_SET,
703 MCI_WAIT | MCI_SET_AUDIO | MCI_SET_VOLUME,
704 &msp, 0);
705
706 msp.ulAudio = MCI_SET_AUDIO_RIGHT;
707 msp.ulLevel = ulVolR;
708
709#else
710 msp.ulAudio = MCI_SET_AUDIO_ALL;
711 msp.ulLevel = max(ulVolR,ulVolL);
712#endif
713
714 mymciSendCommand(DeviceId, MCI_SET,
715 MCI_WAIT | MCI_SET_AUDIO | MCI_SET_VOLUME,
716 &msp, 0);
717 return 0;
718}
719/******************************************************************************/
720/******************************************************************************/
721
Note: See TracBrowser for help on using the repository browser.