From 4af95e6d1963e319ed6bb1681a332ad654bdd1ef Mon Sep 17 00:00:00 2001 From: Guenter Geiger Date: Sun, 22 Feb 2004 16:00:02 +0000 Subject: merged in version 0.37-1test6 svn path=/trunk/; revision=1329 --- pd/src/s_audio_jack.c | 155 +++++++++++++++++++++++++++++--------------------- 1 file changed, 90 insertions(+), 65 deletions(-) (limited to 'pd/src/s_audio_jack.c') diff --git a/pd/src/s_audio_jack.c b/pd/src/s_audio_jack.c index e9d8fcb5..1e79b43b 100644 --- a/pd/src/s_audio_jack.c +++ b/pd/src/s_audio_jack.c @@ -25,12 +25,14 @@ static int jack_started = 0; static jack_port_t *input_port[NUM_JACK_PORTS]; static jack_port_t *output_port[NUM_JACK_PORTS]; -static jack_client_t *jack_client; +static int outport_count = 0; +static jack_client_t *jack_client = NULL; char *jack_client_names[MAX_CLIENTS]; pthread_mutex_t jack_mutex; pthread_cond_t jack_sem; + static int process (jack_nframes_t nframes, void *arg) { @@ -38,9 +40,9 @@ process (jack_nframes_t nframes, void *arg) float *out; float *in; + if (nframes > JACK_OUT_MAX) jack_out_max = nframes; else jack_out_max = JACK_OUT_MAX; - if (jack_filled >= nframes) { if (jack_filled != nframes) fprintf(stderr,"Partial read"); @@ -67,9 +69,8 @@ process (jack_nframes_t nframes, void *arg) } static int -srate (jack_nframes_t srate, void *arg) +jack_srate (jack_nframes_t srate, void *arg) { - printf ("jack: sample rate %ld/sec\n", srate); sys_dacsr = srate; return 0; } @@ -202,12 +203,12 @@ jack_open_audio(int inchans, int outchans, int rate) { int j; char port_name[80] = ""; - int samplerate; int client_iterator = 0; + int new_jack = 0; + int srate; if ((inchans == 0) && (outchans == 0)) return 0; - post("Testing for Jack"); if (outchans > NUM_JACK_PORTS) { fprintf(stderr,"%d output ports not supported, setting to %d\n",outchans, NUM_JACK_PORTS); outchans = NUM_JACK_PORTS; @@ -219,88 +220,97 @@ jack_open_audio(int inchans, int outchans, int rate) } /* try to become a client of the JACK server (we allow two pd's)*/ - - do { - sprintf(port_name,"pure_data_%d",client_iterator); - client_iterator++; - } - while (((jack_client = jack_client_new (port_name)) == 0) && client_iterator < 2); - - if (!jack_client) { // jack spits out enough messages already, do not warn - return 1; - } - - jack_get_clients(); - - /* tell the JACK server to call `process()' whenever - there is work to be done. - */ - - jack_set_process_callback (jack_client, process, 0); + if (!jack_client) { + do { + sprintf(port_name,"pure_data_%d",client_iterator); + client_iterator++; + } while (((jack_client = jack_client_new (port_name)) == 0) && client_iterator < 2); - jack_set_error_function (jack_error); + + if (!jack_client) { // jack spits out enough messages already, do not warn + return 1; + } + + jack_get_clients(); + /* tell the JACK server to call `process()' whenever + there is work to be done. + */ + + jack_set_process_callback (jack_client, process, 0); + + jack_set_error_function (jack_error); + #ifdef JACK_XRUN - jack_set_xrun_callback (jack_client, jack_xrun, NULL); + jack_set_xrun_callback (jack_client, jack_xrun, NULL); #endif + + /* tell the JACK server to call `srate()' whenever + the sample rate of the system changes. + */ + + jack_set_sample_rate_callback (jack_client, jack_srate, 0); + + + /* tell the JACK server to call `jack_shutdown()' if + it ever shuts down, either entirely, or if it + just decides to stop calling us. + */ + + jack_on_shutdown (jack_client, jack_shutdown, 0); + + for (j=0;j