Devin Anderson jackmp-fix-ffado-midi-2.diff patch.
[jack2.git] / tests / test.cpp
blob1c558bc2a55247feb74791052469d81c5b49e258
1 /*
2 Copyright (C) 2005 Samuel TRACOL for GRAME
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file jack_test.c
22 * @brief This client test the jack API.
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <errno.h>
29 #ifndef WIN32
30 #include <unistd.h>
31 #endif
32 #include <string.h>
33 #include <getopt.h>
34 #include <math.h>
35 #include <assert.h>
36 #include <stdarg.h>
37 #include <jack/jack.h>
38 #include <jack/transport.h>
41 #if defined(WIN32) && !defined(M_PI)
42 #define M_PI 3.151592653
43 #endif
45 #ifdef WIN32
46 #define jack_sleep(val) Sleep((val))
47 #else
48 #define jack_sleep(val) usleep((val) * 1000)
49 #endif
51 typedef struct
53 jack_nframes_t ft; // running counter frame time
54 jack_nframes_t fcs; // from sycle start...
55 jack_nframes_t lft; // last frame time...
57 FrameTimeCollector;
59 FILE *file;
60 FrameTimeCollector* framecollect;
61 FrameTimeCollector perpetualcollect;
62 FrameTimeCollector lastperpetualcollect;
63 int frames_collected = 0;
65 // ports
66 jack_port_t *output_port1;
67 jack_port_t *output_port1b;
68 jack_port_t *input_port2;
69 jack_port_t *output_port2;
70 jack_port_t *input_port1;
72 // clients
73 jack_client_t *client1;
74 jack_client_t *client2;
75 const char *client_name1;
76 const char *client_name2;
78 unsigned long sr; // sample rate
79 // for time -t option
80 int time_to_run = 0;
81 int time_before_exit = 1;
82 // standard error count
83 int t_error = 0;
84 int reorder = 0; // graph reorder callback
85 int RT = 0; // is real time or not...
86 int FW = 0; // freewheel mode
87 int init_clbk = 0; // init callback
88 int port_rename_clbk = 0; // portrename callback
89 int i, j, k = 0;
90 int port_callback_reg = 0;
91 jack_nframes_t cur_buffer_size, old_buffer_size, cur_pos;
92 int activated = 0;
93 int count1, count2 = 0; // for freewheel
94 int xrun = 0;
95 int have_xrun = 0; // msg to tell the process1 function to write a special thing in the frametime file.
96 int process1_activated = -1; // to control processing...
97 int process2_activated = -1; // to control processing...
98 unsigned long int index1 = 0;
99 unsigned long int index2 = 0;
100 jack_default_audio_sample_t *signal1; // signal source d'emission
101 jack_default_audio_sample_t *signal2; // tableau de reception
102 jack_transport_state_t ts;
103 jack_position_t pos;
104 jack_position_t request_pos;
105 int silent_error = 0; // jack silent mode
106 int verbose_mode = 0;
107 int transport_mode = 1;
108 jack_nframes_t input_ext_latency = 0; // test latency for PHY devices
109 jack_nframes_t output_ext_latency = 0; // test latency for PHY devices
111 int sync_called = 0;
112 int starting_state = 1;
114 int linecount = 0; // line counter for log file of sampleframe counter --> for graph function.
115 int linebuf = 0; // reminders for graph analysis
116 int linetransport = 0;
117 int linefw = 0;
118 int lineports = 0;
119 int linecl2 = 0;
121 int client_register = 0;
124 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
125 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
127 Callbacks & basics functions
129 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
130 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
133 void usage()
135 fprintf (stderr, "\n\n"
136 "usage: jack_test \n"
137 " [ --time OR -t time_to_run (in seconds) ]\n"
138 " [ --quiet OR -q (quiet mode : without jack server errors) ]\n"
139 " [ --verbose OR -v (verbose mode : no details on tests done. Only main results & errors) ]\n"
140 " [ --transport OR -k (Do not test transport functions.) ]\n"
141 " --realtime OR -R (jack is in rt mode)\n\n\n"
143 exit(1);
146 void Log(const char *fmt, ...)
148 if (verbose_mode) {
149 va_list ap;
150 va_start(ap, fmt);
151 vfprintf(stderr, fmt, ap);
152 va_end(ap);
156 void Collect(FrameTimeCollector* TheFrame)
158 TheFrame->lft = jack_last_frame_time(client1);
159 TheFrame->ft = jack_frame_time(client1);
160 TheFrame->fcs = jack_frames_since_cycle_start(client1);
163 void Jack_Thread_Init_Callback(void *arg)
165 Log("Init callback has been successfully called. (msg from callback)\n");
166 init_clbk = 1;
169 void Jack_Freewheel_Callback(int starting, void *arg)
171 Log("Freewhell callback has been successfully called with value %i. (msg from callback)\n", starting);
172 FW = starting;
175 void Jack_Client_Registration_Callback(const char* name, int val, void *arg)
177 Log("Client registration callback name = %s has been successfully called with value %i. (msg from callback)\n", name, val);
178 if (val)
179 client_register++;
180 else
181 client_register--;
184 int Jack_Port_Rename_Callback(jack_port_id_t port, const char* old_name, const char* new_name, void *arg)
186 Log("Rename callback has been successfully called with old_name '%s' and new_name '%s'. (msg from callback)\n");
187 port_rename_clbk = 1;
190 int Jack_Update_Buffer_Size(jack_nframes_t nframes, void *arg)
192 cur_buffer_size = jack_get_buffer_size(client1);
193 Log("Buffer size = %d (msg from callback)\n", cur_buffer_size);
194 return 0;
197 int Jack_XRun_Callback(void *arg)
199 xrun++;
200 have_xrun = 1;
201 Log("Xrun has been detected ! (msg from callback)\n");
202 return 0;
205 int Jack_Graph_Order_Callback(void *arg)
207 reorder++;
208 return 0;
211 int Jack_Sample_Rate_Callback(jack_nframes_t nframes, void *arg)
213 Log("Sample rate : %i.\n", nframes);
214 return 0;
217 void Jack_Error_Callback(const char *msg)
219 if (silent_error == 0) {
220 fprintf(stderr, "error : %s (msg from callback)\n", msg);
224 void jack_shutdown(void *arg)
226 printf("Jack_test has been kicked out by jackd !\n");
227 exit(1);
230 void jack_info_shutdown(jack_status_t code, const char* reason, void *arg)
232 printf("JACK server failure : %s\n", reason);
233 exit(1);
236 void Jack_Port_Register(jack_port_id_t port, int mode, void *arg)
238 port_callback_reg++;
241 void Jack_Port_Connect(jack_port_id_t a, jack_port_id_t b, int connect, void* arg)
243 Log("PortConnect src = %ld dst = %ld onoff = %ld (msg from callback)\n", a, b, connect);
246 int Jack_Sync_Callback(jack_transport_state_t state, jack_position_t *pos, void *arg)
248 int res = 0;
250 switch (state) {
252 case JackTransportStarting:
253 sync_called++;
254 if (starting_state == 0) {
255 Log("sync callback : Releasing status : now ready...\n");
256 res = 1;
257 } else {
258 if (sync_called == 1) {
259 Log("sync callback : Holding status...\n");
261 res = 0;
263 break;
265 case JackTransportStopped:
266 Log("sync callback : JackTransportStopped...\n");
267 res = 0;
268 break;
270 default:
271 res = 0;
272 break;
275 return res;
280 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
281 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
283 processing functions
285 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
286 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
287 * Proccess1 is for client1
288 * 4 modes, activated with process1_activated
290 * -1 : idle mode
291 * 0 : write zeros to output 1
292 * 1 : write continuously signal1 (sinusoidal test signal) to output1
293 * 3 : mode for summation test. While record (done by process2) is not running, write signal1 to both out1 & out1b.
294 * when record begin (index2 > 0), write signal1 in phase opposition to out1 & out2
295 * 5 : Frames Time checking mode : write the array containing the three values of frame_time, frames cycles start and
296 * last frame time during 150 cycles.
299 int process1(jack_nframes_t nframes, void *arg)
301 if (FW == 0) {
302 Collect(&perpetualcollect);
303 if (have_xrun) {
304 fprintf(file, "%i %i\n", (perpetualcollect.ft - lastperpetualcollect.ft), (2*cur_buffer_size));
305 have_xrun = 0;
306 } else {
307 fprintf(file, "%i 0\n", (perpetualcollect.ft - lastperpetualcollect.ft));
309 linecount++;
310 lastperpetualcollect.ft = perpetualcollect.ft;
313 jack_default_audio_sample_t *out1;
314 jack_default_audio_sample_t *out1b;
315 activated++; // counter of callback activation
316 if (process1_activated == 1) {
317 out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
318 for (jack_nframes_t p = 0; p < nframes; p++) {
319 out1[p] = signal1[index1];
320 index1++;
321 if (index1 == 48000)
322 index1 = 0;
325 if (process1_activated == 3) {
326 out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
327 out1b = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1b, nframes);
328 for (jack_nframes_t p = 0; p < nframes; p++) {
329 out1[p] = signal1[index1];
330 if (index2 != 0) {
331 out1b[p] = ( -1 * signal1[index1]);
332 } else {
333 out1b[p] = signal1[index1];
335 index1++;
336 if (index1 == 48000)
337 index1 = 0;
340 if (process1_activated == 0) {
341 out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
342 memset (out1, 0, sizeof (jack_default_audio_sample_t) * nframes); //�crit des z�ros en sortie...
344 if (process1_activated == 5) {
345 Collect(&framecollect[frames_collected]);
346 frames_collected++;
347 if (frames_collected > 798) {
348 process1_activated = -1;
351 return 0;
355 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
356 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
357 * Proccess2 is for client2
358 * 3 modes, activated with process1_activated
360 * -1 : idle mode
361 * 0 : idle mode
362 * 1 : record in2 into signal2.(for first transmit test)
363 * 2 : record in2 into signal2 while send signal1 in out2. used dor Tie data test.
364 * 3 : record in2 into sigal2 for summation data test.
365 * In records modes, at the end of the record (signal2 is full), it stop the test, setting both activation states to -1.
368 int process2(jack_nframes_t nframes, void *arg)
370 jack_default_audio_sample_t *out2;
371 jack_default_audio_sample_t *in2;
373 if (process2_activated == 1) { // Reception du process1 pour comparer les donnees
374 in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
375 for (unsigned int p = 0; p < nframes; p++) {
376 signal2[index2] = in2[p];
377 if (index2 == 95999) {
378 process2_activated = 0;
379 process1_activated = 0;
380 //index2 = 0;
381 } else {
382 index2++;
387 if (process2_activated == 2) { // envoie de signal1 pour test tie mode et le r�cup�re direct + latence de la boucle jack...
388 out2 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port2, nframes);
389 in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
391 for (unsigned int p = 0; p < nframes; p++) {
392 out2[p] = signal1[index1];
393 index1++;
394 if (index1 == 48000)
395 index1 = 0;
396 signal2[index2] = in2[p];
397 if (index2 == 95999) {
398 process2_activated = -1;
399 //index2 = 0;
400 } else {
401 index2++;
406 if (process2_activated == 3) { // envoie de -signal1 pour sommation en oppo de phase par jack
407 in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
409 for (unsigned int p = 0; p < nframes;p++) {
410 signal2[index2] = in2[p];
411 if (index2 == 95999) {
412 process2_activated = 0;
413 process1_activated = 0;
414 //index2 = 0;
415 } else {
416 index2++;
421 return 0;
424 // Alternate thread model
425 static int _process (jack_nframes_t nframes)
427 jack_default_audio_sample_t *in, *out;
428 in = (jack_default_audio_sample_t *)jack_port_get_buffer (input_port1, nframes);
429 out = (jack_default_audio_sample_t *)jack_port_get_buffer (output_port1, nframes);
430 memcpy (out, in,
431 sizeof (jack_default_audio_sample_t) * nframes);
432 return 0;
435 static void* jack_thread(void *arg)
437 jack_client_t* client = (jack_client_t*) arg;
438 jack_nframes_t last_thread_time = jack_frame_time(client);
440 while (1) {
441 jack_nframes_t frames = jack_cycle_wait (client);
442 jack_nframes_t current_thread_time = jack_frame_time(client);
443 jack_nframes_t delta_time = current_thread_time - last_thread_time;
444 Log("jack_thread : delta_time = %ld\n", delta_time);
445 int status = _process(frames);
446 last_thread_time = current_thread_time;
447 jack_cycle_signal (client, status);
450 return 0;
453 // To test callback exiting
454 int process3(jack_nframes_t nframes, void *arg)
456 static int process3_call = 0;
458 if (process3_call++ > 10) {
459 Log("process3 callback : exiting...\n");
460 return -1;
461 } else {
462 Log("calling process3 callback : process3_call = %ld\n", process3_call);
463 return 0;
467 int process4(jack_nframes_t nframes, void *arg)
469 jack_client_t* client = (jack_client_t*) arg;
471 static jack_nframes_t last_time = jack_frame_time(client);
472 static jack_nframes_t tolerance = (jack_nframes_t)(cur_buffer_size * 0.1f);
474 jack_nframes_t cur_time = jack_frame_time(client);
475 jack_nframes_t delta_time = cur_time - last_time;
477 Log("calling process4 callback : jack_frame_time = %ld delta_time = %ld\n", cur_time, delta_time);
478 if (delta_time > 0 && (unsigned int)abs(delta_time - cur_buffer_size) > tolerance) {
479 printf("!!! ERROR !!! jack_frame_time seems to return incorrect values cur_buffer_size = %d, delta_time = %d\n", cur_buffer_size, delta_time);
482 last_time = cur_time;
483 return 0;
486 static void display_transport_state()
488 jack_transport_state_t ts;
489 jack_position_t pos;
491 ts = jack_transport_query(client2, &pos);
492 switch (ts) {
493 case JackTransportStopped:
494 Log("Transport is stopped...\n");
495 break;
496 case JackTransportRolling:
497 Log("Transport is rolling...\n");
498 break;
499 case JackTransportLooping:
500 Log("Transport is looping...\n");
501 break;
502 case JackTransportStarting:
503 Log("Transport is starting...\n");
504 break;
505 case JackTransportNetStarting:
506 Log("Transport is starting with network sync...\n");
507 break;
512 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
513 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
514 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
515 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
516 MAIN FUNCTION
517 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
518 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
519 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
520 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
522 int main (int argc, char *argv[])
524 const char **inports; // array of PHY input/output
525 const char **outports; // array of PHY input/outputs
526 const char *server_name = NULL;
527 const char **connexions1;
528 const char **connexions2;
529 jack_status_t status;
530 char portname[128] = "port";
531 char filename[128] = "framefile.ext";
532 const char *nullportname = "";
533 int option_index;
534 int opt;
535 int a = 0; // working number for in/out port (PHY)...
536 int test_link = 0; // for testing the "overconnect" function
537 int flag; // flag for ports...
538 int is_mine = 0; // to test jack_port_is_mine function...
539 const char *options = "kRnqvt:";
540 float ratio; // for speed calculation in freewheel mode
541 jack_options_t jack_options = JackNullOption;
542 struct option long_options[] = {
543 {"realtime", 0, 0, 'R'},
544 {"non-realtime", 0, 0, 'n'},
545 {"time", 0, 0, 't'},
546 {"quiet", 0, 0, 'q'},
547 {"verbose", 0, 0, 'v'},
548 {"transport", 0, 0, 'k'},
549 {0, 0, 0, 0}
552 client_name1 = "jack_test";
553 time_to_run = 1;
554 while ((opt = getopt_long (argc, argv, options, long_options, &option_index)) != EOF) {
555 switch (opt) {
556 case 'k':
557 transport_mode = 0;
558 break;
559 case 'q':
560 silent_error = 1;
561 break;
562 case 'v':
563 verbose_mode = 1;
564 printf("Verbose mode is activated...\n");
565 break;
566 case 't':
567 time_to_run = atoi(optarg);
568 break;
569 case 'R':
570 RT = 1;
571 break;
572 default:
573 fprintf (stderr, "unknown option %c\n", opt);
574 usage ();
578 if (RT) {
579 printf("Jack server is said being in realtime mode...\n");
580 } else {
581 printf("Jack server is said being in non-realtime mode...\n");
584 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
585 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
586 init signal data for test
587 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
588 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
590 framecollect = (FrameTimeCollector *) malloc(800 * sizeof(FrameTimeCollector));
592 signal1 = (jack_default_audio_sample_t *) malloc(48000 * sizeof(jack_default_audio_sample_t));
593 signal2 = (jack_default_audio_sample_t *) malloc(96000 * sizeof(jack_default_audio_sample_t));
594 signal1[0] = 0;
595 int p;
596 for (p = 1; p < 48000;p++) {
597 signal1[p] = (float)(sin((p * 2 * M_PI * 1000 ) / 48000));
599 for (p = 0; p < 95999;p++) {
600 signal2[p] = 0.0 ;
602 index1 = 0;
603 index2 = 0;
605 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
606 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
607 begin test
608 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
609 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
611 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
612 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
613 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-* Start jack server stress test *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
614 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
615 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
618 * Register a client...
621 Log("Register a client using jack_client_open()...\n");
622 client1 = jack_client_open(client_name1, jack_options, &status, server_name);
623 if (client1 == NULL) {
624 fprintf (stderr, "jack_client_open() failed, "
625 "status = 0x%2.0x\n", status);
626 if (status & JackServerFailed) {
627 fprintf(stderr, "Unable to connect to JACK server\n");
629 exit (1);
631 if (status & JackServerStarted) {
632 fprintf(stderr, "JACK server started\n");
636 * try to register another one with the same name...
639 Log("trying to register a new jackd client with name %s using jack_client_new()...\n", client_name1);
640 client2 = jack_client_new(client_name1);
641 if (client2 == NULL) {
642 Log ("valid : a second client with the same name cannot be registered\n");
643 } else {
644 printf("!!! ERROR !!! Jackd server has accepted multiples client with the same name !\n");
645 jack_client_close(client2);
649 * try to register another one with the same name using jack_client_open ==> since JackUseExactName is not used, an new client should be opened...
652 Log("trying to register a new jackd client with name %s using jack_client_open()...\n", client_name1);
653 client2 = jack_client_open(client_name1, jack_options, &status, server_name);
654 if (client2 != NULL) {
655 Log ("valid : a second client with the same name can be registered (client automatic renaming)\n");
656 jack_client_close(client2);
657 } else {
658 printf("!!! ERROR !!! Jackd server automatic renaming feature does not work!\n");
662 * testing client name...
663 * Verify that the name sended at registration and the one returned by jack server is the same...
666 Log("Testing name...");
667 client_name2 = jack_get_client_name(client1);
668 if (strcmp(client_name1, client_name2) == 0)
669 Log(" ok\n");
670 else
671 printf("\n!!! ERROR !!! name returned different from the one given : %s\n", client_name2);
674 * Test RT mode...
675 * verify if the real time mode returned by jack match the optional argument defined when launching jack_test*/
676 if (jack_is_realtime(client1) == RT)
677 Log("Jackd is in realtime mode (RT = %i).\n", RT);
678 else
679 printf("!!! ERROR !!! Jackd is in a non-expected realtime mode (RT = %i).\n", RT);
682 * Register all callbacks...
685 if (jack_set_thread_init_callback(client1, Jack_Thread_Init_Callback, 0) != 0)
686 printf("!!! ERROR !!! while calling jack_set_thread_init_callback()...\n");
687 if (jack_set_freewheel_callback(client1, Jack_Freewheel_Callback, 0) != 0 )
688 printf("\n!!! ERROR !!! while calling jack_set_freewheel_callback()...\n");
691 if (jack_set_process_callback(client1, process1, 0) != 0) {
692 printf("Error when calling jack_set_process_callback() !\n");
695 jack_on_shutdown(client1, jack_shutdown, 0);
696 jack_on_info_shutdown(client1, jack_info_shutdown, 0);
698 if (jack_set_buffer_size_callback(client1, Jack_Update_Buffer_Size, 0) != 0) {
699 printf("Error when calling buffer_size_callback !\n");
702 if (jack_set_graph_order_callback(client1, Jack_Graph_Order_Callback, 0) != 0) {
703 printf("Error when calling Jack_Graph_Order_Callback() !\n");
706 if (jack_set_port_rename_callback(client1, Jack_Port_Rename_Callback, 0) != 0 )
707 printf("\n!!! ERROR !!! while calling jack_set_rename_callback()...\n");
709 if (jack_set_xrun_callback(client1, Jack_XRun_Callback, 0 ) != 0) {
710 printf("Error when calling jack_set_xrun_callback() !\n");
713 if (jack_set_sample_rate_callback(client1, Jack_Sample_Rate_Callback, 0 ) != 0) {
714 printf("Error when calling Jack_Sample_Rate_Callback() !\n");
717 if (jack_set_port_registration_callback(client1, Jack_Port_Register, 0) != 0) {
718 printf("Error when calling jack_set_port_registration_callback() !\n");
721 if (jack_set_port_connect_callback(client1, Jack_Port_Connect, 0) != 0) {
722 printf("Error when calling jack_set_port_connect_callback() !\n");
725 if (jack_set_client_registration_callback(client1, Jack_Client_Registration_Callback, 0) != 0) {
726 printf("Error when calling jack_set_client_registration_callback() !\n");
729 jack_set_error_function(Jack_Error_Callback);
732 * Create file for clock "frame time" analysis
735 cur_buffer_size = jack_get_buffer_size(client1);
736 sprintf (filename, "framefile-%i.dat", cur_buffer_size);
737 file = fopen(filename, "w");
738 if (file == NULL) {
739 fprintf(stderr, "Erreur dans l'ouverture du fichier log framefile.dat");
740 exit(-1);
744 * Try to register a client with a NULL name/zero length name...
747 output_port1 = jack_port_register(client1, nullportname,
748 JACK_DEFAULT_AUDIO_TYPE,
749 JackPortIsOutput, 0);
750 if (output_port1 == NULL) {
751 Log("Can't register a port with a NULL portname... ok.\n");
752 } else {
753 printf("!!! ERROR !!! Can register a port with a NULL portname !\n");
754 jack_port_unregister(client1, output_port1);
758 * Register 1 port in order to stress other functions.
761 output_port1 = jack_port_register(client1, portname,
762 JACK_DEFAULT_AUDIO_TYPE,
763 JackPortIsOutput, 0);
764 if (output_port1 == NULL) {
765 printf("!!! ERROR !!! Can't register any port for the client !\n");
766 exit(1);
770 * Test port type of the just registered port.
773 if (strcmp(jack_port_type(output_port1), JACK_DEFAULT_AUDIO_TYPE) != 0) {
774 printf("!!! ERROR !!! jack_port_type returns an incorrect value!\n");
775 } else {
776 Log("Checking jack_port_type()... ok.\n");
780 * Try to register another port with the same name...
783 output_port2 = jack_port_register(client1, portname,
784 JACK_DEFAULT_AUDIO_TYPE,
785 JackPortIsOutput, 0);
786 if (output_port2 == NULL) {
787 Log("Can't register two ports with the same name... ok\n");
788 } else {
789 if (strcmp (jack_port_name(output_port1), jack_port_name(output_port2)) == 0) {
790 printf("!!! ERROR !!! Can register two ports with the same name ! (%px : %s & %px : %s).\n", output_port1, jack_port_name(output_port1), output_port2, jack_port_name(output_port2));
791 jack_port_unregister(client1, output_port2);
792 } else {
793 Log("Can't register two ports with the same name... ok (auto-rename %s into %s).\n", jack_port_name(output_port1), jack_port_name(output_port2));
794 jack_port_unregister(client1, output_port2);
799 * Verify that both port_name and port_short_name return correct results...
802 sprintf (portname, "%s:%s", jack_get_client_name(client1), jack_port_short_name(output_port1));
803 if (strcmp(jack_port_name(output_port1), portname) != 0) {
804 printf("!!! ERROR !!! functions jack_port_name and/or jack_short_port_name seems to be invalid !\n");
805 printf("client_name = %s\n short_port_name = %s\n port_name = %s\n", jack_get_client_name(client1), jack_port_short_name(output_port1), jack_port_name(output_port1));
809 * Verify the function port_set_name
812 if (jack_port_set_name (output_port1, "renamed-port#") == 0 ) {
813 if (strcmp(jack_port_name(output_port1), "renamed-port#") == 0) {
814 printf("!!! ERROR !!! functions jack_port_set_name seems to be invalid !\n");
815 printf("jack_port_name return '%s' whereas 'renamed-port#' was expected...\n", jack_port_name(output_port1));
816 } else {
817 Log("Checking jack_port_set_name()... ok\n");
818 jack_port_set_name (output_port1, "port");
820 } else {
821 printf("error : port_set_name function can't be tested...\n");
825 * Activate the client
828 if (jack_activate(client1) < 0) {
829 printf ("Fatal error : cannot activate client1\n");
830 exit(1);
834 * Test if portrename callback have been called.
837 jack_port_set_name (output_port1, "renamed-port#");
838 jack_sleep(1 * 1000);
840 if (port_rename_clbk == 0)
841 printf("!!! ERROR !!! Jack_Port_Rename_Callback was not called !!.\n");
844 * Test if init callback initThread have been called.
847 if (init_clbk == 0)
848 printf("!!! ERROR !!! Jack_Thread_Init_Callback was not called !!.\n");
850 jack_sleep(10 * 1000); // test see the clock in the graph at the begining...
853 * Stress Freewheel mode...
854 * Try to enter freewheel mode. Check the realtime mode de-activation.
855 * Check that the number of call of the process callback is greater than in non-freewheel mode.
856 * Give an approximated speed ratio (number of process call) between the two modes.
857 * Then return in normal mode.
859 t_error = 0;
860 activated = 0;
861 jack_sleep(1 * 1000);
862 count1 = activated;
863 Log("Testing activation freewheel mode...\n");
864 linefw = linecount; // count for better graph reading with gnuplot
865 jack_set_freewheel(client1, 1);
866 activated = 0;
867 jack_sleep(1 * 1000);
868 count2 = activated;
869 if (jack_is_realtime(client1) == 0) {
870 t_error = 0;
871 } else {
872 printf("\n!!! ERROR !!! RT mode is always activated while freewheel mode is applied !\n");
873 t_error = 1;
875 if (activated == 0)
876 printf("!!! ERROR !!! Freewheel mode doesn't activate audio callback !!\n");
878 jack_set_freewheel(client1, 0);
879 jack_sleep(7 * 1000);
881 if (jack_is_realtime(client1) == 1) {}
882 else {
883 printf("\n!!! ERROR !!! freewheel mode fail to reactivate RT mode when exiting !\n");
884 t_error = 1;
886 if (t_error == 0) {
887 Log("Freewheel mode appears to work well...\n");
889 if (count1 == 0) {
890 Log("Audio Callback in 'standard' (non-freewheel) mode seems not to be called...\n");
891 Log("Ratio speed would be unavailable...\n");
892 } else {
893 ratio = (float) ((count2 - count1) / count1);
894 Log("Approximative speed ratio of freewheel mode = %f : 1.00\n", ratio);
898 * Stress buffer function...
899 * get current buffer size.
900 * Try to apply a new buffer size value ( 2 x the precedent buffer size value)
901 * Then return in previous buffer size mode.
905 float factor = 0.5f;
906 old_buffer_size = jack_get_buffer_size(client1);
907 Log("Testing BufferSize change & Callback...\n--> Current buffer size : %i.\n", old_buffer_size);
908 linebuf = linecount;
909 if (jack_set_buffer_size(client1, (jack_nframes_t)(old_buffer_size * factor)) < 0) {
910 printf("!!! ERROR !!! jack_set_buffer_size fails !\n");
912 jack_sleep(1 * 1000);
913 cur_buffer_size = jack_get_buffer_size(client1);
914 if ((old_buffer_size * factor) != cur_buffer_size) {
915 printf("!!! ERROR !!! Buffer size has not been changed !\n");
916 printf("!!! Maybe jack was compiled without the '--enable-resize' flag...\n");
917 } else {
918 Log("jack_set_buffer_size() command successfully applied...\n");
920 jack_sleep(3 * 1000);
921 jack_set_buffer_size(client1, old_buffer_size);
922 cur_buffer_size = jack_get_buffer_size(client1);
925 * Test the last regestered port to see if port_is_mine function the right value.
926 * A second test will be performed later.
927 * The result will be printed at the end.
930 if (jack_port_is_mine(client1, output_port1)) {
931 is_mine = 1;
932 } else {
933 is_mine = 0;
937 * Check that the ID returned by the port_by_name is right.
938 * (it seems there is a problem here in some jack versions).
941 if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
942 printf("!!! ERROR !!! function jack_port_by_name() return bad value !\n");
943 printf("!!! jack_port_by_name(jack_port_name(_ID_) ) != _ID_returned_at_port_registering ! (%px != %px)\n", jack_port_by_name(client1, jack_port_name(output_port1)), output_port1);
944 } else {
945 Log("Checking jack_port_by_name() return value... ok\n");
947 if (NULL != jack_port_by_name(client1, jack_port_short_name(output_port1))) {
948 printf("!!! ERROR !!! function jack_port_by_name() return a value (%px) while name is incomplete !\n", jack_port_by_name(client1, jack_port_short_name(output_port1)));
949 } else {
950 Log("Checking jack_port_by_name() with bad argument... ok (returned id 0)\n");
954 * remove the output port previously created
955 * no more ports should subsist here for our client.
958 if (jack_port_unregister(client1, output_port1) != 0) {
959 printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
963 * list all in ports
966 inports = jack_get_ports(client1, NULL, NULL, 0);
969 * Test the first PHY (physical) connection to see if it's "mine".
970 * and report the result in the test that began before.
971 * The result is printed later.
974 if (jack_port_is_mine(client1, jack_port_by_name(client1, inports[0]))) {
975 is_mine = 0;
979 * List all devices' flags and print them...
982 Log("\nTry functions jack_get_ports, jack_port_flag & jack_port_by_name to list PHY devices...\n");
983 Log("-----------------------------------------------------------\n");
984 Log("---------------------------DEVICES-------------------------\n");
985 Log("-----------------------------------------------------------\n");
986 a = 0;
987 while (inports[a] != NULL) {
988 flag = jack_port_flags(jack_port_by_name(client1, inports[a]) );
989 Log(" * %s (id : %i)\n", inports[a], jack_port_by_name(client1, inports[a]));
990 Log(" (");
991 if (flag & JackPortIsInput)
992 Log("JackPortIsInput ");
993 if (flag & JackPortIsOutput)
994 Log("JackPortIsOutput ");
995 if (flag & JackPortIsPhysical)
996 Log("JackPortIsPhysical ");
997 if (flag & JackPortCanMonitor)
998 Log("JackPortCanMonitor ");
999 if (flag & JackPortIsTerminal)
1000 Log("JackPortIsTerminal ");
1001 Log(")\n\n");
1002 a++;
1004 Log("-----------------------------------------------------------\n\n");
1007 * list all PHY in/out ports...
1008 * This list will be used later many times.
1011 outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
1012 inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
1014 if (outports == NULL) {
1015 printf("!!! WARNING !!! no physical capture ports founded !\n");
1017 if (inports == NULL) {
1018 printf("!!! WARNING !!! no physical output ports founded !\n");
1022 * Brute test : try to create as many ports as possible.
1023 * It stops when jack returns an error.
1024 * Then try to connect each port to physical entry...
1025 * Check also that graph reorder callback is called.
1028 Log("Registering as many ports as possible and connect them to physical entries...\n");
1029 lineports = linecount;
1030 t_error = 0;
1032 i = 0; // number of couple 'input-ouput'
1033 j = 0; // number of ports created
1034 port_callback_reg = 0; // number of port registration received by the callback
1035 reorder = 0; // number of graph reorder callback activation
1036 test_link = 0 ; // Test the "overconnect" function only one time
1037 while (t_error == 0) {
1038 sprintf (portname, "input_%d", i);
1039 input_port1 = jack_port_register(client1, portname,
1040 JACK_DEFAULT_AUDIO_TYPE,
1041 JackPortIsInput, 0);
1042 j++;
1043 if (input_port1 == NULL) {
1044 j--;
1045 t_error = 1;
1046 } else {
1047 // Connect created input to PHY output
1048 a = 0;
1049 while (outports[a] != NULL) {
1050 if (jack_connect(client1, outports[a], jack_port_name(input_port1))) {
1051 printf ("error : cannot connect input PHY port to client port %s\n", jack_port_name(input_port1));
1052 } else {
1053 // printf ("input PHY port %s connected to client port %s\n", outports[a], jack_port_name(input_port1));
1055 a++;
1057 // Try one time to "overconnect" 2 ports (the latest created)...
1058 if (test_link == 0) {
1059 if (jack_connect(client1, outports[a - 1], jack_port_name(input_port1)) == EEXIST) {
1060 // cannot over-connect input PHY port to client port. ok.
1061 test_link = 1;
1066 sprintf(portname, "output_%d", i);
1067 output_port1 = jack_port_register(client1, portname,
1068 JACK_DEFAULT_AUDIO_TYPE,
1069 JackPortIsOutput, 0);
1070 j++;
1071 if (output_port1 == NULL) {
1072 t_error = 1;
1073 j--;
1074 } else {
1075 // Connect created input to PHY output
1076 a = 0;
1077 while (inports[a] != NULL) {
1078 if (jack_connect(client1, jack_port_name(output_port1), inports[a])) {
1079 printf ("error : cannot connect input PHY port %s to client port %s\n", inports[a], jack_port_name(output_port1));
1080 } else {
1081 // output PHY port %s connected to client port. ok.
1083 a++;
1085 // Try one time to "overconnect" 2 ports (the latest created)...
1086 if (test_link == 0) {
1087 if (jack_connect(client1, jack_port_name(output_port1), inports[a - 1]) == EEXIST) {
1088 // cannot over-connect output PHY port to client port. ok.
1089 test_link = 1;
1093 i++;
1096 jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
1097 if (j == port_callback_reg) {
1098 Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j, port_callback_reg);
1099 } else {
1100 printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j, k);
1102 if (reorder == (2 * j)) {
1103 Log("%i graph reorder callback have been received... ok\n", reorder);
1104 } else {
1105 printf("!!! ERROR !!! %i graph reorder callback have been received (maybe non-valid value)...\n", reorder);
1108 * print basic test connection functions result ...
1109 * over-connected means here that we try to connect 2 ports that are already connected.
1112 if (test_link) {
1113 Log("Jack links can't be 'over-connected'... ok\n");
1114 } else {
1115 printf("!!! ERROR !!! Jack links can be 'over-connected'...\n");
1118 * Print the result of the two jack_is_mine test.
1121 if (is_mine == 1) {
1122 Log("Checking jack_port_is_mine()... ok\n");
1123 } else {
1124 printf("!!! ERROR !!! jack_port_is_mine() function seems to send non-valid datas !\n");
1127 * Free the array of the physical input and ouput ports.
1128 * (as mentionned in the doc of jack_get_ports)
1131 free(inports);
1132 free(outports);
1135 * Try to "reactivate" the client whereas it's already activated...
1138 if (jack_activate(client1) < 0) {
1139 printf("!!! ERROR !!! Cannot activate client1 a second time...\n");
1140 exit(1);
1141 } else {
1142 Log("jackd server accept client.jack_activate() re-activation (while client was already activated).\n");
1146 * Deregister all ports previously created.
1149 Log("Deregistering all ports of the client...\n");
1150 inports = jack_get_ports(client1, NULL, NULL, 0);
1151 a = 0;
1152 while (inports[a] != NULL) {
1153 flag = jack_port_flags(jack_port_by_name(client1, inports[a]));
1154 input_port1 = jack_port_by_name(client1, inports[a]);
1155 if (jack_port_is_mine(client1, input_port1)) {
1156 if (jack_port_unregister(client1, input_port1) != 0) {
1157 printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
1160 a++;
1163 free(inports); // free array of ports (as mentionned in the doc of jack_get_ports)
1166 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1167 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1168 Open a new client (second one) to test some other things...
1169 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1170 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1173 Log("\n\n----------------------------------------------------------------------\n");
1174 Log("Starting second new client 'jack_test_#2'...\n");
1175 /* open a client connection to the JACK server */
1176 client_name2 = "jack_test_#2";
1177 linecl2 = linecount; // reminders for graph analysis
1178 client2 = jack_client_new(client_name2);
1180 if (client2 == NULL) {
1181 fprintf(stderr, "jack_client_new() failed for %s.\n"
1182 "status = 0x%2.0x\n", client_name2, status);
1183 if (status & JackServerFailed) {
1184 fprintf(stderr, "Unable to connect client2 to JACK server\n");
1186 exit(1);
1189 // Check client registration callback
1190 jack_sleep(1000);
1191 if (client_register == 0)
1192 printf("!!! ERROR !!! Client registration callback not called!\n");
1195 * Register callback for this client.
1196 * Callbacks are the same as the first client for most of them, excepted for process audio callback.
1199 jack_set_port_registration_callback(client2, Jack_Port_Register, 0);
1201 jack_set_process_callback(client2, process2, 0);
1203 jack_on_shutdown(client2, jack_shutdown, 0);
1206 * Register one input and one output for each client.
1209 Log("registering 1 input/output ports for each client...\n");
1211 output_port1 = jack_port_register(client1, "out1",
1212 JACK_DEFAULT_AUDIO_TYPE,
1213 JackPortIsOutput, 0);
1214 output_port2 = jack_port_register(client2, "out2",
1215 JACK_DEFAULT_AUDIO_TYPE,
1216 JackPortIsOutput, 0);
1217 input_port1 = jack_port_register(client1, "in1",
1218 JACK_DEFAULT_AUDIO_TYPE,
1219 JackPortIsInput, 0);
1220 input_port2 = jack_port_register(client2, "in2",
1221 JACK_DEFAULT_AUDIO_TYPE,
1222 JackPortIsInput, 0);
1223 if ((output_port1 == NULL) || (output_port2 == NULL) || (input_port1 == NULL) || (input_port2 == NULL)) {
1224 printf("!!! ERROR !!! Unable to register ports...\n");
1228 * Set each process mode to idle and activate client2
1231 process2_activated = -1;
1232 process1_activated = -1;
1233 if (jack_activate(client2) < 0) {
1234 printf ("Fatal error : cannot activate client2\n");
1235 exit (1);
1239 * Connect the two clients and check that all connections are well-done.
1242 Log("Testing connections functions between clients...\n");
1243 if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
1244 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1246 if (jack_connect(client2, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
1247 printf("!!! ERROR !!! while client2 intenting to connect ports...\n");
1249 if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
1250 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1254 * Test the port_connected function...
1257 if ((jack_port_connected(output_port1) == jack_port_connected(input_port1)) &&
1258 (jack_port_connected(output_port2) == jack_port_connected(input_port2)) &&
1259 (jack_port_connected(output_port2) == 1) &&
1260 (jack_port_connected(output_port1) == 2)
1262 Log("Checking jack_port_connected()... ok.\n");
1263 } else {
1264 printf("!!! ERROR !!! function jack_port_connected() return a bad value !\n");
1265 printf("jack_port_connected(output_port1) %d\n", jack_port_connected(output_port1));
1266 printf("jack_port_connected(output_port2) %d\n", jack_port_connected(output_port2));
1267 printf("jack_port_connected(input_port1) %d\n", jack_port_connected(input_port1));
1268 printf("jack_port_connected(input_port2) %d\n", jack_port_connected(input_port2));
1272 * Test a new time the port_by_name function...(now we are in multi-client mode)
1275 Log("Testing again jack_port_by_name...\n");
1276 if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
1277 printf("!!! ERROR !!! function jack_port_by_name() return bad value in a multi-client application!\n");
1278 printf("!!! jack_port_by_name(jack_port_name(_ID_) ) != _ID_ in multiclient application.\n");
1279 } else {
1280 Log("Checking jack_port_by_name() function with a multi-client application... ok\n");
1284 * Test the port_connected_to function...
1287 if ((jack_port_connected_to (output_port1, jack_port_name(input_port2))) &&
1288 (!(jack_port_connected_to (output_port2, jack_port_name(input_port2))))) {
1289 Log("checking jack_port_connected_to()... ok\n");
1290 } else {
1291 printf("!!! ERROR !!! jack_port_connected_to() return bad value !\n");
1295 * Test the port_get_connections & port_get_all_connections functions...
1298 Log("Testing jack_port_get_connections and jack_port_get_all_connections...\n");
1299 a = 0;
1300 t_error = 0;
1301 connexions1 = jack_port_get_connections (output_port1);
1302 connexions2 = jack_port_get_all_connections(client1, output_port1);
1303 if ((connexions1 == NULL) || (connexions2 == NULL)) {
1304 printf("!!! ERROR !!! port_get_connexions or port_get_all_connexions return a NULL pointer !\n");
1305 } else {
1306 while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
1307 t_error = strcmp(connexions1[a], connexions2[a]);
1308 a++;
1311 if (t_error == 0) {
1312 Log("Checking jack_port_get_connections Vs jack_port_get_all_connections... ok\n");
1313 } else {
1314 printf("!!! ERROR !!! while checking jack_port_get_connections Vs jack_port_get_all_connections...\n");
1317 a = 0;
1318 t_error = 0;
1319 inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
1320 connexions1 = NULL;
1321 assert(inports != NULL);
1322 if (inports[0] != NULL) {
1323 connexions1 = jack_port_get_connections (jack_port_by_name(client1, inports[0]));
1324 connexions2 = jack_port_get_all_connections(client1, jack_port_by_name(client1, inports[0]));
1327 free (inports);
1328 if (connexions1 == NULL) {
1329 Log("checking jack_port_get_connections() for external client... ok\n");
1330 } else {
1331 while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
1332 t_error = strcmp(connexions1[a], connexions2[a]);
1333 a++;
1336 if (t_error == 0) {
1337 Log("Checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port... ok\n");
1338 } else {
1339 printf("!!! ERROR !!! while checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port...\n");
1342 if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
1343 printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
1345 if (jack_disconnect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
1346 printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
1348 // No links should subsist now...
1351 * Checking data connexion
1352 * establishing a link between client1.out1 --> client2.in2
1353 * Send the signal1 test on out1. Record the result into signal2. (see process functions).
1354 ---------------------------------------------------------------------------*/
1355 Log("Testing connections datas between clients...\n");
1356 jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2) );
1357 process2_activated = -1;
1358 process1_activated = -1;
1359 Log("process 2 : idle mode...\n");
1360 Log("Sending datas...");
1361 index1 = 0;
1362 index2 = 0;
1363 process1_activated = 1; // We start emitting first.
1364 process2_activated = 1; // So record begin at least when we just begin to emitt the signal, else at next call of process with
1365 // nframe = jack buffersize shifting.
1367 while (process2_activated == 1) {
1368 jack_sleep(1 * 1000);
1369 Log(".");
1371 index2 = 0;
1372 Log("\nAnalysing datas...\n"); // search the first occurence of the first element of the reference signal in the recorded signal
1373 while (signal2[index2] != signal1[1] ) {
1374 index2++;
1375 if (index2 == 95999) {
1376 printf("!!! ERROR !!! Data not found in first connexion data check!\n");
1377 break;
1380 index1 = index2;
1381 Log("Data founded at offset %i.\n", index2);
1382 // And now we founded were the recorded data are, we can see if the two signals matches...
1383 while ( (signal2[index2] == signal1[index2 - index1 + 1]) || (index2 == 95999) || ((index2 - index1 + 1) == 47999) ) {
1384 index2++;
1386 Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
1387 if ((index2 - index1) == 48000) {
1388 Log("Data received are valid...\n");
1389 } else {
1390 printf("!!! ERROR !!! data transmission seems not to be valid in first connexion data check!\n");
1392 if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port2) ) != 0)
1393 // no more connection between ports exist now...
1395 printf("Error while establishing new connexion (disconnect).\n");
1399 * Test TIE MODE
1400 * (This mode seems to be problematic in standard jack version 0.100. It seems that nobody
1401 * is used to apply this mode because the tie mode doesn't work at all. A patch seems difficult to produce
1402 * in this version of jack. Tie mode work well in MP version.)
1403 * Test some basic thinks (tie with 2 differents client, tie non-owned ports...)
1404 * Tie client1.in1 and client1.out1 ports, and make some data test to check the validity of the tie.
1407 Log("Testing tie mode...\n");
1408 if (jack_port_tie(input_port1, output_port2) != 0) {
1409 Log("not possible to tie two ports from two differents clients... ok\n");
1410 } else {
1411 printf("!!! ERROR !!! port_tie has allowed a connexion between two differents clients !\n");
1412 jack_port_untie(output_port2);
1414 Log("Testing connections datas in tie mode...\n");
1415 int g;
1416 for (g = 0; g < 96000; g++)
1417 signal2[g] = 0.0;
1418 // Create a loop (emit test) client2.out2----client.in1--tie--client1.out1-----client2.in1 (receive test)
1419 if (jack_port_tie(input_port1, output_port1) != 0) {
1420 printf("Unable to tie... fatal error : data test will not be performed on tie mode !!\n");
1421 } else { // begin of tie
1422 if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
1423 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1425 if (jack_connect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
1426 printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
1429 process1_activated = -1;
1430 process2_activated = -1;
1432 // We can manualy check here that the tie is effective.
1433 // ie : playing a wav with a client, connecting ports manualy with qjackctl, and listen...
1434 // printf("manual test\n");
1435 // jack_sleep(50);
1436 // printf("end of manual test\n");
1438 index1 = 0;
1439 index2 = 0;
1440 process1_activated = -1;
1441 process2_activated = 2;
1443 Log("Sending datas...");
1445 while (process2_activated == 2) {
1446 jack_sleep(1 * 1000);
1447 Log(".");
1449 process1_activated = -1;
1450 process2_activated = -1;
1451 index2 = 0;
1452 Log("\nAnalysing datas...\n");
1453 // We must find at least 2 identical values to ensure we are at the right place in the siusoidal array...
1454 while (!((signal2[index2] == signal1[1]) && (signal2[index2 + 1] == signal1[2]))) {
1455 index2++;
1456 if (index2 == 95999) {
1457 printf("!!! ERROR !!! Data not found in connexion check of tie mode!\n");
1458 break;
1461 index1 = index2;
1462 Log("Tie mode : Data founded at offset %i.\n", index2);
1463 while (signal2[index2] == signal1[index2 - index1 + 1]) {
1464 index2++;
1465 if ((index2 == 95999) || ((index2 - index1 + 1) == 47999)) {
1466 break;
1469 Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
1470 if ((index2 - index1) > 47995) {
1471 Log("Data received in tie mode are valid...\n");
1472 } else {
1473 // in tie mode, the buffers adress should be the same for the two tied ports.
1474 printf("!!! ERROR !!! data transmission seems not to be valid !\n");
1475 printf("Links topology : (emitt) client2.out2 ----> client1.in1--(tie)--client1.out1----->client2.in2 (recive)\n");
1476 printf(" port_name : Port_adress \n");
1477 printf(" output_port1 : %px\n", jack_port_get_buffer(output_port1, cur_buffer_size));
1478 printf(" input_port2 : %px\n", jack_port_get_buffer(input_port2, cur_buffer_size));
1479 printf(" output_port2 : %px\n", jack_port_get_buffer(output_port2, cur_buffer_size));
1480 printf(" input_port1 : %px\n", jack_port_get_buffer(input_port1, cur_buffer_size));
1483 jack_port_untie(output_port1);
1484 jack_port_disconnect(client1, output_port2);
1485 jack_port_disconnect(client1, output_port1);
1487 } //end of tie
1491 * Testing SUMMATION CAPABILITIES OF JACK CONNECTIONS
1493 * In a short test, we just check a simple summation in jack.
1494 * A first client(client1) send two signal in phase opposition
1495 * A second client(client2) record the summation at one of his port
1496 * So, the result must be zero...
1497 * See process1 for details about steps of this test
1500 // fprintf(file, "Sum test\n");
1501 Log("Checking summation capabilities of patching...\n");
1502 output_port1b = jack_port_register(client1, "out1b",
1503 JACK_DEFAULT_AUDIO_TYPE,
1504 JackPortIsOutput, 0);
1505 jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2));
1506 jack_connect(client2, jack_port_name(output_port1b), jack_port_name(input_port2));
1508 process1_activated = 3;
1509 process2_activated = -1;
1510 for (g = 0; g < 96000; g++)
1511 signal2[g] = 0.0;
1512 index1 = 0;
1513 index2 = 0;
1515 Log("Sending datas...");
1516 process2_activated = 3;
1518 while (process2_activated == 3) {
1519 jack_sleep(1 * 1000);
1520 Log(".");
1522 process1_activated = -1;
1523 process2_activated = -1;
1524 index2 = 0;
1525 Log("\nAnalysing datas...\n"); // same idea as above, with first data check...
1526 while (!((signal2[index2] == 0.0 ) && (signal2[(index2 + 1)] == 0.0 ))) {
1527 index2++;
1528 if (index2 == 95999) {
1529 printf("!!! ERROR !!! Data not found in summation check!\n");
1530 break;
1533 index1 = index2;
1534 Log("Data founded at offset %i.\n", index2);
1536 while ( signal2[index2] == 0.0 ) {
1537 index2++;
1538 if ((index2 > 95998) || ((index2 - index1 + 1) > 47998)) {
1539 break;
1542 Log("Checking difference between datas...\n");
1543 if ((index2 - index1) > 47996) {
1544 Log("Data mixed received are valid...\nSummation is well done.\n");
1545 } else {
1546 printf("!!! ERROR !!! data transmission / summation seems not to be valid !\n");
1548 jack_port_disconnect(client1, output_port1);
1549 jack_port_disconnect(client1, output_port1b);
1550 jack_port_unregister(client1, output_port1b);
1552 if (jack_port_name(output_port1b) != NULL ) {
1553 printf("!!! WARNING !!! port_name return something while the port have been unregistered !\n");
1554 printf("!!! Name of unregistered port : %s !\n", jack_port_name(output_port1b));
1555 } else {
1556 Log("Checking jack_port_name() with a non valid port... ok\n");
1559 if (jack_port_set_name(output_port1b, "new_name") == 0 ) {
1560 printf("!!! WARNING !!! An unregistered port can be renamed successfully !\n");
1561 } else {
1562 Log("Checking renaming of an unregistered port... ok\n");
1564 inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
1565 if (jack_port_set_name(jack_port_by_name(client1, inports[0]), "new_name") == 0 ) {
1566 printf("!!! WARNING !!! A PHYSICAL port can be renamed successfully !\n");
1567 } else {
1568 Log("Checking renaming of an unregistered port... ok\n");
1570 free (inports);
1574 * Checking latency issues
1575 * here are simple latency check
1576 * We simply check that the value returned by jack seems ok
1577 * Latency compensation is a difficult point.
1578 * Actually, jack is not able to see "thru" client to build a full latency chain.
1579 * Ardour use theses informations to do internally his compensations.
1581 * 3 test are done : one with no connections between client, one with a serial connection, and one with parallel connection
1583 Log("Checking about latency functions...\n");
1584 t_error = 0;
1585 jack_recompute_total_latencies(client1);
1586 if ((jack_port_get_latency (output_port1) != 0) ||
1587 (jack_port_get_total_latency(client1, output_port1) != 0) ) {
1588 t_error = 1;
1589 printf("!!! ERROR !!! default latency of a non-PHY device is not set to zero !\n");
1592 inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
1593 outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
1594 if (inports[0] != NULL) {
1595 output_ext_latency = jack_port_get_latency (jack_port_by_name(client1, inports[0])); // from client to out driver (which has "inputs" ports..)
1596 input_ext_latency = jack_port_get_latency (jack_port_by_name(client1, outports[0])); // from in driver (which has "output" ports..) to client
1597 if (output_ext_latency != jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0]))) {
1598 t_error = 1;
1599 printf("!!! ERROR !!! get_latency & get_all_latency for a PHY device (unconnected) didn't return the same value !\n");
1601 Log("Checking a serial model with 2 clients...\n");
1603 jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2));
1604 jack_connect(client1, outports[0], jack_port_name(input_port1));
1605 jack_connect(client2, jack_port_name(output_port2), inports[0]);
1606 jack_port_set_latency(output_port2, 256);
1607 jack_recompute_total_latencies(client1);
1609 if ((jack_port_get_latency (output_port1) != 0) ||
1610 (jack_port_get_total_latency(client1, output_port1) != 0) ||
1611 (jack_port_get_latency (jack_port_by_name(client1, inports[0])) != (output_ext_latency)) ||
1612 (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (output_ext_latency + 256)) ||
1613 (jack_port_get_total_latency(client1, output_port2) != (output_ext_latency + 256)) ||
1614 (jack_port_get_total_latency(client1, input_port2) != 0) ||
1615 (jack_port_get_total_latency(client1, input_port1) != input_ext_latency) ||
1616 (jack_port_get_latency (jack_port_by_name(client1, outports[0])) != input_ext_latency) ||
1617 (jack_port_get_total_latency(client1, jack_port_by_name(client1, outports[0])) != input_ext_latency)
1619 printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
1620 printf("!!! get_latency(output_port1) : %i (must be 0)\n", jack_port_get_latency(output_port1));
1621 printf("!!! get_total_latency(output_port1) : %i (must be 0)\n", jack_port_get_total_latency(client1, output_port1));
1622 printf("!!! get_latency(PHY[0]) : %i (must be external latency : %i)\n", jack_port_get_latency(jack_port_by_name(client1, inports[0])), output_ext_latency);
1623 printf("!!! get_total_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) , (output_ext_latency + 256));
1624 printf("!!! get_total_latency(output_port2) : %i (must be %i)\n", jack_port_get_total_latency(client1, output_port2), (output_ext_latency + 256));
1625 printf("!!! get_total_latency(input_port2) : %i (must be 0)\n", jack_port_get_total_latency(client1, input_port2));
1626 printf("!!! get_total_latency(input_port1) : %i (must be %i)\n", jack_port_get_total_latency(client1, input_port1), input_ext_latency);
1627 printf("!!! get_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_latency(jack_port_by_name(client1, outports[0])), input_ext_latency);
1628 printf("!!! get_total_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_total_latency(client1, jack_port_by_name(client1, outports[0])), input_ext_latency);
1630 } else {
1631 Log("get_latency & get_total_latency seems quite ok...\n");
1634 jack_port_disconnect(client1, output_port1);
1635 jack_port_disconnect(client1, output_port2);
1636 jack_port_disconnect(client1, input_port1);
1637 jack_port_disconnect(client1, input_port2);
1638 Log("Checking a parallel model with 2 clients...\n");
1639 jack_connect(client2, outports[0], jack_port_name(input_port1));
1640 jack_connect(client2, outports[0], jack_port_name(input_port2));
1641 jack_connect(client2, jack_port_name(output_port1), inports[0]);
1642 jack_connect(client2, jack_port_name(output_port2), inports[0]);
1643 jack_port_set_latency(output_port1, 256);
1644 jack_port_set_latency(output_port2, 512);
1645 jack_recompute_total_latencies(client1);
1647 if ((jack_port_get_latency(output_port1) != 256 ) ||
1648 (jack_port_get_total_latency(client1, output_port1) != (256 + output_ext_latency)) ||
1649 (jack_port_get_latency(output_port2) != 512) ||
1650 (jack_port_get_total_latency(client1, output_port2) != (512 + output_ext_latency)) ||
1651 (jack_port_get_latency(jack_port_by_name(client1, inports[0])) != output_ext_latency) ||
1652 (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (512 + output_ext_latency))
1654 printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
1655 printf("!!! get_latency(output_port1) : %i (must be 256)\n", jack_port_get_latency(output_port1));
1656 printf("!!! get_total_latency(output_port1) : %i (must be 256 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port1));
1657 printf("!!! get_latency(output_port2) : %i (must 512)\n", jack_port_get_latency(output_port2));
1658 printf("!!! get_total_latency(output_port2) : %i (must 512 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port2));
1659 printf("!!! get_latency(inports[0])) : %i (must output_ext_latency)\n", jack_port_get_latency(jack_port_by_name(client1, inports[0])));
1660 printf("!!! get_total_latency(inports[0]) : %i (must 512 + output_ext_latency)\n", jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])));
1661 } else {
1662 Log("get_latency & get_total_latency seems quite ok...\n");
1664 } else {
1665 printf("No physical port founded : not able to test latency functions...");
1668 jack_port_disconnect(client1, input_port1);
1669 jack_port_disconnect(client1, input_port2);
1670 jack_port_disconnect(client1, output_port1);
1671 jack_port_disconnect(client1, output_port2);
1673 jack_sleep(1000);
1675 free(inports);
1676 free(outports);
1679 * Checking transport API.
1680 * Simple transport test.
1681 * Check a transport start with a "slow" client, simulating a delay around 1 sec before becoming ready.
1684 Log("-----------------------------------------------------------\n");
1685 Log("---------------------------TRANSPORT-----------------------\n");
1686 Log("-----------------------------------------------------------\n");
1688 lineports = linecount;
1690 if (transport_mode) {
1691 int wait_count;
1692 ts = jack_transport_query(client1, &pos);
1693 if (ts == JackTransportStopped) {
1694 Log("Transport is stopped...\n");
1695 } else {
1696 jack_transport_stop(client1);
1697 Log("Transport state : %i\n", ts);
1699 if (jack_set_sync_callback(client2, Jack_Sync_Callback, 0) != 0)
1700 printf("error while calling set_sync_callback...\n");
1702 Log("starting transport...\n");
1704 starting_state = 1; // Simulate starting state
1705 jack_transport_start(client1);
1707 // Wait until sync callback is called
1708 while (!(sync_called)) {
1709 jack_sleep(1 * 1000);
1712 // Wait untill rolling : simulate sync time out
1713 Log("Simulate a slow-sync client exceeding the time-out\n");
1714 wait_count = 0;
1716 do {
1717 jack_sleep(100); // Wait 100 ms each cycle
1718 wait_count++;
1719 if (wait_count == 100) {
1720 Log("!!! ERROR !!! max time-out exceedeed : sync time-out does not work correctly\n");
1721 break;
1723 ts = jack_transport_query(client2, &pos);
1724 Log("Waiting....pos = %ld\n", pos.frame);
1725 display_transport_state();
1727 } while (ts != JackTransportRolling);
1729 Log("Sync callback have been called %i times.\n", sync_called);
1730 jack_transport_stop(client1);
1732 // Wait until stopped
1733 ts = jack_transport_query(client2, &pos);
1734 while (ts != JackTransportStopped) {
1735 jack_sleep(1 * 1000);
1736 ts = jack_transport_query(client2, &pos);
1739 // Simulate starting a slow-sync client that rolls after 0.5 sec
1740 Log("Simulate a slow-sync client that needs 0.5 sec to start\n");
1741 sync_called = 0;
1742 wait_count = 0;
1743 starting_state = 1; // Simulate starting state
1745 Log("Starting transport...\n");
1746 jack_transport_start(client1);
1747 display_transport_state();
1749 Log("Waiting 0.5 sec...\n");
1750 jack_sleep(500);
1751 starting_state = 0; // Simulate end of starting state after 0.5 sec
1753 // Wait untill rolling
1754 ts = jack_transport_query(client2, &pos);
1755 while (ts != JackTransportRolling) {
1756 jack_sleep(100); // Wait 100 ms each cycle
1757 wait_count++;
1758 if (wait_count == 10) {
1759 Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
1760 break;
1762 ts = jack_transport_query(client2, &pos);
1765 if (sync_called == 0)
1766 Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
1768 Log("Sync callback have been called %i times.\n", sync_called);
1769 display_transport_state();
1771 // Test jack_transport_locate while rolling
1772 Log("Test jack_transport_locate while rolling\n");
1773 ts = jack_transport_query(client2, &pos);
1774 Log("Transport current frame = %ld\n", pos.frame);
1775 jack_nframes_t cur_frame = pos.frame;
1777 wait_count = 0;
1778 do {
1779 display_transport_state();
1780 jack_sleep(10); // 10 ms
1781 // locate at first...
1782 wait_count++;
1783 if (wait_count == 1) {
1784 Log("Do jack_transport_locate\n");
1785 jack_transport_locate(client1, cur_frame / 2);
1786 } else if (wait_count == 100) {
1787 break;
1789 ts = jack_transport_query(client2, &pos);
1790 Log("Locating.... frame = %ld\n", pos.frame);
1791 } while (pos.frame > cur_frame);
1793 ts = jack_transport_query(client2, &pos);
1794 Log("Transport current frame = %ld\n", pos.frame);
1795 if (wait_count == 100) {
1796 printf("!!! ERROR !!! jack_transport_locate does not work correctly\n");
1799 // Test jack_transport_reposition while rolling
1800 Log("Test jack_transport_reposition while rolling\n");
1801 ts = jack_transport_query(client2, &pos);
1802 Log("Transport current frame = %ld\n", pos.frame);
1803 cur_frame = pos.frame;
1805 wait_count = 0;
1806 do {
1807 display_transport_state();
1808 jack_sleep(10); // 10 ms
1809 // locate at first...
1810 wait_count++;
1811 if (wait_count == 1) {
1812 Log("Do jack_transport_reposition\n");
1813 request_pos.frame = cur_frame / 2;
1814 jack_transport_reposition(client1, &request_pos);
1815 } else if (wait_count == 100) {
1816 break;
1818 ts = jack_transport_query(client2, &pos);
1819 Log("Locating.... frame = %ld\n", pos.frame);
1820 } while (pos.frame > cur_frame);
1822 ts = jack_transport_query(client2, &pos);
1823 Log("Transport current frame = %ld\n", pos.frame);
1824 if (wait_count == 100) {
1825 printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
1828 // Test jack_transport_reposition while stopped
1829 jack_transport_stop(client1);
1830 ts = jack_transport_query(client2, &pos);
1831 Log("Transport current frame = %ld\n", pos.frame);
1833 Log("Test jack_transport_reposition while stopped\n");
1834 wait_count = 0;
1835 request_pos.frame = 10000;
1836 jack_transport_reposition(client1, &request_pos);
1838 do {
1839 display_transport_state();
1840 jack_sleep(100); // 100 ms
1841 if (wait_count++ == 10)
1842 break;
1843 ts = jack_transport_query(client2, &pos);
1844 Log("Locating.... frame = %ld\n", pos.frame);
1845 } while (pos.frame != 10000);
1847 ts = jack_transport_query(client2, &pos);
1848 Log("Transport current frame = %ld\n", pos.frame);
1849 if (pos.frame != 10000) {
1850 printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
1853 jack_transport_stop(client1);
1855 /* Tell the JACK server that we are ready to roll. Our
1856 * process() callback will start running now. */
1858 } else {
1859 printf("Transport check is disabled...\n");
1862 time_before_exit = time_to_run;
1863 while (time_before_exit != 0) {
1864 jack_sleep (1 * 1000);
1865 time_before_exit--;
1868 if (jack_deactivate(client2) != 0) {
1869 printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
1871 if (jack_deactivate(client1) != 0) {
1872 printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
1876 * Checking jack_frame_time.
1878 Log("Testing jack_frame_time...\n");
1879 jack_set_process_callback(client1, process4, client1);
1880 jack_activate(client1);
1881 jack_sleep(2 * 1000);
1885 * Checking alternate thread model
1887 Log("Testing alternate thread model...\n");
1888 jack_deactivate(client1);
1889 jack_set_process_callback(client1, NULL, NULL); // remove callback
1890 jack_set_process_thread(client1, jack_thread, client1);
1891 jack_activate(client1);
1892 jack_sleep(2 * 1000);
1895 * Checking callback exiting : when the return code is != 0, the client is desactivated.
1897 Log("Testing callback exiting...\n");
1898 jack_deactivate(client1);
1899 jack_set_process_thread(client1, NULL, NULL); // remove thread callback
1900 jack_set_process_callback(client1, process3, 0);
1901 jack_activate(client1);
1902 jack_sleep(3 * 1000);
1905 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1906 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1907 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1908 Closing program
1909 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1910 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1911 *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
1914 if (jack_deactivate(client2) != 0) {
1915 printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
1917 if (jack_deactivate(client1) != 0) {
1918 printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
1920 if (jack_client_close(client2) != 0) {
1921 printf("!!! ERROR !!! jack_client_close does not return 0 for client2 !\n");
1923 if (jack_client_close(client1) != 0) {
1924 printf("!!! ERROR !!! jack_client_close does not return 0 for client1 !\n");
1927 if (xrun == 0) {
1928 Log("No Xrun have been detected during this test... cool !\n");
1929 } else {
1930 printf("%i Xrun have been detected during this session (seen callback messages to see where are the problems).\n", xrun);
1932 free(framecollect);
1933 free(signal1);
1934 free(signal2);
1935 Log("Exiting jack_test...\n");
1936 fclose(file);
1937 printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
1938 sprintf (filename, "framegraph-%i.gnu", cur_buffer_size);
1939 file = fopen(filename, "w");
1940 if (file == NULL) {
1941 fprintf(stderr, "Erreur dans l'ouverture du fichier");
1942 exit( -1);
1944 fprintf(file, "reset\n");
1945 fprintf(file, "set terminal png transparent nocrop enhanced\n");
1946 fprintf(file, "set output 'framegraph-%i-1.png'\n", cur_buffer_size);
1947 fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
1948 fprintf(file, "set yrange [ %i.00000 : %i.0000 ] noreverse nowriteback\n", cur_buffer_size - (cur_buffer_size / 8), cur_buffer_size + (cur_buffer_size / 8));
1949 fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
1950 fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
1951 fprintf(file, "set xlabel \"FrameTime\"\n");
1952 fprintf(file, "set label \"| buf.siz:%i | fr.wl:%i | rg.ports:%i | 2nd.client:%i | trsprt:%i |\" at graph 0.01, 0.04\n", linebuf, linefw, lineports, linecl2, linetransport);
1953 fprintf(file, "plot 'framefile-%i.dat' using 2 with impulses title \"Xruns\",'framefile-%i.dat' using 1 with line title \"Sampletime variation at %i\"\n", cur_buffer_size, cur_buffer_size, cur_buffer_size);
1955 fprintf(file, "set output 'framegraph-%i-2.png'\n", cur_buffer_size);
1956 fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
1957 fprintf(file, "set yrange [ %i.00000 : %i.0000 ] noreverse nowriteback\n", (int) (cur_buffer_size / 2), (int) (2*cur_buffer_size + (cur_buffer_size / 8)));
1958 fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
1959 fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
1960 fprintf(file, "set xlabel \"FrameTime\"\n");
1961 fprintf(file, "set label \"| buf.siz:%i | fr.wl:%i | rg.ports:%i | 2nd.client:%i | trsprt:%i |\" at graph 0.01, 0.04\n", linebuf, linefw, lineports, linecl2, linetransport);
1962 fprintf(file, "plot 'framefile-%i.dat' using 2 with impulses title \"Xruns\",'framefile-%i.dat' using 1 with line title \"Sampletime variation at %i\"\n", cur_buffer_size, cur_buffer_size, cur_buffer_size);
1963 fclose(file);
1964 return 0;