Skip to content

Commit

Permalink
Changed all the Sound_SetError() calls to __Sound_SetError (or BAIL*_…
Browse files Browse the repository at this point in the history
…MACRO)
  • Loading branch information
icculus committed Jul 5, 2002
1 parent b498ea0 commit 6d7a0b8
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 156 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG
Expand Up @@ -3,7 +3,9 @@
*/

07052002 - Cleaned up some stuff in playsound.c, removing some FIXMEs.
Commandline validation is improved, too.
Commandline validation is improved, too. FIXME removal in
voc.c; should report i/o errors correctly now. Changed DECLSPEC
to SNDDECLSPEC to prevent SDL conflict, and added SDLCALL support.
07022002 - Added WinCE support pack to website, updated INSTALL with CE info.
More altcvt fixes from Frank Ranostaj.
07012002 - Fixed configure.in to work around bug in older autoconfs. Started
Expand Down
16 changes: 8 additions & 8 deletions SDL_sound.c
Expand Up @@ -358,7 +358,7 @@ void __Sound_SetError(const char *str)
if (str == NULL)
return;

SNDDBG(("Sound_SetError(\"%s\");%s\n", str,
SNDDBG(("__Sound_SetError(\"%s\");%s\n", str,
(initialized) ? "" : " [NOT INITIALIZED!]"));

if (!initialized)
Expand Down Expand Up @@ -444,7 +444,7 @@ static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
Sound_SampleInternal *internal = malloc(sizeof (Sound_SampleInternal));
if ((retval == NULL) || (internal == NULL))
{
Sound_SetError(ERR_OUT_OF_MEMORY);
__Sound_SetError(ERR_OUT_OF_MEMORY);
if (retval)
free(retval);
if (internal)
Expand All @@ -460,7 +460,7 @@ static Sound_Sample *alloc_sample(SDL_RWops *rw, Sound_AudioInfo *desired,
retval->buffer = malloc(bufferSize); /* pure ugly. */
if (!retval->buffer)
{
Sound_SetError(ERR_OUT_OF_MEMORY);
__Sound_SetError(ERR_OUT_OF_MEMORY);
free(internal);
free(retval);
return(NULL);
Expand Down Expand Up @@ -549,7 +549,7 @@ static int init_sample(const Sound_DecoderFunctions *funcs,
desired.rate,
sample->buffer_size) == -1)
{
Sound_SetError(SDL_GetError());
__Sound_SetError(SDL_GetError());
funcs->close(sample);
SDL_RWseek(internal->rw, pos, SEEK_SET); /* set for next try... */
return(0);
Expand Down Expand Up @@ -668,7 +668,7 @@ Sound_Sample *Sound_NewSample(SDL_RWops *rw, const char *ext,
free(retval->buffer);
free(retval);
SDL_RWclose(rw);
Sound_SetError(ERR_UNSUPPORTED_FORMAT);
__Sound_SetError(ERR_UNSUPPORTED_FORMAT);
return(NULL);
} /* Sound_NewSample */

Expand Down Expand Up @@ -700,13 +700,13 @@ void Sound_FreeSample(Sound_Sample *sample)

if (!initialized)
{
Sound_SetError(ERR_NOT_INITIALIZED);
__Sound_SetError(ERR_NOT_INITIALIZED);
return;
} /* if */

if (sample == NULL)
{
Sound_SetError(ERR_INVALID_ARGUMENT);
__Sound_SetError(ERR_INVALID_ARGUMENT);
return;
} /* if */

Expand Down Expand Up @@ -827,7 +827,7 @@ Uint32 Sound_DecodeAll(Sound_Sample *sample)
if (ptr == NULL)
{
sample->flags |= SOUND_SAMPLEFLAG_ERROR;
Sound_SetError(ERR_OUT_OF_MEMORY);
__Sound_SetError(ERR_OUT_OF_MEMORY);
} /* if */
else
{
Expand Down
7 changes: 2 additions & 5 deletions SDL_sound_internal.h
Expand Up @@ -163,13 +163,13 @@ typedef struct __SOUND_DECODERFUNCTIONS__
* sample->flags |= SOUND_SAMPLEFLAG_EOF;
*
* If there's an unrecoverable error, then do:
* Sound_SetError(ERR_EXPLAIN_WHAT_WENT_WRONG);
* __Sound_SetError(ERR_EXPLAIN_WHAT_WENT_WRONG);
* sample->flags |= SOUND_SAMPLEFLAG_ERROR;
*
* If there's more data, but you'd have to block for considerable
* amounts of time to get at it, or there's a recoverable error,
* then do:
* Sound_SetError(ERR_EXPLAIN_WHAT_WENT_WRONG);
* __Sound_SetError(ERR_EXPLAIN_WHAT_WENT_WRONG);
* sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;
*
* SDL_sound will not call your read() method for any samples with
Expand Down Expand Up @@ -273,9 +273,6 @@ typedef struct __SOUND_SAMPLEINTERNAL__
*/
void __Sound_SetError(const char *err);

/* !!! FIXME: Clean up elsewhere and get rid of this. */
#define Sound_SetError __Sound_SetError

/*
* Call this to convert milliseconds to an actual byte position, based on
* audio data characteristics.
Expand Down
6 changes: 4 additions & 2 deletions alt_audio_convert.h
Expand Up @@ -32,6 +32,8 @@
#define Sound_AI_Loop 0x2
#define _fsize 32

#include "SDL_sound.h"

typedef struct{
Sint16 numerator;
Sint16 denominator;
Expand Down Expand Up @@ -72,9 +74,9 @@ typedef struct{

#define SDL_SOUND_Loop 0x10

extern DECLSPEC int Sound_ConvertAudio( Sound_AudioCVT *Data );
extern SNDDECLSPEC int Sound_ConvertAudio( Sound_AudioCVT *Data );

extern DECLSPEC int Sound_BuildAudioCVT( Sound_AudioCVT *Data,
extern SNDDECLSPEC int Sound_BuildAudioCVT( Sound_AudioCVT *Data,
Uint16 src_format, Uint8 src_channels, int src_rate,
Uint16 dst_format, Uint8 dst_channels, int dst_rate, Uint32 dst_size );

Expand Down
2 changes: 1 addition & 1 deletion audio_convert.c
Expand Up @@ -551,7 +551,7 @@ int Sound_ConvertAudio(Sound_AudioCVT *cvt)
/* Make sure there's data to convert */
if (cvt->buf == NULL)
{
Sound_SetError("No buffer allocated for conversion");
__Sound_SetError("No buffer allocated for conversion");
return(-1);
} /* if */

Expand Down
9 changes: 3 additions & 6 deletions decoders/aiff.c
Expand Up @@ -441,8 +441,7 @@ static int read_fmt(SDL_RWops *rw, comm_t *c, fmt_t *fmt)
default:
SNDDBG(("AIFF: Format %lu is unknown.\n",
(unsigned int) fmt->type));
Sound_SetError("AIFF: Unsupported format");
return(0); /* not supported whatsoever. */
BAIL_MACRO("AIFF: Unsupported format", 0);
} /* switch */

assert(0); /* shouldn't hit this point. */
Expand Down Expand Up @@ -508,16 +507,14 @@ static int AIFF_open(Sound_Sample *sample, const char *ext)

if (!find_chunk(rw, ssndID))
{
Sound_SetError("AIFF: No sound data chunk.");
free(a);
return(0);
BAIL_MACRO("AIFF: No sound data chunk.", 0);
} /* if */

if (!read_ssnd_chunk(rw, &s))
{
Sound_SetError("AIFF: Can't read sound data chunk.");
free(a);
return(0);
BAIL_MACRO("AIFF: Can't read sound data chunk.", 0);
} /* if */

a->fmt.total_bytes = a->bytesLeft = bytes_per_sample * c.numSampleFrames;
Expand Down
13 changes: 4 additions & 9 deletions decoders/au.c
Expand Up @@ -171,11 +171,8 @@ static int AU_open(Sound_Sample *sample, const char *ext)
struct audec *dec;
char c;

if (!read_au_header(rw, &hdr)) /* does byte order swapping. */
{
Sound_SetError("AU: Not an .au file (bad header)");
return(0);
} /* if */
/* read_au_header() will do byte order swapping. */
BAIL_IF_MACRO(!read_au_header(rw, &hdr), "AU: bad header", 0);

dec = malloc(sizeof *dec);
BAIL_IF_MACRO(dec == NULL, ERR_OUT_OF_MEMORY, 0);
Expand Down Expand Up @@ -203,9 +200,8 @@ static int AU_open(Sound_Sample *sample, const char *ext)
break;

default:
Sound_SetError("AU: Unsupported .au encoding");
free(dec);
return 0;
BAIL_MACRO("AU: Unsupported .au encoding", 0);
} /* switch */

sample->actual.rate = hdr.sample_rate;
Expand Down Expand Up @@ -244,9 +240,8 @@ static int AU_open(Sound_Sample *sample, const char *ext)

else
{
Sound_SetError("AU: Not an .AU stream.");
free(dec);
return(0);
BAIL_MACRO("AU: Not an .AU stream.", 0);
} /* else */

sample->flags = SOUND_SAMPLEFLAG_CANSEEK;
Expand Down
12 changes: 4 additions & 8 deletions decoders/flac.c
Expand Up @@ -308,8 +308,7 @@ static void error_callback(
{
flac_t *f = (flac_t *) client_data;

/* !!! FIXME: Is every error really fatal? I don't know... */
Sound_SetError(d_error_status_string[status]);
__Sound_SetError(d_error_status_string[status]);
f->sample->flags |= SOUND_SAMPLEFLAG_ERROR;
} /* error_callback */

Expand Down Expand Up @@ -449,9 +448,8 @@ static int FLAC_open(Sound_Sample *sample, const char *ext)
decoder = d_new();
if (decoder == NULL)
{
Sound_SetError(ERR_OUT_OF_MEMORY);
free(f);
return(0);
BAIL_MACRO(ERR_OUT_OF_MEMORY, 0);
} /* if */

d_set_read_callback(decoder, read_callback);
Expand Down Expand Up @@ -515,9 +513,8 @@ static int FLAC_open(Sound_Sample *sample, const char *ext)
/* Still not FLAC? Give up. */
if (!f->is_flac)
{
Sound_SetError("FLAC: No metadata found. Not a FLAC stream?");
free_flac(f);
return(0);
BAIL_MACRO("FLAC: No metadata found. Not a FLAC stream?", 0);
} /* if */
} /* if */

Expand All @@ -543,9 +540,8 @@ static Uint32 FLAC_read(Sound_Sample *sample)

if (!d_process_one_frame(f->decoder))
{
Sound_SetError("FLAC: Couldn't decode frame.");
sample->flags |= SOUND_SAMPLEFLAG_ERROR;
return(0);
BAIL_MACRO("FLAC: Couldn't decode frame.", 0);
} /* if */

if (d_get_state(f->decoder) == D_END_OF_STREAM)
Expand Down
3 changes: 1 addition & 2 deletions decoders/modplug.c
Expand Up @@ -189,8 +189,7 @@ static int MODPLUG_open(Sound_Sample *sample, const char *ext)
if (!has_extension)
{
SNDDBG(("MODPLUG: Unrecognized file type: %s\n", ext));
Sound_SetError("MODPLUG: Not a module file.");
return(0);
BAIL_MACRO("MODPLUG: Not a module file.", 0);
} /* if */

/*
Expand Down
20 changes: 7 additions & 13 deletions decoders/mpglib/interface.c
Expand Up @@ -53,14 +53,12 @@ static struct buf *addbuf(struct mpstr *mp,char *buf,int size)
struct buf *nbuf;

nbuf = malloc( sizeof(struct buf) );
if(!nbuf) {
Sound_SetError("MPGLIB: Out of memory!");
return NULL;
}
BAIL_IF_MACRO(!nbuf, ERR_OUT_OF_MEMORY, NULL);

nbuf->pnt = malloc(size);
if(!nbuf->pnt) {
free(nbuf);
return NULL;
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
}
nbuf->size = size;
memcpy(nbuf->pnt,buf,size);
Expand Down Expand Up @@ -106,8 +104,7 @@ static int read_buf_byte(struct mpstr *mp, unsigned long *retval)
remove_buf(mp);
pos = mp->tail->pos;
if(!mp->tail) {
Sound_SetError("MPGLIB: Fatal error! Short read in read_buf_byte()!");
return 0;
BAIL_MACRO("MPGLIB: Short read in read_buf_byte()!", 0);
}
}

Expand Down Expand Up @@ -155,10 +152,7 @@ int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
{
int len;

if(osize < 4608) {
Sound_SetError("MPGLIB: Not enough output space for decoding!");
return MP3_ERR;
}
BAIL_IF_MACRO(osize < 4608, "MPGLIB: Output buffer too small", MP3_ERR);

if(in) {
if(addbuf(mp,in,isize) == NULL) {
Expand Down Expand Up @@ -232,8 +226,8 @@ int set_pointer(long backstep, struct mpstr *mp)
{
unsigned char *bsbufold;
if(mp->fsizeold < 0 && backstep > 0) {
Sound_SetError("MPGLIB: Can't step back!"); /* FIXME: need formatting: %ld!\n",backstep); */
return MP3_ERR;
/* FIXME: need formatting: %ld!\n",backstep); */
BAIL_MACRO("MPGLIB: Can't step back!", MP3_ERR);
}
bsbufold = mp->bsspace[mp->bsnum] + 512;
wordpointer -= backstep;
Expand Down
20 changes: 9 additions & 11 deletions decoders/mpglib/layer3.c
Expand Up @@ -347,8 +347,7 @@ static int III_get_side_info_1(struct III_sideinfo *si,int stereo,
gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3);

if(gr_info->block_type == 0) {
Sound_SetError("MPGLIB: Blocktype == 0 and window-switching == 1 not allowed.");
return 0;
BAIL_MACRO("MPGLIB: Blocktype == 0 and window-switching == 1 not allowed.", 0);
}
/* region_count/start parameters are implicit in this case. */
gr_info->region1start = 36>>1;
Expand Down Expand Up @@ -421,8 +420,7 @@ static int III_get_side_info_2(struct III_sideinfo *si,int stereo,
gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3);

if(gr_info->block_type == 0) {
Sound_SetError("MPGLIB: Blocktype == 0 and window-switching == 1 not allowed.");
return 0;
BAIL_MACRO("MPGLIB: Blocktype == 0 and window-switching == 1 not allowed.", 0);
}
/* region_count/start parameters are implicit in this case. */
/* check this again! */
Expand Down Expand Up @@ -956,8 +954,8 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
if(part2remain > 0)
getbits(part2remain);
else if(part2remain < 0) {
Sound_SetError("MPGLIB: Can't rewind stream!"); /* !!! FIXME: Need formatting: by %d bits!\n",-part2remain);*/
return 1; /* -> error */
/* !!! FIXME: Need formatting: by %d bits!\n",-part2remain);*/
BAIL_MACRO("MPGLIB: Can't rewind stream!", 1); /* -> error */
}
return 0;
}
Expand Down Expand Up @@ -1367,8 +1365,8 @@ static int III_dequantize_sample_ms(real xr[2][SBLIMIT][SSLIMIT],int *scf,
if(part2remain > 0 )
getbits(part2remain);
else if(part2remain < 0) {
Sound_SetError("MPGLIB: Can't rewind stream!"); /* !!! FIXME: Need formatting: by %d bits!\n",-part2remain); */
return 1; /* -> error */
/* !!! FIXME: Need formatting: by %d bits!\n",-part2remain);*/
BAIL_MACRO("MPGLIB: Can't rewind stream!", 1); /* -> error */
}
return 0;
}
Expand Down Expand Up @@ -1906,7 +1904,7 @@ int do_layer3(struct frame *fr,unsigned char *pcm_sample,
if(!III_get_side_info_1(&sideinfo,stereo,ms_stereo,sfreq,single))
return -1;
#else
Sound_SetError("MPGLIB: Not supported!");
__Sound_SetError("MPGLIB: Not supported!");
#endif
}

Expand All @@ -1927,7 +1925,7 @@ int do_layer3(struct frame *fr,unsigned char *pcm_sample,
#ifdef MPEG1
part2bits = III_get_scale_factors_1(scalefacs[0],gr_info);
#else
Sound_SetError("MPGLIB: Not supported!");
__Sound_SetError("MPGLIB: Not supported!");
#endif
}
if(III_dequantize_sample(hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits))
Expand All @@ -1942,7 +1940,7 @@ int do_layer3(struct frame *fr,unsigned char *pcm_sample,
#ifdef MPEG1
part2bits = III_get_scale_factors_1(scalefacs[1],gr_info);
#else
Sound_SetError("MPGLIB: Not supported!");
__Sound_SetError("MPGLIB: Not supported!");
#endif
}

Expand Down

0 comments on commit 6d7a0b8

Please sign in to comment.