From 6c3061cba30b8a79913ee49f67671009358a5b97 Mon Sep 17 00:00:00 2001 From: derselbst Date: Sat, 19 Aug 2017 22:01:47 +0200 Subject: [PATCH] expose a getter for bufcount for rvoice_mixer --- fluidsynth/src/rvoice/fluid_rvoice_mixer.c | 4 ++++ fluidsynth/src/rvoice/fluid_rvoice_mixer.h | 1 + fluidsynth/src/synth/fluid_synth.c | 16 ++++++++-------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/fluidsynth/src/rvoice/fluid_rvoice_mixer.c b/fluidsynth/src/rvoice/fluid_rvoice_mixer.c index b6781644..2436f69f 100644 --- a/fluidsynth/src/rvoice/fluid_rvoice_mixer.c +++ b/fluidsynth/src/rvoice/fluid_rvoice_mixer.c @@ -710,6 +710,10 @@ int fluid_rvoice_mixer_get_fx_bufs(fluid_rvoice_mixer_t* mixer, return mixer->buffers.fx_buf_count; } +int fluid_rvoice_mixer_get_bufcount(fluid_rvoice_mixer_t* mixer) +{ + return mixer->buffers.buf_blocks; +} #ifdef ENABLE_MIXER_THREADS diff --git a/fluidsynth/src/rvoice/fluid_rvoice_mixer.h b/fluidsynth/src/rvoice/fluid_rvoice_mixer.h index 8606b3bf..026673ef 100644 --- a/fluidsynth/src/rvoice/fluid_rvoice_mixer.h +++ b/fluidsynth/src/rvoice/fluid_rvoice_mixer.h @@ -42,6 +42,7 @@ int fluid_rvoice_mixer_get_bufs(fluid_rvoice_mixer_t* mixer, fluid_real_t*** left, fluid_real_t*** right); int fluid_rvoice_mixer_get_fx_bufs(fluid_rvoice_mixer_t* mixer, fluid_real_t*** fx_left, fluid_real_t*** fx_right); +int fluid_rvoice_mixer_get_bufcount(fluid_rvoice_mixer_t* mixer); fluid_rvoice_mixer_t* new_fluid_rvoice_mixer(int buf_count, int fx_buf_count, fluid_real_t sample_rate); diff --git a/fluidsynth/src/synth/fluid_synth.c b/fluidsynth/src/synth/fluid_synth.c index 9421903b..98c9c510 100644 --- a/fluidsynth/src/synth/fluid_synth.c +++ b/fluidsynth/src/synth/fluid_synth.c @@ -2929,7 +2929,7 @@ void fluid_synth_process_event_queue(fluid_synth_t* synth) static int fluid_synth_render_blocks(fluid_synth_t* synth, int blockcount) { - int i; + int i, maxblocks; fluid_profile_ref_var (prof_ref); /* Assign ID of synthesis thread */ @@ -2939,19 +2939,19 @@ fluid_synth_render_blocks(fluid_synth_t* synth, int blockcount) fluid_rvoice_eventhandler_dispatch_all(synth->eventhandler); + /* do not render more blocks than we can store internally */ + maxblocks = fluid_rvoice_mixer_get_bufcount(synth->eventhandler->mixer); + if (blockcount > maxblocks) + blockcount = maxblocks; + for (i=0; i < blockcount; i++) { fluid_sample_timer_process(synth); fluid_synth_add_ticks(synth, FLUID_BUFSIZE); /* If events have been queued waiting for fluid_rvoice_eventhandler_dispatch_all() - * (should only happen with parallel render) OR we are about to process more - * blocks than we can store internally (being at risk having already dispatched many rvoices, - * because we may not be using parallel render), stop processing and go for rendering + * (should only happen with parallel render) stop processing and go for rendering */ - if (fluid_rvoice_eventhandler_dispatch_count(synth->eventhandler) - || i+1 >= FLUID_MIXER_MAX_BUFFERS_DEFAULT-1 /* there actually is one 1 too many here, - but this seems to be the only way it works */ - ) { + if (fluid_rvoice_eventhandler_dispatch_count(synth->eventhandler)) { // Something has happened, we can't process more blockcount = i+1; break;