comparison src/audio/dart/SDL_dart.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 c9b51268668f
children 604d73db6802
comparison
equal deleted inserted replaced
1335:c39265384763 1336:3692456e7b0f
92 int iOpenMode; 92 int iOpenMode;
93 int iSilence; 93 int iSilence;
94 int rc; 94 int rc;
95 95
96 // First thing is to try to open a given DART device! 96 // First thing is to try to open a given DART device!
97 memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS)); 97 SDL_memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS));
98 // pszDeviceType should contain the device type in low word, and device ordinal in high word! 98 // pszDeviceType should contain the device type in low word, and device ordinal in high word!
99 AmpOpenParms.pszDeviceType = (PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16)); 99 AmpOpenParms.pszDeviceType = (PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16));
100 100
101 iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID; 101 iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID;
102 if (bOpenShared) iOpenMode |= MCI_OPEN_SHAREABLE; 102 if (bOpenShared) iOpenMode |= MCI_OPEN_SHAREABLE;
136 /* Update the fragment size as size in bytes */ 136 /* Update the fragment size as size in bytes */
137 SDL_CalculateAudioSpec(spec); 137 SDL_CalculateAudioSpec(spec);
138 iBufSize = spec->size; 138 iBufSize = spec->size;
139 139
140 // Now query this device if it supports the given freq/bits/channels! 140 // Now query this device if it supports the given freq/bits/channels!
141 memset(&(_this->hidden->MixSetupParms), 0, sizeof(MCI_MIXSETUP_PARMS)); 141 SDL_memset(&(_this->hidden->MixSetupParms), 0, sizeof(MCI_MIXSETUP_PARMS));
142 _this->hidden->MixSetupParms.ulBitsPerSample = iBits; 142 _this->hidden->MixSetupParms.ulBitsPerSample = iBits;
143 _this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM; 143 _this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM;
144 _this->hidden->MixSetupParms.ulSamplesPerSec = iFreq; 144 _this->hidden->MixSetupParms.ulSamplesPerSec = iFreq;
145 _this->hidden->MixSetupParms.ulChannels = iChannels; 145 _this->hidden->MixSetupParms.ulChannels = iChannels;
146 _this->hidden->MixSetupParms.ulFormatMode = MCI_PLAY; 146 _this->hidden->MixSetupParms.ulFormatMode = MCI_PLAY;
168 return(-1); 168 return(-1);
169 } 169 }
170 // Ok, the device is initialized. 170 // Ok, the device is initialized.
171 // Now we should allocate buffers. For this, we need a place where 171 // Now we should allocate buffers. For this, we need a place where
172 // the buffer descriptors will be: 172 // the buffer descriptors will be:
173 _this->hidden->pMixBuffers = (MCI_MIX_BUFFER *) malloc(sizeof(MCI_MIX_BUFFER)*iNumBufs); 173 _this->hidden->pMixBuffers = (MCI_MIX_BUFFER *) SDL_malloc(sizeof(MCI_MIX_BUFFER)*iNumBufs);
174 if (!(_this->hidden->pMixBuffers)) 174 if (!(_this->hidden->pMixBuffers))
175 { // Not enough memory! 175 { // Not enough memory!
176 // Close DART, and exit with error code! 176 // Close DART, and exit with error code!
177 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); 177 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
178 SDL_SetError("Not enough memory for audio buffer descriptors"); 178 SDL_SetError("Not enough memory for audio buffer descriptors");
188 MCI_WAIT | MCI_ALLOCATE_MEMORY, 188 MCI_WAIT | MCI_ALLOCATE_MEMORY,
189 &(_this->hidden->BufferParms), 0); 189 &(_this->hidden->BufferParms), 0);
190 if ((rc!=MCIERR_SUCCESS) || (iNumBufs != _this->hidden->BufferParms.ulNumBuffers) || (_this->hidden->BufferParms.ulBufferSize==0)) 190 if ((rc!=MCIERR_SUCCESS) || (iNumBufs != _this->hidden->BufferParms.ulNumBuffers) || (_this->hidden->BufferParms.ulBufferSize==0))
191 { // Could not allocate memory! 191 { // Could not allocate memory!
192 // Close DART, and exit with error code! 192 // Close DART, and exit with error code!
193 free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL; 193 SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
194 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); 194 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
195 SDL_SetError("DART could not allocate buffers"); 195 SDL_SetError("DART could not allocate buffers");
196 return(-1); 196 return(-1);
197 } 197 }
198 // Ok, we have all the buffers allocated, let's mark them! 198 // Ok, we have all the buffers allocated, let's mark them!
199 { 199 {
200 int i; 200 int i;
201 for (i=0; i<iNumBufs; i++) 201 for (i=0; i<iNumBufs; i++)
202 { 202 {
203 pMixBufferDesc pBufferDesc = (pMixBufferDesc) malloc(sizeof(tMixBufferDesc));; 203 pMixBufferDesc pBufferDesc = (pMixBufferDesc) SDL_malloc(sizeof(tMixBufferDesc));;
204 // Check if this buffer was really allocated by DART 204 // Check if this buffer was really allocated by DART
205 if ((!(_this->hidden->pMixBuffers[i].pBuffer)) || (!pBufferDesc)) 205 if ((!(_this->hidden->pMixBuffers[i].pBuffer)) || (!pBufferDesc))
206 { // Wrong buffer! 206 { // Wrong buffer!
207 // Close DART, and exit with error code! 207 // Close DART, and exit with error code!
208 // Free buffer descriptions 208 // Free buffer descriptions
209 { int j; 209 { int j;
210 for (j=0; j<i; j++) free((void *)(_this->hidden->pMixBuffers[j].ulUserParm)); 210 for (j=0; j<i; j++) SDL_free((void *)(_this->hidden->pMixBuffers[j].ulUserParm));
211 } 211 }
212 // and cleanup 212 // and cleanup
213 mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0); 213 mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
214 free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL; 214 SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
215 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); 215 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
216 SDL_SetError("Error at internal buffer check"); 216 SDL_SetError("Error at internal buffer check");
217 return(-1); 217 return(-1);
218 } 218 }
219 pBufferDesc->iBufferUsage = BUFFER_EMPTY; 219 pBufferDesc->iBufferUsage = BUFFER_EMPTY;
222 _this->hidden->pMixBuffers[i].ulBufferLength = _this->hidden->BufferParms.ulBufferSize; 222 _this->hidden->pMixBuffers[i].ulBufferLength = _this->hidden->BufferParms.ulBufferSize;
223 _this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer 223 _this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer
224 _this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of 224 _this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of
225 // audio data, but as we will continously send 225 // audio data, but as we will continously send
226 // audio data, there will be no end.:) 226 // audio data, there will be no end.:)
227 memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence, iBufSize); 227 SDL_memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence, iBufSize);
228 } 228 }
229 } 229 }
230 _this->hidden->iNextFreeBuffer = 0; 230 _this->hidden->iNextFreeBuffer = 0;
231 _this->hidden->iLastPlayedBuf = -1; 231 _this->hidden->iLastPlayedBuf = -1;
232 // Create event semaphore 232 // Create event semaphore
233 if (DosCreateEventSem(NULL, &(_this->hidden->hevAudioBufferPlayed), 0, FALSE)!=NO_ERROR) 233 if (DosCreateEventSem(NULL, &(_this->hidden->hevAudioBufferPlayed), 0, FALSE)!=NO_ERROR)
234 { 234 {
235 // Could not create event semaphore! 235 // Could not create event semaphore!
236 { 236 {
237 int i; 237 int i;
238 for (i=0; i<iNumBufs; i++) free((void *)(_this->hidden->pMixBuffers[i].ulUserParm)); 238 for (i=0; i<iNumBufs; i++) SDL_free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
239 } 239 }
240 mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0); 240 mciSendCommand(iDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
241 free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL; 241 SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
242 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); 242 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
243 SDL_SetError("Could not create event semaphore"); 243 SDL_SetError("Could not create event semaphore");
244 return(-1); 244 return(-1);
245 } 245 }
246 246
361 DosCloseEventSem(_this->hidden->hevAudioBufferPlayed); 361 DosCloseEventSem(_this->hidden->hevAudioBufferPlayed);
362 362
363 // Free memory of buffer descriptions 363 // Free memory of buffer descriptions
364 { 364 {
365 int i; 365 int i;
366 for (i=0; i<_this->hidden->iCurrNumBufs; i++) free((void *)(_this->hidden->pMixBuffers[i].ulUserParm)); 366 for (i=0; i<_this->hidden->iCurrNumBufs; i++) SDL_free((void *)(_this->hidden->pMixBuffers[i].ulUserParm));
367 } 367 }
368 368
369 // Deallocate buffers 369 // Deallocate buffers
370 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0); 370 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER, MCI_WAIT | MCI_DEALLOCATE_MEMORY, &(_this->hidden->BufferParms), 0);
371 371
372 // Free bufferlist 372 // Free bufferlist
373 free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL; 373 SDL_free(_this->hidden->pMixBuffers); _this->hidden->pMixBuffers = NULL;
374 374
375 // Close dart 375 // Close dart
376 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_CLOSE, MCI_WAIT, &(GenericParms), 0); 376 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_CLOSE, MCI_WAIT, &(GenericParms), 0);
377 } 377 }
378 378
383 return(1); 383 return(1);
384 } 384 }
385 385
386 void Audio_DeleteDevice(SDL_AudioDevice *device) 386 void Audio_DeleteDevice(SDL_AudioDevice *device)
387 { 387 {
388 free(device->hidden); 388 SDL_free(device->hidden);
389 free(device); 389 SDL_free(device);
390 } 390 }
391 391
392 SDL_AudioDevice *Audio_CreateDevice(int devindex) 392 SDL_AudioDevice *Audio_CreateDevice(int devindex)
393 { 393 {
394 SDL_AudioDevice *this; 394 SDL_AudioDevice *this;
395 395
396 /* Initialize all variables that we clean on shutdown */ 396 /* Initialize all variables that we clean on shutdown */
397 this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice)); 397 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice));
398 if ( this ) 398 if ( this )
399 { 399 {
400 memset(this, 0, (sizeof *this)); 400 SDL_memset(this, 0, (sizeof *this));
401 this->hidden = (struct SDL_PrivateAudioData *) 401 this->hidden = (struct SDL_PrivateAudioData *)
402 malloc((sizeof *this->hidden)); 402 SDL_malloc((sizeof *this->hidden));
403 } 403 }
404 if ( (this == NULL) || (this->hidden == NULL) ) 404 if ( (this == NULL) || (this->hidden == NULL) )
405 { 405 {
406 SDL_OutOfMemory(); 406 SDL_OutOfMemory();
407 if ( this ) 407 if ( this )
408 free(this); 408 SDL_free(this);
409 return(0); 409 return(0);
410 } 410 }
411 memset(this->hidden, 0, (sizeof *this->hidden)); 411 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
412 412
413 /* Set the function pointers */ 413 /* Set the function pointers */
414 this->OpenAudio = DART_OpenAudio; 414 this->OpenAudio = DART_OpenAudio;
415 this->ThreadInit = DART_ThreadInit; 415 this->ThreadInit = DART_ThreadInit;
416 this->WaitAudio = DART_WaitAudio; 416 this->WaitAudio = DART_WaitAudio;