/* * Ask each module to initialize itself. */ static void initAll () { fprintf (stderr, "init.. "); fprintf (stderr, "Audio : "); fflush (stderr); /* Open the JACK connection and get samplerate. */ if (open_jack()) { perror ("could not connect to JACK."); exit(1); } fprintf (stderr, "Oscillators : "); fflush (stderr); initToneGenerator (inst.synth, inst.midicfg); fprintf (stderr, "Scanner : "); fflush (stderr); initVibrato (inst.synth, inst.midicfg); fprintf (stderr, "Overdrive : "); fflush (stderr); initPreamp (inst.preamp, inst.midicfg); fprintf (stderr, "Reverb : "); fflush (stderr); initReverb (inst.reverb, inst.midicfg, SampleRateD); fprintf (stderr, "Whirl : "); fflush (stderr); initWhirl (inst.whirl, inst.midicfg, SampleRateD); #ifdef HAVE_ZITACONVOLVE fprintf (stderr, "Convolve : "); fflush (stderr); int s_policy= 0; struct sched_param s_param; memset (&s_param, 0, sizeof(struct sched_param)); if (jack_client_thread_id(j_client)) { pthread_getschedparam(jack_client_thread_id(j_client), &s_policy, &s_param); } else { fprintf(stderr, "zita-convolver: not using RT scheduling\n"); } initConvolution(NULL, inst.midicfg, AUDIO_CHANNELS, BUFFER_SIZE_SAMPLES, s_param.sched_priority, s_policy); #endif fprintf (stderr, "RC : "); fflush (stderr); initRunningConfig(inst.state, inst.midicfg); fprintf (stderr, "..done.\n"); }
static void jack_thread_init_callback(void * arg) { boost::atomic_thread_fence(boost::memory_order_acquire); jack_backend * self = static_cast<jack_backend*>(arg); if (jack_client_thread_id(self->client) == pthread_self()) engine_functor::init_thread(); else name_thread("Jack Helper"); }
/***************************************************************************** * * JACK_START() * * Start jack client and attach to playback ports. * *****************************************************************************/ int jack_start(void) { const char **ports; char *p; char *q; int j; /* activate client (callbacks start, so everything else needs to be ready) */ if (jack_activate (client)) { fprintf (stderr, "Unable to activate JACK client.\n"); jack_client_close (client); jack_running = 0; jack_thread_p = 0; client = NULL; return 1; } /* all up and running now */ jack_running = 1; jack_thread_p = jack_client_thread_id (client); /* connect ports. in/out is from server perspective */ /* By default, connect PHASEX output to first two JACK hardware playback ports found */ if (setting_jack_autoconnect) { ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical | JackPortIsInput); if ((ports == NULL) || (ports[0] == NULL)) { fprintf (stderr, "Warning: PHASEX output not connected!\n"); fprintf (stderr, " (No physical JACK playback ports available.)\n"); } else { if (jack_connect (client, jack_port_name (output_port1), ports[0])) { fprintf (stderr, "Unable to connect PHASEX output ports to JACK input.\n"); } if (jack_connect (client, jack_port_name (output_port2), ports[1])) { fprintf (stderr, "Unable to connect PHASEX output ports to JACK input.\n"); } } } /* otherwise, connect to ports that match -o command line flag */ else { ports = jack_get_ports (client, NULL, NULL, JackPortIsInput); if ((ports == NULL) || (ports[0] == NULL)) { fprintf (stderr, "Warning: PHASEX output not connected!\n"); fprintf (stderr, " (No JACK playback ports available.)\n"); } else { p = jack_outputs; if (p != NULL) { if ((q = index (p, ',')) != NULL) { *q = '\0'; q++; } else { q = p; } for (j = 0; ports[j] != NULL; j++) { if (strstr (ports[j], p) != NULL) { if (jack_connect (client, jack_port_name (output_port1), ports[j])) { fprintf (stderr, "Unable to connect PHASEX output ports to JACK input.\n"); } else if (debug) { fprintf (stderr, "JACK connected PHASEX out_1 to %s.\n", ports[j]); } p = "_no_port_"; } if (strstr (ports[j], q) != NULL) { if (jack_connect (client, jack_port_name (output_port2), ports[j])) { fprintf (stderr, "Unable to connect PHASEX output ports to JACK input.\n"); } else if (debug) { fprintf (stderr, "JACK connected PHASEX out_2 to %s.\n", ports[j]); } q = "_no_port_"; } } if (p != q) { q--; *q = ','; } } } } free (ports); /* By default, connect PHASEX input to first two JACK hardware capture ports found */ if (setting_jack_autoconnect) { ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical | JackPortIsOutput); if ((ports == NULL) || (ports[0] == NULL) || (ports[1] == NULL)) { fprintf (stderr, "Warning: PHASEX input not connected!\n"); fprintf (stderr, " (No physical JACK capture ports available.)\n"); } else { if (jack_connect (client, ports[0], jack_port_name (input_port1))) { fprintf (stderr, "Unable to connect PHASEX input ports to JACK output.\n"); } if (jack_connect (client, ports[1], jack_port_name (input_port2))) { fprintf (stderr, "Unable to connect PHASEX input ports to JACK output.\n"); } } } /* otherwise, connect to ports that match -i command line flag */ else { ports = jack_get_ports (client, NULL, NULL, JackPortIsOutput); if ((ports == NULL) || (ports[0] == NULL) || (ports[1] == NULL)) { fprintf (stderr, "Warning: PHASEX input not connected!\n"); fprintf (stderr, " (No JACK capture ports available.)\n"); } else { p = jack_inputs; if (p != NULL) { if ((q = index (p, ',')) != NULL) { *q = '\0'; q++; } else { q = p; } for (j = 0; ports[j] != NULL; j++) { if (strstr (ports[j], p) != NULL) { if (jack_connect (client, ports[j], jack_port_name (input_port1))) { fprintf (stderr, "Unable to connect PHASEX input ports to JACK output.\n"); } else if (debug) { fprintf (stderr, "JACK connected %s to PHASEX in_1.\n", ports[j]); } p = "_no_port_"; } if (strstr (ports[j], q) != NULL) { if (jack_connect (client, ports[j], jack_port_name (input_port2))) { fprintf (stderr, "Unable to connect PHASEX input ports to JACK output.\n"); } else if (debug) { fprintf (stderr, "JACK connected %s to PHASEX in_2.\n", ports[j]); } q = "_no_port_"; } } } } } free (ports); /* report latency and total latency */ if (debug) { fprintf (stderr, "JACK latency: %d\n", jack_port_get_latency (output_port1)); fprintf (stderr, "JACK total latency: %d\n", jack_port_get_total_latency (client, output_port1)); } return 0; }