refactor data types of fluid_channel_t members

Use char if possible + reorder fields to avoid padding. Overall saved 408 bytes per fluid_channel_t instance
This commit is contained in:
derselbst 2018-04-25 17:21:38 +02:00
parent f34567fb61
commit f8e4890a63
2 changed files with 35 additions and 35 deletions

View file

@ -65,8 +65,8 @@
struct mononote
{
unsigned char next; /* next note */
unsigned char note; /* note */
unsigned char vel; /* velocity */
char note; /* note */
char vel; /* velocity */
};
/*
@ -83,42 +83,46 @@ struct _fluid_channel_t
/* Poly Mono variables see macro access description */
int mode; /**< Poly Mono mode */
int mode_val; /**< number of channel in basic channel group */
/* monophonic list - legato detector */
struct mononote monolist[FLUID_CHANNEL_SIZE_MONOLIST]; /**< monophonic list */
unsigned char i_first; /**< First note index */
unsigned char i_last; /**< most recent note index since the most recent add */
unsigned char prev_note; /**< previous note of the most recent add/remove */
char prev_note; /**< previous note of the most recent add/remove */
unsigned char n_notes; /**< actual number of notes in the list */
/*--*/
int key_mono_sustained; /**< previous sustained monophonic note */
struct mononote monolist[FLUID_CHANNEL_SIZE_MONOLIST]; /**< monophonic list */
char key_mono_sustained; /**< previous sustained monophonic note */
char previous_cc_breath; /**< Previous Breath */
enum fluid_channel_legato_mode legatomode; /**< legato mode */
enum fluid_channel_portamento_mode portamentomode; /**< portamento mode */
int previous_cc_breath; /**< Previous Breath */
/*- End of Poly/mono variables description */
int sfont_bank_prog; /**< SoundFont ID (bit 21-31), bank (bit 7-20), program (bit 0-6) */
fluid_preset_t* preset; /**< Selected preset */
char cc[128]; /**< MIDI controller values */
char key_pressure[128]; /**< MIDI polyphonic key pressure */
int channel_pressure; /**< MIDI channel pressure */
int pitch_bend; /**< Current pitch bend value */
int pitch_wheel_sensitivity; /**< Current pitch wheel sensitivity */
int cc[128]; /**< MIDI controller values */
/* Drum channel flag, CHANNEL_TYPE_MELODIC, or CHANNEL_TYPE_DRUM. */
enum fluid_midi_channel_type channel_type;
enum fluid_interp interp_method; /**< Interpolation method (enum fluid_interp) */
char channel_pressure; /**< MIDI channel pressure */
char pitch_wheel_sensitivity; /**< Current pitch wheel sensitivity */
short pitch_bend; /**< Current pitch bend value */
/* Sostenuto order id gives the order of SostenutoOn event.
This value is useful to known when the sostenuto pedal is depressed
(before or after a key note). We need to compare SostenutoOrderId with voice id.
* This value is useful to known when the sostenuto pedal is depressed
* (before or after a key note). We need to compare SostenutoOrderId with voice id.
*/
unsigned int sostenuto_orderid;
int interp_method; /**< Interpolation method (enum fluid_interp) */
fluid_tuning_t* tuning; /**< Micro tuning */
int tuning_bank; /**< Current tuning bank number */
int tuning_prog; /**< Current tuning program number */
fluid_tuning_t* tuning; /**< Micro tuning */
fluid_preset_t* preset; /**< Selected preset */
int sfont_bank_prog; /**< SoundFont ID (bit 21-31), bank (bit 7-20), program (bit 0-6) */
/* NRPN system */
int nrpn_select; /* Generator ID of SoundFont NRPN message */
int nrpn_active; /* 1 if data entry CCs are for NRPN, 0 if RPN */
enum fluid_gen_type nrpn_select; /* Generator ID of SoundFont NRPN message */
char nrpn_active; /* 1 if data entry CCs are for NRPN, 0 if RPN */
/* The values of the generators, set by NRPN messages, or by
* fluid_synth_set_gen(), are cached in the channel so they can be
@ -137,10 +141,6 @@ struct _fluid_channel_t
* flag indicating whether the NRPN value is absolute or not.
*/
char gen_abs[GEN_LAST];
/* Drum channel flag, CHANNEL_TYPE_MELODIC, or CHANNEL_TYPE_DRUM. */
int channel_type;
};
fluid_channel_t* new_fluid_channel(fluid_synth_t* synth, int num);
@ -231,7 +231,7 @@ int fluid_channel_get_interp_method(fluid_channel_t* chan);
fluid_channel_legato(chan))
/* Macros interface to monophonic list variables */
#define INVALID_NOTE 255
#define INVALID_NOTE (-1)
/* Returns true when a note is a valid note */
#define fluid_channel_is_valid_note(n) (n != INVALID_NOTE)
/* Marks prev_note as invalid. */

