diff options
Diffstat (limited to 'libs/fluidsynth/src/fluid_synth.c')
-rw-r--r-- | libs/fluidsynth/src/fluid_synth.c | 73 |
1 files changed, 50 insertions, 23 deletions
diff --git a/libs/fluidsynth/src/fluid_synth.c b/libs/fluidsynth/src/fluid_synth.c index 83d427fcac..42064f93d6 100644 --- a/libs/fluidsynth/src/fluid_synth.c +++ b/libs/fluidsynth/src/fluid_synth.c @@ -463,6 +463,11 @@ fluid_synth_init(void) fluid_mod_set_dest(&custom_balance_mod, GEN_CUSTOM_BALANCE); /* Destination: stereo balance */ /* Amount: 96 dB of attenuation (on the opposite channel) */ fluid_mod_set_amount(&custom_balance_mod, FLUID_PEAK_ATTENUATION); /* Amount: 960 */ + +#ifdef LIBINSTPATCH_SUPPORT + /* defer libinstpatch init to fluid_instpatch.c to avoid #include "libinstpatch.h" */ + fluid_instpatch_init(); +#endif } static FLUID_INLINE unsigned int fluid_synth_get_ticks(fluid_synth_t *synth) @@ -494,16 +499,13 @@ struct _fluid_sample_timer_t */ static void fluid_sample_timer_process(fluid_synth_t *synth) { - fluid_sample_timer_t *st, *stnext; + fluid_sample_timer_t *st; long msec; int cont; unsigned int ticks = fluid_synth_get_ticks(synth); - for(st = synth->sample_timers; st; st = stnext) + for(st = synth->sample_timers; st; st = st->next) { - /* st may be freed in the callback below. cache it's successor now to avoid use after free */ - stnext = st->next; - if(st->isfinished) { continue; @@ -529,7 +531,7 @@ fluid_sample_timer_t *new_fluid_sample_timer(fluid_synth_t *synth, fluid_timer_c return NULL; } - result->starttick = fluid_synth_get_ticks(synth); + fluid_sample_timer_reset(synth, result); result->isfinished = 0; result->data = data; result->callback = callback; @@ -559,6 +561,10 @@ void delete_fluid_sample_timer(fluid_synth_t *synth, fluid_sample_timer_t *timer } } +void fluid_sample_timer_reset(fluid_synth_t *synth, fluid_sample_timer_t *timer) +{ + timer->starttick = fluid_synth_get_ticks(synth); +} /*************************************************************** * @@ -816,6 +822,20 @@ new_fluid_synth(fluid_settings_t *settings) #endif /* LADSPA */ } + /* allocate and add the dls sfont loader */ +#ifdef LIBINSTPATCH_SUPPORT + loader = new_fluid_instpatch_loader(settings); + + if(loader == NULL) + { + FLUID_LOG(FLUID_WARN, "Failed to create the instpatch SoundFont loader"); + } + else + { + fluid_synth_add_sfloader(synth, loader); + } +#endif + /* allocate and add the default sfont loader */ loader = new_fluid_defsfloader(settings); @@ -837,6 +857,7 @@ new_fluid_synth(fluid_settings_t *settings) goto error_recovery; } + FLUID_MEMSET(synth->channel, 0, synth->midi_channels * sizeof(*synth->channel)); for(i = 0; i < synth->midi_channels; i++) { synth->channel[i] = new_fluid_channel(synth, i); @@ -856,6 +877,7 @@ new_fluid_synth(fluid_settings_t *settings) goto error_recovery; } + FLUID_MEMSET(synth->voice, 0, synth->nvoice * sizeof(*synth->voice)); for(i = 0; i < synth->nvoice; i++) { synth->voice[i] = new_fluid_voice(synth->eventhandler, synth->sample_rate); @@ -1008,7 +1030,10 @@ delete_fluid_synth(fluid_synth_t *synth) { for(i = 0; i < synth->midi_channels; i++) { - fluid_channel_set_preset(synth->channel[i], NULL); + if(synth->channel[i] != NULL) + { + fluid_channel_set_preset(synth->channel[i], NULL); + } } } @@ -1712,7 +1737,7 @@ fluid_synth_cc_LOCAL(fluid_synth_t *synth, int channum, int num) case RPN_CHANNEL_FINE_TUNE: /* Fine tune is 14 bit over +/-1 semitone (+/- 100 cents, 8192 = center) */ fluid_synth_set_gen_LOCAL(synth, channum, GEN_FINETUNE, - (data - 8192) / 8192.0 * 100.0); + (float)(data - 8192) * (100.0f / 8192.0f)); break; case RPN_CHANNEL_COARSE_TUNE: /* Coarse tune is 7 bit and in semitones (64 is center) */ @@ -5329,8 +5354,8 @@ fluid_synth_set_chorus_full_LOCAL(fluid_synth_t *synth, int set, int nr, double int fluid_synth_get_chorus_nr(fluid_synth_t *synth) { - double result; - fluid_return_val_if_fail(synth != NULL, 0.0); + int result; + fluid_return_val_if_fail(synth != NULL, 0); fluid_synth_api_enter(synth); result = synth->chorus_nr; @@ -5393,8 +5418,8 @@ fluid_synth_get_chorus_depth(fluid_synth_t *synth) int fluid_synth_get_chorus_type(fluid_synth_t *synth) { - double result; - fluid_return_val_if_fail(synth != NULL, 0.0); + int result; + fluid_return_val_if_fail(synth != NULL, 0); fluid_synth_api_enter(synth); result = synth->chorus_type; @@ -5483,7 +5508,7 @@ fluid_synth_set_interp_method(fluid_synth_t *synth, int chan, int interp_method) } FLUID_API_RETURN(FLUID_OK); -}; +} /** * Get the total count of MIDI channels. @@ -6110,18 +6135,18 @@ fluid_synth_get_settings(fluid_synth_t *synth) } /** - * Set a SoundFont generator (effect) value on a MIDI channel in real-time. + * Apply an offset to a SoundFont generator on a MIDI channel. + * + * This function allows to set an offset for the specified destination generator in real-time. + * The offset will be applied immediately to all voices that are currently and subsequently playing + * on the given MIDI channel. This functionality works equivalent to using NRPN MIDI messages to + * manipulate synthesis parameters. See SoundFont spec, paragraph 8.1.3, for details on SoundFont + * generator parameters and valid ranges, as well as paragraph 9.6 for details on NRPN messages. * @param synth FluidSynth instance * @param chan MIDI channel number (0 to MIDI channel count - 1) * @param param SoundFont generator ID (#fluid_gen_type) - * @param value Offset or absolute generator value to assign to the MIDI channel + * @param value Offset value (in native units of the generator) to assign to the MIDI channel * @return #FLUID_OK on success, #FLUID_FAILED otherwise - * - * This function allows for setting all effect parameters in real time on a - * MIDI channel. Setting absolute to non-zero will cause the value to override - * any generator values set in the instruments played on the MIDI channel. - * See SoundFont 2.01 spec, paragraph 8.1.3, page 48 for details on SoundFont - * generator parameters and valid ranges. */ int fluid_synth_set_gen(fluid_synth_t *synth, int chan, int param, float value) { @@ -6154,11 +6179,13 @@ fluid_synth_set_gen_LOCAL(fluid_synth_t *synth, int chan, int param, float value } /** - * Get generator value assigned to a MIDI channel. + * Retrive the generator NRPN offset assigned to a MIDI channel. + * + * The value returned is in native units of the generator. By default, the offset is zero. * @param synth FluidSynth instance * @param chan MIDI channel number (0 to MIDI channel count - 1) * @param param SoundFont generator ID (#fluid_gen_type) - * @return Current generator value assigned to MIDI channel + * @return Current NRPN generator offset value assigned to the MIDI channel */ float fluid_synth_get_gen(fluid_synth_t *synth, int chan, int param) |