comparison src/audio/windx5/SDL_dx5audio.c @ 1336:3692456e7b0f

Use SDL_ prefixed versions of C library functions. FIXME: Change #include <stdlib.h> to #include "SDL_stdlib.h" Change #include <string.h> to #include "SDL_string.h" Make sure nothing else broke because of this...
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 06:59:48 +0000
parents 450721ad5436
children 604d73db6802
comparison
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
131 } 131 }
132 132
133 static void Audio_DeleteDevice(SDL_AudioDevice *device) 133 static void Audio_DeleteDevice(SDL_AudioDevice *device)
134 { 134 {
135 DX5_Unload(); 135 DX5_Unload();
136 free(device->hidden); 136 SDL_free(device->hidden);
137 free(device); 137 SDL_free(device);
138 } 138 }
139 139
140 static SDL_AudioDevice *Audio_CreateDevice(int devindex) 140 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
141 { 141 {
142 SDL_AudioDevice *this; 142 SDL_AudioDevice *this;
145 if ( DX5_Load() < 0 ) { 145 if ( DX5_Load() < 0 ) {
146 return(NULL); 146 return(NULL);
147 } 147 }
148 148
149 /* Initialize all variables that we clean on shutdown */ 149 /* Initialize all variables that we clean on shutdown */
150 this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); 150 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
151 if ( this ) { 151 if ( this ) {
152 memset(this, 0, (sizeof *this)); 152 SDL_memset(this, 0, (sizeof *this));
153 this->hidden = (struct SDL_PrivateAudioData *) 153 this->hidden = (struct SDL_PrivateAudioData *)
154 malloc((sizeof *this->hidden)); 154 SDL_malloc((sizeof *this->hidden));
155 } 155 }
156 if ( (this == NULL) || (this->hidden == NULL) ) { 156 if ( (this == NULL) || (this->hidden == NULL) ) {
157 SDL_OutOfMemory(); 157 SDL_OutOfMemory();
158 if ( this ) { 158 if ( this ) {
159 free(this); 159 SDL_free(this);
160 } 160 }
161 return(0); 161 return(0);
162 } 162 }
163 memset(this->hidden, 0, (sizeof *this->hidden)); 163 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
164 164
165 /* Set the function pointers */ 165 /* Set the function pointers */
166 this->OpenAudio = DX5_OpenAudio; 166 this->OpenAudio = DX5_OpenAudio;
167 this->ThreadInit = DX5_ThreadInit; 167 this->ThreadInit = DX5_ThreadInit;
168 this->WaitAudio = DX5_WaitAudio_BusyWait; 168 this->WaitAudio = DX5_WaitAudio_BusyWait;
221 break; 221 break;
222 case DSERR_UNSUPPORTED: 222 case DSERR_UNSUPPORTED:
223 error = "Function not supported"; 223 error = "Function not supported";
224 break; 224 break;
225 default: 225 default:
226 snprintf(errbuf, SDL_arraysize(errbuf), 226 SDL_snprintf(errbuf, SDL_arraysize(errbuf),
227 "%s: Unknown DirectSound error: 0x%x", 227 "%s: Unknown DirectSound error: 0x%x",
228 function, code); 228 function, code);
229 break; 229 break;
230 } 230 }
231 if ( ! errbuf[0] ) { 231 if ( ! errbuf[0] ) {
232 snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error); 232 SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error);
233 } 233 }
234 SDL_SetError("%s", errbuf); 234 SDL_SetError("%s", errbuf);
235 return; 235 return;
236 } 236 }
237 237
384 Uint8 *stream; 384 Uint8 *stream;
385 385
386 /* Wait for the playing chunk to finish */ 386 /* Wait for the playing chunk to finish */
387 stream = this->GetAudioBuf(this); 387 stream = this->GetAudioBuf(this);
388 if ( stream != NULL ) { 388 if ( stream != NULL ) {
389 memset(stream, silence, mixlen); 389 SDL_memset(stream, silence, mixlen);
390 this->PlayAudio(this); 390 this->PlayAudio(this);
391 } 391 }
392 this->WaitAudio(this); 392 this->WaitAudio(this);
393 393
394 /* Stop the looping sound buffer */ 394 /* Stop the looping sound buffer */
433 #endif 433 #endif
434 return(-1); 434 return(-1);
435 } 435 }
436 436
437 /* Try to create the primary buffer */ 437 /* Try to create the primary buffer */
438 memset(&format, 0, sizeof(format)); 438 SDL_memset(&format, 0, sizeof(format));
439 format.dwSize = sizeof(format); 439 format.dwSize = sizeof(format);
440 format.dwFlags=(DSBCAPS_PRIMARYBUFFER|DSBCAPS_GETCURRENTPOSITION2); 440 format.dwFlags=(DSBCAPS_PRIMARYBUFFER|DSBCAPS_GETCURRENTPOSITION2);
441 format.dwFlags |= DSBCAPS_STICKYFOCUS; 441 format.dwFlags |= DSBCAPS_STICKYFOCUS;
442 #ifdef USE_POSITION_NOTIFY 442 #ifdef USE_POSITION_NOTIFY
443 format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY; 443 format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
449 #endif 449 #endif
450 return(-1); 450 return(-1);
451 } 451 }
452 452
453 /* Check the size of the fragment buffer */ 453 /* Check the size of the fragment buffer */
454 memset(&caps, 0, sizeof(caps)); 454 SDL_memset(&caps, 0, sizeof(caps));
455 caps.dwSize = sizeof(caps); 455 caps.dwSize = sizeof(caps);
456 result = IDirectSoundBuffer_GetCaps(*sndbuf, &caps); 456 result = IDirectSoundBuffer_GetCaps(*sndbuf, &caps);
457 if ( result != DS_OK ) { 457 if ( result != DS_OK ) {
458 #ifdef DEBUG_SOUND 458 #ifdef DEBUG_SOUND
459 SetDSerror("DirectSound GetCaps", result); 459 SetDSerror("DirectSound GetCaps", result);
514 #endif 514 #endif
515 return(-1); 515 return(-1);
516 } 516 }
517 517
518 /* Try to create the secondary buffer */ 518 /* Try to create the secondary buffer */
519 memset(&format, 0, sizeof(format)); 519 SDL_memset(&format, 0, sizeof(format));
520 format.dwSize = sizeof(format); 520 format.dwSize = sizeof(format);
521 format.dwFlags = DSBCAPS_GETCURRENTPOSITION2; 521 format.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
522 #ifdef USE_POSITION_NOTIFY 522 #ifdef USE_POSITION_NOTIFY
523 format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY; 523 format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY;
524 #endif 524 #endif
548 (LPVOID *)&pvAudioPtr1, &dwAudioBytes1, 548 (LPVOID *)&pvAudioPtr1, &dwAudioBytes1,
549 (LPVOID *)&pvAudioPtr2, &dwAudioBytes2, 549 (LPVOID *)&pvAudioPtr2, &dwAudioBytes2,
550 DSBLOCK_ENTIREBUFFER); 550 DSBLOCK_ENTIREBUFFER);
551 if ( result == DS_OK ) { 551 if ( result == DS_OK ) {
552 if ( wavefmt->wBitsPerSample == 8 ) { 552 if ( wavefmt->wBitsPerSample == 8 ) {
553 memset(pvAudioPtr1, 0x80, dwAudioBytes1); 553 SDL_memset(pvAudioPtr1, 0x80, dwAudioBytes1);
554 } else { 554 } else {
555 memset(pvAudioPtr1, 0x00, dwAudioBytes1); 555 SDL_memset(pvAudioPtr1, 0x00, dwAudioBytes1);
556 } 556 }
557 IDirectSoundBuffer_Unlock(*sndbuf, 557 IDirectSoundBuffer_Unlock(*sndbuf,
558 (LPVOID)pvAudioPtr1, dwAudioBytes1, 558 (LPVOID)pvAudioPtr1, dwAudioBytes1,
559 (LPVOID)pvAudioPtr2, dwAudioBytes2); 559 (LPVOID)pvAudioPtr2, dwAudioBytes2);
560 } 560 }
582 if ( result != DS_OK ) { 582 if ( result != DS_OK ) {
583 goto done; 583 goto done;
584 } 584 }
585 585
586 /* Allocate the notify structures */ 586 /* Allocate the notify structures */
587 notify_positions = (DSBPOSITIONNOTIFY *)malloc(NUM_BUFFERS* 587 notify_positions = (DSBPOSITIONNOTIFY *)SDL_malloc(NUM_BUFFERS*
588 sizeof(*notify_positions)); 588 sizeof(*notify_positions));
589 if ( notify_positions == NULL ) { 589 if ( notify_positions == NULL ) {
590 goto done; 590 goto done;
591 } 591 }
592 592
618 { 618 {
619 HRESULT result; 619 HRESULT result;
620 WAVEFORMATEX waveformat; 620 WAVEFORMATEX waveformat;
621 621
622 /* Set basic WAVE format parameters */ 622 /* Set basic WAVE format parameters */
623 memset(&waveformat, 0, sizeof(waveformat)); 623 SDL_memset(&waveformat, 0, sizeof(waveformat));
624 waveformat.wFormatTag = WAVE_FORMAT_PCM; 624 waveformat.wFormatTag = WAVE_FORMAT_PCM;
625 625
626 /* Determine the audio parameters from the AudioSpec */ 626 /* Determine the audio parameters from the AudioSpec */
627 switch ( spec->format & 0xFF ) { 627 switch ( spec->format & 0xFF ) {
628 case 8: 628 case 8: