Skip to content

Commit

Permalink
timidity: remove noluck variable and directly check whether rw is NULL.
Browse files Browse the repository at this point in the history
  • Loading branch information
sezero committed Dec 16, 2019
1 parent ca41cee commit 8700723
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions src/codecs/timidity/instrum.c
Expand Up @@ -6,8 +6,8 @@
This program is free software; you can redistribute it and/or modify
it under the terms of the Perl Artistic License, available in COPYING.
instrum.c
instrum.c
Code to load and unload GUS-compatible instrument patches.
*/
Expand Down Expand Up @@ -60,7 +60,7 @@ static void free_bank(MidiSong *song, int dr, int b)
static Sint32 convert_envelope_rate(MidiSong *song, Uint8 rate)
{
Sint32 r;

r = 3 - ((rate >> 6) & 0x3);
r *= 3;
r = (Sint32) (rate & 0x3f) << r; /* 6.9 fixed point */
Expand Down Expand Up @@ -139,12 +139,12 @@ static void reverse_data(Sint16 *sp, Sint32 ls, Sint32 le)
}
}

/*
/*
If panning or note_to_use != -1, it will be used for all samples,
instead of the sample-specific values in the instrument file.
For note_to_use, any value <0 or >127 will be forced to 0.
For other parameters, 1 means yes, 0 means no, other values are
undefined.
Expand All @@ -158,16 +158,15 @@ static Instrument *load_instrument(MidiSong *song, char *name, int percussion,
Sample *sp;
SDL_RWops *rw;
char tmp[1024];
int i,j,noluck=0;
int i,j;
static char *patch_ext[] = PATCH_EXT_LIST;
(void)percussion; /* unused */

(void)percussion; /* unused */
if (!name) return 0;

/* Open patch file */
if ((rw=open_file(name)) == NULL)
{
noluck=1;
/* Try with various extensions */
for (i=0; patch_ext[i]; i++)
{
Expand All @@ -176,22 +175,19 @@ static Instrument *load_instrument(MidiSong *song, char *name, int percussion,
strcpy(tmp, name);
strcat(tmp, patch_ext[i]);
if ((rw=open_file(tmp)) != NULL)
{
noluck=0;
break;
}
}
}
}
if (noluck)

if (rw == NULL)
{
SNDDBG(("Instrument `%s' can't be found.\n", name));
return 0;
}

SNDDBG(("Loading instrument %s\n", tmp));

/* Read some headers and do cursory sanity checks. There are loads
of magic offsets. This could be rewritten... */

Expand All @@ -204,8 +200,8 @@ static Instrument *load_instrument(MidiSong *song, char *name, int percussion,
SDL_RWclose(rw);
return 0;
}
if (tmp[82] != 1 && tmp[82] != 0) /* instruments. To some patch makers,

if (tmp[82] != 1 && tmp[82] != 0) /* instruments. To some patch makers,
0 means 1 */
{
SNDDBG(("Can't handle patches with %d instruments\n", tmp[82]));
Expand All @@ -219,13 +215,12 @@ static Instrument *load_instrument(MidiSong *song, char *name, int percussion,
SDL_RWclose(rw);
return 0;
}

ip=safe_malloc(sizeof(Instrument));
ip->samples = tmp[198];
ip->sample = safe_malloc(sizeof(Sample) * ip->samples);
for (i=0; i<ip->samples; i++)
{

Uint8 fractions;
Sint32 tmplong;
Uint16 tmpshort;
Expand Down Expand Up @@ -256,7 +251,7 @@ static Instrument *load_instrument(MidiSong *song, char *name, int percussion,
}

sp=&(ip->sample[i]);

READ_LONG(sp->data_length);
READ_LONG(sp->loop_start);
READ_LONG(sp->loop_end);
Expand All @@ -266,7 +261,7 @@ static Instrument *load_instrument(MidiSong *song, char *name, int percussion,
READ_LONG(sp->root_freq);
SDL_RWseek(rw, 2, RW_SEEK_CUR); /* Why have a "root frequency" and then
* "tuning"?? */

READ_CHAR(tmp[0]);

if (panning==-1)
Expand Down Expand Up @@ -314,20 +309,19 @@ static Instrument *load_instrument(MidiSong *song, char *name, int percussion,
READ_CHAR(sp->modes);

SDL_RWseek(rw, 40, RW_SEEK_CUR); /* skip the useless scale frequency, scale
factor (what's it mean?), and reserved
space */
factor (what's it mean?), and reserved
space */

/* Mark this as a fixed-pitch instrument if such a deed is desired. */
if (note_to_use!=-1)
sp->note_to_use=(Uint8)(note_to_use);
else
sp->note_to_use=0;

/* seashore.pat in the Midia patch set has no Sustain. I don't
understand why, and fixing it by adding the Sustain flag to
all looped patches probably breaks something else. We do it
anyway. */

if (sp->modes & MODES_LOOPING)
sp->modes |= MODES_SUSTAIN;

Expand Down Expand Up @@ -388,7 +382,7 @@ static Instrument *load_instrument(MidiSong *song, char *name, int percussion,
sp->data = (sample_t *) safe_malloc(sp->data_length+4);
if (1 != SDL_RWread(rw, sp->data, sp->data_length, 1))
goto fail;

if (!(sp->modes & MODES_16BIT)) /* convert to 16-bit data */
{
Sint32 k=sp->data_length;
Expand Down Expand Up @@ -416,7 +410,7 @@ static Instrument *load_instrument(MidiSong *song, char *name, int percussion,
}
}
#endif

if (sp->modes & MODES_UNSIGNED) /* convert to signed data */
{
Sint32 k=sp->data_length/2;
Expand Down

0 comments on commit 8700723

Please sign in to comment.