File: test_sample_cache.c

package info (click to toggle)
fluidsynth 2.4.4%2Bdfsg-1%2Bdeb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,328 kB
  • sloc: ansic: 43,529; cpp: 1,434; xml: 1,020; makefile: 71; sh: 46
file content (42 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

#include "test.h"
#include "fluidsynth.h" // use local fluidsynth header
#include "utils/fluid_sys.h"


// this test aims to make sure that sample data used by multiple synths is not freed
// once unloaded by its parent synth
int main(void)
{
    enum { FRAMES = 1024 };
    float buf[FRAMES * 2];

    fluid_settings_t *settings = new_fluid_settings();
    fluid_synth_t *synth1 = new_fluid_synth(settings),
                   *synth2 = new_fluid_synth(settings);

    TEST_ASSERT(settings != NULL);
    TEST_ASSERT(synth1 != NULL);
    TEST_ASSERT(synth2 != NULL);

    // load a sfont to synth1
    TEST_SUCCESS(fluid_synth_sfload(synth1, TEST_SOUNDFONT, 1));

    // load the same font to synth2 and start a note
    TEST_SUCCESS(fluid_synth_sfload(synth2, TEST_SOUNDFONT, 1));
    TEST_SUCCESS(fluid_synth_noteon(synth2, 0, 60, 127));

    // render some audio
    TEST_SUCCESS(fluid_synth_write_float(synth2, FRAMES, buf, 0, 2, buf, 1, 2));

    // delete the synth that owns the soundfont
    delete_fluid_synth(synth1);

    // 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));

    delete_fluid_synth(synth2);
    delete_fluid_settings(settings);

    return EXIT_SUCCESS;
}