int main(int argc, char **argv) { int fd, black_keys; char *button; unsigned char axes = 2; unsigned char buttons = 2; if (argc < 2) { printf("Usage: %s [-black] <jsX device>\n", argv[0]); return 1; } black_keys = 0; if (argc == 3) if (argv[1][0] == '-') if (argv[1][1] == 'b') { black_keys = 1; if (debug) printf("Using black keys\n"); } if (black_keys) fd = open(argv[2], O_RDONLY); else fd = open(argv[1], O_RDONLY); if (fd < 0) { perror("open(argv[x])"); return 1; } client = jack_client_open("sixad-jack", JackNullOption, 0); if (client == NULL) { perror("jack_client_open()"); return 1; } nframes = jack_get_buffer_size(client); output_port = jack_port_register(client, "midi_out", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0); jack_set_process_callback(client, process_callback, 0); jack_set_xrun_callback(client, xrun_callback, 0); if (jack_activate(client)) { perror("jack_activate()"); return 1; } ioctl(fd, JSIOCGAXES, &axes); ioctl(fd, JSIOCGBUTTONS, &buttons); axis = calloc(axes, sizeof(int)); button = calloc(buttons, sizeof(char)); int h; for (h=0; h<20; h++) { axis_prev_action[h] = 0; axis_prev_velocity[h] = 0; } oct = 0; while (1) { if (read(fd, &js, sizeof(struct js_event)) != sizeof(struct js_event)) { perror("read(stdin)"); jack_client_close(client); return 1; } switch (js.type & ~JS_EVENT_INIT) { case JS_EVENT_BUTTON: button[js.number] = js.value; break; case JS_EVENT_AXIS: axis[js.number] = js.value; break; } do_jack(client, button, black_keys); } jack_client_close(client); return 0; }
static void *ja_init(const char *device, unsigned rate, unsigned latency) { int i; jack_t *jd = (jack_t*)calloc(1, sizeof(jack_t)); if (!jd) return NULL; pthread_cond_init(&jd->cond, NULL); pthread_mutex_init(&jd->cond_lock, NULL); const char **jports = NULL; char *dest_ports[2]; size_t bufsize = 0; int parsed = 0; jd->client = jack_client_open("RetroArch", JackNullOption, NULL); if (jd->client == NULL) goto error; g_settings.audio.out_rate = jack_get_sample_rate(jd->client); jack_set_process_callback(jd->client, process_cb, jd); jack_on_shutdown(jd->client, shutdown_cb, jd); jd->ports[0] = jack_port_register(jd->client, "left", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); jd->ports[1] = jack_port_register(jd->client, "right", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if (jd->ports[0] == NULL || jd->ports[1] == NULL) { RARCH_ERR("Failed to register ports.\n"); goto error; } jports = jack_get_ports(jd->client, NULL, NULL, JackPortIsPhysical | JackPortIsInput); if (jports == NULL) { RARCH_ERR("Failed to get ports.\n"); goto error; } bufsize = find_buffersize(jd, latency); jd->buffer_size = bufsize; RARCH_LOG("JACK: Internal buffer size: %d frames.\n", (int)(bufsize / sizeof(jack_default_audio_sample_t))); for (i = 0; i < 2; i++) { jd->buffer[i] = jack_ringbuffer_create(bufsize); if (jd->buffer[i] == NULL) { RARCH_ERR("Failed to create buffers.\n"); goto error; } } parsed = parse_ports(dest_ports, jports); if (jack_activate(jd->client) < 0) { RARCH_ERR("Failed to activate Jack...\n"); goto error; } for (i = 0; i < 2; i++) { if (jack_connect(jd->client, jack_port_name(jd->ports[i]), dest_ports[i])) { RARCH_ERR("Failed to connect to Jack port.\n"); goto error; } } for (i = 0; i < parsed; i++) free(dest_ports[i]); jack_free(jports); return jd; error: if (jports != NULL) jack_free(jports); return NULL; }
/* Hook in our program to the JACK server for realtime audio I/O */ void init_jack(void) { const char **ports; const char *client_name = "classh"; const char *server_name = NULL; jack_options_t options = JackNullOption; jack_status_t status; /* 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); } jack_set_process_callback (client, process, 0); jack_on_shutdown (client, jack_shutdown, 0); input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); output_port_signal = jack_port_register (client, "output_signal", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if ((input_port == NULL) || (output_port_signal == NULL)) { fprintf(stderr, "no more JACK ports available\n"); exit (1); } if (jack_activate (client)) { fprintf (stderr, "cannot activate client"); exit (1); } 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"); } 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_signal), ports[0])) { fprintf (stderr, "cannot connect output ports\n"); } free (ports); rb = jack_ringbuffer_create (sample_size * 16384); if(rb == NULL) { fprintf(stderr, "Cannot create ringbuffer\n"); exit(1); } jack_default_audio_sample_t nullsample[DELAY]; memset(&nullsample,0,DELAY); jack_ringbuffer_write(rb, (void*)nullsample, (sample_size * DELAY)); }
static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi, PaStream** s, const PaStreamParameters *inputParameters, const PaStreamParameters *outputParameters, double sampleRate, unsigned long framesPerBuffer, PaStreamFlags streamFlags, PaStreamCallback *streamCallback, void *userData ) { PaError result = paNoError; PaJackHostApiRepresentation *jackHostApi = (PaJackHostApiRepresentation*)hostApi; PaJackStream *stream = 0; char port_string[100]; char regex_pattern[100]; const char **jack_ports; int jack_max_buffer_size = jack_get_buffer_size( jackHostApi->jack_client ); int i; int inputChannelCount, outputChannelCount; PaSampleFormat inputSampleFormat, outputSampleFormat; /* the client has no say over the frames per callback */ if( framesPerBuffer == paFramesPerBufferUnspecified ) framesPerBuffer = jack_max_buffer_size; /* Preliminary checks */ if( inputParameters ) { inputChannelCount = inputParameters->channelCount; inputSampleFormat = inputParameters->sampleFormat; /* unless alternate device specification is supported, reject the use of paUseHostApiSpecificDeviceSpecification */ if( inputParameters->device == paUseHostApiSpecificDeviceSpecification ) return paInvalidDevice; /* check that input device can support inputChannelCount */ if( inputChannelCount > hostApi->deviceInfos[ inputParameters->device ]->maxInputChannels ) return paInvalidChannelCount; /* validate inputStreamInfo */ if( inputParameters->hostApiSpecificStreamInfo ) return paIncompatibleHostApiSpecificStreamInfo; /* this implementation doesn't use custom stream info */ } else { inputChannelCount = 0; } if( outputParameters ) { outputChannelCount = outputParameters->channelCount; outputSampleFormat = outputParameters->sampleFormat; /* unless alternate device specification is supported, reject the use of paUseHostApiSpecificDeviceSpecification */ if( outputParameters->device == paUseHostApiSpecificDeviceSpecification ) return paInvalidDevice; /* check that output device can support inputChannelCount */ if( outputChannelCount > hostApi->deviceInfos[ outputParameters->device ]->maxOutputChannels ) return paInvalidChannelCount; /* validate outputStreamInfo */ if( outputParameters->hostApiSpecificStreamInfo ) return paIncompatibleHostApiSpecificStreamInfo; /* this implementation doesn't use custom stream info */ } else { outputChannelCount = 0; } /* ... check that the sample rate exactly matches the ONE acceptable rate */ #define ABS(x) ( (x) > 0 ? (x) : -(x) ) if( ABS(sampleRate - hostApi->deviceInfos[0]->defaultSampleRate) > 1 ) return paInvalidSampleRate; #undef ABS /* Allocate memory for structuures */ #define MALLOC(size) \ (PaUtil_GroupAllocateMemory( stream->stream_memory, (size) )) #define MEMVERIFY(ptr) \ if( (ptr) == NULL ) \ { \ result = paInsufficientMemory; \ goto error; \ } stream = (PaJackStream*)PaUtil_AllocateMemory( sizeof(PaJackStream) ); MEMVERIFY( stream ); stream->stream_memory = PaUtil_CreateAllocationGroup(); stream->jack_client = jackHostApi->jack_client; PaUtil_InitializeCpuLoadMeasurer( &stream->cpuLoadMeasurer, sampleRate ); stream->local_input_ports = (jack_port_t**) MALLOC(sizeof(jack_port_t*) * inputChannelCount ); stream->local_output_ports = (jack_port_t**) MALLOC( sizeof(jack_port_t*) * outputChannelCount ); stream->remote_output_ports = (jack_port_t**) MALLOC( sizeof(jack_port_t*) * inputChannelCount ); stream->remote_input_ports = (jack_port_t**) MALLOC( sizeof(jack_port_t*) * outputChannelCount ); MEMVERIFY( stream->local_input_ports ); MEMVERIFY( stream->local_output_ports ); MEMVERIFY( stream->remote_input_ports ); MEMVERIFY( stream->remote_output_ports ); stream->num_incoming_connections = inputChannelCount; stream->num_outgoing_connections = outputChannelCount; if( streamCallback ) { PaUtil_InitializeStreamRepresentation( &stream->streamRepresentation, &jackHostApi->callbackStreamInterface, streamCallback, userData ); } else { /* we do not support blocking I/O */ return paBadIODeviceCombination; } /* create the JACK ports. We cannot connect them until audio * processing begins */ for( i = 0; i < inputChannelCount; i++ ) { sprintf( port_string, "in_%d", i ); stream->local_input_ports[i] = jack_port_register( jackHostApi->jack_client, port_string, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0 ); } for( i = 0; i < outputChannelCount; i++ ) { sprintf( port_string, "out_%d", i ); stream->local_output_ports[i] = jack_port_register( jackHostApi->jack_client, port_string, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0 ); } /* look up the jack_port_t's for the remote ports. We could do * this at stream start time, but doing it here ensures the * name lookup only happens once. */ if( inputChannelCount > 0 ) { /* ... remote output ports (that we input from) */ sprintf( regex_pattern, "%s:.*", hostApi->deviceInfos[ inputParameters->device ]->name ); jack_ports = jack_get_ports( jackHostApi->jack_client, regex_pattern, NULL, JackPortIsOutput); for( i = 0; i < inputChannelCount && jack_ports[i]; i++ ) { stream->remote_output_ports[i] = jack_port_by_name( jackHostApi->jack_client, jack_ports[i] ); } if( i < inputChannelCount ) { /* we found fewer ports than we expected */ return paInternalError; } free( jack_ports ); // XXX: this doesn't happen if we exit prematurely } if( outputChannelCount > 0 ) { /* ... remote input ports (that we output to) */ sprintf( regex_pattern, "%s:.*", hostApi->deviceInfos[ outputParameters->device ]->name ); jack_ports = jack_get_ports( jackHostApi->jack_client, regex_pattern, NULL, JackPortIsInput); for( i = 0; i < outputChannelCount && jack_ports[i]; i++ ) { stream->remote_input_ports[i] = jack_port_by_name( jackHostApi->jack_client, jack_ports[i] ); } if( i < outputChannelCount ) { /* we found fewer ports than we expected */ return paInternalError; } free( jack_ports ); // XXX: this doesn't happen if we exit prematurely } result = PaUtil_InitializeBufferProcessor( &stream->bufferProcessor, inputChannelCount, inputSampleFormat, paFloat32, /* hostInputSampleFormat */ outputChannelCount, outputSampleFormat, paFloat32, /* hostOutputSampleFormat */ sampleRate, streamFlags, framesPerBuffer, jack_max_buffer_size, paUtilFixedHostBufferSize, streamCallback, userData ); if( result != paNoError ) goto error; stream->is_running = FALSE; stream->t0 = -1;/* set the first time through the callback*/ stream->total_frames_sent = 0; jack_set_process_callback( jackHostApi->jack_client, JackCallback, stream ); *s = (PaStream*)stream; return result; error: if( stream ) { if( stream->stream_memory ) { PaUtil_FreeAllAllocations( stream->stream_memory ); PaUtil_DestroyAllocationGroup( stream->stream_memory ); } PaUtil_FreeMemory( stream ); } return result; #undef MALLOC #undef MEMVERIFY }
int main (int argc, char *argv[]) { jack_client_t *client; const char **ports; if (argc < 2) { fprintf (stderr, "usage: jack_simple_client <name>n"); return 1; } /* try to become a client of the JACK server */ if ((client = jack_client_new (argv[1])) == 0) { fprintf (stderr, "jack server not running?n"); return 1; } /* tell the JACK server to call `process()' whenever there is work to be done. */ jack_set_process_callback (client, process, 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 (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); /* tell the JACK server that we are ready to roll */ if (jack_activate (client)) { fprintf (stderr, "cannot activate client"); return 1; } /* connect the ports. Note: you can't do this before the client is activated, because we can't allow connections to be made to clients that aren't running. */ if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput)) == NULL) { fprintf(stderr, "Cannot find any physical capture portsn"); exit(1); } if (jack_connect (client, ports[0], jack_port_name (input_port))) { fprintf (stderr, "cannot connect input portsn"); } free (ports); if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) { fprintf(stderr, "Cannot find any physical playback portsn"); exit(1); } if (jack_connect (client, jack_port_name (output_port), ports[0])) { fprintf (stderr, "cannot connect output portsn"); } free (ports); /* Since this is just a toy, run for a few seconds, then finish */ while(1) { sleep (10); } jack_client_close (client); exit (0); }
static void initialise_jack_ports( mlt_properties properties ) { int i; char mlt_name[20], rack_name[30]; jack_port_t **port = NULL; jack_client_t *jack_client = mlt_properties_get_data( properties, "jack_client", NULL ); jack_nframes_t jack_buffer_size = jack_get_buffer_size( jack_client ); // Propogate these for the Jack processing callback int channels = mlt_properties_get_int( properties, "channels" ); // Start JackRack if ( mlt_properties_get( properties, "src" ) ) { snprintf( rack_name, sizeof( rack_name ), "jackrack%d", getpid() ); jack_rack_t *jackrack = jack_rack_new( rack_name, mlt_properties_get_int( properties, "channels" ) ); jack_rack_open_file( jackrack, mlt_properties_get( properties, "src" ) ); mlt_properties_set_data( properties, "jackrack", jackrack, 0, (mlt_destructor) jack_rack_destroy, NULL ); mlt_properties_set( properties, "_rack_client_name", rack_name ); } else { // We have to set this to something to prevent re-initialization. mlt_properties_set_data( properties, "jackrack", jack_client, 0, NULL, NULL ); } // Allocate buffers and ports jack_ringbuffer_t **output_buffers = mlt_pool_alloc( sizeof( jack_ringbuffer_t *) * channels ); jack_ringbuffer_t **input_buffers = mlt_pool_alloc( sizeof( jack_ringbuffer_t *) * channels ); jack_port_t **jack_output_ports = mlt_pool_alloc( sizeof(jack_port_t *) * channels ); jack_port_t **jack_input_ports = mlt_pool_alloc( sizeof(jack_port_t *) * channels ); float **jack_output_buffers = mlt_pool_alloc( sizeof(float *) * jack_buffer_size ); float **jack_input_buffers = mlt_pool_alloc( sizeof(float *) * jack_buffer_size ); // Set properties - released inside filter_close mlt_properties_set_data( properties, "output_buffers", output_buffers, sizeof( jack_ringbuffer_t *) * channels, mlt_pool_release, NULL ); mlt_properties_set_data( properties, "input_buffers", input_buffers, sizeof( jack_ringbuffer_t *) * channels, mlt_pool_release, NULL ); mlt_properties_set_data( properties, "jack_output_ports", jack_output_ports, sizeof( jack_port_t *) * channels, mlt_pool_release, NULL ); mlt_properties_set_data( properties, "jack_input_ports", jack_input_ports, sizeof( jack_port_t *) * channels, mlt_pool_release, NULL ); mlt_properties_set_data( properties, "jack_output_buffers", jack_output_buffers, sizeof( float *) * channels, mlt_pool_release, NULL ); mlt_properties_set_data( properties, "jack_input_buffers", jack_input_buffers, sizeof( float *) * channels, mlt_pool_release, NULL ); // Register Jack ports for ( i = 0; i < channels; i++ ) { int in; output_buffers[i] = jack_ringbuffer_create( BUFFER_LEN * sizeof(float) ); input_buffers[i] = jack_ringbuffer_create( BUFFER_LEN * sizeof(float) ); snprintf( mlt_name, sizeof( mlt_name ), "obuf%d", i ); mlt_properties_set_data( properties, mlt_name, output_buffers[i], BUFFER_LEN * sizeof(float), (mlt_destructor) jack_ringbuffer_free, NULL ); snprintf( mlt_name, sizeof( mlt_name ), "ibuf%d", i ); mlt_properties_set_data( properties, mlt_name, input_buffers[i], BUFFER_LEN * sizeof(float), (mlt_destructor) jack_ringbuffer_free, NULL ); for ( in = 0; in < 2; in++ ) { snprintf( mlt_name, sizeof( mlt_name ), "%s_%d", in ? "in" : "out", i + 1); port = ( in ? &jack_input_ports[i] : &jack_output_ports[i] ); *port = jack_port_register( jack_client, mlt_name, JACK_DEFAULT_AUDIO_TYPE, ( in ? JackPortIsInput : JackPortIsOutput ) | JackPortIsTerminal, 0 ); } } // Start Jack processing pthread_mutex_lock( &g_activate_mutex ); jack_activate( jack_client ); pthread_mutex_unlock( &g_activate_mutex ); // Establish connections for ( i = 0; i < channels; i++ ) { int in; for ( in = 0; in < 2; in++ ) { port = ( in ? &jack_input_ports[i] : &jack_output_ports[i] ); snprintf( mlt_name, sizeof( mlt_name ), "%s", jack_port_name( *port ) ); snprintf( rack_name, sizeof( rack_name ), "%s_%d", in ? "in" : "out", i + 1 ); if ( mlt_properties_get( properties, "_rack_client_name" ) ) snprintf( rack_name, sizeof( rack_name ), "%s:%s_%d", mlt_properties_get( properties, "_rack_client_name" ), in ? "out" : "in", i + 1); else if ( mlt_properties_get( properties, rack_name ) ) snprintf( rack_name, sizeof( rack_name ), "%s", mlt_properties_get( properties, rack_name ) ); else snprintf( rack_name, sizeof( rack_name ), "%s:%s_%d", mlt_properties_get( properties, "_client_name" ), in ? "out" : "in", i + 1); if ( in ) { mlt_log_verbose( NULL, "JACK connect %s to %s\n", rack_name, mlt_name ); jack_connect( jack_client, rack_name, mlt_name ); } else { mlt_log_verbose( NULL, "JACK connect %s to %s\n", mlt_name, rack_name ); jack_connect( jack_client, mlt_name, rack_name ); } } } }
static int init(int rate, int channels, int format, int flags) { const char **matching_ports = NULL; char *port_name = NULL; char *client_name = NULL; int autostart = 0; const opt_t subopts[] = { {"port", OPT_ARG_MSTRZ, &port_name, NULL}, {"name", OPT_ARG_MSTRZ, &client_name, NULL}, {"estimate", OPT_ARG_BOOL, &estimate, NULL}, {"autostart", OPT_ARG_BOOL, &autostart, NULL}, {NULL} }; jack_options_t open_options = JackUseExactName; int port_flags = JackPortIsInput; int i; estimate = 1; if (subopt_parse(ao_subdevice, subopts) != 0) { print_help(); return 0; } if (channels > MAX_CHANS) { mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] Invalid number of channels: %i\n", channels); goto err_out; } if (!client_name) { client_name = malloc(40); sprintf(client_name, "MPlayer [%d]", getpid()); } if (!autostart) open_options |= JackNoStartServer; client = jack_client_open(client_name, open_options, NULL); if (!client) { mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] cannot open server\n"); goto err_out; } buffer = av_fifo_alloc(BUFFSIZE); jack_set_process_callback(client, outputaudio, 0); // list matching ports if (!port_name) port_flags |= JackPortIsPhysical; matching_ports = jack_get_ports(client, port_name, NULL, port_flags); if (!matching_ports || !matching_ports[0]) { mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] no physical ports available\n"); goto err_out; } i = 1; while (matching_ports[i]) i++; if (channels > i) channels = i; num_ports = channels; // create out output ports for (i = 0; i < num_ports; i++) { char pname[30]; snprintf(pname, 30, "out_%d", i); ports[i] = jack_port_register(client, pname, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if (!ports[i]) { mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] not enough ports available\n"); goto err_out; } } if (jack_activate(client)) { mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] activate failed\n"); goto err_out; } for (i = 0; i < num_ports; i++) { if (jack_connect(client, jack_port_name(ports[i]), matching_ports[i])) { mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] connecting failed\n"); goto err_out; } } rate = jack_get_sample_rate(client); jack_latency = (float)(jack_port_get_total_latency(client, ports[0]) + jack_get_buffer_size(client)) / (float)rate; callback_interval = 0; ao_data.channels = channels; ao_data.samplerate = rate; ao_data.format = AF_FORMAT_FLOAT_NE; ao_data.bps = channels * rate * sizeof(float); ao_data.buffersize = CHUNK_SIZE * NUM_CHUNKS; ao_data.outburst = CHUNK_SIZE; free(matching_ports); free(port_name); free(client_name); return 1; err_out: free(matching_ports); free(port_name); free(client_name); if (client) jack_client_close(client); av_fifo_free(buffer); buffer = NULL; return 0; }
int main (int argc, char *argv[]) { jack_client_t *client = jack_client_open (CLIENT_NAME, JackNullOption, NULL); state data; char *end = argv[1]; if (argc > 1) data.frequency = strtod (argv[1], &end); if (end == argv[1]) data.frequency = MIDDLE_C; data.sample_rate = jack_get_sample_rate (client); if (data.sample_rate < 1) data.sample_rate = SAMPLE_RATE; data.input_port = jack_port_register (client, INPUT_NAME, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); data.output_port = jack_port_register (client, OUTPUT_NAME, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); data.sine_port = jack_port_register (client, SINE_NAME, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); data.square_port = jack_port_register (client, SQUARE_NAME, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); data.block_size = jack_get_buffer_size (client); data.block_count = BUFFER_SIZE / data.block_size; int buffer_size = data.block_count * data.block_size; data.sample_data = calloc (2 * buffer_size - data.block_size, sizeof (jack_sample_t)); data.window_data = malloc (buffer_size * sizeof (double)); data.input_data = fftw_malloc (buffer_size * sizeof (double)); data.output_data = fftw_malloc ((buffer_size / 2 + 1) * sizeof (fftw_complex)); data.fft_routine = fftw_plan_dft_r2c_1d (buffer_size, data.input_data, data.output_data, FFTW_MEASURE | FFTW_DESTROY_INPUT); data.indexed_train = calloc (buffer_size / 2 + 1, sizeof (pulse)); data.sorted_train = malloc ((buffer_size / 2 + 1) * sizeof (pulse)); data.current_block = 0; int sample; for (sample = 0; sample < buffer_size; sample++) data.window_data[sample] = window (buffer_size, sample); for (sample = 0; sample < buffer_size / 2 + 1; sample++) data.indexed_train[sample].index = sample; jack_set_process_callback (client, process, &data); jack_activate (client); while (pause ()); return 0; }
void *JackOpenPlay(struct FFTSound *fftsound){ int lokke; static char *outnames[MAX_SAMPS_PER_FRAME]={"output1","output2","output3","output4","output5","output6","output7","output8"}; struct Jackplay *jackplay; jackplay=calloc(1,sizeof(struct Jackplay)); jackplay->fftsound=fftsound; jackplay->buffersize=BUFFERSIZE; // fprintf(stderr,"Open jack play.\n"); #if 1 if(globalclient==NULL){ // Hack to get around a bug in jack. if (CONFIG_getBool("jack_client_name_is_ceres_plus_pid")==true){ sprintf(clientname,"ceres-%d",getpid()); }else{ sprintf(clientname,"ceres"); } if ((jackplay->client=globalclient = jack_client_new (clientname)) == 0) { fprintf(stderr,"Failed. Jack server not running?\n"); goto failed; } atexit(jackCleanUp); } jackplay->client=globalclient; #else if ((jackplay->client=globalclient=jack_client_new ("ceres")) == 0) { fprintf(stderr,"Failed. Jack server not running?\n"); goto failed; } #endif if(fftsound->R!=jack_get_sample_rate(jackplay->client)){ fprintf( stderr, "Warning, sample rate is %d, while jacks sample rate is %lu.\n", fftsound->R, jack_get_sample_rate(jackplay->client) ); } jack_set_process_callback (jackplay->client, jackprocess, jackplay); for(lokke=0;lokke<fftsound->samps_per_frame;lokke++){ jackplay->jpc[lokke].output_port = jack_port_register( jackplay->client, outnames[lokke], JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0 ); } if (jack_activate (jackplay->client)) { fprintf (stderr, "Error. Cannot activate jack client.\n"); goto failed_activate; } for(lokke=0;lokke<fftsound->samps_per_frame;lokke++){ if ( jack_connect( jackplay->client, jack_port_name(jackplay->jpc[lokke].output_port), outportnames[lokke] ) ) { fprintf (stderr, "Error. Cannot connect jack output port %d: \"%s\".\n",lokke,outportnames[lokke]); goto failed_connect; } } return jackplay; failed_connect: for(lokke=0;lokke<jackplay->fftsound->samps_per_frame;lokke++){ jack_disconnect( jackplay->client, jack_port_name(jackplay->jpc[lokke].output_port), outportnames[lokke] ); jack_port_unregister( jackplay->client,jackplay->jpc[lokke].output_port ); } failed_activate: jack_deactivate(jackplay->client); // jack_client_close (jackplay->client); failed: free(jackplay); return NULL; }
bool AudioJack::initJackClient() { QString clientName = ConfigManager::inst()->value( "audiojack", "clientname" ); if( clientName.isEmpty() ) { clientName = "lmms"; } const char * serverName = NULL; jack_status_t status; m_client = jack_client_open( clientName.toLatin1().constData(), JackNullOption, &status, serverName ); if( m_client == NULL ) { printf( "jack_client_open() failed, status 0x%2.0x\n", status ); if( status & JackServerFailed ) { printf( "Could not connect to JACK server.\n" ); } return false; } if( status & JackNameNotUnique ) { printf( "there's already a client with name '%s', so unique " "name '%s' was assigned\n", clientName. toLatin1().constData(), jack_get_client_name( m_client ) ); } // set process-callback jack_set_process_callback( m_client, staticProcessCallback, this ); // set shutdown-callback jack_on_shutdown( m_client, shutdownCallback, this ); if( jack_get_sample_rate( m_client ) != sampleRate() ) { setSampleRate( jack_get_sample_rate( m_client ) ); } for( ch_cnt_t ch = 0; ch < channels(); ++ch ) { QString name = QString( "master out " ) + ( ( ch % 2 ) ? "R" : "L" ) + QString::number( ch / 2 + 1 ); m_outputPorts.push_back( jack_port_register( m_client, name.toLatin1().constData(), JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0 ) ); if( m_outputPorts.back() == NULL ) { printf( "no more JACK-ports available!\n" ); return false; } } return true; }
int Server_jack_init(Server *self) { char client_name[32]; char name[16]; const char *server_name = "server"; jack_options_t options = JackNullOption; jack_status_t status; int sampleRate = 0; int bufferSize = 0; int nchnls = 0; int total_nchnls = 0; int index = 0; int ret = 0; assert(self->audio_be_data == NULL); PyoJackBackendData *be_data = (PyoJackBackendData *) malloc(sizeof(PyoJackBackendData *)); self->audio_be_data = (void *) be_data; be_data->jack_in_ports = (jack_port_t **) calloc(self->ichnls + self->input_offset, sizeof(jack_port_t *)); be_data->jack_out_ports = (jack_port_t **) calloc(self->nchnls + self->output_offset, sizeof(jack_port_t *)); strncpy(client_name,self->serverName, 32); be_data->jack_client = jack_client_open(client_name, options, &status, server_name); if (be_data->jack_client == NULL) { Server_error(self, "Jack error: Unable to create JACK client\n"); if (status & JackServerFailed) { Server_debug(self, "Jack error: jack_client_open() failed, " "status = 0x%2.0x\n", status); } return -1; } if (status & JackServerStarted) { Server_warning(self, "JACK server started.\n"); } if (strcmp(self->serverName, jack_get_client_name(be_data->jack_client)) ) { strcpy(self->serverName, jack_get_client_name(be_data->jack_client)); Server_warning(self, "Jack name `%s' assigned\n", self->serverName); } sampleRate = jack_get_sample_rate (be_data->jack_client); if (sampleRate != self->samplingRate) { self->samplingRate = (double)sampleRate; Server_warning(self, "Sample rate set to Jack engine sample rate: %" PRIu32 "\n", sampleRate); } else { Server_debug(self, "Jack engine sample rate: %" PRIu32 "\n", sampleRate); } if (sampleRate <= 0) { Server_error(self, "Invalid Jack engine sample rate."); jack_client_close(be_data->jack_client); return -1; } bufferSize = jack_get_buffer_size(be_data->jack_client); if (bufferSize != self->bufferSize) { self->bufferSize = bufferSize; Server_warning(self, "Buffer size set to Jack engine buffer size: %" PRIu32 "\n", bufferSize); } else { Server_debug(self, "Jack engine buffer size: %" PRIu32 "\n", bufferSize); } nchnls = total_nchnls = self->ichnls + self->input_offset; while (nchnls-- > 0) { index = total_nchnls - nchnls - 1; ret = sprintf(name, "input_%i", index + 1); if (ret > 0) { be_data->jack_in_ports[index] = jack_port_register(be_data->jack_client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); } if ((be_data->jack_in_ports[index] == NULL)) { Server_error(self, "Jack: no more JACK input ports available\n"); return -1; } } nchnls = total_nchnls = self->nchnls + self->output_offset; while (nchnls-- > 0) { index = total_nchnls - nchnls - 1; ret = sprintf(name, "output_%i", index + 1); if (ret > 0) { be_data->jack_out_ports[index] = jack_port_register(be_data->jack_client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); } if ((be_data->jack_out_ports[index] == NULL)) { Server_error(self, "Jack: no more JACK output ports available\n"); return -1; } } jack_set_error_function(jack_error_cb); jack_set_sample_rate_callback(be_data->jack_client, jack_srate_cb, (void *) self); jack_on_shutdown(be_data->jack_client, jack_shutdown_cb, (void *) self); jack_set_buffer_size_callback(be_data->jack_client, jack_bufsize_cb, (void *) self); return 0; }
int main(int argc, char **argv) { const char **ports; const char *client_name = "drumbox"; const char *server_name = NULL; jack_options_t options = JackNullOption; jack_status_t status; /* Initialise FFTW */ fft_in = fftwf_malloc(FFT_SIZE * sizeof *fft_in); fft_out = fftwf_malloc(FFT_SIZE * sizeof *fft_out); fft_plan = fftwf_plan_dft_1d(FFT_SIZE, fft_in, fft_out, FFTW_FORWARD, FFTW_MEASURE); if (argc < 2) { note = 48; } else { note = atoi(argv[1]); } /* open a client connection to the JACK server */ client = jack_client_open(client_name, options, &status, server_name); if (client == NULL) { DEBUG("jack_client_open() failed, " "status = 0x%2.0x\n", status); if (status & JackServerFailed) { DEBUG("Unable to connect to JACK server\n"); } exit(1); } if (status & JackServerStarted) { DEBUG("JACK server started\n"); } if (status & JackNameNotUnique) { client_name = jack_get_client_name(client); DEBUG("unique name `%s' assigned\n", client_name); } /* tell the JACK server to call `process()' whenever there is work to be done. */ jack_set_process_callback(client, process, 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(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_MIDI_TYPE, JackPortIsOutput, 0); if ((input_port == NULL) || (output_port == NULL)) { DEBUG("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)) { DEBUG("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) { DEBUG("no physical capture ports\n"); exit(1); } if (jack_connect(client, ports[0], jack_port_name(input_port))) { DEBUG("cannot connect input ports\n"); } free(ports); /* keep running until stopped by the user */ sleep(-1); /* this is never reached but if the program had some other way to exit besides being killed, they would be important to call. */ jack_client_close(client); exit(0); }
static void * audio_cap_jack_init(const char *cfg) { struct state_jack_capture *s; jack_status_t status; const char **ports; int i; if(!cfg || strcmp(cfg, "help") == 0) { audio_cap_jack_help("jack"); return &audio_init_state_ok; } s = (struct state_jack_capture *) calloc(1, sizeof(struct state_jack_capture)); if(!s) { fprintf(stderr, "[JACK capture] Unable to allocate memory.\n"); goto error; } s->client = jack_client_open(PACKAGE_STRING, JackNullOption, &status); if(status & JackFailure) { fprintf(stderr, "[JACK capture] Opening JACK client failed.\n"); goto error; } ports = jack_get_ports(s->client, cfg, NULL, JackPortIsOutput); if(ports == NULL) { fprintf(stderr, "[JACK capture] Unable to output ports matching %s.\n", cfg); goto release_client; } i = 0; while(ports[i]) i++; if(i < (int) audio_capture_channels) { fprintf(stderr, "[JACK capture] Requested channel count %d not found (matching pattern %s).\n", audio_capture_channels, cfg); goto release_client; } s->frame.ch_count = audio_capture_channels; s->frame.bps = 4; if (audio_capture_sample_rate) { log_msg(LOG_LEVEL_WARNING, "[JACK capture] Ignoring user specified sample rate!\n"); } s->frame.sample_rate = jack_get_sample_rate (s->client); s->frame.max_size = s->frame.ch_count * s->frame.bps * s->frame.sample_rate; s->frame.data = malloc(s->frame.max_size); s->tmp = malloc(s->frame.max_size); s->data = ring_buffer_init(s->frame.max_size); if(jack_set_sample_rate_callback(s->client, jack_samplerate_changed_callback, (void *) s)) { fprintf(stderr, "[JACK capture] Registring callback problem.\n"); goto release_client; } if(jack_set_process_callback(s->client, jack_process_callback, (void *) s) != 0) { fprintf(stderr, "[JACK capture] Process callback registration problem.\n"); goto release_client; } if(jack_activate(s->client)) { fprintf(stderr, "[JACK capture] Cannot activate client.\n"); goto release_client; } { int port; char name[32]; for(port = 0; port < s->frame.ch_count; port++) { snprintf(name, 32, "capture_%02u", port); s->input_ports[port] = jack_port_register(s->client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); /* attach ports */ if(jack_connect(s->client, ports[port], jack_port_name(s->input_ports[port]))) { fprintf(stderr, "[JACK capture] Cannot connect input ports.\n"); } } } free(ports); s->can_process = true; return s; release_client: jack_client_close(s->client); error: free(s); return NULL; }
int jack_init_seq() { fprintf(stderr, "Opening JACK MIDI port\n"); midi_port=jack_port_register(client, jmidi_portname, JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0); }
static void plugin_create_aux_ports (plugin_t * plugin, guint copy, jack_rack_t * jack_rack) { plugin_desc_t * desc; // plugin_slot_t * slot; unsigned long aux_channel = 1; unsigned long plugin_index = 1; unsigned long i; char port_name[64]; char * plugin_name; char * ptr; // GList * list; ladspa_holder_t * holder; desc = plugin->desc; holder = plugin->holders + copy; holder->aux_ports = g_malloc (sizeof (jack_port_t *) * desc->aux_channels); /* make the plugin name jack worthy */ ptr = plugin_name = g_strndup (plugin->desc->name, 7); while (*ptr != '\0') { if (*ptr == ' ') *ptr = '_'; else *ptr = tolower (*ptr); ptr++; } /* for (list = jack_rack->slots; list; list = g_list_next (list)) { slot = (plugin_slot_t *) list->data; if (slot->plugin->desc->id == plugin->desc->id) plugin_index++; } */ for (i = 0; i < desc->aux_channels; i++, aux_channel++) { sprintf (port_name, "%s_%ld-%d_%c%ld", plugin_name, plugin_index, copy + 1, desc->aux_are_input ? 'i' : 'o', aux_channel); holder->aux_ports[i] = jack_port_register (jack_rack->procinfo->jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, desc->aux_are_input ? JackPortIsInput : JackPortIsOutput, 0); if (!holder->aux_ports[i]) { mlt_log_panic( NULL, "Could not register jack port '%s'; aborting\n", port_name); } } g_free (plugin_name); }
static int open_jack(out123_handle *ao) { jack_handle_t *handle=NULL; jack_options_t jopt = JackNullOption|JackNoStartServer; jack_status_t jstat = 0; unsigned int i; char *realname; debug("jack open"); if(!ao) return -1; /* Return if already open*/ if(ao->userptr) { if(!AOQUIET) error("audio device is already open."); return -1; } /* The initial open lets me choose the settings. */ if (ao->format==-1) { ao->format = MPG123_ENC_FLOAT_32; ao->channels = 2; /* Really need a framesize defined for callback. */ ao->framesize = 2*4; } else if(!(ao->format & MPG123_ENC_FLOAT)) { if(!AOQUIET) error("JACK only wants float!"); return -1; } /* Create some storage for ourselves*/ if((handle = alloc_jack_handle(ao)) == NULL) return -1; ao->userptr = (void*)handle; /* Register with Jack*/ if((handle->client = jack_client_open(ao->name, jopt, &jstat)) == 0) { if(!AOQUIET) error1("Failed to open jack client: 0x%x", jstat); close_jack(ao); return -1; } realname = jack_get_client_name(handle->client); /* Display the unique client name allocated to us */ if(AOVERBOSE(1)) fprintf( stderr, "Registered as JACK client %s.\n" , realname ? realname : "<nil>" ); /* Just make sure. */ ao->rate = jack_get_sample_rate(handle->client); /* Check the sample rate is correct*/ if (jack_get_sample_rate( handle->client ) != (jack_nframes_t)ao->rate) { if(!AOQUIET) error("JACK Sample Rate is different to sample rate of file."); close_jack(ao); return -1; } /* Register ports with Jack*/ if(handle->channels > 0 && handle->channels < 100) { for(i=0;i<handle->channels;++i) { char numbuf[3]; /* two digits, zero byte */ sprintf(numbuf, "%d", i+1); if( !(handle->ports[i] = jack_port_register( handle->client , numbuf, JACK_DEFAULT_AUDIO_TYPE , JackPortIsOutput, 0 )) ) { if(!AOQUIET) error1("Cannot register JACK output port '%s'.", numbuf); close_jack(ao); return -1; } } } else { if(!AOQUIET) error1("excessive number of output channels (%d).", handle->channels); close_jack(ao); return -1; } /* Use device_buffer parameter for ring buffer, but ensure that two JACK buffers fit in there. We do not support that buffer increasing later on. */ handle->rb_size = (size_t)( ao->device_buffer * jack_get_sample_rate(handle->client) + 0.5 ); /* PCM frames */ handle->procbuf_frames = jack_get_buffer_size(handle->client); if(handle->rb_size < 2*handle->procbuf_frames) handle->rb_size = 2*handle->procbuf_frames; debug1("JACK ringbuffer for %"SIZE_P" PCM frames", (size_p)handle->rb_size); /* Convert to bytes. */ handle->rb_size *= handle->framesize; handle->rb = jack_ringbuffer_create(handle->rb_size); handle->procbuf = malloc(handle->procbuf_frames*handle->framesize); if(!handle->rb || !handle->procbuf) { if(!AOQUIET) error("failed to allocate buffers"); close_jack(ao); return -1; } /* Set the callbacks*/ jack_set_process_callback(handle->client, process_callback, (void*)handle); jack_on_shutdown(handle->client, shutdown_callback, (void*)handle); handle->alive = 1; /* Activate client*/ if(jack_activate(handle->client)) { if(!AOQUIET) error("Can't activate client."); close_jack(ao); return -1; } /* Connect up the portsm, return */ if(!connect_jack_ports(ao, handle)) { /* deregistering of ports will not work but should just fail, then, and let the rest clean up */ close_jack(ao); return -1; } debug("Jack open successful.\n"); ao->realname = compat_strdup(realname); return 0; }
int jack_init(JackCard* obj) { char* client_name; int error; if (!obj->jack_running) { obj->client = NULL; client_name = g_strdup_printf("linphone-%u", g_random_int()); if ((obj->client = jack_client_new (client_name)) == NULL) { g_warning("cannot create jack client"); g_free(client_name); return -1; } g_message("Found Jack Daemon"); g_free(client_name); /* tell the JACK server to call `process()' whenever there is work to be done. */ jack_set_process_callback (obj->client, process, obj); /* 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 (obj->client, jack_shutdown, obj); jack_set_sample_rate_callback (obj->client, samplerate, obj); obj->rate = jack_get_sample_rate (obj->client); if (obj->rate == 0) { g_warning ("rate is 0???"); if (jack_client_close(obj->client) != 0) g_warning("could not close client"); return -1; } obj->buffer_size = jack_get_buffer_size(obj->client); obj->jack_running = TRUE; } if (!obj->jack_active) { if (jack_activate (obj->client)) { g_warning("cannot activate jack client"); return -1; } else obj->jack_active = TRUE; } if (obj->read.init) { if (!obj->read.port && (obj->read.port = jack_port_register (obj->client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0))==NULL) { g_warning("error while trying to register input port"); return -1; } if (!obj->read.phys_ports && (obj->read.phys_ports = jack_get_ports (obj->client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput)) == NULL) { g_warning("Cannot find any physical capture ports\n"); jack_port_unregister(obj->client, obj->read.port); obj->read.port = NULL; return -1; } if (!jack_port_connected(obj->read.port)) if ((error = jack_connect (obj->client, obj->read.phys_ports[0], jack_port_name (obj->read.port))) != 0) { g_warning("cannot connect input ports: %s -> %s\n", jack_port_name (obj->read.port), obj->read.phys_ports[0]); if (error == EEXIST) g_warning("connection already made"); else { jack_port_unregister(obj->client, obj->read.port); obj->read.port = NULL; return -1; } } obj->read.init = FALSE; } if (obj->write.init) { if (!obj->write.port && (obj->write.port = jack_port_register (obj->client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0))==NULL) { g_warning("error while trying to register output port"); return -1; } if (!obj->write.phys_ports && (obj->write.phys_ports = jack_get_ports (obj->client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) { g_warning("Cannot find any physical playback ports\n"); jack_port_unregister(obj->client, obj->write.port); obj->write.port = NULL; return -1; } if (!jack_port_connected(obj->write.port)) { if ((error = jack_connect (obj->client, jack_port_name (obj->write.port), obj->write.phys_ports[0])) != 0) { g_warning("cannot connect output ports: %s -> %s\n", jack_port_name (obj->write.port), obj->write.phys_ports[0]); if (error == EEXIST) g_warning("connection already made"); else { jack_port_unregister(obj->client, obj->write.port); obj->write.port = NULL; return -1; } } if ((error = jack_connect (obj->client, jack_port_name (obj->write.port), obj->write.phys_ports[1])) != 0) { g_warning("cannot connect output ports: %s -> %s\n", jack_port_name (obj->write.port), obj->write.phys_ports[1]); if (error == EEXIST) g_warning("connection already made"); else { jack_port_unregister(obj->client, obj->write.port); obj->write.port = NULL; return -1; } } } obj->write.init = FALSE; } return 0; }
/* initialize JACK audio */ u8 j_init(void){ jack_client_t *client; const intptr_t **ports; fprintf(stderr, "Trying jack....\n"); // tell the JACK server to call error() whenever it //experiences an error. Notice that this callback is // global to this process, not specific to each client. // // This is set here so that it can catch errors in the // connection process jack_set_error_function(j_error); // try to become a client of the JACK server if((client = jack_client_new("pineappletracker")) == 0){ fprintf(stderr, "jack server not running?\n"); return 1; } // tell the JACK server to call `process()' whenever // there is work to be done. jack_set_process_callback(client, j_process, 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(client, j_shutdown, 0); // 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. fprintf(stderr, "engine sample rate: %d\n", jack_get_sample_rate (client)); sr=jack_get_sample_rate(client); output_port = jack_port_register(client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); // tell the JACK server that we are ready to roll if(jack_activate(client)){ fprintf (stderr, "cannot activate client"); return 1; } // connect the ports if((ports = jack_get_ports(client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL){ fprintf(stderr, "Cannot find any physical playback ports\n"); return 1; } int i=0; while(ports[i]!=NULL){ if(jack_connect(client, jack_port_name (output_port), ports[i])) fprintf(stderr, "cannot connect output ports\n"); i++; } return 0; }