comparison src/audio/macrom/SDL_romaudio.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 f12379c41042
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
24 #if defined(__APPLE__) && defined(__MACH__) 24 #if defined(__APPLE__) && defined(__MACH__)
25 # include <Carbon/Carbon.h> 25 # include <Carbon/Carbon.h>
26 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) 26 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335)
27 # include <Carbon.h> 27 # include <Carbon.h>
28 #else 28 #else
29 # include <Sound.h> /* SoundManager interface */ 29 # include <Sound.h> /* SoundManager interface */
30 # include <Gestalt.h> 30 # include <Gestalt.h>
31 # include <DriverServices.h> 31 # include <DriverServices.h>
32 #endif 32 #endif
33 33
34 #if !defined(NewSndCallBackUPP) && (UNIVERSAL_INTERFACES_VERSION < 0x0335) 34 #if !defined(NewSndCallBackUPP) && (UNIVERSAL_INTERFACES_VERSION < 0x0335)
35 #if !defined(NewSndCallBackProc) /* avoid circular redefinition... */ 35 #if !defined(NewSndCallBackProc) /* avoid circular redefinition... */
36 #define NewSndCallBackUPP NewSndCallBackProc 36 #define NewSndCallBackUPP NewSndCallBackProc
37 #endif 37 #endif
38 #if !defined(NewSndCallBackUPP) 38 #if !defined(NewSndCallBackUPP)
39 #define NewSndCallBackUPP NewSndCallBackProc 39 #define NewSndCallBackUPP NewSndCallBackProc
40 #endif 40 #endif
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 Audio_Available(void) 58 static int
59 { 59 Audio_Available (void)
60 return(1); 60 {
61 } 61 return (1);
62 62 }
63 static void Audio_DeleteDevice(SDL_AudioDevice *device) 63
64 { 64 static void
65 SDL_free(device->hidden); 65 Audio_DeleteDevice (SDL_AudioDevice * device)
66 SDL_free(device); 66 {
67 } 67 SDL_free (device->hidden);
68 68 SDL_free (device);
69 static SDL_AudioDevice *Audio_CreateDevice(int devindex) 69 }
70
71 static SDL_AudioDevice *
72 Audio_CreateDevice (int devindex)
70 { 73 {
71 SDL_AudioDevice *this; 74 SDL_AudioDevice *this;
72 75
73 /* Initialize all variables that we clean on shutdown */ 76 /* Initialize all variables that we clean on shutdown */
74 this = (SDL_AudioDevice *)SDL_malloc(sizeof(SDL_AudioDevice)); 77 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice));
75 if ( this ) { 78 if (this) {
76 SDL_memset(this, 0, (sizeof *this)); 79 SDL_memset (this, 0, (sizeof *this));
77 this->hidden = (struct SDL_PrivateAudioData *) 80 this->hidden = (struct SDL_PrivateAudioData *)
78 SDL_malloc((sizeof *this->hidden)); 81 SDL_malloc ((sizeof *this->hidden));
79 } 82 }
80 if ( (this == NULL) || (this->hidden == NULL) ) { 83 if ((this == NULL) || (this->hidden == NULL)) {
81 SDL_OutOfMemory(); 84 SDL_OutOfMemory ();
82 if ( this ) { 85 if (this) {
83 SDL_free(this); 86 SDL_free (this);
84 } 87 }
85 return(0); 88 return (0);
86 } 89 }
87 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); 90 SDL_memset (this->hidden, 0, (sizeof *this->hidden));
88 91
89 /* Set the function pointers */ 92 /* Set the function pointers */
90 this->OpenAudio = Mac_OpenAudio; 93 this->OpenAudio = Mac_OpenAudio;
91 this->CloseAudio = Mac_CloseAudio; 94 this->CloseAudio = Mac_CloseAudio;
92 this->LockAudio = Mac_LockAudio; 95 this->LockAudio = Mac_LockAudio;
93 this->UnlockAudio = Mac_UnlockAudio; 96 this->UnlockAudio = Mac_UnlockAudio;
94 this->free = Audio_DeleteDevice; 97 this->free = Audio_DeleteDevice;
95 98
96 #ifdef __MACOSX__ /* Mac OS X uses threaded audio, so normal thread code is okay */ 99 #ifdef __MACOSX__ /* Mac OS X uses threaded audio, so normal thread code is okay */
97 this->LockAudio = NULL; 100 this->LockAudio = NULL;
98 this->UnlockAudio = NULL; 101 this->UnlockAudio = NULL;
99 #endif 102 #endif
100 return this; 103 return this;
101 } 104 }
102 105
103 AudioBootStrap SNDMGR_bootstrap = { 106 AudioBootStrap SNDMGR_bootstrap = {
104 "sndmgr", "MacOS SoundManager 3.0", 107 "sndmgr", "MacOS SoundManager 3.0",
105 Audio_Available, Audio_CreateDevice 108 Audio_Available, Audio_CreateDevice
106 }; 109 };
107 110
108 #if defined(TARGET_API_MAC_CARBON) || defined(USE_RYANS_SOUNDCODE) 111 #if defined(TARGET_API_MAC_CARBON) || defined(USE_RYANS_SOUNDCODE)
109 /* This works correctly on Mac OS X */ 112 /* This works correctly on Mac OS X */
110 113
111 #pragma options align=power 114 #pragma options align=power
112 115
113 static volatile SInt32 audio_is_locked = 0; 116 static volatile SInt32 audio_is_locked = 0;
114 static volatile SInt32 need_to_mix = 0; 117 static volatile SInt32 need_to_mix = 0;
115 118
116 static UInt8 *buffer[2]; 119 static UInt8 *buffer[2];
117 static volatile UInt32 running = 0; 120 static volatile UInt32 running = 0;
118 static CmpSoundHeader header; 121 static CmpSoundHeader header;
119 static volatile Uint32 fill_me = 0; 122 static volatile Uint32 fill_me = 0;
120 123
121 static void mix_buffer(SDL_AudioDevice *audio, UInt8 *buffer) 124 static void
122 { 125 mix_buffer (SDL_AudioDevice * audio, UInt8 * buffer)
123 if ( ! audio->paused ) { 126 {
127 if (!audio->paused) {
124 #ifdef __MACOSX__ 128 #ifdef __MACOSX__
125 SDL_mutexP(audio->mixer_lock); 129 SDL_mutexP (audio->mixer_lock);
126 #endif 130 #endif
127 if ( audio->convert.needed ) { 131 if (audio->convert.needed) {
128 audio->spec.callback(audio->spec.userdata, 132 audio->spec.callback (audio->spec.userdata,
129 (Uint8 *)audio->convert.buf,audio->convert.len); 133 (Uint8 *) audio->convert.buf,
130 SDL_ConvertAudio(&audio->convert); 134 audio->convert.len);
131 if ( audio->convert.len_cvt != audio->spec.size ) { 135 SDL_ConvertAudio (&audio->convert);
132 /* Uh oh... probably crashes here */; 136 if (audio->convert.len_cvt != audio->spec.size) {
137 /* Uh oh... probably crashes here */ ;
133 } 138 }
134 SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt); 139 SDL_memcpy (buffer, audio->convert.buf, audio->convert.len_cvt);
135 } else { 140 } else {
136 audio->spec.callback(audio->spec.userdata, buffer, audio->spec.size); 141 audio->spec.callback (audio->spec.userdata, buffer,
142 audio->spec.size);
137 } 143 }
138 #ifdef __MACOSX__ 144 #ifdef __MACOSX__
139 SDL_mutexV(audio->mixer_lock); 145 SDL_mutexV (audio->mixer_lock);
140 #endif 146 #endif
141 } 147 }
142 148
143 DecrementAtomic((SInt32 *) &need_to_mix); 149 DecrementAtomic ((SInt32 *) & need_to_mix);
144 } 150 }
145 151
146 static void Mac_LockAudio(_THIS) 152 static void
147 { 153 Mac_LockAudio (_THIS)
148 IncrementAtomic((SInt32 *) &audio_is_locked); 154 {
149 } 155 IncrementAtomic ((SInt32 *) & audio_is_locked);
150 156 }
151 static void Mac_UnlockAudio(_THIS) 157
158 static void
159 Mac_UnlockAudio (_THIS)
152 { 160 {
153 SInt32 oldval; 161 SInt32 oldval;
154 162
155 oldval = DecrementAtomic((SInt32 *) &audio_is_locked); 163 oldval = DecrementAtomic ((SInt32 *) & audio_is_locked);
156 if ( oldval != 1 ) /* != 1 means audio is still locked. */ 164 if (oldval != 1) /* != 1 means audio is still locked. */
157 return; 165 return;
158 166
159 /* 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. */
160 if ( BitAndAtomic (0xFFFFFFFF, (UInt32 *) &need_to_mix) ) { 168 if (BitAndAtomic (0xFFFFFFFF, (UInt32 *) & need_to_mix)) {
161 /* 169 /*
162 * 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
163 * while the audio was locked, and get preempted by a second 171 * while the audio was locked, and get preempted by a second
164 * 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.
165 */ 173 */
166 mix_buffer (this, buffer[fill_me]); 174 mix_buffer (this, buffer[fill_me]);
167 } 175 }
168 } 176 }
169 177
170 static void callBackProc (SndChannel *chan, SndCommand *cmd_passed ) { 178 static void
171 UInt32 play_me; 179 callBackProc (SndChannel * chan, SndCommand * cmd_passed)
172 SndCommand cmd; 180 {
173 SDL_AudioDevice *audio = (SDL_AudioDevice *)chan->userInfo; 181 UInt32 play_me;
174 182 SndCommand cmd;
175 IncrementAtomic((SInt32 *) &need_to_mix); 183 SDL_AudioDevice *audio = (SDL_AudioDevice *) chan->userInfo;
176 184
177 fill_me = cmd_passed->param2; /* buffer that has just finished playing, so fill it */ 185 IncrementAtomic ((SInt32 *) & need_to_mix);
178 play_me = ! fill_me; /* filled buffer to play _now_ */ 186
179 187 fill_me = cmd_passed->param2; /* buffer that has just finished playing, so fill it */
180 if ( ! audio->enabled ) { 188 play_me = !fill_me; /* filled buffer to play _now_ */
181 return; 189
182 } 190 if (!audio->enabled) {
183 191 return;
184 /* queue previously mixed buffer for playback. */ 192 }
185 header.samplePtr = (Ptr)buffer[play_me]; 193
186 cmd.cmd = bufferCmd; 194 /* queue previously mixed buffer for playback. */
187 cmd.param1 = 0; 195 header.samplePtr = (Ptr) buffer[play_me];
188 cmd.param2 = (long)&header; 196 cmd.cmd = bufferCmd;
189 SndDoCommand (chan, &cmd, 0); 197 cmd.param1 = 0;
190 198 cmd.param2 = (long) &header;
191 memset (buffer[fill_me], 0, audio->spec.size); 199 SndDoCommand (chan, &cmd, 0);
192 200
193 /* 201 memset (buffer[fill_me], 0, audio->spec.size);
194 * if audio device isn't locked, mix the next buffer to be queued in 202
195 * the memory block that just finished playing. 203 /*
196 */ 204 * if audio device isn't locked, mix the next buffer to be queued in
197 if ( ! BitAndAtomic(0xFFFFFFFF, (UInt32 *) &audio_is_locked) ) { 205 * the memory block that just finished playing.
198 mix_buffer (audio, buffer[fill_me]); 206 */
199 } 207 if (!BitAndAtomic (0xFFFFFFFF, (UInt32 *) & audio_is_locked)) {
200 208 mix_buffer (audio, buffer[fill_me]);
201 /* set this callback to run again when current buffer drains. */ 209 }
202 if ( running ) { 210
203 cmd.cmd = callBackCmd; 211 /* set this callback to run again when current buffer drains. */
204 cmd.param1 = 0; 212 if (running) {
205 cmd.param2 = play_me; 213 cmd.cmd = callBackCmd;
206 214 cmd.param1 = 0;
207 SndDoCommand (chan, &cmd, 0); 215 cmd.param2 = play_me;
208 } 216
209 } 217 SndDoCommand (chan, &cmd, 0);
210 218 }
211 static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) { 219 }
212 220
213 SndCallBackUPP callback; 221 static int
214 int sample_bits; 222 Mac_OpenAudio (_THIS, SDL_AudioSpec * spec)
215 int i; 223 {
216 long initOptions; 224
217 225 SndCallBackUPP callback;
218 /* Very few conversions are required, but... */ 226 int sample_bits;
227 int i;
228 long initOptions;
229
230 /* Very few conversions are required, but... */
219 switch (spec->format) { 231 switch (spec->format) {
220 case AUDIO_S8: 232 case AUDIO_S8:
221 spec->format = AUDIO_U8; 233 spec->format = AUDIO_U8;
222 break; 234 break;
223 case AUDIO_U16LSB: 235 case AUDIO_U16LSB:
224 spec->format = AUDIO_S16LSB; 236 spec->format = AUDIO_S16LSB;
225 break; 237 break;
226 case AUDIO_U16MSB: 238 case AUDIO_U16MSB:
227 spec->format = AUDIO_S16MSB; 239 spec->format = AUDIO_S16MSB;
228 break; 240 break;
229 } 241 }
230 SDL_CalculateAudioSpec(spec); 242 SDL_CalculateAudioSpec (spec);
231 243
232 /* initialize bufferCmd header */ 244 /* initialize bufferCmd header */
233 memset (&header, 0, sizeof(header)); 245 memset (&header, 0, sizeof (header));
234 callback = (SndCallBackUPP) NewSndCallBackUPP (callBackProc); 246 callback = (SndCallBackUPP) NewSndCallBackUPP (callBackProc);
235 sample_bits = spec->size / spec->samples / spec->channels * 8; 247 sample_bits = spec->size / spec->samples / spec->channels * 8;
236 248
237 #ifdef DEBUG_AUDIO 249 #ifdef DEBUG_AUDIO
238 fprintf(stderr, 250 fprintf (stderr,
239 "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",
240 spec->format, spec->channels, sample_bits, spec->freq); 252 spec->format, spec->channels, sample_bits, spec->freq);
241 #endif /* DEBUG_AUDIO */ 253 #endif /* DEBUG_AUDIO */
242 254
243 header.numChannels = spec->channels; 255 header.numChannels = spec->channels;
244 header.sampleSize = sample_bits; 256 header.sampleSize = sample_bits;
245 header.sampleRate = spec->freq << 16; 257 header.sampleRate = spec->freq << 16;
246 header.numFrames = spec->samples; 258 header.numFrames = spec->samples;
247 header.encode = cmpSH; 259 header.encode = cmpSH;
248 260
249 /* Note that we install the 16bitLittleEndian Converter if needed. */ 261 /* Note that we install the 16bitLittleEndian Converter if needed. */
250 if ( spec->format == 0x8010 ) { 262 if (spec->format == 0x8010) {
251 header.compressionID = fixedCompression; 263 header.compressionID = fixedCompression;
252 header.format = k16BitLittleEndianFormat; 264 header.format = k16BitLittleEndianFormat;
253 } 265 }
254 266
255 /* allocate 2 buffers */ 267 /* allocate 2 buffers */
256 for (i=0; i<2; i++) { 268 for (i = 0; i < 2; i++) {
257 buffer[i] = (UInt8*)malloc (sizeof(UInt8) * spec->size); 269 buffer[i] = (UInt8 *) malloc (sizeof (UInt8) * spec->size);
258 if (buffer[i] == NULL) { 270 if (buffer[i] == NULL) {
259 SDL_OutOfMemory(); 271 SDL_OutOfMemory ();
260 return (-1); 272 return (-1);
261 } 273 }
262 memset (buffer[i], 0, spec->size); 274 memset (buffer[i], 0, spec->size);
263 } 275 }
264 276
265 /* Create the sound manager channel */ 277 /* Create the sound manager channel */
266 channel = (SndChannelPtr)SDL_malloc(sizeof(*channel)); 278 channel = (SndChannelPtr) SDL_malloc (sizeof (*channel));
267 if ( channel == NULL ) { 279 if (channel == NULL) {
268 SDL_OutOfMemory(); 280 SDL_OutOfMemory ();
269 return(-1); 281 return (-1);
270 } 282 }
271 if ( spec->channels >= 2 ) { 283 if (spec->channels >= 2) {
272 initOptions = initStereo; 284 initOptions = initStereo;
273 } else { 285 } else {
274 initOptions = initMono; 286 initOptions = initMono;
275 } 287 }
276 channel->userInfo = (long)this; 288 channel->userInfo = (long) this;
277 channel->qLength = 128; 289 channel->qLength = 128;
278 if ( SndNewChannel(&channel, sampledSynth, initOptions, callback) != noErr ) { 290 if (SndNewChannel (&channel, sampledSynth, initOptions, callback) !=
279 SDL_SetError("Unable to create audio channel"); 291 noErr) {
280 SDL_free(channel); 292 SDL_SetError ("Unable to create audio channel");
293 SDL_free (channel);
281 channel = NULL; 294 channel = NULL;
282 return(-1); 295 return (-1);
283 } 296 }
284 297
285 /* start playback */ 298 /* start playback */
286 { 299 {
287 SndCommand cmd; 300 SndCommand cmd;
288 cmd.cmd = callBackCmd; 301 cmd.cmd = callBackCmd;
289 cmd.param2 = 0; 302 cmd.param2 = 0;
290 running = 1; 303 running = 1;
291 SndDoCommand (channel, &cmd, 0); 304 SndDoCommand (channel, &cmd, 0);
292 } 305 }
293 306
294 return 1; 307 return 1;
295 } 308 }
296 309
297 static void Mac_CloseAudio(_THIS) { 310 static void
298 311 Mac_CloseAudio (_THIS)
299 int i; 312 {
300 313
301 running = 0; 314 int i;
302 315
303 if (channel) { 316 running = 0;
304 SndDisposeChannel (channel, true); 317
305 channel = NULL; 318 if (channel) {
306 } 319 SndDisposeChannel (channel, true);
307 320 channel = NULL;
308 for ( i=0; i<2; ++i ) { 321 }
309 if ( buffer[i] ) { 322
310 SDL_free(buffer[i]); 323 for (i = 0; i < 2; ++i) {
324 if (buffer[i]) {
325 SDL_free (buffer[i]);
311 buffer[i] = NULL; 326 buffer[i] = NULL;
312 } 327 }
313 } 328 }
314 } 329 }
315 330
316 #else /* !TARGET_API_MAC_CARBON && !USE_RYANS_SOUNDCODE */ 331 #else /* !TARGET_API_MAC_CARBON && !USE_RYANS_SOUNDCODE */
317 332
318 static void Mac_LockAudio(_THIS) 333 static void
334 Mac_LockAudio (_THIS)
319 { 335 {
320 /* no-op. */ 336 /* no-op. */
321 } 337 }
322 338
323 static void Mac_UnlockAudio(_THIS) 339 static void
340 Mac_UnlockAudio (_THIS)
324 { 341 {
325 /* no-op. */ 342 /* no-op. */
326 } 343 }
327 344
328 345
329 /* This function is called by Sound Manager when it has exhausted one of 346 /* This function is called by Sound Manager when it has exhausted one of
330 the buffers, so we'll zero it to silence and fill it with audio if 347 the buffers, so we'll zero it to silence and fill it with audio if
331 we're not paused. 348 we're not paused.
332 */ 349 */
333 static pascal 350 static pascal void
334 void sndDoubleBackProc (SndChannelPtr chan, SndDoubleBufferPtr newbuf) 351 sndDoubleBackProc (SndChannelPtr chan, SndDoubleBufferPtr newbuf)
335 { 352 {
336 SDL_AudioDevice *audio = (SDL_AudioDevice *)newbuf->dbUserInfo[0]; 353 SDL_AudioDevice *audio = (SDL_AudioDevice *) newbuf->dbUserInfo[0];
337 354
338 /* If audio is quitting, don't do anything */ 355 /* If audio is quitting, don't do anything */
339 if ( ! audio->enabled ) { 356 if (!audio->enabled) {
340 return; 357 return;
341 } 358 }
342 memset (newbuf->dbSoundData, 0, audio->spec.size); 359 memset (newbuf->dbSoundData, 0, audio->spec.size);
343 newbuf->dbNumFrames = audio->spec.samples; 360 newbuf->dbNumFrames = audio->spec.samples;
344 if ( ! audio->paused ) { 361 if (!audio->paused) {
345 if ( audio->convert.needed ) { 362 if (audio->convert.needed) {
346 audio->spec.callback(audio->spec.userdata, 363 audio->spec.callback (audio->spec.userdata,
347 (Uint8 *)audio->convert.buf,audio->convert.len); 364 (Uint8 *) audio->convert.buf,
348 SDL_ConvertAudio(&audio->convert); 365 audio->convert.len);
366 SDL_ConvertAudio (&audio->convert);
349 #if 0 367 #if 0
350 if ( audio->convert.len_cvt != audio->spec.size ) { 368 if (audio->convert.len_cvt != audio->spec.size) {
351 /* Uh oh... probably crashes here */; 369 /* Uh oh... probably crashes here */ ;
352 } 370 }
353 #endif 371 #endif
354 SDL_memcpy(newbuf->dbSoundData, audio->convert.buf, 372 SDL_memcpy (newbuf->dbSoundData, audio->convert.buf,
355 audio->convert.len_cvt); 373 audio->convert.len_cvt);
356 } else { 374 } else {
357 audio->spec.callback(audio->spec.userdata, 375 audio->spec.callback (audio->spec.userdata,
358 (Uint8 *)newbuf->dbSoundData, audio->spec.size); 376 (Uint8 *) newbuf->dbSoundData,
359 } 377 audio->spec.size);
360 } 378 }
361 newbuf->dbFlags |= dbBufferReady; 379 }
362 } 380 newbuf->dbFlags |= dbBufferReady;
363 381 }
364 static int DoubleBufferAudio_Available(void) 382
383 static int
384 DoubleBufferAudio_Available (void)
365 { 385 {
366 int available; 386 int available;
367 NumVersion sndversion; 387 NumVersion sndversion;
368 long response; 388 long response;
369 389
370 available = 0; 390 available = 0;
371 sndversion = SndSoundManagerVersion(); 391 sndversion = SndSoundManagerVersion ();
372 if ( sndversion.majorRev >= 3 ) { 392 if (sndversion.majorRev >= 3) {
373 if ( Gestalt(gestaltSoundAttr, &response) == noErr ) { 393 if (Gestalt (gestaltSoundAttr, &response) == noErr) {
374 if ( (response & (1 << gestaltSndPlayDoubleBuffer)) ) { 394 if ((response & (1 << gestaltSndPlayDoubleBuffer))) {
375 available = 1; 395 available = 1;
376 } 396 }
377 } 397 }
378 } else { 398 } else {
379 if ( Gestalt(gestaltSoundAttr, &response) == noErr ) { 399 if (Gestalt (gestaltSoundAttr, &response) == noErr) {
380 if ( (response & (1 << gestaltHasASC)) ) { 400 if ((response & (1 << gestaltHasASC))) {
381 available = 1; 401 available = 1;
382 } 402 }
383 } 403 }
384 } 404 }
385 return(available); 405 return (available);
386 } 406 }
387 407
388 static void Mac_CloseAudio(_THIS) 408 static void
409 Mac_CloseAudio (_THIS)
389 { 410 {
390 int i; 411 int i;
391 412
392 if ( channel != NULL ) { 413 if (channel != NULL) {
393 /* Clean up the audio channel */ 414 /* Clean up the audio channel */
394 SndDisposeChannel(channel, true); 415 SndDisposeChannel (channel, true);
395 channel = NULL; 416 channel = NULL;
396 } 417 }
397 for ( i=0; i<2; ++i ) { 418 for (i = 0; i < 2; ++i) {
398 if ( audio_buf[i] ) { 419 if (audio_buf[i]) {
399 SDL_free(audio_buf[i]); 420 SDL_free (audio_buf[i]);
400 audio_buf[i] = NULL; 421 audio_buf[i] = NULL;
401 } 422 }
402 } 423 }
403 } 424 }
404 425
405 static int Mac_OpenAudio(_THIS, SDL_AudioSpec *spec) 426 static int
427 Mac_OpenAudio (_THIS, SDL_AudioSpec * spec)
406 { 428 {
407 SndDoubleBufferHeader2 audio_dbh; 429 SndDoubleBufferHeader2 audio_dbh;
408 int i; 430 int i;
409 long initOptions; 431 long initOptions;
410 int sample_bits; 432 int sample_bits;
411 SndDoubleBackUPP doubleBackProc; 433 SndDoubleBackUPP doubleBackProc;
412 434
413 /* Check to make sure double-buffered audio is available */ 435 /* Check to make sure double-buffered audio is available */
414 if ( ! DoubleBufferAudio_Available() ) { 436 if (!DoubleBufferAudio_Available ()) {
415 SDL_SetError("Sound manager doesn't support double-buffering"); 437 SDL_SetError ("Sound manager doesn't support double-buffering");
416 return(-1); 438 return (-1);
417 } 439 }
418 440
419 /* Very few conversions are required, but... */ 441 /* Very few conversions are required, but... */
420 switch (spec->format) { 442 switch (spec->format) {
421 case AUDIO_S8: 443 case AUDIO_S8:
422 spec->format = AUDIO_U8; 444 spec->format = AUDIO_U8;
423 break; 445 break;
424 case AUDIO_U16LSB: 446 case AUDIO_U16LSB:
425 spec->format = AUDIO_S16LSB; 447 spec->format = AUDIO_S16LSB;
426 break; 448 break;
427 case AUDIO_U16MSB: 449 case AUDIO_U16MSB:
428 spec->format = AUDIO_S16MSB; 450 spec->format = AUDIO_S16MSB;
429 break; 451 break;
430 } 452 }
431 SDL_CalculateAudioSpec(spec); 453 SDL_CalculateAudioSpec (spec);
432 454
433 /* initialize the double-back header */ 455 /* initialize the double-back header */
434 SDL_memset(&audio_dbh, 0, sizeof(audio_dbh)); 456 SDL_memset (&audio_dbh, 0, sizeof (audio_dbh));
435 doubleBackProc = NewSndDoubleBackProc (sndDoubleBackProc); 457 doubleBackProc = NewSndDoubleBackProc (sndDoubleBackProc);
436 sample_bits = spec->size / spec->samples / spec->channels * 8; 458 sample_bits = spec->size / spec->samples / spec->channels * 8;
437 459
438 audio_dbh.dbhNumChannels = spec->channels; 460 audio_dbh.dbhNumChannels = spec->channels;
439 audio_dbh.dbhSampleSize = sample_bits; 461 audio_dbh.dbhSampleSize = sample_bits;
440 audio_dbh.dbhCompressionID = 0; 462 audio_dbh.dbhCompressionID = 0;
441 audio_dbh.dbhPacketSize = 0; 463 audio_dbh.dbhPacketSize = 0;
442 audio_dbh.dbhSampleRate = spec->freq << 16; 464 audio_dbh.dbhSampleRate = spec->freq << 16;
443 audio_dbh.dbhDoubleBack = doubleBackProc; 465 audio_dbh.dbhDoubleBack = doubleBackProc;
444 audio_dbh.dbhFormat = 0; 466 audio_dbh.dbhFormat = 0;
445 467
446 /* Note that we install the 16bitLittleEndian Converter if needed. */ 468 /* Note that we install the 16bitLittleEndian Converter if needed. */
447 if ( spec->format == 0x8010 ) { 469 if (spec->format == 0x8010) {
448 audio_dbh.dbhCompressionID = fixedCompression; 470 audio_dbh.dbhCompressionID = fixedCompression;
449 audio_dbh.dbhFormat = k16BitLittleEndianFormat; 471 audio_dbh.dbhFormat = k16BitLittleEndianFormat;
450 } 472 }
451 473
452 /* allocate the 2 double-back buffers */ 474 /* allocate the 2 double-back buffers */
453 for ( i=0; i<2; ++i ) { 475 for (i = 0; i < 2; ++i) {
454 audio_buf[i] = SDL_calloc(1, sizeof(SndDoubleBuffer)+spec->size); 476 audio_buf[i] = SDL_calloc (1, sizeof (SndDoubleBuffer) + spec->size);
455 if ( audio_buf[i] == NULL ) { 477 if (audio_buf[i] == NULL) {
456 SDL_OutOfMemory(); 478 SDL_OutOfMemory ();
457 return(-1); 479 return (-1);
458 } 480 }
459 audio_buf[i]->dbNumFrames = spec->samples; 481 audio_buf[i]->dbNumFrames = spec->samples;
460 audio_buf[i]->dbFlags = dbBufferReady; 482 audio_buf[i]->dbFlags = dbBufferReady;
461 audio_buf[i]->dbUserInfo[0] = (long)this; 483 audio_buf[i]->dbUserInfo[0] = (long) this;
462 audio_dbh.dbhBufferPtr[i] = audio_buf[i]; 484 audio_dbh.dbhBufferPtr[i] = audio_buf[i];
463 } 485 }
464 486
465 /* Create the sound manager channel */ 487 /* Create the sound manager channel */
466 channel = (SndChannelPtr)SDL_malloc(sizeof(*channel)); 488 channel = (SndChannelPtr) SDL_malloc (sizeof (*channel));
467 if ( channel == NULL ) { 489 if (channel == NULL) {
468 SDL_OutOfMemory(); 490 SDL_OutOfMemory ();
469 return(-1); 491 return (-1);
470 } 492 }
471 if ( spec->channels >= 2 ) { 493 if (spec->channels >= 2) {
472 initOptions = initStereo; 494 initOptions = initStereo;
473 } else { 495 } else {
474 initOptions = initMono; 496 initOptions = initMono;
475 } 497 }
476 channel->userInfo = 0; 498 channel->userInfo = 0;
477 channel->qLength = 128; 499 channel->qLength = 128;
478 if ( SndNewChannel(&channel, sampledSynth, initOptions, 0L) != noErr ) { 500 if (SndNewChannel (&channel, sampledSynth, initOptions, 0L) != noErr) {
479 SDL_SetError("Unable to create audio channel"); 501 SDL_SetError ("Unable to create audio channel");
480 SDL_free(channel); 502 SDL_free (channel);
481 channel = NULL; 503 channel = NULL;
482 return(-1); 504 return (-1);
483 } 505 }
484 506
485 /* Start playback */ 507 /* Start playback */
486 if ( SndPlayDoubleBuffer(channel, (SndDoubleBufferHeaderPtr)&audio_dbh) 508 if (SndPlayDoubleBuffer (channel, (SndDoubleBufferHeaderPtr) & audio_dbh)
487 != noErr ) { 509 != noErr) {
488 SDL_SetError("Unable to play double buffered audio"); 510 SDL_SetError ("Unable to play double buffered audio");
489 return(-1); 511 return (-1);
490 } 512 }
491 513
492 return 1; 514 return 1;
493 } 515 }
494 516
495 #endif /* TARGET_API_MAC_CARBON || USE_RYANS_SOUNDCODE */ 517 #endif /* TARGET_API_MAC_CARBON || USE_RYANS_SOUNDCODE */
496 518 /* vi: set ts=4 sw=4 expandtab: */