remove redundant fluid_rvoice_mixer_t::remove_voice_callback

call rvoice_eventhandler directly to handle finished voices
This commit is contained in:
derselbst 2018-04-22 21:46:54 +02:00
parent 5d28ecc5cc
commit 8aa073b4a4
5 changed files with 12 additions and 34 deletions

View File

@ -97,10 +97,9 @@ static int fluid_rvoice_eventhandler_push_LOCAL(fluid_rvoice_eventhandler_t* han
}
static void
finished_voice_callback(void* userdata, fluid_rvoice_t* rvoice)
void
fluid_rvoice_eventhandler_finished_voice_callback(fluid_rvoice_eventhandler_t* eventhandler, fluid_rvoice_t* rvoice)
{
fluid_rvoice_eventhandler_t* eventhandler = userdata;
fluid_rvoice_t** vptr = fluid_ringbuffer_get_inptr(eventhandler->finished_voices, 0);
if (vptr == NULL)
return; // Buffer full
@ -132,11 +131,10 @@ new_fluid_rvoice_eventhandler(int queuesize,
if (eventhandler->queue == NULL)
goto error_recovery;
eventhandler->mixer = new_fluid_rvoice_mixer(bufs, fx_bufs, sample_rate);
eventhandler->mixer = new_fluid_rvoice_mixer(bufs, fx_bufs, sample_rate, eventhandler);
if (eventhandler->mixer == NULL)
goto error_recovery;
fluid_rvoice_mixer_set_finished_voices_callback(eventhandler->mixer,
finished_voice_callback, eventhandler);
return eventhandler;
error_recovery:

View File

@ -27,7 +27,6 @@
#include "fluid_ringbuffer.h"
typedef struct _fluid_rvoice_event_t fluid_rvoice_event_t;
typedef struct _fluid_rvoice_eventhandler_t fluid_rvoice_eventhandler_t;
struct _fluid_rvoice_event_t {
fluid_rvoice_function_t method;
@ -55,6 +54,8 @@ void delete_fluid_rvoice_eventhandler(fluid_rvoice_eventhandler_t*);
int fluid_rvoice_eventhandler_dispatch_all(fluid_rvoice_eventhandler_t*);
int fluid_rvoice_eventhandler_dispatch_count(fluid_rvoice_eventhandler_t*);
void fluid_rvoice_eventhandler_finished_voice_callback(fluid_rvoice_eventhandler_t* eventhandler,
fluid_rvoice_t* rvoice);
static FLUID_INLINE void
fluid_rvoice_eventhandler_flush(fluid_rvoice_eventhandler_t* handler)

View File

@ -70,8 +70,7 @@ struct _fluid_rvoice_mixer_t {
fluid_mixer_fx_t fx;
fluid_mixer_buffers_t buffers; /**< Used by mixer only: own buffers */
void (*remove_voice_callback)(void*, fluid_rvoice_t*); /**< Used by mixer only: Receive this callback every time a voice is removed */
void* remove_voice_callback_userdata;
fluid_rvoice_eventhandler_t* eventhandler;
fluid_rvoice_t** rvoices; /**< Read-only: Voices array, sorted so that all nulls are last */
int polyphony; /**< Read-only: Length of voices array */
@ -150,20 +149,6 @@ fluid_rvoice_mixer_process_fx(fluid_rvoice_mixer_t* mixer)
#endif
}
/**
* During rendering, rvoices might be finished. Set this callback
* for getting a callback any time the rvoice is finished.
*/
void fluid_rvoice_mixer_set_finished_voices_callback(
fluid_rvoice_mixer_t* mixer,
void (*func)(void*, fluid_rvoice_t*),
void* userdata)
{
mixer->remove_voice_callback_userdata = userdata;
mixer->remove_voice_callback = func;
}
/**
* Glue to get fluid_rvoice_buffers_mix what it wants
* Note: Make sure outbufs has 2 * (buf_count + fx_buf_count) elements before calling
@ -236,9 +221,7 @@ fluid_mixer_buffer_process_finished_voices(fluid_mixer_buffers_t* buffers)
}
buffers->mixer->active_voices = av;
if (buffers->mixer->remove_voice_callback)
buffers->mixer->remove_voice_callback(
buffers->mixer->remove_voice_callback_userdata, v);
fluid_rvoice_eventhandler_finished_voice_callback(buffers->mixer->eventhandler, v);
}
buffers->finished_voice_count = 0;
}
@ -554,7 +537,7 @@ DECLARE_FLUID_RVOICE_FUNCTION(fluid_rvoice_mixer_set_samplerate)
* @param fx_buf_count number of stereo effect buffers
*/
fluid_rvoice_mixer_t*
new_fluid_rvoice_mixer(int buf_count, int fx_buf_count, fluid_real_t sample_rate)
new_fluid_rvoice_mixer(int buf_count, int fx_buf_count, fluid_real_t sample_rate, fluid_rvoice_eventhandler_t* evthandler)
{
fluid_rvoice_mixer_t* mixer = FLUID_NEW(fluid_rvoice_mixer_t);
if (mixer == NULL) {
@ -562,6 +545,7 @@ new_fluid_rvoice_mixer(int buf_count, int fx_buf_count, fluid_real_t sample_rate
return NULL;
}
FLUID_MEMSET(mixer, 0, sizeof(fluid_rvoice_mixer_t));
mixer->eventhandler = evthandler;
mixer->buffers.buf_count = buf_count;
mixer->buffers.fx_buf_count = fx_buf_count;

View File

@ -31,12 +31,6 @@ typedef struct _fluid_rvoice_mixer_t fluid_rvoice_mixer_t;
#define FLUID_MIXER_MAX_BUFFERS_DEFAULT (8192/FLUID_BUFSIZE)
void fluid_rvoice_mixer_set_finished_voices_callback(
fluid_rvoice_mixer_t* mixer,
void (*func)(void*, fluid_rvoice_t*),
void* userdata);
int fluid_rvoice_mixer_render(fluid_rvoice_mixer_t* mixer, int blockcount);
int fluid_rvoice_mixer_get_bufs(fluid_rvoice_mixer_t* mixer,
fluid_real_t*** left, fluid_real_t*** right);
@ -47,7 +41,7 @@ int fluid_rvoice_mixer_get_bufcount(fluid_rvoice_mixer_t* mixer);
int fluid_rvoice_mixer_get_active_voices(fluid_rvoice_mixer_t* mixer);
#endif
fluid_rvoice_mixer_t* new_fluid_rvoice_mixer(int buf_count, int fx_buf_count,
fluid_real_t sample_rate);
fluid_real_t sample_rate, fluid_rvoice_eventhandler_t*);
void delete_fluid_rvoice_mixer(fluid_rvoice_mixer_t*);

View File

@ -204,6 +204,7 @@ typedef struct _fluid_client_t fluid_client_t;
typedef struct _fluid_server_socket_t fluid_server_socket_t;
typedef struct _fluid_sample_timer_t fluid_sample_timer_t;
typedef struct _fluid_zone_range_t fluid_zone_range_t;
typedef struct _fluid_rvoice_eventhandler_t fluid_rvoice_eventhandler_t;
/* Declare rvoice related typedefs here instead of fluid_rvoice.h, as it's needed
* in fluid_lfo.c and fluid_adsr.c as well */