Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
517 lines (453 loc) · 15.4 KB

SDL_dx5audio.c

File metadata and controls

517 lines (453 loc) · 15.4 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
25
26
27
/* Allow access to a raw mixing buffer */
#include "SDL_timer.h"
#include "SDL_audio.h"
Feb 16, 2006
Feb 16, 2006
28
#include "../SDL_audio_c.h"
Apr 26, 2001
Apr 26, 2001
29
30
#include "SDL_dx5audio.h"
Oct 17, 2006
Oct 17, 2006
31
32
33
34
35
36
37
/* !!! FIXME: move this somewhere that other drivers can use it... */
#if defined(_WIN32_WCE)
#define WINDOWS_OS_NAME "Windows CE/PocketPC"
#elif defined(WIN64)
#define WINDOWS_OS_NAME "Win64"
#else
#define WINDOWS_OS_NAME "Win32"
Apr 26, 2001
Apr 26, 2001
38
#endif
Jul 10, 2006
Jul 10, 2006
39
Oct 17, 2006
Oct 17, 2006
40
/* DirectX function pointers for audio */
Apr 26, 2001
Apr 26, 2001
41
static HINSTANCE DSoundDLL = NULL;
Oct 28, 2006
Oct 28, 2006
42
43
static HRESULT(WINAPI * DSoundCreate) (LPGUID, LPDIRECTSOUND *, LPUNKNOWN) =
NULL;
Apr 26, 2001
Apr 26, 2001
44
Jul 10, 2006
Jul 10, 2006
45
static void
Oct 17, 2006
Oct 17, 2006
46
DSOUND_Unload(void)
Apr 26, 2001
Apr 26, 2001
47
{
Jul 10, 2006
Jul 10, 2006
48
49
50
51
if (DSoundDLL != NULL) {
FreeLibrary(DSoundDLL);
}
Oct 17, 2006
Oct 17, 2006
52
53
DSoundCreate = NULL;
DSoundDLL = NULL;
Apr 26, 2001
Apr 26, 2001
54
55
56
}
Oct 17, 2006
Oct 17, 2006
57
58
static int
DSOUND_Load(void)
Apr 26, 2001
Apr 26, 2001
59
{
Oct 17, 2006
Oct 17, 2006
60
int loaded = 0;
Jul 10, 2006
Jul 10, 2006
61
Oct 17, 2006
Oct 17, 2006
62
DSOUND_Unload();
Jul 10, 2006
Jul 10, 2006
63
Oct 17, 2006
Oct 17, 2006
64
65
66
67
68
69
70
71
72
73
DSoundDLL = LoadLibrary(TEXT("DSOUND.DLL"));
if (DSoundDLL == NULL) {
SDL_SetError("DirectSound: failed to load DSOUND.DLL");
} else {
/* Now make sure we have DirectX 5 or better... */
/* (DirectSoundCaptureCreate was added in DX5) */
if (!GetProcAddress(DSoundDLL, TEXT("DirectSoundCaptureCreate"))) {
SDL_SetError("DirectSound: System doesn't appear to have DX5.");
} else {
DSoundCreate = (void *) GetProcAddress(DSoundDLL,
Oct 28, 2006
Oct 28, 2006
74
TEXT("DirectSoundCreate"));
Jul 10, 2006
Jul 10, 2006
75
76
}
Oct 17, 2006
Oct 17, 2006
77
78
79
80
81
82
if (!DSoundCreate) {
SDL_SetError("DirectSound: Failed to find DirectSoundCreate");
} else {
loaded = 1;
}
}
Jul 10, 2006
Jul 10, 2006
83
Oct 17, 2006
Oct 17, 2006
84
85
86
if (!loaded) {
DSOUND_Unload();
}
Jul 10, 2006
Jul 10, 2006
87
Oct 17, 2006
Oct 17, 2006
88
return loaded;
Apr 26, 2001
Apr 26, 2001
89
90
91
}
Jul 10, 2006
Jul 10, 2006
92
93
static void
SetDSerror(const char *function, int code)
Apr 26, 2001
Apr 26, 2001
94
{
Jul 10, 2006
Jul 10, 2006
95
96
97
98
99
100
static const char *error;
static char errbuf[1024];
errbuf[0] = 0;
switch (code) {
case E_NOINTERFACE:
Oct 17, 2006
Oct 17, 2006
101
error = "Unsupported interface -- Is DirectX 5.0 or later installed?";
Jul 10, 2006
Jul 10, 2006
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
break;
case DSERR_ALLOCATED:
error = "Audio device in use";
break;
case DSERR_BADFORMAT:
error = "Unsupported audio format";
break;
case DSERR_BUFFERLOST:
error = "Mixing buffer was lost";
break;
case DSERR_CONTROLUNAVAIL:
error = "Control requested is not available";
break;
case DSERR_INVALIDCALL:
error = "Invalid call for the current state";
break;
case DSERR_INVALIDPARAM:
error = "Invalid parameter";
break;
case DSERR_NODRIVER:
error = "No audio device found";
break;
case DSERR_OUTOFMEMORY:
error = "Out of memory";
break;
case DSERR_PRIOLEVELNEEDED:
error = "Caller doesn't have priority";
break;
case DSERR_UNSUPPORTED:
error = "Function not supported";
break;
default:
SDL_snprintf(errbuf, SDL_arraysize(errbuf),
"%s: Unknown DirectSound error: 0x%x", function, code);
break;
}
if (!errbuf[0]) {
SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function,
error);
}
SDL_SetError("%s", errbuf);
return;
Apr 26, 2001
Apr 26, 2001
144
145
146
147
148
}
/* DirectSound needs to be associated with a window */
static HWND mainwin = NULL;
/* */
Oct 17, 2006
Oct 17, 2006
149
Jul 10, 2006
Jul 10, 2006
150
void
Oct 17, 2006
Oct 17, 2006
151
DSOUND_SoundFocus(HWND hwnd)
Apr 26, 2001
Apr 26, 2001
152
{
Oct 17, 2006
Oct 17, 2006
153
/* !!! FIXME: probably broken with multi-window support in SDL 1.3 ... */
Jul 10, 2006
Jul 10, 2006
154
mainwin = hwnd;
Apr 26, 2001
Apr 26, 2001
155
156
}
Jul 10, 2006
Jul 10, 2006
157
static void
Oct 17, 2006
Oct 17, 2006
158
DSOUND_ThreadInit(_THIS)
Apr 26, 2001
Apr 26, 2001
159
{
Jul 10, 2006
Jul 10, 2006
160
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
Apr 26, 2001
Apr 26, 2001
161
162
}
Jul 10, 2006
Jul 10, 2006
163
static void
Oct 17, 2006
Oct 17, 2006
164
DSOUND_WaitDevice(_THIS)
Apr 26, 2001
Apr 26, 2001
165
{
Oct 17, 2006
Oct 17, 2006
166
167
168
169
DWORD status = 0;
DWORD cursor = 0;
DWORD junk = 0;
HRESULT result = DS_OK;
Jul 10, 2006
Jul 10, 2006
170
171
172
173
/* Semi-busy wait, since we have no way of getting play notification
on a primary mixing buffer located in hardware (DirectX 5.0)
*/
Oct 17, 2006
Oct 17, 2006
174
175
result = IDirectSoundBuffer_GetCurrentPosition(this->hidden->mixbuf,
&junk, &cursor);
Jul 10, 2006
Jul 10, 2006
176
177
if (result != DS_OK) {
if (result == DSERR_BUFFERLOST) {
Oct 17, 2006
Oct 17, 2006
178
IDirectSoundBuffer_Restore(this->hidden->mixbuf);
Jul 10, 2006
Jul 10, 2006
179
}
Apr 26, 2001
Apr 26, 2001
180
#ifdef DEBUG_SOUND
Jul 10, 2006
Jul 10, 2006
181
SetDSerror("DirectSound GetCurrentPosition", result);
Apr 26, 2001
Apr 26, 2001
182
#endif
Jul 10, 2006
Jul 10, 2006
183
184
185
return;
}
Oct 17, 2006
Oct 17, 2006
186
while ((cursor / this->hidden->mixlen) == this->hidden->lastchunk) {
Jul 10, 2006
Jul 10, 2006
187
188
189
190
/* FIXME: find out how much time is left and sleep that long */
SDL_Delay(1);
/* Try to restore a lost sound buffer */
Oct 17, 2006
Oct 17, 2006
191
IDirectSoundBuffer_GetStatus(this->hidden->mixbuf, &status);
Jul 10, 2006
Jul 10, 2006
192
if ((status & DSBSTATUS_BUFFERLOST)) {
Oct 17, 2006
Oct 17, 2006
193
194
IDirectSoundBuffer_Restore(this->hidden->mixbuf);
IDirectSoundBuffer_GetStatus(this->hidden->mixbuf, &status);
Jul 10, 2006
Jul 10, 2006
195
196
197
198
199
if ((status & DSBSTATUS_BUFFERLOST)) {
break;
}
}
if (!(status & DSBSTATUS_PLAYING)) {
Oct 17, 2006
Oct 17, 2006
200
201
result = IDirectSoundBuffer_Play(this->hidden->mixbuf, 0, 0,
DSBPLAY_LOOPING);
Jul 10, 2006
Jul 10, 2006
202
203
204
if (result == DS_OK) {
continue;
}
Apr 26, 2001
Apr 26, 2001
205
#ifdef DEBUG_SOUND
Jul 10, 2006
Jul 10, 2006
206
SetDSerror("DirectSound Play", result);
Apr 26, 2001
Apr 26, 2001
207
#endif
Jul 10, 2006
Jul 10, 2006
208
209
210
211
return;
}
/* Find out where we are playing */
Oct 17, 2006
Oct 17, 2006
212
result = IDirectSoundBuffer_GetCurrentPosition(this->hidden->mixbuf,
Jul 10, 2006
Jul 10, 2006
213
214
215
216
217
218
&junk, &cursor);
if (result != DS_OK) {
SetDSerror("DirectSound GetCurrentPosition", result);
return;
}
}
Apr 26, 2001
Apr 26, 2001
219
220
}
Jul 10, 2006
Jul 10, 2006
221
static void
Oct 17, 2006
Oct 17, 2006
222
DSOUND_PlayDevice(_THIS)
Apr 26, 2001
Apr 26, 2001
223
{
Jul 10, 2006
Jul 10, 2006
224
/* Unlock the buffer, allowing it to play */
Oct 17, 2006
Oct 17, 2006
225
226
227
228
if (this->hidden->locked_buf) {
IDirectSoundBuffer_Unlock(this->hidden->mixbuf,
this->hidden->locked_buf,
this->hidden->mixlen, NULL, 0);
Jul 10, 2006
Jul 10, 2006
229
}
Apr 26, 2001
Apr 26, 2001
230
231
232
}
Jul 10, 2006
Jul 10, 2006
233
static Uint8 *
Oct 17, 2006
Oct 17, 2006
234
DSOUND_GetDeviceBuf(_THIS)
Apr 26, 2001
Apr 26, 2001
235
{
Oct 17, 2006
Oct 17, 2006
236
237
238
239
DWORD cursor = 0;
DWORD junk = 0;
HRESULT result = DS_OK;
DWORD rawlen = 0;
Jul 10, 2006
Jul 10, 2006
240
241
/* Figure out which blocks to fill next */
Oct 17, 2006
Oct 17, 2006
242
243
244
this->hidden->locked_buf = NULL;
result = IDirectSoundBuffer_GetCurrentPosition(this->hidden->mixbuf,
&junk, &cursor);
Jul 10, 2006
Jul 10, 2006
245
if (result == DSERR_BUFFERLOST) {
Oct 17, 2006
Oct 17, 2006
246
247
IDirectSoundBuffer_Restore(this->hidden->mixbuf);
result = IDirectSoundBuffer_GetCurrentPosition(this->hidden->mixbuf,
Jul 10, 2006
Jul 10, 2006
248
249
250
251
252
253
&junk, &cursor);
}
if (result != DS_OK) {
SetDSerror("DirectSound GetCurrentPosition", result);
return (NULL);
}
Oct 17, 2006
Oct 17, 2006
254
cursor /= this->hidden->mixlen;
Jun 23, 2006
Jun 23, 2006
255
#ifdef DEBUG_SOUND
Jul 10, 2006
Jul 10, 2006
256
257
258
/* Detect audio dropouts */
{
DWORD spot = cursor;
Oct 17, 2006
Oct 17, 2006
259
260
if (spot < this->hidden->lastchunk) {
spot += this->hidden->num_buffers;
Jul 10, 2006
Jul 10, 2006
261
}
Oct 17, 2006
Oct 17, 2006
262
if (spot > this->hidden->lastchunk + 1) {
Jul 10, 2006
Jul 10, 2006
263
fprintf(stderr, "Audio dropout, missed %d fragments\n",
Oct 17, 2006
Oct 17, 2006
264
(spot - (this->hidden->lastchunk + 1)));
Jul 10, 2006
Jul 10, 2006
265
266
}
}
Jun 23, 2006
Jun 23, 2006
267
#endif
Oct 17, 2006
Oct 17, 2006
268
269
270
this->hidden->lastchunk = cursor;
cursor = (cursor + 1) % this->hidden->num_buffers;
cursor *= this->hidden->mixlen;
Jul 10, 2006
Jul 10, 2006
271
272
/* Lock the audio buffer */
Oct 17, 2006
Oct 17, 2006
273
274
result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor,
this->hidden->mixlen,
Oct 28, 2006
Oct 28, 2006
275
(LPVOID *) & this->hidden->locked_buf,
Oct 17, 2006
Oct 17, 2006
276
&rawlen, NULL, &junk, 0);
Jul 10, 2006
Jul 10, 2006
277
if (result == DSERR_BUFFERLOST) {
Oct 17, 2006
Oct 17, 2006
278
279
280
IDirectSoundBuffer_Restore(this->hidden->mixbuf);
result = IDirectSoundBuffer_Lock(this->hidden->mixbuf, cursor,
this->hidden->mixlen,
Oct 28, 2006
Oct 28, 2006
281
282
(LPVOID *) & this->hidden->
locked_buf, &rawlen, NULL, &junk, 0);
Jul 10, 2006
Jul 10, 2006
283
284
285
286
287
}
if (result != DS_OK) {
SetDSerror("DirectSound Lock", result);
return (NULL);
}
Oct 17, 2006
Oct 17, 2006
288
return (this->hidden->locked_buf);
Apr 26, 2001
Apr 26, 2001
289
290
}
Jul 10, 2006
Jul 10, 2006
291
static void
Oct 17, 2006
Oct 17, 2006
292
DSOUND_WaitDone(_THIS)
Apr 26, 2001
Apr 26, 2001
293
{
Oct 17, 2006
Oct 17, 2006
294
Uint8 *stream = DSOUND_GetDeviceBuf(this);
Jul 10, 2006
Jul 10, 2006
295
296
297
/* Wait for the playing chunk to finish */
if (stream != NULL) {
Oct 17, 2006
Oct 17, 2006
298
299
SDL_memset(stream, this->spec.silence, this->hidden->mixlen);
DSOUND_PlayDevice(this);
Jul 10, 2006
Jul 10, 2006
300
}
Oct 17, 2006
Oct 17, 2006
301
DSOUND_WaitDevice(this);
Jul 10, 2006
Jul 10, 2006
302
303
/* Stop the looping sound buffer */
Oct 17, 2006
Oct 17, 2006
304
IDirectSoundBuffer_Stop(this->hidden->mixbuf);
Apr 26, 2001
Apr 26, 2001
305
306
}
Jul 10, 2006
Jul 10, 2006
307
static void
Oct 17, 2006
Oct 17, 2006
308
DSOUND_CloseDevice(_THIS)
Apr 26, 2001
Apr 26, 2001
309
{
Oct 17, 2006
Oct 17, 2006
310
311
312
313
314
315
316
317
318
if (this->hidden != NULL) {
if (this->hidden->sound != NULL) {
if (this->hidden->mixbuf != NULL) {
/* Clean up the audio buffer */
IDirectSoundBuffer_Release(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
IDirectSound_Release(this->hidden->sound);
this->hidden->sound = NULL;
Jul 10, 2006
Jul 10, 2006
319
}
Apr 26, 2001
Apr 26, 2001
320
Oct 17, 2006
Oct 17, 2006
321
322
SDL_free(this->hidden);
this->hidden = NULL;
Jul 10, 2006
Jul 10, 2006
323
}
Apr 26, 2001
Apr 26, 2001
324
325
326
327
328
}
/* This function tries to create a secondary audio buffer, and returns the
number of audio chunks available in the created buffer.
*/
Jul 10, 2006
Jul 10, 2006
329
static int
Oct 28, 2006
Oct 28, 2006
330
CreateSecondary(_THIS, HWND focus, WAVEFORMATEX * wavefmt)
Apr 26, 2001
Apr 26, 2001
331
{
Oct 17, 2006
Oct 17, 2006
332
LPDIRECTSOUND sndObj = this->hidden->sound;
Oct 20, 2006
Oct 20, 2006
333
LPDIRECTSOUNDBUFFER *sndbuf = &this->hidden->mixbuf;
Oct 17, 2006
Oct 17, 2006
334
Uint32 chunksize = this->spec.size;
Jul 10, 2006
Jul 10, 2006
335
const int numchunks = 8;
Oct 17, 2006
Oct 17, 2006
336
HRESULT result = DS_OK;
Jul 10, 2006
Jul 10, 2006
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
DSBUFFERDESC format;
LPVOID pvAudioPtr1, pvAudioPtr2;
DWORD dwAudioBytes1, dwAudioBytes2;
/* Try to set primary mixing privileges */
if (focus) {
result = IDirectSound_SetCooperativeLevel(sndObj,
focus, DSSCL_PRIORITY);
} else {
result = IDirectSound_SetCooperativeLevel(sndObj,
GetDesktopWindow(),
DSSCL_NORMAL);
}
if (result != DS_OK) {
SetDSerror("DirectSound SetCooperativeLevel", result);
return (-1);
}
Apr 26, 2001
Apr 26, 2001
354
Jul 10, 2006
Jul 10, 2006
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/* Try to create the secondary buffer */
SDL_memset(&format, 0, sizeof(format));
format.dwSize = sizeof(format);
format.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
if (!focus) {
format.dwFlags |= DSBCAPS_GLOBALFOCUS;
} else {
format.dwFlags |= DSBCAPS_STICKYFOCUS;
}
format.dwBufferBytes = numchunks * chunksize;
if ((format.dwBufferBytes < DSBSIZE_MIN) ||
(format.dwBufferBytes > DSBSIZE_MAX)) {
SDL_SetError("Sound buffer size must be between %d and %d",
DSBSIZE_MIN / numchunks, DSBSIZE_MAX / numchunks);
return (-1);
}
format.dwReserved = 0;
format.lpwfxFormat = wavefmt;
result = IDirectSound_CreateSoundBuffer(sndObj, &format, sndbuf, NULL);
if (result != DS_OK) {
SetDSerror("DirectSound CreateSoundBuffer", result);
return (-1);
}
IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);
/* Silence the initial audio buffer */
result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes,
(LPVOID *) & pvAudioPtr1, &dwAudioBytes1,
(LPVOID *) & pvAudioPtr2, &dwAudioBytes2,
DSBLOCK_ENTIREBUFFER);
if (result == DS_OK) {
Oct 17, 2006
Oct 17, 2006
386
SDL_memset(pvAudioPtr1, this->spec.silence, dwAudioBytes1);
Jul 10, 2006
Jul 10, 2006
387
388
389
390
391
392
393
IDirectSoundBuffer_Unlock(*sndbuf,
(LPVOID) pvAudioPtr1, dwAudioBytes1,
(LPVOID) pvAudioPtr2, dwAudioBytes2);
}
/* We're ready to go */
return (numchunks);
Apr 26, 2001
Apr 26, 2001
394
395
}
Jul 10, 2006
Jul 10, 2006
396
static int
Oct 17, 2006
Oct 17, 2006
397
DSOUND_OpenDevice(_THIS, const char *devname, int iscapture)
Apr 26, 2001
Apr 26, 2001
398
{
Jul 10, 2006
Jul 10, 2006
399
HRESULT result;
Oct 17, 2006
Oct 17, 2006
400
401
402
WAVEFORMATEX waveformat;
int valid_format = 0;
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
Jul 10, 2006
Jul 10, 2006
403
Oct 17, 2006
Oct 17, 2006
404
405
/* !!! FIXME: handle devname */
/* !!! FIXME: handle iscapture */
Jul 10, 2006
Jul 10, 2006
406
Oct 17, 2006
Oct 17, 2006
407
408
/* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *)
Oct 28, 2006
Oct 28, 2006
409
SDL_malloc((sizeof *this->hidden));
Oct 17, 2006
Oct 17, 2006
410
411
412
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
Jul 10, 2006
Jul 10, 2006
413
}
Oct 17, 2006
Oct 17, 2006
414
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
Jul 10, 2006
Jul 10, 2006
415
Oct 17, 2006
Oct 17, 2006
416
417
while ((!valid_format) && (test_format)) {
switch (test_format) {
Oct 28, 2006
Oct 28, 2006
418
419
420
421
422
423
case AUDIO_U8:
case AUDIO_S16:
case AUDIO_S32:
this->spec.format = test_format;
valid_format = 1;
break;
Oct 17, 2006
Oct 17, 2006
424
425
}
test_format = SDL_NextAudioFormat();
Jul 10, 2006
Jul 10, 2006
426
427
}
Oct 17, 2006
Oct 17, 2006
428
429
430
431
if (!valid_format) {
DSOUND_CloseDevice(this);
SDL_SetError("DirectSound: Unsupported audio format");
return 0;
Jul 10, 2006
Jul 10, 2006
432
}
Apr 26, 2001
Apr 26, 2001
433
Jul 10, 2006
Jul 10, 2006
434
435
SDL_memset(&waveformat, 0, sizeof(waveformat));
waveformat.wFormatTag = WAVE_FORMAT_PCM;
Oct 17, 2006
Oct 17, 2006
436
437
438
waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(this->spec.format);
waveformat.nChannels = this->spec.channels;
waveformat.nSamplesPerSec = this->spec.freq;
Jul 10, 2006
Jul 10, 2006
439
440
441
442
443
444
waveformat.nBlockAlign =
waveformat.nChannels * (waveformat.wBitsPerSample / 8);
waveformat.nAvgBytesPerSec =
waveformat.nSamplesPerSec * waveformat.nBlockAlign;
/* Update the fragment size as size in bytes */
Oct 17, 2006
Oct 17, 2006
445
SDL_CalculateAudioSpec(&this->spec);
Jul 10, 2006
Jul 10, 2006
446
447
/* Open the audio device */
Oct 17, 2006
Oct 17, 2006
448
result = DSoundCreate(NULL, &this->hidden->sound, NULL);
Jul 10, 2006
Jul 10, 2006
449
if (result != DS_OK) {
Oct 17, 2006
Oct 17, 2006
450
DSOUND_CloseDevice(this);
Jul 10, 2006
Jul 10, 2006
451
SetDSerror("DirectSoundCreate", result);
Oct 17, 2006
Oct 17, 2006
452
return 0;
Jul 10, 2006
Jul 10, 2006
453
454
455
}
/* Create the audio buffer to which we write */
Oct 17, 2006
Oct 17, 2006
456
457
458
459
this->hidden->num_buffers = CreateSecondary(this, mainwin, &waveformat);
if (this->hidden->num_buffers < 0) {
DSOUND_CloseDevice(this);
return 0;
Jul 10, 2006
Jul 10, 2006
460
}
Oct 17, 2006
Oct 17, 2006
461
462
463
464
/* The buffer will auto-start playing in DSOUND_WaitDevice() */
this->hidden->mixlen = this->spec.size;
Oct 28, 2006
Oct 28, 2006
465
return 1; /* good to go. */
Oct 17, 2006
Oct 17, 2006
466
467
468
469
470
471
472
473
474
475
476
}
static void
DSOUND_Deinitialize(void)
{
DSOUND_Unload();
}
static int
Oct 28, 2006
Oct 28, 2006
477
DSOUND_Init(SDL_AudioDriverImpl * impl)
Oct 17, 2006
Oct 17, 2006
478
479
480
481
482
483
484
485
{
OSVERSIONINFO ver;
/*
* Unfortunately, the sound drivers on NT have higher latencies than the
* audio buffers used by many SDL applications, so there are gaps in the
* audio - it sounds terrible. Punt for now.
*/
Oct 28, 2006
Oct 28, 2006
486
SDL_memset(&ver, '\0', sizeof(OSVERSIONINFO));
Oct 17, 2006
Oct 17, 2006
487
488
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&ver);
Oct 18, 2006
Oct 18, 2006
489
if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) {
Oct 17, 2006
Oct 17, 2006
490
if (ver.dwMajorVersion <= 4) {
Oct 28, 2006
Oct 28, 2006
491
return 0; /* NT4.0 or earlier. Disable dsound support. */
Jul 10, 2006
Jul 10, 2006
492
493
}
}
Apr 26, 2001
Apr 26, 2001
494
Oct 17, 2006
Oct 17, 2006
495
496
if (!DSOUND_Load()) {
return 0;
Jul 10, 2006
Jul 10, 2006
497
}
Oct 17, 2006
Oct 17, 2006
498
499
500
501
502
503
504
505
506
507
/* Set the function pointers */
impl->OpenDevice = DSOUND_OpenDevice;
impl->PlayDevice = DSOUND_PlayDevice;
impl->WaitDevice = DSOUND_WaitDevice;
impl->WaitDone = DSOUND_WaitDone;
impl->ThreadInit = DSOUND_ThreadInit;
impl->GetDeviceBuf = DSOUND_GetDeviceBuf;
impl->CloseDevice = DSOUND_CloseDevice;
impl->Deinitialize = DSOUND_Deinitialize;
Oct 28, 2006
Oct 28, 2006
508
impl->OnlyHasDefaultOutputDevice = 1; /* !!! FIXME */
Oct 17, 2006
Oct 17, 2006
509
510
return 1;
Apr 26, 2001
Apr 26, 2001
511
512
}
Oct 17, 2006
Oct 17, 2006
513
514
515
516
AudioBootStrap DSOUND_bootstrap = {
"dsound", WINDOWS_OS_NAME "DirectSound", DSOUND_Init, 0
};
Jul 10, 2006
Jul 10, 2006
517
/* vi: set ts=4 sw=4 expandtab: */