[linux-audio-dev] Best road to audio programming happiness?

Paul Davis paul at linuxaudiosystems.com
Tue Sep 23 14:38:00 UTC 2003


>It sounds like Jack is a system to learn like on Windows/Mac.

JACK is arguably simpler than either OSS or anything else. you don't
configure any device parameters, you don't use system calls to move
data around, etc. the minimal JACK client (which copies 1 channel's
worth of data from its input to its output):

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

int
process (jack_nframes_t nframes, void *arg)
{
	/* this is where the magic happens */

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

	memcpy (out, in, sizeof (jack_default_audio_sample_t) * nframes);
	
	return 0;      
}

int
main (int argc, char *argv[])
{
	jack_client_t *client;
	const char **ports;

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

	/* 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;
	}

	/* Since this is just a toy, run for a few seconds, then finish */

	sleep (10);
	jack_client_close (client);
	exit (0);
}



More information about the Linux-audio-dev mailing list