diff --git a/examples/playmus.c b/examples/playmus.c index 70c529170..85e5fc274 100644 --- a/examples/playmus.c +++ b/examples/playmus.c @@ -74,7 +74,7 @@ static void Menu(void) printf("Available commands: (p)ause (r)esume (h)alt volume(v#) > "); fflush(stdin); if (scanf("%s",buf) == 1) { - switch(buf[0]){ + switch(buf[0]) { #if defined(SEEK_TEST) case '0': Mix_SetMusicPosition(0); break; case '1': Mix_SetMusicPosition(10);break; @@ -104,9 +104,9 @@ static void Menu(void) static void IntHandler(int sig) { switch (sig) { - case SIGINT: - next_track++; - break; + case SIGINT: + next_track++; + break; } } #endif @@ -134,7 +134,7 @@ int main(int argc, char *argv[]) spec.channels = MIX_DEFAULT_CHANNELS; /* Check command line usage */ - for (i=1; argv[i] && (*argv[i] == '-'); ++i) { + for (i = 1; argv[i] && (*argv[i] == '-'); ++i) { if ((SDL_strcmp(argv[i], "-r") == 0) && argv[i+1]) { ++i; spec.freq = SDL_atoi(argv[i]); @@ -170,18 +170,18 @@ int main(int argc, char *argv[]) rwops = 1; } else { Usage(argv[0]); - return(1); + return 1; } } - if (! argv[i]) { + if (!argv[i]) { Usage(argv[0]); - return(1); + return 1; } /* Initialize the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { SDL_Log("Couldn't initialize SDL: %s\n",SDL_GetError()); - return(255); + return 255; } #ifdef HAVE_SIGNAL_H @@ -190,10 +190,9 @@ int main(int argc, char *argv[]) #endif /* Open the audio device */ - if (Mix_OpenAudio(0, &spec) < 0) { SDL_Log("Couldn't open audio: %s\n", SDL_GetError()); - return(2); + return 2; } else { Mix_QuerySpec(&spec.freq, &spec.format, &spec.channels); SDL_Log("Opened audio at %d Hz %d bit%s %s audio buffer\n", spec.freq, @@ -219,8 +218,7 @@ int main(int argc, char *argv[]) music = Mix_LoadMUS(argv[i]); } if (music == NULL) { - SDL_Log("Couldn't load %s: %s\n", - argv[i], SDL_GetError()); + SDL_Log("Couldn't load %s: %s\n", argv[i], SDL_GetError()); CleanUp(2); } @@ -292,9 +290,9 @@ int main(int argc, char *argv[]) } Mix_FadeInMusic(music,looping,2000); while (!next_track && (Mix_PlayingMusic() || Mix_PausedMusic())) { - if(interactive) + if (interactive) { Menu(); - else { + } else { current_position = Mix_GetMusicPosition(music); if (current_position >= 0.0) { printf("Position: %g seconds \r", current_position); @@ -308,7 +306,9 @@ int main(int argc, char *argv[]) /* If the user presses Ctrl-C more than once, exit. */ SDL_Delay(500); - if (next_track > 1) break; + if (next_track > 1) { + break; + } i++; } diff --git a/examples/playwave.c b/examples/playwave.c index 2090388ab..b66223f02 100644 --- a/examples/playwave.c +++ b/examples/playwave.c @@ -147,9 +147,9 @@ static void SDLCALL channel_complete_callback (int chan) static int still_playing(void) { #ifdef TEST_MIX_CHANNELFINISHED - return(!channel_is_done); + return !channel_is_done; #else - return(Mix_Playing(0)); + return Mix_Playing(0); #endif } @@ -164,7 +164,7 @@ static void do_panning_update(void) static int panningok = 1; static Uint32 next_panning_update = 0; - if ((panningok) && (SDL_GetTicks() >= next_panning_update)) { + if (panningok && (SDL_GetTicks() >= next_panning_update)) { panningok = Mix_SetPanning(0, leftvol, rightvol); if (!panningok) { SDL_Log("Mix_SetPanning(0, %d, %d) failed!\n", @@ -235,7 +235,7 @@ static void do_position_update(void) static int positionok = 1; static Uint32 next_position_update = 0; - if ((positionok) && (SDL_GetTicks() >= next_position_update)) { + if (positionok && (SDL_GetTicks() >= next_position_update)) { positionok = Mix_SetPosition(0, angle, (Uint8)distance); if (!positionok) { SDL_Log("Mix_SetPosition(0, %d, %d) failed!\n", @@ -377,7 +377,7 @@ int main(int argc, char *argv[]) spec.channels = MIX_DEFAULT_CHANNELS; /* Check command line usage */ - for (i=1; argv[i] && (*argv[i] == '-'); ++i) { + for (i = 1; argv[i] && (*argv[i] == '-'); ++i) { if ((SDL_strcmp(argv[i], "-r") == 0) && argv[i+1]) { ++i; spec.freq = SDL_atoi(argv[i]); @@ -405,18 +405,18 @@ int main(int argc, char *argv[]) reverse_sample = 1; } else { Usage(argv[0]); - return(1); + return 1; } } - if (! argv[i]) { + if (!argv[i]) { Usage(argv[0]); - return(1); + return 1; } /* Initialize the SDL library */ if (SDL_Init(SDL_INIT_AUDIO) < 0) { SDL_Log("Couldn't initialize SDL: %s\n",SDL_GetError()); - return(255); + return 255; } #ifdef HAVE_SIGNAL_H signal(SIGINT, CleanUp); @@ -453,8 +453,7 @@ int main(int argc, char *argv[]) /* Load the requested wave file */ g_wave = Mix_LoadWAV(argv[i]); if (g_wave == NULL) { - SDL_Log("Couldn't load %s: %s\n", - argv[i], SDL_GetError()); + SDL_Log("Couldn't load %s: %s\n", argv[i], SDL_GetError()); CleanUp(2); } diff --git a/src/codecs/load_aiff.c b/src/codecs/load_aiff.c index e2001094b..8bea7a44c 100644 --- a/src/codecs/load_aiff.c +++ b/src/codecs/load_aiff.c @@ -65,11 +65,11 @@ static Uint32 SANE_to_Uint32 (Uint8 *sanebuf) SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, SDL_bool freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len) { - SDL_bool was_error = SDL_TRUE; int found_SSND; int found_COMM; int found_VHDR; int found_BODY; + SDL_bool was_error = SDL_TRUE; Sint64 start = 0; Uint32 chunk_type; @@ -146,9 +146,11 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, SDL_bool freesrc, goto done; } next_chunk = SDL_RWtell(src) + chunk_length; + /* Paranoia to avoid infinite loops */ - if (chunk_length == 0) + if (chunk_length == 0) { break; + } switch (chunk_type) { case SSND: diff --git a/src/codecs/load_voc.c b/src/codecs/load_voc.c index 0bc285828..82f21cd8b 100644 --- a/src/codecs/load_voc.c +++ b/src/codecs/load_voc.c @@ -88,24 +88,27 @@ static int voc_check_header(SDL_RWops *src) SDL_RWseek(src, 0, SDL_RW_SEEK_SET); - if (SDL_RWread(src, signature, sizeof(signature)) != sizeof(signature)) - return(0); + if (SDL_RWread(src, signature, sizeof(signature)) != sizeof(signature)) { + return 0; + } if (SDL_memcmp(signature, "Creative Voice File\032", sizeof(signature)) != 0) { SDL_SetError("Unrecognized file type (not VOC)"); - return(0); + return 0; } /* get the offset where the first datablock is located */ - if (SDL_RWread(src, &datablockofs, sizeof(Uint16)) != sizeof(Uint16)) - return(0); + if (SDL_RWread(src, &datablockofs, sizeof(Uint16)) != sizeof(Uint16)) { + return 0; + } datablockofs = SDL_SwapLE16(datablockofs); - if (SDL_RWseek(src, datablockofs, SDL_RW_SEEK_SET) != datablockofs) - return(0); + if (SDL_RWseek(src, datablockofs, SDL_RW_SEEK_SET) != datablockofs) { + return 0; + } - return(1); /* success! */ + return 1; /* success! */ } /* voc_check_header */ @@ -122,38 +125,37 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec) unsigned int i; v->silent = 0; - while (v->rest == 0) - { - if (SDL_RWread(src, &block, sizeof(block)) != sizeof(block)) + while (v->rest == 0) { + if (SDL_RWread(src, &block, sizeof(block)) != sizeof(block)) { return 1; /* assume that's the end of the file. */ + } - if (block == VOC_TERM) + if (block == VOC_TERM) { return 1; + } - if (SDL_RWread(src, bits24, sizeof(bits24)) != sizeof(bits24)) + if (SDL_RWread(src, bits24, sizeof(bits24)) != sizeof(bits24)) { return 1; /* assume that's the end of the file. */ + } /* Size is an 24-bit value. Ugh. */ sblen = (Uint32)((bits24[0]) | (bits24[1] << 8) | (bits24[2] << 16)); - switch(block) - { + switch(block) { case VOC_DATA: - if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) + if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) { return 0; + } /* When DATA block preceeded by an EXTENDED */ /* block, the DATA blocks rate value is invalid */ - if (!v->has_extended) - { - if (uc == 0) - { + if (!v->has_extended) { + if (uc == 0) { SDL_SetError("VOC Sample rate is zero?"); return 0; } - if ((v->rate != VOC_BAD_RATE) && (uc != v->rate)) - { + if ((v->rate != VOC_BAD_RATE) && (uc != v->rate)) { SDL_SetError("VOC sample rate codes differ"); return 0; } @@ -163,11 +165,11 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec) v->channels = 1; } - if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) + if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) { return 0; + } - if (uc != 0) - { + if (uc != 0) { SDL_SetError("VOC decoder only interprets 8-bit data"); return 0; } @@ -178,27 +180,26 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec) return 1; case VOC_DATA_16: - if (SDL_RWread(src, &new_rate_long, sizeof(new_rate_long)) != sizeof(new_rate_long)) + if (SDL_RWread(src, &new_rate_long, sizeof(new_rate_long)) != sizeof(new_rate_long)) { return 0; + } new_rate_long = SDL_SwapLE32(new_rate_long); - if (new_rate_long == 0) - { + if (new_rate_long == 0) { SDL_SetError("VOC Sample rate is zero?"); return 0; } - if ((v->rate != VOC_BAD_RATE) && (new_rate_long != v->rate)) - { + if ((v->rate != VOC_BAD_RATE) && (new_rate_long != v->rate)) { SDL_SetError("VOC sample rate codes differ"); return 0; } v->rate = new_rate_long; spec->freq = (int)new_rate_long; - if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) + if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) { return 0; + } - switch (uc) - { + switch (uc) { case 8: v->size = ST_SIZE_BYTE; break; case 16: v->size = ST_SIZE_WORD; break; default: @@ -206,11 +207,13 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec) return 0; } - if (SDL_RWread(src, &v->channels, sizeof(Uint8)) != sizeof(Uint8)) + if (SDL_RWread(src, &v->channels, sizeof(Uint8)) != sizeof(Uint8)) { return 0; + } - if (SDL_RWread(src, trash, 6) != 6) + if (SDL_RWread(src, trash, 6) != 6) { return 0; + } v->rest = sblen - 12; return 1; @@ -220,14 +223,15 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec) return 1; case VOC_SILENCE: - if (SDL_RWread(src, &period, sizeof(period)) != sizeof(period)) + if (SDL_RWread(src, &period, sizeof(period)) != sizeof(period)) { return 0; + } period = SDL_SwapLE16(period); - if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) + if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) { return 0; - if (uc == 0) - { + } + if (uc == 0) { SDL_SetError("VOC silence sample rate is zero"); return 0; } @@ -247,10 +251,10 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec) case VOC_LOOP: case VOC_LOOPEND: - for(i = 0; i < sblen; i++) /* skip repeat loops. */ - { - if (SDL_RWread(src, trash, sizeof(Uint8)) != sizeof(Uint8)) + for (i = 0; i < sblen; i++) { /* skip repeat loops. */ + if (SDL_RWread(src, trash, sizeof(Uint8)) != sizeof(Uint8)) { return 0; + } } break; @@ -260,60 +264,61 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec) /* value from the extended block and not the */ /* data block. */ v->has_extended = 1; - if (SDL_RWread(src, &new_rate_short, sizeof(new_rate_short)) != sizeof(new_rate_short)) + if (SDL_RWread(src, &new_rate_short, sizeof(new_rate_short)) != sizeof(new_rate_short)) { return 0; + } new_rate_short = SDL_SwapLE16(new_rate_short); - if (new_rate_short == 0) - { + if (new_rate_short == 0) { SDL_SetError("VOC sample rate is zero"); return 0; } - if ((v->rate != VOC_BAD_RATE) && (new_rate_short != v->rate)) - { + if ((v->rate != VOC_BAD_RATE) && (new_rate_short != v->rate)) { SDL_SetError("VOC sample rate codes differ"); return 0; } v->rate = new_rate_short; - if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) + if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) { return 0; + } - if (uc != 0) - { + if (uc != 0) { SDL_SetError("VOC decoder only interprets 8-bit data"); return 0; } - if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) + if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) { return 0; + } - if (uc) - spec->channels = 2; /* Stereo */ + if (uc) /* Stereo */ + spec->channels = 2; /* VOC_EXTENDED may be read before spec->channels inited: */ else spec->channels = 1; /* Needed number of channels before finishing compute for rate */ - spec->freq = (256000000L/(65536L - v->rate))/spec->channels; + spec->freq = (256000000L / (65536L - v->rate)) / spec->channels; /* An extended block must be followed by a data */ /* block to be valid so loop back to top so it */ /* can be grabed. */ continue; case VOC_MARKER: - if (SDL_RWread(src, trash, 2) != 2) + if (SDL_RWread(src, trash, 2) != 2) { return 0; - + } /* fallthrough */ default: /* text block or other krapola. */ - for(i = 0; i < sblen; i++) - { - if (SDL_RWread(src, trash, sizeof(Uint8)) != sizeof(Uint8)) + for (i = 0; i < sblen; i++) { + if (SDL_RWread(src, trash, sizeof(Uint8)) != sizeof(Uint8)) { return 0; + } } - if (block == VOC_TEXT) + if (block == VOC_TEXT) { continue; /* get next block */ + } } } @@ -326,38 +331,37 @@ static Uint32 voc_read(SDL_RWops *src, vs_t *v, Uint8 *buf, SDL_AudioSpec *spec) Sint64 done = 0; Uint8 silence = 0x80; - if (v->rest == 0) - { - if (!voc_get_block(src, v, spec)) + if (v->rest == 0) { + if (!voc_get_block(src, v, spec)) { return 0; + } } - if (v->rest == 0) + if (v->rest == 0) { return 0; + } - if (v->silent) - { - if (v->size == ST_SIZE_WORD) + if (v->silent) { + if (v->size == ST_SIZE_WORD) { silence = 0x00; + } /* Fill in silence */ SDL_memset(buf, silence, v->rest); done = v->rest; v->rest = 0; } - else - { + else { done = SDL_RWread(src, buf, v->rest); - if (done <= 0) + if (done <= 0) { return 0; + } v->rest = (Uint32)(v->rest - done); - if (v->size == ST_SIZE_WORD) - { + if (v->size == ST_SIZE_WORD) { #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) Uint16 *samples = (Uint16 *)buf; - for (; v->rest > 0; v->rest -= 2) - { + for (; v->rest > 0; v->rest -= 2) { *samples = SDL_SwapLE16(*samples); samples++; } @@ -401,16 +405,18 @@ SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, SDL_bool freesrc, goto done; } - if (!voc_check_header(src)) + if (!voc_check_header(src)) { goto done; + } SDL_zero(v); v.rate = VOC_BAD_RATE; v.rest = 0; v.has_extended = 0; - if (!voc_get_block(src, &v, spec)) + if (!voc_get_block(src, &v, spec)) { goto done; + } if (v.rate == VOC_BAD_RATE) { SDL_SetError("VOC data had no sound!"); @@ -424,25 +430,26 @@ SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, SDL_bool freesrc, SDL_zerop(spec); spec->format = ((v.size == ST_SIZE_WORD) ? SDL_AUDIO_S16 : SDL_AUDIO_U8); - if (spec->channels == 0) + if (spec->channels == 0) { spec->channels = v.channels; + } *audio_len = v.rest; *audio_buf = (v.rest == 0) ? NULL : SDL_malloc(v.rest); - if (*audio_buf == NULL) + if (*audio_buf == NULL) { goto done; + } fillptr = *audio_buf; - while (voc_read(src, &v, fillptr, spec)) - { - if (!voc_get_block(src, &v, spec)) + while (voc_read(src, &v, fillptr, spec)) { + if (!voc_get_block(src, &v, spec)) { goto done; + } *audio_len += v.rest; ptr = SDL_realloc(*audio_buf, *audio_len); - if (ptr == NULL) - { + if (ptr == NULL) { goto done; } diff --git a/src/codecs/music_cmd.c b/src/codecs/music_cmd.c index 96510c917..10441be47 100644 --- a/src/codecs/music_cmd.c +++ b/src/codecs/music_cmd.c @@ -123,7 +123,7 @@ static int ParseCommandLine(char *cmdline, char **argv) if (argv) { argv[argc] = NULL; } - return(argc); + return argc; } static char **parse_args(char *command, char *last_arg) @@ -138,7 +138,7 @@ static char **parse_args(char *command, char *last_arg) } argv = (char **)SDL_malloc((argc+1)*(sizeof *argv)); if (argv == NULL) { - return(NULL); + return NULL; } argc = ParseCommandLine(command, argv); @@ -149,7 +149,7 @@ static char **parse_args(char *command, char *last_arg) argv[argc] = NULL; /* We're ready! */ - return(argv); + return argv; } /* Start playback of a given music stream */ diff --git a/src/codecs/native_midi/native_midi_common.c b/src/codecs/native_midi/native_midi_common.c index 91dc1ddea..a4d608702 100644 --- a/src/codecs/native_midi/native_midi_common.c +++ b/src/codecs/native_midi/native_midi_common.c @@ -58,19 +58,18 @@ typedef struct #endif - /* Get Variable Length Quantity */ static int GetVLQ(MIDITrack *track, int *currentPos) { int l = 0; Uint8 c; - while(1) - { + while (1) { c = track->data[*currentPos]; (*currentPos)++; l += (c & 0x7f); - if (!(c & 0x80)) + if (!(c & 0x80)) { return l; + } l <<= 7; } } @@ -82,15 +81,14 @@ static MIDIEvent *CreateEvent(Uint32 time, Uint8 event, Uint8 a, Uint8 b) newEvent = SDL_calloc(1, sizeof(MIDIEvent)); - if (newEvent) - { + if (newEvent) { newEvent->time = time; newEvent->status = event; newEvent->data[0] = a; newEvent->data[1] = b; - } - else + } else { Mix_OutOfMemory(); + } return newEvent; } @@ -108,23 +106,20 @@ static MIDIEvent *MIDITracktoStream(MIDITrack *track) MIDIEvent *head = CreateEvent(0,0,0,0); /* dummy event to make handling the list easier */ MIDIEvent *currentEvent = head; - while (!end) - { - if (currentPos >= track->len) + while (!end) { + if (currentPos >= track->len) { break; /* End of data stream reached */ + } atime += GetVLQ(track, ¤tPos); event = track->data[currentPos++]; /* Handle SysEx seperatly */ - if (((event>>4) & 0x0F) == MIDI_STATUS_SYSEX) - { - if (event == 0xFF) - { + if (((event>>4) & 0x0F) == MIDI_STATUS_SYSEX) { + if (event == 0xFF) { type = track->data[currentPos]; currentPos++; - switch(type) - { + switch(type) { case 0x2f: /* End of data marker */ end = 1; case 0x51: /* Tempo change */ @@ -136,33 +131,28 @@ static MIDIEvent *MIDITracktoStream(MIDITrack *track) */ break; } - } - else + } else { type = 0; + } len = GetVLQ(track, ¤tPos); /* Create an event and attach the extra data, if any */ currentEvent->next = CreateEvent(atime, event, type, 0); currentEvent = currentEvent->next; - if (NULL == currentEvent) - { + if (NULL == currentEvent) { FreeMIDIEventList(head); return NULL; } - if (len) - { + if (len) { currentEvent->extraLen = len; currentEvent->extraData = SDL_malloc(len); SDL_memcpy(currentEvent->extraData, &(track->data[currentPos]), len); currentPos += len; } - } - else - { + } else { a = event; - if (a & 0x80) /* It's a status byte */ - { + if (a & 0x80) { /* It's a status byte */ /* Extract channel and status information */ lastchan = a & 0x0F; laststatus = (a>>4) & 0x0F; @@ -170,8 +160,7 @@ static MIDIEvent *MIDITracktoStream(MIDITrack *track) /* Read the next byte which should always be a data byte */ a = track->data[currentPos++] & 0x7F; } - switch(laststatus) - { + switch(laststatus) { case MIDI_STATUS_NOTE_OFF: case MIDI_STATUS_NOTE_ON: /* Note on */ case MIDI_STATUS_AFTERTOUCH: /* Key Pressure */ @@ -180,8 +169,7 @@ static MIDIEvent *MIDITracktoStream(MIDITrack *track) b = track->data[currentPos++] & 0x7F; currentEvent->next = CreateEvent(atime, (Uint8)((laststatus<<4)+lastchan), a, b); currentEvent = currentEvent->next; - if (NULL == currentEvent) - { + if (NULL == currentEvent) { FreeMIDIEventList(head); return NULL; } @@ -192,8 +180,7 @@ static MIDIEvent *MIDITracktoStream(MIDITrack *track) a &= 0x7f; currentEvent->next = CreateEvent(atime, (Uint8)((laststatus<<4)+lastchan), a, 0); currentEvent = currentEvent->next; - if (NULL == currentEvent) - { + if (NULL == currentEvent) { FreeMIDIEventList(head); return NULL; } @@ -222,47 +209,45 @@ static MIDIEvent *MIDItoStream(MIDIFile *mididata) MIDIEvent *currentEvent = head; int trackID; - if (NULL == head) + if (NULL == head) { return NULL; + } track = (MIDIEvent**) SDL_calloc(1, sizeof(MIDIEvent*) * mididata->nTracks); - if (NULL == track) - { + if (NULL == track) { SDL_free(head); return NULL; } /* First, convert all tracks to MIDIEvent lists */ - for (trackID = 0; trackID < mididata->nTracks; trackID++) + for (trackID = 0; trackID < mididata->nTracks; trackID++) { track[trackID] = MIDITracktoStream(&mididata->track[trackID]); + } /* Now, merge the lists. */ /* TODO */ - while(1) - { + while (1) { Uint32 lowestTime = 0x7FFFFFFF; /* INT_MAX */ int currentTrackID = -1; /* Find the next event */ - for (trackID = 0; trackID < mididata->nTracks; trackID++) - { - if (track[trackID] && (track[trackID]->time < lowestTime)) - { + for (trackID = 0; trackID < mididata->nTracks; trackID++) { + if (track[trackID] && (track[trackID]->time < lowestTime)) { currentTrackID = trackID; lowestTime = track[currentTrackID]->time; } } /* Check if we processes all events */ - if (currentTrackID == -1) + if (currentTrackID == -1) { break; + } currentEvent->next = track[currentTrackID]; track[currentTrackID] = track[currentTrackID]->next; currentEvent = currentEvent->next; - lowestTime = 0; } @@ -278,16 +263,18 @@ static MIDIEvent *MIDItoStream(MIDIFile *mididata) static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src) { int i = 0; - Uint32 ID = 0; - Uint32 size = 0; - Uint16 format = 0; - Uint16 tracks = 0; - Uint16 division = 0; + Uint32 ID = 0; + Uint32 size = 0; + Uint16 format = 0; + Uint16 tracks = 0; + Uint16 division = 0; - if (!mididata) + if (!mididata) { return 0; - if (!src) + } + if (!src) { return 0; + } /* Make sure this is really a MIDI file */ if (SDL_RWread(src, &ID, 4) != 4) { @@ -299,24 +286,27 @@ static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src) return 0; } } - if (BE_LONG(ID) != MIDI_MAGIC) + if (BE_LONG(ID) != MIDI_MAGIC) { return 0; + } /* Header size must be 6 */ if (SDL_RWread(src, &size, 4) != 4) { return 0; } size = BE_LONG(size); - if (size != 6) + if (size != 6) { return 0; + } /* We only support format 0 and 1, but not 2 */ if (SDL_RWread(src, &format, 2) != 2) { return 0; } format = BE_SHORT(format); - if (format != 0 && format != 1) + if (format != 0 && format != 1) { return 0; + } if (SDL_RWread(src, &tracks, 2) != 2) { return 0; @@ -326,8 +316,7 @@ static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src) /* Allocate tracks */ mididata->track = (MIDITrack*) SDL_calloc(1, sizeof(MIDITrack) * mididata->nTracks); - if (NULL == mididata->track) - { + if (NULL == mididata->track) { Mix_OutOfMemory(); goto bail; } @@ -338,9 +327,7 @@ static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src) } mididata->division = BE_SHORT(division); - - for (i=0; itrack[i].len = size; mididata->track[i].data = SDL_malloc(size); - if (NULL == mididata->track[i].data) - { + if (NULL == mididata->track[i].data) { Mix_OutOfMemory(); goto bail; } @@ -362,10 +348,10 @@ static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src) return 1; bail: - for(;i >= 0; i--) - { - if (mididata->track[i].data) + for (; i >= 0; i--) { + if (mididata->track[i].data) { SDL_free(mididata->track[i].data); + } } SDL_free(mididata->track); @@ -379,38 +365,35 @@ MIDIEvent *CreateMIDIEventList(SDL_RWops *src, Uint16 *division) int trackID; mididata = SDL_calloc(1, sizeof(MIDIFile)); - if (!mididata) + if (!mididata) { return NULL; + } /* Open the file */ - if ( src != NULL ) - { + if (src != NULL) { /* Read in the data */ - if ( ! ReadMIDIFile(mididata, src)) - { + if (!ReadMIDIFile(mididata, src)) { SDL_free(mididata); return NULL; } - } - else - { + } else { SDL_free(mididata); return NULL; } - if (division) + if (division) { *division = mididata->division; + } eventList = MIDItoStream(mididata); - if (eventList == NULL) - { + if (eventList == NULL) { SDL_free(mididata); return NULL; } - for(trackID = 0; trackID < mididata->nTracks; trackID++) - { - if (mididata->track[trackID].data) + for (trackID = 0; trackID < mididata->nTracks; trackID++) { + if (mididata->track[trackID].data) { SDL_free(mididata->track[trackID].data); + } } SDL_free(mididata->track); SDL_free(mididata); @@ -424,12 +407,12 @@ void FreeMIDIEventList(MIDIEvent *head) cur = head; - while (cur) - { + while (cur) { next = cur->next; - if (cur->extraData) - SDL_free (cur->extraData); - SDL_free (cur); + if (cur->extraData) { + SDL_free(cur->extraData); + } + SDL_free(cur); cur = next; } } diff --git a/src/effect_position.c b/src/effect_position.c index 55be136d4..be50201a6 100644 --- a/src/effect_position.c +++ b/src/effect_position.c @@ -131,7 +131,7 @@ static void SDLCALL _Eff_position_u8(int chan, void *stream, int len, void *udat } if (((position_args *)udata)->room_angle == 180) { - for (i = 0; i < len; i += sizeof (Uint8) * 2) { + for (i = 0; i < len; i += sizeof(Uint8) * 2) { /* must adjust the sample so that 0 is the center */ *ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) * right_f) * dist_f) + 128); @@ -142,7 +142,7 @@ static void SDLCALL _Eff_position_u8(int chan, void *stream, int len, void *udat } } else { - for (i = 0; i < len; i += sizeof (Uint8) * 2) { + for (i = 0; i < len; i += sizeof(Uint8) * 2) { /* must adjust the sample so that 0 is the center */ *ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) * left_f) * dist_f) + 128); @@ -174,7 +174,7 @@ static void SDLCALL _Eff_position_u8_c4(int chan, void *stream, int len, void *u } if (args->room_angle == 0) { - for (i = 0; i < len; i += sizeof (Uint8) * 4) { + for (i = 0; i < len; i += sizeof(Uint8) * 4) { /* must adjust the sample so that 0 is the center */ *ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) * args->left_f) * args->distance_f) + 128); @@ -191,7 +191,7 @@ static void SDLCALL _Eff_position_u8_c4(int chan, void *stream, int len, void *u } } else if (args->room_angle == 90) { - for (i = 0; i < len; i += sizeof (Uint8) * 4) { + for (i = 0; i < len; i += sizeof(Uint8) * 4) { /* must adjust the sample so that 0 is the center */ *ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) * args->right_f) * args->distance_f) + 128); @@ -208,7 +208,7 @@ static void SDLCALL _Eff_position_u8_c4(int chan, void *stream, int len, void *u } } else if (args->room_angle == 180) { - for (i = 0; i < len; i += sizeof (Uint8) * 4) { + for (i = 0; i < len; i += sizeof(Uint8) * 4) { /* must adjust the sample so that 0 is the center */ *ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) * args->right_rear_f) * args->distance_f) + 128); @@ -225,7 +225,7 @@ static void SDLCALL _Eff_position_u8_c4(int chan, void *stream, int len, void *u } } else if (args->room_angle == 270) { - for (i = 0; i < len; i += sizeof (Uint8) * 4) { + for (i = 0; i < len; i += sizeof(Uint8) * 4) { /* must adjust the sample so that 0 is the center */ *ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) * args->left_rear_f) * args->distance_f) + 128); @@ -264,7 +264,7 @@ static void SDLCALL _Eff_position_u8_c6(int chan, void *stream, int len, void *u } if (args->room_angle == 0) { - for (i = 0; i < len; i += sizeof (Uint8) * 6) { + for (i = 0; i < len; i += sizeof(Uint8) * 6) { /* must adjust the sample so that 0 is the center */ *ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) * args->left_f) * args->distance_f) + 128); @@ -287,7 +287,7 @@ static void SDLCALL _Eff_position_u8_c6(int chan, void *stream, int len, void *u } } else if (args->room_angle == 90) { - for (i = 0; i < len; i += sizeof (Uint8) * 6) { + for (i = 0; i < len; i += sizeof(Uint8) * 6) { /* must adjust the sample so that 0 is the center */ *ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) * args->right_f) * args->distance_f) + 128); @@ -312,7 +312,7 @@ static void SDLCALL _Eff_position_u8_c6(int chan, void *stream, int len, void *u } } else if (args->room_angle == 180) { - for (i = 0; i < len; i += sizeof (Uint8) * 6) { + for (i = 0; i < len; i += sizeof(Uint8) * 6) { /* must adjust the sample so that 0 is the center */ *ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) * args->right_rear_f) * args->distance_f) + 128); @@ -337,7 +337,7 @@ static void SDLCALL _Eff_position_u8_c6(int chan, void *stream, int len, void *u } } else if (args->room_angle == 270) { - for (i = 0; i < len; i += sizeof (Uint8) * 6) { + for (i = 0; i < len; i += sizeof(Uint8) * 6) { /* must adjust the sample so that 0 is the center */ *ptr = (Uint8) ((Sint8) ((((float) (Sint8) (*ptr - 128)) * args->left_rear_f) * args->distance_f) + 128); @@ -406,7 +406,7 @@ static void SDLCALL _Eff_position_table_u8(int chan, void *stream, int len, void p = (Uint32 *) ptr; - for (i = 0; i < len; i += sizeof (Uint32)) { + for (i = 0; i < len; i += sizeof(Uint32)) { #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) *p = (d[l[(*p & 0xFF000000) >> 24]] << 24) | (d[r[(*p & 0x00FF0000) >> 16]] << 16) | @@ -445,7 +445,7 @@ static void SDLCALL _Eff_position_s8(int chan, void *stream, int len, void *udat } if (((position_args *)udata)->room_angle == 180) { - for (i = 0; i < len; i += sizeof (Sint8) * 2) { + for (i = 0; i < len; i += sizeof(Sint8) * 2) { *ptr = (Sint8)((((float) *ptr) * right_f) * dist_f); ptr++; *ptr = (Sint8)((((float) *ptr) * left_f) * dist_f); @@ -453,7 +453,7 @@ static void SDLCALL _Eff_position_s8(int chan, void *stream, int len, void *udat } } else { - for (i = 0; i < len; i += sizeof (Sint8) * 2) { + for (i = 0; i < len; i += sizeof(Sint8) * 2) { *ptr = (Sint8)((((float) *ptr) * left_f) * dist_f); ptr++; *ptr = (Sint8)((((float) *ptr) * right_f) * dist_f); @@ -480,7 +480,7 @@ static void SDLCALL _Eff_position_s8_c4(int chan, void *stream, int len, void *u len--; } - for (i = 0; i < len; i += sizeof (Sint8) * 4) { + for (i = 0; i < len; i += sizeof(Sint8) * 4) { switch (args->room_angle) { case 0: *ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f); ptr++; @@ -529,7 +529,7 @@ static void SDLCALL _Eff_position_s8_c6(int chan, void *stream, int len, void *u len--; } - for (i = 0; i < len; i += sizeof (Sint8) * 6) { + for (i = 0; i < len; i += sizeof(Sint8) * 6) { switch (args->room_angle) { case 0: *ptr = (Sint8)((((float) *ptr) * args->left_f) * args->distance_f); ptr++; @@ -608,7 +608,7 @@ static void SDLCALL _Eff_position_table_s8(int chan, void *stream, int len, void p = (Uint32 *) ptr; - for (i = 0; i < len; i += sizeof (Uint32)) { + for (i = 0; i < len; i += sizeof(Uint32)) { #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) *p = (d[l[((Sint16)(Sint8)((*p & 0xFF000000) >> 24))+128]] << 24) | (d[r[((Sint16)(Sint8)((*p & 0x00FF0000) >> 16))+128]] << 16) | @@ -646,7 +646,7 @@ static void SDLCALL _Eff_position_s16lsb(int chan, void *stream, int len, void * } #endif - for (i = 0; i < len; i += sizeof (Sint16) * 2) { + for (i = 0; i < len; i += sizeof(Sint16) * 2) { Sint16 swapl = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+0))) * left_f) * dist_f); Sint16 swapr = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+1))) * @@ -670,7 +670,7 @@ static void SDLCALL _Eff_position_s16lsb_c4(int chan, void *stream, int len, voi (void)chan; - for (i = 0; i < len; i += sizeof (Sint16) * 4) { + for (i = 0; i < len; i += sizeof(Sint16) * 4) { Sint16 swapl = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+0))) * args->left_f) * args->distance_f); Sint16 swapr = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+1))) * @@ -717,7 +717,7 @@ static void SDLCALL _Eff_position_s16lsb_c6(int chan, void *stream, int len, voi (void)chan; - for (i = 0; i < len; i += sizeof (Sint16) * 6) { + for (i = 0; i < len; i += sizeof(Sint16) * 6) { Sint16 swapl = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+0))) * args->left_f) * args->distance_f); Sint16 swapr = (Sint16) ((((float) (Sint16) SDL_SwapLE16(*(ptr+1))) * @@ -778,7 +778,7 @@ static void SDLCALL _Eff_position_s16msb(int chan, void *stream, int len, void * (void)chan; - for (i = 0; i < len; i += sizeof (Sint16) * 2) { + for (i = 0; i < len; i += sizeof(Sint16) * 2) { Sint16 swapl = (Sint16) ((((float) (Sint16) SDL_SwapBE16(*(ptr+0))) * left_f) * dist_f); Sint16 swapr = (Sint16) ((((float) (Sint16) SDL_SwapBE16(*(ptr+1))) * @@ -797,7 +797,7 @@ static void SDLCALL _Eff_position_s16msb_c4(int chan, void *stream, int len, voi (void)chan; - for (i = 0; i < len; i += sizeof (Sint16) * 4) { + for (i = 0; i < len; i += sizeof(Sint16) * 4) { Sint16 swapl = (Sint16) ((((float) (Sint16) SDL_SwapBE16(*(ptr+0))) * args->left_f) * args->distance_f); Sint16 swapr = (Sint16) ((((float) (Sint16) SDL_SwapBE16(*(ptr+1))) * @@ -844,7 +844,7 @@ static void SDLCALL _Eff_position_s16msb_c6(int chan, void *stream, int len, voi (void)chan; - for (i = 0; i < len; i += sizeof (Sint16) * 6) { + for (i = 0; i < len; i += sizeof(Sint16) * 6) { Sint16 swapl = (Sint16) ((((float) (Sint16) SDL_SwapBE16(*(ptr+0))) * args->left_f) * args->distance_f); Sint16 swapr = (Sint16) ((((float) (Sint16) SDL_SwapBE16(*(ptr+1))) * @@ -914,7 +914,7 @@ static void SDLCALL _Eff_position_s32lsb(int chan, void *stream, int len, void * } #endif - for (i = 0; i < len; i += sizeof (Sint32) * 2) { + for (i = 0; i < len; i += sizeof(Sint32) * 2) { Sint32 swapl = (Sint32) ((((float) (Sint32) SDL_SwapLE32(*(ptr+0))) * left_f) * dist_f); Sint32 swapr = (Sint32) ((((float) (Sint32) SDL_SwapLE32(*(ptr+1))) * @@ -939,7 +939,7 @@ static void SDLCALL _Eff_position_s32lsb_c4(int chan, void *stream, int len, voi (void)chan; - for (i = 0; i < len; i += sizeof (Sint32) * 4) { + for (i = 0; i < len; i += sizeof(Sint32) * 4) { Sint32 swapl = (Sint32) ((((float) (Sint32) SDL_SwapLE32(*(ptr+0))) * args->left_f) * args->distance_f); Sint32 swapr = (Sint32) ((((float) (Sint32) SDL_SwapLE32(*(ptr+1))) * @@ -986,7 +986,7 @@ static void SDLCALL _Eff_position_s32lsb_c6(int chan, void *stream, int len, voi (void)chan; - for (i = 0; i < len; i += sizeof (Sint32) * 6) { + for (i = 0; i < len; i += sizeof(Sint32) * 6) { Sint32 swapl = (Sint32) ((((float) (Sint32) SDL_SwapLE32(*(ptr+0))) * args->left_f) * args->distance_f); Sint32 swapr = (Sint32) ((((float) (Sint32) SDL_SwapLE32(*(ptr+1))) * @@ -1047,7 +1047,7 @@ static void SDLCALL _Eff_position_s32msb(int chan, void *stream, int len, void * (void)chan; - for (i = 0; i < len; i += sizeof (Sint32) * 2) { + for (i = 0; i < len; i += sizeof(Sint32) * 2) { Sint32 swapl = (Sint32) ((((float) (Sint32) SDL_SwapBE32(*(ptr+0))) * left_f) * dist_f); Sint32 swapr = (Sint32) ((((float) (Sint32) SDL_SwapBE32(*(ptr+1))) * @@ -1066,7 +1066,7 @@ static void SDLCALL _Eff_position_s32msb_c4(int chan, void *stream, int len, voi (void)chan; - for (i = 0; i < len; i += sizeof (Sint32) * 4) { + for (i = 0; i < len; i += sizeof(Sint32) * 4) { Sint32 swapl = (Sint32) ((((float) (Sint32) SDL_SwapBE32(*(ptr+0))) * args->left_f) * args->distance_f); Sint32 swapr = (Sint32) ((((float) (Sint32) SDL_SwapBE32(*(ptr+1))) * @@ -1113,7 +1113,7 @@ static void SDLCALL _Eff_position_s32msb_c6(int chan, void *stream, int len, voi (void)chan; - for (i = 0; i < len; i += sizeof (Sint32) * 6) { + for (i = 0; i < len; i += sizeof(Sint32) * 6) { Sint32 swapl = (Sint32) ((((float) (Sint32) SDL_SwapBE32(*(ptr+0))) * args->left_f) * args->distance_f); Sint32 swapr = (Sint32) ((((float) (Sint32) SDL_SwapBE32(*(ptr+1))) * @@ -1175,7 +1175,7 @@ static void SDLCALL _Eff_position_f32sys(int chan, void *stream, int len, void * (void)chan; - for (i = 0; i < len; i += sizeof (float) * 2) { + for (i = 0; i < len; i += sizeof(float) * 2) { float swapl = ((*(ptr+0) * left_f) * dist_f); float swapr = ((*(ptr+1) * right_f) * dist_f); *(ptr++) = swapl; @@ -1192,7 +1192,7 @@ static void SDLCALL _Eff_position_f32sys_c4(int chan, void *stream, int len, voi (void)chan; - for (i = 0; i < len; i += sizeof (float) * 4) { + for (i = 0; i < len; i += sizeof(float) * 4) { float swapl = ((*(ptr+0) * args->left_f) * args->distance_f); float swapr = ((*(ptr+1) * args->right_f) * args->distance_f); float swaplr = ((*(ptr+2) * args->left_rear_f) * args->distance_f); @@ -1235,7 +1235,7 @@ static void SDLCALL _Eff_position_f32sys_c6(int chan, void *stream, int len, voi (void)chan; - for (i = 0; i < len; i += sizeof (float) * 6) { + for (i = 0; i < len; i += sizeof(float) * 6) { float swapl = ((*(ptr+0) * args->left_f) * args->distance_f); float swapr = ((*(ptr+1) * args->right_f) * args->distance_f); float swaplr = ((*(ptr+2) * args->left_rear_f) * args->distance_f); @@ -1282,7 +1282,7 @@ static void SDLCALL _Eff_position_f32sys_c6(int chan, void *stream, int len, voi static void init_position_args(position_args *args) { - SDL_memset(args, '\0', sizeof (position_args)); + SDL_memset(args, '\0', sizeof(position_args)); args->in_use = 0; args->room_angle = 0; args->left_u8 = args->right_u8 = args->distance_u8 = 255; @@ -1299,22 +1299,22 @@ static position_args *get_position_arg(int channel) if (channel < 0) { if (pos_args_global == NULL) { - pos_args_global = SDL_malloc(sizeof (position_args)); + pos_args_global = SDL_malloc(sizeof(position_args)); if (pos_args_global == NULL) { Mix_OutOfMemory(); - return(NULL); + return NULL; } init_position_args(pos_args_global); } - return(pos_args_global); + return pos_args_global; } if (channel >= position_channels) { rc = SDL_realloc(pos_args_array, (size_t)(channel + 1) * sizeof(position_args *)); if (rc == NULL) { Mix_OutOfMemory(); - return(NULL); + return NULL; } pos_args_array = (position_args **) rc; for (i = position_channels; i <= channel; i++) { @@ -1327,12 +1327,12 @@ static position_args *get_position_arg(int channel) pos_args_array[channel] = (position_args *)SDL_malloc(sizeof(position_args)); if (pos_args_array[channel] == NULL) { Mix_OutOfMemory(); - return(NULL); + return NULL; } init_position_args(pos_args_array[channel]); } - return(pos_args_array[channel]); + return pos_args_array[channel]; } static Mix_EffectFunc_t get_position_effect_func(Uint16 format, int channels) @@ -1473,7 +1473,7 @@ static Mix_EffectFunc_t get_position_effect_func(Uint16 format, int channels) break; } - return(f); + return f; } static Uint8 speaker_amplitude[6]; @@ -1485,8 +1485,7 @@ static void set_amplitudes(int channels, int angle, int room_angle) /* our only caller Mix_SetPosition() already makes angle between 0 and 359. */ - if (channels == 2) - { + if (channels == 2) { /* * We only attenuate by position if the angle falls on the far side * of center; That is, an angle that's due north would not attenuate @@ -1508,8 +1507,7 @@ static void set_amplitudes(int channels, int angle, int room_angle) } } - if (channels == 4 || channels == 6) - { + if (channels == 4 || channels == 6) { /* * An angle that's due north does not attenuate the center channel. * An angle in the first quadrant, 0-90, does not attenuate the RF. @@ -1625,7 +1623,7 @@ int Mix_SetPanning(int channel, Uint8 left, Uint8 right) Mix_QuerySpec(NULL, &format, &channels); if (channels != 2 && channels != 4 && channels != 6) /* it's a no-op; we call that successful. */ - return(1); + return 1; if (channels > 2) { /* left = right = 255 => angle = 0, to unregister effect as when channels = 2 */ @@ -1642,13 +1640,13 @@ int Mix_SetPanning(int channel, Uint8 left, Uint8 right) f = get_position_effect_func(format, channels); if (f == NULL) - return(0); + return 0; Mix_LockAudio(); args = get_position_arg(channel); if (!args) { Mix_UnlockAudio(); - return(0); + return 0; } /* it's a no-op; unregister the effect, if it's registered. */ @@ -1656,10 +1654,10 @@ int Mix_SetPanning(int channel, Uint8 left, Uint8 right) if (args->in_use) { retval = _Mix_UnregisterEffect_locked(channel, f); Mix_UnlockAudio(); - return(retval); + return retval; } else { Mix_UnlockAudio(); - return(1); + return 1; } } @@ -1675,7 +1673,7 @@ int Mix_SetPanning(int channel, Uint8 left, Uint8 right) } Mix_UnlockAudio(); - return(retval); + return retval; } @@ -1690,13 +1688,13 @@ int Mix_SetDistance(int channel, Uint8 distance) Mix_QuerySpec(NULL, &format, &channels); f = get_position_effect_func(format, channels); if (f == NULL) - return(0); + return 0; Mix_LockAudio(); args = get_position_arg(channel); if (!args) { Mix_UnlockAudio(); - return(0); + return 0; } distance = 255 - distance; /* flip it to our scale. */ @@ -1706,10 +1704,10 @@ int Mix_SetDistance(int channel, Uint8 distance) if (args->in_use) { retval = _Mix_UnregisterEffect_locked(channel, f); Mix_UnlockAudio(); - return(retval); + return retval; } else { Mix_UnlockAudio(); - return(1); + return 1; } } @@ -1721,7 +1719,7 @@ int Mix_SetDistance(int channel, Uint8 distance) } Mix_UnlockAudio(); - return(retval); + return retval; } @@ -1737,7 +1735,7 @@ int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance) Mix_QuerySpec(NULL, &format, &channels); f = get_position_effect_func(format, channels); if (f == NULL) - return(0); + return 0; /* make angle between 0 and 359. */ angle %= 360; @@ -1747,7 +1745,7 @@ int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance) args = get_position_arg(channel); if (!args) { Mix_UnlockAudio(); - return(0); + return 0; } /* it's a no-op; unregister the effect, if it's registered. */ @@ -1755,10 +1753,10 @@ int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance) if (args->in_use) { retval = _Mix_UnregisterEffect_locked(channel, f); Mix_UnlockAudio(); - return(retval); + return retval; } else { Mix_UnlockAudio(); - return(1); + return 1; } } @@ -1772,7 +1770,7 @@ int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance) if (angle > 315) room_angle = 0; else if (angle > 225) room_angle = 270; else if (angle > 135) room_angle = 180; - else if (angle > 45) room_angle = 90; + else if (angle > 45) room_angle = 90; else room_angle = 0; } @@ -1801,7 +1799,7 @@ int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance) } Mix_UnlockAudio(); - return(retval); + return retval; } /* end of effects_position.c ... */ diff --git a/src/effect_stereoreverse.c b/src/effect_stereoreverse.c index fd24af819..f8d1ffbe0 100644 --- a/src/effect_stereoreverse.c +++ b/src/effect_stereoreverse.c @@ -58,7 +58,7 @@ static void SDLCALL _Eff_reversestereo32(int chan, void *stream, int len, void * (void)chan; (void)udata; - for (i = 0; i < len; i += 2 * sizeof (Uint32), ptr += 2) { + for (i = 0; i < len; i += 2 * sizeof(Uint32), ptr += 2) { tmp = ptr[0]; ptr[0] = ptr[1]; ptr[1] = tmp; @@ -74,7 +74,7 @@ static void SDLCALL _Eff_reversestereo16(int chan, void *stream, int len, void * (void)chan; (void)udata; - for (i = 0; i < len; i += sizeof (Uint32), ptr++) { + for (i = 0; i < len; i += sizeof(Uint32), ptr++) { *ptr = (((*ptr) & 0xFFFF0000) >> 16) | (((*ptr) & 0x0000FFFF) << 16); } } @@ -95,7 +95,7 @@ static void SDLCALL _Eff_reversestereo8(int chan, void *stream, int len, void *u len -= 2; } - for (i = 0; i < len; i += sizeof (Uint32), ptr++) { + for (i = 0; i < len; i += sizeof(Uint32), ptr++) { *ptr = (((*ptr) & 0x0000FF00) >> 8) | (((*ptr) & 0x000000FF) << 8) | (((*ptr) & 0xFF000000) >> 8) | (((*ptr) & 0x00FF0000) << 8); } @@ -123,14 +123,16 @@ int Mix_SetReverseStereo(int channel, int flip) break; default: Mix_SetError("Unsupported audio format"); - return(0); + return 0; } - if (!flip) return Mix_UnregisterEffect(channel, f); - return(Mix_RegisterEffect(channel, f, NULL, NULL)); + if (!flip) { + return Mix_UnregisterEffect(channel, f); + } + return Mix_RegisterEffect(channel, f, NULL, NULL); } Mix_SetError("Trying to reverse stereo on a non-stereo stream"); - return(0); + return 0; } /* end of effect_stereoreverse.c ... */ diff --git a/src/effects_internal.c b/src/effects_internal.c index 87ce10c02..a1d81f779 100644 --- a/src/effects_internal.c +++ b/src/effects_internal.c @@ -63,7 +63,7 @@ void *_Eff_build_volume_table_u8(void) Uint8 *rc; if (!_Mix_effects_max_speed) { - return(NULL); + return NULL; } if (!_Eff_volume_table) { @@ -80,7 +80,7 @@ void *_Eff_build_volume_table_u8(void) } } - return(_Eff_volume_table); + return _Eff_volume_table; } @@ -110,7 +110,7 @@ void *_Eff_build_volume_table_s8(void) } } - return(_Eff_volume_table); + return _Eff_volume_table; } diff --git a/src/mixer.c b/src/mixer.c index 6c6d7a9f6..843e796ec 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -119,7 +119,7 @@ static SDL_AtomicInt master_volume = { MIX_MAX_VOLUME }; int Mix_GetNumChunkDecoders(void) { - return(num_decoders); + return num_decoders; } const char *Mix_GetChunkDecoder(int index) @@ -127,7 +127,7 @@ const char *Mix_GetChunkDecoder(int index) if ((index < 0) || (index >= num_decoders)) { return NULL; } - return(chunk_decoders[index]); + return chunk_decoders[index]; } SDL_bool Mix_HasChunkDecoder(const char *name) @@ -153,7 +153,7 @@ void add_chunk_decoder(const char *decoder) } } - ptr = SDL_realloc((void *)chunk_decoders, (size_t)(num_decoders + 1) * sizeof (const char *)); + ptr = SDL_realloc((void *)chunk_decoders, (size_t)(num_decoders + 1) * sizeof(const char *)); if (ptr == NULL) { return; /* oh well, go on without it. */ } @@ -166,7 +166,7 @@ const SDL_version *Mix_Linked_Version(void) { static SDL_version linked_version; SDL_MIXER_VERSION(&linked_version); - return(&linked_version); + return &linked_version; } /* @@ -321,7 +321,7 @@ static void *Mix_DoEffects(int chan, void *snd, int len) if (!posteffect) { buf = SDL_malloc((size_t)len); if (buf == NULL) { - return(snd); + return snd; } SDL_memcpy(buf, snd, (size_t)len); } @@ -334,7 +334,7 @@ static void *Mix_DoEffects(int chan, void *snd, int len) } /* be sure to SDL_free() the return value if != snd ... */ - return(buf); + return buf; } @@ -372,7 +372,7 @@ mix_channels(void *udata, SDL_AudioStream *astream, int len, int total) /* Mix any playing channels... */ sdl_ticks = SDL_GetTicks(); - for (i=0; i 0 && mix_channel[i].expire < sdl_ticks) { /* Expiration delay for that channel is reached */ @@ -500,7 +500,7 @@ int Mix_OpenAudio(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec) if (audio_opened) { if (spec && (spec->format == mixer.format) && (spec->channels == mixer.channels)) { ++audio_opened; - return(0); + return 0; } while (audio_opened) { Mix_CloseAudio(); @@ -534,7 +534,7 @@ int Mix_OpenAudio(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec) mix_channel = (struct _Mix_Channel *) SDL_malloc(num_channels * sizeof(struct _Mix_Channel)); /* Clear out the audio channels */ - for (i=0; i num_channels) { /* Initialize the new channels */ int i; - for(i=num_channels; i < numchans; i++) { + for (i = num_channels; i < numchans; i++) { mix_channel[i].chunk = NULL; mix_channel[i].playing = 0; mix_channel[i].looping = 0; @@ -613,7 +613,7 @@ int Mix_AllocateChannels(int numchans) } num_channels = numchans; Mix_UnlockAudio(); - return(num_channels); + return num_channels; } /* Return the actual mixer parameters */ @@ -630,7 +630,7 @@ int Mix_QuerySpec(int *frequency, Uint16 *format, int *channels) *channels = mixer.channels; } } - return(audio_opened); + return audio_opened; } typedef struct _MusicFragment @@ -792,7 +792,7 @@ Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, SDL_bool freesrc) /* rcg06012001 Make sure src is valid */ if (!src) { Mix_SetError("Mix_LoadWAV_RW with NULL src"); - return(NULL); + return NULL; } /* Make sure audio has been opened */ @@ -801,7 +801,7 @@ Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, SDL_bool freesrc) if (freesrc) { SDL_RWclose(src); } - return(NULL); + return NULL; } /* Allocate the chunk memory */ @@ -811,7 +811,7 @@ Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, SDL_bool freesrc) if (freesrc) { SDL_RWclose(src); } - return(NULL); + return NULL; } /* Find out what kind of audio file this is */ @@ -843,7 +843,7 @@ Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, SDL_bool freesrc) if (!loaded) { /* The individual loaders have closed src if needed */ SDL_free(chunk); - return(NULL); + return NULL; } #if 0 @@ -891,14 +891,14 @@ Mix_Chunk *Mix_QuickLoad_WAV(Uint8 *mem) /* Make sure audio has been opened */ if (! audio_opened) { Mix_SetError("Audio device hasn't been opened"); - return(NULL); + return NULL; } /* Allocate the chunk memory */ chunk = (Mix_Chunk *)SDL_calloc(1,sizeof(Mix_Chunk)); if (chunk == NULL) { Mix_OutOfMemory(); - return(NULL); + return NULL; } /* Essentially just skip to the audio data (no error checking - fast) */ @@ -914,7 +914,7 @@ Mix_Chunk *Mix_QuickLoad_WAV(Uint8 *mem) } while (SDL_memcmp(magic, "data", 4) != 0); chunk->volume = MIX_MAX_VOLUME; - return(chunk); + return chunk; } /* Load raw audio data of the mixer format from a memory buffer */ @@ -925,14 +925,14 @@ Mix_Chunk *Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len) /* Make sure audio has been opened */ if (! audio_opened) { Mix_SetError("Audio device hasn't been opened"); - return(NULL); + return NULL; } /* Allocate the chunk memory */ chunk = (Mix_Chunk *)SDL_malloc(sizeof(Mix_Chunk)); if (chunk == NULL) { Mix_OutOfMemory(); - return(NULL); + return NULL; } /* Essentially just point at the audio data (no error checking - fast) */ @@ -941,7 +941,7 @@ Mix_Chunk *Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len) chunk->abuf = mem; chunk->volume = MIX_MAX_VOLUME; - return(chunk); + return chunk; } /* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */ @@ -968,7 +968,7 @@ void Mix_FreeChunk(Mix_Chunk *chunk) /* Guarantee that this chunk isn't playing */ Mix_LockAudio(); if (mix_channel) { - for (i=0; i0) ? (SDL_GetTicks() + (Uint32)ticks) : 0; Mix_UnlockAudio(); - ++ status; + ++status; } - return(status); + return status; } /* Fade in a sound on a channel, over ms milliseconds */ @@ -1140,11 +1140,11 @@ int Mix_FadeInChannelTimed(int which, Mix_Chunk *chunk, int loops, int ms, int t /* Don't play null pointers :-) */ if (chunk == NULL) { - return(-1); + return -1; } if (!checkchunkintegral(chunk)) { Mix_SetError("Tried to play a chunk with a bad frame"); - return(-1); + return -1; } /* Lock the mixer while modifying the playing channels */ @@ -1152,7 +1152,7 @@ int Mix_FadeInChannelTimed(int which, Mix_Chunk *chunk, int loops, int ms, int t { /* If which is -1, play on the first free channel */ if (which == -1) { - for (i=reserved_channels; ivolume; if (volume >= 0) { @@ -1234,7 +1234,7 @@ int Mix_VolumeChunk(Mix_Chunk *chunk, int volume) } chunk->volume = volume; } - return(prev_volume); + return prev_volume; } /* Halt playing of a particular channel */ @@ -1244,14 +1244,14 @@ int Mix_HaltChannel(int which) Mix_LockAudio(); if (which == -1) { - for (i=0; i 0) || mix_channel[i].looping) { @@ -1350,7 +1350,7 @@ int Mix_Playing(int which) ++status; } } - return(status); + return status; } /* rcg06072001 Get the chunk associated with a channel. */ @@ -1362,7 +1362,7 @@ Mix_Chunk *Mix_GetChunk(int channel) retval = mix_channel[channel].chunk; } - return(retval); + return retval; } /* Close the mixer, halting all playing audio */ @@ -1405,7 +1405,7 @@ void Mix_Pause(int which) if (which == -1) { int i; - for (i=0; i 0) + if (mix_channel[i].expire > 0) { mix_channel[i].expire += sdl_ticks - mix_channel[i].paused; + } mix_channel[i].paused = 0; } } } else if (which < num_channels) { if (Mix_Playing(which)) { - if (mix_channel[which].expire > 0) + if (mix_channel[which].expire > 0) { mix_channel[which].expire += sdl_ticks - mix_channel[which].paused; + } mix_channel[which].paused = 0; } } @@ -1466,7 +1468,7 @@ int Mix_ResumeGroup(int tag) Mix_Resume(i); } } - return(0); + return 0; } int Mix_Paused(int which) @@ -1474,51 +1476,52 @@ int Mix_Paused(int which) if (which < 0) { int status = 0; int i; - for(i=0; i < num_channels; ++i) { + for (i = 0; i < num_channels; ++i) { if (Mix_Playing(i) && mix_channel[i].paused) { - ++ status; + ++status; } } - return(status); - } else if (which < num_channels) { - return(Mix_Playing(which) && mix_channel[which].paused != 0); - } else { - return(0); + return status; + } + if (which < num_channels) { + return (Mix_Playing(which) && mix_channel[which].paused != 0); } + return 0; } /* Change the group of a channel */ int Mix_GroupChannel(int which, int tag) { - if (which < 0 || which > num_channels) - return(0); + if (which < 0 || which > num_channels) { + return 0; + } Mix_LockAudio(); mix_channel[which].tag = tag; Mix_UnlockAudio(); - return(1); + return 1; } /* Assign several consecutive channels to a group */ int Mix_GroupChannels(int from, int to, int tag) { int status = 0; - for(; from <= to; ++ from) { + for (; from <= to; ++from) { status += Mix_GroupChannel(from, tag); } - return(status); + return status; } /* Finds the first available channel in a group of channels */ int Mix_GroupAvailable(int tag) { int i; - for(i=0; i < num_channels; i ++) { - if (((tag == -1) || (tag == mix_channel[i].tag)) && - (!Mix_Playing(i))) + for (i = 0; i < num_channels; i++) { + if ((tag == -1 || tag == mix_channel[i].tag) && !Mix_Playing(i)) { return i; + } } - return(-1); + return -1; } int Mix_GroupCount(int tag) @@ -1530,11 +1533,12 @@ int Mix_GroupCount(int tag) return num_channels; /* minor optimization; no need to go through the loop. */ } - for(i=0; i < num_channels; i ++) { - if (mix_channel[i].tag == tag) - ++ count; + for (i = 0; i < num_channels; i++) { + if (mix_channel[i].tag == tag) { + ++count; + } } - return(count); + return count; } /* Finds the "oldest" sample playing in a group of channels */ @@ -1543,14 +1547,14 @@ int Mix_GroupOldest(int tag) int chan = -1; Uint64 mintime = SDL_GetTicks(); int i; - for(i=0; i < num_channels; i ++) { - if ((mix_channel[i].tag==tag || tag==-1) && Mix_Playing(i) + for (i = 0; i < num_channels; i++) { + if ((mix_channel[i].tag == tag || tag == -1) && Mix_Playing(i) && mix_channel[i].start_time <= mintime) { mintime = mix_channel[i].start_time; chan = i; } } - return(chan); + return chan; } /* Finds the "most recent" (i.e. last) sample playing in a group of channels */ @@ -1559,14 +1563,14 @@ int Mix_GroupNewer(int tag) int chan = -1; Uint64 maxtime = 0; int i; - for(i=0; i < num_channels; i ++) { - if ((mix_channel[i].tag==tag || tag==-1) && Mix_Playing(i) + for (i = 0; i < num_channels; i++) { + if ((mix_channel[i].tag == tag || tag == -1) && Mix_Playing(i) && mix_channel[i].start_time >= maxtime) { maxtime = mix_channel[i].start_time; chan = i; } } - return(chan); + return chan; } @@ -1585,18 +1589,18 @@ static int _Mix_register_effect(effect_info **e, Mix_EffectFunc_t f, if (!e) { Mix_SetError("Internal error"); - return(0); + return 0; } if (f == NULL) { Mix_SetError("NULL effect callback"); - return(0); + return 0; } - new_e = SDL_malloc(sizeof (effect_info)); + new_e = SDL_malloc(sizeof(effect_info)); if (new_e == NULL) { Mix_OutOfMemory(); - return(0); + return 0; } new_e->callback = f; @@ -1618,7 +1622,7 @@ static int _Mix_register_effect(effect_info **e, Mix_EffectFunc_t f, } } - return(1); + return 1; } @@ -1631,7 +1635,7 @@ static int _Mix_remove_effect(int channel, effect_info **e, Mix_EffectFunc_t f) if (!e) { Mix_SetError("Internal error"); - return(0); + return 0; } for (cur = *e; cur != NULL; cur = cur->next) { @@ -1647,13 +1651,13 @@ static int _Mix_remove_effect(int channel, effect_info **e, Mix_EffectFunc_t f) } else { prev->next = next; } - return(1); + return 1; } prev = cur; } Mix_SetError("No such effect registered"); - return(0); + return 0; } @@ -1665,7 +1669,7 @@ static int _Mix_remove_all_effects(int channel, effect_info **e) if (!e) { Mix_SetError("Internal error"); - return(0); + return 0; } for (cur = *e; cur != NULL; cur = next) { @@ -1677,7 +1681,7 @@ static int _Mix_remove_all_effects(int channel, effect_info **e) } *e = NULL; - return(1); + return 1; } @@ -1692,7 +1696,7 @@ int _Mix_RegisterEffect_locked(int channel, Mix_EffectFunc_t f, } else { if ((channel < 0) || (channel >= num_channels)) { Mix_SetError("Invalid channel number"); - return(0); + return 0; } e = &mix_channel[channel].effects; } @@ -1721,7 +1725,7 @@ int _Mix_UnregisterEffect_locked(int channel, Mix_EffectFunc_t f) } else { if ((channel < 0) || (channel >= num_channels)) { Mix_SetError("Invalid channel number"); - return(0); + return 0; } e = &mix_channel[channel].effects; } @@ -1735,7 +1739,7 @@ int Mix_UnregisterEffect(int channel, Mix_EffectFunc_t f) Mix_LockAudio(); retval = _Mix_UnregisterEffect_locked(channel, f); Mix_UnlockAudio(); - return(retval); + return retval; } /* MAKE SURE you hold the audio lock (Mix_LockAudio()) before calling this! */ @@ -1748,7 +1752,7 @@ int _Mix_UnregisterAllEffects_locked(int channel) } else { if ((channel < 0) || (channel >= num_channels)) { Mix_SetError("Invalid channel number"); - return(0); + return 0; } e = &mix_channel[channel].effects; } @@ -1762,7 +1766,7 @@ int Mix_UnregisterAllEffects(int channel) Mix_LockAudio(); retval = _Mix_UnregisterAllEffects_locked(channel); Mix_UnlockAudio(); - return(retval); + return retval; } void Mix_LockAudio(void) @@ -1785,7 +1789,7 @@ int Mix_MasterVolume(int volume) volume = SDL_MIX_MAXVOLUME; } SDL_AtomicSet(&master_volume, volume); - return(prev_volume); + return prev_volume; } /* end of mixer.c ... */ diff --git a/src/music.c b/src/music.c index 73ae5afbc..51712e4fa 100644 --- a/src/music.c +++ b/src/music.c @@ -220,7 +220,7 @@ Mix_MusicInterface *get_music_interface(int index) int Mix_GetNumMusicDecoders(void) { - return(num_decoders); + return num_decoders; } const char *Mix_GetMusicDecoder(int index) @@ -228,7 +228,7 @@ const char *Mix_GetMusicDecoder(int index) if ((index < 0) || (index >= num_decoders)) { return NULL; } - return(music_decoders[index]); + return music_decoders[index]; } SDL_bool Mix_HasMusicDecoder(const char *name) @@ -254,7 +254,7 @@ static void add_music_decoder(const char *decoder) } } - ptr = SDL_realloc((void *)music_decoders, ((size_t)num_decoders + 1) * sizeof (const char *)); + ptr = SDL_realloc((void *)music_decoders, ((size_t)num_decoders + 1) * sizeof(const char *)); if (ptr == NULL) { return; /* oh well, go on without it. */ } @@ -848,7 +848,7 @@ Mix_MusicType Mix_GetMusicType(const Mix_Music *music) } Mix_UnlockAudio(); } - return(type); + return type; } static const char * get_music_tag_internal(const Mix_Music *music, Mix_MusicMetaTag tag_type) @@ -939,7 +939,7 @@ static int music_internal_play(Mix_Music *music, int play_count, double position music->playing = SDL_FALSE; music_playing = NULL; } - return(retval); + return retval; } int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position) @@ -948,13 +948,13 @@ int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position) if (ms_per_step == 0) { Mix_SetError("Audio device hasn't been opened"); - return(-1); + return -1; } /* Don't play null pointers :-) */ if (music == NULL) { Mix_SetError("music parameter was NULL"); - return(-1); + return -1; } /* Setup the data */ @@ -983,7 +983,7 @@ int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position) music_active = (retval == 0); Mix_UnlockAudio(); - return(retval); + return retval; } int Mix_FadeInMusic(Mix_Music *music, int loops, int ms) { @@ -1038,7 +1038,7 @@ int Mix_SetMusicPosition(double position) } Mix_UnlockAudio(); - return(retval); + return retval; } /* Set the playing music position */ @@ -1064,7 +1064,7 @@ double Mix_GetMusicPosition(Mix_Music *music) } Mix_UnlockAudio(); - return(retval); + return retval; } static double music_internal_duration(Mix_Music *music) @@ -1091,7 +1091,7 @@ double Mix_MusicDuration(Mix_Music *music) } Mix_UnlockAudio(); - return(retval); + return retval; } /* Get Loop start position */ @@ -1117,7 +1117,7 @@ double Mix_GetMusicLoopStartTime(Mix_Music *music) } Mix_UnlockAudio(); - return(retval); + return retval; } /* Get Loop end position */ @@ -1143,7 +1143,7 @@ double Mix_GetMusicLoopEndTime(Mix_Music *music) } Mix_UnlockAudio(); - return(retval); + return retval; } /* Get Loop end position */ @@ -1169,7 +1169,7 @@ double Mix_GetMusicLoopLengthTime(Mix_Music *music) } Mix_UnlockAudio(); - return(retval); + return retval; } /* Set the music's initial volume */ @@ -1206,7 +1206,7 @@ int Mix_VolumeMusic(int volume) music_internal_volume(music_volume); } Mix_UnlockAudio(); - return(prev_volume); + return prev_volume; } int Mix_GetMusicVolume(Mix_Music *music) @@ -1246,7 +1246,7 @@ int Mix_HaltMusic(void) } Mix_UnlockAudio(); - return(0); + return 0; } /* Progressively stop the music */ @@ -1285,7 +1285,7 @@ int Mix_FadeOutMusic(int ms) } Mix_UnlockAudio(); - return(retval); + return retval; } Mix_Fading Mix_FadingMusic(void) @@ -1298,7 +1298,7 @@ Mix_Fading Mix_FadingMusic(void) } Mix_UnlockAudio(); - return(fading); + return fading; } /* Pause/Resume the music stream */