remove obsolete fluid_rvoice_eventhandler_t::is_threadsafe

This commit is contained in:
derselbst 2018-04-08 12:07:10 +02:00
parent 5698106dde
commit a7bb2e8a08
4 changed files with 9 additions and 39 deletions

View file

@ -243,7 +243,7 @@ finished_voice_callback(void* userdata, fluid_rvoice_t* rvoice)
} }
fluid_rvoice_eventhandler_t* fluid_rvoice_eventhandler_t*
new_fluid_rvoice_eventhandler(int is_threadsafe, int queuesize, new_fluid_rvoice_eventhandler(int queuesize,
int finished_voices_size, int bufs, int fx_bufs, fluid_real_t sample_rate) int finished_voices_size, int bufs, int fx_bufs, fluid_real_t sample_rate)
{ {
fluid_rvoice_eventhandler_t* eventhandler = FLUID_NEW(fluid_rvoice_eventhandler_t); fluid_rvoice_eventhandler_t* eventhandler = FLUID_NEW(fluid_rvoice_eventhandler_t);
@ -255,12 +255,6 @@ new_fluid_rvoice_eventhandler(int is_threadsafe, int queuesize,
eventhandler->queue = NULL; eventhandler->queue = NULL;
eventhandler->finished_voices = NULL; eventhandler->finished_voices = NULL;
/* HACK 2017-08-27: always enforce threadsafety, i.e. enforce enqueuing events
* otherwise we mess up rendering if more than one block is requested by the user
* because fluid_rvoice_eventhandler_dispatch_count() always stays zero causing
* that too many events are dispatched too early, causing incorrectly timed audio
*/
eventhandler->is_threadsafe = TRUE;
fluid_atomic_int_set(&eventhandler->queue_stored, 0); fluid_atomic_int_set(&eventhandler->queue_stored, 0);
eventhandler->finished_voices = new_fluid_ringbuffer(finished_voices_size, eventhandler->finished_voices = new_fluid_ringbuffer(finished_voices_size,

View file

@ -44,11 +44,10 @@ void fluid_rvoice_event_dispatch(fluid_rvoice_event_t* event);
/* /*
* Bridge between the renderer thread and the midi state thread. * Bridge between the renderer thread and the midi state thread.
* If is_threadsafe is true, that means fluid_rvoice_eventhandler_fetch_all * fluid_rvoice_eventhandler_fetch_all() can be called in parallell
* can be called in parallell with fluid_rvoice_eventhandler_push/flush * with fluid_rvoice_eventhandler_push/flush()
*/ */
struct _fluid_rvoice_eventhandler_t { struct _fluid_rvoice_eventhandler_t {
int is_threadsafe; /* False for optimal performance, true for atomic operations */
fluid_ringbuffer_t* queue; /**< List of fluid_rvoice_event_t */ fluid_ringbuffer_t* queue; /**< List of fluid_rvoice_event_t */
fluid_atomic_int_t queue_stored; /**< Extras pushed but not flushed */ fluid_atomic_int_t queue_stored; /**< Extras pushed but not flushed */
fluid_ringbuffer_t* finished_voices; /**< return queue from handler, list of fluid_rvoice_t* */ fluid_ringbuffer_t* finished_voices; /**< return queue from handler, list of fluid_rvoice_t* */
@ -56,7 +55,7 @@ struct _fluid_rvoice_eventhandler_t {
}; };
fluid_rvoice_eventhandler_t* new_fluid_rvoice_eventhandler( fluid_rvoice_eventhandler_t* new_fluid_rvoice_eventhandler(
int is_threadsafe, int queuesize, int finished_voices_size, int bufs, int queuesize, int finished_voices_size, int bufs,
int fx_bufs, fluid_real_t sample_rate); int fx_bufs, fluid_real_t sample_rate);
void delete_fluid_rvoice_eventhandler(fluid_rvoice_eventhandler_t*); void delete_fluid_rvoice_eventhandler(fluid_rvoice_eventhandler_t*);
@ -105,11 +104,8 @@ static FLUID_INLINE void
fluid_rvoice_eventhandler_add_rvoice(fluid_rvoice_eventhandler_t* handler, fluid_rvoice_eventhandler_add_rvoice(fluid_rvoice_eventhandler_t* handler,
fluid_rvoice_t* rvoice) fluid_rvoice_t* rvoice)
{ {
if (handler->is_threadsafe)
fluid_rvoice_eventhandler_push_ptr(handler, fluid_rvoice_mixer_add_voice, fluid_rvoice_eventhandler_push_ptr(handler, fluid_rvoice_mixer_add_voice,
handler->mixer, rvoice); handler->mixer, rvoice);
else
fluid_rvoice_mixer_add_voice(handler->mixer, rvoice);
} }

View file

@ -695,7 +695,7 @@ new_fluid_synth(fluid_settings_t *settings)
/* Allocate event queue for rvoice mixer */ /* Allocate event queue for rvoice mixer */
fluid_settings_getint(settings, "synth.parallel-render", &i); fluid_settings_getint(settings, "synth.parallel-render", &i);
/* In an overflow situation, a new voice takes about 50 spaces in the queue! */ /* In an overflow situation, a new voice takes about 50 spaces in the queue! */
synth->eventhandler = new_fluid_rvoice_eventhandler(i, synth->polyphony*64, synth->eventhandler = new_fluid_rvoice_eventhandler(synth->polyphony*64,
synth->polyphony, nbuf, synth->effects_channels, synth->sample_rate); synth->polyphony, nbuf, synth->effects_channels, synth->sample_rate);
if (synth->eventhandler == NULL) if (synth->eventhandler == NULL)
@ -2900,9 +2900,6 @@ fluid_synth_nwrite_float(fluid_synth_t* synth, int len,
int bytes; int bytes;
#endif #endif
float cpu_load; float cpu_load;
if (!synth->eventhandler->is_threadsafe)
fluid_synth_api_enter(synth);
/* First, take what's still available in the buffer */ /* First, take what's still available in the buffer */
count = 0; count = 0;
@ -3011,9 +3008,6 @@ fluid_synth_nwrite_float(fluid_synth_t* synth, int len,
time = fluid_utime() - time; time = fluid_utime() - time;
cpu_load = 0.5 * (fluid_atomic_float_get(&synth->cpu_load) + time * synth->sample_rate / len / 10000.0); cpu_load = 0.5 * (fluid_atomic_float_get(&synth->cpu_load) + time * synth->sample_rate / len / 10000.0);
fluid_atomic_float_set (&synth->cpu_load, cpu_load); fluid_atomic_float_set (&synth->cpu_load, cpu_load);
if (!synth->eventhandler->is_threadsafe)
fluid_synth_api_exit(synth);
return FLUID_OK; return FLUID_OK;
} }
@ -3096,10 +3090,7 @@ fluid_synth_write_float(fluid_synth_t* synth, int len,
float cpu_load; float cpu_load;
fluid_profile_ref_var (prof_ref); fluid_profile_ref_var (prof_ref);
if (!synth->eventhandler->is_threadsafe)
fluid_synth_api_enter(synth);
fluid_rvoice_mixer_set_mix_fx(synth->eventhandler->mixer, 1); fluid_rvoice_mixer_set_mix_fx(synth->eventhandler->mixer, 1);
l = synth->cur; l = synth->cur;
fluid_rvoice_mixer_get_bufs(synth->eventhandler->mixer, &left_in, &right_in); fluid_rvoice_mixer_get_bufs(synth->eventhandler->mixer, &left_in, &right_in);
@ -3123,9 +3114,6 @@ fluid_synth_write_float(fluid_synth_t* synth, int len,
time = fluid_utime() - time; time = fluid_utime() - time;
cpu_load = 0.5 * (fluid_atomic_float_get(&synth->cpu_load) + time * synth->sample_rate / len / 10000.0); cpu_load = 0.5 * (fluid_atomic_float_get(&synth->cpu_load) + time * synth->sample_rate / len / 10000.0);
fluid_atomic_float_set (&synth->cpu_load, cpu_load); fluid_atomic_float_set (&synth->cpu_load, cpu_load);
if (!synth->eventhandler->is_threadsafe)
fluid_synth_api_exit(synth);
fluid_profile_write(FLUID_PROF_WRITE, prof_ref, fluid_profile_write(FLUID_PROF_WRITE, prof_ref,
fluid_rvoice_mixer_get_active_voices(synth->eventhandler->mixer), fluid_rvoice_mixer_get_active_voices(synth->eventhandler->mixer),
@ -3203,10 +3191,7 @@ fluid_synth_write_s16(fluid_synth_t* synth, int len,
float cpu_load; float cpu_load;
fluid_profile_ref_var (prof_ref); fluid_profile_ref_var (prof_ref);
if (!synth->eventhandler->is_threadsafe)
fluid_synth_api_enter(synth);
fluid_rvoice_mixer_set_mix_fx(synth->eventhandler->mixer, 1); fluid_rvoice_mixer_set_mix_fx(synth->eventhandler->mixer, 1);
fluid_rvoice_mixer_get_bufs(synth->eventhandler->mixer, &left_in, &right_in); fluid_rvoice_mixer_get_bufs(synth->eventhandler->mixer, &left_in, &right_in);
@ -3246,9 +3231,6 @@ fluid_synth_write_s16(fluid_synth_t* synth, int len,
cpu_load = 0.5 * (fluid_atomic_float_get(&synth->cpu_load) + time * synth->sample_rate / len / 10000.0); cpu_load = 0.5 * (fluid_atomic_float_get(&synth->cpu_load) + time * synth->sample_rate / len / 10000.0);
fluid_atomic_float_set (&synth->cpu_load, cpu_load); fluid_atomic_float_set (&synth->cpu_load, cpu_load);
if (!synth->eventhandler->is_threadsafe)
fluid_synth_api_exit(synth);
fluid_profile_write(FLUID_PROF_WRITE, prof_ref, fluid_profile_write(FLUID_PROF_WRITE, prof_ref,
fluid_rvoice_mixer_get_active_voices(synth->eventhandler->mixer), fluid_rvoice_mixer_get_active_voices(synth->eventhandler->mixer),
len); len);
@ -3634,8 +3616,7 @@ fluid_synth_start_voice(fluid_synth_t* synth, fluid_voice_t* voice)
fluid_synth_kill_by_exclusive_class_LOCAL(synth, voice); fluid_synth_kill_by_exclusive_class_LOCAL(synth, voice);
fluid_voice_start(voice); /* Start the new voice */ fluid_voice_start(voice); /* Start the new voice */
if (synth->eventhandler->is_threadsafe) fluid_voice_lock_rvoice(voice);
fluid_voice_lock_rvoice(voice);
fluid_rvoice_eventhandler_add_rvoice(synth->eventhandler, voice->rvoice); fluid_rvoice_eventhandler_add_rvoice(synth->eventhandler, voice->rvoice);
fluid_synth_api_exit(synth); fluid_synth_api_exit(synth);
} }

View file

@ -169,11 +169,10 @@ float fluid_voice_get_overflow_prio(fluid_voice_t* voice,
/** /**
* Locks the rvoice for rendering, so it can't be modified directly * Locks the rvoice for rendering, so it can't be modified directly
*/ */
static FLUID_INLINE fluid_rvoice_t* static FLUID_INLINE void
fluid_voice_lock_rvoice(fluid_voice_t* voice) fluid_voice_lock_rvoice(fluid_voice_t* voice)
{ {
voice->can_access_rvoice = 0; voice->can_access_rvoice = 0;
return voice->rvoice;
} }
/** /**