measuring jack themes technologies tooltips linux measuring jack themes technologies tooltip linux limejack claim limejack limejack

Start | Language  de en fr | Menu | Map | Search

You are here: start » en » jack » simple_client

Simple JACK Client

This simple_client serves as a template for development with JACK. All exception handling have been removed without affecting the functionality of the client. LimeJACK systems are solidly designed and without errors. ;-)

  • Replace the memcpy command in the callback routine with your MSR code.
  • The sleep command in the main routine should be understood as a never-ending loop for program control.
  • Main routine and callback routine run in separate threads.

Program control

  • Create global variables.
  • Replace the sleep command with a query (fgets).
  • Set control variables that also apply in the callback routine, which controls it.
simple_client.c
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

#include <jack/jack.h>

jack_port_t *input_port;
jack_port_t *output_port;
jack_client_t *client;

int process (jack_nframes_t nframes, void *arg)
{
  jack_default_audio_sample_t *in, *out;

  in = jack_port_get_buffer (input_port, nframes);
  out = jack_port_get_buffer (output_port, nframes);
  memcpy (out, in, sizeof (jack_default_audio_sample_t) * nframes);

  return 0;
}

void jack_shutdown (void *arg)
{
  exit (1);
}

int main (int argc, char *argv[])
{
  const char **ports;
  const char *client_name = "simple";
  const char *server_name = NULL;
  jack_options_t options = JackNullOption;
  jack_status_t status;

  client = jack_client_open (client_name, options, &status, server_name);
  if (status & JackNameNotUnique)
  {
    client_name = jack_get_client_name(client);
  }
  jack_set_process_callback (client, process, 0);
  jack_on_shutdown (client, jack_shutdown, 0);

  printf ("engine sample rate: %" PRIu32 "\n",jack_get_sample_rate (client));

  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);

  jack_activate (client);

  ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput);
  jack_connect (client, ports[0], jack_port_name (input_port))
  free (ports);
  ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput);
  jack_connect (client, jack_port_name (output_port), ports[0])
  free (ports);

  sleep (-1); //Newer ending loop

  jack_client_close (client);
  exit (0);
}
Disclaimer | Impressum | Privacy | Copyleft