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
This commit is contained in:
Stefan Westerfeld 2019-04-14 14:54:43 +02:00 committed by derselbst
parent 68db8f4a80
commit f791162569
1 changed files with 4 additions and 3 deletions

View File

@ -3645,7 +3645,7 @@ fluid_synth_process_LOCAL(fluid_synth_t *synth, int len, int nfx, float *fx[],
int nfxchan, nfxunits, naudchan; int nfxchan, nfxunits, naudchan;
double time = fluid_utime(); double time = fluid_utime();
int i, f, num, count; int i, f, num, count, buffered_blocks;
float cpu_load; float cpu_load;
@ -3669,9 +3669,10 @@ fluid_synth_process_LOCAL(fluid_synth_t *synth, int len, int nfx, float *fx[],
count = 0; count = 0;
num = synth->cur; 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; num = (available > len) ? len : available;
if(nout != 0) if(nout != 0)