1 /** @file simple_client.c
3 * @brief This simple client demonstrates the most basic features of JACK
4 * as they would be used by many applications.
13 #include <jack/jack.h>
15 jack_port_t
*input_port
;
16 jack_port_t
*output_port
;
17 jack_client_t
*client
;
20 * The process callback for this JACK application is called in a
21 * special realtime thread once for each audio cycle.
23 * This client does nothing more than copy data from its input
24 * port to its output port. It will exit when stopped by
25 * the user (e.g. using Ctrl-C on a unix-ish operating system)
28 process (jack_nframes_t nframes
, void *arg
)
30 jack_default_audio_sample_t
*in
, *out
;
32 in
= jack_port_get_buffer (input_port
, nframes
);
33 out
= jack_port_get_buffer (output_port
, nframes
);
35 sizeof (jack_default_audio_sample_t
) * nframes
);
41 * JACK calls this shutdown_callback if the server ever shuts down or
42 * decides to disconnect the client.
45 jack_shutdown (void *arg
)
51 main (int argc
, char *argv
[])
54 const char *client_name
= "simple";
55 const char *server_name
= NULL
;
56 jack_options_t options
= JackNullOption
;
59 /* open a client connection to the JACK server */
61 client
= jack_client_open (client_name
, options
, &status
, server_name
);
63 fprintf (stderr
, "jack_client_open() failed, "
64 "status = 0x%2.0x\n", status
);
65 if (status
& JackServerFailed
) {
66 fprintf (stderr
, "Unable to connect to JACK server\n");
70 if (status
& JackServerStarted
) {
71 fprintf (stderr
, "JACK server started\n");
73 if (status
& JackNameNotUnique
) {
74 client_name
= jack_get_client_name(client
);
75 fprintf (stderr
, "unique name `%s' assigned\n", client_name
);
78 /* tell the JACK server to call `process()' whenever
79 there is work to be done.
82 jack_set_process_callback (client
, process
, 0);
84 /* tell the JACK server to call `jack_shutdown()' if
85 it ever shuts down, either entirely, or if it
86 just decides to stop calling us.
89 jack_on_shutdown (client
, jack_shutdown
, 0);
91 /* display the current sample rate.
94 printf ("engine sample rate: %" PRIu32
"\n",
95 jack_get_sample_rate (client
));
97 /* create two ports */
99 input_port
= jack_port_register (client
, "input",
100 JACK_DEFAULT_AUDIO_TYPE
,
102 output_port
= jack_port_register (client
, "output",
103 JACK_DEFAULT_AUDIO_TYPE
,
104 JackPortIsOutput
, 0);
106 if ((input_port
== NULL
) || (output_port
== NULL
)) {
107 fprintf(stderr
, "no more JACK ports available\n");
111 /* Tell the JACK server that we are ready to roll. Our
112 * process() callback will start running now. */
114 if (jack_activate (client
)) {
115 fprintf (stderr
, "cannot activate client");
119 /* Connect the ports. You can't do this before the client is
120 * activated, because we can't make connections to clients
121 * that aren't running. Note the confusing (but necessary)
122 * orientation of the driver backend ports: playback ports are
123 * "input" to the backend, and capture ports are "output" from
127 ports
= jack_get_ports (client
, NULL
, NULL
,
128 JackPortIsPhysical
|JackPortIsOutput
);
130 fprintf(stderr
, "no physical capture ports\n");
134 if (jack_connect (client
, ports
[0], jack_port_name (input_port
))) {
135 fprintf (stderr
, "cannot connect input ports\n");
140 ports
= jack_get_ports (client
, NULL
, NULL
,
141 JackPortIsPhysical
|JackPortIsInput
);
143 fprintf(stderr
, "no physical playback ports\n");
147 if (jack_connect (client
, jack_port_name (output_port
), ports
[0])) {
148 fprintf (stderr
, "cannot connect output ports\n");
153 /* keep running until stopped by the user */
157 /* this is never reached but if the program
158 had some other way to exit besides being killed,
159 they would be important to call.
162 jack_client_close (client
);