jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2151 lines
84KB

  1. /*
  2. Copyright (C) 2005 Samuel TRACOL for GRAME
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. /** @file jack_test.c
  16. *
  17. * @brief This client test the jack API.
  18. *
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <errno.h>
  23. #ifndef WIN32
  24. #include <unistd.h>
  25. #endif
  26. #include <string.h>
  27. #include <getopt.h>
  28. #include <math.h>
  29. #include <assert.h>
  30. #include <stdarg.h>
  31. #include <jack/jack.h>
  32. #include <jack/intclient.h>
  33. #include <jack/transport.h>
  34. #if defined(WIN32) && !defined(M_PI)
  35. #define M_PI 3.151592653
  36. #endif
  37. #ifdef WIN32
  38. #define jack_sleep(val) Sleep((val))
  39. #else
  40. #define jack_sleep(val) usleep((val) * 1000)
  41. #endif
  42. typedef struct
  43. {
  44. jack_nframes_t ft; // running counter frame time
  45. jack_nframes_t fcs; // from sycle start...
  46. jack_nframes_t lft; // last frame time...
  47. }
  48. FrameTimeCollector;
  49. FILE *file;
  50. FrameTimeCollector* framecollect;
  51. FrameTimeCollector perpetualcollect;
  52. FrameTimeCollector lastperpetualcollect;
  53. int frames_collected = 0;
  54. // ports
  55. jack_port_t *output_port1;
  56. jack_port_t *output_port1b;
  57. jack_port_t *input_port2;
  58. jack_port_t *output_port2;
  59. jack_port_t *input_port1;
  60. // clients
  61. jack_client_t *client1;
  62. jack_client_t *client2;
  63. const char *client_name1;
  64. const char *client_name2;
  65. unsigned long sr; // sample rate
  66. // for time -t option
  67. int time_to_run = 0;
  68. int time_before_exit = 1;
  69. // standard error count
  70. int t_error = 0;
  71. int reorder = 0; // graph reorder callback
  72. int RT = 0; // is real time or not...
  73. int FW = 0; // freewheel mode
  74. int init_clbk = 0; // init callback
  75. int port_rename_clbk = 0; // portrename callback
  76. int i, j, k = 0;
  77. int port_callback_reg = 0;
  78. jack_nframes_t cur_buffer_size, old_buffer_size, cur_pos;
  79. int activated = 0;
  80. int count1, count2 = 0; // for freewheel
  81. int xrun = 0;
  82. int have_xrun = 0; // msg to tell the process1 function to write a special thing in the frametime file.
  83. int process1_activated = -1; // to control processing...
  84. int process2_activated = -1; // to control processing...
  85. unsigned long int index1 = 0;
  86. unsigned long int index2 = 0;
  87. jack_default_audio_sample_t *signal1; // signal source d'emission
  88. jack_default_audio_sample_t *signal2; // tableau de reception
  89. jack_transport_state_t ts;
  90. jack_position_t pos;
  91. jack_position_t request_pos;
  92. int silent_error = 0; // jack silent mode
  93. int verbose_mode = 0;
  94. int transport_mode = 1;
  95. jack_nframes_t input_ext_latency = 0; // test latency for PHY devices
  96. jack_nframes_t output_ext_latency = 0; // test latency for PHY devices
  97. int sync_called = 0;
  98. int starting_state = 1;
  99. int linecount = 0; // line counter for log file of sampleframe counter --> for graph function.
  100. int linebuf = 0; // reminders for graph analysis
  101. int linetransport = 0;
  102. int linefw = 0;
  103. int lineports = 0;
  104. int linecl2 = 0;
  105. int client_register = 0;
  106. /**
  107. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  108. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  109. Callbacks & basics functions
  110. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  111. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  112. */
  113. void usage()
  114. {
  115. fprintf (stderr, "\n\n"
  116. "usage: jack_test \n"
  117. " [ --time OR -t time_to_run (in seconds) ]\n"
  118. " [ --quiet OR -q (quiet mode : without jack server errors) ]\n"
  119. " [ --verbose OR -v (verbose mode : no details on tests done. Only main results & errors) ]\n"
  120. " [ --transport OR -k (Do not test transport functions.) ]\n"
  121. " --realtime OR -R (jack is in rt mode)\n\n\n"
  122. );
  123. exit(1);
  124. }
  125. void Log(const char *fmt, ...)
  126. {
  127. if (verbose_mode) {
  128. va_list ap;
  129. va_start(ap, fmt);
  130. vfprintf(stderr, fmt, ap);
  131. va_end(ap);
  132. }
  133. }
  134. void Collect(FrameTimeCollector* TheFrame)
  135. {
  136. TheFrame->lft = jack_last_frame_time(client1);
  137. TheFrame->ft = jack_frame_time(client1);
  138. TheFrame->fcs = jack_frames_since_cycle_start(client1);
  139. }
  140. void Jack_Thread_Init_Callback(void *arg)
  141. {
  142. #ifdef WIN32
  143. Log("Init callback has been successfully called from thread = %x. (msg from callback)\n", GetCurrentThread());
  144. #else
  145. Log("Init callback has been successfully called from thread = %x. (msg from callback)\n", pthread_self());
  146. #endif
  147. init_clbk = 1;
  148. }
  149. void Jack_Freewheel_Callback(int starting, void *arg)
  150. {
  151. Log("Freewheel callback has been successfully called with value %i. (msg from callback)\n", starting);
  152. FW = starting;
  153. }
  154. void Jack_Client_Registration_Callback(const char* name, int val, void *arg)
  155. {
  156. Log("Client registration callback name = %s has been successfully called with value %i. (msg from callback)\n", name, val);
  157. if (val)
  158. client_register++;
  159. else
  160. client_register--;
  161. }
  162. void Jack_Port_Rename_Callback(jack_port_id_t port, const char* old_name, const char* new_name, void *arg)
  163. {
  164. Log("Rename callback has been successfully called with old_name '%s' and new_name '%s'. (msg from callback)\n", old_name, new_name);
  165. port_rename_clbk = 1;
  166. }
  167. int Jack_Update_Buffer_Size(jack_nframes_t nframes, void *arg)
  168. {
  169. cur_buffer_size = jack_get_buffer_size(client1);
  170. Log("Buffer size = %d (msg from callback)\n", cur_buffer_size);
  171. return 0;
  172. }
  173. int Jack_XRun_Callback(void *arg)
  174. {
  175. xrun++;
  176. have_xrun = 1;
  177. Log("Xrun has been detected ! (msg from callback)\n");
  178. return 0;
  179. }
  180. int Jack_Graph_Order_Callback(void *arg)
  181. {
  182. reorder++;
  183. return 0;
  184. }
  185. int Jack_Sample_Rate_Callback(jack_nframes_t nframes, void *arg)
  186. {
  187. Log("Sample rate : %i.\n", nframes);
  188. return 0;
  189. }
  190. void Jack_Error_Callback(const char *msg)
  191. {
  192. if (silent_error == 0) {
  193. fprintf(stderr, "error : %s (msg from callback)\n", msg);
  194. }
  195. }
  196. void jack_shutdown(void *arg)
  197. {
  198. printf("Jack_test has been kicked out by jackd !\n");
  199. exit(1);
  200. }
  201. void jack_info_shutdown(jack_status_t code, const char* reason, void *arg)
  202. {
  203. printf("JACK server failure : %s\n", reason);
  204. exit(1);
  205. }
  206. void Jack_Port_Register(jack_port_id_t port, int mode, void *arg)
  207. {
  208. port_callback_reg++;
  209. }
  210. void Jack_Port_Connect(jack_port_id_t a, jack_port_id_t b, int connect, void* arg)
  211. {
  212. Log("PortConnect src = %ld dst = %ld onoff = %ld (msg from callback)\n", a, b, connect);
  213. }
  214. int Jack_Sync_Callback(jack_transport_state_t state, jack_position_t *pos, void *arg)
  215. {
  216. int res = 0;
  217. switch (state) {
  218. case JackTransportStarting:
  219. sync_called++;
  220. if (starting_state == 0) {
  221. Log("sync callback : Releasing status : now ready...\n");
  222. res = 1;
  223. } else {
  224. if (sync_called == 1) {
  225. Log("sync callback : Holding status...\n");
  226. }
  227. res = 0;
  228. }
  229. break;
  230. case JackTransportStopped:
  231. Log("sync callback : JackTransportStopped...\n");
  232. res = 0;
  233. break;
  234. default:
  235. res = 0;
  236. break;
  237. }
  238. return res;
  239. }
  240. /**
  241. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  242. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  243. processing functions
  244. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  245. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  246. * Proccess1 is for client1
  247. * 4 modes, activated with process1_activated
  248. *
  249. * -1 : idle mode
  250. * 0 : write zeros to output 1
  251. * 1 : write continuously signal1 (sinusoidal test signal) to output1
  252. * 3 : mode for summation test. While record (done by process2) is not running, write signal1 to both out1 & out1b.
  253. * when record begin (index2 > 0), write signal1 in phase opposition to out1 & out2
  254. * 5 : Frames Time checking mode : write the array containing the three values of frame_time, frames cycles start and
  255. * last frame time during 150 cycles.
  256. */
  257. int process1(jack_nframes_t nframes, void *arg)
  258. {
  259. if (FW == 0) {
  260. Collect(&perpetualcollect);
  261. if (have_xrun) {
  262. fprintf(file, "%i %i\n", (perpetualcollect.ft - lastperpetualcollect.ft), (2*cur_buffer_size));
  263. have_xrun = 0;
  264. } else {
  265. fprintf(file, "%i 0\n", (perpetualcollect.ft - lastperpetualcollect.ft));
  266. }
  267. linecount++;
  268. lastperpetualcollect.ft = perpetualcollect.ft;
  269. }
  270. jack_default_audio_sample_t *out1;
  271. jack_default_audio_sample_t *out1b;
  272. activated++; // counter of callback activation
  273. if (process1_activated == 1) {
  274. out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
  275. for (jack_nframes_t p = 0; p < nframes; p++) {
  276. out1[p] = signal1[index1];
  277. index1++;
  278. if (index1 == 48000)
  279. index1 = 0;
  280. }
  281. }
  282. if (process1_activated == 3) {
  283. out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
  284. out1b = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1b, nframes);
  285. for (jack_nframes_t p = 0; p < nframes; p++) {
  286. out1[p] = signal1[index1];
  287. if (index2 != 0) {
  288. out1b[p] = ( -1 * signal1[index1]);
  289. } else {
  290. out1b[p] = signal1[index1];
  291. }
  292. index1++;
  293. if (index1 == 48000)
  294. index1 = 0;
  295. }
  296. }
  297. if (process1_activated == 0) {
  298. out1 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port1, nframes);
  299. memset (out1, 0, sizeof (jack_default_audio_sample_t) * nframes); //�crit des z�ros en sortie...
  300. }
  301. if (process1_activated == 5) {
  302. Collect(&framecollect[frames_collected]);
  303. frames_collected++;
  304. if (frames_collected > 798) {
  305. process1_activated = -1;
  306. }
  307. }
  308. return 0;
  309. }
  310. /**
  311. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  312. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  313. * Proccess2 is for client2
  314. * 3 modes, activated with process1_activated
  315. *
  316. * -1 : idle mode
  317. * 0 : idle mode
  318. * 1 : record in2 into signal2.(for first transmit test)
  319. * 2 : record in2 into signal2 while send signal1 in out2. used dor Tie data test.
  320. * 3 : record in2 into sigal2 for summation data test.
  321. * In records modes, at the end of the record (signal2 is full), it stop the test, setting both activation states to -1.
  322. */
  323. int process2(jack_nframes_t nframes, void *arg)
  324. {
  325. jack_default_audio_sample_t *out2;
  326. jack_default_audio_sample_t *in2;
  327. if (process2_activated == 1) { // Reception du process1 pour comparer les donnees
  328. in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
  329. for (unsigned int p = 0; p < nframes; p++) {
  330. signal2[index2] = in2[p];
  331. if (index2 == 95999) {
  332. process2_activated = 0;
  333. process1_activated = 0;
  334. //index2 = 0;
  335. } else {
  336. index2++;
  337. }
  338. }
  339. }
  340. if (process2_activated == 2) { // envoie de signal1 pour test tie mode et le r�cup�re direct + latence de la boucle jack...
  341. out2 = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port2, nframes);
  342. in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
  343. for (unsigned int p = 0; p < nframes; p++) {
  344. out2[p] = signal1[index1];
  345. index1++;
  346. if (index1 == 48000)
  347. index1 = 0;
  348. signal2[index2] = in2[p];
  349. if (index2 == 95999) {
  350. process2_activated = -1;
  351. //index2 = 0;
  352. } else {
  353. index2++;
  354. }
  355. }
  356. }
  357. if (process2_activated == 3) { // envoie de -signal1 pour sommation en oppo de phase par jack
  358. in2 = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port2, nframes);
  359. for (unsigned int p = 0; p < nframes;p++) {
  360. signal2[index2] = in2[p];
  361. if (index2 == 95999) {
  362. process2_activated = 0;
  363. process1_activated = 0;
  364. //index2 = 0;
  365. } else {
  366. index2++;
  367. }
  368. }
  369. }
  370. return 0;
  371. }
  372. // Alternate thread model
  373. static int _process (jack_nframes_t nframes)
  374. {
  375. jack_default_audio_sample_t *in, *out;
  376. in = (jack_default_audio_sample_t *)jack_port_get_buffer (input_port1, nframes);
  377. out = (jack_default_audio_sample_t *)jack_port_get_buffer (output_port1, nframes);
  378. memcpy (out, in, sizeof (jack_default_audio_sample_t) * nframes);
  379. return 0;
  380. }
  381. static void* jack_thread(void *arg)
  382. {
  383. jack_client_t* client = (jack_client_t*) arg;
  384. jack_nframes_t last_thread_time = jack_frame_time(client);
  385. while (1) {
  386. jack_nframes_t frames = jack_cycle_wait(client);
  387. jack_nframes_t current_thread_time = jack_frame_time(client);
  388. jack_nframes_t delta_time = current_thread_time - last_thread_time;
  389. Log("jack_thread : delta_time = %ld\n", delta_time);
  390. int status = _process(frames);
  391. last_thread_time = current_thread_time;
  392. jack_cycle_signal (client, status);
  393. }
  394. return 0;
  395. }
  396. // To test callback exiting
  397. int process3(jack_nframes_t nframes, void *arg)
  398. {
  399. static int process3_call = 0;
  400. if (process3_call++ > 10) {
  401. Log("process3 callback : exiting...\n");
  402. return -1;
  403. } else {
  404. Log("calling process3 callback : process3_call = %ld\n", process3_call);
  405. return 0;
  406. }
  407. }
  408. int process4(jack_nframes_t nframes, void *arg)
  409. {
  410. jack_client_t* client = (jack_client_t*) arg;
  411. static jack_nframes_t last_time = jack_frame_time(client);
  412. static jack_nframes_t tolerance = (jack_nframes_t)(cur_buffer_size * 0.1f);
  413. jack_nframes_t cur_time = jack_frame_time(client);
  414. jack_nframes_t delta_time = cur_time - last_time;
  415. Log("calling process4 callback : jack_frame_time = %ld delta_time = %ld\n", cur_time, delta_time);
  416. if (delta_time > 0 && abs((int64_t)delta_time - (int64_t)cur_buffer_size) > (int64_t)tolerance) {
  417. printf("!!! ERROR !!! jack_frame_time seems to return incorrect values cur_buffer_size = %d, delta_time = %d tolerance %d\n", cur_buffer_size, delta_time, tolerance);
  418. }
  419. last_time = cur_time;
  420. return 0;
  421. }
  422. int process5(jack_nframes_t nframes, void *arg)
  423. {
  424. jack_client_t* client = (jack_client_t*) arg;
  425. static jack_nframes_t first_current_frames;
  426. static jack_time_t first_current_usecs;
  427. static jack_time_t first_next_usecs;
  428. jack_nframes_t current_frames;
  429. jack_time_t current_usecs;
  430. jack_time_t next_usecs;
  431. float period_usecs;
  432. int res = jack_get_cycle_times(client, &current_frames, &current_usecs, &next_usecs, &period_usecs);
  433. if (res != 0) {
  434. printf("!!! ERROR !!! jack_get_cycle_times fails...\n");
  435. return 0;
  436. }
  437. Log("calling process5 callback : jack_get_cycle_times delta current_frames = %ld delta current_usecs = %ld delta next_usecs = %ld period_usecs = %f\n",
  438. current_frames - first_current_frames, current_usecs - first_current_usecs, next_usecs - first_next_usecs, period_usecs);
  439. first_current_frames = current_frames;
  440. first_current_usecs = current_usecs;
  441. first_next_usecs = next_usecs;
  442. return 0;
  443. }
  444. static void display_transport_state()
  445. {
  446. jack_transport_state_t ts;
  447. jack_position_t pos;
  448. ts = jack_transport_query(client2, &pos);
  449. switch (ts) {
  450. case JackTransportStopped:
  451. Log("Transport is stopped...\n");
  452. break;
  453. case JackTransportRolling:
  454. Log("Transport is rolling...\n");
  455. break;
  456. case JackTransportLooping:
  457. Log("Transport is looping...\n");
  458. break;
  459. case JackTransportStarting:
  460. Log("Transport is starting...\n");
  461. break;
  462. case JackTransportNetStarting:
  463. Log("Transport is starting with network sync...\n");
  464. break;
  465. }
  466. }
  467. /**
  468. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  469. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  470. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  471. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  472. MAIN FUNCTION
  473. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  474. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  475. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  476. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  477. */
  478. int main (int argc, char *argv[])
  479. {
  480. const char **inports; // array of PHY input/output
  481. const char **outports; // array of PHY input/outputs
  482. const char *server_name = NULL;
  483. const char **connexions1;
  484. const char **connexions2;
  485. jack_status_t status;
  486. char portname[128] = "port";
  487. char filename[128] = "framefile.ext";
  488. const char *nullportname = "";
  489. int option_index;
  490. int opt;
  491. int a = 0; // working number for in/out port (PHY)...
  492. int test_link = 0; // for testing the "overconnect" function
  493. int flag; // flag for ports...
  494. int is_mine = 0; // to test jack_port_is_mine function...
  495. const char *options = "kRnqvt:";
  496. float ratio; // for speed calculation in freewheel mode
  497. jack_options_t jack_options = JackNullOption;
  498. struct option long_options[] = {
  499. {"realtime", 0, 0, 'R'},
  500. {"non-realtime", 0, 0, 'n'},
  501. {"time", 0, 0, 't'},
  502. {"quiet", 0, 0, 'q'},
  503. {"verbose", 0, 0, 'v'},
  504. {"transport", 0, 0, 'k'},
  505. {0, 0, 0, 0}
  506. };
  507. client_name1 = "jack_test";
  508. time_to_run = 1;
  509. //verbose_mode = 1;
  510. //RT = 1;
  511. while ((opt = getopt_long (argc, argv, options, long_options, &option_index)) != EOF) {
  512. switch (opt) {
  513. case 'k':
  514. transport_mode = 0;
  515. break;
  516. case 'q':
  517. silent_error = 1;
  518. break;
  519. case 'v':
  520. verbose_mode = 1;
  521. printf("Verbose mode is activated...\n");
  522. break;
  523. case 't':
  524. time_to_run = atoi(optarg);
  525. break;
  526. case 'R':
  527. RT = 1;
  528. break;
  529. default:
  530. fprintf (stderr, "unknown option %c\n", opt);
  531. usage ();
  532. }
  533. }
  534. if (RT) {
  535. printf("Jack server is said being in realtime mode...\n");
  536. } else {
  537. printf("Jack server is said being in non-realtime mode...\n");
  538. }
  539. /**
  540. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  541. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  542. init signal data for test
  543. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  544. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  545. */
  546. framecollect = (FrameTimeCollector *) malloc(800 * sizeof(FrameTimeCollector));
  547. signal1 = (jack_default_audio_sample_t *) malloc(48000 * sizeof(jack_default_audio_sample_t));
  548. signal2 = (jack_default_audio_sample_t *) malloc(96000 * sizeof(jack_default_audio_sample_t));
  549. signal1[0] = 0;
  550. int p;
  551. for (p = 1; p < 48000;p++) {
  552. signal1[p] = (float)(sin((p * 2 * M_PI * 1000 ) / 48000));
  553. }
  554. for (p = 0; p < 95999;p++) {
  555. signal2[p] = 0.0 ;
  556. }
  557. index1 = 0;
  558. index2 = 0;
  559. /**
  560. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  561. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  562. begin test
  563. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  564. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  565. */
  566. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  567. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  568. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-* Start jack server stress test *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  569. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  570. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  571. /**
  572. * Register a client...
  573. *
  574. */
  575. Log("Register a client using jack_client_open()...\n");
  576. client1 = jack_client_open(client_name1, jack_options, &status, server_name);
  577. if (client1 == NULL) {
  578. fprintf (stderr, "jack_client_open() failed, "
  579. "status = 0x%2.0x\n", status);
  580. if (status & JackServerFailed) {
  581. fprintf(stderr, "Unable to connect to JACK server\n");
  582. }
  583. exit (1);
  584. }
  585. if (status & JackServerStarted) {
  586. fprintf(stderr, "JACK server started\n");
  587. }
  588. /**
  589. * Internal client tests...
  590. *
  591. */
  592. jack_intclient_t intclient;
  593. Log("trying to load the \"inprocess\" server internal client \n");
  594. intclient = jack_internal_client_load (client1, "inprocess",
  595. (jack_options_t)(JackLoadName|JackLoadInit),
  596. &status, "inprocess", "");
  597. if (intclient == 0 || status & JackFailure) {
  598. printf("!!! ERROR !!! cannot load internal client \"inprocess\" intclient 0x%llX status 0x%2.0x !\n", (unsigned long long)intclient, status);
  599. } else {
  600. Log("\"inprocess\" server internal client loaded\n");
  601. char* internal_name = jack_get_internal_client_name(client1, intclient);
  602. if (strcmp(internal_name, "inprocess") == 0) {
  603. Log("jack_get_internal_client_name returns %s\n", internal_name);
  604. } else {
  605. printf("!!! ERROR !!! jack_get_internal_client_name returns incorrect name %s\n", internal_name);
  606. }
  607. jack_intclient_t intclient1 = jack_internal_client_handle(client1, "inprocess", &status);
  608. if (intclient1 == intclient) {
  609. Log("jack_internal_client_handle returns correct handle\n");
  610. } else {
  611. printf("!!! ERROR !!! jack_internal_client_handle returns incorrect handle 0x%llX\n", (unsigned long long)intclient1);
  612. }
  613. // Unload internal client
  614. status = jack_internal_client_unload (client1, intclient);
  615. if (status == 0) {
  616. Log("jack_internal_client_unload done first time returns correct value\n");
  617. } else {
  618. printf("!!! ERROR !!! jack_internal_client_unload returns incorrect value 0x%2.0x\n", status);
  619. }
  620. // Unload internal client second time
  621. status = jack_internal_client_unload (client1, intclient);
  622. if (status & JackFailure && status & JackNoSuchClient) {
  623. Log("jack_internal_client_unload done second time returns correct value\n");
  624. } else {
  625. printf("!!! ERROR !!! jack_internal_client_unload returns incorrect value 0x%2.0x\n", status);
  626. }
  627. }
  628. /**
  629. * try to register another one with the same name...
  630. *
  631. */
  632. Log("trying to register a new jackd client with name %s using jack_client_new()...\n", client_name1);
  633. client2 = jack_client_new(client_name1);
  634. if (client2 == NULL) {
  635. Log ("valid : a second client with the same name cannot be registered\n");
  636. } else {
  637. printf("!!! ERROR !!! Jackd server has accepted multiples client with the same name !\n");
  638. jack_client_close(client2);
  639. }
  640. /**
  641. * try to register another one with the same name using jack_client_open ==> since JackUseExactName is not used, an new client should be opened...
  642. *
  643. */
  644. Log("trying to register a new jackd client with name %s using jack_client_open()...\n", client_name1);
  645. client2 = jack_client_open(client_name1, jack_options, &status, server_name);
  646. if (client2 != NULL) {
  647. Log ("valid : a second client with the same name can be registered (client automatic renaming)\n");
  648. jack_client_close(client2);
  649. } else {
  650. printf("!!! ERROR !!! Jackd server automatic renaming feature does not work!\n");
  651. }
  652. /**
  653. * try to register a client with maximum possible client name size
  654. *
  655. */
  656. char client_name3[jack_client_name_size()];
  657. // "jack_client_name_size" - 1 effective characters
  658. for (int i = 0; i < jack_client_name_size() - 1; i++) {
  659. client_name3[i] = 'A';
  660. }
  661. // And last one is the terminating '0'
  662. client_name3[jack_client_name_size()] = 0;
  663. Log("trying to register a new jackd client with maximum possible client name size...\n", client_name3);
  664. client2 = jack_client_open(client_name3, jack_options, &status, server_name);
  665. if (client2 != NULL) {
  666. Log ("valid : a client with maximum possible client name size can be opened\n");
  667. jack_client_close(client2);
  668. } else {
  669. printf("!!! ERROR !!! opening a client with maximum possible client name size does not work!\n");
  670. }
  671. /**
  672. * testing client name...
  673. * Verify that the name sended at registration and the one returned by jack server is the same...
  674. *
  675. */
  676. Log("Testing name...");
  677. client_name2 = jack_get_client_name(client1);
  678. if (strcmp(client_name1, client_name2) == 0) {
  679. Log(" ok\n");
  680. } else {
  681. printf("\n!!! ERROR !!! name returned different from the one given : %s\n", client_name2);
  682. }
  683. /**
  684. * Test RT mode...
  685. * verify if the real time mode returned by jack match the optional argument defined when launching jack_test*/
  686. if (jack_is_realtime(client1) == RT) {
  687. Log("Jackd is in realtime mode (RT = %i).\n", RT);
  688. } else {
  689. printf("!!! ERROR !!! Jackd is in a non-expected realtime mode (RT = %i).\n", RT);
  690. }
  691. /**
  692. * Register all callbacks...
  693. *
  694. */
  695. if (jack_set_thread_init_callback(client1, Jack_Thread_Init_Callback, 0) != 0) {
  696. printf("!!! ERROR !!! while calling jack_set_thread_init_callback()...\n");
  697. }
  698. if (jack_set_freewheel_callback(client1, Jack_Freewheel_Callback, 0) != 0 ) {
  699. printf("\n!!! ERROR !!! while calling jack_set_freewheel_callback()...\n");
  700. }
  701. if (jack_set_process_callback(client1, process1, 0) != 0) {
  702. printf("Error when calling jack_set_process_callback() !\n");
  703. }
  704. jack_on_shutdown(client1, jack_shutdown, 0);
  705. if (jack_on_info_shutdown) {
  706. jack_on_info_shutdown(client1, jack_info_shutdown, 0);
  707. }
  708. if (jack_set_buffer_size_callback(client1, Jack_Update_Buffer_Size, 0) != 0) {
  709. printf("Error when calling buffer_size_callback !\n");
  710. }
  711. if (jack_set_graph_order_callback(client1, Jack_Graph_Order_Callback, 0) != 0) {
  712. printf("Error when calling Jack_Graph_Order_Callback() !\n");
  713. }
  714. if (jack_set_port_rename_callback(client1, Jack_Port_Rename_Callback, 0) != 0 )
  715. printf("\n!!! ERROR !!! while calling jack_set_rename_callback()...\n");
  716. if (jack_set_xrun_callback(client1, Jack_XRun_Callback, 0 ) != 0) {
  717. printf("Error when calling jack_set_xrun_callback() !\n");
  718. }
  719. if (jack_set_sample_rate_callback(client1, Jack_Sample_Rate_Callback, 0 ) != 0) {
  720. printf("Error when calling Jack_Sample_Rate_Callback() !\n");
  721. }
  722. if (jack_set_port_registration_callback(client1, Jack_Port_Register, 0) != 0) {
  723. printf("Error when calling jack_set_port_registration_callback() !\n");
  724. }
  725. if (jack_set_port_connect_callback(client1, Jack_Port_Connect, 0) != 0) {
  726. printf("Error when calling jack_set_port_connect_callback() !\n");
  727. }
  728. if (jack_set_client_registration_callback(client1, Jack_Client_Registration_Callback, 0) != 0) {
  729. printf("Error when calling jack_set_client_registration_callback() !\n");
  730. }
  731. jack_set_error_function(Jack_Error_Callback);
  732. /**
  733. * Create file for clock "frame time" analysis
  734. *
  735. */
  736. cur_buffer_size = jack_get_buffer_size(client1);
  737. sprintf (filename, "framefile-%i.dat", cur_buffer_size);
  738. file = fopen(filename, "w");
  739. if (file == NULL) {
  740. fprintf(stderr, "Error when opening framefile.dat log file");
  741. exit(-1);
  742. }
  743. /**
  744. * Try to register a client with a NULL name/zero length name...
  745. *
  746. */
  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);
  755. }
  756. /**
  757. * Register 1 port in order to stress other functions.
  758. *
  759. */
  760. output_port1 = jack_port_register(client1, portname,
  761. JACK_DEFAULT_AUDIO_TYPE,
  762. JackPortIsOutput, 0);
  763. if (output_port1 == NULL) {
  764. printf("!!! ERROR !!! Can't register any port for the client !\n");
  765. exit(1);
  766. }
  767. /**
  768. * Test port type of the just registered port.
  769. *
  770. */
  771. if (strcmp(jack_port_type(output_port1), JACK_DEFAULT_AUDIO_TYPE) != 0) {
  772. printf("!!! ERROR !!! jack_port_type returns an incorrect value!\n");
  773. } else {
  774. Log("Checking jack_port_type()... ok.\n");
  775. }
  776. /**
  777. * Try to register another port with the same name...
  778. *
  779. */
  780. output_port2 = jack_port_register(client1, portname,
  781. JACK_DEFAULT_AUDIO_TYPE,
  782. JackPortIsOutput, 0);
  783. if (output_port2 == NULL) {
  784. Log("Can't register two ports with the same name... ok\n");
  785. } else {
  786. if (strcmp (jack_port_name(output_port1), jack_port_name(output_port2)) == 0) {
  787. 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));
  788. jack_port_unregister(client1, output_port2);
  789. } else {
  790. 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));
  791. jack_port_unregister(client1, output_port2);
  792. }
  793. }
  794. /**
  795. * Verify that both port_name and port_short_name return correct results...
  796. *
  797. */
  798. sprintf (portname, "%s:%s", jack_get_client_name(client1), jack_port_short_name(output_port1));
  799. if (strcmp(jack_port_name(output_port1), portname) != 0) {
  800. printf("!!! ERROR !!! functions jack_port_name and/or jack_short_port_name seems to be invalid !\n");
  801. 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));
  802. }
  803. /**
  804. * Verify the function port_set_name
  805. *
  806. */
  807. if (jack_port_set_name (output_port1, "renamed-port#") == 0 ) {
  808. if (strcmp(jack_port_name(output_port1), "renamed-port#") == 0) {
  809. printf("!!! ERROR !!! functions jack_port_set_name seems to be invalid !\n");
  810. printf("jack_port_name return '%s' whereas 'renamed-port#' was expected...\n", jack_port_name(output_port1));
  811. } else {
  812. Log("Checking jack_port_set_name()... ok\n");
  813. jack_port_set_name (output_port1, "port");
  814. }
  815. } else {
  816. printf("error : port_set_name function can't be tested...\n");
  817. }
  818. /**
  819. * Verify if a port can be registered with maximum port name size (that is "short name")
  820. *
  821. */
  822. int short_port_size_max = jack_port_name_size() - jack_client_name_size() - 1; // Port is of shape: "client_name:port_name"
  823. char port_name3[short_port_size_max];
  824. // "short_port_size_max" - 1 effective characters
  825. for (int i = 0; i < short_port_size_max - 1; i++) {
  826. port_name3[i] = 'A';
  827. }
  828. // And last one is the terminating '0'
  829. port_name3[short_port_size_max] = 0;
  830. jack_port_t * test_max_port = jack_port_register(client1, port_name3,
  831. JACK_DEFAULT_AUDIO_TYPE,
  832. JackPortIsOutput, 0);
  833. if (test_max_port != NULL) {
  834. Log ("valid : a port with maximum possible port name size can be registered\n");
  835. jack_port_unregister(client1, test_max_port);
  836. } else {
  837. printf("!!! ERROR !!! registering a port with maximum possible port name size does not work!\n");
  838. }
  839. port_callback_reg = 0; // number of port registration received by the callback
  840. /**
  841. * Activate the client
  842. *
  843. */
  844. if (jack_activate(client1) < 0) {
  845. printf ("Fatal error : cannot activate client1\n");
  846. exit(1);
  847. }
  848. /**
  849. * Test if port rename callback have been called.
  850. *
  851. */
  852. jack_port_set_name (output_port1, "renamed-port#");
  853. jack_sleep(1 * 1000);
  854. if (port_rename_clbk == 0) {
  855. printf("!!! ERROR !!! Jack_Port_Rename_Callback was not called !!.\n");
  856. }
  857. /**
  858. * Test if port registration callback have been called.
  859. *
  860. */
  861. jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
  862. if (1 == port_callback_reg) {
  863. Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", 1, port_callback_reg);
  864. } else {
  865. printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", 1, port_callback_reg);
  866. }
  867. /**
  868. * Test if init callback initThread have been called.
  869. *
  870. */
  871. if (init_clbk == 0) {
  872. printf("!!! ERROR !!! Jack_Thread_Init_Callback was not called !!.\n");
  873. }
  874. jack_sleep(10 * 1000); // test see the clock in the graph at the begining...
  875. /**
  876. * Stress Freewheel mode...
  877. * Try to enter freewheel mode. Check the realtime mode de-activation.
  878. * Check that the number of call of the process callback is greater than in non-freewheel mode.
  879. * Give an approximated speed ratio (number of process call) between the two modes.
  880. * Then return in normal mode.
  881. */
  882. t_error = 0;
  883. activated = 0;
  884. jack_sleep(1 * 1000);
  885. count1 = activated;
  886. Log("Testing activation freewheel mode...\n");
  887. linefw = linecount; // count for better graph reading with gnuplot
  888. jack_set_freewheel(client1, 1);
  889. activated = 0;
  890. jack_sleep(1 * 1000);
  891. count2 = activated;
  892. if (jack_is_realtime(client1) == 0) {
  893. t_error = 0;
  894. } else {
  895. printf("\n!!! ERROR !!! RT mode is always activated while freewheel mode is applied !\n");
  896. t_error = 1;
  897. }
  898. if (activated == 0) {
  899. printf("!!! ERROR !!! Freewheel mode doesn't activate audio callback !!\n");
  900. }
  901. jack_set_freewheel(client1, 0);
  902. jack_sleep(7 * 1000);
  903. if (jack_is_realtime(client1) == 1) {
  904. } else {
  905. printf("\n!!! ERROR !!! freewheel mode fail to reactivate RT mode when exiting !\n");
  906. t_error = 1;
  907. }
  908. if (t_error == 0) {
  909. Log("Freewheel mode appears to work well...\n");
  910. }
  911. if (count1 == 0) {
  912. Log("Audio Callback in 'standard' (non-freewheel) mode seems not to be called...\n");
  913. Log("Ratio speed would be unavailable...\n");
  914. } else {
  915. ratio = (float) ((count2 - count1) / count1);
  916. Log("Approximative speed ratio of freewheel mode = %f : 1.00\n", ratio);
  917. }
  918. /**
  919. * Stress buffer function...
  920. * get current buffer size.
  921. * Try to apply a new buffer size value ( 2 x the precedent buffer size value)
  922. * Then return in previous buffer size mode.
  923. *
  924. */
  925. float factor = 0.5f;
  926. old_buffer_size = jack_get_buffer_size(client1);
  927. Log("Testing BufferSize change & Callback...\n--> Current buffer size : %d.\n", old_buffer_size);
  928. linebuf = linecount;
  929. if (jack_set_buffer_size(client1, (jack_nframes_t)(old_buffer_size * factor)) < 0) {
  930. printf("!!! ERROR !!! jack_set_buffer_size fails !\n");
  931. }
  932. jack_sleep(1 * 1000);
  933. cur_buffer_size = jack_get_buffer_size(client1);
  934. if (abs((old_buffer_size * factor) - cur_buffer_size) > 5) { // Tolerance needed for dummy driver...
  935. printf("!!! ERROR !!! Buffer size has not been changed !\n");
  936. printf("!!! Maybe jack was compiled without the '--enable-resize' flag...\n");
  937. } else {
  938. Log("jack_set_buffer_size() command successfully applied...\n");
  939. }
  940. jack_sleep(3 * 1000);
  941. jack_set_buffer_size(client1, old_buffer_size);
  942. cur_buffer_size = jack_get_buffer_size(client1);
  943. /**
  944. * Test the last regestered port to see if port_is_mine function the right value.
  945. * A second test will be performed later.
  946. * The result will be printed at the end.
  947. *
  948. */
  949. if (jack_port_is_mine(client1, output_port1)) {
  950. is_mine = 1;
  951. } else {
  952. is_mine = 0;
  953. }
  954. /**
  955. * Check that the ID returned by the port_by_name is right.
  956. * (it seems there is a problem here in some jack versions).
  957. *
  958. */
  959. if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
  960. printf("!!! ERROR !!! function jack_port_by_name() return bad value !\n");
  961. 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);
  962. } else {
  963. Log("Checking jack_port_by_name() return value... ok\n");
  964. }
  965. if (NULL != jack_port_by_name(client1, jack_port_short_name(output_port1))) {
  966. 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)));
  967. } else {
  968. Log("Checking jack_port_by_name() with bad argument... ok (returned id 0)\n");
  969. }
  970. /**
  971. * remove the output port previously created
  972. * no more ports should subsist here for our client.
  973. *
  974. */
  975. if (jack_port_unregister(client1, output_port1) != 0) {
  976. printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
  977. }
  978. /**
  979. * list all in ports
  980. *
  981. */
  982. inports = jack_get_ports(client1, NULL, NULL, 0);
  983. /**
  984. * Test the first PHY (physical) connection to see if it's "mine".
  985. * and report the result in the test that began before.
  986. * The result is printed later.
  987. *
  988. */
  989. if (jack_port_is_mine(client1, jack_port_by_name(client1, inports[0]))) {
  990. is_mine = 0;
  991. }
  992. /**
  993. * List all devices' flags and print them...
  994. *
  995. */
  996. Log("\nTry functions jack_get_ports, jack_port_flag & jack_port_by_name to list PHY devices...\n");
  997. Log("-----------------------------------------------------------\n");
  998. Log("---------------------------DEVICES-------------------------\n");
  999. Log("-----------------------------------------------------------\n");
  1000. a = 0;
  1001. while (inports[a] != NULL) {
  1002. flag = jack_port_flags(jack_port_by_name(client1, inports[a]) );
  1003. Log(" * %s (id : %i)\n", inports[a], jack_port_by_name(client1, inports[a]));
  1004. Log(" (");
  1005. if (flag & JackPortIsInput)
  1006. Log("JackPortIsInput ");
  1007. if (flag & JackPortIsOutput)
  1008. Log("JackPortIsOutput ");
  1009. if (flag & JackPortIsPhysical)
  1010. Log("JackPortIsPhysical ");
  1011. if (flag & JackPortCanMonitor)
  1012. Log("JackPortCanMonitor ");
  1013. if (flag & JackPortIsTerminal)
  1014. Log("JackPortIsTerminal ");
  1015. Log(")\n\n");
  1016. a++;
  1017. }
  1018. Log("-----------------------------------------------------------\n\n");
  1019. /**
  1020. * list all PHY in/out ports...
  1021. * This list will be used later many times.
  1022. *
  1023. */
  1024. outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
  1025. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1026. if (outports == NULL) {
  1027. printf("!!! WARNING !!! no physical capture ports founded !\n");
  1028. }
  1029. if (inports == NULL) {
  1030. printf("!!! WARNING !!! no physical output ports founded !\n");
  1031. }
  1032. /**
  1033. * Brute test : try to create as many ports as possible.
  1034. * It stops when jack returns an error.
  1035. * Then try to connect each port to physical entry...
  1036. * Check also that graph reorder callback is called.
  1037. *
  1038. */
  1039. Log("Registering as many ports as possible and connect them to physical entries...\n");
  1040. lineports = linecount;
  1041. t_error = 0;
  1042. i = 0; // number of couple 'input-ouput'
  1043. j = 0; // number of ports created
  1044. port_callback_reg = 0; // number of port registration received by the callback
  1045. reorder = 0; // number of graph reorder callback activation
  1046. test_link = 0 ; // Test the "overconnect" function only one time
  1047. while (t_error == 0) {
  1048. sprintf (portname, "input_%d", i);
  1049. input_port1 = jack_port_register(client1, portname,
  1050. JACK_DEFAULT_AUDIO_TYPE,
  1051. JackPortIsInput, 0);
  1052. j++;
  1053. if (input_port1 == NULL) {
  1054. j--;
  1055. t_error = 1;
  1056. } else {
  1057. // Connect created input to PHY output
  1058. a = 0;
  1059. while (outports && outports[a] != NULL) {
  1060. if (jack_connect(client1, outports[a], jack_port_name(input_port1))) {
  1061. printf ("error : cannot connect input PHY port to client port %s\n", jack_port_name(input_port1));
  1062. } else {
  1063. // printf ("input PHY port %s connected to client port %s\n", outports[a], jack_port_name(input_port1));
  1064. }
  1065. a++;
  1066. }
  1067. // Try one time to "overconnect" 2 ports (the latest created)...
  1068. if (test_link == 0 && outports && ((a - 1) > 0) && outports[a - 1]) {
  1069. if (jack_connect(client1, outports[a - 1], jack_port_name(input_port1)) == EEXIST) {
  1070. // cannot over-connect input PHY port to client port. ok.
  1071. test_link = 1;
  1072. }
  1073. }
  1074. }
  1075. sprintf(portname, "output_%d", i);
  1076. output_port1 = jack_port_register(client1, portname,
  1077. JACK_DEFAULT_AUDIO_TYPE,
  1078. JackPortIsOutput, 0);
  1079. j++;
  1080. if (output_port1 == NULL) {
  1081. t_error = 1;
  1082. j--;
  1083. } else {
  1084. // Connect created input to PHY output
  1085. a = 0;
  1086. while (inports && inports[a] != NULL) {
  1087. if (jack_connect(client1, jack_port_name(output_port1), inports[a])) {
  1088. printf ("error : cannot connect input PHY port %s to client port %s\n", inports[a], jack_port_name(output_port1));
  1089. } else {
  1090. // output PHY port %s connected to client port. ok.
  1091. }
  1092. a++;
  1093. }
  1094. // Try one time to "overconnect" 2 ports (the latest created)...
  1095. if (test_link == 0 && inports && ((a - 1) > 0) && inports[a - 1]) {
  1096. if (jack_connect(client1, jack_port_name(output_port1), inports[a - 1]) == EEXIST) {
  1097. // cannot over-connect output PHY port to client port. ok.
  1098. test_link = 1;
  1099. }
  1100. }
  1101. }
  1102. i++;
  1103. }
  1104. jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
  1105. // Check port registration callback
  1106. if (j == port_callback_reg) {
  1107. Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j, port_callback_reg);
  1108. } else {
  1109. printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j, port_callback_reg);
  1110. }
  1111. if (reorder == (2 * j)) {
  1112. Log("%i graph reorder callback have been received... ok\n", reorder);
  1113. } else {
  1114. printf("!!! ERROR !!! %i graph reorder callback have been received (maybe non-valid value)...\n", reorder);
  1115. }
  1116. /**
  1117. * print basic test connection functions result ...
  1118. * over-connected means here that we try to connect 2 ports that are already connected.
  1119. *
  1120. */
  1121. if (test_link) {
  1122. Log("Jack links can't be 'over-connected'... ok\n");
  1123. } else {
  1124. printf("!!! ERROR !!! Jack links can be 'over-connected'...\n");
  1125. }
  1126. /**
  1127. * Print the result of the two jack_is_mine test.
  1128. *
  1129. */
  1130. if (is_mine == 1) {
  1131. Log("Checking jack_port_is_mine()... ok\n");
  1132. } else {
  1133. printf("!!! ERROR !!! jack_port_is_mine() function seems to send non-valid datas !\n");
  1134. }
  1135. /**
  1136. * Free the array of the physical input and ouput ports.
  1137. * (as mentionned in the doc of jack_get_ports)
  1138. *
  1139. */
  1140. jack_free(inports);
  1141. jack_free(outports);
  1142. /**
  1143. * Try to "reactivate" the client whereas it's already activated...
  1144. *
  1145. */
  1146. if (jack_activate(client1) < 0) {
  1147. printf("!!! ERROR !!! Cannot activate client1 a second time...\n");
  1148. exit(1);
  1149. } else {
  1150. Log("jackd server accept client.jack_activate() re-activation (while client was already activated).\n");
  1151. }
  1152. /**
  1153. * Deregister all ports previously created.
  1154. *
  1155. */
  1156. port_callback_reg = 0; // to check registration callback
  1157. Log("Deregistering all ports of the client...\n");
  1158. inports = jack_get_ports(client1, NULL, NULL, 0);
  1159. a = 0;
  1160. while (inports[a] != NULL) {
  1161. flag = jack_port_flags(jack_port_by_name(client1, inports[a]));
  1162. input_port1 = jack_port_by_name(client1, inports[a]);
  1163. if (jack_port_is_mine(client1, input_port1)) {
  1164. if (jack_port_unregister(client1, input_port1) != 0) {
  1165. printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
  1166. }
  1167. }
  1168. a++;
  1169. }
  1170. jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
  1171. // Check port registration callback again
  1172. if (j == port_callback_reg) {
  1173. Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j, port_callback_reg);
  1174. } else {
  1175. printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j, port_callback_reg);
  1176. }
  1177. jack_free(inports); // free array of ports (as mentionned in the doc of jack_get_ports)
  1178. /**
  1179. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1180. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1181. Open a new client (second one) to test some other things...
  1182. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1183. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1184. */
  1185. Log("\n\n----------------------------------------------------------------------\n");
  1186. Log("Starting second new client 'jack_test_#2'...\n");
  1187. /* open a client connection to the JACK server */
  1188. client_name2 = "jack_test_#2";
  1189. linecl2 = linecount; // reminders for graph analysis
  1190. client2 = jack_client_new(client_name2);
  1191. if (client2 == NULL) {
  1192. fprintf(stderr, "jack_client_new() failed for %s.\n"
  1193. "status = 0x%2.0x\n", client_name2, status);
  1194. if (status & JackServerFailed) {
  1195. fprintf(stderr, "Unable to connect client2 to JACK server\n");
  1196. }
  1197. exit(1);
  1198. }
  1199. // Check client registration callback after jack_client_new
  1200. jack_sleep(2000);
  1201. if (client_register == 0) {
  1202. printf("!!! ERROR !!! Client registration callback not called for an opened client !\n");
  1203. }
  1204. // Check client registration callback after jack_client_close
  1205. jack_client_close(client2);
  1206. jack_sleep(2000);
  1207. if (client_register == 1) {
  1208. printf("!!! ERROR !!! Client registration callback not called for a closed client!\n");
  1209. }
  1210. // Open client2 again...
  1211. client2 = jack_client_new(client_name2);
  1212. /**
  1213. * Register callback for this client.
  1214. * Callbacks are the same as the first client for most of them, excepted for process audio callback.
  1215. *
  1216. */
  1217. jack_set_port_registration_callback(client2, Jack_Port_Register, 0);
  1218. jack_set_process_callback(client2, process2, 0);
  1219. jack_on_shutdown(client2, jack_shutdown, 0);
  1220. /**
  1221. * Register one input and one output for each client.
  1222. *
  1223. */
  1224. Log("registering 1 input/output ports for each client...\n");
  1225. output_port1 = jack_port_register(client1, "out1",
  1226. JACK_DEFAULT_AUDIO_TYPE,
  1227. JackPortIsOutput, 0);
  1228. output_port2 = jack_port_register(client2, "out2",
  1229. JACK_DEFAULT_AUDIO_TYPE,
  1230. JackPortIsOutput, 0);
  1231. input_port1 = jack_port_register(client1, "in1",
  1232. JACK_DEFAULT_AUDIO_TYPE,
  1233. JackPortIsInput, 0);
  1234. input_port2 = jack_port_register(client2, "in2",
  1235. JACK_DEFAULT_AUDIO_TYPE,
  1236. JackPortIsInput, 0);
  1237. if ((output_port1 == NULL) || (output_port2 == NULL) || (input_port1 == NULL) || (input_port2 == NULL)) {
  1238. printf("!!! ERROR !!! Unable to register ports...\n");
  1239. }
  1240. /**
  1241. * Set each process mode to idle and activate client2
  1242. *
  1243. */
  1244. process2_activated = -1;
  1245. process1_activated = -1;
  1246. if (jack_activate(client2) < 0) {
  1247. printf("Fatal error : cannot activate client2\n");
  1248. exit(1);
  1249. }
  1250. /**
  1251. * Connect the two clients and check that all connections are well-done.
  1252. *
  1253. */
  1254. Log("Testing connections functions between clients...\n");
  1255. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
  1256. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1257. }
  1258. if (jack_connect(client2, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1259. printf("!!! ERROR !!! while client2 intenting to connect ports...\n");
  1260. }
  1261. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
  1262. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1263. }
  1264. /**
  1265. * Test the port_connected function...
  1266. *
  1267. */
  1268. if ((jack_port_connected(output_port1) == jack_port_connected(input_port1)) &&
  1269. (jack_port_connected(output_port2) == jack_port_connected(input_port2)) &&
  1270. (jack_port_connected(output_port2) == 1) &&
  1271. (jack_port_connected(output_port1) == 2)
  1272. ) {
  1273. Log("Checking jack_port_connected()... ok.\n");
  1274. } else {
  1275. printf("!!! ERROR !!! function jack_port_connected() return a bad value !\n");
  1276. printf("jack_port_connected(output_port1) %d\n", jack_port_connected(output_port1));
  1277. printf("jack_port_connected(output_port2) %d\n", jack_port_connected(output_port2));
  1278. printf("jack_port_connected(input_port1) %d\n", jack_port_connected(input_port1));
  1279. printf("jack_port_connected(input_port2) %d\n", jack_port_connected(input_port2));
  1280. }
  1281. /**
  1282. * Test a new time the port_by_name function...(now we are in multi-client mode)
  1283. *
  1284. */
  1285. Log("Testing again jack_port_by_name...\n");
  1286. if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
  1287. printf("!!! ERROR !!! function jack_port_by_name() return bad value in a multi-client application!\n");
  1288. printf("!!! jack_port_by_name(jack_port_name(_ID_) ) != _ID_ in multiclient application.\n");
  1289. } else {
  1290. Log("Checking jack_port_by_name() function with a multi-client application... ok\n");
  1291. }
  1292. /**
  1293. * Test the port_connected_to function...
  1294. *
  1295. */
  1296. if ((jack_port_connected_to (output_port1, jack_port_name(input_port2))) &&
  1297. (!(jack_port_connected_to (output_port2, jack_port_name(input_port2))))) {
  1298. Log("checking jack_port_connected_to()... ok\n");
  1299. } else {
  1300. printf("!!! ERROR !!! jack_port_connected_to() return bad value !\n");
  1301. }
  1302. /**
  1303. * Test the port_get_connections & port_get_all_connections functions...
  1304. *
  1305. */
  1306. Log("Testing jack_port_get_connections and jack_port_get_all_connections...\n");
  1307. a = 0;
  1308. t_error = 0;
  1309. connexions1 = jack_port_get_connections (output_port1);
  1310. connexions2 = jack_port_get_all_connections(client1, output_port1);
  1311. if ((connexions1 == NULL) || (connexions2 == NULL)) {
  1312. printf("!!! ERROR !!! port_get_connexions or port_get_all_connexions return a NULL pointer !\n");
  1313. } else {
  1314. while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
  1315. t_error = strcmp(connexions1[a], connexions2[a]);
  1316. a++;
  1317. }
  1318. if (t_error == 0) {
  1319. Log("Checking jack_port_get_connections Vs jack_port_get_all_connections... ok\n");
  1320. } else {
  1321. printf("!!! ERROR !!! while checking jack_port_get_connections Vs jack_port_get_all_connections...\n");
  1322. }
  1323. }
  1324. a = 0;
  1325. t_error = 0;
  1326. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1327. connexions1 = NULL;
  1328. if (inports && inports[0] != NULL) {
  1329. connexions1 = jack_port_get_connections (jack_port_by_name(client1, inports[0]));
  1330. connexions2 = jack_port_get_all_connections(client1, jack_port_by_name(client1, inports[0]));
  1331. }
  1332. jack_free (inports);
  1333. if (connexions1 == NULL) {
  1334. Log("checking jack_port_get_connections() for external client... ok\n");
  1335. } else {
  1336. while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
  1337. t_error = strcmp(connexions1[a], connexions2[a]);
  1338. a++;
  1339. }
  1340. }
  1341. if (t_error == 0) {
  1342. Log("Checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port... ok\n");
  1343. } else {
  1344. printf("!!! ERROR !!! while checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port...\n");
  1345. }
  1346. if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
  1347. printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
  1348. }
  1349. if (jack_disconnect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1350. printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
  1351. }
  1352. // No links should subsist now...
  1353. /**
  1354. * Checking data connexion
  1355. * establishing a link between client1.out1 --> client2.in2
  1356. * Send the signal1 test on out1. Record the result into signal2. (see process functions).
  1357. ---------------------------------------------------------------------------*/
  1358. Log("Testing connections datas between clients...\n");
  1359. jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2) );
  1360. process2_activated = -1;
  1361. process1_activated = -1;
  1362. Log("process 2 : idle mode...\n");
  1363. Log("Sending datas...");
  1364. index1 = 0;
  1365. index2 = 0;
  1366. process1_activated = 1; // We start emitting first.
  1367. process2_activated = 1; // So record begin at least when we just begin to emitt the signal, else at next call of process with
  1368. // nframe = jack buffersize shifting.
  1369. while (process2_activated == 1) {
  1370. jack_sleep(1 * 1000);
  1371. Log(".");
  1372. }
  1373. index2 = 0;
  1374. Log("\nAnalysing datas...\n"); // search the first occurence of the first element of the reference signal in the recorded signal
  1375. while (signal2[index2] != signal1[1] ) {
  1376. index2++;
  1377. if (index2 == 95999) {
  1378. printf("!!! ERROR !!! Data not found in first connexion data check!\n");
  1379. break;
  1380. }
  1381. }
  1382. index1 = index2;
  1383. Log("Data founded at offset %i.\n", index2);
  1384. // And now we founded were the recorded data are, we can see if the two signals matches...
  1385. while ( (signal2[index2] == signal1[index2 - index1 + 1]) || (index2 == 95999) || ((index2 - index1 + 1) == 47999) ) {
  1386. index2++;
  1387. }
  1388. Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
  1389. if ((index2 - index1) == 48000) {
  1390. Log("Data received are valid...\n");
  1391. } else {
  1392. printf("!!! ERROR !!! data transmission seems not to be valid in first connexion data check!\n");
  1393. }
  1394. if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port2) ) != 0)
  1395. // no more connection between ports exist now...
  1396. {
  1397. printf("Error while establishing new connexion (disconnect).\n");
  1398. }
  1399. /**
  1400. * Test TIE MODE
  1401. * (This mode seems to be problematic in standard jack version 0.100. It seems that nobody
  1402. * is used to apply this mode because the tie mode doesn't work at all. A patch seems difficult to produce
  1403. * in this version of jack. Tie mode work well in MP version.)
  1404. * Test some basic thinks (tie with 2 different client, tie non-owned ports...)
  1405. * Tie client1.in1 and client1.out1 ports, and make some data test to check the validity of the tie.
  1406. *
  1407. */
  1408. Log("Testing tie mode...\n");
  1409. if (jack_port_tie(input_port1, output_port2) != 0) {
  1410. Log("not possible to tie two ports from two different clients... ok\n");
  1411. } else {
  1412. printf("!!! ERROR !!! port_tie has allowed a connexion between two different clients !\n");
  1413. jack_port_untie(output_port2);
  1414. }
  1415. Log("Testing connections datas in tie mode...\n");
  1416. int g;
  1417. for (g = 0; g < 96000; g++)
  1418. signal2[g] = 0.0;
  1419. // Create a loop (emit test) client2.out2----client.in1--tie--client1.out1-----client2.in1 (receive test)
  1420. if (jack_port_tie(input_port1, output_port1) != 0) {
  1421. printf("Unable to tie... fatal error : data test will not be performed on tie mode !!\n");
  1422. } else { // begin of tie
  1423. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
  1424. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1425. }
  1426. if (jack_connect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1427. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1428. }
  1429. process1_activated = -1;
  1430. process2_activated = -1;
  1431. // We can manualy check here that the tie is effective.
  1432. // ie : playing a wav with a client, connecting ports manualy with qjackctl, and listen...
  1433. // printf("manual test\n");
  1434. // jack_sleep(50);
  1435. // printf("end of manual test\n");
  1436. index1 = 0;
  1437. index2 = 0;
  1438. process1_activated = -1;
  1439. process2_activated = 2;
  1440. Log("Sending datas...");
  1441. while (process2_activated == 2) {
  1442. jack_sleep(1 * 1000);
  1443. Log(".");
  1444. }
  1445. process1_activated = -1;
  1446. process2_activated = -1;
  1447. index2 = 0;
  1448. Log("\nAnalysing datas...\n");
  1449. // We must find at least 2 identical values to ensure we are at the right place in the siusoidal array...
  1450. while (!((signal2[index2] == signal1[1]) && (signal2[index2 + 1] == signal1[2]))) {
  1451. index2++;
  1452. if (index2 == 95999) {
  1453. printf("!!! ERROR !!! Data not found in connexion check of tie mode!\n");
  1454. break;
  1455. }
  1456. }
  1457. index1 = index2;
  1458. Log("Tie mode : Data founded at offset %i.\n", index2);
  1459. while (signal2[index2] == signal1[index2 - index1 + 1]) {
  1460. index2++;
  1461. if ((index2 == 95999) || ((index2 - index1 + 1) == 47999)) {
  1462. break;
  1463. }
  1464. }
  1465. Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
  1466. if ((index2 - index1) > 47995) {
  1467. Log("Data received in tie mode are valid...\n");
  1468. } else {
  1469. // in tie mode, the buffers adress should be the same for the two tied ports.
  1470. printf("!!! ERROR !!! data transmission seems not to be valid !\n");
  1471. printf("Links topology : (emitt) client2.out2 ----> client1.in1--(tie)--client1.out1----->client2.in2 (recive)\n");
  1472. printf(" port_name : Port_adress \n");
  1473. printf(" output_port1 : %px\n", jack_port_get_buffer(output_port1, cur_buffer_size));
  1474. printf(" input_port2 : %px\n", jack_port_get_buffer(input_port2, cur_buffer_size));
  1475. printf(" output_port2 : %px\n", jack_port_get_buffer(output_port2, cur_buffer_size));
  1476. printf(" input_port1 : %px\n", jack_port_get_buffer(input_port1, cur_buffer_size));
  1477. }
  1478. jack_port_untie(output_port1);
  1479. jack_port_disconnect(client1, output_port2);
  1480. jack_port_disconnect(client1, output_port1);
  1481. } //end of tie
  1482. /**
  1483. * Testing SUMMATION CAPABILITIES OF JACK CONNECTIONS
  1484. *
  1485. * In a short test, we just check a simple summation in jack.
  1486. * A first client(client1) send two signal in phase opposition
  1487. * A second client(client2) record the summation at one of his port
  1488. * So, the result must be zero...
  1489. * See process1 for details about steps of this test
  1490. *
  1491. */
  1492. // fprintf(file, "Sum test\n");
  1493. Log("Checking summation capabilities of patching...\n");
  1494. output_port1b = jack_port_register(client1, "out1b",
  1495. JACK_DEFAULT_AUDIO_TYPE,
  1496. JackPortIsOutput, 0);
  1497. jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2));
  1498. jack_connect(client2, jack_port_name(output_port1b), jack_port_name(input_port2));
  1499. process1_activated = 3;
  1500. process2_activated = -1;
  1501. for (g = 0; g < 96000; g++)
  1502. signal2[g] = 0.0;
  1503. index1 = 0;
  1504. index2 = 0;
  1505. Log("Sending datas...");
  1506. process2_activated = 3;
  1507. while (process2_activated == 3) {
  1508. jack_sleep(1 * 1000);
  1509. Log(".");
  1510. }
  1511. process1_activated = -1;
  1512. process2_activated = -1;
  1513. index2 = 0;
  1514. Log("\nAnalysing datas...\n"); // same idea as above, with first data check...
  1515. while (!((signal2[index2] == 0.0 ) && (signal2[(index2 + 1)] == 0.0 ))) {
  1516. index2++;
  1517. if (index2 == 95999) {
  1518. printf("!!! ERROR !!! Data not found in summation check!\n");
  1519. break;
  1520. }
  1521. }
  1522. index1 = index2;
  1523. Log("Data founded at offset %i.\n", index2);
  1524. while ( signal2[index2] == 0.0 ) {
  1525. index2++;
  1526. if ((index2 > 95998) || ((index2 - index1 + 1) > 47998)) {
  1527. break;
  1528. }
  1529. }
  1530. Log("Checking difference between datas...\n");
  1531. if ((index2 - index1) > 47996) {
  1532. Log("Data mixed received are valid...\nSummation is well done.\n");
  1533. } else {
  1534. printf("!!! ERROR !!! data transmission / summation seems not to be valid !\n");
  1535. }
  1536. jack_port_disconnect(client1, output_port1);
  1537. jack_port_disconnect(client1, output_port1b);
  1538. jack_port_unregister(client1, output_port1b);
  1539. if (jack_port_name(output_port1b) != NULL ) {
  1540. printf("!!! WARNING !!! port_name return something while the port have been unregistered !\n");
  1541. printf("!!! Name of unregistered port : %s !\n", jack_port_name(output_port1b));
  1542. } else {
  1543. Log("Checking jack_port_name() with a non valid port... ok\n");
  1544. }
  1545. if (jack_port_set_name(output_port1b, "new_name") == 0 ) {
  1546. printf("!!! WARNING !!! An unregistered port can be renamed successfully !\n");
  1547. } else {
  1548. Log("Checking renaming of an unregistered port... ok\n");
  1549. }
  1550. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1551. if (inports && jack_port_set_name(jack_port_by_name(client1, inports[0]), "new_name") == 0 ) {
  1552. printf("!!! WARNING !!! A PHYSICAL port can be renamed successfully !\n");
  1553. } else {
  1554. Log("Checking renaming of an unregistered port... ok\n");
  1555. }
  1556. jack_free (inports);
  1557. /**
  1558. * Checking latency issues
  1559. * here are simple latency check
  1560. * We simply check that the value returned by jack seems ok
  1561. * Latency compensation is a difficult point.
  1562. * Actually, jack is not able to see "thru" client to build a full latency chain.
  1563. * Ardour use theses informations to do internally his compensations.
  1564. *
  1565. * 3 test are done : one with no connections between client, one with a serial connection, and one with parallel connection
  1566. */
  1567. Log("Checking about latency functions...\n");
  1568. t_error = 0;
  1569. jack_recompute_total_latencies(client1);
  1570. Log("jack_recompute_total_latencies...\n");
  1571. if ((jack_port_get_latency (output_port1) != 0) ||
  1572. (jack_port_get_total_latency(client1, output_port1) != 0) ) {
  1573. t_error = 1;
  1574. printf("!!! ERROR !!! default latency of a non-PHY device is not set to zero !\n");
  1575. }
  1576. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1577. outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
  1578. if (inports && outports && inports[0] != NULL && outports[0] != NULL) {
  1579. output_ext_latency = jack_port_get_latency (jack_port_by_name(client1, inports[0])); // from client to out driver (which has "inputs" ports..)
  1580. input_ext_latency = jack_port_get_latency (jack_port_by_name(client1, outports[0])); // from in driver (which has "output" ports..) to client
  1581. if (output_ext_latency != jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0]))) {
  1582. t_error = 1;
  1583. printf("!!! ERROR !!! get_latency & get_all_latency for a PHY device (unconnected) didn't return the same value !\n");
  1584. }
  1585. Log("Checking a serial model with 2 clients...\n");
  1586. jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2));
  1587. jack_connect(client1, outports[0], jack_port_name(input_port1));
  1588. jack_connect(client2, jack_port_name(output_port2), inports[0]);
  1589. jack_port_set_latency(output_port2, 256);
  1590. jack_recompute_total_latencies(client1);
  1591. if ((jack_port_get_latency (output_port1) != 0) ||
  1592. (jack_port_get_total_latency(client1, output_port1) != 0) ||
  1593. (jack_port_get_latency (jack_port_by_name(client1, inports[0])) != (output_ext_latency)) ||
  1594. (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (output_ext_latency + 256)) ||
  1595. (jack_port_get_total_latency(client1, output_port2) != (output_ext_latency + 256)) ||
  1596. (jack_port_get_total_latency(client1, input_port2) != 0) ||
  1597. (jack_port_get_total_latency(client1, input_port1) != input_ext_latency) ||
  1598. (jack_port_get_latency (jack_port_by_name(client1, outports[0])) != input_ext_latency) ||
  1599. (jack_port_get_total_latency(client1, jack_port_by_name(client1, outports[0])) != input_ext_latency)
  1600. ) {
  1601. printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
  1602. printf("!!! get_latency(output_port1) : %i (must be 0)\n", jack_port_get_latency(output_port1));
  1603. printf("!!! get_total_latency(output_port1) : %i (must be 0)\n", jack_port_get_total_latency(client1, output_port1));
  1604. 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);
  1605. 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));
  1606. printf("!!! get_total_latency(output_port2) : %i (must be %i)\n", jack_port_get_total_latency(client1, output_port2), (output_ext_latency + 256));
  1607. printf("!!! get_total_latency(input_port2) : %i (must be 0)\n", jack_port_get_total_latency(client1, input_port2));
  1608. printf("!!! get_total_latency(input_port1) : %i (must be %i)\n", jack_port_get_total_latency(client1, input_port1), input_ext_latency);
  1609. printf("!!! get_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_latency(jack_port_by_name(client1, outports[0])), input_ext_latency);
  1610. 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);
  1611. } else {
  1612. Log("get_latency & get_total_latency seems quite ok...\n");
  1613. }
  1614. jack_port_disconnect(client1, output_port1);
  1615. jack_port_disconnect(client1, output_port2);
  1616. jack_port_disconnect(client1, input_port1);
  1617. jack_port_disconnect(client1, input_port2);
  1618. Log("Checking a parallel model with 2 clients...\n");
  1619. jack_connect(client2, outports[0], jack_port_name(input_port1));
  1620. jack_connect(client2, outports[0], jack_port_name(input_port2));
  1621. jack_connect(client2, jack_port_name(output_port1), inports[0]);
  1622. jack_connect(client2, jack_port_name(output_port2), inports[0]);
  1623. jack_port_set_latency(output_port1, 256);
  1624. jack_port_set_latency(output_port2, 512);
  1625. jack_recompute_total_latencies(client1);
  1626. if ((jack_port_get_latency(output_port1) != 256 ) ||
  1627. (jack_port_get_total_latency(client1, output_port1) != (256 + output_ext_latency)) ||
  1628. (jack_port_get_latency(output_port2) != 512) ||
  1629. (jack_port_get_total_latency(client1, output_port2) != (512 + output_ext_latency)) ||
  1630. (jack_port_get_latency(jack_port_by_name(client1, inports[0])) != output_ext_latency) ||
  1631. (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (512 + output_ext_latency))
  1632. ) {
  1633. printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
  1634. printf("!!! get_latency(output_port1) : %i (must be 256)\n", jack_port_get_latency(output_port1));
  1635. printf("!!! get_total_latency(output_port1) : %i (must be 256 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port1));
  1636. printf("!!! get_latency(output_port2) : %i (must 512)\n", jack_port_get_latency(output_port2));
  1637. printf("!!! get_total_latency(output_port2) : %i (must 512 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port2));
  1638. printf("!!! get_latency(inports[0])) : %i (must output_ext_latency)\n", jack_port_get_latency(jack_port_by_name(client1, inports[0])));
  1639. 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])));
  1640. } else {
  1641. Log("get_latency & get_total_latency seems quite ok...\n");
  1642. }
  1643. } else {
  1644. printf("No physical port founded : not able to test latency functions...");
  1645. }
  1646. jack_port_disconnect(client1, input_port1);
  1647. jack_port_disconnect(client1, input_port2);
  1648. jack_port_disconnect(client1, output_port1);
  1649. jack_port_disconnect(client1, output_port2);
  1650. jack_sleep(1000);
  1651. jack_free(inports);
  1652. jack_free(outports);
  1653. /**
  1654. * Checking transport API.
  1655. * Simple transport test.
  1656. * Check a transport start with a "slow" client, simulating a delay around 1 sec before becoming ready.
  1657. *
  1658. */
  1659. Log("-----------------------------------------------------------\n");
  1660. Log("---------------------------TRANSPORT-----------------------\n");
  1661. Log("-----------------------------------------------------------\n");
  1662. lineports = linecount;
  1663. if (transport_mode) {
  1664. int wait_count;
  1665. ts = jack_transport_query(client1, &pos);
  1666. if (ts == JackTransportStopped) {
  1667. Log("Transport is stopped...\n");
  1668. } else {
  1669. jack_transport_stop(client1);
  1670. Log("Transport state : %i\n", ts);
  1671. }
  1672. if (jack_set_sync_callback(client2, Jack_Sync_Callback, 0) != 0) {
  1673. printf("error while calling set_sync_callback...\n");
  1674. }
  1675. Log("starting transport...\n");
  1676. starting_state = 1; // Simulate starting state
  1677. jack_transport_start(client1);
  1678. // Wait until sync callback is called
  1679. while (!(sync_called)) {
  1680. jack_sleep(1 * 1000);
  1681. }
  1682. // Wait untill rolling : simulate sync time out
  1683. Log("Simulate a slow-sync client exceeding the time-out\n");
  1684. wait_count = 0;
  1685. do {
  1686. jack_sleep(100); // Wait 100 ms each cycle
  1687. wait_count++;
  1688. if (wait_count == 100) {
  1689. Log("!!! ERROR !!! max time-out exceedeed : sync time-out does not work correctly\n");
  1690. break;
  1691. }
  1692. ts = jack_transport_query(client2, &pos);
  1693. Log("Waiting....pos = %ld\n", pos.frame);
  1694. display_transport_state();
  1695. } while (ts != JackTransportRolling);
  1696. Log("Sync callback have been called %i times.\n", sync_called);
  1697. jack_transport_stop(client1);
  1698. // Wait until stopped
  1699. ts = jack_transport_query(client2, &pos);
  1700. while (ts != JackTransportStopped) {
  1701. jack_sleep(1 * 1000);
  1702. ts = jack_transport_query(client2, &pos);
  1703. }
  1704. // Simulate starting a slow-sync client that rolls after 0.5 sec
  1705. Log("Simulate a slow-sync client that needs 0.5 sec to start\n");
  1706. sync_called = 0;
  1707. wait_count = 0;
  1708. starting_state = 1; // Simulate starting state
  1709. Log("Starting transport...\n");
  1710. jack_transport_start(client1);
  1711. display_transport_state();
  1712. Log("Waiting 0.5 sec...\n");
  1713. jack_sleep(500);
  1714. starting_state = 0; // Simulate end of starting state after 0.5 sec
  1715. // Wait untill rolling
  1716. ts = jack_transport_query(client2, &pos);
  1717. while (ts != JackTransportRolling) {
  1718. jack_sleep(100); // Wait 100 ms each cycle
  1719. wait_count++;
  1720. if (wait_count == 10) {
  1721. Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
  1722. break;
  1723. }
  1724. ts = jack_transport_query(client2, &pos);
  1725. }
  1726. if (sync_called == 0) {
  1727. Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
  1728. }
  1729. Log("Sync callback have been called %i times.\n", sync_called);
  1730. display_transport_state();
  1731. // Test jack_transport_locate while rolling
  1732. Log("Test jack_transport_locate while rolling\n");
  1733. ts = jack_transport_query(client2, &pos);
  1734. Log("Transport current frame = %ld\n", pos.frame);
  1735. jack_nframes_t cur_frame = pos.frame;
  1736. wait_count = 0;
  1737. do {
  1738. display_transport_state();
  1739. jack_sleep(10); // 10 ms
  1740. // locate at first...
  1741. wait_count++;
  1742. if (wait_count == 1) {
  1743. Log("Do jack_transport_locate\n");
  1744. jack_transport_locate(client1, cur_frame / 2);
  1745. } else if (wait_count == 100) {
  1746. break;
  1747. }
  1748. ts = jack_transport_query(client2, &pos);
  1749. Log("Locating.... frame = %ld\n", pos.frame);
  1750. } while (pos.frame > cur_frame);
  1751. ts = jack_transport_query(client2, &pos);
  1752. Log("Transport current frame = %ld\n", pos.frame);
  1753. if (wait_count == 100) {
  1754. printf("!!! ERROR !!! jack_transport_locate does not work correctly\n");
  1755. }
  1756. // Test jack_transport_reposition while rolling
  1757. Log("Test jack_transport_reposition while rolling\n");
  1758. ts = jack_transport_query(client2, &pos);
  1759. Log("Transport current frame = %ld\n", pos.frame);
  1760. cur_frame = pos.frame;
  1761. wait_count = 0;
  1762. do {
  1763. display_transport_state();
  1764. jack_sleep(10); // 10 ms
  1765. // locate at first...
  1766. wait_count++;
  1767. if (wait_count == 1) {
  1768. Log("Do jack_transport_reposition\n");
  1769. request_pos.frame = cur_frame / 2;
  1770. jack_transport_reposition(client1, &request_pos);
  1771. } else if (wait_count == 100) {
  1772. break;
  1773. }
  1774. ts = jack_transport_query(client2, &pos);
  1775. Log("Locating.... frame = %ld\n", pos.frame);
  1776. } while (pos.frame > cur_frame);
  1777. ts = jack_transport_query(client2, &pos);
  1778. Log("Transport current frame = %ld\n", pos.frame);
  1779. if (wait_count == 100) {
  1780. printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
  1781. }
  1782. // Test jack_transport_reposition while stopped
  1783. jack_transport_stop(client1);
  1784. ts = jack_transport_query(client2, &pos);
  1785. Log("Transport current frame = %ld\n", pos.frame);
  1786. Log("Test jack_transport_reposition while stopped\n");
  1787. wait_count = 0;
  1788. request_pos.frame = 10000;
  1789. jack_transport_reposition(client1, &request_pos);
  1790. do {
  1791. display_transport_state();
  1792. jack_sleep(100); // 100 ms
  1793. if (wait_count++ == 10)
  1794. break;
  1795. ts = jack_transport_query(client2, &pos);
  1796. Log("Locating.... frame = %ld\n", pos.frame);
  1797. } while (pos.frame != 10000);
  1798. ts = jack_transport_query(client2, &pos);
  1799. Log("Transport current frame = %ld\n", pos.frame);
  1800. if (pos.frame != 10000) {
  1801. printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
  1802. }
  1803. jack_transport_stop(client1);
  1804. /* Tell the JACK server that we are ready to roll. Our
  1805. * process() callback will start running now. */
  1806. } else {
  1807. printf("Transport check is disabled...\n");
  1808. }
  1809. time_before_exit = time_to_run;
  1810. while (time_before_exit != 0) {
  1811. jack_sleep (1 * 1000);
  1812. time_before_exit--;
  1813. }
  1814. if (jack_deactivate(client2) != 0) {
  1815. printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
  1816. }
  1817. if (jack_deactivate(client1) != 0) {
  1818. printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
  1819. }
  1820. /**
  1821. * Checking jack_frame_time.
  1822. */
  1823. Log("Testing jack_frame_time...\n");
  1824. jack_set_process_callback(client1, process4, client1);
  1825. jack_activate(client1);
  1826. jack_sleep(2 * 1000);
  1827. /**
  1828. * Checking jack_get_cycle_times.
  1829. */
  1830. Log("Testing jack_get_cycle_times...\n");
  1831. jack_deactivate(client1);
  1832. jack_set_process_callback(client1, process5, client1);
  1833. jack_activate(client1);
  1834. jack_sleep(3 * 1000);
  1835. /**
  1836. * Checking alternate thread model
  1837. */
  1838. Log("Testing alternate thread model...\n");
  1839. jack_deactivate(client1);
  1840. jack_set_process_callback(client1, NULL, NULL); // remove callback
  1841. jack_set_process_thread(client1, jack_thread, client1);
  1842. jack_activate(client1);
  1843. jack_sleep(2 * 1000);
  1844. /**
  1845. * Checking callback exiting : when the return code is != 0, the client is desactivated.
  1846. */
  1847. Log("Testing callback exiting...\n");
  1848. jack_deactivate(client1);
  1849. jack_set_process_thread(client1, NULL, NULL); // remove thread callback
  1850. jack_set_process_callback(client1, process3, 0);
  1851. jack_activate(client1);
  1852. jack_sleep(3 * 1000);
  1853. /**
  1854. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1855. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1856. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1857. Closing program
  1858. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1859. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1860. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1861. */
  1862. if (jack_deactivate(client2) != 0) {
  1863. printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
  1864. }
  1865. if (jack_deactivate(client1) != 0) {
  1866. printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
  1867. }
  1868. if (jack_client_close(client2) != 0) {
  1869. printf("!!! ERROR !!! jack_client_close does not return 0 for client2 !\n");
  1870. }
  1871. if (jack_client_close(client1) != 0) {
  1872. printf("!!! ERROR !!! jack_client_close does not return 0 for client1 !\n");
  1873. }
  1874. if (xrun == 0) {
  1875. Log("No Xrun have been detected during this test... cool !\n");
  1876. } else {
  1877. printf("%i Xrun have been detected during this session (seen callback messages to see where are the problems).\n", xrun);
  1878. }
  1879. free(framecollect);
  1880. free(signal1);
  1881. free(signal2);
  1882. Log("Exiting jack_test...\n");
  1883. fclose(file);
  1884. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  1885. sprintf (filename, "framegraph-%i.gnu", cur_buffer_size);
  1886. file = fopen(filename, "w");
  1887. if (file == NULL) {
  1888. fprintf(stderr, "Error while opening file");
  1889. exit(-1);
  1890. }
  1891. fprintf(file, "reset\n");
  1892. fprintf(file, "set terminal png transparent nocrop enhanced\n");
  1893. fprintf(file, "set output 'framegraph-%i-1.png'\n", cur_buffer_size);
  1894. fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
  1895. 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));
  1896. fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
  1897. fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
  1898. fprintf(file, "set xlabel \"FrameTime\"\n");
  1899. 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);
  1900. 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);
  1901. fprintf(file, "set output 'framegraph-%i-2.png'\n", cur_buffer_size);
  1902. fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
  1903. 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)));
  1904. fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
  1905. fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
  1906. fprintf(file, "set xlabel \"FrameTime\"\n");
  1907. 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);
  1908. 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);
  1909. fclose(file);
  1910. return 0;
  1911. }