diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 1c83cf17..244a21b4 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -3632,6 +3632,13 @@ alias with buffers of \c fx. NULL buffers are permitted and will cause to skip m int fluid_synth_process(fluid_synth_t *synth, int len, int nfx, float *fx[], int nout, float *out[]) +{ + return fluid_synth_process_LOCAL(synth, len, nfx, fx, nout, out, fluid_synth_render_blocks); +} + +int +fluid_synth_process_LOCAL(fluid_synth_t *synth, int len, int nfx, float *fx[], + int nout, float *out[], int (*block_render_func)(fluid_synth_t *, int)) { fluid_real_t *left_in, *fx_left_in; fluid_real_t *right_in, *fx_right_in; @@ -3706,7 +3713,7 @@ fluid_synth_process(fluid_synth_t *synth, int len, int nfx, float *fx[], while(count < len) { int blocksleft = (len - count + FLUID_BUFSIZE - 1) / FLUID_BUFSIZE; - int blockcount = fluid_synth_render_blocks(synth, blocksleft); + int blockcount = block_render_func(synth, blocksleft); num = (blockcount * FLUID_BUFSIZE > len - count) ? len - count : blockcount * FLUID_BUFSIZE; diff --git a/src/synth/fluid_synth.h b/src/synth/fluid_synth.h index 156424af..c22e61fb 100644 --- a/src/synth/fluid_synth.h +++ b/src/synth/fluid_synth.h @@ -212,6 +212,9 @@ void fluid_synth_process_event_queue(fluid_synth_t *synth); int fluid_synth_set_gen2(fluid_synth_t *synth, int chan, int param, float value, int absolute, int normalized); +int +fluid_synth_process_LOCAL(fluid_synth_t *synth, int len, int nfx, float *fx[], + int nout, float *out[], int (*block_render_func)(fluid_synth_t *, int)); /* * misc */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8f229c85..0b735452 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,6 +15,7 @@ ADD_FLUID_TEST(test_pointer_alignment) ADD_FLUID_TEST(test_seqbind_unregister) ADD_FLUID_TEST(test_synth_chorus_reverb) ADD_FLUID_TEST(test_snprintf) +ADD_FLUID_TEST(test_synth_process) # if ( LIBSNDFILE_HASVORBIS ) # ADD_FLUID_TEST(test_sf3_sfont_loading) diff --git a/test/test.h b/test/test.h index 74c4bc59..2df1ebe6 100644 --- a/test/test.h +++ b/test/test.h @@ -4,7 +4,7 @@ #include #include -#define TEST_ASSERT(COND) do { if (!(COND)) { fprintf(stderr, __FILE__ ":%d assertion (%s) failed\n", __LINE__, #COND); exit(-1); } } while (0) +#define TEST_ASSERT(COND) do { if (!(COND)) { fprintf(stderr, __FILE__ ":%d assertion (%s) failed\n", __LINE__, #COND); abort(); } } while (0) /* macro to test whether a fluidsynth function succeeded or not */ #define TEST_SUCCESS(FLUID_FUNCT) TEST_ASSERT((FLUID_FUNCT) != FLUID_FAILED) diff --git a/test/test_synth_process.c b/test/test_synth_process.c new file mode 100644 index 00000000..d273bdf2 --- /dev/null +++ b/test/test_synth_process.c @@ -0,0 +1,86 @@ + +#include "test.h" +#include "fluidsynth.h" +#include "fluidsynth_priv.h" +#include "fluid_synth.h" +#include + +static int smpl; +// static const int CHANNELS=16; +static const int SAMPLES=1024; + +int render_one_mock(fluid_synth_t *synth, int blocks) +{ + fluid_real_t *left_in, *fx_left_in; + fluid_real_t *right_in, *fx_right_in; + + int i, j; + + int nfxchan = fluid_synth_count_effects_channels(synth), + nfxunits = fluid_synth_count_effects_groups(synth), + naudchan = fluid_synth_count_audio_channels(synth); + + fluid_rvoice_mixer_get_bufs(synth->eventhandler->mixer, &left_in, &right_in); + fluid_rvoice_mixer_get_fx_bufs(synth->eventhandler->mixer, &fx_left_in, &fx_right_in); + + for(i = 0; i < naudchan; i++) + { + for(j = 0; j < blocks * FLUID_BUFSIZE; j++) + { + int idx = i * FLUID_MIXER_MAX_BUFFERS_DEFAULT * FLUID_BUFSIZE + j; + + right_in[idx] = left_in[idx] = (float)smpl++; + } + } + + return blocks; +} + +int render_and_check(fluid_synth_t* synth, int number_of_samples, int offset) +{ + int i; + float left[SAMPLES], right[SAMPLES]; + float *dry[1 * 2]; + dry[0] = left; + dry[1] = right; + memset(left, 0, sizeof(left)); + memset(right, 0, sizeof(right)); + + TEST_SUCCESS(fluid_synth_process_LOCAL(synth, number_of_samples, 0, NULL, 2, dry, render_one_mock)); + + for(i=0; i