View file

@ -162,10 +162,10 @@
* - In mono staccato playing,default_fromkey must be INVALID_NOTE.
* - In mono legato playing,default_fromkey must be valid.
*/
static unsigned char fluid_synth_get_fromkey_portamento_legato(fluid_channel_t* chan,
unsigned char default_fromkey)
static char fluid_synth_get_fromkey_portamento_legato(fluid_channel_t* chan,
char default_fromkey)
{
unsigned char ptc = fluid_channel_get_cc(chan, PORTAMENTO_CTRL);
char ptc = fluid_channel_get_cc(chan, PORTAMENTO_CTRL);
if(fluid_channel_is_valid_note(ptc))
{ /* CC PTC has been received */
fluid_channel_clear_portamento(chan); /* clears the CC PTC receive */
@ -178,12 +178,12 @@ static unsigned char fluid_synth_get_fromkey_portamento_legato(fluid_channel_t*
}
else
{ /* determines and returns fromkey portamento */
unsigned char fromkey_portamento = INVALID_NOTE;
char fromkey_portamento = INVALID_NOTE;
if(fluid_channel_portamento(chan))
{ /* Portamento when Portamento pedal is On */
/* 'fromkey portamento'is determined from the portamento mode
and the most recent note played (prev_note)*/
unsigned char portamentomode = chan->portamentomode;
enum fluid_channel_portamento_mode portamentomode = chan->portamentomode;
if(fluid_channel_is_valid_note(default_fromkey))
{
fromkey_portamento = default_fromkey; /* on each note */
@ -319,7 +319,7 @@ int fluid_synth_noteon_mono_LOCAL(fluid_synth_t* synth, int chan,
fluid_channel_t* channel = synth->channel[chan];
/* Adds the note into the monophonic list */
fluid_channel_add_monolist(channel,(unsigned char)key,(unsigned char)vel,0);
fluid_channel_add_monolist(channel, key, vel, 0);
/* in Breath Sync mode, the noteon triggering is postponed
until the musician starts blowing in the breath controller */
@ -381,7 +381,7 @@ int fluid_synth_noteoff_mono_LOCAL(fluid_synth_t* synth, int chan, int key)
int i,i_prev;
fluid_channel_t* channel = synth->channel[chan];
/* searching the note in the monophonic list */
i=fluid_channel_search_monolist(channel, (unsigned char)key , &i_prev);
i=fluid_channel_search_monolist(channel, key , &i_prev);
if (i >= 0)
{ /* the note is in the monophonic list */
@ -624,11 +624,11 @@ int fluid_synth_noteon_monopoly_legato(fluid_synth_t* synth, int chan,
int fromkey, int tokey, int vel)
{
fluid_channel_t* channel = synth->channel[chan];
unsigned char legatomode = channel->legatomode;
enum fluid_channel_legato_mode legatomode = channel->legatomode;
fluid_voice_t* voice;
int i ;
/* Gets possible 'fromkey portamento' and possible 'fromkey legato' note */
fromkey = fluid_synth_get_fromkey_portamento_legato( channel, (unsigned char)fromkey);
fromkey = fluid_synth_get_fromkey_portamento_legato( channel, fromkey);
if (fluid_channel_is_valid_note(fromkey)) for (i = 0; i < synth->polyphony; i++)
{