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 modulators checking at soundfont loading time #467

Merged
merged 31 commits into from
Dec 21, 2018

Conversation

jjceresa
Copy link
Collaborator

Actually some basic modulators check are done at noteon time (in fluid_voice_add_mod()). That means that we know if a modulator (modx) is invalid only when a MIDI noteon is received and only for a preset modx belongs to. This is not appropriate.

This PR moves the modulator checking at soundfont loading time. Enhancements are:

  1. A better verbose modulator integrity check, for any soudnfont loaded at appropriate time.
    1.1) All modulators are checked (preset zone (local/global), instrument zone (local/global).
    1.2.1) Modulators check are enforced to source src1 and src2 (for non-CC and CC sources) (following SF specs (except for CC LSB) ( see comment in fluid_synth_cc_LOCAL()).
    Modulators CC sources checking is coherent with the actual behaviour in fluid_synth_cc_LOCAL() in regard of modulation triggering.
    1.2.2)Also, identic modulator in the same zone are detected.
    1.2.3)Any invalid modulator(sources invalid, or modulator identic) is removed at loading time with a warning message displaying the cause and name of the modulators.

  2. This fix a bug in noteon, in the case of identic modulators in global preset zone.
    Assuming 2 identics modulator (m1 and m2) in a preset global zone, the actual noteon doesn't check this case. (the actual code detect identic modulator in all others zones (instrument (local or global), preset(local)) but not preset global).

  3. NoteOn is faster.
    2.1)There is no more modulators checks at noteon making this more efficient.
    2.2 As there are no identic modulator in the same zone, there is no more identity modulator check (i.e local zone against local zone), (i.e global zone against global zone). This result in a faster code and the bug described in (2) is gone.

  4. Modulators sources checking as been added in API functions fluid_synth_add_default_mod() and fluid_voice_add_mod(). Please note that actually fluid_voice_add_mod() has no return code, but this could be perhaps changed ?

jjceresa added 10 commits November 20, 2018 00:04
- This step 1 adds modulators checking when loading soundfont.
-   This is done when importing soundfont.
-   Invalid modulators are removed from zones modulators list.
- Removing modulators check at noteOn time.
This is done by introducing fluid_voice_add_mod_local() function.
- Since duplicate modulators were removed at soundfont
loading, it worth to avoid wasting cpu cycles at noteon time.
- change name voice_mod_list_limit_count to voice_mod_limit_count.
- Fix typos.
-rename count to mod_idx
Copy link
Member

@derselbst derselbst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Some comments below.

* local version of fluid_voice_add_mod function. Called at noteon time.
* @param voice, mod, mode, same as for fluid_voice_add_mod() (see above).
* @param check_limit_count is the modulator number limit to handle with existing
* identical modulator(for mode FLUID_VOICE_OVERWRITE or FLUID_VOICE_OVERWRITE only).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FLUID_VOICE_OVERWRITE or FLUID_VOICE_OVERWRITE ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant why are you listing FLUID_VOICE_OVERWRITE twice?

src/synth/fluid_voice.c Show resolved Hide resolved
* #FLUID_VOICE_ADD to add (offset) the modulator amounts,
* #FLUID_VOICE_OVERWRITE to replace the modulator,
*/
void static
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure that static is always at the beginning of the declaration: https://travis-ci.org/FluidSynth/fluidsynth/jobs/458603436#L982

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more occurrences, pls see the provided build log.

src/synth/fluid_mod.c Outdated Show resolved Hide resolved
src/sfloader/fluid_defsfont.c Outdated Show resolved Hide resolved
src/sfloader/fluid_defsfont.c Outdated Show resolved Hide resolved
- clarify comment in fluid_voice_add_mod_local.
- move static at the beginning of declaration.
- Avoiding compiler complaints "comment within a comment".
- fix typos "unsing" to "using".
@jjceresa
Copy link
Collaborator Author

Unfortunately this function doesn't return an int. But this shouldn't matter too much, because if the user adds an invalid modulator, the current implementation would ignore it anyway on a noteon, wouldn't it?

Yes, actually current implementation fluid_voice_add_mod() has no return code. For now, this PR reproduces same behaviour. However, assuming this PR accepted, maybe future implementation of this function API could return an int (FLUID_OK, FLUID_FAILED) ?. Of course doing this will introduce an API change.

@derselbst
Copy link
Member

However, assuming this PR accepted, maybe future implementation of this function API could return an int

Yes. But since the current implementation ignores it anyway, I currently consider this nice-to-have.

@jjceresa
Copy link
Collaborator Author

Sorry for commit pollution. Commits 5659cc5 and ab9c8a2 are useless. These are due to my local faulty command "git commit --amend". :(

jjceresa added 10 commits November 28, 2018 15:33
- xxx_limit count replaced by unique identity_limit_count variable.
- clarifying comment about this useful limit count variable.
- fix typos in comments.
- Merging reducing defsfont.c code
- this was forgotten in commit fcd6ec6.
- inside fluid_zone_mod_import_sfont.
to fluid_zone_check_mod()
@derselbst
Copy link
Member

I would schedule this for 2.1 if you don't mind? Just let me know when you think it's ready.

@jjceresa
Copy link
Collaborator Author

Just let me know when you think it's ready.

I am fine with this PR. I consider this ready.

I would schedule this for 2.1 if you don't mind?

Ok. For information, i am currently working on adding linked modulators which will be based on the result of this PR. In short, this will involve:

  • linked modulators checking at soundfont loading time.
  • taking these new linked modulators in the voice at noteon time (using same or similar methods that for actual unlinked modulators).
  • taking account of linked modulators inside voice_modulate() and voice_get_lower_boundary_for_attenuation().
    I would prefer waiting for this PR merged before starting a new branch for linked modulators.

@derselbst
Copy link
Member

Ok. I'll try to test and merge this within the next 2 or 3 days.

@derselbst derselbst changed the base branch from master to 2.1-testing December 19, 2018 13:21
@derselbst derselbst added this to the 2.1 milestone Dec 19, 2018
@jjceresa
Copy link
Collaborator Author

I'll try to test and merge this within the next 2 or 3 days.

Please, no need to hurry.

@derselbst
Copy link
Member

Works well for me. Thanks!

@derselbst derselbst merged commit e9b0f0d into 2.1-testing Dec 21, 2018
@derselbst derselbst deleted the modulator-check branch December 21, 2018 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants