From f7911625699d791b404e2c71f184423bb8eb11b1 Mon Sep 17 00:00:00 2001 From: Stefan Westerfeld Date: Sun, 14 Apr 2019 14:54:43 +0200 Subject: [PATCH] Fix buffering bug in fluid_synth_process(). The old buffering code assumes that synth->cur is between 0 and FLUID_BUFSIZE. However since fluid_synth_process() can render more than one buffer at a time this isn't always true, and the new code handles other values properly. Closes #527 --- src/synth/fluid_synth.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/synth/fluid_synth.c b/src/synth/fluid_synth.c index 244a21b4..70bc3cee 100644 --- a/src/synth/fluid_synth.c +++ b/src/synth/fluid_synth.c @@ -3645,7 +3645,7 @@ fluid_synth_process_LOCAL(fluid_synth_t *synth, int len, int nfx, float *fx[], int nfxchan, nfxunits, naudchan; double time = fluid_utime(); - int i, f, num, count; + int i, f, num, count, buffered_blocks; float cpu_load; @@ -3669,9 +3669,10 @@ fluid_synth_process_LOCAL(fluid_synth_t *synth, int len, int nfx, float *fx[], count = 0; num = synth->cur; - if(synth->cur < FLUID_BUFSIZE) + buffered_blocks = (synth->cur + FLUID_BUFSIZE - 1) / FLUID_BUFSIZE; + if(synth->cur < buffered_blocks * FLUID_BUFSIZE) { - int available = FLUID_BUFSIZE - synth->cur; + int available = (buffered_blocks * FLUID_BUFSIZE) - synth->cur; num = (available > len) ? len : available; if(nout != 0)