Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for absolute transform #1409

Merged
merged 5 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/sfloader/fluid_defsfont.c
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ fluid_zone_mod_import_sfont(char *zone_name, fluid_mod_t **mod, SFZone *sfzone)
/* Note: When secondary source input (src2) is set to General Controller 'No Controller',
output will be forced to +1.0 at synthesis time (see fluid_mod_get_value()).
That means that this source will behave unipolar only. We need to force the
unipolar flag to ensure to ensure a correct evaluation of the minimum
unipolar flag to ensure a correct evaluation of the minimum
value later (see fluid_voice_get_lower_boundary_for_attenuation()).
*/
if(((mod_dest->flags2 & FLUID_MOD_CC) == FLUID_MOD_GC) &&
Expand All @@ -1648,14 +1648,8 @@ fluid_zone_mod_import_sfont(char *zone_name, fluid_mod_t **mod, SFZone *sfzone)
mod_dest->flags2 &= ~FLUID_MOD_BIPOLAR;
}

/* *** Transform *** */
/* SF2.01 only uses the 'linear' transform (0).
* Deactivate the modulator by setting the amount to 0 in any other case.
*/
if(mod_src->trans != 0)
{
mod_dest->amount = 0;
}
/* *** Transform Type *** */
mod_dest->trans = mod_src->trans;
spessasus marked this conversation as resolved.
Show resolved Hide resolved

/* Store the new modulator in the zone The order of modulators
* will make a difference, at least in an instrument context: The
Expand Down
12 changes: 10 additions & 2 deletions src/synth/fluid_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fluid_mod_clone(fluid_mod_t *mod, const fluid_mod_t *src)
mod->src2 = src->src2;
mod->flags2 = src->flags2;
mod->amount = src->amount;
mod->trans = src->trans;
}

/**
Expand Down Expand Up @@ -382,6 +383,7 @@ fluid_mod_get_value(fluid_mod_t *mod, fluid_voice_t *voice)
extern fluid_mod_t default_vel2filter_mod;

fluid_real_t v1 = 0.0, v2 = 1.0;
fluid_real_t final_value;
/* The wording of the default modulators refers to a range of 127/128.
* And the table in section 9.5.3 suggests, that this mapping should be applied
* to all unipolar and bipolar mappings respectively.
Expand Down Expand Up @@ -470,8 +472,14 @@ fluid_mod_get_value(fluid_mod_t *mod, fluid_voice_t *voice)
v2 = 1.0f;
}

/* it's as simple as that: */
return (fluid_real_t) mod->amount * v1 * v2;
/* it indeed is as simple as that: */
final_value = (fluid_real_t) mod->amount * v1 * v2;
/* check for absolute value transform*/
if(mod->trans == 2)
spessasus marked this conversation as resolved.
Show resolved Hide resolved
{
final_value = fabs(final_value);
spessasus marked this conversation as resolved.
Show resolved Hide resolved
}
return final_value;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/synth/fluid_mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct _fluid_mod_t
unsigned char flags1; /**< Source controller 1 flags */
unsigned char src2; /**< Source controller 2 */
unsigned char flags2; /**< Source controller 2 flags */
unsigned char trans; /**< Output transform flag */
derselbst marked this conversation as resolved.
Show resolved Hide resolved
double amount; /**< Multiplier amount */
/* The 'next' field allows to link modulators into a list. It is
* not used in fluid_voice.c, there each voice allocates memory for a
Expand Down
Loading