1.1 --- a/src/audio/windx5/SDL_dx5audio.c Sun May 21 17:27:13 2006 +0000
1.2 +++ b/src/audio/windx5/SDL_dx5audio.c Sun May 28 13:04:16 2006 +0000
1.3 @@ -32,664 +32,693 @@
1.4 //#define USE_POSITION_NOTIFY
1.5
1.6 /* DirectX function pointers for audio */
1.7 -HRESULT (WINAPI *DSoundCreate)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN);
1.8 +HRESULT (WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN);
1.9
1.10 /* Audio driver functions */
1.11 -static int DX5_OpenAudio(_THIS, SDL_AudioSpec *spec);
1.12 -static void DX5_ThreadInit(_THIS);
1.13 -static void DX5_WaitAudio_BusyWait(_THIS);
1.14 +static int DX5_OpenAudio (_THIS, SDL_AudioSpec * spec);
1.15 +static void DX5_ThreadInit (_THIS);
1.16 +static void DX5_WaitAudio_BusyWait (_THIS);
1.17 #ifdef USE_POSITION_NOTIFY
1.18 -static void DX6_WaitAudio_EventWait(_THIS);
1.19 +static void DX6_WaitAudio_EventWait (_THIS);
1.20 #endif
1.21 -static void DX5_PlayAudio(_THIS);
1.22 -static Uint8 *DX5_GetAudioBuf(_THIS);
1.23 -static void DX5_WaitDone(_THIS);
1.24 -static void DX5_CloseAudio(_THIS);
1.25 +static void DX5_PlayAudio (_THIS);
1.26 +static Uint8 *DX5_GetAudioBuf (_THIS);
1.27 +static void DX5_WaitDone (_THIS);
1.28 +static void DX5_CloseAudio (_THIS);
1.29
1.30 /* Audio driver bootstrap functions */
1.31
1.32 -static int Audio_Available(void)
1.33 +static int
1.34 +Audio_Available (void)
1.35 {
1.36 - HINSTANCE DSoundDLL;
1.37 - int dsound_ok;
1.38 + HINSTANCE DSoundDLL;
1.39 + int dsound_ok;
1.40
1.41 - /* Version check DSOUND.DLL (Is DirectX okay?) */
1.42 - dsound_ok = 0;
1.43 - DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL"));
1.44 - if ( DSoundDLL != NULL ) {
1.45 - /* We just use basic DirectSound, we're okay */
1.46 - /* Yay! */
1.47 - /* Unfortunately, the sound drivers on NT have
1.48 - higher latencies than the audio buffers used
1.49 - by many SDL applications, so there are gaps
1.50 - in the audio - it sounds terrible. Punt for now.
1.51 - */
1.52 - OSVERSIONINFO ver;
1.53 - ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
1.54 - GetVersionEx(&ver);
1.55 - switch (ver.dwPlatformId) {
1.56 - case VER_PLATFORM_WIN32_NT:
1.57 - if ( ver.dwMajorVersion > 4 ) {
1.58 - /* Win2K */
1.59 - dsound_ok = 1;
1.60 - } else {
1.61 - /* WinNT */
1.62 - dsound_ok = 0;
1.63 - }
1.64 - break;
1.65 - default:
1.66 - /* Win95 or Win98 */
1.67 - dsound_ok = 1;
1.68 - break;
1.69 - }
1.70 - /* Now check for DirectX 5 or better - otherwise
1.71 - * we will fail later in DX5_OpenAudio without a chance
1.72 - * to fall back to the DIB driver. */
1.73 - if (dsound_ok) {
1.74 - /* DirectSoundCaptureCreate was added in DX5 */
1.75 - if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate")))
1.76 - dsound_ok = 0;
1.77 + /* Version check DSOUND.DLL (Is DirectX okay?) */
1.78 + dsound_ok = 0;
1.79 + DSoundDLL = LoadLibrary (TEXT ("DSOUND.DLL"));
1.80 + if (DSoundDLL != NULL) {
1.81 + /* We just use basic DirectSound, we're okay */
1.82 + /* Yay! */
1.83 + /* Unfortunately, the sound drivers on NT have
1.84 + higher latencies than the audio buffers used
1.85 + by many SDL applications, so there are gaps
1.86 + in the audio - it sounds terrible. Punt for now.
1.87 + */
1.88 + OSVERSIONINFO ver;
1.89 + ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
1.90 + GetVersionEx (&ver);
1.91 + switch (ver.dwPlatformId) {
1.92 + case VER_PLATFORM_WIN32_NT:
1.93 + if (ver.dwMajorVersion > 4) {
1.94 + /* Win2K */
1.95 + dsound_ok = 1;
1.96 + } else {
1.97 + /* WinNT */
1.98 + dsound_ok = 0;
1.99 + }
1.100 + break;
1.101 + default:
1.102 + /* Win95 or Win98 */
1.103 + dsound_ok = 1;
1.104 + break;
1.105 + }
1.106 + /* Now check for DirectX 5 or better - otherwise
1.107 + * we will fail later in DX5_OpenAudio without a chance
1.108 + * to fall back to the DIB driver. */
1.109 + if (dsound_ok) {
1.110 + /* DirectSoundCaptureCreate was added in DX5 */
1.111 + if (!GetProcAddress
1.112 + (DSoundDLL, TEXT ("DirectSoundCaptureCreate")))
1.113 + dsound_ok = 0;
1.114
1.115 - }
1.116 - /* Clean up.. */
1.117 - FreeLibrary(DSoundDLL);
1.118 - }
1.119 - return(dsound_ok);
1.120 + }
1.121 + /* Clean up.. */
1.122 + FreeLibrary (DSoundDLL);
1.123 + }
1.124 + return (dsound_ok);
1.125 }
1.126
1.127 /* Functions for loading the DirectX functions dynamically */
1.128 static HINSTANCE DSoundDLL = NULL;
1.129
1.130 -static void DX5_Unload(void)
1.131 +static void
1.132 +DX5_Unload (void)
1.133 {
1.134 - if ( DSoundDLL != NULL ) {
1.135 - FreeLibrary(DSoundDLL);
1.136 - DSoundCreate = NULL;
1.137 - DSoundDLL = NULL;
1.138 - }
1.139 + if (DSoundDLL != NULL) {
1.140 + FreeLibrary (DSoundDLL);
1.141 + DSoundCreate = NULL;
1.142 + DSoundDLL = NULL;
1.143 + }
1.144 }
1.145 -static int DX5_Load(void)
1.146 +static int
1.147 +DX5_Load (void)
1.148 {
1.149 - int status;
1.150 + int status;
1.151
1.152 - DX5_Unload();
1.153 - DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL"));
1.154 - if ( DSoundDLL != NULL ) {
1.155 - DSoundCreate = (void *)GetProcAddress(DSoundDLL,
1.156 - TEXT("DirectSoundCreate"));
1.157 - }
1.158 - if ( DSoundDLL && DSoundCreate ) {
1.159 - status = 0;
1.160 - } else {
1.161 - DX5_Unload();
1.162 - status = -1;
1.163 - }
1.164 - return status;
1.165 + DX5_Unload ();
1.166 + DSoundDLL = LoadLibrary (TEXT ("DSOUND.DLL"));
1.167 + if (DSoundDLL != NULL) {
1.168 + DSoundCreate = (void *) GetProcAddress (DSoundDLL,
1.169 + TEXT ("DirectSoundCreate"));
1.170 + }
1.171 + if (DSoundDLL && DSoundCreate) {
1.172 + status = 0;
1.173 + } else {
1.174 + DX5_Unload ();
1.175 + status = -1;
1.176 + }
1.177 + return status;
1.178 }
1.179
1.180 -static void Audio_DeleteDevice(SDL_AudioDevice *device)
1.181 +static void
1.182 +Audio_DeleteDevice (SDL_AudioDevice * device)
1.183 {
1.184 - DX5_Unload();
1.185 - SDL_free(device->hidden);
1.186 - SDL_free(device);
1.187 + DX5_Unload ();
1.188 + SDL_free (device->hidden);
1.189 + SDL_free (device);
1.190 }
1.191
1.192 -static SDL_AudioDevice *Audio_CreateDevice(int devindex)
1.193 +static SDL_AudioDevice *
1.194 +Audio_CreateDevice (int devindex)
1.195 {
1.196 - SDL_AudioDevice *this;
1.197 + SDL_AudioDevice *this;
1.198
1.199 - /* Load DirectX */
1.200 - if ( DX5_Load() < 0 ) {
1.201 - return(NULL);
1.202 - }
1.203 + /* Load DirectX */
1.204 + if (DX5_Load () < 0) {
1.205 + return (NULL);
1.206 + }
1.207
1.208 - /* Initialize all variables that we clean on shutdown */
1.209 - this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
1.210 - if ( this ) {
1.211 - SDL_memset(this, 0, (sizeof *this));
1.212 - this->hidden = (struct SDL_PrivateAudioData *)
1.213 - SDL_malloc((sizeof *this->hidden));
1.214 - }
1.215 - if ( (this == NULL) || (this->hidden == NULL) ) {
1.216 - SDL_OutOfMemory();
1.217 - if ( this ) {
1.218 - SDL_free(this);
1.219 - }
1.220 - return(0);
1.221 - }
1.222 - SDL_memset(this->hidden, 0, (sizeof *this->hidden));
1.223 + /* Initialize all variables that we clean on shutdown */
1.224 + this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice));
1.225 + if (this) {
1.226 + SDL_memset (this, 0, (sizeof *this));
1.227 + this->hidden = (struct SDL_PrivateAudioData *)
1.228 + SDL_malloc ((sizeof *this->hidden));
1.229 + }
1.230 + if ((this == NULL) || (this->hidden == NULL)) {
1.231 + SDL_OutOfMemory ();
1.232 + if (this) {
1.233 + SDL_free (this);
1.234 + }
1.235 + return (0);
1.236 + }
1.237 + SDL_memset (this->hidden, 0, (sizeof *this->hidden));
1.238
1.239 - /* Set the function pointers */
1.240 - this->OpenAudio = DX5_OpenAudio;
1.241 - this->ThreadInit = DX5_ThreadInit;
1.242 - this->WaitAudio = DX5_WaitAudio_BusyWait;
1.243 - this->PlayAudio = DX5_PlayAudio;
1.244 - this->GetAudioBuf = DX5_GetAudioBuf;
1.245 - this->WaitDone = DX5_WaitDone;
1.246 - this->CloseAudio = DX5_CloseAudio;
1.247 + /* Set the function pointers */
1.248 + this->OpenAudio = DX5_OpenAudio;
1.249 + this->ThreadInit = DX5_ThreadInit;
1.250 + this->WaitAudio = DX5_WaitAudio_BusyWait;
1.251 + this->PlayAudio = DX5_PlayAudio;
1.252 + this->GetAudioBuf = DX5_GetAudioBuf;
1.253 + this->WaitDone = DX5_WaitDone;
1.254 + this->CloseAudio = DX5_CloseAudio;
1.255
1.256 - this->free = Audio_DeleteDevice;
1.257 + this->free = Audio_DeleteDevice;
1.258
1.259 - return this;
1.260 + return this;
1.261 }
1.262
1.263 AudioBootStrap DSOUND_bootstrap = {
1.264 - "dsound", "Win95/98/2000 DirectSound",
1.265 - Audio_Available, Audio_CreateDevice
1.266 + "dsound", "Win95/98/2000 DirectSound",
1.267 + Audio_Available, Audio_CreateDevice
1.268 };
1.269
1.270 -static void SetDSerror(const char *function, int code)
1.271 +static void
1.272 +SetDSerror (const char *function, int code)
1.273 {
1.274 - static const char *error;
1.275 - static char errbuf[1024];
1.276 + static const char *error;
1.277 + static char errbuf[1024];
1.278
1.279 - errbuf[0] = 0;
1.280 - switch (code) {
1.281 - case E_NOINTERFACE:
1.282 - error =
1.283 - "Unsupported interface\n-- Is DirectX 5.0 or later installed?";
1.284 - break;
1.285 - case DSERR_ALLOCATED:
1.286 - error = "Audio device in use";
1.287 - break;
1.288 - case DSERR_BADFORMAT:
1.289 - error = "Unsupported audio format";
1.290 - break;
1.291 - case DSERR_BUFFERLOST:
1.292 - error = "Mixing buffer was lost";
1.293 - break;
1.294 - case DSERR_CONTROLUNAVAIL:
1.295 - error = "Control requested is not available";
1.296 - break;
1.297 - case DSERR_INVALIDCALL:
1.298 - error = "Invalid call for the current state";
1.299 - break;
1.300 - case DSERR_INVALIDPARAM:
1.301 - error = "Invalid parameter";
1.302 - break;
1.303 - case DSERR_NODRIVER:
1.304 - error = "No audio device found";
1.305 - break;
1.306 - case DSERR_OUTOFMEMORY:
1.307 - error = "Out of memory";
1.308 - break;
1.309 - case DSERR_PRIOLEVELNEEDED:
1.310 - error = "Caller doesn't have priority";
1.311 - break;
1.312 - case DSERR_UNSUPPORTED:
1.313 - error = "Function not supported";
1.314 - break;
1.315 - default:
1.316 - SDL_snprintf(errbuf, SDL_arraysize(errbuf),
1.317 - "%s: Unknown DirectSound error: 0x%x",
1.318 - function, code);
1.319 - break;
1.320 - }
1.321 - if ( ! errbuf[0] ) {
1.322 - SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
1.323 - }
1.324 - SDL_SetError("%s", errbuf);
1.325 - return;
1.326 + errbuf[0] = 0;
1.327 + switch (code) {
1.328 + case E_NOINTERFACE:
1.329 + error =
1.330 + "Unsupported interface\n-- Is DirectX 5.0 or later installed?";
1.331 + break;
1.332 + case DSERR_ALLOCATED:
1.333 + error = "Audio device in use";
1.334 + break;
1.335 + case DSERR_BADFORMAT:
1.336 + error = "Unsupported audio format";
1.337 + break;
1.338 + case DSERR_BUFFERLOST:
1.339 + error = "Mixing buffer was lost";
1.340 + break;
1.341 + case DSERR_CONTROLUNAVAIL:
1.342 + error = "Control requested is not available";
1.343 + break;
1.344 + case DSERR_INVALIDCALL:
1.345 + error = "Invalid call for the current state";
1.346 + break;
1.347 + case DSERR_INVALIDPARAM:
1.348 + error = "Invalid parameter";
1.349 + break;
1.350 + case DSERR_NODRIVER:
1.351 + error = "No audio device found";
1.352 + break;
1.353 + case DSERR_OUTOFMEMORY:
1.354 + error = "Out of memory";
1.355 + break;
1.356 + case DSERR_PRIOLEVELNEEDED:
1.357 + error = "Caller doesn't have priority";
1.358 + break;
1.359 + case DSERR_UNSUPPORTED:
1.360 + error = "Function not supported";
1.361 + break;
1.362 + default:
1.363 + SDL_snprintf (errbuf, SDL_arraysize (errbuf),
1.364 + "%s: Unknown DirectSound error: 0x%x", function, code);
1.365 + break;
1.366 + }
1.367 + if (!errbuf[0]) {
1.368 + SDL_snprintf (errbuf, SDL_arraysize (errbuf), "%s: %s", function,
1.369 + error);
1.370 + }
1.371 + SDL_SetError ("%s", errbuf);
1.372 + return;
1.373 }
1.374
1.375 /* DirectSound needs to be associated with a window */
1.376 static HWND mainwin = NULL;
1.377 /* */
1.378 -void DX5_SoundFocus(HWND hwnd)
1.379 +void
1.380 +DX5_SoundFocus (HWND hwnd)
1.381 {
1.382 - mainwin = hwnd;
1.383 + mainwin = hwnd;
1.384 }
1.385
1.386 -static void DX5_ThreadInit(_THIS)
1.387 +static void
1.388 +DX5_ThreadInit (_THIS)
1.389 {
1.390 - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
1.391 + SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST);
1.392 }
1.393
1.394 -static void DX5_WaitAudio_BusyWait(_THIS)
1.395 +static void
1.396 +DX5_WaitAudio_BusyWait (_THIS)
1.397 {
1.398 - DWORD status;
1.399 - DWORD cursor, junk;
1.400 - HRESULT result;
1.401 + DWORD status;
1.402 + DWORD cursor, junk;
1.403 + HRESULT result;
1.404
1.405 - /* Semi-busy wait, since we have no way of getting play notification
1.406 - on a primary mixing buffer located in hardware (DirectX 5.0)
1.407 - */
1.408 - result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk);
1.409 - if ( result != DS_OK ) {
1.410 - if ( result == DSERR_BUFFERLOST ) {
1.411 - IDirectSoundBuffer_Restore(mixbuf);
1.412 - }
1.413 + /* Semi-busy wait, since we have no way of getting play notification
1.414 + on a primary mixing buffer located in hardware (DirectX 5.0)
1.415 + */
1.416 + result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, &cursor, &junk);
1.417 + if (result != DS_OK) {
1.418 + if (result == DSERR_BUFFERLOST) {
1.419 + IDirectSoundBuffer_Restore (mixbuf);
1.420 + }
1.421 #ifdef DEBUG_SOUND
1.422 - SetDSerror("DirectSound GetCurrentPosition", result);
1.423 + SetDSerror ("DirectSound GetCurrentPosition", result);
1.424 #endif
1.425 - return;
1.426 - }
1.427 - cursor /= mixlen;
1.428 + return;
1.429 + }
1.430 + cursor /= mixlen;
1.431
1.432 - while ( cursor == playing ) {
1.433 - /* FIXME: find out how much time is left and sleep that long */
1.434 - SDL_Delay(10);
1.435 + while (cursor == playing) {
1.436 + /* FIXME: find out how much time is left and sleep that long */
1.437 + SDL_Delay (10);
1.438
1.439 - /* Try to restore a lost sound buffer */
1.440 - IDirectSoundBuffer_GetStatus(mixbuf, &status);
1.441 - if ( (status&DSBSTATUS_BUFFERLOST) ) {
1.442 - IDirectSoundBuffer_Restore(mixbuf);
1.443 - IDirectSoundBuffer_GetStatus(mixbuf, &status);
1.444 - if ( (status&DSBSTATUS_BUFFERLOST) ) {
1.445 - break;
1.446 - }
1.447 - }
1.448 - if ( ! (status&DSBSTATUS_PLAYING) ) {
1.449 - result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING);
1.450 - if ( result == DS_OK ) {
1.451 - continue;
1.452 - }
1.453 + /* Try to restore a lost sound buffer */
1.454 + IDirectSoundBuffer_GetStatus (mixbuf, &status);
1.455 + if ((status & DSBSTATUS_BUFFERLOST)) {
1.456 + IDirectSoundBuffer_Restore (mixbuf);
1.457 + IDirectSoundBuffer_GetStatus (mixbuf, &status);
1.458 + if ((status & DSBSTATUS_BUFFERLOST)) {
1.459 + break;
1.460 + }
1.461 + }
1.462 + if (!(status & DSBSTATUS_PLAYING)) {
1.463 + result = IDirectSoundBuffer_Play (mixbuf, 0, 0, DSBPLAY_LOOPING);
1.464 + if (result == DS_OK) {
1.465 + continue;
1.466 + }
1.467 #ifdef DEBUG_SOUND
1.468 - SetDSerror("DirectSound Play", result);
1.469 + SetDSerror ("DirectSound Play", result);
1.470 #endif
1.471 - return;
1.472 - }
1.473 + return;
1.474 + }
1.475
1.476 - /* Find out where we are playing */
1.477 - result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,
1.478 - &cursor, &junk);
1.479 - if ( result != DS_OK ) {
1.480 - SetDSerror("DirectSound GetCurrentPosition", result);
1.481 - return;
1.482 - }
1.483 - cursor /= mixlen;
1.484 - }
1.485 + /* Find out where we are playing */
1.486 + result = IDirectSoundBuffer_GetCurrentPosition (mixbuf,
1.487 + &cursor, &junk);
1.488 + if (result != DS_OK) {
1.489 + SetDSerror ("DirectSound GetCurrentPosition", result);
1.490 + return;
1.491 + }
1.492 + cursor /= mixlen;
1.493 + }
1.494 }
1.495
1.496 #ifdef USE_POSITION_NOTIFY
1.497 -static void DX6_WaitAudio_EventWait(_THIS)
1.498 +static void
1.499 +DX6_WaitAudio_EventWait (_THIS)
1.500 {
1.501 - DWORD status;
1.502 - HRESULT result;
1.503 + DWORD status;
1.504 + HRESULT result;
1.505
1.506 - /* Try to restore a lost sound buffer */
1.507 - IDirectSoundBuffer_GetStatus(mixbuf, &status);
1.508 - if ( (status&DSBSTATUS_BUFFERLOST) ) {
1.509 - IDirectSoundBuffer_Restore(mixbuf);
1.510 - IDirectSoundBuffer_GetStatus(mixbuf, &status);
1.511 - if ( (status&DSBSTATUS_BUFFERLOST) ) {
1.512 - return;
1.513 - }
1.514 - }
1.515 - if ( ! (status&DSBSTATUS_PLAYING) ) {
1.516 - result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING);
1.517 - if ( result != DS_OK ) {
1.518 + /* Try to restore a lost sound buffer */
1.519 + IDirectSoundBuffer_GetStatus (mixbuf, &status);
1.520 + if ((status & DSBSTATUS_BUFFERLOST)) {
1.521 + IDirectSoundBuffer_Restore (mixbuf);
1.522 + IDirectSoundBuffer_GetStatus (mixbuf, &status);
1.523 + if ((status & DSBSTATUS_BUFFERLOST)) {
1.524 + return;
1.525 + }
1.526 + }
1.527 + if (!(status & DSBSTATUS_PLAYING)) {
1.528 + result = IDirectSoundBuffer_Play (mixbuf, 0, 0, DSBPLAY_LOOPING);
1.529 + if (result != DS_OK) {
1.530 #ifdef DEBUG_SOUND
1.531 - SetDSerror("DirectSound Play", result);
1.532 + SetDSerror ("DirectSound Play", result);
1.533 #endif
1.534 - return;
1.535 - }
1.536 - }
1.537 - WaitForSingleObject(audio_event, INFINITE);
1.538 + return;
1.539 + }
1.540 + }
1.541 + WaitForSingleObject (audio_event, INFINITE);
1.542 }
1.543 #endif /* USE_POSITION_NOTIFY */
1.544
1.545 -static void DX5_PlayAudio(_THIS)
1.546 +static void
1.547 +DX5_PlayAudio (_THIS)
1.548 {
1.549 - /* Unlock the buffer, allowing it to play */
1.550 - if ( locked_buf ) {
1.551 - IDirectSoundBuffer_Unlock(mixbuf, locked_buf, mixlen, NULL, 0);
1.552 - }
1.553 + /* Unlock the buffer, allowing it to play */
1.554 + if (locked_buf) {
1.555 + IDirectSoundBuffer_Unlock (mixbuf, locked_buf, mixlen, NULL, 0);
1.556 + }
1.557
1.558 }
1.559
1.560 -static Uint8 *DX5_GetAudioBuf(_THIS)
1.561 +static Uint8 *
1.562 +DX5_GetAudioBuf (_THIS)
1.563 {
1.564 - DWORD cursor, junk;
1.565 - HRESULT result;
1.566 - DWORD rawlen;
1.567 + DWORD cursor, junk;
1.568 + HRESULT result;
1.569 + DWORD rawlen;
1.570
1.571 - /* Figure out which blocks to fill next */
1.572 - locked_buf = NULL;
1.573 - result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk);
1.574 - if ( result == DSERR_BUFFERLOST ) {
1.575 - IDirectSoundBuffer_Restore(mixbuf);
1.576 - result = IDirectSoundBuffer_GetCurrentPosition(mixbuf,
1.577 - &cursor, &junk);
1.578 - }
1.579 - if ( result != DS_OK ) {
1.580 - SetDSerror("DirectSound GetCurrentPosition", result);
1.581 - return(NULL);
1.582 - }
1.583 - cursor /= mixlen;
1.584 - playing = cursor;
1.585 - cursor = (cursor+1)%NUM_BUFFERS;
1.586 - cursor *= mixlen;
1.587 + /* Figure out which blocks to fill next */
1.588 + locked_buf = NULL;
1.589 + result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, &cursor, &junk);
1.590 + if (result == DSERR_BUFFERLOST) {
1.591 + IDirectSoundBuffer_Restore (mixbuf);
1.592 + result = IDirectSoundBuffer_GetCurrentPosition (mixbuf,
1.593 + &cursor, &junk);
1.594 + }
1.595 + if (result != DS_OK) {
1.596 + SetDSerror ("DirectSound GetCurrentPosition", result);
1.597 + return (NULL);
1.598 + }
1.599 + cursor /= mixlen;
1.600 + playing = cursor;
1.601 + cursor = (cursor + 1) % NUM_BUFFERS;
1.602 + cursor *= mixlen;
1.603
1.604 - /* Lock the audio buffer */
1.605 - result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen,
1.606 - (LPVOID *)&locked_buf, &rawlen, NULL, &junk, 0);
1.607 - if ( result == DSERR_BUFFERLOST ) {
1.608 - IDirectSoundBuffer_Restore(mixbuf);
1.609 - result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen,
1.610 - (LPVOID *)&locked_buf, &rawlen, NULL, &junk, 0);
1.611 - }
1.612 - if ( result != DS_OK ) {
1.613 - SetDSerror("DirectSound Lock", result);
1.614 - return(NULL);
1.615 - }
1.616 - return(locked_buf);
1.617 + /* Lock the audio buffer */
1.618 + result = IDirectSoundBuffer_Lock (mixbuf, cursor, mixlen,
1.619 + (LPVOID *) & locked_buf, &rawlen, NULL,
1.620 + &junk, 0);
1.621 + if (result == DSERR_BUFFERLOST) {
1.622 + IDirectSoundBuffer_Restore (mixbuf);
1.623 + result = IDirectSoundBuffer_Lock (mixbuf, cursor, mixlen,
1.624 + (LPVOID *) & locked_buf, &rawlen,
1.625 + NULL, &junk, 0);
1.626 + }
1.627 + if (result != DS_OK) {
1.628 + SetDSerror ("DirectSound Lock", result);
1.629 + return (NULL);
1.630 + }
1.631 + return (locked_buf);
1.632 }
1.633
1.634 -static void DX5_WaitDone(_THIS)
1.635 +static void
1.636 +DX5_WaitDone (_THIS)
1.637 {
1.638 - Uint8 *stream;
1.639 + Uint8 *stream;
1.640
1.641 - /* Wait for the playing chunk to finish */
1.642 - stream = this->GetAudioBuf(this);
1.643 - if ( stream != NULL ) {
1.644 - SDL_memset(stream, silence, mixlen);
1.645 - this->PlayAudio(this);
1.646 - }
1.647 - this->WaitAudio(this);
1.648 + /* Wait for the playing chunk to finish */
1.649 + stream = this->GetAudioBuf (this);
1.650 + if (stream != NULL) {
1.651 + SDL_memset (stream, silence, mixlen);
1.652 + this->PlayAudio (this);
1.653 + }
1.654 + this->WaitAudio (this);
1.655
1.656 - /* Stop the looping sound buffer */
1.657 - IDirectSoundBuffer_Stop(mixbuf);
1.658 + /* Stop the looping sound buffer */
1.659 + IDirectSoundBuffer_Stop (mixbuf);
1.660 }
1.661
1.662 -static void DX5_CloseAudio(_THIS)
1.663 +static void
1.664 +DX5_CloseAudio (_THIS)
1.665 {
1.666 - if ( sound != NULL ) {
1.667 - if ( mixbuf != NULL ) {
1.668 - /* Clean up the audio buffer */
1.669 - IDirectSoundBuffer_Release(mixbuf);
1.670 - mixbuf = NULL;
1.671 - }
1.672 - if ( audio_event != NULL ) {
1.673 - CloseHandle(audio_event);
1.674 - audio_event = NULL;
1.675 - }
1.676 - IDirectSound_Release(sound);
1.677 - sound = NULL;
1.678 - }
1.679 + if (sound != NULL) {
1.680 + if (mixbuf != NULL) {
1.681 + /* Clean up the audio buffer */
1.682 + IDirectSoundBuffer_Release (mixbuf);
1.683 + mixbuf = NULL;
1.684 + }
1.685 + if (audio_event != NULL) {
1.686 + CloseHandle (audio_event);
1.687 + audio_event = NULL;
1.688 + }
1.689 + IDirectSound_Release (sound);
1.690 + sound = NULL;
1.691 + }
1.692 }
1.693
1.694 #ifdef USE_PRIMARY_BUFFER
1.695 /* This function tries to create a primary audio buffer, and returns the
1.696 number of audio chunks available in the created buffer.
1.697 */
1.698 -static int CreatePrimary(LPDIRECTSOUND sndObj, HWND focus,
1.699 - LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize)
1.700 +static int
1.701 +CreatePrimary (LPDIRECTSOUND sndObj, HWND focus,
1.702 + LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt,
1.703 + Uint32 chunksize)
1.704 {
1.705 - HRESULT result;
1.706 - DSBUFFERDESC format;
1.707 - DSBCAPS caps;
1.708 - int numchunks;
1.709 + HRESULT result;
1.710 + DSBUFFERDESC format;
1.711 + DSBCAPS caps;
1.712 + int numchunks;
1.713
1.714 - /* Try to set primary mixing privileges */
1.715 - result = IDirectSound_SetCooperativeLevel(sndObj, focus,
1.716 - DSSCL_WRITEPRIMARY);
1.717 - if ( result != DS_OK ) {
1.718 + /* Try to set primary mixing privileges */
1.719 + result = IDirectSound_SetCooperativeLevel (sndObj, focus,
1.720 + DSSCL_WRITEPRIMARY);
1.721 + if (result != DS_OK) {
1.722 #ifdef DEBUG_SOUND
1.723 - SetDSerror("DirectSound SetCooperativeLevel", result);
1.724 + SetDSerror ("DirectSound SetCooperativeLevel", result);
1.725 #endif
1.726 - return(-1);
1.727 - }
1.728 + return (-1);
1.729 + }
1.730
1.731 - /* Try to create the primary buffer */
1.732 - SDL_memset(&format, 0, sizeof(format));
1.733 - format.dwSize = sizeof(format);
1.734 - format.dwFlags=(DSBCAPS_PRIMARYBUFFER|DSBCAPS_GETCURRENTPOSITION2);
1.735 - format.dwFlags |= DSBCAPS_STICKYFOCUS;
1.736 + /* Try to create the primary buffer */
1.737 + SDL_memset (&format, 0, sizeof (format));
1.738 + format.dwSize = sizeof (format);
1.739 + format.dwFlags = (DSBCAPS_PRIMARYBUFFER | DSBCAPS_GETCURRENTPOSITION2);
1.740 + format.dwFlags |= DSBCAPS_STICKYFOCUS;
1.741 #ifdef USE_POSITION_NOTIFY
1.742 - format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
1.743 + format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
1.744 #endif
1.745 - result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
1.746 - if ( result != DS_OK ) {
1.747 + result = IDirectSound_CreateSoundBuffer (sndObj, &format, sndbuf, NULL);
1.748 + if (result != DS_OK) {
1.749 #ifdef DEBUG_SOUND
1.750 - SetDSerror("DirectSound CreateSoundBuffer", result);
1.751 + SetDSerror ("DirectSound CreateSoundBuffer", result);
1.752 #endif
1.753 - return(-1);
1.754 - }
1.755 + return (-1);
1.756 + }
1.757
1.758 - /* Check the size of the fragment buffer */
1.759 - SDL_memset(&caps, 0, sizeof(caps));
1.760 - caps.dwSize = sizeof(caps);
1.761 - result = IDirectSoundBuffer_GetCaps(*sndbuf, &caps);
1.762 - if ( result != DS_OK ) {
1.763 + /* Check the size of the fragment buffer */
1.764 + SDL_memset (&caps, 0, sizeof (caps));
1.765 + caps.dwSize = sizeof (caps);
1.766 + result = IDirectSoundBuffer_GetCaps (*sndbuf, &caps);
1.767 + if (result != DS_OK) {
1.768 #ifdef DEBUG_SOUND
1.769 - SetDSerror("DirectSound GetCaps", result);
1.770 + SetDSerror ("DirectSound GetCaps", result);
1.771 #endif
1.772 - IDirectSoundBuffer_Release(*sndbuf);
1.773 - return(-1);
1.774 - }
1.775 - if ( (chunksize > caps.dwBufferBytes) ||
1.776 - ((caps.dwBufferBytes%chunksize) != 0) ) {
1.777 - /* The primary buffer size is not a multiple of 'chunksize'
1.778 - -- this hopefully doesn't happen when 'chunksize' is a
1.779 - power of 2.
1.780 - */
1.781 - IDirectSoundBuffer_Release(*sndbuf);
1.782 - SDL_SetError(
1.783 -"Primary buffer size is: %d, cannot break it into chunks of %d bytes\n",
1.784 - caps.dwBufferBytes, chunksize);
1.785 - return(-1);
1.786 - }
1.787 - numchunks = (caps.dwBufferBytes/chunksize);
1.788 + IDirectSoundBuffer_Release (*sndbuf);
1.789 + return (-1);
1.790 + }
1.791 + if ((chunksize > caps.dwBufferBytes) ||
1.792 + ((caps.dwBufferBytes % chunksize) != 0)) {
1.793 + /* The primary buffer size is not a multiple of 'chunksize'
1.794 + -- this hopefully doesn't happen when 'chunksize' is a
1.795 + power of 2.
1.796 + */
1.797 + IDirectSoundBuffer_Release (*sndbuf);
1.798 + SDL_SetError
1.799 + ("Primary buffer size is: %d, cannot break it into chunks of %d bytes\n",
1.800 + caps.dwBufferBytes, chunksize);
1.801 + return (-1);
1.802 + }
1.803 + numchunks = (caps.dwBufferBytes / chunksize);
1.804
1.805 - /* Set the primary audio format */
1.806 - result = IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);
1.807 - if ( result != DS_OK ) {
1.808 + /* Set the primary audio format */
1.809 + result = IDirectSoundBuffer_SetFormat (*sndbuf, wavefmt);
1.810 + if (result != DS_OK) {
1.811 #ifdef DEBUG_SOUND
1.812 - SetDSerror("DirectSound SetFormat", result);
1.813 + SetDSerror ("DirectSound SetFormat", result);
1.814 #endif
1.815 - IDirectSoundBuffer_Release(*sndbuf);
1.816 - return(-1);
1.817 - }
1.818 - return(numchunks);
1.819 + IDirectSoundBuffer_Release (*sndbuf);
1.820 + return (-1);
1.821 + }
1.822 + return (numchunks);
1.823 }
1.824 #endif /* USE_PRIMARY_BUFFER */
1.825
1.826 /* This function tries to create a secondary audio buffer, and returns the
1.827 number of audio chunks available in the created buffer.
1.828 */
1.829 -static int CreateSecondary(LPDIRECTSOUND sndObj, HWND focus,
1.830 - LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize)
1.831 +static int
1.832 +CreateSecondary (LPDIRECTSOUND sndObj, HWND focus,
1.833 + LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt,
1.834 + Uint32 chunksize)
1.835 {
1.836 - const int numchunks = 2;
1.837 - HRESULT result;
1.838 - DSBUFFERDESC format;
1.839 - LPVOID pvAudioPtr1, pvAudioPtr2;
1.840 - DWORD dwAudioBytes1, dwAudioBytes2;
1.841 + const int numchunks = 2;
1.842 + HRESULT result;
1.843 + DSBUFFERDESC format;
1.844 + LPVOID pvAudioPtr1, pvAudioPtr2;
1.845 + DWORD dwAudioBytes1, dwAudioBytes2;
1.846
1.847 - /* Try to set primary mixing privileges */
1.848 - if ( focus ) {
1.849 - result = IDirectSound_SetCooperativeLevel(sndObj,
1.850 - focus, DSSCL_PRIORITY);
1.851 - } else {
1.852 - result = IDirectSound_SetCooperativeLevel(sndObj,
1.853 - GetDesktopWindow(), DSSCL_NORMAL);
1.854 - }
1.855 - if ( result != DS_OK ) {
1.856 + /* Try to set primary mixing privileges */
1.857 + if (focus) {
1.858 + result = IDirectSound_SetCooperativeLevel (sndObj,
1.859 + focus, DSSCL_PRIORITY);
1.860 + } else {
1.861 + result = IDirectSound_SetCooperativeLevel (sndObj,
1.862 + GetDesktopWindow (),
1.863 + DSSCL_NORMAL);
1.864 + }
1.865 + if (result != DS_OK) {
1.866 #ifdef DEBUG_SOUND
1.867 - SetDSerror("DirectSound SetCooperativeLevel", result);
1.868 + SetDSerror ("DirectSound SetCooperativeLevel", result);
1.869 #endif
1.870 - return(-1);
1.871 - }
1.872 + return (-1);
1.873 + }
1.874
1.875 - /* Try to create the secondary buffer */
1.876 - SDL_memset(&format, 0, sizeof(format));
1.877 - format.dwSize = sizeof(format);
1.878 - format.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
1.879 + /* Try to create the secondary buffer */
1.880 + SDL_memset (&format, 0, sizeof (format));
1.881 + format.dwSize = sizeof (format);
1.882 + format.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
1.883 #ifdef USE_POSITION_NOTIFY
1.884 - format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
1.885 + format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
1.886 #endif
1.887 - if ( ! focus ) {
1.888 - format.dwFlags |= DSBCAPS_GLOBALFOCUS;
1.889 - } else {
1.890 - format.dwFlags |= DSBCAPS_STICKYFOCUS;
1.891 - }
1.892 - format.dwBufferBytes = numchunks*chunksize;
1.893 - if ( (format.dwBufferBytes < DSBSIZE_MIN) ||
1.894 - (format.dwBufferBytes > DSBSIZE_MAX) ) {
1.895 - SDL_SetError("Sound buffer size must be between %d and %d",
1.896 - DSBSIZE_MIN/numchunks, DSBSIZE_MAX/numchunks);
1.897 - return(-1);
1.898 - }
1.899 - format.dwReserved = 0;
1.900 - format.lpwfxFormat = wavefmt;
1.901 - result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
1.902 - if ( result != DS_OK ) {
1.903 - SetDSerror("DirectSound CreateSoundBuffer", result);
1.904 - return(-1);
1.905 - }
1.906 - IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);
1.907 + if (!focus) {
1.908 + format.dwFlags |= DSBCAPS_GLOBALFOCUS;
1.909 + } else {
1.910 + format.dwFlags |= DSBCAPS_STICKYFOCUS;
1.911 + }
1.912 + format.dwBufferBytes = numchunks * chunksize;
1.913 + if ((format.dwBufferBytes < DSBSIZE_MIN) ||
1.914 + (format.dwBufferBytes > DSBSIZE_MAX)) {
1.915 + SDL_SetError ("Sound buffer size must be between %d and %d",
1.916 + DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks);
1.917 + return (-1);
1.918 + }
1.919 + format.dwReserved = 0;
1.920 + format.lpwfxFormat = wavefmt;
1.921 + result = IDirectSound_CreateSoundBuffer (sndObj, &format, sndbuf, NULL);
1.922 + if (result != DS_OK) {
1.923 + SetDSerror ("DirectSound CreateSoundBuffer", result);
1.924 + return (-1);
1.925 + }
1.926 + IDirectSoundBuffer_SetFormat (*sndbuf, wavefmt);
1.927
1.928 - /* Silence the initial audio buffer */
1.929 - result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes,
1.930 - (LPVOID *)&pvAudioPtr1, &dwAudioBytes1,
1.931 - (LPVOID *)&pvAudioPtr2, &dwAudioBytes2,
1.932 - DSBLOCK_ENTIREBUFFER);
1.933 - if ( result == DS_OK ) {
1.934 - if ( wavefmt->wBitsPerSample == 8 ) {
1.935 - SDL_memset(pvAudioPtr1, 0x80, dwAudioBytes1);
1.936 - } else {
1.937 - SDL_memset(pvAudioPtr1, 0x00, dwAudioBytes1);
1.938 - }
1.939 - IDirectSoundBuffer_Unlock(*sndbuf,
1.940 - (LPVOID)pvAudioPtr1, dwAudioBytes1,
1.941 - (LPVOID)pvAudioPtr2, dwAudioBytes2);
1.942 - }
1.943 + /* Silence the initial audio buffer */
1.944 + result = IDirectSoundBuffer_Lock (*sndbuf, 0, format.dwBufferBytes,
1.945 + (LPVOID *) & pvAudioPtr1,
1.946 + &dwAudioBytes1,
1.947 + (LPVOID *) & pvAudioPtr2,
1.948 + &dwAudioBytes2, DSBLOCK_ENTIREBUFFER);
1.949 + if (result == DS_OK) {
1.950 + if (wavefmt->wBitsPerSample == 8) {
1.951 + SDL_memset (pvAudioPtr1, 0x80, dwAudioBytes1);
1.952 + } else {
1.953 + SDL_memset (pvAudioPtr1, 0x00, dwAudioBytes1);
1.954 + }
1.955 + IDirectSoundBuffer_Unlock (*sndbuf,
1.956 + (LPVOID) pvAudioPtr1, dwAudioBytes1,
1.957 + (LPVOID) pvAudioPtr2, dwAudioBytes2);
1.958 + }
1.959
1.960 - /* We're ready to go */
1.961 - return(numchunks);
1.962 + /* We're ready to go */
1.963 + return (numchunks);
1.964 }
1.965
1.966 /* This function tries to set position notify events on the mixing buffer */
1.967 #ifdef USE_POSITION_NOTIFY
1.968 -static int CreateAudioEvent(_THIS)
1.969 +static int
1.970 +CreateAudioEvent (_THIS)
1.971 {
1.972 - LPDIRECTSOUNDNOTIFY notify;
1.973 - DSBPOSITIONNOTIFY *notify_positions;
1.974 - int i, retval;
1.975 - HRESULT result;
1.976 + LPDIRECTSOUNDNOTIFY notify;
1.977 + DSBPOSITIONNOTIFY *notify_positions;
1.978 + int i, retval;
1.979 + HRESULT result;
1.980
1.981 - /* Default to fail on exit */
1.982 - retval = -1;
1.983 - notify = NULL;
1.984 + /* Default to fail on exit */
1.985 + retval = -1;
1.986 + notify = NULL;
1.987
1.988 - /* Query for the interface */
1.989 - result = IDirectSoundBuffer_QueryInterface(mixbuf,
1.990 - &IID_IDirectSoundNotify, (void *)¬ify);
1.991 - if ( result != DS_OK ) {
1.992 - goto done;
1.993 - }
1.994 + /* Query for the interface */
1.995 + result = IDirectSoundBuffer_QueryInterface (mixbuf,
1.996 + &IID_IDirectSoundNotify,
1.997 + (void *) ¬ify);
1.998 + if (result != DS_OK) {
1.999 + goto done;
1.1000 + }
1.1001
1.1002 - /* Allocate the notify structures */
1.1003 - notify_positions = (DSBPOSITIONNOTIFY *)SDL_malloc(NUM_BUFFERS*
1.1004 - sizeof(*notify_positions));
1.1005 - if ( notify_positions == NULL ) {
1.1006 - goto done;
1.1007 - }
1.1008 + /* Allocate the notify structures */
1.1009 + notify_positions = (DSBPOSITIONNOTIFY *) SDL_malloc (NUM_BUFFERS *
1.1010 + sizeof
1.1011 + (*notify_positions));
1.1012 + if (notify_positions == NULL) {
1.1013 + goto done;
1.1014 + }
1.1015
1.1016 - /* Create the notify event */
1.1017 - audio_event = CreateEvent(NULL, FALSE, FALSE, NULL);
1.1018 - if ( audio_event == NULL ) {
1.1019 - goto done;
1.1020 - }
1.1021 + /* Create the notify event */
1.1022 + audio_event = CreateEvent (NULL, FALSE, FALSE, NULL);
1.1023 + if (audio_event == NULL) {
1.1024 + goto done;
1.1025 + }
1.1026
1.1027 - /* Set up the notify structures */
1.1028 - for ( i=0; i<NUM_BUFFERS; ++i ) {
1.1029 - notify_positions[i].dwOffset = i*mixlen;
1.1030 - notify_positions[i].hEventNotify = audio_event;
1.1031 - }
1.1032 - result = IDirectSoundNotify_SetNotificationPositions(notify,
1.1033 - NUM_BUFFERS, notify_positions);
1.1034 - if ( result == DS_OK ) {
1.1035 - retval = 0;
1.1036 - }
1.1037 -done:
1.1038 - if ( notify != NULL ) {
1.1039 - IDirectSoundNotify_Release(notify);
1.1040 - }
1.1041 - return(retval);
1.1042 + /* Set up the notify structures */
1.1043 + for (i = 0; i < NUM_BUFFERS; ++i) {
1.1044 + notify_positions[i].dwOffset = i * mixlen;
1.1045 + notify_positions[i].hEventNotify = audio_event;
1.1046 + }
1.1047 + result = IDirectSoundNotify_SetNotificationPositions (notify,
1.1048 + NUM_BUFFERS,
1.1049 + notify_positions);
1.1050 + if (result == DS_OK) {
1.1051 + retval = 0;
1.1052 + }
1.1053 + done:
1.1054 + if (notify != NULL) {
1.1055 + IDirectSoundNotify_Release (notify);
1.1056 + }
1.1057 + return (retval);
1.1058 }
1.1059 #endif /* USE_POSITION_NOTIFY */
1.1060
1.1061 -static int DX5_OpenAudio(_THIS, SDL_AudioSpec *spec)
1.1062 +static int
1.1063 +DX5_OpenAudio (_THIS, SDL_AudioSpec * spec)
1.1064 {
1.1065 - HRESULT result;
1.1066 - WAVEFORMATEX waveformat;
1.1067 + HRESULT result;
1.1068 + WAVEFORMATEX waveformat;
1.1069
1.1070 - /* Set basic WAVE format parameters */
1.1071 - SDL_memset(&waveformat, 0, sizeof(waveformat));
1.1072 - waveformat.wFormatTag = WAVE_FORMAT_PCM;
1.1073 + /* Set basic WAVE format parameters */
1.1074 + SDL_memset (&waveformat, 0, sizeof (waveformat));
1.1075 + waveformat.wFormatTag = WAVE_FORMAT_PCM;
1.1076
1.1077 - /* Determine the audio parameters from the AudioSpec */
1.1078 - switch ( spec->format & 0xFF ) {
1.1079 - case 8:
1.1080 - /* Unsigned 8 bit audio data */
1.1081 - spec->format = AUDIO_U8;
1.1082 - silence = 0x80;
1.1083 - waveformat.wBitsPerSample = 8;
1.1084 - break;
1.1085 - case 16:
1.1086 - /* Signed 16 bit audio data */
1.1087 - spec->format = AUDIO_S16;
1.1088 - silence = 0x00;
1.1089 - waveformat.wBitsPerSample = 16;
1.1090 - break;
1.1091 - default:
1.1092 - SDL_SetError("Unsupported audio format");
1.1093 - return(-1);
1.1094 - }
1.1095 - waveformat.nChannels = spec->channels;
1.1096 - waveformat.nSamplesPerSec = spec->freq;
1.1097 - waveformat.nBlockAlign =
1.1098 - waveformat.nChannels * (waveformat.wBitsPerSample/8);
1.1099 - waveformat.nAvgBytesPerSec =
1.1100 - waveformat.nSamplesPerSec * waveformat.nBlockAlign;
1.1101 + /* Determine the audio parameters from the AudioSpec */
1.1102 + switch (spec->format & 0xFF) {
1.1103 + case 8:
1.1104 + /* Unsigned 8 bit audio data */
1.1105 + spec->format = AUDIO_U8;
1.1106 + silence = 0x80;
1.1107 + waveformat.wBitsPerSample = 8;
1.1108 + break;
1.1109 + case 16:
1.1110 + /* Signed 16 bit audio data */
1.1111 + spec->format = AUDIO_S16;
1.1112 + silence = 0x00;
1.1113 + waveformat.wBitsPerSample = 16;
1.1114 + break;
1.1115 + default:
1.1116 + SDL_SetError ("Unsupported audio format");
1.1117 + return (-1);
1.1118 + }
1.1119 + waveformat.nChannels = spec->channels;
1.1120 + waveformat.nSamplesPerSec = spec->freq;
1.1121 + waveformat.nBlockAlign =
1.1122 + waveformat.nChannels * (waveformat.wBitsPerSample / 8);
1.1123 + waveformat.nAvgBytesPerSec =
1.1124 + waveformat.nSamplesPerSec * waveformat.nBlockAlign;
1.1125
1.1126 - /* Update the fragment size as size in bytes */
1.1127 - SDL_CalculateAudioSpec(spec);
1.1128 + /* Update the fragment size as size in bytes */
1.1129 + SDL_CalculateAudioSpec (spec);
1.1130
1.1131 - /* Open the audio device */
1.1132 - result = DSoundCreate(NULL, &sound, NULL);
1.1133 - if ( result != DS_OK ) {
1.1134 - SetDSerror("DirectSoundCreate", result);
1.1135 - return(-1);
1.1136 - }
1.1137 + /* Open the audio device */
1.1138 + result = DSoundCreate (NULL, &sound, NULL);
1.1139 + if (result != DS_OK) {
1.1140 + SetDSerror ("DirectSoundCreate", result);
1.1141 + return (-1);
1.1142 + }
1.1143
1.1144 - /* Create the audio buffer to which we write */
1.1145 - NUM_BUFFERS = -1;
1.1146 + /* Create the audio buffer to which we write */
1.1147 + NUM_BUFFERS = -1;
1.1148 #ifdef USE_PRIMARY_BUFFER
1.1149 - if ( mainwin ) {
1.1150 - NUM_BUFFERS = CreatePrimary(sound, mainwin, &mixbuf,
1.1151 - &waveformat, spec->size);
1.1152 - }
1.1153 + if (mainwin) {
1.1154 + NUM_BUFFERS = CreatePrimary (sound, mainwin, &mixbuf,
1.1155 + &waveformat, spec->size);
1.1156 + }
1.1157 #endif /* USE_PRIMARY_BUFFER */
1.1158 - if ( NUM_BUFFERS < 0 ) {
1.1159 - NUM_BUFFERS = CreateSecondary(sound, mainwin, &mixbuf,
1.1160 - &waveformat, spec->size);
1.1161 - if ( NUM_BUFFERS < 0 ) {
1.1162 - return(-1);
1.1163 - }
1.1164 + if (NUM_BUFFERS < 0) {
1.1165 + NUM_BUFFERS = CreateSecondary (sound, mainwin, &mixbuf,
1.1166 + &waveformat, spec->size);
1.1167 + if (NUM_BUFFERS < 0) {
1.1168 + return (-1);
1.1169 + }
1.1170 #ifdef DEBUG_SOUND
1.1171 - fprintf(stderr, "Using secondary audio buffer\n");
1.1172 + fprintf (stderr, "Using secondary audio buffer\n");
1.1173 #endif
1.1174 - }
1.1175 + }
1.1176 #ifdef DEBUG_SOUND
1.1177 - else
1.1178 - fprintf(stderr, "Using primary audio buffer\n");
1.1179 + else
1.1180 + fprintf (stderr, "Using primary audio buffer\n");
1.1181 #endif
1.1182
1.1183 - /* The buffer will auto-start playing in DX5_WaitAudio() */
1.1184 - playing = 0;
1.1185 - mixlen = spec->size;
1.1186 + /* The buffer will auto-start playing in DX5_WaitAudio() */
1.1187 + playing = 0;
1.1188 + mixlen = spec->size;
1.1189
1.1190 #ifdef USE_POSITION_NOTIFY
1.1191 - /* See if we can use DirectX 6 event notification */
1.1192 - if ( CreateAudioEvent(this) == 0 ) {
1.1193 - this->WaitAudio = DX6_WaitAudio_EventWait;
1.1194 - } else {
1.1195 - this->WaitAudio = DX5_WaitAudio_BusyWait;
1.1196 - }
1.1197 + /* See if we can use DirectX 6 event notification */
1.1198 + if (CreateAudioEvent (this) == 0) {
1.1199 + this->WaitAudio = DX6_WaitAudio_EventWait;
1.1200 + } else {
1.1201 + this->WaitAudio = DX5_WaitAudio_BusyWait;
1.1202 + }
1.1203 #endif
1.1204 - return(0);
1.1205 + return (0);
1.1206 }
1.1207
1.1208 +/* vi: set ts=4 sw=4 expandtab: */