Skip to content

Commit

Permalink
load_voc.c: invent and use new VOC_BAD_RATE macro instead of casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Nov 18, 2019
1 parent 2236c13 commit 77ed762
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions load_voc.c
Expand Up @@ -77,6 +77,8 @@ typedef struct vocstuff {
#define VOC_EXTENDED 8
#define VOC_DATA_16 9

#define VOC_BAD_RATE ~((Uint32)0)


static int voc_check_header(SDL_RWops *src)
{
Expand Down Expand Up @@ -150,7 +152,7 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
return 0;
}

if (((Sint32)v->rate != -1) && (uc != v->rate))
if ((v->rate != VOC_BAD_RATE) && (uc != v->rate))
{
SDL_SetError("VOC sample rate codes differ");
return 0;
Expand Down Expand Up @@ -184,7 +186,7 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
SDL_SetError("VOC Sample rate is zero?");
return 0;
}
if (((Sint32)v->rate != -1) && (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;
Expand Down Expand Up @@ -235,7 +237,7 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
* different sample rate codes in silence.
* Adjust period.
*/
if (((Sint32)v->rate != -1) && (uc != v->rate))
if ((v->rate != VOC_BAD_RATE) && (uc != v->rate))
period = (Uint16)((period * (256 - uc))/(256 - v->rate));
else
v->rate = uc;
Expand Down Expand Up @@ -266,7 +268,7 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
SDL_SetError("VOC sample rate is zero");
return 0;
}
if (((Sint32)v->rate != -1) && (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;
Expand Down Expand Up @@ -380,7 +382,7 @@ SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, int freesrc,
if (!voc_check_header(src))
goto done;

v.rate = ~(Uint32)0;
v.rate = VOC_BAD_RATE;
v.rest = 0;
v.has_extended = 0;
*audio_buf = NULL;
Expand All @@ -390,8 +392,7 @@ SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, int freesrc,
if (!voc_get_block(src, &v, spec))
goto done;

if ((Sint32)v.rate == -1)
{
if (v.rate == VOC_BAD_RATE) {
SDL_SetError("VOC data had no sound!");
goto done;
}
Expand Down Expand Up @@ -432,7 +433,7 @@ SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, int freesrc,

/* Don't return a buffer that isn't a multiple of samplesize */
samplesize = ((spec->format & 0xFF)/8)*spec->channels;
*audio_len &= (Uint32)~(samplesize-1);
*audio_len &= (Uint32) ~(samplesize-1);

done:
if (freesrc && src) {
Expand Down

0 comments on commit 77ed762

Please sign in to comment.