Mercurial > sdl-ios-xcode
comparison src/audio/windx5/SDL_dx5audio.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | d910939febfa |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
30 | 30 |
31 /* Define this if you want to use DirectX 6 DirectSoundNotify interface */ | 31 /* Define this if you want to use DirectX 6 DirectSoundNotify interface */ |
32 //#define USE_POSITION_NOTIFY | 32 //#define USE_POSITION_NOTIFY |
33 | 33 |
34 /* DirectX function pointers for audio */ | 34 /* DirectX function pointers for audio */ |
35 HRESULT (WINAPI *DSoundCreate)(LPGUID, LPDIRECTSOUND *, LPUNKNOWN); | 35 HRESULT (WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN); |
36 | 36 |
37 /* Audio driver functions */ | 37 /* Audio driver functions */ |
38 static int DX5_OpenAudio(_THIS, SDL_AudioSpec *spec); | 38 static int DX5_OpenAudio (_THIS, SDL_AudioSpec * spec); |
39 static void DX5_ThreadInit(_THIS); | 39 static void DX5_ThreadInit (_THIS); |
40 static void DX5_WaitAudio_BusyWait(_THIS); | 40 static void DX5_WaitAudio_BusyWait (_THIS); |
41 #ifdef USE_POSITION_NOTIFY | 41 #ifdef USE_POSITION_NOTIFY |
42 static void DX6_WaitAudio_EventWait(_THIS); | 42 static void DX6_WaitAudio_EventWait (_THIS); |
43 #endif | 43 #endif |
44 static void DX5_PlayAudio(_THIS); | 44 static void DX5_PlayAudio (_THIS); |
45 static Uint8 *DX5_GetAudioBuf(_THIS); | 45 static Uint8 *DX5_GetAudioBuf (_THIS); |
46 static void DX5_WaitDone(_THIS); | 46 static void DX5_WaitDone (_THIS); |
47 static void DX5_CloseAudio(_THIS); | 47 static void DX5_CloseAudio (_THIS); |
48 | 48 |
49 /* Audio driver bootstrap functions */ | 49 /* Audio driver bootstrap functions */ |
50 | 50 |
51 static int Audio_Available(void) | 51 static int |
52 { | 52 Audio_Available (void) |
53 HINSTANCE DSoundDLL; | 53 { |
54 int dsound_ok; | 54 HINSTANCE DSoundDLL; |
55 | 55 int dsound_ok; |
56 /* Version check DSOUND.DLL (Is DirectX okay?) */ | 56 |
57 dsound_ok = 0; | 57 /* Version check DSOUND.DLL (Is DirectX okay?) */ |
58 DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL")); | 58 dsound_ok = 0; |
59 if ( DSoundDLL != NULL ) { | 59 DSoundDLL = LoadLibrary (TEXT ("DSOUND.DLL")); |
60 /* We just use basic DirectSound, we're okay */ | 60 if (DSoundDLL != NULL) { |
61 /* Yay! */ | 61 /* We just use basic DirectSound, we're okay */ |
62 /* Unfortunately, the sound drivers on NT have | 62 /* Yay! */ |
63 higher latencies than the audio buffers used | 63 /* Unfortunately, the sound drivers on NT have |
64 by many SDL applications, so there are gaps | 64 higher latencies than the audio buffers used |
65 in the audio - it sounds terrible. Punt for now. | 65 by many SDL applications, so there are gaps |
66 */ | 66 in the audio - it sounds terrible. Punt for now. |
67 OSVERSIONINFO ver; | 67 */ |
68 ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); | 68 OSVERSIONINFO ver; |
69 GetVersionEx(&ver); | 69 ver.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); |
70 switch (ver.dwPlatformId) { | 70 GetVersionEx (&ver); |
71 case VER_PLATFORM_WIN32_NT: | 71 switch (ver.dwPlatformId) { |
72 if ( ver.dwMajorVersion > 4 ) { | 72 case VER_PLATFORM_WIN32_NT: |
73 /* Win2K */ | 73 if (ver.dwMajorVersion > 4) { |
74 dsound_ok = 1; | 74 /* Win2K */ |
75 } else { | 75 dsound_ok = 1; |
76 /* WinNT */ | 76 } else { |
77 dsound_ok = 0; | 77 /* WinNT */ |
78 } | 78 dsound_ok = 0; |
79 break; | 79 } |
80 default: | 80 break; |
81 /* Win95 or Win98 */ | 81 default: |
82 dsound_ok = 1; | 82 /* Win95 or Win98 */ |
83 break; | 83 dsound_ok = 1; |
84 } | 84 break; |
85 /* Now check for DirectX 5 or better - otherwise | 85 } |
86 * we will fail later in DX5_OpenAudio without a chance | 86 /* Now check for DirectX 5 or better - otherwise |
87 * to fall back to the DIB driver. */ | 87 * we will fail later in DX5_OpenAudio without a chance |
88 if (dsound_ok) { | 88 * to fall back to the DIB driver. */ |
89 /* DirectSoundCaptureCreate was added in DX5 */ | 89 if (dsound_ok) { |
90 if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate"))) | 90 /* DirectSoundCaptureCreate was added in DX5 */ |
91 dsound_ok = 0; | 91 if (!GetProcAddress |
92 | 92 (DSoundDLL, TEXT ("DirectSoundCaptureCreate"))) |
93 } | 93 dsound_ok = 0; |
94 /* Clean up.. */ | 94 |
95 FreeLibrary(DSoundDLL); | 95 } |
96 } | 96 /* Clean up.. */ |
97 return(dsound_ok); | 97 FreeLibrary (DSoundDLL); |
98 } | |
99 return (dsound_ok); | |
98 } | 100 } |
99 | 101 |
100 /* Functions for loading the DirectX functions dynamically */ | 102 /* Functions for loading the DirectX functions dynamically */ |
101 static HINSTANCE DSoundDLL = NULL; | 103 static HINSTANCE DSoundDLL = NULL; |
102 | 104 |
103 static void DX5_Unload(void) | 105 static void |
104 { | 106 DX5_Unload (void) |
105 if ( DSoundDLL != NULL ) { | 107 { |
106 FreeLibrary(DSoundDLL); | 108 if (DSoundDLL != NULL) { |
107 DSoundCreate = NULL; | 109 FreeLibrary (DSoundDLL); |
108 DSoundDLL = NULL; | 110 DSoundCreate = NULL; |
109 } | 111 DSoundDLL = NULL; |
110 } | 112 } |
111 static int DX5_Load(void) | 113 } |
112 { | 114 static int |
113 int status; | 115 DX5_Load (void) |
114 | 116 { |
115 DX5_Unload(); | 117 int status; |
116 DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL")); | 118 |
117 if ( DSoundDLL != NULL ) { | 119 DX5_Unload (); |
118 DSoundCreate = (void *)GetProcAddress(DSoundDLL, | 120 DSoundDLL = LoadLibrary (TEXT ("DSOUND.DLL")); |
119 TEXT("DirectSoundCreate")); | 121 if (DSoundDLL != NULL) { |
120 } | 122 DSoundCreate = (void *) GetProcAddress (DSoundDLL, |
121 if ( DSoundDLL && DSoundCreate ) { | 123 TEXT ("DirectSoundCreate")); |
122 status = 0; | 124 } |
123 } else { | 125 if (DSoundDLL && DSoundCreate) { |
124 DX5_Unload(); | 126 status = 0; |
125 status = -1; | 127 } else { |
126 } | 128 DX5_Unload (); |
127 return status; | 129 status = -1; |
128 } | 130 } |
129 | 131 return status; |
130 static void Audio_DeleteDevice(SDL_AudioDevice *device) | 132 } |
131 { | 133 |
132 DX5_Unload(); | 134 static void |
133 SDL_free(device->hidden); | 135 Audio_DeleteDevice (SDL_AudioDevice * device) |
134 SDL_free(device); | 136 { |
135 } | 137 DX5_Unload (); |
136 | 138 SDL_free (device->hidden); |
137 static SDL_AudioDevice *Audio_CreateDevice(int devindex) | 139 SDL_free (device); |
138 { | 140 } |
139 SDL_AudioDevice *this; | 141 |
140 | 142 static SDL_AudioDevice * |
141 /* Load DirectX */ | 143 Audio_CreateDevice (int devindex) |
142 if ( DX5_Load() < 0 ) { | 144 { |
143 return(NULL); | 145 SDL_AudioDevice *this; |
144 } | 146 |
145 | 147 /* Load DirectX */ |
146 /* Initialize all variables that we clean on shutdown */ | 148 if (DX5_Load () < 0) { |
147 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); | 149 return (NULL); |
148 if ( this ) { | 150 } |
149 SDL_memset(this, 0, (sizeof *this)); | 151 |
150 this->hidden = (struct SDL_PrivateAudioData *) | 152 /* Initialize all variables that we clean on shutdown */ |
151 SDL_malloc((sizeof *this->hidden)); | 153 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); |
152 } | 154 if (this) { |
153 if ( (this == NULL) || (this->hidden == NULL) ) { | 155 SDL_memset (this, 0, (sizeof *this)); |
154 SDL_OutOfMemory(); | 156 this->hidden = (struct SDL_PrivateAudioData *) |
155 if ( this ) { | 157 SDL_malloc ((sizeof *this->hidden)); |
156 SDL_free(this); | 158 } |
157 } | 159 if ((this == NULL) || (this->hidden == NULL)) { |
158 return(0); | 160 SDL_OutOfMemory (); |
159 } | 161 if (this) { |
160 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); | 162 SDL_free (this); |
161 | 163 } |
162 /* Set the function pointers */ | 164 return (0); |
163 this->OpenAudio = DX5_OpenAudio; | 165 } |
164 this->ThreadInit = DX5_ThreadInit; | 166 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); |
165 this->WaitAudio = DX5_WaitAudio_BusyWait; | 167 |
166 this->PlayAudio = DX5_PlayAudio; | 168 /* Set the function pointers */ |
167 this->GetAudioBuf = DX5_GetAudioBuf; | 169 this->OpenAudio = DX5_OpenAudio; |
168 this->WaitDone = DX5_WaitDone; | 170 this->ThreadInit = DX5_ThreadInit; |
169 this->CloseAudio = DX5_CloseAudio; | 171 this->WaitAudio = DX5_WaitAudio_BusyWait; |
170 | 172 this->PlayAudio = DX5_PlayAudio; |
171 this->free = Audio_DeleteDevice; | 173 this->GetAudioBuf = DX5_GetAudioBuf; |
172 | 174 this->WaitDone = DX5_WaitDone; |
173 return this; | 175 this->CloseAudio = DX5_CloseAudio; |
176 | |
177 this->free = Audio_DeleteDevice; | |
178 | |
179 return this; | |
174 } | 180 } |
175 | 181 |
176 AudioBootStrap DSOUND_bootstrap = { | 182 AudioBootStrap DSOUND_bootstrap = { |
177 "dsound", "Win95/98/2000 DirectSound", | 183 "dsound", "Win95/98/2000 DirectSound", |
178 Audio_Available, Audio_CreateDevice | 184 Audio_Available, Audio_CreateDevice |
179 }; | 185 }; |
180 | 186 |
181 static void SetDSerror(const char *function, int code) | 187 static void |
182 { | 188 SetDSerror (const char *function, int code) |
183 static const char *error; | 189 { |
184 static char errbuf[1024]; | 190 static const char *error; |
185 | 191 static char errbuf[1024]; |
186 errbuf[0] = 0; | 192 |
187 switch (code) { | 193 errbuf[0] = 0; |
188 case E_NOINTERFACE: | 194 switch (code) { |
189 error = | 195 case E_NOINTERFACE: |
190 "Unsupported interface\n-- Is DirectX 5.0 or later installed?"; | 196 error = |
191 break; | 197 "Unsupported interface\n-- Is DirectX 5.0 or later installed?"; |
192 case DSERR_ALLOCATED: | 198 break; |
193 error = "Audio device in use"; | 199 case DSERR_ALLOCATED: |
194 break; | 200 error = "Audio device in use"; |
195 case DSERR_BADFORMAT: | 201 break; |
196 error = "Unsupported audio format"; | 202 case DSERR_BADFORMAT: |
197 break; | 203 error = "Unsupported audio format"; |
198 case DSERR_BUFFERLOST: | 204 break; |
199 error = "Mixing buffer was lost"; | 205 case DSERR_BUFFERLOST: |
200 break; | 206 error = "Mixing buffer was lost"; |
201 case DSERR_CONTROLUNAVAIL: | 207 break; |
202 error = "Control requested is not available"; | 208 case DSERR_CONTROLUNAVAIL: |
203 break; | 209 error = "Control requested is not available"; |
204 case DSERR_INVALIDCALL: | 210 break; |
205 error = "Invalid call for the current state"; | 211 case DSERR_INVALIDCALL: |
206 break; | 212 error = "Invalid call for the current state"; |
207 case DSERR_INVALIDPARAM: | 213 break; |
208 error = "Invalid parameter"; | 214 case DSERR_INVALIDPARAM: |
209 break; | 215 error = "Invalid parameter"; |
210 case DSERR_NODRIVER: | 216 break; |
211 error = "No audio device found"; | 217 case DSERR_NODRIVER: |
212 break; | 218 error = "No audio device found"; |
213 case DSERR_OUTOFMEMORY: | 219 break; |
214 error = "Out of memory"; | 220 case DSERR_OUTOFMEMORY: |
215 break; | 221 error = "Out of memory"; |
216 case DSERR_PRIOLEVELNEEDED: | 222 break; |
217 error = "Caller doesn't have priority"; | 223 case DSERR_PRIOLEVELNEEDED: |
218 break; | 224 error = "Caller doesn't have priority"; |
219 case DSERR_UNSUPPORTED: | 225 break; |
220 error = "Function not supported"; | 226 case DSERR_UNSUPPORTED: |
221 break; | 227 error = "Function not supported"; |
222 default: | 228 break; |
223 SDL_snprintf(errbuf, SDL_arraysize(errbuf), | 229 default: |
224 "%s: Unknown DirectSound error: 0x%x", | 230 SDL_snprintf (errbuf, SDL_arraysize (errbuf), |
225 function, code); | 231 "%s: Unknown DirectSound error: 0x%x", function, code); |
226 break; | 232 break; |
227 } | 233 } |
228 if ( ! errbuf[0] ) { | 234 if (!errbuf[0]) { |
229 SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error); | 235 SDL_snprintf (errbuf, SDL_arraysize (errbuf), "%s: %s", function, |
230 } | 236 error); |
231 SDL_SetError("%s", errbuf); | 237 } |
232 return; | 238 SDL_SetError ("%s", errbuf); |
239 return; | |
233 } | 240 } |
234 | 241 |
235 /* DirectSound needs to be associated with a window */ | 242 /* DirectSound needs to be associated with a window */ |
236 static HWND mainwin = NULL; | 243 static HWND mainwin = NULL; |
237 /* */ | 244 /* */ |
238 void DX5_SoundFocus(HWND hwnd) | 245 void |
239 { | 246 DX5_SoundFocus (HWND hwnd) |
240 mainwin = hwnd; | 247 { |
241 } | 248 mainwin = hwnd; |
242 | 249 } |
243 static void DX5_ThreadInit(_THIS) | 250 |
244 { | 251 static void |
245 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); | 252 DX5_ThreadInit (_THIS) |
246 } | 253 { |
247 | 254 SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST); |
248 static void DX5_WaitAudio_BusyWait(_THIS) | 255 } |
249 { | 256 |
250 DWORD status; | 257 static void |
251 DWORD cursor, junk; | 258 DX5_WaitAudio_BusyWait (_THIS) |
252 HRESULT result; | 259 { |
253 | 260 DWORD status; |
254 /* Semi-busy wait, since we have no way of getting play notification | 261 DWORD cursor, junk; |
255 on a primary mixing buffer located in hardware (DirectX 5.0) | 262 HRESULT result; |
256 */ | 263 |
257 result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk); | 264 /* Semi-busy wait, since we have no way of getting play notification |
258 if ( result != DS_OK ) { | 265 on a primary mixing buffer located in hardware (DirectX 5.0) |
259 if ( result == DSERR_BUFFERLOST ) { | 266 */ |
260 IDirectSoundBuffer_Restore(mixbuf); | 267 result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, &cursor, &junk); |
261 } | 268 if (result != DS_OK) { |
262 #ifdef DEBUG_SOUND | 269 if (result == DSERR_BUFFERLOST) { |
263 SetDSerror("DirectSound GetCurrentPosition", result); | 270 IDirectSoundBuffer_Restore (mixbuf); |
264 #endif | 271 } |
265 return; | 272 #ifdef DEBUG_SOUND |
266 } | 273 SetDSerror ("DirectSound GetCurrentPosition", result); |
267 cursor /= mixlen; | 274 #endif |
268 | 275 return; |
269 while ( cursor == playing ) { | 276 } |
270 /* FIXME: find out how much time is left and sleep that long */ | 277 cursor /= mixlen; |
271 SDL_Delay(10); | 278 |
272 | 279 while (cursor == playing) { |
273 /* Try to restore a lost sound buffer */ | 280 /* FIXME: find out how much time is left and sleep that long */ |
274 IDirectSoundBuffer_GetStatus(mixbuf, &status); | 281 SDL_Delay (10); |
275 if ( (status&DSBSTATUS_BUFFERLOST) ) { | 282 |
276 IDirectSoundBuffer_Restore(mixbuf); | 283 /* Try to restore a lost sound buffer */ |
277 IDirectSoundBuffer_GetStatus(mixbuf, &status); | 284 IDirectSoundBuffer_GetStatus (mixbuf, &status); |
278 if ( (status&DSBSTATUS_BUFFERLOST) ) { | 285 if ((status & DSBSTATUS_BUFFERLOST)) { |
279 break; | 286 IDirectSoundBuffer_Restore (mixbuf); |
280 } | 287 IDirectSoundBuffer_GetStatus (mixbuf, &status); |
281 } | 288 if ((status & DSBSTATUS_BUFFERLOST)) { |
282 if ( ! (status&DSBSTATUS_PLAYING) ) { | 289 break; |
283 result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING); | 290 } |
284 if ( result == DS_OK ) { | 291 } |
285 continue; | 292 if (!(status & DSBSTATUS_PLAYING)) { |
286 } | 293 result = IDirectSoundBuffer_Play (mixbuf, 0, 0, DSBPLAY_LOOPING); |
287 #ifdef DEBUG_SOUND | 294 if (result == DS_OK) { |
288 SetDSerror("DirectSound Play", result); | 295 continue; |
289 #endif | 296 } |
290 return; | 297 #ifdef DEBUG_SOUND |
291 } | 298 SetDSerror ("DirectSound Play", result); |
292 | 299 #endif |
293 /* Find out where we are playing */ | 300 return; |
294 result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, | 301 } |
295 &cursor, &junk); | 302 |
296 if ( result != DS_OK ) { | 303 /* Find out where we are playing */ |
297 SetDSerror("DirectSound GetCurrentPosition", result); | 304 result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, |
298 return; | 305 &cursor, &junk); |
299 } | 306 if (result != DS_OK) { |
300 cursor /= mixlen; | 307 SetDSerror ("DirectSound GetCurrentPosition", result); |
301 } | 308 return; |
309 } | |
310 cursor /= mixlen; | |
311 } | |
302 } | 312 } |
303 | 313 |
304 #ifdef USE_POSITION_NOTIFY | 314 #ifdef USE_POSITION_NOTIFY |
305 static void DX6_WaitAudio_EventWait(_THIS) | 315 static void |
306 { | 316 DX6_WaitAudio_EventWait (_THIS) |
307 DWORD status; | 317 { |
308 HRESULT result; | 318 DWORD status; |
309 | 319 HRESULT result; |
310 /* Try to restore a lost sound buffer */ | 320 |
311 IDirectSoundBuffer_GetStatus(mixbuf, &status); | 321 /* Try to restore a lost sound buffer */ |
312 if ( (status&DSBSTATUS_BUFFERLOST) ) { | 322 IDirectSoundBuffer_GetStatus (mixbuf, &status); |
313 IDirectSoundBuffer_Restore(mixbuf); | 323 if ((status & DSBSTATUS_BUFFERLOST)) { |
314 IDirectSoundBuffer_GetStatus(mixbuf, &status); | 324 IDirectSoundBuffer_Restore (mixbuf); |
315 if ( (status&DSBSTATUS_BUFFERLOST) ) { | 325 IDirectSoundBuffer_GetStatus (mixbuf, &status); |
316 return; | 326 if ((status & DSBSTATUS_BUFFERLOST)) { |
317 } | 327 return; |
318 } | 328 } |
319 if ( ! (status&DSBSTATUS_PLAYING) ) { | 329 } |
320 result = IDirectSoundBuffer_Play(mixbuf, 0, 0, DSBPLAY_LOOPING); | 330 if (!(status & DSBSTATUS_PLAYING)) { |
321 if ( result != DS_OK ) { | 331 result = IDirectSoundBuffer_Play (mixbuf, 0, 0, DSBPLAY_LOOPING); |
322 #ifdef DEBUG_SOUND | 332 if (result != DS_OK) { |
323 SetDSerror("DirectSound Play", result); | 333 #ifdef DEBUG_SOUND |
324 #endif | 334 SetDSerror ("DirectSound Play", result); |
325 return; | 335 #endif |
326 } | 336 return; |
327 } | 337 } |
328 WaitForSingleObject(audio_event, INFINITE); | 338 } |
339 WaitForSingleObject (audio_event, INFINITE); | |
329 } | 340 } |
330 #endif /* USE_POSITION_NOTIFY */ | 341 #endif /* USE_POSITION_NOTIFY */ |
331 | 342 |
332 static void DX5_PlayAudio(_THIS) | 343 static void |
333 { | 344 DX5_PlayAudio (_THIS) |
334 /* Unlock the buffer, allowing it to play */ | 345 { |
335 if ( locked_buf ) { | 346 /* Unlock the buffer, allowing it to play */ |
336 IDirectSoundBuffer_Unlock(mixbuf, locked_buf, mixlen, NULL, 0); | 347 if (locked_buf) { |
337 } | 348 IDirectSoundBuffer_Unlock (mixbuf, locked_buf, mixlen, NULL, 0); |
338 | 349 } |
339 } | 350 |
340 | 351 } |
341 static Uint8 *DX5_GetAudioBuf(_THIS) | 352 |
342 { | 353 static Uint8 * |
343 DWORD cursor, junk; | 354 DX5_GetAudioBuf (_THIS) |
344 HRESULT result; | 355 { |
345 DWORD rawlen; | 356 DWORD cursor, junk; |
346 | 357 HRESULT result; |
347 /* Figure out which blocks to fill next */ | 358 DWORD rawlen; |
348 locked_buf = NULL; | 359 |
349 result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, &cursor, &junk); | 360 /* Figure out which blocks to fill next */ |
350 if ( result == DSERR_BUFFERLOST ) { | 361 locked_buf = NULL; |
351 IDirectSoundBuffer_Restore(mixbuf); | 362 result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, &cursor, &junk); |
352 result = IDirectSoundBuffer_GetCurrentPosition(mixbuf, | 363 if (result == DSERR_BUFFERLOST) { |
353 &cursor, &junk); | 364 IDirectSoundBuffer_Restore (mixbuf); |
354 } | 365 result = IDirectSoundBuffer_GetCurrentPosition (mixbuf, |
355 if ( result != DS_OK ) { | 366 &cursor, &junk); |
356 SetDSerror("DirectSound GetCurrentPosition", result); | 367 } |
357 return(NULL); | 368 if (result != DS_OK) { |
358 } | 369 SetDSerror ("DirectSound GetCurrentPosition", result); |
359 cursor /= mixlen; | 370 return (NULL); |
360 playing = cursor; | 371 } |
361 cursor = (cursor+1)%NUM_BUFFERS; | 372 cursor /= mixlen; |
362 cursor *= mixlen; | 373 playing = cursor; |
363 | 374 cursor = (cursor + 1) % NUM_BUFFERS; |
364 /* Lock the audio buffer */ | 375 cursor *= mixlen; |
365 result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen, | 376 |
366 (LPVOID *)&locked_buf, &rawlen, NULL, &junk, 0); | 377 /* Lock the audio buffer */ |
367 if ( result == DSERR_BUFFERLOST ) { | 378 result = IDirectSoundBuffer_Lock (mixbuf, cursor, mixlen, |
368 IDirectSoundBuffer_Restore(mixbuf); | 379 (LPVOID *) & locked_buf, &rawlen, NULL, |
369 result = IDirectSoundBuffer_Lock(mixbuf, cursor, mixlen, | 380 &junk, 0); |
370 (LPVOID *)&locked_buf, &rawlen, NULL, &junk, 0); | 381 if (result == DSERR_BUFFERLOST) { |
371 } | 382 IDirectSoundBuffer_Restore (mixbuf); |
372 if ( result != DS_OK ) { | 383 result = IDirectSoundBuffer_Lock (mixbuf, cursor, mixlen, |
373 SetDSerror("DirectSound Lock", result); | 384 (LPVOID *) & locked_buf, &rawlen, |
374 return(NULL); | 385 NULL, &junk, 0); |
375 } | 386 } |
376 return(locked_buf); | 387 if (result != DS_OK) { |
377 } | 388 SetDSerror ("DirectSound Lock", result); |
378 | 389 return (NULL); |
379 static void DX5_WaitDone(_THIS) | 390 } |
380 { | 391 return (locked_buf); |
381 Uint8 *stream; | 392 } |
382 | 393 |
383 /* Wait for the playing chunk to finish */ | 394 static void |
384 stream = this->GetAudioBuf(this); | 395 DX5_WaitDone (_THIS) |
385 if ( stream != NULL ) { | 396 { |
386 SDL_memset(stream, silence, mixlen); | 397 Uint8 *stream; |
387 this->PlayAudio(this); | 398 |
388 } | 399 /* Wait for the playing chunk to finish */ |
389 this->WaitAudio(this); | 400 stream = this->GetAudioBuf (this); |
390 | 401 if (stream != NULL) { |
391 /* Stop the looping sound buffer */ | 402 SDL_memset (stream, silence, mixlen); |
392 IDirectSoundBuffer_Stop(mixbuf); | 403 this->PlayAudio (this); |
393 } | 404 } |
394 | 405 this->WaitAudio (this); |
395 static void DX5_CloseAudio(_THIS) | 406 |
396 { | 407 /* Stop the looping sound buffer */ |
397 if ( sound != NULL ) { | 408 IDirectSoundBuffer_Stop (mixbuf); |
398 if ( mixbuf != NULL ) { | 409 } |
399 /* Clean up the audio buffer */ | 410 |
400 IDirectSoundBuffer_Release(mixbuf); | 411 static void |
401 mixbuf = NULL; | 412 DX5_CloseAudio (_THIS) |
402 } | 413 { |
403 if ( audio_event != NULL ) { | 414 if (sound != NULL) { |
404 CloseHandle(audio_event); | 415 if (mixbuf != NULL) { |
405 audio_event = NULL; | 416 /* Clean up the audio buffer */ |
406 } | 417 IDirectSoundBuffer_Release (mixbuf); |
407 IDirectSound_Release(sound); | 418 mixbuf = NULL; |
408 sound = NULL; | 419 } |
409 } | 420 if (audio_event != NULL) { |
421 CloseHandle (audio_event); | |
422 audio_event = NULL; | |
423 } | |
424 IDirectSound_Release (sound); | |
425 sound = NULL; | |
426 } | |
410 } | 427 } |
411 | 428 |
412 #ifdef USE_PRIMARY_BUFFER | 429 #ifdef USE_PRIMARY_BUFFER |
413 /* This function tries to create a primary audio buffer, and returns the | 430 /* This function tries to create a primary audio buffer, and returns the |
414 number of audio chunks available in the created buffer. | 431 number of audio chunks available in the created buffer. |
415 */ | 432 */ |
416 static int CreatePrimary(LPDIRECTSOUND sndObj, HWND focus, | 433 static int |
417 LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize) | 434 CreatePrimary (LPDIRECTSOUND sndObj, HWND focus, |
418 { | 435 LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt, |
419 HRESULT result; | 436 Uint32 chunksize) |
420 DSBUFFERDESC format; | 437 { |
421 DSBCAPS caps; | 438 HRESULT result; |
422 int numchunks; | 439 DSBUFFERDESC format; |
423 | 440 DSBCAPS caps; |
424 /* Try to set primary mixing privileges */ | 441 int numchunks; |
425 result = IDirectSound_SetCooperativeLevel(sndObj, focus, | 442 |
426 DSSCL_WRITEPRIMARY); | 443 /* Try to set primary mixing privileges */ |
427 if ( result != DS_OK ) { | 444 result = IDirectSound_SetCooperativeLevel (sndObj, focus, |
428 #ifdef DEBUG_SOUND | 445 DSSCL_WRITEPRIMARY); |
429 SetDSerror("DirectSound SetCooperativeLevel", result); | 446 if (result != DS_OK) { |
430 #endif | 447 #ifdef DEBUG_SOUND |
431 return(-1); | 448 SetDSerror ("DirectSound SetCooperativeLevel", result); |
432 } | 449 #endif |
433 | 450 return (-1); |
434 /* Try to create the primary buffer */ | 451 } |
435 SDL_memset(&format, 0, sizeof(format)); | 452 |
436 format.dwSize = sizeof(format); | 453 /* Try to create the primary buffer */ |
437 format.dwFlags=(DSBCAPS_PRIMARYBUFFER|DSBCAPS_GETCURRENTPOSITION2); | 454 SDL_memset (&format, 0, sizeof (format)); |
438 format.dwFlags |= DSBCAPS_STICKYFOCUS; | 455 format.dwSize = sizeof (format); |
456 format.dwFlags = (DSBCAPS_PRIMARYBUFFER | DSBCAPS_GETCURRENTPOSITION2); | |
457 format.dwFlags |= DSBCAPS_STICKYFOCUS; | |
439 #ifdef USE_POSITION_NOTIFY | 458 #ifdef USE_POSITION_NOTIFY |
440 format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY; | 459 format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY; |
441 #endif | 460 #endif |
442 result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL); | 461 result = IDirectSound_CreateSoundBuffer (sndObj, &format, sndbuf, NULL); |
443 if ( result != DS_OK ) { | 462 if (result != DS_OK) { |
444 #ifdef DEBUG_SOUND | 463 #ifdef DEBUG_SOUND |
445 SetDSerror("DirectSound CreateSoundBuffer", result); | 464 SetDSerror ("DirectSound CreateSoundBuffer", result); |
446 #endif | 465 #endif |
447 return(-1); | 466 return (-1); |
448 } | 467 } |
449 | 468 |
450 /* Check the size of the fragment buffer */ | 469 /* Check the size of the fragment buffer */ |
451 SDL_memset(&caps, 0, sizeof(caps)); | 470 SDL_memset (&caps, 0, sizeof (caps)); |
452 caps.dwSize = sizeof(caps); | 471 caps.dwSize = sizeof (caps); |
453 result = IDirectSoundBuffer_GetCaps(*sndbuf, &caps); | 472 result = IDirectSoundBuffer_GetCaps (*sndbuf, &caps); |
454 if ( result != DS_OK ) { | 473 if (result != DS_OK) { |
455 #ifdef DEBUG_SOUND | 474 #ifdef DEBUG_SOUND |
456 SetDSerror("DirectSound GetCaps", result); | 475 SetDSerror ("DirectSound GetCaps", result); |
457 #endif | 476 #endif |
458 IDirectSoundBuffer_Release(*sndbuf); | 477 IDirectSoundBuffer_Release (*sndbuf); |
459 return(-1); | 478 return (-1); |
460 } | 479 } |
461 if ( (chunksize > caps.dwBufferBytes) || | 480 if ((chunksize > caps.dwBufferBytes) || |
462 ((caps.dwBufferBytes%chunksize) != 0) ) { | 481 ((caps.dwBufferBytes % chunksize) != 0)) { |
463 /* The primary buffer size is not a multiple of 'chunksize' | 482 /* The primary buffer size is not a multiple of 'chunksize' |
464 -- this hopefully doesn't happen when 'chunksize' is a | 483 -- this hopefully doesn't happen when 'chunksize' is a |
465 power of 2. | 484 power of 2. |
466 */ | 485 */ |
467 IDirectSoundBuffer_Release(*sndbuf); | 486 IDirectSoundBuffer_Release (*sndbuf); |
468 SDL_SetError( | 487 SDL_SetError |
469 "Primary buffer size is: %d, cannot break it into chunks of %d bytes\n", | 488 ("Primary buffer size is: %d, cannot break it into chunks of %d bytes\n", |
470 caps.dwBufferBytes, chunksize); | 489 caps.dwBufferBytes, chunksize); |
471 return(-1); | 490 return (-1); |
472 } | 491 } |
473 numchunks = (caps.dwBufferBytes/chunksize); | 492 numchunks = (caps.dwBufferBytes / chunksize); |
474 | 493 |
475 /* Set the primary audio format */ | 494 /* Set the primary audio format */ |
476 result = IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt); | 495 result = IDirectSoundBuffer_SetFormat (*sndbuf, wavefmt); |
477 if ( result != DS_OK ) { | 496 if (result != DS_OK) { |
478 #ifdef DEBUG_SOUND | 497 #ifdef DEBUG_SOUND |
479 SetDSerror("DirectSound SetFormat", result); | 498 SetDSerror ("DirectSound SetFormat", result); |
480 #endif | 499 #endif |
481 IDirectSoundBuffer_Release(*sndbuf); | 500 IDirectSoundBuffer_Release (*sndbuf); |
482 return(-1); | 501 return (-1); |
483 } | 502 } |
484 return(numchunks); | 503 return (numchunks); |
485 } | 504 } |
486 #endif /* USE_PRIMARY_BUFFER */ | 505 #endif /* USE_PRIMARY_BUFFER */ |
487 | 506 |
488 /* This function tries to create a secondary audio buffer, and returns the | 507 /* This function tries to create a secondary audio buffer, and returns the |
489 number of audio chunks available in the created buffer. | 508 number of audio chunks available in the created buffer. |
490 */ | 509 */ |
491 static int CreateSecondary(LPDIRECTSOUND sndObj, HWND focus, | 510 static int |
492 LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize) | 511 CreateSecondary (LPDIRECTSOUND sndObj, HWND focus, |
493 { | 512 LPDIRECTSOUNDBUFFER * sndbuf, WAVEFORMATEX * wavefmt, |
494 const int numchunks = 2; | 513 Uint32 chunksize) |
495 HRESULT result; | 514 { |
496 DSBUFFERDESC format; | 515 const int numchunks = 2; |
497 LPVOID pvAudioPtr1, pvAudioPtr2; | 516 HRESULT result; |
498 DWORD dwAudioBytes1, dwAudioBytes2; | 517 DSBUFFERDESC format; |
499 | 518 LPVOID pvAudioPtr1, pvAudioPtr2; |
500 /* Try to set primary mixing privileges */ | 519 DWORD dwAudioBytes1, dwAudioBytes2; |
501 if ( focus ) { | 520 |
502 result = IDirectSound_SetCooperativeLevel(sndObj, | 521 /* Try to set primary mixing privileges */ |
503 focus, DSSCL_PRIORITY); | 522 if (focus) { |
504 } else { | 523 result = IDirectSound_SetCooperativeLevel (sndObj, |
505 result = IDirectSound_SetCooperativeLevel(sndObj, | 524 focus, DSSCL_PRIORITY); |
506 GetDesktopWindow(), DSSCL_NORMAL); | 525 } else { |
507 } | 526 result = IDirectSound_SetCooperativeLevel (sndObj, |
508 if ( result != DS_OK ) { | 527 GetDesktopWindow (), |
509 #ifdef DEBUG_SOUND | 528 DSSCL_NORMAL); |
510 SetDSerror("DirectSound SetCooperativeLevel", result); | 529 } |
511 #endif | 530 if (result != DS_OK) { |
512 return(-1); | 531 #ifdef DEBUG_SOUND |
513 } | 532 SetDSerror ("DirectSound SetCooperativeLevel", result); |
514 | 533 #endif |
515 /* Try to create the secondary buffer */ | 534 return (-1); |
516 SDL_memset(&format, 0, sizeof(format)); | 535 } |
517 format.dwSize = sizeof(format); | 536 |
518 format.dwFlags = DSBCAPS_GETCURRENTPOSITION2; | 537 /* Try to create the secondary buffer */ |
538 SDL_memset (&format, 0, sizeof (format)); | |
539 format.dwSize = sizeof (format); | |
540 format.dwFlags = DSBCAPS_GETCURRENTPOSITION2; | |
519 #ifdef USE_POSITION_NOTIFY | 541 #ifdef USE_POSITION_NOTIFY |
520 format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY; | 542 format.dwFlags |= DSBCAPS_CTRLPOSITIONNOTIFY; |
521 #endif | 543 #endif |
522 if ( ! focus ) { | 544 if (!focus) { |
523 format.dwFlags |= DSBCAPS_GLOBALFOCUS; | 545 format.dwFlags |= DSBCAPS_GLOBALFOCUS; |
524 } else { | 546 } else { |
525 format.dwFlags |= DSBCAPS_STICKYFOCUS; | 547 format.dwFlags |= DSBCAPS_STICKYFOCUS; |
526 } | 548 } |
527 format.dwBufferBytes = numchunks*chunksize; | 549 format.dwBufferBytes = numchunks * chunksize; |
528 if ( (format.dwBufferBytes < DSBSIZE_MIN) || | 550 if ((format.dwBufferBytes < DSBSIZE_MIN) || |
529 (format.dwBufferBytes > DSBSIZE_MAX) ) { | 551 (format.dwBufferBytes > DSBSIZE_MAX)) { |
530 SDL_SetError("Sound buffer size must be between %d and %d", | 552 SDL_SetError ("Sound buffer size must be between %d and %d", |
531 DSBSIZE_MIN/numchunks, DSBSIZE_MAX/numchunks); | 553 DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks); |
532 return(-1); | 554 return (-1); |
533 } | 555 } |
534 format.dwReserved = 0; | 556 format.dwReserved = 0; |
535 format.lpwfxFormat = wavefmt; | 557 format.lpwfxFormat = wavefmt; |
536 result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL); | 558 result = IDirectSound_CreateSoundBuffer (sndObj, &format, sndbuf, NULL); |
537 if ( result != DS_OK ) { | 559 if (result != DS_OK) { |
538 SetDSerror("DirectSound CreateSoundBuffer", result); | 560 SetDSerror ("DirectSound CreateSoundBuffer", result); |
539 return(-1); | 561 return (-1); |
540 } | 562 } |
541 IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt); | 563 IDirectSoundBuffer_SetFormat (*sndbuf, wavefmt); |
542 | 564 |
543 /* Silence the initial audio buffer */ | 565 /* Silence the initial audio buffer */ |
544 result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes, | 566 result = IDirectSoundBuffer_Lock (*sndbuf, 0, format.dwBufferBytes, |
545 (LPVOID *)&pvAudioPtr1, &dwAudioBytes1, | 567 (LPVOID *) & pvAudioPtr1, |
546 (LPVOID *)&pvAudioPtr2, &dwAudioBytes2, | 568 &dwAudioBytes1, |
547 DSBLOCK_ENTIREBUFFER); | 569 (LPVOID *) & pvAudioPtr2, |
548 if ( result == DS_OK ) { | 570 &dwAudioBytes2, DSBLOCK_ENTIREBUFFER); |
549 if ( wavefmt->wBitsPerSample == 8 ) { | 571 if (result == DS_OK) { |
550 SDL_memset(pvAudioPtr1, 0x80, dwAudioBytes1); | 572 if (wavefmt->wBitsPerSample == 8) { |
551 } else { | 573 SDL_memset (pvAudioPtr1, 0x80, dwAudioBytes1); |
552 SDL_memset(pvAudioPtr1, 0x00, dwAudioBytes1); | 574 } else { |
553 } | 575 SDL_memset (pvAudioPtr1, 0x00, dwAudioBytes1); |
554 IDirectSoundBuffer_Unlock(*sndbuf, | 576 } |
555 (LPVOID)pvAudioPtr1, dwAudioBytes1, | 577 IDirectSoundBuffer_Unlock (*sndbuf, |
556 (LPVOID)pvAudioPtr2, dwAudioBytes2); | 578 (LPVOID) pvAudioPtr1, dwAudioBytes1, |
557 } | 579 (LPVOID) pvAudioPtr2, dwAudioBytes2); |
558 | 580 } |
559 /* We're ready to go */ | 581 |
560 return(numchunks); | 582 /* We're ready to go */ |
583 return (numchunks); | |
561 } | 584 } |
562 | 585 |
563 /* This function tries to set position notify events on the mixing buffer */ | 586 /* This function tries to set position notify events on the mixing buffer */ |
564 #ifdef USE_POSITION_NOTIFY | 587 #ifdef USE_POSITION_NOTIFY |
565 static int CreateAudioEvent(_THIS) | 588 static int |
566 { | 589 CreateAudioEvent (_THIS) |
567 LPDIRECTSOUNDNOTIFY notify; | 590 { |
568 DSBPOSITIONNOTIFY *notify_positions; | 591 LPDIRECTSOUNDNOTIFY notify; |
569 int i, retval; | 592 DSBPOSITIONNOTIFY *notify_positions; |
570 HRESULT result; | 593 int i, retval; |
571 | 594 HRESULT result; |
572 /* Default to fail on exit */ | 595 |
573 retval = -1; | 596 /* Default to fail on exit */ |
574 notify = NULL; | 597 retval = -1; |
575 | 598 notify = NULL; |
576 /* Query for the interface */ | 599 |
577 result = IDirectSoundBuffer_QueryInterface(mixbuf, | 600 /* Query for the interface */ |
578 &IID_IDirectSoundNotify, (void *)¬ify); | 601 result = IDirectSoundBuffer_QueryInterface (mixbuf, |
579 if ( result != DS_OK ) { | 602 &IID_IDirectSoundNotify, |
580 goto done; | 603 (void *) ¬ify); |
581 } | 604 if (result != DS_OK) { |
582 | 605 goto done; |
583 /* Allocate the notify structures */ | 606 } |
584 notify_positions = (DSBPOSITIONNOTIFY *)SDL_malloc(NUM_BUFFERS* | 607 |
585 sizeof(*notify_positions)); | 608 /* Allocate the notify structures */ |
586 if ( notify_positions == NULL ) { | 609 notify_positions = (DSBPOSITIONNOTIFY *) SDL_malloc (NUM_BUFFERS * |
587 goto done; | 610 sizeof |
588 } | 611 (*notify_positions)); |
589 | 612 if (notify_positions == NULL) { |
590 /* Create the notify event */ | 613 goto done; |
591 audio_event = CreateEvent(NULL, FALSE, FALSE, NULL); | 614 } |
592 if ( audio_event == NULL ) { | 615 |
593 goto done; | 616 /* Create the notify event */ |
594 } | 617 audio_event = CreateEvent (NULL, FALSE, FALSE, NULL); |
595 | 618 if (audio_event == NULL) { |
596 /* Set up the notify structures */ | 619 goto done; |
597 for ( i=0; i<NUM_BUFFERS; ++i ) { | 620 } |
598 notify_positions[i].dwOffset = i*mixlen; | 621 |
599 notify_positions[i].hEventNotify = audio_event; | 622 /* Set up the notify structures */ |
600 } | 623 for (i = 0; i < NUM_BUFFERS; ++i) { |
601 result = IDirectSoundNotify_SetNotificationPositions(notify, | 624 notify_positions[i].dwOffset = i * mixlen; |
602 NUM_BUFFERS, notify_positions); | 625 notify_positions[i].hEventNotify = audio_event; |
603 if ( result == DS_OK ) { | 626 } |
604 retval = 0; | 627 result = IDirectSoundNotify_SetNotificationPositions (notify, |
605 } | 628 NUM_BUFFERS, |
606 done: | 629 notify_positions); |
607 if ( notify != NULL ) { | 630 if (result == DS_OK) { |
608 IDirectSoundNotify_Release(notify); | 631 retval = 0; |
609 } | 632 } |
610 return(retval); | 633 done: |
634 if (notify != NULL) { | |
635 IDirectSoundNotify_Release (notify); | |
636 } | |
637 return (retval); | |
611 } | 638 } |
612 #endif /* USE_POSITION_NOTIFY */ | 639 #endif /* USE_POSITION_NOTIFY */ |
613 | 640 |
614 static int DX5_OpenAudio(_THIS, SDL_AudioSpec *spec) | 641 static int |
615 { | 642 DX5_OpenAudio (_THIS, SDL_AudioSpec * spec) |
616 HRESULT result; | 643 { |
617 WAVEFORMATEX waveformat; | 644 HRESULT result; |
618 | 645 WAVEFORMATEX waveformat; |
619 /* Set basic WAVE format parameters */ | 646 |
620 SDL_memset(&waveformat, 0, sizeof(waveformat)); | 647 /* Set basic WAVE format parameters */ |
621 waveformat.wFormatTag = WAVE_FORMAT_PCM; | 648 SDL_memset (&waveformat, 0, sizeof (waveformat)); |
622 | 649 waveformat.wFormatTag = WAVE_FORMAT_PCM; |
623 /* Determine the audio parameters from the AudioSpec */ | 650 |
624 switch ( spec->format & 0xFF ) { | 651 /* Determine the audio parameters from the AudioSpec */ |
625 case 8: | 652 switch (spec->format & 0xFF) { |
626 /* Unsigned 8 bit audio data */ | 653 case 8: |
627 spec->format = AUDIO_U8; | 654 /* Unsigned 8 bit audio data */ |
628 silence = 0x80; | 655 spec->format = AUDIO_U8; |
629 waveformat.wBitsPerSample = 8; | 656 silence = 0x80; |
630 break; | 657 waveformat.wBitsPerSample = 8; |
631 case 16: | 658 break; |
632 /* Signed 16 bit audio data */ | 659 case 16: |
633 spec->format = AUDIO_S16; | 660 /* Signed 16 bit audio data */ |
634 silence = 0x00; | 661 spec->format = AUDIO_S16; |
635 waveformat.wBitsPerSample = 16; | 662 silence = 0x00; |
636 break; | 663 waveformat.wBitsPerSample = 16; |
637 default: | 664 break; |
638 SDL_SetError("Unsupported audio format"); | 665 default: |
639 return(-1); | 666 SDL_SetError ("Unsupported audio format"); |
640 } | 667 return (-1); |
641 waveformat.nChannels = spec->channels; | 668 } |
642 waveformat.nSamplesPerSec = spec->freq; | 669 waveformat.nChannels = spec->channels; |
643 waveformat.nBlockAlign = | 670 waveformat.nSamplesPerSec = spec->freq; |
644 waveformat.nChannels * (waveformat.wBitsPerSample/8); | 671 waveformat.nBlockAlign = |
645 waveformat.nAvgBytesPerSec = | 672 waveformat.nChannels * (waveformat.wBitsPerSample / 8); |
646 waveformat.nSamplesPerSec * waveformat.nBlockAlign; | 673 waveformat.nAvgBytesPerSec = |
647 | 674 waveformat.nSamplesPerSec * waveformat.nBlockAlign; |
648 /* Update the fragment size as size in bytes */ | 675 |
649 SDL_CalculateAudioSpec(spec); | 676 /* Update the fragment size as size in bytes */ |
650 | 677 SDL_CalculateAudioSpec (spec); |
651 /* Open the audio device */ | 678 |
652 result = DSoundCreate(NULL, &sound, NULL); | 679 /* Open the audio device */ |
653 if ( result != DS_OK ) { | 680 result = DSoundCreate (NULL, &sound, NULL); |
654 SetDSerror("DirectSoundCreate", result); | 681 if (result != DS_OK) { |
655 return(-1); | 682 SetDSerror ("DirectSoundCreate", result); |
656 } | 683 return (-1); |
657 | 684 } |
658 /* Create the audio buffer to which we write */ | 685 |
659 NUM_BUFFERS = -1; | 686 /* Create the audio buffer to which we write */ |
687 NUM_BUFFERS = -1; | |
660 #ifdef USE_PRIMARY_BUFFER | 688 #ifdef USE_PRIMARY_BUFFER |
661 if ( mainwin ) { | 689 if (mainwin) { |
662 NUM_BUFFERS = CreatePrimary(sound, mainwin, &mixbuf, | 690 NUM_BUFFERS = CreatePrimary (sound, mainwin, &mixbuf, |
663 &waveformat, spec->size); | 691 &waveformat, spec->size); |
664 } | 692 } |
665 #endif /* USE_PRIMARY_BUFFER */ | 693 #endif /* USE_PRIMARY_BUFFER */ |
666 if ( NUM_BUFFERS < 0 ) { | 694 if (NUM_BUFFERS < 0) { |
667 NUM_BUFFERS = CreateSecondary(sound, mainwin, &mixbuf, | 695 NUM_BUFFERS = CreateSecondary (sound, mainwin, &mixbuf, |
668 &waveformat, spec->size); | 696 &waveformat, spec->size); |
669 if ( NUM_BUFFERS < 0 ) { | 697 if (NUM_BUFFERS < 0) { |
670 return(-1); | 698 return (-1); |
671 } | 699 } |
672 #ifdef DEBUG_SOUND | 700 #ifdef DEBUG_SOUND |
673 fprintf(stderr, "Using secondary audio buffer\n"); | 701 fprintf (stderr, "Using secondary audio buffer\n"); |
674 #endif | 702 #endif |
675 } | 703 } |
676 #ifdef DEBUG_SOUND | 704 #ifdef DEBUG_SOUND |
677 else | 705 else |
678 fprintf(stderr, "Using primary audio buffer\n"); | 706 fprintf (stderr, "Using primary audio buffer\n"); |
679 #endif | 707 #endif |
680 | 708 |
681 /* The buffer will auto-start playing in DX5_WaitAudio() */ | 709 /* The buffer will auto-start playing in DX5_WaitAudio() */ |
682 playing = 0; | 710 playing = 0; |
683 mixlen = spec->size; | 711 mixlen = spec->size; |
684 | 712 |
685 #ifdef USE_POSITION_NOTIFY | 713 #ifdef USE_POSITION_NOTIFY |
686 /* See if we can use DirectX 6 event notification */ | 714 /* See if we can use DirectX 6 event notification */ |
687 if ( CreateAudioEvent(this) == 0 ) { | 715 if (CreateAudioEvent (this) == 0) { |
688 this->WaitAudio = DX6_WaitAudio_EventWait; | 716 this->WaitAudio = DX6_WaitAudio_EventWait; |
689 } else { | 717 } else { |
690 this->WaitAudio = DX5_WaitAudio_BusyWait; | 718 this->WaitAudio = DX5_WaitAudio_BusyWait; |
691 } | 719 } |
692 #endif | 720 #endif |
693 return(0); | 721 return (0); |
694 } | 722 } |
695 | 723 |
724 /* vi: set ts=4 sw=4 expandtab: */ |