Changeset 2935 for trunk/src/winmm/dwaveout.cpp
- Timestamp:
- Feb 27, 2000, 9:29:47 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/winmm/dwaveout.cpp
r2812 r2935 1 /* $Id: dwaveout.cpp,v 1.1 4 2000-02-17 14:09:30sandervl Exp $ */1 /* $Id: dwaveout.cpp,v 1.15 2000-02-27 20:29:46 sandervl Exp $ */ 2 2 3 3 /* … … 31 31 #include "dwaveout.h" 32 32 33 #define DBG_LOCALLOG 33 #define DBG_LOCALLOG DBG_dwaveout 34 34 #include "dbglocal.h" 35 35 … … 65 65 66 66 if(!ulError) 67 67 callback((ULONG)this, WOM_OPEN, dwInstance, 0, 0); 68 68 } 69 69 /******************************************************************************/ … … 76 76 77 77 if(!ulError) 78 78 PostMessageA(hwndCallback, WOM_OPEN, 0, 0); 79 79 } 80 80 /******************************************************************************/ … … 157 157 DeviceId = AmpOpenParms.usDeviceID; 158 158 if(rc) { 159 #ifdef DEBUG 160 WriteLog("MCI_OPEN failed\n"); 161 #endif 159 dprintf(("MCI_OPEN failed\n")); 162 160 mciError(rc); 163 161 ulError = MMSYSERR_NODRIVER; … … 169 167 (PVOID)&GenericParms, 0); 170 168 if(rc) { 171 #ifdef DEBUG 172 WriteLog("MCI_ACQUIREDEVICE failed\n"); 173 #endif 169 dprintf(("MCI_ACQUIREDEVICE failed\n")); 174 170 mciError(rc); 175 171 ulError = MMSYSERR_NOTENABLED; … … 209 205 210 206 if(!ulError) { 211 212 213 214 215 216 217 207 // Generic parameters 208 GenericParms.hwndCallback = 0; //hwndFrame 209 210 // Stop the playback. 211 mciSendCommand(DeviceId, MCI_STOP,MCI_WAIT, (PVOID)&GenericParms,0); 212 213 mciSendCommand(DeviceId, 218 214 MCI_BUFFER, 219 215 MCI_WAIT | MCI_DEALLOCATE_MEMORY, … … 221 217 0); 222 218 223 224 225 226 227 219 // Generic parameters 220 GenericParms.hwndCallback = 0; //hwndFrame 221 222 // Close the device 223 mciSendCommand(DeviceId, MCI_CLOSE, MCI_WAIT, (PVOID)&GenericParms, 0); 228 224 } 229 225 230 226 if(wmutex) 231 227 wmutex->enter(VMUTEX_WAIT_FOREVER); 232 228 233 229 State = STATE_STOPPED; 234 230 235 231 if(waveout == this) { 236 waveout = this->next;232 waveout = this->next; 237 233 } 238 234 else { 239 DartWaveOut *dwave = waveout;240 241 while(dwave->next != this) {242 dwave = dwave->next;243 }244 dwave->next = this->next;235 DartWaveOut *dwave = waveout; 236 237 while(dwave->next != this) { 238 dwave = dwave->next; 239 } 240 dwave->next = this->next; 245 241 } 246 242 if(wmutex) 247 wmutex->leave();243 wmutex->leave(); 248 244 249 245 if(!ulError) { 250 251 252 253 254 255 246 if(mthdCallback) { 247 callback((ULONG)this, WOM_CLOSE, dwInstance, 0, 0); 248 } 249 else 250 if(hwndCallback) 251 PostMessageA(hwndCallback, WOM_CLOSE, 0, 0); 256 252 } 257 253 258 254 if(wmutex) 259 delete wmutex;255 delete wmutex; 260 256 261 257 if(MixBuffer) 262 free(MixBuffer);258 free(MixBuffer); 263 259 if(MixSetupParms) 264 free(MixSetupParms);260 free(MixSetupParms); 265 261 if(BufferParms) 266 free(BufferParms);262 free(BufferParms); 267 263 } 268 264 /******************************************************************************/ … … 292 288 293 289 if(rc) { 294 290 return 0; //no devices present 295 291 } 296 292 … … 311 307 int i, buflength; 312 308 313 if(fMixerSetup == FALSE) { 314 #ifdef DEBUG 315 WriteLog("device acquired\n"); 316 #endif 317 /* Set the MixSetupParms data structure to match the loaded file. 318 * This is a global that is used to setup the mixer. 319 */ 320 memset(MixSetupParms, 0, sizeof( MCI_MIXSETUP_PARMS ) ); 321 322 MixSetupParms->ulBitsPerSample = BitsPerSample; 323 MixSetupParms->ulSamplesPerSec = SampleRate; 324 MixSetupParms->ulFormatTag = MCI_WAVE_FORMAT_PCM; 325 MixSetupParms->ulChannels = nChannels; 326 327 #ifdef DEBUG 328 WriteLog("bps %d, sps %d chan %d\n", BitsPerSample, SampleRate, nChannels); 329 #endif 309 if(fMixerSetup == FALSE) 310 { 311 dprintf(("device acquired\n")); 312 /* Set the MixSetupParms data structure to match the loaded file. 313 * This is a global that is used to setup the mixer. 314 */ 315 memset(MixSetupParms, 0, sizeof( MCI_MIXSETUP_PARMS ) ); 316 317 MixSetupParms->ulBitsPerSample = BitsPerSample; 318 MixSetupParms->ulSamplesPerSec = SampleRate; 319 MixSetupParms->ulFormatTag = MCI_WAVE_FORMAT_PCM; 320 MixSetupParms->ulChannels = nChannels; 321 322 dprintf(("bps %d, sps %d chan %d\n", BitsPerSample, SampleRate, nChannels)); 330 323 331 324 /* Setup the mixer for playback of wave data 332 325 */ 333 MixSetupParms->ulFormatMode = MCI_PLAY;326 MixSetupParms->ulFormatMode = MCI_PLAY; 334 327 MixSetupParms->ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; 335 328 MixSetupParms->pmixEvent = WaveOutHandler; … … 341 334 0); 342 335 343 if ( rc != MCIERR_SUCCESS ) {344 mciError(rc);345 mciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT,346 (PVOID)&GenericParms, 0);347 return(MMSYSERR_NOTSUPPORTED);348 }336 if ( rc != MCIERR_SUCCESS ) { 337 mciError(rc); 338 mciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT, 339 (PVOID)&GenericParms, 0); 340 return(MMSYSERR_NOTSUPPORTED); 341 } 349 342 350 343 /* … … 352 345 * device buffers from the Amp-Mixer 353 346 */ 354 #ifdef DEBUG 355 WriteLog("mix setup %d, %d\n", pwh->dwBufferLength, pwh->dwBufferLength); 356 #endif 347 dprintf(("mix setup %d, %d\n", pwh->dwBufferLength, pwh->dwBufferLength)); 348 357 349 #if 1 358 ulBufSize = pwh->dwBufferLength/2;350 ulBufSize = pwh->dwBufferLength/2; 359 351 #else 360 if(pwh->dwBufferLength >= 512 && pwh->dwBufferLength <= 1024)361 ulBufSize = pwh->dwBufferLength;362 else ulBufSize = 1024;363 #endif 364 365 MixSetupParms->ulBufferSize = ulBufSize;352 if(pwh->dwBufferLength >= 512 && pwh->dwBufferLength <= 1024) 353 ulBufSize = pwh->dwBufferLength; 354 else ulBufSize = 1024; 355 #endif 356 357 MixSetupParms->ulBufferSize = ulBufSize; 366 358 367 359 BufferParms->ulNumBuffers = PREFILLBUF_DART; … … 370 362 371 363 for(i=0;i<PREFILLBUF_DART;i++) { 372 MixBuffer[i].ulUserParm = (ULONG)this;364 MixBuffer[i].ulUserParm = (ULONG)this; 373 365 } 374 366 … … 380 372 381 373 if(ULONG_LOWD(rc) != MCIERR_SUCCESS) { 382 mciError(rc);383 mciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT,384 (PVOID)&GenericParms, 0);385 return(MMSYSERR_NOTSUPPORTED);386 }387 388 wmutex->enter(VMUTEX_WAIT_FOREVER);389 fMixerSetup = TRUE;390 391 curPlayBuf = curFillBuf = curFillPos = curPlayPos = 0;374 mciError(rc); 375 mciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT, 376 (PVOID)&GenericParms, 0); 377 return(MMSYSERR_NOTSUPPORTED); 378 } 379 380 wmutex->enter(VMUTEX_WAIT_FOREVER); 381 fMixerSetup = TRUE; 382 383 curPlayBuf = curFillBuf = curFillPos = curPlayPos = 0; 392 384 393 385 for(i=0;i<PREFILLBUF_DART;i++) { 394 memset(MixBuffer[i].pBuffer, 0, MixBuffer[i].ulBufferLength);395 }396 #ifdef DEBUG 397 WriteLog("Dart opened, bufsize = %d\n", MixBuffer[i].ulBufferLength); 398 #endif 399 400 wavehdr = pwh;401 curhdr = pwh; 402 pwh->lpNext = NULL;403 404 while(TRUE) {405 buflength = min((ULONG)MixBuffer[curFillBuf].ulBufferLength - curPlayPos,406 (ULONG)wavehdr->dwBufferLength - curFillPos); 407 #ifdef DEBUG 408 WriteLog("Copying %d data; curPlayPos = %d curFillPos = %d\n", buflength, curPlayPos, curFillPos);409 #endif 410 memcpy((char *)MixBuffer[curFillBuf].pBuffer + curPlayPos, 411 wavehdr->lpData + curFillPos,412 buflength);413 414 curPlayPos += buflength;415 curFillPos += buflength;416 if(curFillPos == wavehdr->dwBufferLength) {417 #ifdef DEBUG 418 WriteLog("Processed first win32 buffer\n");419 #endif 420 curFillPos = 0;421 wavehdr->dwFlags |= WHDR_DONE;422 curhdr = NULL;423 }424 if(curPlayPos == MixBuffer[curPlayBuf].ulBufferLength) {425 if(++curPlayBuf == PREFILLBUF_DART) {426 curPlayBuf = 0;386 memset(MixBuffer[i].pBuffer, 0, MixBuffer[i].ulBufferLength); 387 } 388 dprintf(("Dart opened, bufsize = %d\n", MixBuffer[i].ulBufferLength)); 389 390 wavehdr = pwh; 391 curhdr = pwh; 392 pwh->lpNext = NULL; 393 394 while(TRUE) { 395 buflength = min((ULONG)MixBuffer[curFillBuf].ulBufferLength - curPlayPos, 396 (ULONG)wavehdr->dwBufferLength - curFillPos); 397 dprintf(("Copying %d data; curPlayPos = %d curFillPos = %d\n", buflength, curPlayPos, curFillPos)); 398 399 memcpy((char *)MixBuffer[curFillBuf].pBuffer + curPlayPos, 400 wavehdr->lpData + curFillPos, 401 buflength); 402 403 curPlayPos += buflength; 404 curFillPos += buflength; 405 if(curFillPos == wavehdr->dwBufferLength) { 406 dprintf(("Processed first win32 buffer\n")); 407 curFillPos = 0; 408 wavehdr->dwFlags |= WHDR_DONE; 409 curhdr = NULL; 410 } 411 if(curPlayPos == MixBuffer[curPlayBuf].ulBufferLength) { 412 if(++curPlayBuf == PREFILLBUF_DART) { 413 curPlayBuf = 0; 414 break; 415 } 416 curPlayPos = 0; 417 } 418 if(curFillPos == 0) 427 419 break; 420 } 421 dprintf(("MixSetupParms = %X\n", MixSetupParms)); 422 State = STATE_PLAYING; 423 wmutex->leave(); 424 425 MixSetupParms->pmixWrite(MixSetupParms->ulMixHandle, 426 MixBuffer, 427 PREFILLBUF_DART); 428 dprintf(("Dart playing\n")); 429 } 430 else 431 { 432 wmutex->enter(VMUTEX_WAIT_FOREVER); 433 pwh->lpNext = NULL; 434 if(wavehdr) { 435 WAVEHDR *chdr = wavehdr; 436 while(chdr->lpNext) { 437 chdr = chdr->lpNext; 428 438 } 429 curPlayPos = 0; 430 } 431 if(curFillPos == 0) 432 break; 433 } 434 #ifdef DEBUG 435 WriteLog("MixSetupParms = %X\n", MixSetupParms); 436 #endif 437 State = STATE_PLAYING; 438 wmutex->leave(); 439 440 MixSetupParms->pmixWrite(MixSetupParms->ulMixHandle, 441 MixBuffer, 442 PREFILLBUF_DART); 443 #ifdef DEBUG 444 WriteLog("Dart playing\n"); 445 #endif 446 } 447 else { 448 wmutex->enter(VMUTEX_WAIT_FOREVER); 449 pwh->lpNext = NULL; 450 if(wavehdr) { 451 WAVEHDR *chdr = wavehdr; 452 while(chdr->lpNext) { 453 chdr = chdr->lpNext; 454 } 455 chdr->lpNext = pwh; 456 } 457 else wavehdr = pwh; 458 wmutex->leave(); 459 if(State != STATE_PLAYING) {//continue playback 460 restart(); 461 } 439 chdr->lpNext = pwh; 440 } 441 else wavehdr = pwh; 442 wmutex->leave(); 443 if(State != STATE_PLAYING) {//continue playback 444 restart(); 445 } 462 446 } 463 447 … … 471 455 472 456 if(State != STATE_PLAYING) 473 return(MMSYSERR_HANDLEBUSY);457 return(MMSYSERR_NOERROR); 474 458 475 459 wmutex->enter(VMUTEX_WAIT_FOREVER); … … 492 476 dprintf(("DartWaveOut::reset %s", (State == STATE_PLAYING) ? "playing" : "stopped")); 493 477 if(State != STATE_PLAYING) 494 return(MMSYSERR_HANDLEBUSY);478 return(MMSYSERR_HANDLEBUSY); 495 479 496 480 memset(&Params, 0, sizeof(Params)); … … 499 483 mciSendCommand(DeviceId, MCI_STOP, MCI_WAIT, (PVOID)&Params, 0); 500 484 501 #ifdef DEBUG 502 WriteLog("Nr of threads blocked on mutex = %d\n", wmutex->getNrBlocked()); 503 #endif 485 dprintf(("Nr of threads blocked on mutex = %d\n", wmutex->getNrBlocked())); 504 486 505 487 wmutex->enter(VMUTEX_WAIT_FOREVER); … … 510 492 callback((ULONG)this, WOM_DONE, dwInstance, wavehdr->dwUser, (ULONG)wavehdr); 511 493 } 512 else 494 else { 513 495 if(hwndCallback) 514 PostMessageA(hwndCallback, WOM_DONE, wavehdr->dwUser, (ULONG)wavehdr);515 496 PostMessageA(hwndCallback, WOM_DONE, wavehdr->dwUser, (ULONG)wavehdr); 497 } 516 498 wmutex->enter(VMUTEX_WAIT_FOREVER); 517 499 wavehdr = wavehdr->lpNext; … … 527 509 MMRESULT DartWaveOut::restart() 528 510 { 529 dprintf(("DartWaveOut::restart")); 530 wmutex->enter(VMUTEX_WAIT_FOREVER); 531 State = STATE_PLAYING; 532 wmutex->leave(); 533 MixSetupParms->pmixWrite(MixSetupParms->ulMixHandle, 534 &MixBuffer[curPlayBuf], 535 PREFILLBUF_DART); 536 return(MMSYSERR_NOERROR); 511 dprintf(("DartWaveOut::restart")); 512 wmutex->enter(VMUTEX_WAIT_FOREVER); 513 State = STATE_PLAYING; 514 wmutex->leave(); 515 MixSetupParms->pmixWrite(MixSetupParms->ulMixHandle, 516 &MixBuffer[curPlayBuf], 517 PREFILLBUF_DART); 518 return(MMSYSERR_NOERROR); 519 } 520 /******************************************************************************/ 521 /******************************************************************************/ 522 ULONG DartWaveOut::getPosition() 523 { 524 MCI_STATUS_PARMS mciStatus = {0}; 525 ULONG rc, nrbytes; 526 527 if(State != STATE_PLAYING) 528 return 0; 529 530 mciStatus.ulItem = MCI_STATUS_POSITION; 531 rc = mciSendCommand(DeviceId, MCI_STATUS, MCI_STATUS_ITEM|MCI_WAIT, (PVOID)&mciStatus, 0); 532 if((rc & 0xFFFF) == MCIERR_SUCCESS) { 533 nrbytes = (mciStatus.ulReturn * getAvgBytesPerSecond())/1000; 534 return nrbytes;; 535 } 536 mciError(rc); 537 return 0xFFFFFFFF; 537 538 } 538 539 /******************************************************************************/ … … 560 561 0); 561 562 if (rc != 0) { 562 return(FALSE);563 return(FALSE); 563 564 } 564 565 DeviceId = mciOpenParms.usDeviceID; … … 591 592 0); 592 593 if((rc & 0xFFFF) != MCIERR_SUCCESS) { 593 594 595 } 596 else 594 mciError(rc); 595 winrc = FALSE; 596 } 597 else winrc = TRUE; 597 598 598 599 // Close the device … … 608 609 609 610 mciGetErrorString(ulError, szError, sizeof(szError)); 610 WriteLog("WINMM: DartWaveOut: %s\n", szError);611 dprintf(("WINMM: DartWaveOut: %s\n", szError)); 611 612 #endif 612 613 } … … 637 638 638 639 #ifdef DEBUG1 639 WriteLog("WINMM: handler %d\n", curPlayBuf);640 dprintf(("WINMM: handler %d\n", curPlayBuf)); 640 641 #endif 641 642 if(ulFlags == MIX_STREAM_ERROR) { … … 653 654 if(whdr->dwFlags & WHDR_DONE) { 654 655 #ifdef DEBUG1 655 WriteLog("WINMM: handler buf %X done\n", whdr);656 dprintf(("WINMM: handler buf %X done\n", whdr)); 656 657 #endif 657 658 whdr->dwFlags &= ~WHDR_INQUEUE; … … 681 682 682 683 #ifdef DEBUG1 683 WriteLog("WINMM: handler cur (%d,%d), fill (%d,%d)\n", curPlayBuf, curPlayPos, curFillBuf, curFillPos);684 dprintf(("WINMM: handler cur (%d,%d), fill (%d,%d)\n", curPlayBuf, curPlayPos, curFillBuf, curFillPos)); 684 685 #endif 685 686 … … 693 694 curFillPos += buflength; 694 695 #ifdef DEBUG1 695 WriteLog("WINMM: copied %d bytes, cufFillPos = %d, dwBufferLength = %d\n", buflength, curFillPos, curhdr->dwBufferLength);696 dprintf(("WINMM: copied %d bytes, cufFillPos = %d, dwBufferLength = %d\n", buflength, curFillPos, curhdr->dwBufferLength)); 696 697 #endif 697 698 if(curFillPos == curhdr->dwBufferLength) { 698 699 #ifdef DEBUG1 699 WriteLog("Buffer %d done\n", curFillBuf);700 dprintf(("Buffer %d done\n", curFillBuf)); 700 701 #endif 701 702 curFillPos = 0; … … 747 748 /******************************************************************************/ 748 749 MMRESULT DartWaveOut::setVolume(ULONG ulVol) 749 { 750 ULONG ulVolR = (((ulVol & 0xffff0000) >> 16 )*100)/0xFFFF; // Right Volume 750 { 751 ULONG ulVolR = (((ulVol & 0xffff0000) >> 16 )*100)/0xFFFF; // Right Volume 751 752 ULONG ulVolL = ((ulVol& 0x0000ffff)*100)/0xFFFF; // Left Volume 752 753 MCI_SET_PARMS msp = {0}; … … 757 758 // one channel Left or Right :-( 758 759 // 759 #ifdef GOOD_AUDIO_CARD_DRIVER 760 #ifdef GOOD_AUDIO_CARD_DRIVER 760 761 761 762 msp.ulAudio = MCI_SET_AUDIO_LEFT;
Note:
See TracChangeset
for help on using the changeset viewer.