Skip to content

Commit

Permalink
error returns and Mix_SetError clean-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Jan 15, 2024
1 parent 8503a0b commit 491bb53
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 86 deletions.
26 changes: 13 additions & 13 deletions src/codecs/load_voc.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static int voc_check_header(SDL_RWops *src)
}

if (SDL_memcmp(signature, "Creative Voice File\032", sizeof(signature)) != 0) {
SDL_SetError("Unrecognized file type (not VOC)");
Mix_SetError("Unrecognized file type (not VOC)");
return 0;
}

Expand Down Expand Up @@ -151,12 +151,12 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
/* block, the DATA blocks rate value is invalid */
if (!v->has_extended) {
if (uc == 0) {
SDL_SetError("VOC Sample rate is zero?");
Mix_SetError("VOC Sample rate is zero?");
return 0;
}

if ((v->rate != VOC_BAD_RATE) && (uc != v->rate)) {
SDL_SetError("VOC sample rate codes differ");
Mix_SetError("VOC sample rate codes differ");
return 0;
}

Expand All @@ -170,7 +170,7 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
}

if (uc != 0) {
SDL_SetError("VOC decoder only interprets 8-bit data");
Mix_SetError("VOC decoder only interprets 8-bit data");
return 0;
}

Expand All @@ -185,11 +185,11 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
}
new_rate_long = SDL_SwapLE32(new_rate_long);
if (new_rate_long == 0) {
SDL_SetError("VOC Sample rate is zero?");
Mix_SetError("VOC Sample rate is zero?");
return 0;
}
if ((v->rate != VOC_BAD_RATE) && (new_rate_long != v->rate)) {
SDL_SetError("VOC sample rate codes differ");
Mix_SetError("VOC sample rate codes differ");
return 0;
}
v->rate = new_rate_long;
Expand All @@ -203,7 +203,7 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
case 8: v->size = ST_SIZE_BYTE; break;
case 16: v->size = ST_SIZE_WORD; break;
default:
SDL_SetError("VOC with unknown data size");
Mix_SetError("VOC with unknown data size");
return 0;
}

Expand Down Expand Up @@ -232,7 +232,7 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
return 0;
}
if (uc == 0) {
SDL_SetError("VOC silence sample rate is zero");
Mix_SetError("VOC silence sample rate is zero");
return 0;
}

Expand Down Expand Up @@ -269,11 +269,11 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
}
new_rate_short = SDL_SwapLE16(new_rate_short);
if (new_rate_short == 0) {
SDL_SetError("VOC sample rate is zero");
Mix_SetError("VOC sample rate is zero");
return 0;
}
if ((v->rate != VOC_BAD_RATE) && (new_rate_short != v->rate)) {
SDL_SetError("VOC sample rate codes differ");
Mix_SetError("VOC sample rate codes differ");
return 0;
}
v->rate = new_rate_short;
Expand All @@ -283,7 +283,7 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
}

if (uc != 0) {
SDL_SetError("VOC decoder only interprets 8-bit data");
Mix_SetError("VOC decoder only interprets 8-bit data");
return 0;
}

Expand Down Expand Up @@ -401,12 +401,12 @@ SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, int freesrc,
}

if (v.rate == VOC_BAD_RATE) {
SDL_SetError("VOC data had no sound!");
Mix_SetError("VOC data had no sound!");
goto done;
}

if (v.size == 0) {
SDL_SetError("VOC data had invalid word size!");
Mix_SetError("VOC data had invalid word size!");
goto done;
}

