Mercurial > sdl-ios-xcode
comparison src/audio/windx5/SDL_dx5audio.c @ 2060:866052b01ee5
indent is evil
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 28 Oct 2006 16:48:03 +0000 |
parents | c03f1446e897 |
children | e1da92da346c |
comparison
equal
deleted
inserted
replaced
2059:4685ccd33d0e | 2060:866052b01ee5 |
---|---|
37 #define WINDOWS_OS_NAME "Win32" | 37 #define WINDOWS_OS_NAME "Win32" |
38 #endif | 38 #endif |
39 | 39 |
40 /* DirectX function pointers for audio */ | 40 /* DirectX function pointers for audio */ |
41 static HINSTANCE DSoundDLL = NULL; | 41 static HINSTANCE DSoundDLL = NULL; |
42 static HRESULT (WINAPI *DSoundCreate)(LPGUID,LPDIRECTSOUND*,LPUNKNOWN) = NULL; | 42 static HRESULT(WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN) = |
43 NULL; | |
43 | 44 |
44 static void | 45 static void |
45 DSOUND_Unload(void) | 46 DSOUND_Unload(void) |
46 { | 47 { |
47 if (DSoundDLL != NULL) { | 48 if (DSoundDLL != NULL) { |
68 /* (DirectSoundCaptureCreate was added in DX5) */ | 69 /* (DirectSoundCaptureCreate was added in DX5) */ |
69 if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate"))) { | 70 if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate"))) { |
70 SDL_SetError("DirectSound: System doesn't appear to have DX5."); | 71 SDL_SetError("DirectSound: System doesn't appear to have DX5."); |
71 } else { | 72 } else { |
72 DSoundCreate = (void *) GetProcAddress(DSoundDLL, | 73 DSoundCreate = (void *) GetProcAddress(DSoundDLL, |
73 TEXT("DirectSoundCreate")); | 74 TEXT("DirectSoundCreate")); |
74 } | 75 } |
75 | 76 |
76 if (!DSoundCreate) { | 77 if (!DSoundCreate) { |
77 SDL_SetError("DirectSound: Failed to find DirectSoundCreate"); | 78 SDL_SetError("DirectSound: Failed to find DirectSoundCreate"); |
78 } else { | 79 } else { |
269 cursor *= this->hidden->mixlen; | 270 cursor *= this->hidden->mixlen; |
270 | 271 |
271 /* Lock the audio buffer */ | 272 /* Lock the audio buffer */ |
272 result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor, | 273 result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor, |
273 this->hidden->mixlen, | 274 this->hidden->mixlen, |
274 (LPVOID *) &this->hidden->locked_buf, | 275 (LPVOID *) & this->hidden->locked_buf, |
275 &rawlen, NULL, &junk, 0); | 276 &rawlen, NULL, &junk, 0); |
276 if (result == DSERR_BUFFERLOST) { | 277 if (result == DSERR_BUFFERLOST) { |
277 IDirectSoundBuffer_Restore(this->hidden->mixbuf); | 278 IDirectSoundBuffer_Restore(this->hidden->mixbuf); |
278 result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor, | 279 result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor, |
279 this->hidden->mixlen, | 280 this->hidden->mixlen, |
280 (LPVOID *) &this->hidden->locked_buf, | 281 (LPVOID *) & this->hidden-> |
281 &rawlen, NULL, &junk, 0); | 282 locked_buf, &rawlen, NULL, &junk, 0); |
282 } | 283 } |
283 if (result != DS_OK) { | 284 if (result != DS_OK) { |
284 SetDSerror("DirectSound Lock", result); | 285 SetDSerror("DirectSound Lock", result); |
285 return (NULL); | 286 return (NULL); |
286 } | 287 } |
324 | 325 |
325 /* This function tries to create a secondary audio buffer, and returns the | 326 /* This function tries to create a secondary audio buffer, and returns the |
326 number of audio chunks available in the created buffer. | 327 number of audio chunks available in the created buffer. |
327 */ | 328 */ |
328 static int | 329 static int |
329 CreateSecondary(_THIS, HWND focus, WAVEFORMATEX *wavefmt) | 330 CreateSecondary(_THIS, HWND focus, WAVEFORMATEX * wavefmt) |
330 { | 331 { |
331 LPDIRECTSOUND sndObj = this->hidden->sound; | 332 LPDIRECTSOUND sndObj = this->hidden->sound; |
332 LPDIRECTSOUNDBUFFER *sndbuf = &this->hidden->mixbuf; | 333 LPDIRECTSOUNDBUFFER *sndbuf = &this->hidden->mixbuf; |
333 Uint32 chunksize = this->spec.size; | 334 Uint32 chunksize = this->spec.size; |
334 const int numchunks = 8; | 335 const int numchunks = 8; |
403 /* !!! FIXME: handle devname */ | 404 /* !!! FIXME: handle devname */ |
404 /* !!! FIXME: handle iscapture */ | 405 /* !!! FIXME: handle iscapture */ |
405 | 406 |
406 /* Initialize all variables that we clean on shutdown */ | 407 /* Initialize all variables that we clean on shutdown */ |
407 this->hidden = (struct SDL_PrivateAudioData *) | 408 this->hidden = (struct SDL_PrivateAudioData *) |
408 SDL_malloc((sizeof *this->hidden)); | 409 SDL_malloc((sizeof *this->hidden)); |
409 if (this->hidden == NULL) { | 410 if (this->hidden == NULL) { |
410 SDL_OutOfMemory(); | 411 SDL_OutOfMemory(); |
411 return 0; | 412 return 0; |
412 } | 413 } |
413 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); | 414 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
414 | 415 |
415 while ((!valid_format) && (test_format)) { | 416 while ((!valid_format) && (test_format)) { |
416 switch (test_format) { | 417 switch (test_format) { |
417 case AUDIO_U8: | 418 case AUDIO_U8: |
418 case AUDIO_S16: | 419 case AUDIO_S16: |
419 case AUDIO_S32: | 420 case AUDIO_S32: |
420 this->spec.format = test_format; | 421 this->spec.format = test_format; |
421 valid_format = 1; | 422 valid_format = 1; |
422 break; | 423 break; |
423 } | 424 } |
424 test_format = SDL_NextAudioFormat(); | 425 test_format = SDL_NextAudioFormat(); |
425 } | 426 } |
426 | 427 |
427 if (!valid_format) { | 428 if (!valid_format) { |
459 } | 460 } |
460 | 461 |
461 /* The buffer will auto-start playing in DSOUND_WaitDevice() */ | 462 /* The buffer will auto-start playing in DSOUND_WaitDevice() */ |
462 this->hidden->mixlen = this->spec.size; | 463 this->hidden->mixlen = this->spec.size; |
463 | 464 |
464 return 1; /* good to go. */ | 465 return 1; /* good to go. */ |
465 } | 466 } |
466 | 467 |
467 | 468 |
468 static void | 469 static void |
469 DSOUND_Deinitialize(void) | 470 DSOUND_Deinitialize(void) |
471 DSOUND_Unload(); | 472 DSOUND_Unload(); |
472 } | 473 } |
473 | 474 |
474 | 475 |
475 static int | 476 static int |
476 DSOUND_Init(SDL_AudioDriverImpl *impl) | 477 DSOUND_Init(SDL_AudioDriverImpl * impl) |
477 { | 478 { |
478 OSVERSIONINFO ver; | 479 OSVERSIONINFO ver; |
479 | 480 |
480 /* | 481 /* |
481 * Unfortunately, the sound drivers on NT have higher latencies than the | 482 * Unfortunately, the sound drivers on NT have higher latencies than the |
482 * audio buffers used by many SDL applications, so there are gaps in the | 483 * audio buffers used by many SDL applications, so there are gaps in the |
483 * audio - it sounds terrible. Punt for now. | 484 * audio - it sounds terrible. Punt for now. |
484 */ | 485 */ |
485 SDL_memset(&ver, '\0', sizeof (OSVERSIONINFO)); | 486 SDL_memset(&ver, '\0', sizeof(OSVERSIONINFO)); |
486 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | 487 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
487 GetVersionEx(&ver); | 488 GetVersionEx(&ver); |
488 if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) { | 489 if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) { |
489 if (ver.dwMajorVersion <= 4) { | 490 if (ver.dwMajorVersion <= 4) { |
490 return 0; /* NT4.0 or earlier. Disable dsound support. */ | 491 return 0; /* NT4.0 or earlier. Disable dsound support. */ |
491 } | 492 } |
492 } | 493 } |
493 | 494 |
494 if (!DSOUND_Load()) { | 495 if (!DSOUND_Load()) { |
495 return 0; | 496 return 0; |
502 impl->WaitDone = DSOUND_WaitDone; | 503 impl->WaitDone = DSOUND_WaitDone; |
503 impl->ThreadInit = DSOUND_ThreadInit; | 504 impl->ThreadInit = DSOUND_ThreadInit; |
504 impl->GetDeviceBuf = DSOUND_GetDeviceBuf; | 505 impl->GetDeviceBuf = DSOUND_GetDeviceBuf; |
505 impl->CloseDevice = DSOUND_CloseDevice; | 506 impl->CloseDevice = DSOUND_CloseDevice; |
506 impl->Deinitialize = DSOUND_Deinitialize; | 507 impl->Deinitialize = DSOUND_Deinitialize; |
507 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME */ | 508 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME */ |
508 | 509 |
509 return 1; | 510 return 1; |
510 } | 511 } |
511 | 512 |
512 AudioBootStrap DSOUND_bootstrap = { | 513 AudioBootStrap DSOUND_bootstrap = { |