From 29d1947ccc0edf46810e63b439e1b4e12bd7d9d0 Mon Sep 17 00:00:00 2001 From: Tom M Date: Fri, 15 Jun 2018 18:46:10 +0200 Subject: [PATCH] implement true zero gain for maximum attenuation (#396) fixes #319 --- src/rvoice/fluid_rvoice_mixer.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/rvoice/fluid_rvoice_mixer.c b/src/rvoice/fluid_rvoice_mixer.c index df5ef5a6..4d515b33 100644 --- a/src/rvoice/fluid_rvoice_mixer.c +++ b/src/rvoice/fluid_rvoice_mixer.c @@ -310,6 +310,21 @@ fluid_rvoice_buffers_mix(fluid_rvoice_buffers_t* buffers, int start_block, int sample_count, fluid_real_t** dest_bufs, int dest_bufcount) { + /* + * SF2.04 9.1.7 Envelope Generators: + * + * "When 96 dB of attenuation is reached in the final gain amplifier, + * an abrupt jump to zero gain (infinite dB of attenuation) occurs." + * + * fluidsynth is a 24 bit synth, it could (should??) use 144 dB of attenuation. + * However the spec makes no distinction between 16 or 24 bit synths, so use + * 96 dB here. + * + * This magic number was obtained by + * powl(10.0L, -FLUID_PEAK_ATTENUATION / 200.0L); + */ + static const fluid_real_t MIN_GAIN = 0.000015848931924611135L; + int bufcount = buffers->count; int i, dsp_i; if (sample_count <= 0 || dest_bufcount <= 0) @@ -322,7 +337,7 @@ fluid_rvoice_buffers_mix(fluid_rvoice_buffers_t* buffers, fluid_real_t *FLUID_RESTRICT buf = get_dest_buf(buffers, i, dest_bufs, dest_bufcount); fluid_real_t amp = buffers->bufs[i].amp; - if (buf == NULL || amp == 0.0f) + if (buf == NULL || amp <= MIN_GAIN) continue; FLUID_ASSERT((uintptr_t)buf % FLUID_DEFAULT_ALIGNMENT == 0);