From 5c4e48a83ecd93b1d184e622cb203f8adde6478c Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 17 Mar 2021 23:56:50 +0300
Subject: [PATCH] timidity: minor clean-ups / tidy-ups, mostly whitespace.
---
src/codecs/timidity/instrum.c | 25 ++--
src/codecs/timidity/instrum.h | 8 +-
src/codecs/timidity/mix.c | 34 ++---
src/codecs/timidity/mix.h | 2 -
src/codecs/timidity/output.c | 5 +-
src/codecs/timidity/output.h | 4 +-
src/codecs/timidity/playmidi.c | 228 ++++++++++++++--------------
src/codecs/timidity/readmidi.c | 87 ++++++-----
src/codecs/timidity/readmidi.h | 6 +-
src/codecs/timidity/resample.c | 139 +++++++++--------
src/codecs/timidity/resample.h | 1 -
src/codecs/timidity/tables.c | 12 +-
src/codecs/timidity/tables.h | 3 +-
src/codecs/timidity/timidity.c | 263 +++++++++++++++------------------
14 files changed, 387 insertions(+), 430 deletions(-)
diff --git a/src/codecs/timidity/instrum.c b/src/codecs/timidity/instrum.c
index 1c58379..36da50a 100644
--- a/src/codecs/timidity/instrum.c
+++ b/src/codecs/timidity/instrum.c
@@ -141,8 +141,9 @@ static void reverse_data(Sint16 *sp, Sint32 ls, Sint32 le)
undefined.
TODO: do reverse loops right */
-static Instrument *load_instrument(MidiSong *song, char *name, int percussion,
- int panning, int amp, int note_to_use,
+static Instrument *load_instrument(MidiSong *song, const char *name,
+ int percussion, int panning,
+ int amp, int note_to_use,
int strip_loop, int strip_envelope,
int strip_tail)
{
@@ -214,15 +215,15 @@ static Instrument *load_instrument(MidiSong *song, char *name, int percussion,
Uint16 tmpshort;
Uint8 tmpchar;
-#define READ_CHAR(thing) \
- if (1 != SDL_RWread(rw, &tmpchar, 1, 1)) goto fail; \
- thing = tmpchar;
-#define READ_SHORT(thing) \
- if (1 != SDL_RWread(rw, &tmpshort, 2, 1)) goto fail; \
- thing = SDL_SwapLE16(tmpshort);
-#define READ_LONG(thing) \
- if (1 != SDL_RWread(rw, &tmplong, 4, 1)) goto fail; \
- thing = (Sint32)SDL_SwapLE32((Uint32)tmplong);
+#define READ_CHAR(thing) \
+ if (1 != SDL_RWread(rw, &tmpchar, 1, 1)) goto fail; \
+ thing = tmpchar;
+#define READ_SHORT(thing) \
+ if (1 != SDL_RWread(rw, &tmpshort, 2, 1)) goto fail; \
+ thing = SDL_SwapLE16(tmpshort);
+#define READ_LONG(thing) \
+ if (1 != SDL_RWread(rw, &tmplong, 4, 1)) g oto fail; \
+ thing = (Sint32)SDL_SwapLE32((Uint32)tmplong);
SDL_RWseek(rw, 7, RW_SEEK_CUR); /* Skip the wave name */
@@ -581,7 +582,7 @@ void free_instruments(MidiSong *song)
}
}
-int set_default_instrument(MidiSong *song, char *name)
+int set_default_instrument(MidiSong *song, const char *name)
{
Instrument *ip;
if (!(ip=load_instrument(song, name, 0, -1, -1, -1, 0, 0, 0)))
diff --git a/src/codecs/timidity/instrum.h b/src/codecs/timidity/instrum.h
index 3371fce..fa3f3ba 100644
--- a/src/codecs/timidity/instrum.h
+++ b/src/codecs/timidity/instrum.h
@@ -1,14 +1,12 @@
/*
-
TiMidity -- Experimental MIDI to WAVE converter
Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
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.h
-
- */
+ instrum.h
+*/
/* Bits in modes: */
#define MODES_16BIT (1<<0)
@@ -27,4 +25,4 @@
extern int load_missing_instruments(MidiSong *song);
extern void free_instruments(MidiSong *song);
-extern int set_default_instrument(MidiSong *song, char *name);
+extern int set_default_instrument(MidiSong *song, const char *name);
diff --git a/src/codecs/timidity/mix.c b/src/codecs/timidity/mix.c
index 13d601a..a0759c7 100644
--- a/src/codecs/timidity/mix.c
+++ b/src/codecs/timidity/mix.c
@@ -77,14 +77,14 @@ void apply_envelope_to_amp(MidiSong *song, int v)
}
la = (Sint32)FSCALE(lamp,AMP_BITS);
-
+
if (la>MAX_AMP_VALUE)
la=MAX_AMP_VALUE;
ra = (Sint32)FSCALE(ramp,AMP_BITS);
if (ra>MAX_AMP_VALUE)
ra=MAX_AMP_VALUE;
-
+
song->voice[v].left_mix = la;
song->voice[v].right_mix = ra;
}
@@ -186,7 +186,7 @@ static void mix_mystery_signal(MidiSong *song, sample_t *sp, Sint32 *lp, int v,
left = vp->left_mix;
right = vp->right_mix;
}
-
+
while (count)
if (cc < count)
{
@@ -232,7 +232,7 @@ static void mix_center_signal(MidiSong *song, sample_t *sp, Sint32 *lp, int v,
return; /* Envelope ran out */
left = vp->left_mix;
}
-
+
while (count)
if (cc < count)
{
@@ -269,7 +269,7 @@ static void mix_single_signal(MidiSong *song, sample_t *sp, Sint32 *lp, int v,
left=vp->left_mix;
int cc;
sample_t s;
-
+
if (!(cc = vp->control_counter))
{
cc = song->control_ratio;
@@ -277,7 +277,7 @@ static void mix_single_signal(MidiSong *song, sample_t *sp, Sint32 *lp, int v,
return; /* Envelope ran out */
left = vp->left_mix;
}
-
+
while (count)
if (cc < count)
{
@@ -314,7 +314,7 @@ static void mix_mono_signal(MidiSong *song, sample_t *sp, Sint32 *lp, int v,
left=vp->left_mix;
int cc;
sample_t s;
-
+
if (!(cc = vp->control_counter))
{
cc = song->control_ratio;
@@ -322,7 +322,7 @@ static void mix_mono_signal(MidiSong *song, sample_t *sp, Sint32 *lp, int v,
return; /* Envelope ran out */
left = vp->left_mix;
}
-
+
while (count)
if (cc < count)
{
@@ -355,7 +355,7 @@ static void mix_mystery(MidiSong *song, sample_t *sp, Sint32 *lp, int v, int cou
left = song->voice[v].left_mix,
right = song->voice[v].right_mix;
sample_t s;
-
+
while (count--)
{
s = *sp++;
@@ -369,7 +369,7 @@ static void mix_center(MidiSong *song, sample_t *sp, Sint32 *lp, int v, int coun
final_volume_t
left = song->voice[v].left_mix;
sample_t s;
-
+
while (count--)
{
s = *sp++;
@@ -383,7 +383,7 @@ static void mix_single(MidiSong *song, sample_t *sp, Sint32 *lp, int v, int coun
final_volume_t
left = song->voice[v].left_mix;
sample_t s;
-
+
while (count--)
{
s = *sp++;
@@ -397,7 +397,7 @@ static void mix_mono(MidiSong *song, sample_t *sp, Sint32 *lp, int v, int count)
final_volume_t
left = song->voice[v].left_mix;
sample_t s;
-
+
while (count--)
{
s = *sp++;
@@ -408,7 +408,6 @@ static void mix_mono(MidiSong *song, sample_t *sp, Sint32 *lp, int v, int count)
/* Ramp a note out in c samples */
static void ramp_out(MidiSong *song, sample_t *sp, Sint32 *lp, int v, Sint32 c)
{
-
/* should be final_volume_t, but Uint8 gives trouble. */
Sint32 left, right, li, ri;
@@ -446,7 +445,7 @@ static void ramp_out(MidiSong *song, sample_t *sp, Sint32 *lp, int v, Sint32 c)
left += li;
if (left<0)
return;
- s=*sp++;
+ s=*sp++;
MIXATION(left);
MIXATION(left);
}
@@ -534,16 +533,17 @@ void mix_voice(MidiSong *song, Sint32 *buf, int v, Sint32 c)
mix_center(song, sp, buf, v, c);
}
else
- {
+ {
/* It's either full left or full right. In either case,
every other sample is 0. Just get the offset right: */
if (vp->panned == PANNED_RIGHT) buf++;
-
+
if (vp->envelope_increment || vp->tremolo_phase_increment)
mix_single_signal(song, sp, buf, v, c);
- else
+ else
mix_single(song, sp, buf, v, c);
}
}
}
}
+
diff --git a/src/codecs/timidity/mix.h b/src/codecs/timidity/mix.h
index be2a5f1..f729146 100644
--- a/src/codecs/timidity/mix.h
+++ b/src/codecs/timidity/mix.h
@@ -1,5 +1,4 @@
/*
-
TiMidity -- Experimental MIDI to WAVE converter
Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
@@ -7,7 +6,6 @@
it under the terms of the Perl Artistic License, available in COPYING.
mix.h
-
*/
extern void mix_voice(MidiSong *song, Sint32 *buf, int v, Sint32 c);
diff --git a/src/codecs/timidity/output.c b/src/codecs/timidity/output.c
index 0c42061..cc9f9d2 100644
--- a/src/codecs/timidity/output.c
+++ b/src/codecs/timidity/output.c
@@ -1,5 +1,4 @@
-/*
-
+/*
TiMidity -- Experimental MIDI to WAVE converter
Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
@@ -7,7 +6,7 @@
it under the terms of the Perl Artistic License, available in COPYING.
output.c
-
+
Audio output (to file / device) functions.
*/
diff --git a/src/codecs/timidity/output.h b/src/codecs/timidity/output.h
index 849bb47..8cfd122 100644
--- a/src/codecs/timidity/output.h
+++ b/src/codecs/timidity/output.h
@@ -1,5 +1,4 @@
-/*
-
+/*
TiMidity -- Experimental MIDI to WAVE converter
Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
@@ -7,7 +6,6 @@
it under the terms of the Perl Artistic License, available in COPYING.
output.h
-
*/
/* Data format encoding bits */
diff --git a/src/codecs/timidity/playmidi.c b/src/codecs/timidity/playmidi.c
index f9d3574..f6cd32a 100644
--- a/src/codecs/timidity/playmidi.c
+++ b/src/codecs/timidity/playmidi.c
@@ -21,8 +21,8 @@
#include "tables.h"
static void adjust_amplification(MidiSong *song)
-{
- song->master_volume = (float)(song->amplification) / (float)100.0;
+{
+ song->master_volume = (float)(song->amplification) / 100.0f;
}
static void reset_voices(MidiSong *song)
@@ -73,25 +73,24 @@ static void select_sample(MidiSong *song, int v, Instrument *ip)
}
f=song->voice[v].orig_frequency;
- for (i=0; i<s; i++)
+ for (i=0; i<s; i++, sp++)
{
if (sp->low_freq <= f && sp->high_freq >= f)
{
song->voice[v].sample=sp;
return;
}
- sp++;
}
- /*
+ /*
No suitable sample found! We'll select the sample whose root
frequency is closest to the one we want. (Actually we should
- probably convert the low, high, and root frequencies to MIDI note
- values and compare those.) */
-
+ probably convert the low, high, and root frequencies to MIDI
+ note values and compare those.)
+ */
cdiff=0x7FFFFFFF;
closest=sp=ip->sample;
- for(i=0; i<s; i++)
+ for(i=0; i<s; i++, sp++)
{
diff=sp->root_freq - f;
if (diff<0) diff=-diff;
@@ -100,10 +99,8 @@ static void select_sample(MidiSong *song, int v, Instrument *ip)
cdiff=diff;
closest=sp;
}
- sp++;
}
song->voice[v].sample=closest;
- return;
}
static void recompute_freq(MidiSong *song, int v)
@@ -112,7 +109,7 @@ static void recompute_freq(MidiSong *song, int v)
sign=(song->voice[v].sample_increment < 0), /* for bidirectional loops */
pb=song->channel[song->voice[v].channel].pitchbend;
double a;
-
+
if (!song->voice[v].sample->sample_rate)
return;
@@ -156,7 +153,7 @@ static void recompute_freq(MidiSong *song, int v)
(double)(song->rate)),
FRACTION_BITS);
- if (sign)
+ if (sign)
a = -a; /* need to preserve the loop direction */
song->voice[v].sample_increment = (Sint32)(a);
@@ -241,7 +238,7 @@ static void start_note(MidiSong *song, MidiEvent *e, int i)
song->voice[i].orig_frequency = freq_table[(int)(ip->sample->note_to_use)];
else
song->voice[i].orig_frequency = freq_table[e->a & 0x7F];
-
+
/* drums are supposed to have only one sample */
song->voice[i].sample = ip->sample;
}
@@ -313,7 +310,7 @@ static void kill_note(MidiSong *song, int i)
/* Only one instance of a note can be playing on a single channel. */
static void note_on(MidiSong *song)
{
- int i = song->voices, lowest=-1;
+ int i = song->voices, lowest=-1;
Sint32 lv=0x7FFFFFFF, v;
MidiEvent *e = song->current_event;
@@ -332,7 +329,7 @@ static void note_on(MidiSong *song)
start_note(song,e,lowest);
return;
}
-
+
/* Look for the decaying note with the lowest volume */
i = song->voices;
while (i--)
@@ -358,7 +355,7 @@ static void note_on(MidiSong *song)
spare for ramping down this note, we wouldn't need to kill it
in the first place... Still, this needs to be fixed. Perhaps
we could use a reserve of voices to play dying notes only. */
-
+
song->cut_notes++;
song->voice[lowest].status=VOICE_FREE;
start_note(song,e,lowest);
@@ -380,8 +377,8 @@ static void finish_note(MidiSong *song, int i)
else
{
/* Set status to OFF so resample_voice() will let this voice out
- of its loop, if any. In any case, this voice dies when it
- hits the end of its data (ofs>=data_length). */
+ of its loop, if any. In any case, this voice dies when it
+ hits the end of its data (ofs>=data_length). */
song->voice[i].status = VOICE_OFF;
}
}
@@ -443,7 +440,7 @@ static void adjust_pressure(MidiSong *song)
{
MidiEvent *e = song->current_event;
int i = song->voices;
-
+
while (i--)
if (song->voice[i].status == VOICE_ON &&
song->voice[i].channel == e->channel &&
@@ -470,7 +467,7 @@ static void adjust_pitchbend(MidiSong *song)
{
int c = song->current_event->channel;
int i = song->voices;
-
+
while (i--)
if (song->voice[i].status != VOICE_FREE && song->voice[i].channel == c)
{
@@ -506,28 +503,28 @@ static void seek_forward(MidiSong *song, Sint32 until_time)
song->current_event->a;
song->channel[song->current_event->channel].pitchfactor = 0;
break;
-
+
case ME_PITCHWHEEL:
song->channel[song->current_event->channel].pitchbend =
song->current_event->a + song->current_event->b * 128;
song->channel[song->current_event->channel].pitchfactor = 0;
break;
-
+
case ME_MAINVOLUME:
song->channel[song->current_event->channel].volume =
song->current_event->a;
break;
-
+
case ME_PAN:
song->channel[song->current_event->channel].panning =
song->current_event->a;
break;
-
+
case ME_EXPRESSION:
song->channel[song->current_event->channel].expression =
song->current_event->a;
break;
-
+
case ME_PROGRAM:
if (ISDRUMCHANNEL(song, song->current_event->channel))
/* Change drum set */
@@ -546,12 +543,12 @@ static void seek_forward(MidiSong *song, Sint32 until_time)
case ME_RESET_CONTROLLERS:
reset_controllers(song, song->current_event->channel);
break;
-
+
case ME_TONE_BANK:
song->channel[song->current_event->channel].bank =
song->current_event->a;
break;
-
+
case ME_EOT:
song->current_sample = song->current_event->time;
return;
@@ -573,7 +570,7 @@ static void skip_to(MidiSong *song, Sint32 until_time)
song->buffered_count = 0;
song->buffer_pointer = song->common_buffer;
song->current_event = song->events;
-
+
if (until_time)
seek_forward(song, until_time);
}
@@ -655,112 +652,109 @@ int Timidity_PlaySome(MidiSong *song, void *stream, Sint32 len)
if (!song->playing)
return 0;
-
+
bytes_per_sample = 1;
bytes_per_sample *= ((song->encoding & PE_32BIT) ? 4 : ((song->encoding & PE_16BIT) ? 2 : 1));
bytes_per_sample *= ((song->encoding & PE_MONO) ? 1 : 2);
samples = len / bytes_per_sample;
-
+
start_sample = song->current_sample;
end_sample = song->current_sample+samples;
while ( song->current_sample < end_sample ) {
/* Handle all events that should happen at this time */
while (song->current_event->time <= song->current_sample) {
switch(song->current_event->type) {
+ /* Effects affecting a single note */
+ case ME_NOTEON:
+ if (!(song->current_event->b)) /* Velocity 0? */
+ note_off(song);
+ else
+ note_on(song);
+ break;
+
+ case ME_NOTEOFF:
+ note_off(song);
+ break;
+
+ case ME_KEYPRESSURE:
+ adjust_pressure(song);
+ break;
- /* Effects affecting a single note */
-
- case ME_NOTEON:
- if (!(song->current_event->b)) /* Velocity 0? */
- note_off(song);
- else
- note_on(song);
- break;
-
- case ME_NOTEOFF:
- note_off(song);
- break;
-
- case ME_KEYPRESSURE:
- adjust_pressure(song);
- break;
-
- /* Effects affecting a single channel */
-
- case ME_PITCH_SENS:
- song->channel[song->current_event->channel].pitchsens =
+ /* Effects affecting a single channel */
+ case ME_PITCH_SENS:
+ song->channel[song->current_event->channel].pitchsens =
song->current_event->a;
- song->channel[song->current_event->channel].pitchfactor = 0;
- break;
-
- case ME_PITCHWHEEL:
- song->channel[song->current_event->channel].pitchbend =
- song->current_event->a + song->current_event->b * 128;
- song->channel[song->current_event->channel].pitchfactor = 0;
- /* Adjust pitch for notes already playing */
- adjust_pitchbend(song);
- break;
-
- case ME_MAINVOLUME:
- song->channel[song->current_event->channel].volume =
+ song->channel[song->current_event->channel].pitchfactor = 0;
+ break;
+
+ case ME_PITCHWHEEL:
+ song->channel[song->current_event->channel].pitchbend =
+ song->current_event->a + song->current_event->b * 128;
+ song->channel[song->current_event->channel].pitchfactor = 0;
+ /* Adjust pitch for notes already playing */
+ adjust_pitchbend(song);
+ break;
+
+ case ME_MAINVOLUME:
+ song->channel[song->current_event->channel].volume =
song->current_event->a;
- adjust_volume(song);
- break;
-
- case ME_PAN:
- song->channel[song->current_event->channel].panning =
+ adjust_volume(song);
+ break;
+
+ case ME_PAN:
+ song->channel[song->current_event->channel].panning =
song->current_event->a;
- break;
-
- case ME_EXPRESSION:
- song->channel[song->current_event->channel].expression =
+ break;
+
+ case ME_EXPRESSION:
+ song->channel[song->current_event->channel].expression =
song->current_event->a;
- adjust_volume(song);
- break;
-
- case ME_PROGRAM:
- if (ISDRUMCHANNEL(song, song->current_event->channel)) {
- /* Change drum set */
- song->channel[song->current_event->channel].bank =
+ adjust_volume(song);
+ break;
+
+ case ME_PROGRAM:
+ if (ISDRUMCHANNEL(song, song->current_event->channel)) {
+ /* Change drum set */
+ song->channel[song->current_event->channel].bank =
song->current_event->a;
- }
- else
- song->channel[song->current_event->channel].program =
+ }
+ else
+ song->channel[song->current_event->channel].program =
song->current_event->a;
- break;
-
- case ME_SUSTAIN:
- song->channel[song->current_event->channel].sustain =
+ break;
+
+ case ME_SUSTAIN:
+ song->channel[song->current_event->channel].sustain =
song->current_event->a;
- if (!song->current_event->a)
- drop_sustain(song);
- break;
-
- case ME_RESET_CONTROLLERS:
- reset_controllers(song, song->current_event->channel);
- break;
-
- case ME_ALL_NOTES_OFF:
- all_notes_off(song);
- break;
-
- case ME_ALL_SOUNDS_OFF:
- all_sounds_off(song);
- break;
-
- case ME_TONE_BANK:
- song->channel[song->current_event->channel].bank =
+ if (!song->current_event->a)
+ drop_sustain(song);
+ break;
+
+ case ME_RESET_CONTROLLERS:
+ reset_controllers(song, song->current_event->channel);
+ break;
+
+ case ME_ALL_NOTES_OFF:
+ all_notes_off(song);
+ break;
+
+ case ME_ALL_SOUNDS_OFF:
+ all_sounds_off(song);
+ break;
+
+ case ME_TONE_BANK:
+ song->channel[song->current_event->channel].bank =
song->current_event->a;
- break;
-
- case ME_EOT:
- /* Give the last notes a couple of seconds to decay */
- SNDDBG(("Playing time: ~%d seconds\n",
- song->current_sample/song->rate+2));
- SNDDBG(("Notes cut: %d\n", song->cut_notes));
- SNDDBG(("Notes lost totally: %d\n", song->lost_notes));
+ break;
+
+ case ME_EOT:
+ /* Give the last notes a couple of seconds to decay */
+ SNDDBG(("Playing time: ~%d seconds\n",
+ song->current_sample/song->rate+2));
+ SNDDBG(("Notes cut: %d\n", song->cut_notes));
+ SNDDBG(("Notes lost totally: %d\n", song->lost_notes));
song->playing = 0;
- return (song->current_sample - start_sample) * bytes_per_sample;
+ return (song->current_sample - start_sample) * bytes_per_sample;
}
song->current_event++;
}
@@ -786,7 +780,7 @@ void Timidity_SetVolume(MidiSong *song, int volume)
for (i = 0; i < song->voices; i++)
if (song->voice[i].status != VOICE_FREE)
{
- recompute_amp(song, i);
- apply_envelope_to_amp(song, i);
+ recompute_amp(song, i);
+ apply_envelope_to_amp(song, i);
}
}
diff --git a/src/codecs/timidity/readmidi.c b/src/codecs/timidity/readmidi.c
index 5245c5d..237e60b 100644
--- a/src/codecs/timidity/readmidi.c
+++ b/src/codecs/timidity/readmidi.c
@@ -49,10 +49,10 @@ static Sint32 getvl(SDL_RWops *rw)
or unprintable characters will be converted to periods. */
static int dumpstring(SDL_RWops *rw, Sint32 len, Uint8 type)
{
- static char *label[]={
+ static const char *label[] = {
"Text event: ", "Text: ", "Copyright: ", "Track name: ",
- "Instrument: ", "Lyric: ", "Marker: ", "Cue point: "};
- signed char *s=SDL_malloc(len+1);
+ "Instrument: ", "Lyric: ", "Marker: ", "Cue point: " };
+ signed char *s = SDL_malloc(len+1);
if (len != (Sint32) SDL_RWread(rw, s, 1, len))
{
SDL_free(s);
@@ -70,11 +70,15 @@ static int dumpstring(SDL_RWops *rw, Sint32 len, Uint8 type)
}
#endif
-#define MIDIEVENT(at,t,ch,pa,pb) \
- new=SDL_malloc(sizeof(MidiEventList)); \
- new->event.time=at; new->event.type=t; new->event.channel=ch; \
- new->event.a=pa; new->event.b=pb; new->next=0;\
- return new;
+#define MIDIEVENT(at,t,ch,pa,pb) \
+ newlist = (MidiEventList *) SDL_malloc(sizeof(MidiEventList));\
+ newlist->event.time = at; \
+ newlist->event.type = t; \
+ newlist->event.channel = ch; \
+ newlist->event.a = pa; \
+ newlist->event.b = pb; \
+ newlist->next = NULL; \
+ return newlist;
#define MAGIC_EOT ((MidiEventList *)(-1))
@@ -86,7 +90,7 @@ static MidiEventList *read_midi_event(MidiSong *song)
static Uint8 nrpn=0, rpn_msb[16], rpn_lsb[16]; /* one per channel */
Uint8 me, type, a,b,c;
Sint32 len;
- MidiEventList *new;
+ MidiEventList *newlist;
for (;;)
{
@@ -96,7 +100,7 @@ static MidiEventList *read_midi_event(MidiSong *song)
SNDDBG(("read_midi_event: SDL_RWread() failure\n"));
return NULL;
}
-
+
if(me==0xF0 || me == 0xF7) /* SysEx event */
{
len=getvl(song->rw);
@@ -122,7 +126,7 @@ static MidiEventList *read_midi_event(MidiSong *song)
SDL_RWread(song->rw, &b, 1, 1);
SDL_RWread(song->rw, &c, 1, 1);
MIDIEVENT(song->at, ME_TEMPO, c, a, b);
-
+
default:
SNDDBG(("(Meta event type 0x%02x, length %d)\n", type, len));
SDL_RWseek(song->rw, len, RW_SEEK_CUR);
@@ -171,12 +175,12 @@ static MidiEventList *read_midi_event(MidiSong *song)
case 121: control=ME_RESET_CONTROLLERS; break;
case 123: control=ME_ALL_NOTES_OFF; break;
- /* These should be the SCC-1 tone bank switch
- commands. I don't know why there are two, or
- why the latter only allows switching to bank 0.
- Also, some MIDI files use 0 as some sort of
- continuous controller. This will cause lots of
- warnings about undefined tone banks. */
+ /* These should be the SCC-1 tone bank switch
+ commands. I don't know why there are two, or
+ why the latter only allows switching to bank 0.
+ Also, some MIDI files use 0 as some sort of
+ continuous controller. This will cause lots of
+ warnings about undefined tone banks. */
case 0: control=ME_TONE_BANK; break;
case 32:
if (b!=0) {
@@ -192,7 +196,7 @@ static MidiEventList *read_midi_event(MidiSong *song)
case 101: nrpn=0; rpn_lsb[lastchan]=b; break;
case 99: nrpn=1; rpn_msb[lastchan]=b; break;
case 98: nrpn=1; rpn_lsb[lastchan]=b; break;
-
+
case 6:
if (nrpn)
{
@@ -200,7 +204,7 @@ static MidiEventList *read_midi_event(MidiSong *song)
rpn_msb[lastchan], rpn_lsb[lastchan], b));
break;
}
-
+
switch((rpn_msb[lastchan]<<8) | rpn_lsb[lastchan])
{
case 0x0000: /* Pitch bend sensitivity */
@@ -217,13 +221,13 @@ static MidiEventList *read_midi_event(MidiSong *song)
break;
}
break;
-
+
default:
SNDDBG(("(Control %d: %d)\n", a, b));
break;
}
if (control != 255)
- {
+ {
MIDIEVENT(song->at, control, lastchan, b, 0);
}
}
@@ -241,15 +245,15 @@ static MidiEventList *read_midi_event(MidiSong *song)
b &= 0x7F;
MIDIEVENT(song->at, ME_PITCHWHEEL, lastchan, a, b);
- default:
+ default:
SNDDBG(("*** Can't happen: status 0x%02X, channel 0x%02X\n",
laststatus, lastchan));
break;
}
}
}
-
- return new;
+
+ return newlist;
}
#undef MIDIEVENT
@@ -259,7 +263,7 @@ static MidiEventList *read_midi_event(MidiSong *song)
static int read_track(MidiSong *song, int append)
{
MidiEventList *meep;
- MidiEventList *next, *new;
+ MidiEventList *next, *newlist;
Sint32 len;
Sint64 next_pos, pos;
char tmp[4];
@@ -276,7 +280,6 @@ static int read_track(MidiSong *song, int append)
song->at=0;
/* Check the formalities */
-
if (SDL_RWread(song->rw, tmp, 1, 4) != 4 || SDL_RWread(song->rw, &len, 4, 1) != 1)
{
SNDDBG(("Can't read track header.\n"));
@@ -292,29 +295,31 @@ static int read_track(MidiSong *song, int append)
for (;;)
{
- if (!(new=read_midi_event(song))) /* Some kind of error */
+ if (!(newlist=read_midi_event(song))) /* Some kind of error */
return -2;
- if (new==MAGIC_EOT) /* End-of-track Hack. */
+ if (newlist==MAGIC_EOT) /* End-of-track Hack. */
{
- pos = SDL_RWtell(song->rw);
- if (pos < next_pos)
- SDL_RWseek(song->rw, next_pos - pos, RW_SEEK_CUR);
+ /* If the track ends before the size of the
+ * track data, skip any junk at the end. */
+ pos = SDL_RWtell(song->rw);
+ if (pos < next_pos)
+ SDL_RWseek(song->rw, next_pos - pos, RW_SEEK_CUR);
return 0;
}
next=meep->next;
- while (next && (next->event.time < new->event.time))
+ while (next && (next->event.time < newlist->event.time))
{
meep=next;
next=meep->next;
}
-
- new->next=next;
- meep->next=new;
+
+ newlist->next=next;
+ meep->next=newlist;
song->event_count++; /* Count the event. (About one?) */
- meep=new;
+ meep=newlist;
}
}
@@ -322,14 +327,14 @@ static int read_track(MidiSong *song, int append)
static void free_midi_list(MidiSong *song)
{
MidiEventList *meep, *next;
- if (!(meep = song->evlist)) return;
+ meep = song->evlist;
while (meep)
{
next=meep->next;
SDL_free(meep);
meep=next;
}
- song->evlist=NULL;
+ song->evlist = NULL;
}
/* Allocate an array of MidiEvents and fill it from the linked list of
@@ -344,7 +349,7 @@ static MidiEvent *groom_list(MidiSong *song, Sint32 divisions,Sint32 *eventsp,
Sint32 i, our_event_count, tempo, skip_this_event, new_value;
Sint32 sample_cum, samples_to_do, at, st, dt, counting_time;
- int current_bank[MAXCHAN], current_set[MAXCHAN], current_program[MAXCHAN];
+ int current_bank[MAXCHAN], current_set[MAXCHAN], current_program[MAXCHAN];
/* Or should each bank have its own current program? */
for (i=0; i<MAXCHAN; i++)
@@ -389,7 +394,7 @@ static MidiEvent *groom_list(MidiSong *song, Sint32 divisions,Sint32 *eventsp,
}
if (current_set[meep->event.channel] != new_value)
current_set[meep->event.channel]=new_value;
- else
+ else
skip_this_event=1;
}
else
@@ -435,7 +440,7 @@ static MidiEvent *groom_list(MidiSong *song, Sint32 divisions,Sint32 *eventsp,
}
if (song->tonebank[meep->event.a]) /* Is this a defined tone bank? */
new_value=meep->event.a;
- else
+ else
{
SNDDBG(("Tone bank %d is undefined\n", meep->event.a));
new_value=meep->event.a=0;
diff --git a/src/codecs/timidity/readmidi.h b/src/codecs/timidity/readmidi.h
index 295c6e3..020b587 100644
--- a/src/codecs/timidity/readmidi.h
+++ b/src/codecs/timidity/readmidi.h
@@ -1,13 +1,11 @@
/*
-
TiMidity -- Experimental MIDI to WAVE converter
Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
This program is free software; you can redistribute it and/or modify
it under the terms of the Perl Artistic License, available in COPYING.
- readmidi.h
-
- */
+ readmidi.h
+*/
extern MidiEvent *read_midi_file(MidiSong *song, Sint32 *count, Sint32 *sp);
diff --git a/src/codecs/timidity/resample.c b/src/codecs/timidity/resample.c
index 66b2f7c..7fd9ac3 100644
--- a/src/codecs/timidity/resample.c
+++ b/src/codecs/timidity/resample.c
@@ -51,7 +51,7 @@ static sample_t *rs_plain(MidiSong *song, int v, Sint32 *countptr)
{
i = count;
count = 0;
- }
+ }
else count -= i;
for (j = 0; j < i; j++)
@@ -62,51 +62,50 @@ static sample_t *rs_plain(MidiSong *song, int v, Sint32 *countptr)
ofs += incr;
}
- if (ofs >= le)
+ if (ofs >= le)
{
if (ofs == le)
*dest++ = src[(ofs>>FRACTION_BITS)-1]/2;
vp->status=VOICE_FREE;
*countptr-=count+1;
}
-
+
vp->sample_offset=ofs; /* Update offset */
return song->resample_buffer;
}
static sample_t *rs_loop(MidiSong *song, Voice *vp, Sint32 count)
{
-
/* Play sample until end-of-loop, skip back and continue. */
sample_t v1, v2;
Sint32
- ofs=vp->sample_offset,
+ ofs=vp->sample_offset,
incr=vp->sample_increment,
- le=vp->sample->loop_end,
+ le=vp->sample->loop_end,
ll=le - vp->sample->loop_start;
sample_t
*dest=song->resample_buffer,
*src=vp->sample->data;
Sint32 i, j;
-
- while (count)
+
+ while (count)
{
while (ofs >= le)
ofs -= ll;
/* Precalc how many times we should go through the loop */
i = PRECALC_LOOP_COUNT(ofs, le, incr);
- if (i > count)
+ if (i > count)
{
i = count;
count = 0;
- }
+ }
else count -= i;
for (j = 0; j < i; j++)
{
- v1 = src[ofs >> FRACTION_BITS];
- v2 = src[(ofs >> FRACTION_BITS)+1];
- *dest++ = v1 + (((v2 - v1) * (ofs & FRACTION_MASK)) >> FRACTION_BITS);
+ v1 = src[ofs >> FRACTION_BITS];
+ v2 = src[(ofs >> FRACTION_BITS)+1];
+ *dest++ = v1 + (((v2 - v1) * (ofs & FRACTION_MASK)) >> FRACTION_BITS);
ofs += incr;
}
}
@@ -124,7 +123,7 @@ static sample_t *rs_bidir(MidiSong *song, Voice *vp, Sint32 count)
le=vp->sample->loop_end,
ls=vp->sample->loop_start;
sample_t
- *dest=song->resample_buffer,
+ *dest=song->resample_buffer,
*src=vp->sample->data;
Sint32
le2 = le<<1,
@@ -138,47 +137,46 @@ static sample_t *rs_bidir(MidiSong *song, Voice *vp, Sint32 count)
when doing bidirectional looping. I have yet to see a case
where both ofs <= ls AND incr < 0, however. */
i = PRECALC_LOOP_COUNT(ofs, ls, incr);
- if (i > count)
+ if (i > count)
{
i = count;
count = 0;
- }
+ }
else count -= i;
for (j = 0; j < i;
(Patch may be truncated, please check the link at the top of this post.)