comparison src/audio/dart/SDL_dart.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
44 // 44 //
45 // This function is called by DART, when an event occures, like end of 45 // This function is called by DART, when an event occures, like end of
46 // playback of a buffer, etc... 46 // playback of a buffer, etc...
47 //--------------------------------------------------------------------- 47 //---------------------------------------------------------------------
48 LONG APIENTRY 48 LONG APIENTRY
49 DARTEventFunc (ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags) 49 DARTEventFunc(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags)
50 { 50 {
51 if (ulFlags && MIX_WRITE_COMPLETE) { // Playback of buffer completed! 51 if (ulFlags && MIX_WRITE_COMPLETE) { // Playback of buffer completed!
52 52
53 // Get pointer to buffer description 53 // Get pointer to buffer description
54 pMixBufferDesc pBufDesc; 54 pMixBufferDesc pBufDesc;
60 SDL_AudioDevice *pSDLAudioDevice = pBufDesc->pSDLAudioDevice; 60 SDL_AudioDevice *pSDLAudioDevice = pBufDesc->pSDLAudioDevice;
61 // Set the buffer to be empty 61 // Set the buffer to be empty
62 pBufDesc->iBufferUsage = BUFFER_EMPTY; 62 pBufDesc->iBufferUsage = BUFFER_EMPTY;
63 // And notify DART feeder thread that it will have to work a bit. 63 // And notify DART feeder thread that it will have to work a bit.
64 if (pSDLAudioDevice) 64 if (pSDLAudioDevice)
65 DosPostEventSem (pSDLAudioDevice->hidden-> 65 DosPostEventSem(pSDLAudioDevice->hidden->
66 hevAudioBufferPlayed); 66 hevAudioBufferPlayed);
67 } 67 }
68 } 68 }
69 } 69 }
70 return TRUE; 70 return TRUE;
71 } 71 }
72 72
73 73
74 int 74 int
75 DART_OpenAudio (_THIS, SDL_AudioSpec * spec) 75 DART_OpenAudio(_THIS, SDL_AudioSpec * spec)
76 { 76 {
77 MCI_AMP_OPEN_PARMS AmpOpenParms; 77 MCI_AMP_OPEN_PARMS AmpOpenParms;
78 MCI_GENERIC_PARMS GenericParms; 78 MCI_GENERIC_PARMS GenericParms;
79 int iDeviceOrd = 0; // Default device to be used 79 int iDeviceOrd = 0; // Default device to be used
80 int bOpenShared = 1; // Try opening it shared 80 int bOpenShared = 1; // Try opening it shared
86 int iOpenMode; 86 int iOpenMode;
87 int iSilence; 87 int iSilence;
88 int rc; 88 int rc;
89 89
90 // First thing is to try to open a given DART device! 90 // First thing is to try to open a given DART device!
91 SDL_memset (&AmpOpenParms, 0, sizeof (MCI_AMP_OPEN_PARMS)); 91 SDL_memset(&AmpOpenParms, 0, sizeof(MCI_AMP_OPEN_PARMS));
92 // pszDeviceType should contain the device type in low word, and device ordinal in high word! 92 // pszDeviceType should contain the device type in low word, and device ordinal in high word!
93 AmpOpenParms.pszDeviceType = 93 AmpOpenParms.pszDeviceType =
94 (PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16)); 94 (PSZ) (MCI_DEVTYPE_AUDIO_AMPMIX | (iDeviceOrd << 16));
95 95
96 iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID; 96 iOpenMode = MCI_WAIT | MCI_OPEN_TYPE_ID;
97 if (bOpenShared) 97 if (bOpenShared)
98 iOpenMode |= MCI_OPEN_SHAREABLE; 98 iOpenMode |= MCI_OPEN_SHAREABLE;
99 99
100 rc = mciSendCommand (0, MCI_OPEN, iOpenMode, (PVOID) & AmpOpenParms, 0); 100 rc = mciSendCommand(0, MCI_OPEN, iOpenMode, (PVOID) & AmpOpenParms, 0);
101 if (rc != MCIERR_SUCCESS) // No audio available?? 101 if (rc != MCIERR_SUCCESS) // No audio available??
102 return (-1); 102 return (-1);
103 // Save the device ID we got from DART! 103 // Save the device ID we got from DART!
104 // We will use this in the next calls! 104 // We will use this in the next calls!
105 iDeviceOrd = AmpOpenParms.usDeviceID; 105 iDeviceOrd = AmpOpenParms.usDeviceID;
118 iSilence = 0x00; 118 iSilence = 0x00;
119 iBits = 16; 119 iBits = 16;
120 break; 120 break;
121 default: 121 default:
122 // Close DART, and exit with error code! 122 // Close DART, and exit with error code!
123 mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); 123 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
124 SDL_SetError ("Unsupported audio format"); 124 SDL_SetError("Unsupported audio format");
125 return (-1); 125 return (-1);
126 } 126 }
127 iFreq = spec->freq; 127 iFreq = spec->freq;
128 iChannels = spec->channels; 128 iChannels = spec->channels;
129 /* Update the fragment size as size in bytes */ 129 /* Update the fragment size as size in bytes */
130 SDL_CalculateAudioSpec (spec); 130 SDL_CalculateAudioSpec(spec);
131 iBufSize = spec->size; 131 iBufSize = spec->size;
132 132
133 // Now query this device if it supports the given freq/bits/channels! 133 // Now query this device if it supports the given freq/bits/channels!
134 SDL_memset (&(_this->hidden->MixSetupParms), 0, 134 SDL_memset(&(_this->hidden->MixSetupParms), 0,
135 sizeof (MCI_MIXSETUP_PARMS)); 135 sizeof(MCI_MIXSETUP_PARMS));
136 _this->hidden->MixSetupParms.ulBitsPerSample = iBits; 136 _this->hidden->MixSetupParms.ulBitsPerSample = iBits;
137 _this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM; 137 _this->hidden->MixSetupParms.ulFormatTag = MCI_WAVE_FORMAT_PCM;
138 _this->hidden->MixSetupParms.ulSamplesPerSec = iFreq; 138 _this->hidden->MixSetupParms.ulSamplesPerSec = iFreq;
139 _this->hidden->MixSetupParms.ulChannels = iChannels; 139 _this->hidden->MixSetupParms.ulChannels = iChannels;
140 _this->hidden->MixSetupParms.ulFormatMode = MCI_PLAY; 140 _this->hidden->MixSetupParms.ulFormatMode = MCI_PLAY;
141 _this->hidden->MixSetupParms.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; 141 _this->hidden->MixSetupParms.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
142 _this->hidden->MixSetupParms.pmixEvent = DARTEventFunc; 142 _this->hidden->MixSetupParms.pmixEvent = DARTEventFunc;
143 rc = mciSendCommand (iDeviceOrd, MCI_MIXSETUP, 143 rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP,
144 MCI_WAIT | MCI_MIXSETUP_QUERYMODE, 144 MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
145 &(_this->hidden->MixSetupParms), 0); 145 &(_this->hidden->MixSetupParms), 0);
146 if (rc != MCIERR_SUCCESS) { // The device cannot handle this format! 146 if (rc != MCIERR_SUCCESS) { // The device cannot handle this format!
147 // Close DART, and exit with error code! 147 // Close DART, and exit with error code!
148 mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); 148 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
149 SDL_SetError ("Audio device doesn't support requested audio format"); 149 SDL_SetError("Audio device doesn't support requested audio format");
150 return (-1); 150 return (-1);
151 } 151 }
152 // The device can handle this format, so initialize! 152 // The device can handle this format, so initialize!
153 rc = mciSendCommand (iDeviceOrd, MCI_MIXSETUP, 153 rc = mciSendCommand(iDeviceOrd, MCI_MIXSETUP,
154 MCI_WAIT | MCI_MIXSETUP_INIT, 154 MCI_WAIT | MCI_MIXSETUP_INIT,
155 &(_this->hidden->MixSetupParms), 0); 155 &(_this->hidden->MixSetupParms), 0);
156 if (rc != MCIERR_SUCCESS) { // The device could not be opened! 156 if (rc != MCIERR_SUCCESS) { // The device could not be opened!
157 // Close DART, and exit with error code! 157 // Close DART, and exit with error code!
158 mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); 158 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
159 SDL_SetError ("Audio device could not be set up"); 159 SDL_SetError("Audio device could not be set up");
160 return (-1); 160 return (-1);
161 } 161 }
162 // Ok, the device is initialized. 162 // Ok, the device is initialized.
163 // Now we should allocate buffers. For this, we need a place where 163 // Now we should allocate buffers. For this, we need a place where
164 // the buffer descriptors will be: 164 // the buffer descriptors will be:
165 _this->hidden->pMixBuffers = 165 _this->hidden->pMixBuffers =
166 (MCI_MIX_BUFFER *) SDL_malloc (sizeof (MCI_MIX_BUFFER) * iNumBufs); 166 (MCI_MIX_BUFFER *) SDL_malloc(sizeof(MCI_MIX_BUFFER) * iNumBufs);
167 if (!(_this->hidden->pMixBuffers)) { // Not enough memory! 167 if (!(_this->hidden->pMixBuffers)) { // Not enough memory!
168 // Close DART, and exit with error code! 168 // Close DART, and exit with error code!
169 mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); 169 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
170 SDL_SetError ("Not enough memory for audio buffer descriptors"); 170 SDL_SetError("Not enough memory for audio buffer descriptors");
171 return (-1); 171 return (-1);
172 } 172 }
173 // Now that we have the place for buffer list, we can ask DART for the 173 // Now that we have the place for buffer list, we can ask DART for the
174 // buffers! 174 // buffers!
175 _this->hidden->BufferParms.ulNumBuffers = iNumBufs; // Number of buffers 175 _this->hidden->BufferParms.ulNumBuffers = iNumBufs; // Number of buffers
176 _this->hidden->BufferParms.ulBufferSize = iBufSize; // each with this size 176 _this->hidden->BufferParms.ulBufferSize = iBufSize; // each with this size
177 _this->hidden->BufferParms.pBufList = _this->hidden->pMixBuffers; // getting descriptorts into this list 177 _this->hidden->BufferParms.pBufList = _this->hidden->pMixBuffers; // getting descriptorts into this list
178 // Allocate buffers! 178 // Allocate buffers!
179 rc = mciSendCommand (iDeviceOrd, MCI_BUFFER, 179 rc = mciSendCommand(iDeviceOrd, MCI_BUFFER,
180 MCI_WAIT | MCI_ALLOCATE_MEMORY, 180 MCI_WAIT | MCI_ALLOCATE_MEMORY,
181 &(_this->hidden->BufferParms), 0); 181 &(_this->hidden->BufferParms), 0);
182 if ((rc != MCIERR_SUCCESS) 182 if ((rc != MCIERR_SUCCESS)
183 || (iNumBufs != _this->hidden->BufferParms.ulNumBuffers) 183 || (iNumBufs != _this->hidden->BufferParms.ulNumBuffers)
184 || (_this->hidden->BufferParms.ulBufferSize == 0)) { // Could not allocate memory! 184 || (_this->hidden->BufferParms.ulBufferSize == 0)) { // Could not allocate memory!
185 // Close DART, and exit with error code! 185 // Close DART, and exit with error code!
186 SDL_free (_this->hidden->pMixBuffers); 186 SDL_free(_this->hidden->pMixBuffers);
187 _this->hidden->pMixBuffers = NULL; 187 _this->hidden->pMixBuffers = NULL;
188 mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); 188 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
189 SDL_SetError ("DART could not allocate buffers"); 189 SDL_SetError("DART could not allocate buffers");
190 return (-1); 190 return (-1);
191 } 191 }
192 // Ok, we have all the buffers allocated, let's mark them! 192 // Ok, we have all the buffers allocated, let's mark them!
193 { 193 {
194 int i; 194 int i;
195 for (i = 0; i < iNumBufs; i++) { 195 for (i = 0; i < iNumBufs; i++) {
196 pMixBufferDesc pBufferDesc = 196 pMixBufferDesc pBufferDesc =
197 (pMixBufferDesc) SDL_malloc (sizeof (tMixBufferDesc));; 197 (pMixBufferDesc) SDL_malloc(sizeof(tMixBufferDesc));;
198 // Check if this buffer was really allocated by DART 198 // Check if this buffer was really allocated by DART
199 if ((!(_this->hidden->pMixBuffers[i].pBuffer)) 199 if ((!(_this->hidden->pMixBuffers[i].pBuffer))
200 || (!pBufferDesc)) { // Wrong buffer! 200 || (!pBufferDesc)) { // Wrong buffer!
201 // Close DART, and exit with error code! 201 // Close DART, and exit with error code!
202 // Free buffer descriptions 202 // Free buffer descriptions
203 { 203 {
204 int j; 204 int j;
205 for (j = 0; j < i; j++) 205 for (j = 0; j < i; j++)
206 SDL_free ((void *) (_this->hidden->pMixBuffers[j]. 206 SDL_free((void *) (_this->hidden->pMixBuffers[j].
207 ulUserParm)); 207 ulUserParm));
208 } 208 }
209 // and cleanup 209 // and cleanup
210 mciSendCommand (iDeviceOrd, MCI_BUFFER, 210 mciSendCommand(iDeviceOrd, MCI_BUFFER,
211 MCI_WAIT | MCI_DEALLOCATE_MEMORY, 211 MCI_WAIT | MCI_DEALLOCATE_MEMORY,
212 &(_this->hidden->BufferParms), 0); 212 &(_this->hidden->BufferParms), 0);
213 SDL_free (_this->hidden->pMixBuffers); 213 SDL_free(_this->hidden->pMixBuffers);
214 _this->hidden->pMixBuffers = NULL; 214 _this->hidden->pMixBuffers = NULL;
215 mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, 215 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT,
216 &GenericParms, 0); 216 &GenericParms, 0);
217 SDL_SetError ("Error at internal buffer check"); 217 SDL_SetError("Error at internal buffer check");
218 return (-1); 218 return (-1);
219 } 219 }
220 pBufferDesc->iBufferUsage = BUFFER_EMPTY; 220 pBufferDesc->iBufferUsage = BUFFER_EMPTY;
221 pBufferDesc->pSDLAudioDevice = _this; 221 pBufferDesc->pSDLAudioDevice = _this;
222 222
224 _this->hidden->BufferParms.ulBufferSize; 224 _this->hidden->BufferParms.ulBufferSize;
225 _this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer 225 _this->hidden->pMixBuffers[i].ulUserParm = (ULONG) pBufferDesc; // User parameter: Description of buffer
226 _this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of 226 _this->hidden->pMixBuffers[i].ulFlags = 0; // Some stuff should be flagged here for DART, like end of
227 // audio data, but as we will continously send 227 // audio data, but as we will continously send
228 // audio data, there will be no end.:) 228 // audio data, there will be no end.:)
229 SDL_memset (_this->hidden->pMixBuffers[i].pBuffer, iSilence, 229 SDL_memset(_this->hidden->pMixBuffers[i].pBuffer, iSilence,
230 iBufSize); 230 iBufSize);
231 } 231 }
232 } 232 }
233 _this->hidden->iNextFreeBuffer = 0; 233 _this->hidden->iNextFreeBuffer = 0;
234 _this->hidden->iLastPlayedBuf = -1; 234 _this->hidden->iLastPlayedBuf = -1;
235 // Create event semaphore 235 // Create event semaphore
238 { 238 {
239 // Could not create event semaphore! 239 // Could not create event semaphore!
240 { 240 {
241 int i; 241 int i;
242 for (i = 0; i < iNumBufs; i++) 242 for (i = 0; i < iNumBufs; i++)
243 SDL_free ((void *) (_this->hidden->pMixBuffers[i]. 243 SDL_free((void *) (_this->hidden->pMixBuffers[i].ulUserParm));
244 ulUserParm));
245 } 244 }
246 mciSendCommand (iDeviceOrd, MCI_BUFFER, 245 mciSendCommand(iDeviceOrd, MCI_BUFFER,
247 MCI_WAIT | MCI_DEALLOCATE_MEMORY, 246 MCI_WAIT | MCI_DEALLOCATE_MEMORY,
248 &(_this->hidden->BufferParms), 0); 247 &(_this->hidden->BufferParms), 0);
249 SDL_free (_this->hidden->pMixBuffers); 248 SDL_free(_this->hidden->pMixBuffers);
250 _this->hidden->pMixBuffers = NULL; 249 _this->hidden->pMixBuffers = NULL;
251 mciSendCommand (iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0); 250 mciSendCommand(iDeviceOrd, MCI_CLOSE, MCI_WAIT, &GenericParms, 0);
252 SDL_SetError ("Could not create event semaphore"); 251 SDL_SetError("Could not create event semaphore");
253 return (-1); 252 return (-1);
254 } 253 }
255 // Store the new settings in global variables 254 // Store the new settings in global variables
256 _this->hidden->iCurrDeviceOrd = iDeviceOrd; 255 _this->hidden->iCurrDeviceOrd = iDeviceOrd;
257 _this->hidden->iCurrFreq = iFreq; 256 _this->hidden->iCurrFreq = iFreq;
264 } 263 }
265 264
266 265
267 266
268 void 267 void
269 DART_ThreadInit (_THIS) 268 DART_ThreadInit(_THIS)
270 { 269 {
271 return; 270 return;
272 } 271 }
273 272
274 /* This function waits until it is possible to write a full sound buffer */ 273 /* This function waits until it is possible to write a full sound buffer */
275 void 274 void
276 DART_WaitAudio (_THIS) 275 DART_WaitAudio(_THIS)
277 { 276 {
278 int i; 277 int i;
279 pMixBufferDesc pBufDesc; 278 pMixBufferDesc pBufDesc;
280 ULONG ulPostCount; 279 ULONG ulPostCount;
281 280
282 DosResetEventSem (_this->hidden->hevAudioBufferPlayed, &ulPostCount); 281 DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
283 // If there is already an empty buffer, then return now! 282 // If there is already an empty buffer, then return now!
284 for (i = 0; i < _this->hidden->iCurrNumBufs; i++) { 283 for (i = 0; i < _this->hidden->iCurrNumBufs; i++) {
285 pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[i].ulUserParm; 284 pBufDesc = (pMixBufferDesc) _this->hidden->pMixBuffers[i].ulUserParm;
286 if (pBufDesc->iBufferUsage == BUFFER_EMPTY) 285 if (pBufDesc->iBufferUsage == BUFFER_EMPTY)
287 return; 286 return;
288 } 287 }
289 // If there is no empty buffer, wait for one to be empty! 288 // If there is no empty buffer, wait for one to be empty!
290 DosWaitEventSem (_this->hidden->hevAudioBufferPlayed, 1000); // Wait max 1 sec!!! Important! 289 DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // Wait max 1 sec!!! Important!
291 return; 290 return;
292 } 291 }
293 292
294 void 293 void
295 DART_PlayAudio (_THIS) 294 DART_PlayAudio(_THIS)
296 { 295 {
297 int iFreeBuf = _this->hidden->iNextFreeBuffer; 296 int iFreeBuf = _this->hidden->iNextFreeBuffer;
298 pMixBufferDesc pBufDesc; 297 pMixBufferDesc pBufDesc;
299 298
300 pBufDesc = 299 pBufDesc =
301 (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm; 300 (pMixBufferDesc) _this->hidden->pMixBuffers[iFreeBuf].ulUserParm;
302 pBufDesc->iBufferUsage = BUFFER_USED; 301 pBufDesc->iBufferUsage = BUFFER_USED;
303 // Send it to DART to be queued 302 // Send it to DART to be queued
304 _this->hidden->MixSetupParms.pmixWrite (_this->hidden->MixSetupParms. 303 _this->hidden->MixSetupParms.pmixWrite(_this->hidden->MixSetupParms.
305 ulMixHandle, 304 ulMixHandle,
306 &(_this->hidden-> 305 &(_this->hidden->
307 pMixBuffers[iFreeBuf]), 1); 306 pMixBuffers[iFreeBuf]), 1);
308 307
309 _this->hidden->iLastPlayedBuf = iFreeBuf; 308 _this->hidden->iLastPlayedBuf = iFreeBuf;
310 iFreeBuf = (iFreeBuf + 1) % _this->hidden->iCurrNumBufs; 309 iFreeBuf = (iFreeBuf + 1) % _this->hidden->iCurrNumBufs;
311 _this->hidden->iNextFreeBuffer = iFreeBuf; 310 _this->hidden->iNextFreeBuffer = iFreeBuf;
312 } 311 }
313 312
314 Uint8 * 313 Uint8 *
315 DART_GetAudioBuf (_THIS) 314 DART_GetAudioBuf(_THIS)
316 { 315 {
317 int iFreeBuf; 316 int iFreeBuf;
318 Uint8 *pResult; 317 Uint8 *pResult;
319 pMixBufferDesc pBufDesc; 318 pMixBufferDesc pBufDesc;
320 319
329 if (pBufDesc->iBufferUsage == BUFFER_EMPTY) { 328 if (pBufDesc->iBufferUsage == BUFFER_EMPTY) {
330 pResult = _this->hidden->pMixBuffers[iFreeBuf].pBuffer; 329 pResult = _this->hidden->pMixBuffers[iFreeBuf].pBuffer;
331 return pResult; 330 return pResult;
332 } 331 }
333 } else 332 } else
334 printf ("[DART_GetAudioBuf] : ERROR! pBufDesc = %p\n", 333 printf("[DART_GetAudioBuf] : ERROR! pBufDesc = %p\n",
335 pBufDesc); 334 pBufDesc);
336 } else 335 } else
337 printf ("[DART_GetAudioBuf] : ERROR! _this->hidden = %p\n", 336 printf("[DART_GetAudioBuf] : ERROR! _this->hidden = %p\n",
338 _this->hidden); 337 _this->hidden);
339 } else 338 } else
340 printf ("[DART_GetAudioBuf] : ERROR! _this = %p\n", _this); 339 printf("[DART_GetAudioBuf] : ERROR! _this = %p\n", _this);
341 return NULL; 340 return NULL;
342 } 341 }
343 342
344 void 343 void
345 DART_WaitDone (_THIS) 344 DART_WaitDone(_THIS)
346 { 345 {
347 pMixBufferDesc pBufDesc; 346 pMixBufferDesc pBufDesc;
348 ULONG ulPostCount; 347 ULONG ulPostCount;
349 APIRET rc; 348 APIRET rc;
350 349
352 (pMixBufferDesc) _this->hidden->pMixBuffers[_this->hidden-> 351 (pMixBufferDesc) _this->hidden->pMixBuffers[_this->hidden->
353 iLastPlayedBuf]. 352 iLastPlayedBuf].
354 ulUserParm; 353 ulUserParm;
355 rc = NO_ERROR; 354 rc = NO_ERROR;
356 while ((pBufDesc->iBufferUsage != BUFFER_EMPTY) && (rc == NO_ERROR)) { 355 while ((pBufDesc->iBufferUsage != BUFFER_EMPTY) && (rc == NO_ERROR)) {
357 DosResetEventSem (_this->hidden->hevAudioBufferPlayed, &ulPostCount); 356 DosResetEventSem(_this->hidden->hevAudioBufferPlayed, &ulPostCount);
358 rc = DosWaitEventSem (_this->hidden->hevAudioBufferPlayed, 1000); // 1 sec timeout! Important! 357 rc = DosWaitEventSem(_this->hidden->hevAudioBufferPlayed, 1000); // 1 sec timeout! Important!
359 } 358 }
360 } 359 }
361 360
362 void 361 void
363 DART_CloseAudio (_THIS) 362 DART_CloseAudio(_THIS)
364 { 363 {
365 MCI_GENERIC_PARMS GenericParms; 364 MCI_GENERIC_PARMS GenericParms;
366 int rc; 365 int rc;
367 366
368 // Stop DART playback 367 // Stop DART playback
369 rc = mciSendCommand (_this->hidden->iCurrDeviceOrd, MCI_STOP, MCI_WAIT, 368 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_STOP, MCI_WAIT,
370 &GenericParms, 0); 369 &GenericParms, 0);
371 if (rc != MCIERR_SUCCESS) { 370 if (rc != MCIERR_SUCCESS) {
372 #ifdef SFX_DEBUG_BUILD 371 #ifdef SFX_DEBUG_BUILD
373 printf ("Could not stop DART playback!\n"); 372 printf("Could not stop DART playback!\n");
374 fflush (stdout); 373 fflush(stdout);
375 #endif 374 #endif
376 } 375 }
377 // Close event semaphore 376 // Close event semaphore
378 DosCloseEventSem (_this->hidden->hevAudioBufferPlayed); 377 DosCloseEventSem(_this->hidden->hevAudioBufferPlayed);
379 378
380 // Free memory of buffer descriptions 379 // Free memory of buffer descriptions
381 { 380 {
382 int i; 381 int i;
383 for (i = 0; i < _this->hidden->iCurrNumBufs; i++) 382 for (i = 0; i < _this->hidden->iCurrNumBufs; i++)
384 SDL_free ((void *) (_this->hidden->pMixBuffers[i].ulUserParm)); 383 SDL_free((void *) (_this->hidden->pMixBuffers[i].ulUserParm));
385 } 384 }
386 385
387 // Deallocate buffers 386 // Deallocate buffers
388 rc = mciSendCommand (_this->hidden->iCurrDeviceOrd, MCI_BUFFER, 387 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_BUFFER,
389 MCI_WAIT | MCI_DEALLOCATE_MEMORY, 388 MCI_WAIT | MCI_DEALLOCATE_MEMORY,
390 &(_this->hidden->BufferParms), 0); 389 &(_this->hidden->BufferParms), 0);
391 390
392 // Free bufferlist 391 // Free bufferlist
393 SDL_free (_this->hidden->pMixBuffers); 392 SDL_free(_this->hidden->pMixBuffers);
394 _this->hidden->pMixBuffers = NULL; 393 _this->hidden->pMixBuffers = NULL;
395 394
396 // Close dart 395 // Close dart
397 rc = mciSendCommand (_this->hidden->iCurrDeviceOrd, MCI_CLOSE, MCI_WAIT, 396 rc = mciSendCommand(_this->hidden->iCurrDeviceOrd, MCI_CLOSE, MCI_WAIT,
398 &(GenericParms), 0); 397 &(GenericParms), 0);
399 } 398 }
400 399
401 /* Audio driver bootstrap functions */ 400 /* Audio driver bootstrap functions */
402 401
403 int 402 int
404 Audio_Available (void) 403 Audio_Available(void)
405 { 404 {
406 return (1); 405 return (1);
407 } 406 }
408 407
409 void 408 void
410 Audio_DeleteDevice (SDL_AudioDevice * device) 409 Audio_DeleteDevice(SDL_AudioDevice * device)
411 { 410 {
412 SDL_free (device->hidden); 411 SDL_free(device->hidden);
413 SDL_free (device); 412 SDL_free(device);
414 } 413 }
415 414
416 SDL_AudioDevice * 415 SDL_AudioDevice *
417 Audio_CreateDevice (int devindex) 416 Audio_CreateDevice(int devindex)
418 { 417 {
419 SDL_AudioDevice *this; 418 SDL_AudioDevice *this;
420 419
421 /* Initialize all variables that we clean on shutdown */ 420 /* Initialize all variables that we clean on shutdown */
422 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); 421 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
423 if (this) { 422 if (this) {
424 SDL_memset (this, 0, (sizeof *this)); 423 SDL_memset(this, 0, (sizeof *this));
425 this->hidden = (struct SDL_PrivateAudioData *) 424 this->hidden = (struct SDL_PrivateAudioData *)
426 SDL_malloc ((sizeof *this->hidden)); 425 SDL_malloc((sizeof *this->hidden));
427 } 426 }
428 if ((this == NULL) || (this->hidden == NULL)) { 427 if ((this == NULL) || (this->hidden == NULL)) {
429 SDL_OutOfMemory (); 428 SDL_OutOfMemory();
430 if (this) 429 if (this)
431 SDL_free (this); 430 SDL_free(this);
432 return (0); 431 return (0);
433 } 432 }
434 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); 433 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
435 434
436 /* Set the function pointers */ 435 /* Set the function pointers */
437 this->OpenAudio = DART_OpenAudio; 436 this->OpenAudio = DART_OpenAudio;
438 this->ThreadInit = DART_ThreadInit; 437 this->ThreadInit = DART_ThreadInit;
439 this->WaitAudio = DART_WaitAudio; 438 this->WaitAudio = DART_WaitAudio;