2018-04-06 18:21:14 +00:00
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
#include "fluidsynth.h" // use local fluidsynth header
|
2018-04-11 09:03:12 +00:00
|
|
|
#include "utils/fluidsynth_priv.h"
|
2018-04-06 18:21:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
// this test aims to make sure that sample data used by multiple synths is not freed
|
|
|
|
// once unloaded by its parent synth
|
2018-04-07 16:40:53 +00:00
|
|
|
int main(void)
|
2018-04-06 18:21:14 +00:00
|
|
|
{
|
|
|
|
enum { FRAMES = 1024 };
|
|
|
|
float buf[FRAMES * 2];
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-06 18:21:14 +00:00
|
|
|
fluid_settings_t *settings = new_fluid_settings();
|
|
|
|
fluid_synth_t *synth1 = new_fluid_synth(settings),
|
2018-06-24 11:01:31 +00:00
|
|
|
*synth2 = new_fluid_synth(settings);
|
|
|
|
|
2018-04-11 08:23:17 +00:00
|
|
|
TEST_ASSERT(settings != NULL);
|
|
|
|
TEST_ASSERT(synth1 != NULL);
|
|
|
|
TEST_ASSERT(synth2 != NULL);
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-06 18:21:14 +00:00
|
|
|
// load a sfont to synth1
|
2018-04-11 09:03:12 +00:00
|
|
|
TEST_SUCCESS(fluid_synth_sfload(synth1, TEST_SOUNDFONT, 1));
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-06 18:21:14 +00:00
|
|
|
// load the same font to synth2 and start a note
|
2018-04-11 09:03:12 +00:00
|
|
|
TEST_SUCCESS(fluid_synth_sfload(synth2, TEST_SOUNDFONT, 1));
|
2018-04-06 18:21:14 +00:00
|
|
|
TEST_SUCCESS(fluid_synth_noteon(synth2, 0, 60, 127));
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-06 18:21:14 +00:00
|
|
|
// render some audio
|
|
|
|
TEST_SUCCESS(fluid_synth_write_float(synth2, FRAMES, buf, 0, 2, buf, 1, 2));
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-06 18:21:14 +00:00
|
|
|
// delete the synth that owns the soundfont
|
|
|
|
delete_fluid_synth(synth1);
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-06 18:21:14 +00:00
|
|
|
// render again with the unloaded sfont and hope no segfault happens
|
|
|
|
TEST_SUCCESS(fluid_synth_write_float(synth2, FRAMES, buf, 0, 2, buf, 1, 2));
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-06 18:21:14 +00:00
|
|
|
delete_fluid_synth(synth2);
|
|
|
|
delete_fluid_settings(settings);
|
2018-06-24 11:01:31 +00:00
|
|
|
|
2018-04-06 18:21:14 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|