File: test_bug_635.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 (70 lines) | stat: -rw-r--r-- 2,170 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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;
}