** Warning: Cannot open xref database.
1 /** @file simple_client.c
2 *
3 * @brief This is very simple client that demonstrates the basic
4 * features of JACK as they would be used by many applications.
5 */
6
7 #include <stdio.h>
8 #include <errno.h>
9 #include <unistd.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include <jack/jack.h>
14
15 jack_port_t *input_port;
16 jack_port_t *output_port;
17
18 /**
19 * The process callback for this JACK application.
20 * It is called by JACK at the appropriate times.
21 */
22 int
23 process (jack_nframes_t nframes, void *arg)
24 {
25 jack_default_audio_sample_t *out = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port, nframes);
26 jack_default_audio_sample_t *in = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port, nframes);
27
28 memcpy (out, in, sizeof (jack_default_audio_sample_t) * nframes);
29
30 return 0;
31 }
32
33 /**
34 * This is the shutdown callback for this JACK application.
35 * It is called by JACK if the server ever shuts down or
36 * decides to disconnect the client.
37 */
38 void
39 jack_shutdown (void *arg)
40 {
41
42 exit (1);
43 }
44
45 int
46 main (int argc, char *argv[])
47 {
48 jack_client_t *client;
49 const char **ports;
50
51 if (argc < 2) {
52 fprintf (stderr, "usage: jack_simple_client <name>\n");
53 return 1;
54 }
55
56 /* try to become a client of the JACK server */
57
58 if ((client = jack_client_new (argv[1])) == 0) {
59 fprintf (stderr, "jack server not running?\n");
60 return 1;
61 }
62
63 /* tell the JACK server to call `process()' whenever
64 there is work to be done.
65 */
66
67 jack_set_process_callback (client, process, 0);
68
69 /* tell the JACK server to call `jack_shutdown()' if
70 it ever shuts down, either entirely, or if it
71 just decides to stop calling us.
72 */
73
74 jack_on_shutdown (client, jack_shutdown, 0);
75
76 /* display the current sample rate.
77 */
78
79 printf ("engine sample rate: %" PRIu32 "\n",
80 jack_get_sample_rate (client));
81
82 /* create two ports */
83
84 input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
85 output_port = jack_port_register (client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
86
87 /* tell the JACK server that we are ready to roll */
88
89 if (jack_activate (client)) {
90 fprintf (stderr, "cannot activate client");
91 return 1;
92 }
93
94 /* connect the ports. Note: you can't do this before
95 the client is activated, because we can't allow
96 connections to be made to clients that aren't
97 running.
98 */
99
100 if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput)) == NULL) {
101 fprintf(stderr, "Cannot find any physical capture ports\n");
102 exit(1);
103 }
104
105 if (jack_connect (client, ports[0], jack_port_name (input_port))) {
106 fprintf (stderr, "cannot connect input ports\n");
107 }
108
109 free (ports);
110
111 if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) {
112 fprintf(stderr, "Cannot find any physical playback ports\n");
113 exit(1);
114 }
115
116 if (jack_connect (client, jack_port_name (output_port), ports[0])) {
117 fprintf (stderr, "cannot connect output ports\n");
118 }
119
120 free (ports);
121
122 /* Since this is just a toy, run for a few seconds, then finish */
123
124 sleep (10);
125 jack_client_close (client);
126 exit (0);
127 }
128
129
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.