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:
David Henningsson 2011-02-07 07:30:50 +00:00
parent 26b297f144
commit f75ed6243b
3 changed files with 34 additions and 18 deletions

View file

@ -246,6 +246,8 @@ fluid_jack_client_register_ports (void *driver, int isaudio, jack_client_t *clie
char name[64]; char name[64];
int multi; int multi;
int i; int i;
int jack_srate;
double sample_rate;
if (!isaudio) 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; 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; jack_client_t *client;
const char ** jack_ports; /* for looking up ports */ const char ** jack_ports; /* for looking up ports */
int autoconnect = 0; int autoconnect = 0;
int jack_srate;
double sample_rate;
int i; int i;
dev = FLUID_NEW(fluid_jack_audio_driver_t); 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; 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. */ /* connect the ports. */

View file

@ -753,6 +753,8 @@ new_fluid_synth(fluid_settings_t *settings)
else if (fluid_settings_str_equal (settings, "synth.midi-bank-select", "mma") == 1) else if (fluid_settings_str_equal (settings, "synth.midi-bank-select", "mma") == 1)
synth->bank_select = FLUID_BANK_STYLE_MMA; synth->bank_select = FLUID_BANK_STYLE_MMA;
fluid_synth_process_event_queue(synth);
/* FIXME */ /* FIXME */
synth->start = fluid_curtime(); 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. * Process blocks (FLUID_BUFSIZE) of audio.
* Must be called from renderer thread only! * Must be called from renderer thread only!

View file

@ -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_enter(fluid_synth_t* synth);
void fluid_synth_api_exit(fluid_synth_t* synth); void fluid_synth_api_exit(fluid_synth_t* synth);
void fluid_synth_process_event_queue(fluid_synth_t* synth);
/* /*
* misc * misc
*/ */