9 jack_port_t *input_port;
10 jack_port_t *output_port;
11 jack_client_t *client;
14 int consecutive_xruns = 0;
15 float first_xrun = 0.0f;
16 float last_load = 0.0f;
20 int chunksize = 1024 * 1024 * 10;
23 fooey (jack_nframes_t n)
26 thechunk[random()%chunksize] = n;
30 process (jack_nframes_t nframes, void *arg)
32 jack_default_audio_sample_t *in, *out;
35 in = jack_port_get_buffer (input_port, nframes);
36 out = jack_port_get_buffer (output_port, nframes);
38 memcpy (out, in, sizeof (jack_default_audio_sample_t) * nframes);
40 for (i = 0; i < loopsize; ++i) {
44 last_load = jack_cpu_load (client);
46 if ((at_loop += nframes) >= at_loop_size) {
47 if (last_load < 25.0f) {
49 } else if (last_load < 50.0f) {
50 loopsize = (int) (1.5 * loopsize);
51 } else if (last_load < 90.0f) {
52 loopsize += (int) (0.10 * loopsize);
53 } else if (last_load < 95.0f) {
54 loopsize += (int) (0.05 * loopsize);
56 loopsize += (int) (0.001 * loopsize);
59 printf ("loopsize = %d\n", loopsize);
63 if (consecutive_xruns == 0) {
64 first_xrun = last_load;
71 if (consecutive_xruns >= 10) {
72 fprintf (stderr, "Stopping with load = %f (first xrun at %f)\n", last_load, first_xrun);
80 * JACK calls this shutdown_callback if the server ever shuts down or
81 * decides to disconnect the client.
84 jack_shutdown (void *arg)
86 fprintf (stderr, "shutdown with load = %f\n", last_load);
93 fprintf (stderr, "xrun occured with loop size = %d\n", loopsize);
99 main (int argc, char *argv[])
102 const char *client_name;
103 const char *server_name = NULL;
104 jack_options_t options = JackNullOption;
105 jack_status_t status;
107 client_name = "jacktester";
109 chunksize = atoi (argv[1]);
110 printf ("using chunksize of %d\n", chunksize);
113 /* open a client connection to the JACK server */
115 client = jack_client_open (client_name, options, &status, server_name);
116 if (client == NULL) {
117 fprintf (stderr, "jack_client_open() failed, status = 0x%x\n",
119 if (status & JackServerFailed) {
120 fprintf (stderr, "Unable to connect to JACK server\n");
124 if (status & JackServerStarted) {
125 fprintf (stderr, "JACK server started\n");
127 if (status & JackNameNotUnique) {
128 client_name = jack_get_client_name(client);
129 fprintf (stderr, "unique name `%s' assigned\n", client_name);
132 /* tell the JACK server to call `process()' whenever
133 there is work to be done.
136 jack_set_process_callback (client, process, 0);
137 jack_set_xrun_callback (client, jack_xrun, 0);
138 jack_on_shutdown (client, jack_shutdown, 0);
140 /* create two ports */
142 input_port = jack_port_register (client, "input",
143 JACK_DEFAULT_AUDIO_TYPE,
145 output_port = jack_port_register (client, "output",
146 JACK_DEFAULT_AUDIO_TYPE,
147 JackPortIsOutput, 0);
149 if ((input_port == NULL) || (output_port == NULL)) {
150 fprintf(stderr, "no more JACK ports available\n");
154 at_loop_size = jack_get_sample_rate (client) * 2;
155 if ((thechunk = (char *) malloc (chunksize)) == NULL) {
156 fprintf (stderr, "cannot allocate chunk\n");
160 /* Tell the JACK server that we are ready to roll. Our
161 * process() callback will start running now. */
163 if (jack_activate (client)) {
164 fprintf (stderr, "cannot activate client");
168 /* connect the ports. Note: you can't do this before the
169 client is activated, because we can't allow connections to
170 be made to clients that aren't running.
173 ports = jack_get_ports (client, NULL, NULL,
174 JackPortIsPhysical|JackPortIsOutput);
176 fprintf(stderr, "no physical capture ports\n");
180 if (jack_connect (client, ports[0], jack_port_name (input_port))) {
181 fprintf (stderr, "cannot connect input ports\n");
186 ports = jack_get_ports (client, NULL, NULL,
187 JackPortIsPhysical|JackPortIsInput);
189 fprintf(stderr, "no physical playback ports\n");
193 if (jack_connect (client, jack_port_name (output_port), ports[0])) {
194 fprintf (stderr, "cannot connect output ports\n");
203 jack_client_close (client);