Expand Down
3 changes: 1 addition & 2 deletions src/codecs/music_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ static int MusicCMD_Play(void *context, int play_count)
switch(music->pid) {
/* Failed fork() system call */
case -1:
Mix_SetError("fork() failed");
return -1;
return Mix_SetError("fork() failed");

/* Child process - executes here */
case 0: {
Expand Down
3 changes: 1 addition & 2 deletions src/codecs/music_drflac.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ static int DRFLAC_GetSome(void *context, void *data, int bytes, SDL_bool *done)

if (music->loop_flag) {
if (!drflac_seek_to_pcm_frame(music->dec, music->loop_start)) {
SDL_SetError("drflac_seek_to_pcm_frame() failed");
return -1;
return Mix_SetError("drflac_seek_to_pcm_frame() failed");
} else {
int play_count = -1;
if (music->play_count > 0) {
Expand Down
31 changes: 14 additions & 17 deletions src/codecs/music_flac.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ static FLAC__StreamDecoderWriteStatus flac_write_music_cb(
shift_amount = 8;
break;
default:
SDL_SetError("FLAC decoder doesn't support %d bits_per_sample", music->bits_per_sample);
Mix_SetError("FLAC decoder doesn't support %d bits_per_sample", music->bits_per_sample);
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}

Expand All @@ -329,7 +329,7 @@ static FLAC__StreamDecoderWriteStatus flac_write_music_cb(

data = SDL_stack_alloc(Sint16, (frame->header.blocksize * channels));
if (!data) {
SDL_SetError("Couldn't allocate %d bytes stack memory", (int)(frame->header.blocksize * channels * sizeof(*data)));
Mix_SetError("Couldn't allocate %d bytes stack memory", (int)(frame->header.blocksize * channels * sizeof(*data)));
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
if (music->channels == 3) {
Expand Down Expand Up @@ -485,19 +485,19 @@ static void flac_error_music_cb(
/* print an SDL error based on the error status */
switch (status) {
case FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC:
SDL_SetError("Error processing the FLAC file [LOST_SYNC].");
Mix_SetError("Error processing the FLAC file [LOST_SYNC].");
break;
case FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER:
SDL_SetError("Error processing the FLAC file [BAD_HEADER].");
Mix_SetError("Error processing the FLAC file [BAD_HEADER].");
break;
case FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH:
SDL_SetError("Error processing the FLAC file [CRC_MISMATCH].");
Mix_SetError("Error processing the FLAC file [CRC_MISMATCH].");
break;
case FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM:
SDL_SetError("Error processing the FLAC file [UNPARSEABLE].");
Mix_SetError("Error processing the FLAC file [UNPARSEABLE].");
break;
default:
SDL_SetError("Error processing the FLAC file [UNKNOWN].");
Mix_SetError("Error processing the FLAC file [UNKNOWN].");
break;
}
}
Expand All @@ -512,7 +512,7 @@ static void *FLAC_CreateFromRW(SDL_RWops *src, int freesrc)
int is_ogg_flac;
Uint8 magic[4];
if (SDL_RWread(src, magic, 1, 4) != 4) {
SDL_SetError("Couldn't read first 4 bytes of audio data");
Mix_SetError("Couldn't read first 4 bytes of audio data");
return NULL;
}
SDL_RWseek(src, -4, RW_SEEK_CUR);
Expand Down Expand Up @@ -556,13 +556,13 @@ static void *FLAC_CreateFromRW(SDL_RWops *src, int freesrc)
if (flac.FLAC__stream_decoder_process_until_end_of_metadata(music->flac_decoder)) {
was_error = 0;
} else {
SDL_SetError("FLAC__stream_decoder_process_until_end_of_metadata() failed");
Mix_SetError("FLAC__stream_decoder_process_until_end_of_metadata() failed");
}
} else {
SDL_SetError("FLAC__stream_decoder_init_stream() failed");
Mix_SetError("FLAC__stream_decoder_init_stream() failed");
}
} else {
SDL_SetError("FLAC__stream_decoder_new() failed");
Mix_SetError("FLAC__stream_decoder_new() failed");
}

if (was_error) {
Expand Down Expand Up @@ -645,17 +645,15 @@ static int FLAC_GetSome(void *context, void *data, int bytes, SDL_bool *done)
}

if (!flac.FLAC__stream_decoder_process_single(music->flac_decoder)) {
SDL_SetError("FLAC__stream_decoder_process_single() failed");
return -1;
return Mix_SetError("FLAC__stream_decoder_process_single() failed");
}

if (music->loop_flag) {
music->pcm_pos = music->loop_start;
if (flac.FLAC__stream_decoder_seek_absolute(music->flac_decoder, (FLAC__uint64)music->loop_start) ==
FLAC__STREAM_DECODER_SEEK_ERROR) {
SDL_SetError("FLAC__stream_decoder_seek_absolute() failed");
flac.FLAC__stream_decoder_flush(music->flac_decoder);
return -1;
return Mix_SetError("FLAC__stream_decoder_seek_absolute() failed");
} else {
int play_count = -1;
if (music->play_count > 0) {
Expand Down Expand Up @@ -704,8 +702,7 @@ static int FLAC_Seek(void *context, double position)
flac.FLAC__stream_decoder_flush(music->flac_decoder);
}

SDL_SetError("Seeking of FLAC stream failed: libFLAC seek failed.");
return -1;
return Mix_SetError("Seeking of FLAC stream failed: libFLAC seek failed.");
}
return 0;
}
Expand Down
3 changes: 1 addition & 2 deletions src/codecs/music_fluidsynth.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ static int FLUIDSYNTH_GetSome(void *context, void *data, int bytes, SDL_bool *do
}

if (music->synth_write(music->synth, music_spec.samples, music->buffer, 0, 2, music->buffer, 1, 2) != FLUID_OK) {
Mix_SetError("Error generating FluidSynth audio");
return -1;
return Mix_SetError("Error generating FluidSynth audio");
}
if (SDL_AudioStreamPut(music->stream, music->buffer, music->buffer_size) < 0) {
return -1;
Expand Down
14 changes: 4 additions & 10 deletions src/codecs/music_gme.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ static int initialize_from_track_info(GME_Music *music, int track)

err = gme.gme_track_info(music->game_emu, &musInfo, track);
if (err != 0) {
Mix_SetError("GME: %s", err);
return -1;
return Mix_SetError("GME: %s", err);
}

music->track_length = musInfo->length;
Expand Down Expand Up @@ -266,7 +265,7 @@ static void *GME_CreateFromRW(struct SDL_RWops *src, int freesrc)
music->volume = MIX_MAX_VOLUME;

meta_tags_init(&music->tags);
if (initialize_from_track_info(music, 0) == -1) {
if (initialize_from_track_info(music, 0) < 0) {
GME_Delete(music);
return NULL;
}
Expand Down Expand Up @@ -396,17 +395,12 @@ static int GME_StartTrack(void *music_p, int track)

err = gme.gme_start_track(music->game_emu, track);
if (err != 0) {
Mix_SetError("GME: %s", err);
return -1;
return Mix_SetError("GME: %s", err);
}

GME_Play(music, music->play_count);

if (initialize_from_track_info(music, track) == -1) {
return -1;
}

return 0;
return initialize_from_track_info(music, track);
}


Expand Down
9 changes: 3 additions & 6 deletions src/codecs/music_mpg123.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ static int MPG123_Open(const SDL_AudioSpec *spec)
{
(void)spec;
if (mpg123.mpg123_init() != MPG123_OK) {
Mix_SetError("mpg123_init() failed");
return -1;
return Mix_SetError("mpg123_init() failed");
}
return 0;
}
Expand Down Expand Up @@ -392,8 +391,7 @@ static int MPG123_GetSome(void *context, void *data, int bytes, SDL_bool *done)
case MPG123_NEW_FORMAT:
result = mpg123.mpg123_getformat(music->handle, &rate, &channels, &encoding);
if (result != MPG123_OK) {
Mix_SetError("mpg123_getformat: %s", mpg_err(music->handle, result));
return -1;
return Mix_SetError("mpg123_getformat: %s", mpg_err(music->handle, result));
}
#ifdef DEBUG_MPG123
printf("MPG123 format: %s, channels: %d, rate: %ld\n",
Expand Down Expand Up @@ -436,8 +434,7 @@ static int MPG123_GetSome(void *context, void *data, int bytes, SDL_bool *done)
}
break;
default:
Mix_SetError("mpg123_read: %s", mpg_err(music->handle, result));
return -1;
return Mix_SetError("mpg123_read: %s", mpg_err(music->handle, result));
}
return 0;
}
Expand Down
17 changes: 7 additions & 10 deletions src/codecs/music_ogg.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ static int OGG_UpdateSection(OGG_music *music)

vi = vorbis.ov_info(&music->vf, -1);
if (!vi) {
Mix_SetError("ov_info returned NULL");
return -1;
return Mix_SetError("ov_info returned NULL");
}

if (vi->channels == music->vi.channels && vi->rate == music->vi.rate) {
Expand Down Expand Up @@ -257,7 +256,7 @@ static void *OGG_CreateFromRW(SDL_RWops *src, int freesrc)
callbacks.tell_func = sdl_tell_func;

if (vorbis.ov_open_callbacks(src, &music->vf, NULL, 0, callbacks) < 0) {
SDL_SetError("Not an Ogg Vorbis audio stream");
Mix_SetError("Not an Ogg Vorbis audio stream");
SDL_free(music);
return NULL;
}
Expand Down Expand Up @@ -391,8 +390,7 @@ static int OGG_GetSome(void *context, void *data, int bytes, SDL_bool *done)
amount = (int)vorbis.ov_read(&music->vf, music->buffer, music->buffer_size, SDL_BYTEORDER == SDL_BIG_ENDIAN, 2, 1, &section);
#endif
if (amount < 0) {
set_ov_error("ov_read", amount);
return -1;
return set_ov_error("ov_read", amount);
}

if (section != music->section) {
Expand All @@ -407,8 +405,7 @@ static int OGG_GetSome(void *context, void *data, int bytes, SDL_bool *done)
amount -= (int)((pcmPos - music->loop_end) * music->vi.channels) * (int)sizeof(Sint16);
result = vorbis.ov_pcm_seek(&music->vf, music->loop_start);
if (result < 0) {
set_ov_error("ov_pcm_seek", result);
return -1;
return set_ov_error("ov_pcm_seek", result);
} else {
int play_count = -1;
if (music->play_count > 0) {
Expand Down Expand Up @@ -482,7 +479,7 @@ static double OGG_Duration(void *context)
#endif
}

static double OGG_LoopStart(void *music_p)
static double OGG_LoopStart(void *music_p)
{
OGG_music *music = (OGG_music *)music_p;
if (music->loop > 0) {
Expand All @@ -491,7 +488,7 @@ static double OGG_LoopStart(void *music_p)
return -1.0;
}

static double OGG_LoopEnd(void *music_p)
static double OGG_LoopEnd(void *music_p)
{
OGG_music *music = (OGG_music *)music_p;
if (music->loop > 0) {
Expand All @@ -500,7 +497,7 @@ static double OGG_LoopEnd(void *music_p)
return -1.0;
}

static double OGG_LoopLength(void *music_p)
static double OGG_LoopLength(void *music_p)
{
OGG_music *music = (OGG_music *)music_p;
if (music->loop > 0) {
Expand Down
Loading

0 comments on commit 491bb53

Please sign in to comment.