From f2cf1f82c7ccb32e56a983cc7ddd45c387c5cead Mon Sep 17 00:00:00 2001 From: derselbst Date: Sat, 21 Apr 2018 10:31:02 +0200 Subject: [PATCH] move fluid_rvoice_buffers_mix() to rvoice_mixer --- src/rvoice/fluid_rvoice.c | 54 --------------------------------- src/rvoice/fluid_rvoice.h | 4 --- src/rvoice/fluid_rvoice_mixer.c | 53 ++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 58 deletions(-) diff --git a/src/rvoice/fluid_rvoice.c b/src/rvoice/fluid_rvoice.c index 240591cc..6cddcc77 100644 --- a/src/rvoice/fluid_rvoice.c +++ b/src/rvoice/fluid_rvoice.c @@ -404,60 +404,6 @@ fluid_rvoice_write (fluid_rvoice_t* voice, fluid_real_t *dsp_buf) return count; } - -static FLUID_INLINE fluid_real_t* -get_dest_buf(fluid_rvoice_buffers_t* buffers, int index, - fluid_real_t** dest_bufs, int dest_bufcount) -{ - int j = buffers->bufs[index].mapping; - if (j >= dest_bufcount || j < 0) return NULL; - return dest_bufs[j]; -} - -/** - * Mix data down to buffers - * - * @param buffers Destination buffer(s) - * @param dsp_buf Mono sample source - * @param samplecount Number of samples to process (no FLUID_BUFSIZE restriction) - * @param dest_bufs Array of buffers to mixdown to - * @param dest_bufcount Length of dest_bufs - */ -void -fluid_rvoice_buffers_mix(fluid_rvoice_buffers_t* buffers, - fluid_real_t* dsp_buf, int start, int samplecount, - fluid_real_t** dest_bufs, int dest_bufcount) -{ - int bufcount = buffers->count; - int i, dsp_i; - if (!samplecount || !bufcount || !dest_bufcount) - return; - - for (i=0; i < bufcount; i++) { - fluid_real_t* buf = get_dest_buf(buffers, i, dest_bufs, dest_bufcount); - fluid_real_t* next_buf; - fluid_real_t amp = buffers->bufs[i].amp; - if (buf == NULL || amp == 0.0f) - continue; - - /* Optimization for centered stereo samples - we can save one - multiplication per sample */ - next_buf = (i+1 >= bufcount ? NULL : get_dest_buf(buffers, i+1, dest_bufs, dest_bufcount)); - if (next_buf && buffers->bufs[i+1].amp == amp) { - for (dsp_i = start; dsp_i < samplecount; dsp_i++) { - fluid_real_t samp = amp * dsp_buf[dsp_i]; - buf[dsp_i] += samp; - next_buf[dsp_i] += samp; - } - i++; - } - else { - for (dsp_i = start; dsp_i < samplecount; dsp_i++) - buf[dsp_i] += amp * dsp_buf[dsp_i]; - } - } -} - /** * Initialize buffers up to (and including) bufnum */ diff --git a/src/rvoice/fluid_rvoice.h b/src/rvoice/fluid_rvoice.h index 5f36a12e..f544a418 100644 --- a/src/rvoice/fluid_rvoice.h +++ b/src/rvoice/fluid_rvoice.h @@ -164,10 +164,6 @@ struct _fluid_rvoice_t int fluid_rvoice_write(fluid_rvoice_t* voice, fluid_real_t *dsp_buf); -void fluid_rvoice_buffers_mix(fluid_rvoice_buffers_t* buffers, - fluid_real_t* dsp_buf, int start, int samplecount, - fluid_real_t** dest_bufs, int dest_bufcount); - DECLARE_FLUID_RVOICE_FUNCTION(fluid_rvoice_buffers_set_amp); DECLARE_FLUID_RVOICE_FUNCTION(fluid_rvoice_buffers_set_mapping); diff --git a/src/rvoice/fluid_rvoice_mixer.c b/src/rvoice/fluid_rvoice_mixer.c index 8378a194..fa7bd119 100644 --- a/src/rvoice/fluid_rvoice_mixer.c +++ b/src/rvoice/fluid_rvoice_mixer.c @@ -256,6 +256,59 @@ static FLUID_INLINE void fluid_rvoice_mixer_process_finished_voices(fluid_rvoice } +static FLUID_INLINE fluid_real_t* +get_dest_buf(fluid_rvoice_buffers_t* buffers, int index, + fluid_real_t** dest_bufs, int dest_bufcount) +{ + int j = buffers->bufs[index].mapping; + if (j >= dest_bufcount || j < 0) return NULL; + return dest_bufs[j]; +} + +/** + * Mix data down to buffers + * + * @param buffers Destination buffer(s) + * @param dsp_buf Mono sample source + * @param samplecount Number of samples to process (no FLUID_BUFSIZE restriction) + * @param dest_bufs Array of buffers to mixdown to + * @param dest_bufcount Length of dest_bufs + */ +static void +fluid_rvoice_buffers_mix(fluid_rvoice_buffers_t* buffers, + fluid_real_t* dsp_buf, int start, int samplecount, + fluid_real_t** dest_bufs, int dest_bufcount) +{ + int bufcount = buffers->count; + int i, dsp_i; + if (!samplecount || !bufcount || !dest_bufcount) + return; + + for (i=0; i < bufcount; i++) { + fluid_real_t* buf = get_dest_buf(buffers, i, dest_bufs, dest_bufcount); + fluid_real_t* next_buf; + fluid_real_t amp = buffers->bufs[i].amp; + if (buf == NULL || amp == 0.0f) + continue; + + /* Optimization for centered stereo samples - we can save one + multiplication per sample */ + next_buf = (i+1 >= bufcount ? NULL : get_dest_buf(buffers, i+1, dest_bufs, dest_bufcount)); + if (next_buf && buffers->bufs[i+1].amp == amp) { + for (dsp_i = start; dsp_i < samplecount; dsp_i++) { + fluid_real_t samp = amp * dsp_buf[dsp_i]; + buf[dsp_i] += samp; + next_buf[dsp_i] += samp; + } + i++; + } + else { + for (dsp_i = start; dsp_i < samplecount; dsp_i++) + buf[dsp_i] += amp * dsp_buf[dsp_i]; + } + } +} + /** * Synthesize one voice and add to buffer. * NOTE: If return value is less than blockcount*FLUID_BUFSIZE, that means