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.

2140 lines
83KB

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