From bebb5571aeecd51e5710cb4ee2aecbaf5a75a9de Mon Sep 17 00:00:00 2001 From: jjceresa <32781294+jjceresa@users.noreply.github.com> Date: Fri, 8 Nov 2019 21:26:07 +0100 Subject: [PATCH] Make Fine Tune destination of default modulator Pitch-Wheel-To-pitch (#590) --- include/fluidsynth/gen.h | 21 ++++++++++++++++----- src/synth/fluid_gen.c | 2 +- src/synth/fluid_gen.h | 2 +- src/synth/fluid_synth.c | 7 ++++++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/include/fluidsynth/gen.h b/include/fluidsynth/gen.h index 4b625831..1f46fe2a 100644 --- a/include/fluidsynth/gen.h +++ b/include/fluidsynth/gen.h @@ -95,11 +95,22 @@ enum fluid_gen_type GEN_EXCLUSIVECLASS, /**< Exclusive class number */ GEN_OVERRIDEROOTKEY, /**< Sample root note override */ - /* the initial pitch is not a "standard" generator. It is not - * mentioned in the list of generator in the SF2 specifications. It - * is used, however, as the destination for the default pitch wheel - * modulator. */ - GEN_PITCH, /**< Pitch @note Not a real SoundFont generator */ + /** + * @brief Initial Pitch + * + * @note This is not "standard" SoundFont generator, because it is not + * mentioned in the list of generators in the SF2 specifications. + * It is used by FluidSynth internally to compute the nominal pitch of + * a note on note-on event. By nature it shouldn't be allowed to be modulated, + * however the specification defines a default modulator having "Initial Pitch" + * as destination (cf. SF2.01 page 57 section 8.4.10 MIDI Pitch Wheel to Initial Pitch). + * Thus it is impossible to cancel this default modulator, which would be required + * to let the MIDI Pitch Wheel controller modulate a different generator. + * In order to provide this flexibility, FluidSynth >= 2.1.0 uses a default modulator + * "Pitch Wheel to Fine Tune", rather than Initial Pitch. The same "compromise" can + * be found on the Audigy 2 ZS for instance. + */ + GEN_PITCH, GEN_CUSTOM_BALANCE, /**< Balance @note Not a real SoundFont generator */ /* non-standard generator for an additional custom high- or low-pass filter */ diff --git a/src/synth/fluid_gen.c b/src/synth/fluid_gen.c index cf3cc48b..6472dd32 100644 --- a/src/synth/fluid_gen.c +++ b/src/synth/fluid_gen.c @@ -26,7 +26,7 @@ /* See SFSpec21 $8.1.3 */ static const fluid_gen_info_t fluid_gen_info[] = { - /* number/name init scale min max def */ + /* number/name init nrpn-scale min max def */ { GEN_STARTADDROFS, 1, 1, 0.0f, 1e10f, 0.0f }, { GEN_ENDADDROFS, 1, 1, -1e10f, 0.0f, 0.0f }, { GEN_STARTLOOPADDROFS, 1, 1, -1e10f, 1e10f, 0.0f }, diff --git a/src/synth/fluid_gen.h b/src/synth/fluid_gen.h index 76d168c2..3f8f14b1 100644 --- a/src/synth/fluid_gen.h +++ b/src/synth/fluid_gen.h @@ -27,7 +27,7 @@ typedef struct _fluid_gen_info_t { char num; /* Generator number */ - char init; /* Does the generator need to be initialized (cfr. fluid_voice_init()) */ + char init; /* Does the generator need to be initialized (not used) */ char nrpn_scale; /* The scale to convert from NRPN (cfr. fluid_gen_map_nrpn()) */ float min; /* The minimum value */ float max; /* The maximum value */ diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 54937fb7..e03c6408 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -431,6 +431,10 @@ fluid_synth_init(void) /* SF2.01 page 57 section 8.4.10 MIDI Pitch Wheel to Initial Pitch ... */ + /* Initial Pitch is not a "standard" generator, because it isn't mentioned in the + list of generators in the SF2 specifications. That's why destination Initial Pitch + is replaced here by fine tune generator. + */ fluid_mod_set_source1(&default_pitch_bend_mod, FLUID_MOD_PITCHWHEEL, /* Index=14 */ FLUID_MOD_GC /* CC =0 */ | FLUID_MOD_LINEAR /* type=0 */ @@ -443,7 +447,8 @@ fluid_synth_init(void) | FLUID_MOD_UNIPOLAR /* P=0 */ | FLUID_MOD_POSITIVE /* D=0 */ ); - fluid_mod_set_dest(&default_pitch_bend_mod, GEN_PITCH); /* Destination: Initial pitch */ + /* Also see the comment in gen.h about GEN_PITCH */ + fluid_mod_set_dest(&default_pitch_bend_mod, GEN_FINETUNE); /* Destination: Fine Tune */ fluid_mod_set_amount(&default_pitch_bend_mod, 12700.0); /* Amount: 12700 cents */