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.
61 jack_initialize (jack_client_t
*client
, const char *load_init
)
63 port_pair_t
*pp
= malloc (sizeof (port_pair_t
));
67 return 1; /* heap exhausted */
69 jack_set_process_callback (client
, inprocess
, pp
);
71 /* create a pair of ports */
72 pp
->input_port
= jack_port_register (client
, "input",
73 JACK_DEFAULT_AUDIO_TYPE
,
75 pp
->output_port
= jack_port_register (client
, "output",
76 JACK_DEFAULT_AUDIO_TYPE
,
79 /* join the process() cycle */
80 jack_activate (client
);
82 ports
= jack_get_ports (client
, NULL
, NULL
,
83 JackPortIsPhysical
|JackPortIsOutput
);
85 fprintf(stderr
, "no physical capture ports\n");
86 return 1; /* terminate client */
89 if (jack_connect (client
, ports
[0], jack_port_name (pp
->input_port
))) {
90 fprintf (stderr
, "cannot connect input ports\n");
95 ports
= jack_get_ports (client
, NULL
, NULL
,
96 JackPortIsPhysical
|JackPortIsInput
);
98 fprintf(stderr
, "no physical playback ports\n");
99 return 1; /* terminate client */
102 if (jack_connect (client
, jack_port_name (pp
->output_port
), ports
[0])) {
103 fprintf (stderr
, "cannot connect output ports\n");
108 return 0; /* success */
112 * This required entry point is called immediately before the client
113 * is unloaded, which could happen due to a call to
114 * jack_internal_client_unload(), or a nonzero return from either
115 * jack_initialize() or inprocess().
117 * @param arg the same parameter provided to inprocess().
121 jack_finish (void *arg
)
124 free ((port_pair_t
*) arg
);