3 * @brief This demonstrates the basic concepts for writing a client
4 * that runs within the JACK server process.
6 * For the sake of example, a port_pair_t is allocated in
7 * jack_initialize(), passed to inprocess() as an argument, then freed
14 #include <jack/jack.h>
17 * For the sake of example, an instance of this struct is allocated in
18 * jack_initialize(), passed to inprocess() as an argument, then freed
22 jack_port_t
*input_port
;
23 jack_port_t
*output_port
;
27 * Called in the realtime thread on every process cycle. The entry
28 * point name was passed to jack_set_process_callback() from
29 * jack_initialize(). Although this is an internal client, its
30 * process() interface is identical to @ref simple_client.c.
32 * @return 0 if successful; otherwise jack_finish() will be called and
33 * the client terminated immediately.
36 inprocess (jack_nframes_t nframes
, void *arg
)
38 port_pair_t
*pp
= arg
;
39 jack_default_audio_sample_t
*out
=
40 jack_port_get_buffer (pp
->output_port
, nframes
);
41 jack_default_audio_sample_t
*in
=
42 jack_port_get_buffer (pp
->input_port
, nframes
);
44 memcpy (out
, in
, sizeof (jack_default_audio_sample_t
) * nframes
);
46 return 0; /* continue */
50 * This required entry point is called after the client is loaded by
51 * jack_internal_client_load().
53 * @param client pointer to JACK client structure.
54 * @param load_init character string passed to the load operation.
56 * @return 0 if successful; otherwise jack_finish() will be called and
57 * the client terminated immediately.
60 jack_initialize (jack_client_t
*client
, const char *load_init
)
62 port_pair_t
*pp
= malloc (sizeof (port_pair_t
));
65 return 1; /* heap exhausted */
67 jack_set_process_callback (client
, inprocess
, pp
);
69 /* create a pair of ports */
70 pp
->input_port
= jack_port_register (client
, "input",
71 JACK_DEFAULT_AUDIO_TYPE
,
73 pp
->output_port
= jack_port_register (client
, "output",
74 JACK_DEFAULT_AUDIO_TYPE
,
77 /* join the process() cycle */
78 jack_activate (client
);
80 /* try to connect to the first physical input & output ports */
82 if (jack_connect (client
, "system:capture_1",
83 jack_port_name (pp
->input_port
))) {
84 fprintf (stderr
, "cannot connect input port\n");
85 return 1; /* terminate client */
88 if (jack_connect (client
, jack_port_name (pp
->output_port
),
89 "system:playback_1")) {
90 fprintf (stderr
, "cannot connect output port\n");
91 return 1; /* terminate client */
94 return 0; /* success */
98 * This required entry point is called immediately before the client
99 * is unloaded, which could happen due to a call to
100 * jack_internal_client_unload(), or a nonzero return from either
101 * jack_initialize() or inprocess().
103 * @param arg the same parameter provided to inprocess().
106 jack_finish (void *arg
)
109 free ((port_pair_t
*) arg
);