Mercurial > sdl-ios-xcode
comparison src/audio/windib/SDL_dibaudio.c @ 2060:866052b01ee5
indent is evil
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 28 Oct 2006 16:48:03 +0000 |
parents | bbc89e09503f |
children | e27bdcc80744 204be4fc2726 |
comparison
equal
deleted
inserted
replaced
2059:4685ccd33d0e | 2060:866052b01ee5 |
---|---|
105 } | 105 } |
106 | 106 |
107 Uint8 * | 107 Uint8 * |
108 WINWAVEOUT_GetDeviceBuf(_THIS) | 108 WINWAVEOUT_GetDeviceBuf(_THIS) |
109 { | 109 { |
110 return (Uint8 *) (this->hidden->wavebuf[this->hidden->next_buffer].lpData); | 110 return (Uint8 *) (this->hidden->wavebuf[this->hidden->next_buffer]. |
111 lpData); | |
111 } | 112 } |
112 | 113 |
113 void | 114 void |
114 WINWAVEOUT_PlayDevice(_THIS) | 115 WINWAVEOUT_PlayDevice(_THIS) |
115 { | 116 { |
116 /* Queue it up */ | 117 /* Queue it up */ |
117 waveOutWrite(this->hidden->sound, | 118 waveOutWrite(this->hidden->sound, |
118 &this->hidden->wavebuf[this->hidden->next_buffer], | 119 &this->hidden->wavebuf[this->hidden->next_buffer], |
119 sizeof (this->hidden->wavebuf[0])); | 120 sizeof(this->hidden->wavebuf[0])); |
120 this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS; | 121 this->hidden->next_buffer = (this->hidden->next_buffer + 1) % NUM_BUFFERS; |
121 } | 122 } |
122 | 123 |
123 void | 124 void |
124 WINWAVEOUT_WaitDone(_THIS) | 125 WINWAVEOUT_WaitDone(_THIS) |
163 /* Clean up mixing buffers */ | 164 /* Clean up mixing buffers */ |
164 for (i = 0; i < NUM_BUFFERS; ++i) { | 165 for (i = 0; i < NUM_BUFFERS; ++i) { |
165 if (this->hidden->wavebuf[i].dwUser != 0xFFFF) { | 166 if (this->hidden->wavebuf[i].dwUser != 0xFFFF) { |
166 waveOutUnprepareHeader(this->hidden->sound, | 167 waveOutUnprepareHeader(this->hidden->sound, |
167 &this->hidden->wavebuf[i], | 168 &this->hidden->wavebuf[i], |
168 sizeof (this->hidden->wavebuf[i])); | 169 sizeof(this->hidden->wavebuf[i])); |
169 this->hidden->wavebuf[i].dwUser = 0xFFFF; | 170 this->hidden->wavebuf[i].dwUser = 0xFFFF; |
170 } | 171 } |
171 } | 172 } |
172 | 173 |
173 if (this->hidden->mixbuf != NULL) { | 174 if (this->hidden->mixbuf != NULL) { |
190 WAVEFORMATEX waveformat; | 191 WAVEFORMATEX waveformat; |
191 int i; | 192 int i; |
192 | 193 |
193 /* Initialize all variables that we clean on shutdown */ | 194 /* Initialize all variables that we clean on shutdown */ |
194 this->hidden = (struct SDL_PrivateAudioData *) | 195 this->hidden = (struct SDL_PrivateAudioData *) |
195 SDL_malloc((sizeof *this->hidden)); | 196 SDL_malloc((sizeof *this->hidden)); |
196 if (this->hidden == NULL) { | 197 if (this->hidden == NULL) { |
197 SDL_OutOfMemory(); | 198 SDL_OutOfMemory(); |
198 return 0; | 199 return 0; |
199 } | 200 } |
200 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); | 201 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
205 | 206 |
206 while ((!valid_datatype) && (test_format)) { | 207 while ((!valid_datatype) && (test_format)) { |
207 valid_datatype = 1; | 208 valid_datatype = 1; |
208 this->spec.format = test_format; | 209 this->spec.format = test_format; |
209 switch (test_format) { | 210 switch (test_format) { |
210 case AUDIO_U8: | 211 case AUDIO_U8: |
211 case AUDIO_S16: | 212 case AUDIO_S16: |
212 case AUDIO_S32: | 213 case AUDIO_S32: |
213 break; /* valid. */ | 214 break; /* valid. */ |
214 | 215 |
215 default: | 216 default: |
216 valid_datatype = 0; | 217 valid_datatype = 0; |
217 test_format = SDL_NextAudioFormat(); | 218 test_format = SDL_NextAudioFormat(); |
218 break; | 219 break; |
219 } | 220 } |
220 } | 221 } |
221 | 222 |
222 if (!valid_datatype) { | 223 if (!valid_datatype) { |
223 WINWAVEOUT_CloseDevice(this); | 224 WINWAVEOUT_CloseDevice(this); |
224 SDL_SetError("Unsupported audio format"); | 225 SDL_SetError("Unsupported audio format"); |
225 return 0; | 226 return 0; |
226 } | 227 } |
227 | 228 |
228 /* Set basic WAVE format parameters */ | 229 /* Set basic WAVE format parameters */ |
229 SDL_memset(&waveformat, '\0', sizeof (waveformat)); | 230 SDL_memset(&waveformat, '\0', sizeof(waveformat)); |
230 waveformat.wFormatTag = WAVE_FORMAT_PCM; | 231 waveformat.wFormatTag = WAVE_FORMAT_PCM; |
231 waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format); | 232 waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format); |
232 | 233 |
233 if (this->spec.channels > 2) | 234 if (this->spec.channels > 2) |
234 this->spec.channels = 2; /* !!! FIXME: is this right? */ | 235 this->spec.channels = 2; /* !!! FIXME: is this right? */ |
235 | 236 |
236 waveformat.nChannels = this->spec.channels; | 237 waveformat.nChannels = this->spec.channels; |
237 waveformat.nSamplesPerSec = this->spec.freq; | 238 waveformat.nSamplesPerSec = this->spec.freq; |
238 waveformat.nBlockAlign = | 239 waveformat.nBlockAlign = |
239 waveformat.nChannels * (waveformat.wBitsPerSample / 8); | 240 waveformat.nChannels * (waveformat.wBitsPerSample / 8); |
271 printf("Audio device: %s\n", caps.szPname); | 272 printf("Audio device: %s\n", caps.szPname); |
272 } | 273 } |
273 #endif | 274 #endif |
274 | 275 |
275 /* Create the audio buffer semaphore */ | 276 /* Create the audio buffer semaphore */ |
276 this->hidden->audio_sem = | 277 this->hidden->audio_sem = |
277 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) | 278 #if defined(_WIN32_WCE) && (_WIN32_WCE < 300) |
278 CreateSemaphoreCE(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL); | 279 CreateSemaphoreCE(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL); |
279 #else | 280 #else |
280 CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL); | 281 CreateSemaphore(NULL, NUM_BUFFERS - 1, NUM_BUFFERS, NULL); |
281 #endif | 282 #endif |
282 if (this->hidden->audio_sem == NULL) { | 283 if (this->hidden->audio_sem == NULL) { |
283 WINWAVEOUT_CloseDevice(this); | 284 WINWAVEOUT_CloseDevice(this); |
284 SDL_SetError("Couldn't create semaphore"); | 285 SDL_SetError("Couldn't create semaphore"); |
285 return 0; | 286 return 0; |
286 } | 287 } |
287 | 288 |
288 /* Create the sound buffers */ | 289 /* Create the sound buffers */ |
289 this->hidden->mixbuf = (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size); | 290 this->hidden->mixbuf = |
291 (Uint8 *) SDL_malloc(NUM_BUFFERS * this->spec.size); | |
290 if (this->hidden->mixbuf == NULL) { | 292 if (this->hidden->mixbuf == NULL) { |
291 WINWAVEOUT_CloseDevice(this); | 293 WINWAVEOUT_CloseDevice(this); |
292 SDL_OutOfMemory(); | 294 SDL_OutOfMemory(); |
293 return 0; | 295 return 0; |
294 } | 296 } |
295 for (i = 0; i < NUM_BUFFERS; ++i) { | 297 for (i = 0; i < NUM_BUFFERS; ++i) { |
296 SDL_memset(&this->hidden->wavebuf[i], '\0', | 298 SDL_memset(&this->hidden->wavebuf[i], '\0', |
297 sizeof (this->hidden->wavebuf[i])); | 299 sizeof(this->hidden->wavebuf[i])); |
298 this->hidden->wavebuf[i].dwBufferLength = this->spec.size; | 300 this->hidden->wavebuf[i].dwBufferLength = this->spec.size; |
299 this->hidden->wavebuf[i].dwFlags = WHDR_DONE; | 301 this->hidden->wavebuf[i].dwFlags = WHDR_DONE; |
300 this->hidden->wavebuf[i].lpData = | 302 this->hidden->wavebuf[i].lpData = |
301 (LPSTR) &this->hidden->mixbuf[i * this->spec.size]; | 303 (LPSTR) & this->hidden->mixbuf[i * this->spec.size]; |
302 result = waveOutPrepareHeader(this->hidden->sound, | 304 result = waveOutPrepareHeader(this->hidden->sound, |
303 &this->hidden->wavebuf[i], | 305 &this->hidden->wavebuf[i], |
304 sizeof (this->hidden->wavebuf[i])); | 306 sizeof(this->hidden->wavebuf[i])); |
305 if (result != MMSYSERR_NOERROR) { | 307 if (result != MMSYSERR_NOERROR) { |
306 WINWAVEOUT_CloseDevice(this); | 308 WINWAVEOUT_CloseDevice(this); |
307 SetMMerror("waveOutPrepareHeader()", result); | 309 SetMMerror("waveOutPrepareHeader()", result); |
308 return 0; | 310 return 0; |
309 } | 311 } |
310 } | 312 } |
311 | 313 |
312 return 1; /* Ready to go! */ | 314 return 1; /* Ready to go! */ |
313 } | 315 } |
314 | 316 |
315 | 317 |
316 static int | 318 static int |
317 WINWAVEOUT_Init(SDL_AudioDriverImpl *impl) | 319 WINWAVEOUT_Init(SDL_AudioDriverImpl * impl) |
318 { | 320 { |
319 /* Set the function pointers */ | 321 /* Set the function pointers */ |
320 impl->OpenDevice = WINWAVEOUT_OpenDevice; | 322 impl->OpenDevice = WINWAVEOUT_OpenDevice; |
321 impl->ThreadInit = WINWAVEOUT_ThreadInit; | 323 impl->ThreadInit = WINWAVEOUT_ThreadInit; |
322 impl->PlayDevice = WINWAVEOUT_PlayDevice; | 324 impl->PlayDevice = WINWAVEOUT_PlayDevice; |
323 impl->WaitDevice = WINWAVEOUT_WaitDevice; | 325 impl->WaitDevice = WINWAVEOUT_WaitDevice; |
324 impl->WaitDone = WINWAVEOUT_WaitDone; | 326 impl->WaitDone = WINWAVEOUT_WaitDone; |
325 impl->GetDeviceBuf = WINWAVEOUT_GetDeviceBuf; | 327 impl->GetDeviceBuf = WINWAVEOUT_GetDeviceBuf; |
326 impl->CloseDevice = WINWAVEOUT_CloseDevice; | 328 impl->CloseDevice = WINWAVEOUT_CloseDevice; |
327 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Is this true? */ | 329 impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME: Is this true? */ |
328 | 330 |
329 return 1; | 331 return 1; |
330 } | 332 } |
331 | 333 |
332 AudioBootStrap WINWAVEOUT_bootstrap = { | 334 AudioBootStrap WINWAVEOUT_bootstrap = { |