comparison src/audio/dart/SDL_dart.c @ 2060:866052b01ee5

indent is evil
author Sam Lantinga <slouken@libsdl.org>
date Sat, 28 Oct 2006 16:48:03 +0000
parents 5f6550e5184f
children e1da92da346c
comparison
equal deleted inserted replaced
2059:4685ccd33d0e 2060:866052b01ee5
88 int iSilence; 88 int iSilence;
89 int rc; 89 int rc;
90 90
91 /* Initialize all variables that we clean on shutdown */ 91 /* Initialize all variables that we clean on shutdown */
92 _this->hidden = (struct SDL_PrivateAudioData *) 92 _this->hidden = (struct SDL_PrivateAudioData *)
93 SDL_malloc((sizeof *_this->hidden)); 93 SDL_malloc((sizeof *_this->hidden));
94 if (_this->hidden == NULL) { 94 if (_this->hidden == NULL) {
95 SDL_OutOfMemory(); 95 SDL_OutOfMemory();
96 return 0; 96 return 0;
97 } 97 }
98 SDL_memset(_this->hidden, 0, (sizeof *_this->hidden)); 98 SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
106 iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID; 106 iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID;
107 if (bOpenShared) 107 if (bOpenShared)
108 iOpenMode |= MCI_OPEN_SHAREABLE; 108 iOpenMode |= MCI_OPEN_SHAREABLE;
109 109
110 rc = mciSendCommand(0, MCI_OPEN, iOpenMode, (PVOID) & AmpOpenParms, 0); 110 rc = mciSendCommand(0, MCI_OPEN, iOpenMode, (PVOID) & AmpOpenParms, 0);
111 if (rc != MCIERR_SUCCESS) { // No audio available?? 111 if (rc != MCIERR_SUCCESS) { // No audio available??
112 DART_CloseDevice(_this); 112 DART_CloseDevice(_this);
113 SDL_SetError("DART: Couldn't open audio device."); 113 SDL_SetError("DART: Couldn't open audio device.");
114 return 0; 114 return 0;
115 } 115 }
116
117 // Save the device ID we got from DART! 116 // Save the device ID we got from DART!
118 // We will use this in the next calls! 117 // We will use this in the next calls!
119 _this->hidden->iCurrDeviceOrd = iDeviceOrd = AmpOpenParms.usDeviceID; 118 _this->hidden->iCurrDeviceOrd = iDeviceOrd = AmpOpenParms.usDeviceID;
120 119
121 // Determine the audio parameters from the AudioSpec 120 // Determine the audio parameters from the AudioSpec
359 pMixBufferDesc pBufDesc; 358 pMixBufferDesc pBufDesc;
360 ULONG ulPostCount = 0; 359 ULONG ulPostCount = 0;
361 APIRET rc = NO_ERROR; 360 APIRET rc = NO_ERROR;
362 361
363 pBufDesc = (pMixBufferDesc) 362 pBufDesc = (pMixBufferDesc)
364 _this->hidden->pMixBuffers[_this->hidden->iLastPlayedBuf].ulUserParm; 363 _this->hidden->pMixBuffers[_this->hidden->iLastPlayedBuf].ulUserParm;
365 364
366 while ((pBufDesc->iBufferUsage != BUFFER_EMPTY) && (rc == NO_ERROR)) { 365 while ((pBufDesc->iBufferUsage != BUFFER_EMPTY) && (rc == NO_ERROR)) {
367 DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount); 366 DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
368 rc = DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // 1 sec timeout! Important! 367 rc = DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // 1 sec timeout! Important!
369 } 368 }
386 printf("Could not stop DART playback!\n"); 385 printf("Could not stop DART playback!\n");
387 fflush(stdout); 386 fflush(stdout);
388 } 387 }
389 #endif 388 #endif
390 } 389 }
391
392 // Close event semaphore 390 // Close event semaphore
393 if (_this->hidden->hevAudioBufferPlayed) { 391 if (_this->hidden->hevAudioBufferPlayed) {
394 DosCloseEventSem(_this->hidden->hevAudioBufferPlayed); 392 DosCloseEventSem(_this->hidden->hevAudioBufferPlayed);
395 _this->hidden->hevAudioBufferPlayed = 0; 393 _this->hidden->hevAudioBufferPlayed = 0;
396 } 394 }
397
398 // Free memory of buffer descriptions 395 // Free memory of buffer descriptions
399 for (i = 0; i < _this->hidden->iCurrNumBufs; i++) { 396 for (i = 0; i < _this->hidden->iCurrNumBufs; i++) {
400 SDL_free((void *) (_this->hidden->pMixBuffers[i].ulUserParm)); 397 SDL_free((void *) (_this->hidden->pMixBuffers[i].ulUserParm));
401 _this->hidden->pMixBuffers[i].ulUserParm = 0; 398 _this->hidden->pMixBuffers[i].ulUserParm = 0;
402 } 399 }
406 if (_this->hidden->iCurrDeviceOrd) { 403 if (_this->hidden->iCurrDeviceOrd) {
407 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER, 404 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER,
408 MCI_WAIT | MCI_DEALLOCATE_MEMORY, 405 MCI_WAIT | MCI_DEALLOCATE_MEMORY,
409 &(_this->hidden->BufferParms), 0); 406 &(_this->hidden->BufferParms), 0);
410 } 407 }
411
412 // Free bufferlist 408 // Free bufferlist
413 if (_this->hidden->pMixBuffers != NULL) { 409 if (_this->hidden->pMixBuffers != NULL) {
414 SDL_free(_this->hidden->pMixBuffers); 410 SDL_free(_this->hidden->pMixBuffers);
415 _this->hidden->pMixBuffers = NULL; 411 _this->hidden->pMixBuffers = NULL;
416 } 412 }
417
418 // Close dart 413 // Close dart
419 if (_this->hidden->iCurrDeviceOrd) { 414 if (_this->hidden->iCurrDeviceOrd) {
420 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_CLOSE, 415 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_CLOSE,
421 MCI_WAIT, &(GenericParms), 0); 416 MCI_WAIT, &(GenericParms), 0);
422 } 417 }
427 } 422 }
428 } 423 }
429 424
430 425
431 static int 426 static int
432 DART_Init(SDL_AudioDriverImpl *impl) 427 DART_Init(SDL_AudioDriverImpl * impl)
433 { 428 {
434 /* Set the function pointers */ 429 /* Set the function pointers */
435 impl->OpenDevice = DART_OpenDevice; 430 impl->OpenDevice = DART_OpenDevice;
436 impl->ThreadInit = DART_ThreadInit; 431 impl->ThreadInit = DART_ThreadInit;
437 impl->WaitDevice = DART_WaitDevice; 432 impl->WaitDevice = DART_WaitDevice;
438 impl->GetDeviceBuf = DART_GetDeviceBuf; 433 impl->GetDeviceBuf = DART_GetDeviceBuf;
439 impl->PlayDevice = DART_PlayDevice; 434 impl->PlayDevice = DART_PlayDevice;
440 impl->WaitDone = DART_WaitDone; 435 impl->WaitDone = DART_WaitDone;
441 impl->CloseDevice = DART_CloseDevice; 436 impl->CloseDevice = DART_CloseDevice;
442 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: is this right? */ 437 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: is this right? */
443 438
444 return 1; 439 return 1;
445 } 440 }
446 441
447 442