comparison src/audio/macrom/SDL_romaudio.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
45 #include "../SDL_sysaudio.h" 45 #include "../SDL_sysaudio.h"
46 #include "SDL_romaudio.h" 46 #include "SDL_romaudio.h"
47 47
48 /* Audio driver functions */ 48 /* Audio driver functions */
49 49
50 static void Mac_CloseAudio (_THIS); 50 static void Mac_CloseAudio(_THIS);
51 static int Mac_OpenAudio (_THIS, SDL_AudioSpec * spec); 51 static int Mac_OpenAudio(_THIS, SDL_AudioSpec * spec);
52 static void Mac_LockAudio (_THIS); 52 static void Mac_LockAudio(_THIS);
53 static void Mac_UnlockAudio (_THIS); 53 static void Mac_UnlockAudio(_THIS);
54 54
55 /* Audio driver bootstrap functions */ 55 /* Audio driver bootstrap functions */
56 56
57 57
58 static int 58 static int
59 Audio_Available (void) 59 Audio_Available(void)
60 { 60 {
61 return (1); 61 return (1);
62 } 62 }
63 63
64 static void 64 static void
65 Audio_DeleteDevice (SDL_AudioDevice * device) 65 Audio_DeleteDevice(SDL_AudioDevice * device)
66 { 66 {
67 SDL_free (device->hidden); 67 SDL_free(device->hidden);
68 SDL_free (device); 68 SDL_free(device);
69 } 69 }
70 70
71 static SDL_AudioDevice * 71 static SDL_AudioDevice *
72 Audio_CreateDevice (int devindex) 72 Audio_CreateDevice(int devindex)
73 { 73 {
74 SDL_AudioDevice *this; 74 SDL_AudioDevice *this;
75 75
76 /* Initialize all variables that we clean on shutdown */ 76 /* Initialize all variables that we clean on shutdown */
77 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); 77 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
78 if (this) { 78 if (this) {
79 SDL_memset (this, 0, (sizeof *this)); 79 SDL_memset(this, 0, (sizeof *this));
80 this->hidden = (struct SDL_PrivateAudioData *) 80 this->hidden = (struct SDL_PrivateAudioData *)
81 SDL_malloc ((sizeof *this->hidden)); 81 SDL_malloc((sizeof *this->hidden));
82 } 82 }
83 if ((this == NULL) || (this->hidden == NULL)) { 83 if ((this == NULL) || (this->hidden == NULL)) {
84 SDL_OutOfMemory (); 84 SDL_OutOfMemory();
85 if (this) { 85 if (this) {
86 SDL_free (this); 86 SDL_free(this);
87 } 87 }
88 return (0); 88 return (0);
89 } 89 }
90 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); 90 SDL_memset(this->hidden, 0, (sizeof *this->hidden));
91 91
92 /* Set the function pointers */ 92 /* Set the function pointers */
93 this->OpenAudio = Mac_OpenAudio; 93 this->OpenAudio = Mac_OpenAudio;
94 this->CloseAudio = Mac_CloseAudio; 94 this->CloseAudio = Mac_CloseAudio;
95 this->LockAudio = Mac_LockAudio; 95 this->LockAudio = Mac_LockAudio;
120 static volatile UInt32 running = 0; 120 static volatile UInt32 running = 0;
121 static CmpSoundHeader header; 121 static CmpSoundHeader header;
122 static volatile Uint32 fill_me = 0; 122 static volatile Uint32 fill_me = 0;
123 123
124 static void 124 static void
125 mix_buffer (SDL_AudioDevice * audio, UInt8 * buffer) 125 mix_buffer(SDL_AudioDevice * audio, UInt8 * buffer)
126 { 126 {
127 if (!audio->paused) { 127 if (!audio->paused) {
128 #ifdef __MACOSX__ 128 #ifdef __MACOSX__
129 SDL_mutexP (audio->mixer_lock); 129 SDL_mutexP(audio->mixer_lock);
130 #endif 130 #endif
131 if (audio->convert.needed) { 131 if (audio->convert.needed) {
132 audio->spec.callback (audio->spec.userdata, 132 audio->spec.callback(audio->spec.userdata,
133 (Uint8 *) audio->convert.buf, 133 (Uint8 *) audio->convert.buf,
134 audio->convert.len); 134 audio->convert.len);
135 SDL_ConvertAudio (&audio->convert); 135 SDL_ConvertAudio(&audio->convert);
136 if (audio->convert.len_cvt != audio->spec.size) { 136 if (audio->convert.len_cvt != audio->spec.size) {
137 /* Uh oh... probably crashes here */ ; 137 /* Uh oh... probably crashes here */ ;
138 } 138 }
139 SDL_memcpy (buffer, audio->convert.buf, audio->convert.len_cvt); 139 SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
140 } else { 140 } else {
141 audio->spec.callback (audio->spec.userdata, buffer, 141 audio->spec.callback(audio->spec.userdata, buffer,
142 audio->spec.size); 142 audio->spec.size);
143 } 143 }
144 #ifdef __MACOSX__ 144 #ifdef __MACOSX__
145 SDL_mutexV (audio->mixer_lock); 145 SDL_mutexV(audio->mixer_lock);
146 #endif 146 #endif
147 } 147 }
148 148
149 DecrementAtomic ((SInt32 *) & need_to_mix); 149 DecrementAtomic((SInt32 *) & need_to_mix);
150 } 150 }
151 151
152 static void 152 static void
153 Mac_LockAudio (_THIS) 153 Mac_LockAudio(_THIS)
154 { 154 {
155 IncrementAtomic ((SInt32 *) & audio_is_locked); 155 IncrementAtomic((SInt32 *) & audio_is_locked);
156 } 156 }
157 157
158 static void 158 static void
159 Mac_UnlockAudio (_THIS) 159 Mac_UnlockAudio(_THIS)
160 { 160 {
161 SInt32 oldval; 161 SInt32 oldval;
162 162
163 oldval = DecrementAtomic ((SInt32 *) & audio_is_locked); 163 oldval = DecrementAtomic((SInt32 *) & audio_is_locked);
164 if (oldval != 1) /* != 1 means audio is still locked. */ 164 if (oldval != 1) /* != 1 means audio is still locked. */
165 return; 165 return;
166 166
167 /* Did we miss the chance to mix in an interrupt? Do it now. */ 167 /* Did we miss the chance to mix in an interrupt? Do it now. */
168 if (BitAndAtomic (0xFFFFFFFF, (UInt32 *) & need_to_mix)) { 168 if (BitAndAtomic(0xFFFFFFFF, (UInt32 *) & need_to_mix)) {
169 /* 169 /*
170 * Note that this could be a problem if you missed an interrupt 170 * Note that this could be a problem if you missed an interrupt
171 * while the audio was locked, and get preempted by a second 171 * while the audio was locked, and get preempted by a second
172 * interrupt here, but that means you locked for way too long anyhow. 172 * interrupt here, but that means you locked for way too long anyhow.
173 */ 173 */
174 mix_buffer (this, buffer[fill_me]); 174 mix_buffer(this, buffer[fill_me]);
175 } 175 }
176 } 176 }
177 177
178 static void 178 static void
179 callBackProc (SndChannel * chan, SndCommand * cmd_passed) 179 callBackProc(SndChannel * chan, SndCommand * cmd_passed)
180 { 180 {
181 UInt32 play_me; 181 UInt32 play_me;
182 SndCommand cmd; 182 SndCommand cmd;
183 SDL_AudioDevice *audio = (SDL_AudioDevice *) chan->userInfo; 183 SDL_AudioDevice *audio = (SDL_AudioDevice *) chan->userInfo;
184 184
185 IncrementAtomic ((SInt32 *) & need_to_mix); 185 IncrementAtomic((SInt32 *) & need_to_mix);
186 186
187 fill_me = cmd_passed->param2; /* buffer that has just finished playing, so fill it */ 187 fill_me = cmd_passed->param2; /* buffer that has just finished playing, so fill it */
188 play_me = !fill_me; /* filled buffer to play _now_ */ 188 play_me = !fill_me; /* filled buffer to play _now_ */
189 189
190 if (!audio->enabled) { 190 if (!audio->enabled) {
194 /* queue previously mixed buffer for playback. */ 194 /* queue previously mixed buffer for playback. */
195 header.samplePtr = (Ptr) buffer[play_me]; 195 header.samplePtr = (Ptr) buffer[play_me];
196 cmd.cmd = bufferCmd; 196 cmd.cmd = bufferCmd;
197 cmd.param1 = 0; 197 cmd.param1 = 0;
198 cmd.param2 = (long) &header; 198 cmd.param2 = (long) &header;
199 SndDoCommand (chan, &cmd, 0); 199 SndDoCommand(chan, &cmd, 0);
200 200
201 memset (buffer[fill_me], 0, audio->spec.size); 201 memset(buffer[fill_me], 0, audio->spec.size);
202 202
203 /* 203 /*
204 * if audio device isn't locked, mix the next buffer to be queued in 204 * if audio device isn't locked, mix the next buffer to be queued in
205 * the memory block that just finished playing. 205 * the memory block that just finished playing.
206 */ 206 */
207 if (!BitAndAtomic (0xFFFFFFFF, (UInt32 *) & audio_is_locked)) { 207 if (!BitAndAtomic(0xFFFFFFFF, (UInt32 *) & audio_is_locked)) {
208 mix_buffer (audio, buffer[fill_me]); 208 mix_buffer(audio, buffer[fill_me]);
209 } 209 }
210 210
211 /* set this callback to run again when current buffer drains. */ 211 /* set this callback to run again when current buffer drains. */
212 if (running) { 212 if (running) {
213 cmd.cmd = callBackCmd; 213 cmd.cmd = callBackCmd;
214 cmd.param1 = 0; 214 cmd.param1 = 0;
215 cmd.param2 = play_me; 215 cmd.param2 = play_me;
216 216
217 SndDoCommand (chan, &cmd, 0); 217 SndDoCommand(chan, &cmd, 0);
218 } 218 }
219 } 219 }
220 220
221 static int 221 static int
222 Mac_OpenAudio (_THIS, SDL_AudioSpec * spec) 222 Mac_OpenAudio(_THIS, SDL_AudioSpec * spec)
223 { 223 {
224 224
225 SndCallBackUPP callback; 225 SndCallBackUPP callback;
226 int sample_bits; 226 int sample_bits;
227 int i; 227 int i;
237 break; 237 break;
238 case AUDIO_U16MSB: 238 case AUDIO_U16MSB:
239 spec->format = AUDIO_S16MSB; 239 spec->format = AUDIO_S16MSB;
240 break; 240 break;
241 } 241 }
242 SDL_CalculateAudioSpec (spec); 242 SDL_CalculateAudioSpec(spec);
243 243
244 /* initialize bufferCmd header */ 244 /* initialize bufferCmd header */
245 memset (&header, 0, sizeof (header)); 245 memset(&header, 0, sizeof(header));
246 callback = (SndCallBackUPP) NewSndCallBackUPP (callBackProc); 246 callback = (SndCallBackUPP) NewSndCallBackUPP(callBackProc);
247 sample_bits = spec->size / spec->samples / spec->channels * 8; 247 sample_bits = spec->size / spec->samples / spec->channels * 8;
248 248
249 #ifdef DEBUG_AUDIO 249 #ifdef DEBUG_AUDIO
250 fprintf (stderr, 250 fprintf(stderr,
251 "Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n", 251 "Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n",
252 spec->format, spec->channels, sample_bits, spec->freq); 252 spec->format, spec->channels, sample_bits, spec->freq);
253 #endif /* DEBUG_AUDIO */ 253 #endif /* DEBUG_AUDIO */
254 254
255 header.numChannels = spec->channels; 255 header.numChannels = spec->channels;
256 header.sampleSize = sample_bits; 256 header.sampleSize = sample_bits;
257 header.sampleRate = spec->freq << 16; 257 header.sampleRate = spec->freq << 16;
264 header.format = k16BitLittleEndianFormat; 264 header.format = k16BitLittleEndianFormat;
265 } 265 }
266 266
267 /* allocate 2 buffers */ 267 /* allocate 2 buffers */
268 for (i = 0; i < 2; i++) { 268 for (i = 0; i < 2; i++) {
269 buffer[i] = (UInt8 *) malloc (sizeof (UInt8) * spec->size); 269 buffer[i] = (UInt8 *) malloc(sizeof(UInt8) * spec->size);
270 if (buffer[i] == NULL) { 270 if (buffer[i] == NULL) {
271 SDL_OutOfMemory (); 271 SDL_OutOfMemory();
272 return (-1); 272 return (-1);
273 } 273 }
274 memset (buffer[i], 0, spec->size); 274 memset(buffer[i], 0, spec->size);
275 } 275 }
276 276
277 /* Create the sound manager channel */ 277 /* Create the sound manager channel */
278 channel = (SndChannelPtr) SDL_malloc (sizeof (*channel)); 278 channel = (SndChannelPtr) SDL_malloc(sizeof(*channel));
279 if (channel == NULL) { 279 if (channel == NULL) {
280 SDL_OutOfMemory (); 280 SDL_OutOfMemory();
281 return (-1); 281 return (-1);
282 } 282 }
283 if (spec->channels >= 2) { 283 if (spec->channels >= 2) {
284 initOptions = initStereo; 284 initOptions = initStereo;
285 } else { 285 } else {
286 initOptions = initMono; 286 initOptions = initMono;
287 } 287 }
288 channel->userInfo = (long) this; 288 channel->userInfo = (long) this;
289 channel->qLength = 128; 289 channel->qLength = 128;
290 if (SndNewChannel (&channel, sampledSynth, initOptions, callback) != 290 if (SndNewChannel(&channel, sampledSynth, initOptions, callback) != noErr) {
291 noErr) { 291 SDL_SetError("Unable to create audio channel");
292 SDL_SetError ("Unable to create audio channel"); 292 SDL_free(channel);
293 SDL_free (channel);
294 channel = NULL; 293 channel = NULL;
295 return (-1); 294 return (-1);
296 } 295 }
297 296
298 /* start playback */ 297 /* start playback */
299 { 298 {
300 SndCommand cmd; 299 SndCommand cmd;
301 cmd.cmd = callBackCmd; 300 cmd.cmd = callBackCmd;
302 cmd.param2 = 0; 301 cmd.param2 = 0;
303 running = 1; 302 running = 1;
304 SndDoCommand (channel, &cmd, 0); 303 SndDoCommand(channel, &cmd, 0);
305 } 304 }
306 305
307 return 1; 306 return 1;
308 } 307 }
309 308
310 static void 309 static void
311 Mac_CloseAudio (_THIS) 310 Mac_CloseAudio(_THIS)
312 { 311 {
313 312
314 int i; 313 int i;
315 314
316 running = 0; 315 running = 0;
317 316
318 if (channel) { 317 if (channel) {
319 SndDisposeChannel (channel, true); 318 SndDisposeChannel(channel, true);
320 channel = NULL; 319 channel = NULL;
321 } 320 }
322 321
323 for (i = 0; i < 2; ++i) { 322 for (i = 0; i < 2; ++i) {
324 if (buffer[i]) { 323 if (buffer[i]) {
325 SDL_free (buffer[i]); 324 SDL_free(buffer[i]);
326 buffer[i] = NULL; 325 buffer[i] = NULL;
327 } 326 }
328 } 327 }
329 } 328 }
330 329
331 #else /* !TARGET_API_MAC_CARBON && !USE_RYANS_SOUNDCODE */ 330 #else /* !TARGET_API_MAC_CARBON && !USE_RYANS_SOUNDCODE */
332 331
333 static void 332 static void
334 Mac_LockAudio (_THIS) 333 Mac_LockAudio(_THIS)
335 { 334 {
336 /* no-op. */ 335 /* no-op. */
337 } 336 }
338 337
339 static void 338 static void
340 Mac_UnlockAudio (_THIS) 339 Mac_UnlockAudio(_THIS)
341 { 340 {
342 /* no-op. */ 341 /* no-op. */
343 } 342 }
344 343
345 344
346 /* This function is called by Sound Manager when it has exhausted one of 345 /* This function is called by Sound Manager when it has exhausted one of
347 the buffers, so we'll zero it to silence and fill it with audio if 346 the buffers, so we'll zero it to silence and fill it with audio if
348 we're not paused. 347 we're not paused.
349 */ 348 */
350 static pascal void 349 static pascal void
351 sndDoubleBackProc (SndChannelPtr chan, SndDoubleBufferPtr newbuf) 350 sndDoubleBackProc(SndChannelPtr chan, SndDoubleBufferPtr newbuf)
352 { 351 {
353 SDL_AudioDevice *audio = (SDL_AudioDevice *) newbuf->dbUserInfo[0]; 352 SDL_AudioDevice *audio = (SDL_AudioDevice *) newbuf->dbUserInfo[0];
354 353
355 /* If audio is quitting, don't do anything */ 354 /* If audio is quitting, don't do anything */
356 if (!audio->enabled) { 355 if (!audio->enabled) {
357 return; 356 return;
358 } 357 }
359 memset (newbuf->dbSoundData, 0, audio->spec.size); 358 memset(newbuf->dbSoundData, 0, audio->spec.size);
360 newbuf->dbNumFrames = audio->spec.samples; 359 newbuf->dbNumFrames = audio->spec.samples;
361 if (!audio->paused) { 360 if (!audio->paused) {
362 if (audio->convert.needed) { 361 if (audio->convert.needed) {
363 audio->spec.callback (audio->spec.userdata, 362 audio->spec.callback(audio->spec.userdata,
364 (Uint8 *) audio->convert.buf, 363 (Uint8 *) audio->convert.buf,
365 audio->convert.len); 364 audio->convert.len);
366 SDL_ConvertAudio (&audio->convert); 365 SDL_ConvertAudio(&audio->convert);
367 #if 0 366 #if 0
368 if (audio->convert.len_cvt != audio->spec.size) { 367 if (audio->convert.len_cvt != audio->spec.size) {
369 /* Uh oh... probably crashes here */ ; 368 /* Uh oh... probably crashes here */ ;
370 } 369 }
371 #endif 370 #endif
372 SDL_memcpy (newbuf->dbSoundData, audio->convert.buf, 371 SDL_memcpy(newbuf->dbSoundData, audio->convert.buf,
373 audio->convert.len_cvt); 372 audio->convert.len_cvt);
374 } else { 373 } else {
375 audio->spec.callback (audio->spec.userdata, 374 audio->spec.callback(audio->spec.userdata,
376 (Uint8 *) newbuf->dbSoundData, 375 (Uint8 *) newbuf->dbSoundData,
377 audio->spec.size); 376 audio->spec.size);
378 } 377 }
379 } 378 }
380 newbuf->dbFlags |= dbBufferReady; 379 newbuf->dbFlags |= dbBufferReady;
381 } 380 }
382 381
383 static int 382 static int
384 DoubleBufferAudio_Available (void) 383 DoubleBufferAudio_Available(void)
385 { 384 {
386 int available; 385 int available;
387 NumVersion sndversion; 386 NumVersion sndversion;
388 long response; 387 long response;
389 388
390 available = 0; 389 available = 0;
391 sndversion = SndSoundManagerVersion (); 390 sndversion = SndSoundManagerVersion();
392 if (sndversion.majorRev >= 3) { 391 if (sndversion.majorRev >= 3) {
393 if (Gestalt (gestaltSoundAttr, &response) == noErr) { 392 if (Gestalt(gestaltSoundAttr, &response) == noErr) {
394 if ((response & (1 << gestaltSndPlayDoubleBuffer))) { 393 if ((response & (1 << gestaltSndPlayDoubleBuffer))) {
395 available = 1; 394 available = 1;
396 } 395 }
397 } 396 }
398 } else { 397 } else {
399 if (Gestalt (gestaltSoundAttr, &response) == noErr) { 398 if (Gestalt(gestaltSoundAttr, &response) == noErr) {
400 if ((response & (1 << gestaltHasASC))) { 399 if ((response & (1 << gestaltHasASC))) {
401 available = 1; 400 available = 1;
402 } 401 }
403 } 402 }
404 } 403 }
405 return (available); 404 return (available);
406 } 405 }
407 406
408 static void 407 static void
409 Mac_CloseAudio (_THIS) 408 Mac_CloseAudio(_THIS)
410 { 409 {
411 int i; 410 int i;
412 411
413 if (channel != NULL) { 412 if (channel != NULL) {
414 /* Clean up the audio channel */ 413 /* Clean up the audio channel */
415 SndDisposeChannel (channel, true); 414 SndDisposeChannel(channel, true);
416 channel = NULL; 415 channel = NULL;
417 } 416 }
418 for (i = 0; i < 2; ++i) { 417 for (i = 0; i < 2; ++i) {
419 if (audio_buf[i]) { 418 if (audio_buf[i]) {
420 SDL_free (audio_buf[i]); 419 SDL_free(audio_buf[i]);
421 audio_buf[i] = NULL; 420 audio_buf[i] = NULL;
422 } 421 }
423 } 422 }
424 } 423 }
425 424
426 static int 425 static int
427 Mac_OpenAudio (_THIS, SDL_AudioSpec * spec) 426 Mac_OpenAudio(_THIS, SDL_AudioSpec * spec)
428 { 427 {
429 SndDoubleBufferHeader2 audio_dbh; 428 SndDoubleBufferHeader2 audio_dbh;
430 int i; 429 int i;
431 long initOptions; 430 long initOptions;
432 int sample_bits; 431 int sample_bits;
433 SndDoubleBackUPP doubleBackProc; 432 SndDoubleBackUPP doubleBackProc;
434 433
435 /* Check to make sure double-buffered audio is available */ 434 /* Check to make sure double-buffered audio is available */
436 if (!DoubleBufferAudio_Available ()) { 435 if (!DoubleBufferAudio_Available()) {
437 SDL_SetError ("Sound manager doesn't support double-buffering"); 436 SDL_SetError("Sound manager doesn't support double-buffering");
438 return (-1); 437 return (-1);
439 } 438 }
440 439
441 /* Very few conversions are required, but... */ 440 /* Very few conversions are required, but... */
442 switch (spec->format) { 441 switch (spec->format) {
448 break; 447 break;
449 case AUDIO_U16MSB: 448 case AUDIO_U16MSB:
450 spec->format = AUDIO_S16MSB; 449 spec->format = AUDIO_S16MSB;
451 break; 450 break;
452 } 451 }
453 SDL_CalculateAudioSpec (spec); 452 SDL_CalculateAudioSpec(spec);
454 453
455 /* initialize the double-back header */ 454 /* initialize the double-back header */
456 SDL_memset (&audio_dbh, 0, sizeof (audio_dbh)); 455 SDL_memset(&audio_dbh, 0, sizeof(audio_dbh));
457 doubleBackProc = NewSndDoubleBackProc (sndDoubleBackProc); 456 doubleBackProc = NewSndDoubleBackProc(sndDoubleBackProc);
458 sample_bits = spec->size / spec->samples / spec->channels * 8; 457 sample_bits = spec->size / spec->samples / spec->channels * 8;
459 458
460 audio_dbh.dbhNumChannels = spec->channels; 459 audio_dbh.dbhNumChannels = spec->channels;
461 audio_dbh.dbhSampleSize = sample_bits; 460 audio_dbh.dbhSampleSize = sample_bits;
462 audio_dbh.dbhCompressionID = 0; 461 audio_dbh.dbhCompressionID = 0;
471 audio_dbh.dbhFormat = k16BitLittleEndianFormat; 470 audio_dbh.dbhFormat = k16BitLittleEndianFormat;
472 } 471 }
473 472
474 /* allocate the 2 double-back buffers */ 473 /* allocate the 2 double-back buffers */
475 for (i = 0; i < 2; ++i) { 474 for (i = 0; i < 2; ++i) {
476 audio_buf[i] = SDL_calloc (1, sizeof (SndDoubleBuffer) + spec->size); 475 audio_buf[i] = SDL_calloc(1, sizeof(SndDoubleBuffer) + spec->size);
477 if (audio_buf[i] == NULL) { 476 if (audio_buf[i] == NULL) {
478 SDL_OutOfMemory (); 477 SDL_OutOfMemory();
479 return (-1); 478 return (-1);
480 } 479 }
481 audio_buf[i]->dbNumFrames = spec->samples; 480 audio_buf[i]->dbNumFrames = spec->samples;
482 audio_buf[i]->dbFlags = dbBufferReady; 481 audio_buf[i]->dbFlags = dbBufferReady;
483 audio_buf[i]->dbUserInfo[0] = (long) this; 482 audio_buf[i]->dbUserInfo[0] = (long) this;
484 audio_dbh.dbhBufferPtr[i] = audio_buf[i]; 483 audio_dbh.dbhBufferPtr[i] = audio_buf[i];
485 } 484 }
486 485
487 /* Create the sound manager channel */ 486 /* Create the sound manager channel */
488 channel = (SndChannelPtr) SDL_malloc (sizeof (*channel)); 487 channel = (SndChannelPtr) SDL_malloc(sizeof(*channel));
489 if (channel == NULL) { 488 if (channel == NULL) {
490 SDL_OutOfMemory (); 489 SDL_OutOfMemory();
491 return (-1); 490 return (-1);
492 } 491 }
493 if (spec->channels >= 2) { 492 if (spec->channels >= 2) {
494 initOptions = initStereo; 493 initOptions = initStereo;
495 } else { 494 } else {
496 initOptions = initMono; 495 initOptions = initMono;
497 } 496 }
498 channel->userInfo = 0; 497 channel->userInfo = 0;
499 channel->qLength = 128; 498 channel->qLength = 128;
500 if (SndNewChannel (&channel, sampledSynth, initOptions, 0L) != noErr) { 499 if (SndNewChannel(&channel, sampledSynth, initOptions, 0L) != noErr) {
501 SDL_SetError ("Unable to create audio channel"); 500 SDL_SetError("Unable to create audio channel");
502 SDL_free (channel); 501 SDL_free(channel);
503 channel = NULL; 502 channel = NULL;
504 return (-1); 503 return (-1);
505 } 504 }
506 505
507 /* Start playback */ 506 /* Start playback */
508 if (SndPlayDoubleBuffer (channel, (SndDoubleBufferHeaderPtr) & audio_dbh) 507 if (SndPlayDoubleBuffer(channel, (SndDoubleBufferHeaderPtr) & audio_dbh)
509 != noErr) { 508 != noErr) {
510 SDL_SetError ("Unable to play double buffered audio"); 509 SDL_SetError("Unable to play double buffered audio");
511 return (-1); 510 return (-1);
512 } 511 }
513 512
514 return 1; 513 return 1;
515 } 514 }