Skip to content

Commit

Permalink
Add support for AWE32 NRPNs (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst authored Oct 31, 2024
1 parent 98b115f commit e93eab2
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/rvoice/fluid_iir_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ void fluid_iir_filter_calc(fluid_iir_filter_t *iir_filter,
fres = 5.f;
}

// FLUID_LOG(FLUID_INFO, "%f + %f cents = %f cents = %f Hz | Q: %f", iir_filter->fres, fres_mod, iir_filter->fres + fres_mod, fres, iir_filter->q_lin);
/* if filter enabled and there is a significant frequency change.. */
if(iir_filter->type != FLUID_IIR_DISABLED && FLUID_FABS(fres - iir_filter->last_fres) > 0.01f)
{
Expand Down
10 changes: 7 additions & 3 deletions src/sfloader/fluid_defsfont.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,6 @@ fluid_defpreset_noteon(fluid_defpreset_t *defpreset, fluid_synth_t *synth, int c

for(i = 0; i < GEN_LAST; i++)
{

/* SF 2.01 section 9.4 'bullet' 4:
*
* A generator in a local instrument zone supersedes a
Expand All @@ -977,7 +976,6 @@ fluid_defpreset_noteon(fluid_defpreset_t *defpreset, fluid_synth_t *synth, int c
* Do nothing, leave it at the default.
*/
}

} /* for all generators */

/* Adds instrument zone modulators (global and local) to the voice.*/
Expand All @@ -991,7 +989,7 @@ fluid_defpreset_noteon(fluid_defpreset_t *defpreset, fluid_synth_t *synth, int c

for(i = 0; i < GEN_LAST; i++)
{

fluid_real_t awe_val;
/* SF 2.01 section 8.5 page 58: If some generators are
encountered at preset level, they should be ignored.
However this check is not necessary when the soundfont
Expand Down Expand Up @@ -1026,6 +1024,12 @@ fluid_defpreset_noteon(fluid_defpreset_t *defpreset, fluid_synth_t *synth, int c
* Do nothing, leave it unchanged.
*/
}

/* ...unless the default value has been overridden by an AWE32 NRPN */
if (fluid_channel_get_override_gen_default(synth->channel[chan], i, &awe_val))
{
fluid_voice_gen_set(voice, i, awe_val);
}
} /* for all generators */

/* Adds preset zone modulators (global and local) to the voice.*/
Expand Down
22 changes: 22 additions & 0 deletions src/synth/fluid_chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ fluid_channel_init_ctrl(fluid_channel_t *chan, int is_all_ctrl_off)
for(i = 0; i < GEN_LAST; i++)
{
chan->gen[i] = 0.0f;
chan->override_gen_default[i].flags = GEN_UNUSED;
chan->override_gen_default[i].val = 0.0f;
}
// Not all MIDIs initialize the IIR filter coefficient, e.g. Uplift.mid.
// A default value is not documented, hence I'm assuming zero here.
chan->awe32_filter_coeff = 0;

if(is_all_ctrl_off)
{
Expand Down Expand Up @@ -730,3 +735,20 @@ void fluid_channel_cc_breath_note_on_off(fluid_channel_t *chan, int value)

chan->previous_cc_breath = value;
}

int fluid_channel_get_override_gen_default(fluid_channel_t *chan, int gen, fluid_real_t* val)
{
if(chan->override_gen_default[gen].flags != GEN_UNUSED)
{
*val = chan->override_gen_default[gen].val;
return TRUE;
}

return FALSE;
}

void fluid_channel_set_override_gen_default(fluid_channel_t *chan, int gen, fluid_real_t val)
{
chan->override_gen_default[gen].flags = GEN_SET;
chan->override_gen_default[gen].val = val;
}
12 changes: 12 additions & 0 deletions src/synth/fluid_chan.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "fluidsynth_priv.h"
#include "fluid_midi.h"
#include "fluid_tuning.h"
#include "fluid_gen.h"

/* The mononophonic list is part of the legato detector for monophonic mode */
/* see fluid_synth_monopoly.c about a description of the legato detector device */
Expand Down Expand Up @@ -124,11 +125,20 @@ struct _fluid_channel_t
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 */

char awe32_filter_coeff;

/* The values of the generators, set by NRPN messages, or by
* fluid_synth_set_gen(), are cached in the channel so they can be
* applied to future notes. They are copied to a voice's generators
* in fluid_voice_init(), which calls fluid_gen_init(). */
fluid_real_t gen[GEN_LAST];

/* Same for AWE32 NRPNs, however they override the gen's default values */
struct
{
enum fluid_gen_flags flags;
fluid_real_t val;
} override_gen_default[GEN_LAST];
};

fluid_channel_t *new_fluid_channel(fluid_synth_t *synth, int num);
Expand Down Expand Up @@ -272,5 +282,7 @@ void fluid_channel_invalid_prev_note_staccato(fluid_channel_t *chan);
void fluid_channel_cc_legato(fluid_channel_t *chan, int value);
void fluid_channel_cc_breath_note_on_off(fluid_channel_t *chan, int value);

int fluid_channel_get_override_gen_default(fluid_channel_t *chan, int gen, fluid_real_t *val);
void fluid_channel_set_override_gen_default(fluid_channel_t *chan, int gen, fluid_real_t val);

#endif /* _FLUID_CHAN_H */
2 changes: 1 addition & 1 deletion src/synth/fluid_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ fluid_mod_get_source_value(const unsigned char mod_src,
/**
* transforms the initial value retrieved by \c fluid_mod_get_source_value into [0.0;1.0]
*/
static fluid_real_t
fluid_real_t
fluid_mod_transform_source_value(fluid_real_t val, unsigned char mod_flags, const fluid_real_t range)
{
/* normalized value, i.e. usually in the range [0;1] */
Expand Down
2 changes: 2 additions & 0 deletions src/synth/fluid_mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ struct _fluid_mod_t

fluid_real_t fluid_mod_get_value(fluid_mod_t *mod, fluid_voice_t *voice);
int fluid_mod_check_sources(const fluid_mod_t *mod, char *name);
fluid_real_t fluid_mod_transform_source_value(fluid_real_t val, unsigned char mod_flags, const fluid_real_t range);


#ifdef DEBUG
void fluid_dump_modulator(fluid_mod_t *mod);
Expand Down
Loading

0 comments on commit e93eab2

Please sign in to comment.