diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b55f4264..d1325c5e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,6 +11,7 @@ ADD_FLUID_TEST(test_sample_cache) ADD_FLUID_TEST(test_sfont_loading) ADD_FLUID_TEST(test_sample_rate_change) ADD_FLUID_TEST(test_preset_sample_loading) +ADD_FLUID_TEST(test_bug_635) ADD_FLUID_TEST(test_pointer_alignment) ADD_FLUID_TEST(test_seqbind_unregister) ADD_FLUID_TEST(test_synth_chorus_reverb) diff --git a/test/test_bug_635.c b/test/test_bug_635.c new file mode 100644 index 00000000..5afdfc38 --- /dev/null +++ b/test/test_bug_635.c @@ -0,0 +1,70 @@ +#include "test.h" +#include "fluidsynth.h" +#include "sfloader/fluid_sfont.h" +#include "sfloader/fluid_defsfont.h" +#include "utils/fluid_sys.h" +#include "utils/fluid_list.h" + +// load our sf2 and sf3 test soundfonts, with and without dynamic sample loading +int main(void) +{ + int id[2], sfcount, i; + + fluid_synth_t *synth; + fluid_settings_t *settings = new_fluid_settings(); + + fluid_settings_setint(settings, "synth.dynamic-sample-loading", 1); + synth = new_fluid_synth(settings); + id[0] = fluid_synth_sfload(synth, TEST_SOUNDFONT, 0); + sfcount = fluid_synth_sfcount(synth); + + TEST_ASSERT(id[0] != FLUID_FAILED); + TEST_ASSERT(sfcount == 1); + + for(i = 0; i < sfcount; i++) + { + fluid_preset_t *preset; + fluid_list_t *list; + + fluid_sfont_t *sfont = fluid_synth_get_sfont_by_id(synth, id[i]); + fluid_defsfont_t *defsfont = fluid_sfont_get_data(sfont); + + /* Make sure we have the right number of presets */ + fluid_sfont_iteration_start(sfont); + + while((preset = fluid_sfont_iteration_next(sfont)) != NULL) + { + // Try to start a voice with a preset that has not been selected on any channel (bug #635) + + // ignore return value check on fluid_synth_start + fluid_synth_start(synth, 0, preset, 0, 1, 60, 127); + + // fluidsynth < 2.1.3 would crash here + TEST_SUCCESS(fluid_synth_process(synth, 1024, 0, NULL, 0, NULL)); + + fluid_synth_stop(synth, 0); + } + + for(list = defsfont->sample; list; list = fluid_list_next(list)) + { + fluid_sample_t *sample = fluid_list_get(list); + fluid_voice_t *v; + + v = fluid_synth_alloc_voice(synth, sample, 0, 60, 127); + + fluid_synth_start_voice(synth, v); + + // fluidsynth < 2.1.3 would crash here + TEST_SUCCESS(fluid_synth_process(synth, 1024, 0, NULL, 0, NULL)); + + // make sure the voice was NULL, no need for fluid_synth_stop() here + TEST_ASSERT(v == NULL); + } + } + + /* teardown */ + delete_fluid_synth(synth); + delete_fluid_settings(settings); + + return EXIT_SUCCESS; +}