fluidsynth/test/test_sample_rate_change.c

67 lines
1.9 KiB
C
Raw Normal View History

2018-04-11 09:03:24 +00:00
#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"
2018-04-11 09:03:24 +00:00
static void verify_sample_rate(fluid_synth_t *synth, int expected_srate)
2018-04-11 09:03:24 +00:00
{
int i;
2018-04-11 09:03:24 +00:00
TEST_ASSERT(synth->sample_rate == expected_srate);
for(i = 0; i < synth->polyphony; i++)
2018-04-11 09:03:24 +00:00
{
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);
}
2018-04-11 09:03:24 +00:00
// 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;
2018-04-11 09:03:24 +00:00
fluid_settings_t *settings = new_fluid_settings();
fluid_synth_t *synth = new_fluid_synth(settings);
2018-04-11 09:03:24 +00:00
TEST_ASSERT(settings != NULL);
TEST_ASSERT(synth != NULL);
2018-04-11 09:03:24 +00:00
TEST_SUCCESS(fluid_settings_getint(settings, "synth.polyphony", &polyphony));
TEST_ASSERT(polyphony == synth->polyphony);
2018-04-11 09:03:24 +00:00
TEST_SUCCESS(fluid_settings_getnum(settings, "synth.sample-rate", &sample_rate));
2018-04-11 09:03:24 +00:00
verify_sample_rate(synth, sample_rate);
TEST_SUCCESS(fluid_synth_sfload(synth, TEST_SOUNDFONT, 1));
2018-04-11 09:03:24 +00:00
// 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));
2018-04-11 09:03:24 +00:00
verify_sample_rate(synth, sample_rate);
2018-04-11 09:03:24 +00:00
// set srate to minimum allowed
sample_rate = 8000;
fluid_synth_set_sample_rate(synth, sample_rate);
2018-04-11 09:03:24 +00:00
// manually dispatch rvoice events to get samples rates updated (this simulates the render thread)
fluid_synth_process_event_queue(synth);
2018-04-11 09:03:24 +00:00
verify_sample_rate(synth, sample_rate);
2018-04-11 09:03:24 +00:00
delete_fluid_synth(synth);
delete_fluid_settings(settings);
2018-04-11 09:03:24 +00:00
return EXIT_SUCCESS;
}