mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-02-24 12:51:47 +00:00
Empty event queue from non-realtime context on startup
Some time extensive events were queued to be carried out on the first audio block rendering, when in fact they could be carried out before rendering has even started, from a non-RT context. Reported-by: Krysztof Foltman
This commit is contained in:
parent
26b297f144
commit
f75ed6243b
3 changed files with 34 additions and 18 deletions
|
@ -246,6 +246,8 @@ fluid_jack_client_register_ports (void *driver, int isaudio, jack_client_t *clie
|
|||
char name[64];
|
||||
int multi;
|
||||
int i;
|
||||
int jack_srate;
|
||||
double sample_rate;
|
||||
|
||||
if (!isaudio)
|
||||
{
|
||||
|
@ -323,6 +325,23 @@ fluid_jack_client_register_ports (void *driver, int isaudio, jack_client_t *clie
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* Adjust sample rate to match JACK's */
|
||||
jack_srate = jack_get_sample_rate (client);
|
||||
FLUID_LOG (FLUID_DBG, "Jack engine sample rate: %lu", jack_srate);
|
||||
|
||||
fluid_settings_getnum (settings, "synth.sample-rate", &sample_rate);
|
||||
|
||||
if ((int)sample_rate != jack_srate) {
|
||||
FLUID_LOG(FLUID_INFO, "Jack sample rate mismatch, adjusting."
|
||||
" (synth.sample-rate=%lu, jackd=%lu)", (int)sample_rate, jack_srate);
|
||||
fluid_settings_setnum (settings, "synth.sample-rate", jack_srate);
|
||||
}
|
||||
|
||||
/* Changing sample rate is non RT, so make sure we process it and/or other things now */
|
||||
if (dev->callback == NULL)
|
||||
fluid_synth_process_event_queue(dev->data);
|
||||
|
||||
return FLUID_OK;
|
||||
}
|
||||
|
||||
|
@ -370,8 +389,6 @@ new_fluid_jack_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func
|
|||
jack_client_t *client;
|
||||
const char ** jack_ports; /* for looking up ports */
|
||||
int autoconnect = 0;
|
||||
int jack_srate;
|
||||
double sample_rate;
|
||||
int i;
|
||||
|
||||
dev = FLUID_NEW(fluid_jack_audio_driver_t);
|
||||
|
@ -394,22 +411,6 @@ new_fluid_jack_audio_driver2(fluid_settings_t* settings, fluid_audio_func_t func
|
|||
|
||||
client = dev->client_ref->client;
|
||||
|
||||
/* display the current sample rate. once the client is activated
|
||||
(see below), you should rely on your own sample rate
|
||||
callback (see above) for this value.
|
||||
*/
|
||||
jack_srate = jack_get_sample_rate (client);
|
||||
FLUID_LOG (FLUID_DBG, "Jack engine sample rate: %lu", jack_srate);
|
||||
|
||||
fluid_settings_getnum (settings, "synth.sample-rate", &sample_rate);
|
||||
|
||||
if ((int)sample_rate != jack_srate) {
|
||||
FLUID_LOG(FLUID_INFO, "Jack sample rate mismatch, adjusting."
|
||||
" (synth.sample-rate=%lu, jackd=%lu)", (int)sample_rate, jack_srate);
|
||||
fluid_settings_setnum (settings, "synth.sample-rate", jack_srate);
|
||||
}
|
||||
|
||||
|
||||
/* connect the ports. */
|
||||
|
||||
|
||||
|
|
|
@ -753,6 +753,8 @@ new_fluid_synth(fluid_settings_t *settings)
|
|||
else if (fluid_settings_str_equal (settings, "synth.midi-bank-select", "mma") == 1)
|
||||
synth->bank_select = FLUID_BANK_STYLE_MMA;
|
||||
|
||||
fluid_synth_process_event_queue(synth);
|
||||
|
||||
/* FIXME */
|
||||
synth->start = fluid_curtime();
|
||||
|
||||
|
@ -2729,6 +2731,17 @@ fluid_synth_check_finished_voices(fluid_synth_t* synth)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process all waiting events in the rvoice queue.
|
||||
* Make sure no (other) rendering is running in parallel when
|
||||
* you call this function!
|
||||
*/
|
||||
void fluid_synth_process_event_queue(fluid_synth_t* synth)
|
||||
{
|
||||
fluid_rvoice_eventhandler_dispatch_all(synth->eventhandler);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process blocks (FLUID_BUFSIZE) of audio.
|
||||
* Must be called from renderer thread only!
|
||||
|
|
|
@ -224,6 +224,8 @@ int delete_fluid_sample_timer(fluid_synth_t* synth, fluid_sample_timer_t* timer)
|
|||
void fluid_synth_api_enter(fluid_synth_t* synth);
|
||||
void fluid_synth_api_exit(fluid_synth_t* synth);
|
||||
|
||||
void fluid_synth_process_event_queue(fluid_synth_t* synth);
|
||||
|
||||
/*
|
||||
* misc
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue