diff --git a/fluidsynth/src/drivers/fluid_jack.c b/fluidsynth/src/drivers/fluid_jack.c index 15ddb52..78c6441 100644 --- a/fluidsynth/src/drivers/fluid_jack.c +++ b/fluidsynth/src/drivers/fluid_jack.c @@ -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. */ diff --git a/fluidsynth/src/synth/fluid_synth.c b/fluidsynth/src/synth/fluid_synth.c index 5682acb..2aadb67 100644 --- a/fluidsynth/src/synth/fluid_synth.c +++ b/fluidsynth/src/synth/fluid_synth.c @@ -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(); @@ -2730,6 +2732,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! * @return number of blocks rendered. Might (often) return less than requested diff --git a/fluidsynth/src/synth/fluid_synth.h b/fluidsynth/src/synth/fluid_synth.h index fae03f5..d88d71a 100644 --- a/fluidsynth/src/synth/fluid_synth.h +++ b/fluidsynth/src/synth/fluid_synth.h @@ -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 */