Mercurial > sdl-ios-xcode
diff 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 |
line wrap: on
line diff
--- a/src/audio/macrom/SDL_romaudio.c Mon May 29 03:53:21 2006 +0000 +++ b/src/audio/macrom/SDL_romaudio.c Mon May 29 04:04:35 2006 +0000 @@ -47,47 +47,47 @@ /* Audio driver functions */ -static void Mac_CloseAudio (_THIS); -static int Mac_OpenAudio (_THIS, SDL_AudioSpec * spec); -static void Mac_LockAudio (_THIS); -static void Mac_UnlockAudio (_THIS); +static void Mac_CloseAudio(_THIS); +static int Mac_OpenAudio(_THIS, SDL_AudioSpec * spec); +static void Mac_LockAudio(_THIS); +static void Mac_UnlockAudio(_THIS); /* Audio driver bootstrap functions */ static int -Audio_Available (void) +Audio_Available(void) { return (1); } static void -Audio_DeleteDevice (SDL_AudioDevice * device) +Audio_DeleteDevice(SDL_AudioDevice * device) { - SDL_free (device->hidden); - SDL_free (device); + SDL_free(device->hidden); + SDL_free(device); } static SDL_AudioDevice * -Audio_CreateDevice (int devindex) +Audio_CreateDevice(int devindex) { SDL_AudioDevice *this; /* Initialize all variables that we clean on shutdown */ - this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); + this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); if (this) { - SDL_memset (this, 0, (sizeof *this)); + SDL_memset(this, 0, (sizeof *this)); this->hidden = (struct SDL_PrivateAudioData *) - SDL_malloc ((sizeof *this->hidden)); + SDL_malloc((sizeof *this->hidden)); } if ((this == NULL) || (this->hidden == NULL)) { - SDL_OutOfMemory (); + SDL_OutOfMemory(); if (this) { - SDL_free (this); + SDL_free(this); } return (0); } - SDL_memset (this->hidden, 0, (sizeof *this->hidden)); + SDL_memset(this->hidden, 0, (sizeof *this->hidden)); /* Set the function pointers */ this->OpenAudio = Mac_OpenAudio; @@ -122,67 +122,67 @@ static volatile Uint32 fill_me = 0; static void -mix_buffer (SDL_AudioDevice * audio, UInt8 * buffer) +mix_buffer(SDL_AudioDevice * audio, UInt8 * buffer) { if (!audio->paused) { #ifdef __MACOSX__ - SDL_mutexP (audio->mixer_lock); + SDL_mutexP(audio->mixer_lock); #endif if (audio->convert.needed) { - audio->spec.callback (audio->spec.userdata, - (Uint8 *) audio->convert.buf, - audio->convert.len); - SDL_ConvertAudio (&audio->convert); + audio->spec.callback(audio->spec.userdata, + (Uint8 *) audio->convert.buf, + audio->convert.len); + SDL_ConvertAudio(&audio->convert); if (audio->convert.len_cvt != audio->spec.size) { /* Uh oh... probably crashes here */ ; } - SDL_memcpy (buffer, audio->convert.buf, audio->convert.len_cvt); + SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt); } else { - audio->spec.callback (audio->spec.userdata, buffer, - audio->spec.size); + audio->spec.callback(audio->spec.userdata, buffer, + audio->spec.size); } #ifdef __MACOSX__ - SDL_mutexV (audio->mixer_lock); + SDL_mutexV(audio->mixer_lock); #endif } - DecrementAtomic ((SInt32 *) & need_to_mix); + DecrementAtomic((SInt32 *) & need_to_mix); } static void -Mac_LockAudio (_THIS) +Mac_LockAudio(_THIS) { - IncrementAtomic ((SInt32 *) & audio_is_locked); + IncrementAtomic((SInt32 *) & audio_is_locked); } static void -Mac_UnlockAudio (_THIS) +Mac_UnlockAudio(_THIS) { SInt32 oldval; - oldval = DecrementAtomic ((SInt32 *) & audio_is_locked); + oldval = DecrementAtomic((SInt32 *) & audio_is_locked); if (oldval != 1) /* != 1 means audio is still locked. */ return; /* Did we miss the chance to mix in an interrupt? Do it now. */ - if (BitAndAtomic (0xFFFFFFFF, (UInt32 *) & need_to_mix)) { + if (BitAndAtomic(0xFFFFFFFF, (UInt32 *) & need_to_mix)) { /* * Note that this could be a problem if you missed an interrupt * while the audio was locked, and get preempted by a second * interrupt here, but that means you locked for way too long anyhow. */ - mix_buffer (this, buffer[fill_me]); + mix_buffer(this, buffer[fill_me]); } } static void -callBackProc (SndChannel * chan, SndCommand * cmd_passed) +callBackProc(SndChannel * chan, SndCommand * cmd_passed) { UInt32 play_me; SndCommand cmd; SDL_AudioDevice *audio = (SDL_AudioDevice *) chan->userInfo; - IncrementAtomic ((SInt32 *) & need_to_mix); + IncrementAtomic((SInt32 *) & need_to_mix); fill_me = cmd_passed->param2; /* buffer that has just finished playing, so fill it */ play_me = !fill_me; /* filled buffer to play _now_ */ @@ -196,16 +196,16 @@ cmd.cmd = bufferCmd; cmd.param1 = 0; cmd.param2 = (long) &header; - SndDoCommand (chan, &cmd, 0); + SndDoCommand(chan, &cmd, 0); - memset (buffer[fill_me], 0, audio->spec.size); + memset(buffer[fill_me], 0, audio->spec.size); /* * if audio device isn't locked, mix the next buffer to be queued in * the memory block that just finished playing. */ - if (!BitAndAtomic (0xFFFFFFFF, (UInt32 *) & audio_is_locked)) { - mix_buffer (audio, buffer[fill_me]); + if (!BitAndAtomic(0xFFFFFFFF, (UInt32 *) & audio_is_locked)) { + mix_buffer(audio, buffer[fill_me]); } /* set this callback to run again when current buffer drains. */ @@ -214,12 +214,12 @@ cmd.param1 = 0; cmd.param2 = play_me; - SndDoCommand (chan, &cmd, 0); + SndDoCommand(chan, &cmd, 0); } } static int -Mac_OpenAudio (_THIS, SDL_AudioSpec * spec) +Mac_OpenAudio(_THIS, SDL_AudioSpec * spec) { SndCallBackUPP callback; @@ -239,17 +239,17 @@ spec->format = AUDIO_S16MSB; break; } - SDL_CalculateAudioSpec (spec); + SDL_CalculateAudioSpec(spec); /* initialize bufferCmd header */ - memset (&header, 0, sizeof (header)); - callback = (SndCallBackUPP) NewSndCallBackUPP (callBackProc); + memset(&header, 0, sizeof(header)); + callback = (SndCallBackUPP) NewSndCallBackUPP(callBackProc); sample_bits = spec->size / spec->samples / spec->channels * 8; #ifdef DEBUG_AUDIO - fprintf (stderr, - "Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n", - spec->format, spec->channels, sample_bits, spec->freq); + fprintf(stderr, + "Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n", + spec->format, spec->channels, sample_bits, spec->freq); #endif /* DEBUG_AUDIO */ header.numChannels = spec->channels; @@ -266,18 +266,18 @@ /* allocate 2 buffers */ for (i = 0; i < 2; i++) { - buffer[i] = (UInt8 *) malloc (sizeof (UInt8) * spec->size); + buffer[i] = (UInt8 *) malloc(sizeof(UInt8) * spec->size); if (buffer[i] == NULL) { - SDL_OutOfMemory (); + SDL_OutOfMemory(); return (-1); } - memset (buffer[i], 0, spec->size); + memset(buffer[i], 0, spec->size); } /* Create the sound manager channel */ - channel = (SndChannelPtr) SDL_malloc (sizeof (*channel)); + channel = (SndChannelPtr) SDL_malloc(sizeof(*channel)); if (channel == NULL) { - SDL_OutOfMemory (); + SDL_OutOfMemory(); return (-1); } if (spec->channels >= 2) { @@ -287,10 +287,9 @@ } channel->userInfo = (long) this; channel->qLength = 128; - if (SndNewChannel (&channel, sampledSynth, initOptions, callback) != - noErr) { - SDL_SetError ("Unable to create audio channel"); - SDL_free (channel); + if (SndNewChannel(&channel, sampledSynth, initOptions, callback) != noErr) { + SDL_SetError("Unable to create audio channel"); + SDL_free(channel); channel = NULL; return (-1); } @@ -301,14 +300,14 @@ cmd.cmd = callBackCmd; cmd.param2 = 0; running = 1; - SndDoCommand (channel, &cmd, 0); + SndDoCommand(channel, &cmd, 0); } return 1; } static void -Mac_CloseAudio (_THIS) +Mac_CloseAudio(_THIS) { int i; @@ -316,13 +315,13 @@ running = 0; if (channel) { - SndDisposeChannel (channel, true); + SndDisposeChannel(channel, true); channel = NULL; } for (i = 0; i < 2; ++i) { if (buffer[i]) { - SDL_free (buffer[i]); + SDL_free(buffer[i]); buffer[i] = NULL; } } @@ -331,13 +330,13 @@ #else /* !TARGET_API_MAC_CARBON && !USE_RYANS_SOUNDCODE */ static void -Mac_LockAudio (_THIS) +Mac_LockAudio(_THIS) { /* no-op. */ } static void -Mac_UnlockAudio (_THIS) +Mac_UnlockAudio(_THIS) { /* no-op. */ } @@ -348,7 +347,7 @@ we're not paused. */ static pascal void -sndDoubleBackProc (SndChannelPtr chan, SndDoubleBufferPtr newbuf) +sndDoubleBackProc(SndChannelPtr chan, SndDoubleBufferPtr newbuf) { SDL_AudioDevice *audio = (SDL_AudioDevice *) newbuf->dbUserInfo[0]; @@ -356,47 +355,47 @@ if (!audio->enabled) { return; } - memset (newbuf->dbSoundData, 0, audio->spec.size); + memset(newbuf->dbSoundData, 0, audio->spec.size); newbuf->dbNumFrames = audio->spec.samples; if (!audio->paused) { if (audio->convert.needed) { - audio->spec.callback (audio->spec.userdata, - (Uint8 *) audio->convert.buf, - audio->convert.len); - SDL_ConvertAudio (&audio->convert); + audio->spec.callback(audio->spec.userdata, + (Uint8 *) audio->convert.buf, + audio->convert.len); + SDL_ConvertAudio(&audio->convert); #if 0 if (audio->convert.len_cvt != audio->spec.size) { /* Uh oh... probably crashes here */ ; } #endif - SDL_memcpy (newbuf->dbSoundData, audio->convert.buf, - audio->convert.len_cvt); + SDL_memcpy(newbuf->dbSoundData, audio->convert.buf, + audio->convert.len_cvt); } else { - audio->spec.callback (audio->spec.userdata, - (Uint8 *) newbuf->dbSoundData, - audio->spec.size); + audio->spec.callback(audio->spec.userdata, + (Uint8 *) newbuf->dbSoundData, + audio->spec.size); } } newbuf->dbFlags |= dbBufferReady; } static int -DoubleBufferAudio_Available (void) +DoubleBufferAudio_Available(void) { int available; NumVersion sndversion; long response; available = 0; - sndversion = SndSoundManagerVersion (); + sndversion = SndSoundManagerVersion(); if (sndversion.majorRev >= 3) { - if (Gestalt (gestaltSoundAttr, &response) == noErr) { + if (Gestalt(gestaltSoundAttr, &response) == noErr) { if ((response & (1 << gestaltSndPlayDoubleBuffer))) { available = 1; } } } else { - if (Gestalt (gestaltSoundAttr, &response) == noErr) { + if (Gestalt(gestaltSoundAttr, &response) == noErr) { if ((response & (1 << gestaltHasASC))) { available = 1; } @@ -406,25 +405,25 @@ } static void -Mac_CloseAudio (_THIS) +Mac_CloseAudio(_THIS) { int i; if (channel != NULL) { /* Clean up the audio channel */ - SndDisposeChannel (channel, true); + SndDisposeChannel(channel, true); channel = NULL; } for (i = 0; i < 2; ++i) { if (audio_buf[i]) { - SDL_free (audio_buf[i]); + SDL_free(audio_buf[i]); audio_buf[i] = NULL; } } } static int -Mac_OpenAudio (_THIS, SDL_AudioSpec * spec) +Mac_OpenAudio(_THIS, SDL_AudioSpec * spec) { SndDoubleBufferHeader2 audio_dbh; int i; @@ -433,8 +432,8 @@ SndDoubleBackUPP doubleBackProc; /* Check to make sure double-buffered audio is available */ - if (!DoubleBufferAudio_Available ()) { - SDL_SetError ("Sound manager doesn't support double-buffering"); + if (!DoubleBufferAudio_Available()) { + SDL_SetError("Sound manager doesn't support double-buffering"); return (-1); } @@ -450,11 +449,11 @@ spec->format = AUDIO_S16MSB; break; } - SDL_CalculateAudioSpec (spec); + SDL_CalculateAudioSpec(spec); /* initialize the double-back header */ - SDL_memset (&audio_dbh, 0, sizeof (audio_dbh)); - doubleBackProc = NewSndDoubleBackProc (sndDoubleBackProc); + SDL_memset(&audio_dbh, 0, sizeof(audio_dbh)); + doubleBackProc = NewSndDoubleBackProc(sndDoubleBackProc); sample_bits = spec->size / spec->samples / spec->channels * 8; audio_dbh.dbhNumChannels = spec->channels; @@ -473,9 +472,9 @@ /* allocate the 2 double-back buffers */ for (i = 0; i < 2; ++i) { - audio_buf[i] = SDL_calloc (1, sizeof (SndDoubleBuffer) + spec->size); + audio_buf[i] = SDL_calloc(1, sizeof(SndDoubleBuffer) + spec->size); if (audio_buf[i] == NULL) { - SDL_OutOfMemory (); + SDL_OutOfMemory(); return (-1); } audio_buf[i]->dbNumFrames = spec->samples; @@ -485,9 +484,9 @@ } /* Create the sound manager channel */ - channel = (SndChannelPtr) SDL_malloc (sizeof (*channel)); + channel = (SndChannelPtr) SDL_malloc(sizeof(*channel)); if (channel == NULL) { - SDL_OutOfMemory (); + SDL_OutOfMemory(); return (-1); } if (spec->channels >= 2) { @@ -497,17 +496,17 @@ } channel->userInfo = 0; channel->qLength = 128; - if (SndNewChannel (&channel, sampledSynth, initOptions, 0L) != noErr) { - SDL_SetError ("Unable to create audio channel"); - SDL_free (channel); + if (SndNewChannel(&channel, sampledSynth, initOptions, 0L) != noErr) { + SDL_SetError("Unable to create audio channel"); + SDL_free(channel); channel = NULL; return (-1); } /* Start playback */ - if (SndPlayDoubleBuffer (channel, (SndDoubleBufferHeaderPtr) & audio_dbh) + if (SndPlayDoubleBuffer(channel, (SndDoubleBufferHeaderPtr) & audio_dbh) != noErr) { - SDL_SetError ("Unable to play double buffered audio"); + SDL_SetError("Unable to play double buffered audio"); return (-1); }