move fluid_rvoice_buffers_mix() to rvoice_mixer

This commit is contained in:
derselbst 2018-04-21 10:31:02 +02:00
parent 907ec27a9e
commit f2cf1f82c7
3 changed files with 53 additions and 58 deletions

View file

@ -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
*/

View file

@ -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);

View file

@ -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