int ja_initialize(SAMPLE srate, unsigned int input_channels, unsigned int output_channels, unsigned int nframes, const char* client_name) { sigset_t sset; (void) srate; (void) nframes; ja_error_msg[0] = '\0'; client = jack_client_open(client_name, JackNoStartServer, NULL); if (client == NULL) { ja_set_error_msg("jack_client_open failure"); return 1; } ja_frames = jack_get_buffer_size(client); ja_sample_rate = (SAMPLE) jack_get_sample_rate(client); ja_in_channels = input_channels; ja_out_channels = output_channels; ja_buffer_bytes = ja_frames * JA_SAMPLE_SIZE; ja_inputs = (jack_default_audio_sample_t **) malloc(sizeof(jack_default_audio_sample_t *) * input_channels); RETURN_IF_NULLPTR(ja_inputs, "malloc failure"); ja_outputs = (jack_default_audio_sample_t **) malloc(sizeof(jack_default_audio_sample_t *) * output_channels); RETURN_IF_NULLPTR(ja_outputs, "malloc failure"); if (ja_register_ports() != 0) return 1; jack_set_process_thread(client, ja_process_thread, NULL); jack_on_shutdown(client, ja_shutdown, NULL); /* Unblock signals */ sigemptyset(&sset); if (sigprocmask(SIG_SETMASK, &sset, NULL) < 0) { ja_error("Unblock signals error\n"); return 1; } ja_lisp_busy = 1; return 0; }
int main (int argc, char *argv[]) { const char **ports; const char *client_name; const char *server_name = NULL; jack_options_t options = JackNullOption; jack_status_t status; if (argc >= 2) { /* client name specified? */ client_name = argv[1]; if (argc >= 3) { /* server name specified? */ server_name = argv[2]; options |= JackServerName; } } else { /* use basename of argv[0] */ client_name = strrchr(argv[0], '/'); if (client_name == 0) { client_name = argv[0]; } else { client_name++; } } /* open a client connection to the JACK server */ client = jack_client_open (client_name, options, &status, server_name); if (client == NULL) { fprintf (stderr, "jack_client_open() failed, " "status = 0x%2.0x\n", status); if (status & JackServerFailed) { fprintf (stderr, "Unable to connect to JACK server\n"); } exit (1); } if (status & JackServerStarted) { fprintf (stderr, "JACK server started\n"); } if (status & JackNameNotUnique) { client_name = jack_get_client_name(client); fprintf (stderr, "unique name `%s' assigned\n", client_name); } /* tell the JACK server to call `process()' whenever there is work to be done. */ if (jack_set_process_thread(client, jack_thread, client) < 0) exit(1); /* 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 (client, jack_shutdown, 0); /* display the current sample rate. */ printf ("engine sample rate: %" PRIu32 "\n", jack_get_sample_rate (client)); /* create two ports */ input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); output_port = jack_port_register (client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if ((input_port == NULL) || (output_port == NULL)) { fprintf(stderr, "no more JACK ports available\n"); exit (1); } /* Tell the JACK server that we are ready to roll. Our * process() callback will start running now. */ if (jack_activate (client)) { fprintf (stderr, "cannot activate client"); exit (1); } /* Connect the ports. You can't do this before the client is * activated, because we can't make connections to clients * that aren't running. Note the confusing (but necessary) * orientation of the driver backend ports: playback ports are * "input" to the backend, and capture ports are "output" from * it. */ ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput); if (ports == NULL) { fprintf(stderr, "no physical capture ports\n"); exit (1); } if (jack_connect (client, ports[0], jack_port_name (input_port))) { fprintf (stderr, "cannot connect input ports\n"); } jack_free (ports); ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput); if (ports == NULL) { fprintf(stderr, "no physical playback ports\n"); exit (1); } if (jack_connect (client, jack_port_name (output_port), ports[0])) { fprintf (stderr, "cannot connect output ports\n"); } jack_free (ports); /* install a signal handler to properly quits jack client */ signal(SIGQUIT, signal_handler); signal(SIGTERM, signal_handler); signal(SIGHUP, signal_handler); signal(SIGINT, signal_handler); /* keep running until the transport stops */ while (client_state != Exit) { sleep (1); } jack_client_close (client); exit (0); }