File: test_sample_rate_change.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 (66 lines) | stat: -rw-r--r-- 1,961 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

#include "test.h"
#include "fluidsynth.h"
#include "synth/fluid_synth.h"
#include "synth/fluid_voice.h"
#include "rvoice/fluid_rvoice.h"
#include "utils/fluid_sys.h"

static void verify_sample_rate(fluid_synth_t *synth, int expected_srate)
{
    int i;

    TEST_ASSERT(synth->sample_rate == expected_srate);

    for(i = 0; i < synth->polyphony; i++)
    {
        TEST_ASSERT(synth->voice[i]->output_rate == expected_srate);
        TEST_ASSERT(synth->voice[i]->rvoice->dsp.output_rate == expected_srate);
        TEST_ASSERT(synth->voice[i]->overflow_rvoice->dsp.output_rate == expected_srate);
    }

    // TODO check fx, rvoice_mixer et. al.?
}

// this test should make sure that sample rate changed are handled correctly
int main(void)
{
    int polyphony;
    double sample_rate;

    fluid_settings_t *settings = new_fluid_settings();
    fluid_synth_t *synth = new_fluid_synth(settings);

    TEST_ASSERT(settings != NULL);
    TEST_ASSERT(synth != NULL);

    TEST_SUCCESS(fluid_settings_getint(settings, "synth.polyphony", &polyphony));
    TEST_ASSERT(polyphony == synth->polyphony);

    TEST_SUCCESS(fluid_settings_getnum(settings, "synth.sample-rate", &sample_rate));

    verify_sample_rate(synth, sample_rate);


    TEST_SUCCESS(fluid_synth_sfload(synth, TEST_SOUNDFONT, 1));
    // play some notes to start some voices
    TEST_SUCCESS(fluid_synth_noteon(synth, 0, 60, 127));
    TEST_SUCCESS(fluid_synth_noteon(synth, 2, 71, 127));
    TEST_SUCCESS(fluid_synth_noteon(synth, 3, 82, 127));

    verify_sample_rate(synth, sample_rate);

    // set srate to minimum allowed
    sample_rate = 8000;
    fluid_synth_set_sample_rate(synth, sample_rate);

    // manually dispatch rvoice events to get samples rates updated (this simulates the render thread)
    fluid_synth_process_event_queue(synth);

    verify_sample_rate(synth, sample_rate);

    delete_fluid_synth(synth);
    delete_fluid_settings(settings);

    return EXIT_SUCCESS;
}