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.

2154 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. 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. // "jack_client_name_size" - 1 effective characters
  661. for (int i = 0; i < jack_client_name_size() - 1; i++) {
  662. client_name3[i] = 'A';
  663. }
  664. // And last one is the terminating '0'
  665. client_name3[jack_client_name_size()] = 0;
  666. Log("trying to register a new jackd client with maximum possible client name size...\n", client_name3);
  667. client2 = jack_client_open(client_name3, jack_options, &status, server_name);
  668. if (client2 != NULL) {
  669. Log ("valid : a client with maximum possible client name size can be opened\n");
  670. jack_client_close(client2);
  671. } else {
  672. printf("!!! ERROR !!! opening a client with maximum possible client name size does not work!\n");
  673. }
  674. /**
  675. * testing client name...
  676. * Verify that the name sended at registration and the one returned by jack server is the same...
  677. *
  678. */
  679. Log("Testing name...");
  680. client_name2 = jack_get_client_name(client1);
  681. if (strcmp(client_name1, client_name2) == 0) {
  682. Log(" ok\n");
  683. } else {
  684. printf("\n!!! ERROR !!! name returned different from the one given : %s\n", client_name2);
  685. }
  686. /**
  687. * Test RT mode...
  688. * verify if the real time mode returned by jack match the optional argument defined when launching jack_test*/
  689. if (jack_is_realtime(client1) == RT) {
  690. Log("Jackd is in realtime mode (RT = %i).\n", RT);
  691. } else {
  692. printf("!!! ERROR !!! Jackd is in a non-expected realtime mode (RT = %i).\n", RT);
  693. }
  694. /**
  695. * Register all callbacks...
  696. *
  697. */
  698. if (jack_set_thread_init_callback(client1, Jack_Thread_Init_Callback, 0) != 0) {
  699. printf("!!! ERROR !!! while calling jack_set_thread_init_callback()...\n");
  700. }
  701. if (jack_set_freewheel_callback(client1, Jack_Freewheel_Callback, 0) != 0 ) {
  702. printf("\n!!! ERROR !!! while calling jack_set_freewheel_callback()...\n");
  703. }
  704. if (jack_set_process_callback(client1, process1, 0) != 0) {
  705. printf("Error when calling jack_set_process_callback() !\n");
  706. }
  707. jack_on_shutdown(client1, jack_shutdown, 0);
  708. if (jack_on_info_shutdown) {
  709. jack_on_info_shutdown(client1, jack_info_shutdown, 0);
  710. }
  711. if (jack_set_buffer_size_callback(client1, Jack_Update_Buffer_Size, 0) != 0) {
  712. printf("Error when calling buffer_size_callback !\n");
  713. }
  714. if (jack_set_graph_order_callback(client1, Jack_Graph_Order_Callback, 0) != 0) {
  715. printf("Error when calling Jack_Graph_Order_Callback() !\n");
  716. }
  717. if (jack_set_port_rename_callback(client1, Jack_Port_Rename_Callback, 0) != 0 )
  718. printf("\n!!! ERROR !!! while calling jack_set_rename_callback()...\n");
  719. if (jack_set_xrun_callback(client1, Jack_XRun_Callback, 0 ) != 0) {
  720. printf("Error when calling jack_set_xrun_callback() !\n");
  721. }
  722. if (jack_set_sample_rate_callback(client1, Jack_Sample_Rate_Callback, 0 ) != 0) {
  723. printf("Error when calling Jack_Sample_Rate_Callback() !\n");
  724. }
  725. if (jack_set_port_registration_callback(client1, Jack_Port_Register, 0) != 0) {
  726. printf("Error when calling jack_set_port_registration_callback() !\n");
  727. }
  728. if (jack_set_port_connect_callback(client1, Jack_Port_Connect, 0) != 0) {
  729. printf("Error when calling jack_set_port_connect_callback() !\n");
  730. }
  731. if (jack_set_client_registration_callback(client1, Jack_Client_Registration_Callback, 0) != 0) {
  732. printf("Error when calling jack_set_client_registration_callback() !\n");
  733. }
  734. jack_set_error_function(Jack_Error_Callback);
  735. /**
  736. * Create file for clock "frame time" analysis
  737. *
  738. */
  739. cur_buffer_size = jack_get_buffer_size(client1);
  740. sprintf (filename, "framefile-%i.dat", cur_buffer_size);
  741. file = fopen(filename, "w");
  742. if (file == NULL) {
  743. fprintf(stderr, "Error when opening framefile.dat log file");
  744. exit(-1);
  745. }
  746. /**
  747. * Try to register a client with a NULL name/zero length name...
  748. *
  749. */
  750. output_port1 = jack_port_register(client1, nullportname,
  751. JACK_DEFAULT_AUDIO_TYPE,
  752. JackPortIsOutput, 0);
  753. if (output_port1 == NULL) {
  754. Log("Can't register a port with a NULL portname... ok.\n");
  755. } else {
  756. printf("!!! ERROR !!! Can register a port with a NULL portname !\n");
  757. jack_port_unregister(client1, output_port1);
  758. }
  759. /**
  760. * Register 1 port in order to stress other functions.
  761. *
  762. */
  763. output_port1 = jack_port_register(client1, portname,
  764. JACK_DEFAULT_AUDIO_TYPE,
  765. JackPortIsOutput, 0);
  766. if (output_port1 == NULL) {
  767. printf("!!! ERROR !!! Can't register any port for the client !\n");
  768. exit(1);
  769. }
  770. /**
  771. * Test port type of the just registered port.
  772. *
  773. */
  774. if (strcmp(jack_port_type(output_port1), JACK_DEFAULT_AUDIO_TYPE) != 0) {
  775. printf("!!! ERROR !!! jack_port_type returns an incorrect value!\n");
  776. } else {
  777. Log("Checking jack_port_type()... ok.\n");
  778. }
  779. /**
  780. * Try to register another port with the same name...
  781. *
  782. */
  783. output_port2 = jack_port_register(client1, portname,
  784. JACK_DEFAULT_AUDIO_TYPE,
  785. JackPortIsOutput, 0);
  786. if (output_port2 == NULL) {
  787. Log("Can't register two ports with the same name... ok\n");
  788. } else {
  789. if (strcmp (jack_port_name(output_port1), jack_port_name(output_port2)) == 0) {
  790. printf("!!! ERROR !!! Can register two ports with the same name ! (%px : %s & %px : %s).\n", output_port1, jack_port_name(output_port1), output_port2, jack_port_name(output_port2));
  791. jack_port_unregister(client1, output_port2);
  792. } else {
  793. Log("Can't register two ports with the same name... ok (auto-rename %s into %s).\n", jack_port_name(output_port1), jack_port_name(output_port2));
  794. jack_port_unregister(client1, output_port2);
  795. }
  796. }
  797. /**
  798. * Verify that both port_name and port_short_name return correct results...
  799. *
  800. */
  801. sprintf (portname, "%s:%s", jack_get_client_name(client1), jack_port_short_name(output_port1));
  802. if (strcmp(jack_port_name(output_port1), portname) != 0) {
  803. printf("!!! ERROR !!! functions jack_port_name and/or jack_short_port_name seems to be invalid !\n");
  804. 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));
  805. }
  806. /**
  807. * Verify the function port_set_name
  808. *
  809. */
  810. if (jack_port_set_name (output_port1, "renamed-port#") == 0 ) {
  811. if (strcmp(jack_port_name(output_port1), "renamed-port#") == 0) {
  812. printf("!!! ERROR !!! functions jack_port_set_name seems to be invalid !\n");
  813. printf("jack_port_name return '%s' whereas 'renamed-port#' was expected...\n", jack_port_name(output_port1));
  814. } else {
  815. Log("Checking jack_port_set_name()... ok\n");
  816. jack_port_set_name (output_port1, "port");
  817. }
  818. } else {
  819. printf("error : port_set_name function can't be tested...\n");
  820. }
  821. /**
  822. * Verify if a port can be registered with maximum port name size (that is "short name")
  823. *
  824. */
  825. int short_port_size_max = jack_port_name_size() - jack_client_name_size() - 1; // Port is of shape: "client_name:port_name"
  826. char port_name3[short_port_size_max];
  827. // "short_port_size_max" - 1 effective characters
  828. for (int i = 0; i < short_port_size_max - 1; i++) {
  829. port_name3[i] = 'A';
  830. }
  831. // And last one is the terminating '0'
  832. port_name3[short_port_size_max] = 0;
  833. jack_port_t * test_max_port = jack_port_register(client1, port_name3,
  834. JACK_DEFAULT_AUDIO_TYPE,
  835. JackPortIsOutput, 0);
  836. if (test_max_port != NULL) {
  837. Log ("valid : a port with maximum possible port name size can be registered\n");
  838. jack_port_unregister(client1, test_max_port);
  839. } else {
  840. printf("!!! ERROR !!! registering a port with maximum possible port name size does not work!\n");
  841. }
  842. port_callback_reg = 0; // number of port registration received by the callback
  843. /**
  844. * Activate the client
  845. *
  846. */
  847. if (jack_activate(client1) < 0) {
  848. printf ("Fatal error : cannot activate client1\n");
  849. exit(1);
  850. }
  851. /**
  852. * Test if port rename callback have been called.
  853. *
  854. */
  855. jack_port_set_name (output_port1, "renamed-port#");
  856. jack_sleep(1 * 1000);
  857. if (port_rename_clbk == 0) {
  858. printf("!!! ERROR !!! Jack_Port_Rename_Callback was not called !!.\n");
  859. }
  860. /**
  861. * Test if port registration callback have been called.
  862. *
  863. */
  864. jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
  865. if (1 == port_callback_reg) {
  866. Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", 1, port_callback_reg);
  867. } else {
  868. printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", 1, port_callback_reg);
  869. }
  870. /**
  871. * Test if init callback initThread have been called.
  872. *
  873. */
  874. if (init_clbk == 0) {
  875. printf("!!! ERROR !!! Jack_Thread_Init_Callback was not called !!.\n");
  876. }
  877. jack_sleep(10 * 1000); // test see the clock in the graph at the begining...
  878. /**
  879. * Stress Freewheel mode...
  880. * Try to enter freewheel mode. Check the realtime mode de-activation.
  881. * Check that the number of call of the process callback is greater than in non-freewheel mode.
  882. * Give an approximated speed ratio (number of process call) between the two modes.
  883. * Then return in normal mode.
  884. */
  885. t_error = 0;
  886. activated = 0;
  887. jack_sleep(1 * 1000);
  888. count1 = activated;
  889. Log("Testing activation freewheel mode...\n");
  890. linefw = linecount; // count for better graph reading with gnuplot
  891. jack_set_freewheel(client1, 1);
  892. activated = 0;
  893. jack_sleep(1 * 1000);
  894. count2 = activated;
  895. if (jack_is_realtime(client1) == 0) {
  896. t_error = 0;
  897. } else {
  898. printf("\n!!! ERROR !!! RT mode is always activated while freewheel mode is applied !\n");
  899. t_error = 1;
  900. }
  901. if (activated == 0) {
  902. printf("!!! ERROR !!! Freewheel mode doesn't activate audio callback !!\n");
  903. }
  904. jack_set_freewheel(client1, 0);
  905. jack_sleep(7 * 1000);
  906. if (jack_is_realtime(client1) == 1) {
  907. } else {
  908. printf("\n!!! ERROR !!! freewheel mode fail to reactivate RT mode when exiting !\n");
  909. t_error = 1;
  910. }
  911. if (t_error == 0) {
  912. Log("Freewheel mode appears to work well...\n");
  913. }
  914. if (count1 == 0) {
  915. Log("Audio Callback in 'standard' (non-freewheel) mode seems not to be called...\n");
  916. Log("Ratio speed would be unavailable...\n");
  917. } else {
  918. ratio = (float) ((count2 - count1) / count1);
  919. Log("Approximative speed ratio of freewheel mode = %f : 1.00\n", ratio);
  920. }
  921. /**
  922. * Stress buffer function...
  923. * get current buffer size.
  924. * Try to apply a new buffer size value ( 2 x the precedent buffer size value)
  925. * Then return in previous buffer size mode.
  926. *
  927. */
  928. float factor = 0.5f;
  929. old_buffer_size = jack_get_buffer_size(client1);
  930. Log("Testing BufferSize change & Callback...\n--> Current buffer size : %d.\n", old_buffer_size);
  931. linebuf = linecount;
  932. if (jack_set_buffer_size(client1, (jack_nframes_t)(old_buffer_size * factor)) < 0) {
  933. printf("!!! ERROR !!! jack_set_buffer_size fails !\n");
  934. }
  935. jack_sleep(1 * 1000);
  936. cur_buffer_size = jack_get_buffer_size(client1);
  937. if (abs((old_buffer_size * factor) - cur_buffer_size) > 5) { // Tolerance needed for dummy driver...
  938. printf("!!! ERROR !!! Buffer size has not been changed !\n");
  939. printf("!!! Maybe jack was compiled without the '--enable-resize' flag...\n");
  940. } else {
  941. Log("jack_set_buffer_size() command successfully applied...\n");
  942. }
  943. jack_sleep(3 * 1000);
  944. jack_set_buffer_size(client1, old_buffer_size);
  945. cur_buffer_size = jack_get_buffer_size(client1);
  946. /**
  947. * Test the last regestered port to see if port_is_mine function the right value.
  948. * A second test will be performed later.
  949. * The result will be printed at the end.
  950. *
  951. */
  952. if (jack_port_is_mine(client1, output_port1)) {
  953. is_mine = 1;
  954. } else {
  955. is_mine = 0;
  956. }
  957. /**
  958. * Check that the ID returned by the port_by_name is right.
  959. * (it seems there is a problem here in some jack versions).
  960. *
  961. */
  962. if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
  963. printf("!!! ERROR !!! function jack_port_by_name() return bad value !\n");
  964. 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);
  965. } else {
  966. Log("Checking jack_port_by_name() return value... ok\n");
  967. }
  968. if (NULL != jack_port_by_name(client1, jack_port_short_name(output_port1))) {
  969. 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)));
  970. } else {
  971. Log("Checking jack_port_by_name() with bad argument... ok (returned id 0)\n");
  972. }
  973. /**
  974. * remove the output port previously created
  975. * no more ports should subsist here for our client.
  976. *
  977. */
  978. if (jack_port_unregister(client1, output_port1) != 0) {
  979. printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
  980. }
  981. /**
  982. * list all in ports
  983. *
  984. */
  985. inports = jack_get_ports(client1, NULL, NULL, 0);
  986. /**
  987. * Test the first PHY (physical) connection to see if it's "mine".
  988. * and report the result in the test that began before.
  989. * The result is printed later.
  990. *
  991. */
  992. if (jack_port_is_mine(client1, jack_port_by_name(client1, inports[0]))) {
  993. is_mine = 0;
  994. }
  995. /**
  996. * List all devices' flags and print them...
  997. *
  998. */
  999. Log("\nTry functions jack_get_ports, jack_port_flag & jack_port_by_name to list PHY devices...\n");
  1000. Log("-----------------------------------------------------------\n");
  1001. Log("---------------------------DEVICES-------------------------\n");
  1002. Log("-----------------------------------------------------------\n");
  1003. a = 0;
  1004. while (inports[a] != NULL) {
  1005. flag = jack_port_flags(jack_port_by_name(client1, inports[a]) );
  1006. Log(" * %s (id : %i)\n", inports[a], jack_port_by_name(client1, inports[a]));
  1007. Log(" (");
  1008. if (flag & JackPortIsInput)
  1009. Log("JackPortIsInput ");
  1010. if (flag & JackPortIsOutput)
  1011. Log("JackPortIsOutput ");
  1012. if (flag & JackPortIsPhysical)
  1013. Log("JackPortIsPhysical ");
  1014. if (flag & JackPortCanMonitor)
  1015. Log("JackPortCanMonitor ");
  1016. if (flag & JackPortIsTerminal)
  1017. Log("JackPortIsTerminal ");
  1018. Log(")\n\n");
  1019. a++;
  1020. }
  1021. Log("-----------------------------------------------------------\n\n");
  1022. /**
  1023. * list all PHY in/out ports...
  1024. * This list will be used later many times.
  1025. *
  1026. */
  1027. outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
  1028. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1029. if (outports == NULL) {
  1030. printf("!!! WARNING !!! no physical capture ports founded !\n");
  1031. }
  1032. if (inports == NULL) {
  1033. printf("!!! WARNING !!! no physical output ports founded !\n");
  1034. }
  1035. /**
  1036. * Brute test : try to create as many ports as possible.
  1037. * It stops when jack returns an error.
  1038. * Then try to connect each port to physical entry...
  1039. * Check also that graph reorder callback is called.
  1040. *
  1041. */
  1042. Log("Registering as many ports as possible and connect them to physical entries...\n");
  1043. lineports = linecount;
  1044. t_error = 0;
  1045. i = 0; // number of couple 'input-ouput'
  1046. j = 0; // number of ports created
  1047. port_callback_reg = 0; // number of port registration received by the callback
  1048. reorder = 0; // number of graph reorder callback activation
  1049. test_link = 0 ; // Test the "overconnect" function only one time
  1050. while (t_error == 0) {
  1051. sprintf (portname, "input_%d", i);
  1052. input_port1 = jack_port_register(client1, portname,
  1053. JACK_DEFAULT_AUDIO_TYPE,
  1054. JackPortIsInput, 0);
  1055. j++;
  1056. if (input_port1 == NULL) {
  1057. j--;
  1058. t_error = 1;
  1059. } else {
  1060. // Connect created input to PHY output
  1061. a = 0;
  1062. while (outports && outports[a] != NULL) {
  1063. if (jack_connect(client1, outports[a], jack_port_name(input_port1))) {
  1064. printf ("error : cannot connect input PHY port to client port %s\n", jack_port_name(input_port1));
  1065. } else {
  1066. // printf ("input PHY port %s connected to client port %s\n", outports[a], jack_port_name(input_port1));
  1067. }
  1068. a++;
  1069. }
  1070. // Try one time to "overconnect" 2 ports (the latest created)...
  1071. if (test_link == 0 && outports && ((a - 1) > 0) && outports[a - 1]) {
  1072. if (jack_connect(client1, outports[a - 1], jack_port_name(input_port1)) == EEXIST) {
  1073. // cannot over-connect input PHY port to client port. ok.
  1074. test_link = 1;
  1075. }
  1076. }
  1077. }
  1078. sprintf(portname, "output_%d", i);
  1079. output_port1 = jack_port_register(client1, portname,
  1080. JACK_DEFAULT_AUDIO_TYPE,
  1081. JackPortIsOutput, 0);
  1082. j++;
  1083. if (output_port1 == NULL) {
  1084. t_error = 1;
  1085. j--;
  1086. } else {
  1087. // Connect created input to PHY output
  1088. a = 0;
  1089. while (inports && inports[a] != NULL) {
  1090. if (jack_connect(client1, jack_port_name(output_port1), inports[a])) {
  1091. printf ("error : cannot connect input PHY port %s to client port %s\n", inports[a], jack_port_name(output_port1));
  1092. } else {
  1093. // output PHY port %s connected to client port. ok.
  1094. }
  1095. a++;
  1096. }
  1097. // Try one time to "overconnect" 2 ports (the latest created)...
  1098. if (test_link == 0 && inports && ((a - 1) > 0) && inports[a - 1]) {
  1099. if (jack_connect(client1, jack_port_name(output_port1), inports[a - 1]) == EEXIST) {
  1100. // cannot over-connect output PHY port to client port. ok.
  1101. test_link = 1;
  1102. }
  1103. }
  1104. }
  1105. i++;
  1106. }
  1107. jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
  1108. // Check port registration callback
  1109. if (j == port_callback_reg) {
  1110. Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j, port_callback_reg);
  1111. } else {
  1112. printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j, port_callback_reg);
  1113. }
  1114. if (reorder == (2 * j)) {
  1115. Log("%i graph reorder callback have been received... ok\n", reorder);
  1116. } else {
  1117. printf("!!! ERROR !!! %i graph reorder callback have been received (maybe non-valid value)...\n", reorder);
  1118. }
  1119. /**
  1120. * print basic test connection functions result ...
  1121. * over-connected means here that we try to connect 2 ports that are already connected.
  1122. *
  1123. */
  1124. if (test_link) {
  1125. Log("Jack links can't be 'over-connected'... ok\n");
  1126. } else {
  1127. printf("!!! ERROR !!! Jack links can be 'over-connected'...\n");
  1128. }
  1129. /**
  1130. * Print the result of the two jack_is_mine test.
  1131. *
  1132. */
  1133. if (is_mine == 1) {
  1134. Log("Checking jack_port_is_mine()... ok\n");
  1135. } else {
  1136. printf("!!! ERROR !!! jack_port_is_mine() function seems to send non-valid datas !\n");
  1137. }
  1138. /**
  1139. * Free the array of the physical input and ouput ports.
  1140. * (as mentionned in the doc of jack_get_ports)
  1141. *
  1142. */
  1143. jack_free(inports);
  1144. jack_free(outports);
  1145. /**
  1146. * Try to "reactivate" the client whereas it's already activated...
  1147. *
  1148. */
  1149. if (jack_activate(client1) < 0) {
  1150. printf("!!! ERROR !!! Cannot activate client1 a second time...\n");
  1151. exit(1);
  1152. } else {
  1153. Log("jackd server accept client.jack_activate() re-activation (while client was already activated).\n");
  1154. }
  1155. /**
  1156. * Deregister all ports previously created.
  1157. *
  1158. */
  1159. port_callback_reg = 0; // to check registration callback
  1160. Log("Deregistering all ports of the client...\n");
  1161. inports = jack_get_ports(client1, NULL, NULL, 0);
  1162. a = 0;
  1163. while (inports[a] != NULL) {
  1164. flag = jack_port_flags(jack_port_by_name(client1, inports[a]));
  1165. input_port1 = jack_port_by_name(client1, inports[a]);
  1166. if (jack_port_is_mine(client1, input_port1)) {
  1167. if (jack_port_unregister(client1, input_port1) != 0) {
  1168. printf("!!! ERROR !!! while unregistering port %s.\n", jack_port_name(output_port1));
  1169. }
  1170. }
  1171. a++;
  1172. }
  1173. jack_sleep(1 * 1000); // To hope all port registration and reorder callback have been received...
  1174. // Check port registration callback again
  1175. if (j == port_callback_reg) {
  1176. Log("%i ports have been successfully created, and %i callback reg ports have been received... ok\n", j, port_callback_reg);
  1177. } else {
  1178. printf("!!! ERROR !!! %i ports have been created, and %i callback reg ports have been received !\n", j, port_callback_reg);
  1179. }
  1180. jack_free(inports); // free array of ports (as mentionned in the doc of jack_get_ports)
  1181. /**
  1182. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1183. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1184. Open a new client (second one) to test some other things...
  1185. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1186. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1187. */
  1188. Log("\n\n----------------------------------------------------------------------\n");
  1189. Log("Starting second new client 'jack_test_#2'...\n");
  1190. /* open a client connection to the JACK server */
  1191. client_name2 = "jack_test_#2";
  1192. linecl2 = linecount; // reminders for graph analysis
  1193. client2 = jack_client_new(client_name2);
  1194. if (client2 == NULL) {
  1195. fprintf(stderr, "jack_client_new() failed for %s.\n"
  1196. "status = 0x%2.0x\n", client_name2, status);
  1197. if (status & JackServerFailed) {
  1198. fprintf(stderr, "Unable to connect client2 to JACK server\n");
  1199. }
  1200. exit(1);
  1201. }
  1202. // Check client registration callback after jack_client_new
  1203. jack_sleep(2000);
  1204. if (client_register == 0) {
  1205. printf("!!! ERROR !!! Client registration callback not called for an opened client !\n");
  1206. }
  1207. // Check client registration callback after jack_client_close
  1208. jack_client_close(client2);
  1209. jack_sleep(2000);
  1210. if (client_register == 1) {
  1211. printf("!!! ERROR !!! Client registration callback not called for a closed client!\n");
  1212. }
  1213. // Open client2 again...
  1214. client2 = jack_client_new(client_name2);
  1215. /**
  1216. * Register callback for this client.
  1217. * Callbacks are the same as the first client for most of them, excepted for process audio callback.
  1218. *
  1219. */
  1220. jack_set_port_registration_callback(client2, Jack_Port_Register, 0);
  1221. jack_set_process_callback(client2, process2, 0);
  1222. jack_on_shutdown(client2, jack_shutdown, 0);
  1223. /**
  1224. * Register one input and one output for each client.
  1225. *
  1226. */
  1227. Log("registering 1 input/output ports for each client...\n");
  1228. output_port1 = jack_port_register(client1, "out1",
  1229. JACK_DEFAULT_AUDIO_TYPE,
  1230. JackPortIsOutput, 0);
  1231. output_port2 = jack_port_register(client2, "out2",
  1232. JACK_DEFAULT_AUDIO_TYPE,
  1233. JackPortIsOutput, 0);
  1234. input_port1 = jack_port_register(client1, "in1",
  1235. JACK_DEFAULT_AUDIO_TYPE,
  1236. JackPortIsInput, 0);
  1237. input_port2 = jack_port_register(client2, "in2",
  1238. JACK_DEFAULT_AUDIO_TYPE,
  1239. JackPortIsInput, 0);
  1240. if ((output_port1 == NULL) || (output_port2 == NULL) || (input_port1 == NULL) || (input_port2 == NULL)) {
  1241. printf("!!! ERROR !!! Unable to register ports...\n");
  1242. }
  1243. /**
  1244. * Set each process mode to idle and activate client2
  1245. *
  1246. */
  1247. process2_activated = -1;
  1248. process1_activated = -1;
  1249. if (jack_activate(client2) < 0) {
  1250. printf("Fatal error : cannot activate client2\n");
  1251. exit(1);
  1252. }
  1253. /**
  1254. * Connect the two clients and check that all connections are well-done.
  1255. *
  1256. */
  1257. Log("Testing connections functions between clients...\n");
  1258. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
  1259. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1260. }
  1261. if (jack_connect(client2, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1262. printf("!!! ERROR !!! while client2 intenting to connect ports...\n");
  1263. }
  1264. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
  1265. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1266. }
  1267. /**
  1268. * Test the port_connected function...
  1269. *
  1270. */
  1271. if ((jack_port_connected(output_port1) == jack_port_connected(input_port1)) &&
  1272. (jack_port_connected(output_port2) == jack_port_connected(input_port2)) &&
  1273. (jack_port_connected(output_port2) == 1) &&
  1274. (jack_port_connected(output_port1) == 2)
  1275. ) {
  1276. Log("Checking jack_port_connected()... ok.\n");
  1277. } else {
  1278. printf("!!! ERROR !!! function jack_port_connected() return a bad value !\n");
  1279. printf("jack_port_connected(output_port1) %d\n", jack_port_connected(output_port1));
  1280. printf("jack_port_connected(output_port2) %d\n", jack_port_connected(output_port2));
  1281. printf("jack_port_connected(input_port1) %d\n", jack_port_connected(input_port1));
  1282. printf("jack_port_connected(input_port2) %d\n", jack_port_connected(input_port2));
  1283. }
  1284. /**
  1285. * Test a new time the port_by_name function...(now we are in multi-client mode)
  1286. *
  1287. */
  1288. Log("Testing again jack_port_by_name...\n");
  1289. if (output_port1 != jack_port_by_name(client1, jack_port_name(output_port1))) {
  1290. printf("!!! ERROR !!! function jack_port_by_name() return bad value in a multi-client application!\n");
  1291. printf("!!! jack_port_by_name(jack_port_name(_ID_) ) != _ID_ in multiclient application.\n");
  1292. } else {
  1293. Log("Checking jack_port_by_name() function with a multi-client application... ok\n");
  1294. }
  1295. /**
  1296. * Test the port_connected_to function...
  1297. *
  1298. */
  1299. if ((jack_port_connected_to (output_port1, jack_port_name(input_port2))) &&
  1300. (!(jack_port_connected_to (output_port2, jack_port_name(input_port2))))) {
  1301. Log("checking jack_port_connected_to()... ok\n");
  1302. } else {
  1303. printf("!!! ERROR !!! jack_port_connected_to() return bad value !\n");
  1304. }
  1305. /**
  1306. * Test the port_get_connections & port_get_all_connections functions...
  1307. *
  1308. */
  1309. Log("Testing jack_port_get_connections and jack_port_get_all_connections...\n");
  1310. a = 0;
  1311. t_error = 0;
  1312. connexions1 = jack_port_get_connections (output_port1);
  1313. connexions2 = jack_port_get_all_connections(client1, output_port1);
  1314. if ((connexions1 == NULL) || (connexions2 == NULL)) {
  1315. printf("!!! ERROR !!! port_get_connexions or port_get_all_connexions return a NULL pointer !\n");
  1316. } else {
  1317. while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
  1318. t_error = strcmp(connexions1[a], connexions2[a]);
  1319. a++;
  1320. }
  1321. if (t_error == 0) {
  1322. Log("Checking jack_port_get_connections Vs jack_port_get_all_connections... ok\n");
  1323. } else {
  1324. printf("!!! ERROR !!! while checking jack_port_get_connections Vs jack_port_get_all_connections...\n");
  1325. }
  1326. }
  1327. a = 0;
  1328. t_error = 0;
  1329. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1330. connexions1 = NULL;
  1331. if (inports && inports[0] != NULL) {
  1332. connexions1 = jack_port_get_connections (jack_port_by_name(client1, inports[0]));
  1333. connexions2 = jack_port_get_all_connections(client1, jack_port_by_name(client1, inports[0]));
  1334. }
  1335. jack_free (inports);
  1336. if (connexions1 == NULL) {
  1337. Log("checking jack_port_get_connections() for external client... ok\n");
  1338. } else {
  1339. while ((connexions1[a] != NULL) && (connexions2[a] != NULL) && (t_error == 0)) {
  1340. t_error = strcmp(connexions1[a], connexions2[a]);
  1341. a++;
  1342. }
  1343. }
  1344. if (t_error == 0) {
  1345. Log("Checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port... ok\n");
  1346. } else {
  1347. printf("!!! ERROR !!! while checking jack_port_get_connections() Vs jack_port_get_all_connections() on PHY port...\n");
  1348. }
  1349. if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port1)) != 0) {
  1350. printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
  1351. }
  1352. if (jack_disconnect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1353. printf("!!! ERROR !!! while client1 intenting to disconnect ports...\n");
  1354. }
  1355. // No links should subsist now...
  1356. /**
  1357. * Checking data connexion
  1358. * establishing a link between client1.out1 --> client2.in2
  1359. * Send the signal1 test on out1. Record the result into signal2. (see process functions).
  1360. ---------------------------------------------------------------------------*/
  1361. Log("Testing connections datas between clients...\n");
  1362. jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2) );
  1363. process2_activated = -1;
  1364. process1_activated = -1;
  1365. Log("process 2 : idle mode...\n");
  1366. Log("Sending datas...");
  1367. index1 = 0;
  1368. index2 = 0;
  1369. process1_activated = 1; // We start emitting first.
  1370. process2_activated = 1; // So record begin at least when we just begin to emitt the signal, else at next call of process with
  1371. // nframe = jack buffersize shifting.
  1372. while (process2_activated == 1) {
  1373. jack_sleep(1 * 1000);
  1374. Log(".");
  1375. }
  1376. index2 = 0;
  1377. Log("\nAnalysing datas...\n"); // search the first occurence of the first element of the reference signal in the recorded signal
  1378. while (signal2[index2] != signal1[1] ) {
  1379. index2++;
  1380. if (index2 == 95999) {
  1381. printf("!!! ERROR !!! Data not found in first connexion data check!\n");
  1382. break;
  1383. }
  1384. }
  1385. index1 = index2;
  1386. Log("Data founded at offset %i.\n", index2);
  1387. // And now we founded were the recorded data are, we can see if the two signals matches...
  1388. while ( (signal2[index2] == signal1[index2 - index1 + 1]) || (index2 == 95999) || ((index2 - index1 + 1) == 47999) ) {
  1389. index2++;
  1390. }
  1391. Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
  1392. if ((index2 - index1) == 48000) {
  1393. Log("Data received are valid...\n");
  1394. } else {
  1395. printf("!!! ERROR !!! data transmission seems not to be valid in first connexion data check!\n");
  1396. }
  1397. if (jack_disconnect(client1, jack_port_name(output_port1), jack_port_name(input_port2) ) != 0)
  1398. // no more connection between ports exist now...
  1399. {
  1400. printf("Error while establishing new connexion (disconnect).\n");
  1401. }
  1402. /**
  1403. * Test TIE MODE
  1404. * (This mode seems to be problematic in standard jack version 0.100. It seems that nobody
  1405. * is used to apply this mode because the tie mode doesn't work at all. A patch seems difficult to produce
  1406. * in this version of jack. Tie mode work well in MP version.)
  1407. * Test some basic thinks (tie with 2 differents client, tie non-owned ports...)
  1408. * Tie client1.in1 and client1.out1 ports, and make some data test to check the validity of the tie.
  1409. *
  1410. */
  1411. Log("Testing tie mode...\n");
  1412. if (jack_port_tie(input_port1, output_port2) != 0) {
  1413. Log("not possible to tie two ports from two differents clients... ok\n");
  1414. } else {
  1415. printf("!!! ERROR !!! port_tie has allowed a connexion between two differents clients !\n");
  1416. jack_port_untie(output_port2);
  1417. }
  1418. Log("Testing connections datas in tie mode...\n");
  1419. int g;
  1420. for (g = 0; g < 96000; g++)
  1421. signal2[g] = 0.0;
  1422. // Create a loop (emit test) client2.out2----client.in1--tie--client1.out1-----client2.in1 (receive test)
  1423. if (jack_port_tie(input_port1, output_port1) != 0) {
  1424. printf("Unable to tie... fatal error : data test will not be performed on tie mode !!\n");
  1425. } else { // begin of tie
  1426. if (jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2)) != 0) {
  1427. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1428. }
  1429. if (jack_connect(client1, jack_port_name(output_port2), jack_port_name(input_port1)) != 0) {
  1430. printf("!!! ERROR !!! while client1 intenting to connect ports...\n");
  1431. }
  1432. process1_activated = -1;
  1433. process2_activated = -1;
  1434. // We can manualy check here that the tie is effective.
  1435. // ie : playing a wav with a client, connecting ports manualy with qjackctl, and listen...
  1436. // printf("manual test\n");
  1437. // jack_sleep(50);
  1438. // printf("end of manual test\n");
  1439. index1 = 0;
  1440. index2 = 0;
  1441. process1_activated = -1;
  1442. process2_activated = 2;
  1443. Log("Sending datas...");
  1444. while (process2_activated == 2) {
  1445. jack_sleep(1 * 1000);
  1446. Log(".");
  1447. }
  1448. process1_activated = -1;
  1449. process2_activated = -1;
  1450. index2 = 0;
  1451. Log("\nAnalysing datas...\n");
  1452. // We must find at least 2 identical values to ensure we are at the right place in the siusoidal array...
  1453. while (!((signal2[index2] == signal1[1]) && (signal2[index2 + 1] == signal1[2]))) {
  1454. index2++;
  1455. if (index2 == 95999) {
  1456. printf("!!! ERROR !!! Data not found in connexion check of tie mode!\n");
  1457. break;
  1458. }
  1459. }
  1460. index1 = index2;
  1461. Log("Tie mode : Data founded at offset %i.\n", index2);
  1462. while (signal2[index2] == signal1[index2 - index1 + 1]) {
  1463. index2++;
  1464. if ((index2 == 95999) || ((index2 - index1 + 1) == 47999)) {
  1465. break;
  1466. }
  1467. }
  1468. Log("Checking difference between datas... %i have the same value...\n", index2 - index1);
  1469. if ((index2 - index1) > 47995) {
  1470. Log("Data received in tie mode are valid...\n");
  1471. } else {
  1472. // in tie mode, the buffers adress should be the same for the two tied ports.
  1473. printf("!!! ERROR !!! data transmission seems not to be valid !\n");
  1474. printf("Links topology : (emitt) client2.out2 ----> client1.in1--(tie)--client1.out1----->client2.in2 (recive)\n");
  1475. printf(" port_name : Port_adress \n");
  1476. printf(" output_port1 : %px\n", jack_port_get_buffer(output_port1, cur_buffer_size));
  1477. printf(" input_port2 : %px\n", jack_port_get_buffer(input_port2, cur_buffer_size));
  1478. printf(" output_port2 : %px\n", jack_port_get_buffer(output_port2, cur_buffer_size));
  1479. printf(" input_port1 : %px\n", jack_port_get_buffer(input_port1, cur_buffer_size));
  1480. }
  1481. jack_port_untie(output_port1);
  1482. jack_port_disconnect(client1, output_port2);
  1483. jack_port_disconnect(client1, output_port1);
  1484. } //end of tie
  1485. /**
  1486. * Testing SUMMATION CAPABILITIES OF JACK CONNECTIONS
  1487. *
  1488. * In a short test, we just check a simple summation in jack.
  1489. * A first client(client1) send two signal in phase opposition
  1490. * A second client(client2) record the summation at one of his port
  1491. * So, the result must be zero...
  1492. * See process1 for details about steps of this test
  1493. *
  1494. */
  1495. // fprintf(file, "Sum test\n");
  1496. Log("Checking summation capabilities of patching...\n");
  1497. output_port1b = jack_port_register(client1, "out1b",
  1498. JACK_DEFAULT_AUDIO_TYPE,
  1499. JackPortIsOutput, 0);
  1500. jack_connect(client2, jack_port_name(output_port1), jack_port_name(input_port2));
  1501. jack_connect(client2, jack_port_name(output_port1b), jack_port_name(input_port2));
  1502. process1_activated = 3;
  1503. process2_activated = -1;
  1504. for (g = 0; g < 96000; g++)
  1505. signal2[g] = 0.0;
  1506. index1 = 0;
  1507. index2 = 0;
  1508. Log("Sending datas...");
  1509. process2_activated = 3;
  1510. while (process2_activated == 3) {
  1511. jack_sleep(1 * 1000);
  1512. Log(".");
  1513. }
  1514. process1_activated = -1;
  1515. process2_activated = -1;
  1516. index2 = 0;
  1517. Log("\nAnalysing datas...\n"); // same idea as above, with first data check...
  1518. while (!((signal2[index2] == 0.0 ) && (signal2[(index2 + 1)] == 0.0 ))) {
  1519. index2++;
  1520. if (index2 == 95999) {
  1521. printf("!!! ERROR !!! Data not found in summation check!\n");
  1522. break;
  1523. }
  1524. }
  1525. index1 = index2;
  1526. Log("Data founded at offset %i.\n", index2);
  1527. while ( signal2[index2] == 0.0 ) {
  1528. index2++;
  1529. if ((index2 > 95998) || ((index2 - index1 + 1) > 47998)) {
  1530. break;
  1531. }
  1532. }
  1533. Log("Checking difference between datas...\n");
  1534. if ((index2 - index1) > 47996) {
  1535. Log("Data mixed received are valid...\nSummation is well done.\n");
  1536. } else {
  1537. printf("!!! ERROR !!! data transmission / summation seems not to be valid !\n");
  1538. }
  1539. jack_port_disconnect(client1, output_port1);
  1540. jack_port_disconnect(client1, output_port1b);
  1541. jack_port_unregister(client1, output_port1b);
  1542. if (jack_port_name(output_port1b) != NULL ) {
  1543. printf("!!! WARNING !!! port_name return something while the port have been unregistered !\n");
  1544. printf("!!! Name of unregistered port : %s !\n", jack_port_name(output_port1b));
  1545. } else {
  1546. Log("Checking jack_port_name() with a non valid port... ok\n");
  1547. }
  1548. if (jack_port_set_name(output_port1b, "new_name") == 0 ) {
  1549. printf("!!! WARNING !!! An unregistered port can be renamed successfully !\n");
  1550. } else {
  1551. Log("Checking renaming of an unregistered port... ok\n");
  1552. }
  1553. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1554. if (inports && jack_port_set_name(jack_port_by_name(client1, inports[0]), "new_name") == 0 ) {
  1555. printf("!!! WARNING !!! A PHYSICAL port can be renamed successfully !\n");
  1556. } else {
  1557. Log("Checking renaming of an unregistered port... ok\n");
  1558. }
  1559. jack_free (inports);
  1560. /**
  1561. * Checking latency issues
  1562. * here are simple latency check
  1563. * We simply check that the value returned by jack seems ok
  1564. * Latency compensation is a difficult point.
  1565. * Actually, jack is not able to see "thru" client to build a full latency chain.
  1566. * Ardour use theses informations to do internally his compensations.
  1567. *
  1568. * 3 test are done : one with no connections between client, one with a serial connection, and one with parallel connection
  1569. */
  1570. Log("Checking about latency functions...\n");
  1571. t_error = 0;
  1572. jack_recompute_total_latencies(client1);
  1573. Log("jack_recompute_total_latencies...\n");
  1574. if ((jack_port_get_latency (output_port1) != 0) ||
  1575. (jack_port_get_total_latency(client1, output_port1) != 0) ) {
  1576. t_error = 1;
  1577. printf("!!! ERROR !!! default latency of a non-PHY device is not set to zero !\n");
  1578. }
  1579. inports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
  1580. outports = jack_get_ports(client1, NULL, NULL, JackPortIsPhysical | JackPortIsOutput);
  1581. if (inports && outports && inports[0] != NULL && outports[0] != NULL) {
  1582. output_ext_latency = jack_port_get_latency (jack_port_by_name(client1, inports[0])); // from client to out driver (which has "inputs" ports..)
  1583. input_ext_latency = jack_port_get_latency (jack_port_by_name(client1, outports[0])); // from in driver (which has "output" ports..) to client
  1584. if (output_ext_latency != jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0]))) {
  1585. t_error = 1;
  1586. printf("!!! ERROR !!! get_latency & get_all_latency for a PHY device (unconnected) didn't return the same value !\n");
  1587. }
  1588. Log("Checking a serial model with 2 clients...\n");
  1589. jack_connect(client1, jack_port_name(output_port1), jack_port_name(input_port2));
  1590. jack_connect(client1, outports[0], jack_port_name(input_port1));
  1591. jack_connect(client2, jack_port_name(output_port2), inports[0]);
  1592. jack_port_set_latency(output_port2, 256);
  1593. jack_recompute_total_latencies(client1);
  1594. if ((jack_port_get_latency (output_port1) != 0) ||
  1595. (jack_port_get_total_latency(client1, output_port1) != 0) ||
  1596. (jack_port_get_latency (jack_port_by_name(client1, inports[0])) != (output_ext_latency)) ||
  1597. (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (output_ext_latency + 256)) ||
  1598. (jack_port_get_total_latency(client1, output_port2) != (output_ext_latency + 256)) ||
  1599. (jack_port_get_total_latency(client1, input_port2) != 0) ||
  1600. (jack_port_get_total_latency(client1, input_port1) != input_ext_latency) ||
  1601. (jack_port_get_latency (jack_port_by_name(client1, outports[0])) != input_ext_latency) ||
  1602. (jack_port_get_total_latency(client1, jack_port_by_name(client1, outports[0])) != input_ext_latency)
  1603. ) {
  1604. printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
  1605. printf("!!! get_latency(output_port1) : %i (must be 0)\n", jack_port_get_latency(output_port1));
  1606. printf("!!! get_total_latency(output_port1) : %i (must be 0)\n", jack_port_get_total_latency(client1, output_port1));
  1607. 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);
  1608. 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));
  1609. printf("!!! get_total_latency(output_port2) : %i (must be %i)\n", jack_port_get_total_latency(client1, output_port2), (output_ext_latency + 256));
  1610. printf("!!! get_total_latency(input_port2) : %i (must be 0)\n", jack_port_get_total_latency(client1, input_port2));
  1611. printf("!!! get_total_latency(input_port1) : %i (must be %i)\n", jack_port_get_total_latency(client1, input_port1), input_ext_latency);
  1612. printf("!!! get_latency(PHY[0]) : %i (must be %i)\n", jack_port_get_latency(jack_port_by_name(client1, outports[0])), input_ext_latency);
  1613. 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);
  1614. } else {
  1615. Log("get_latency & get_total_latency seems quite ok...\n");
  1616. }
  1617. jack_port_disconnect(client1, output_port1);
  1618. jack_port_disconnect(client1, output_port2);
  1619. jack_port_disconnect(client1, input_port1);
  1620. jack_port_disconnect(client1, input_port2);
  1621. Log("Checking a parallel model with 2 clients...\n");
  1622. jack_connect(client2, outports[0], jack_port_name(input_port1));
  1623. jack_connect(client2, outports[0], jack_port_name(input_port2));
  1624. jack_connect(client2, jack_port_name(output_port1), inports[0]);
  1625. jack_connect(client2, jack_port_name(output_port2), inports[0]);
  1626. jack_port_set_latency(output_port1, 256);
  1627. jack_port_set_latency(output_port2, 512);
  1628. jack_recompute_total_latencies(client1);
  1629. if ((jack_port_get_latency(output_port1) != 256 ) ||
  1630. (jack_port_get_total_latency(client1, output_port1) != (256 + output_ext_latency)) ||
  1631. (jack_port_get_latency(output_port2) != 512) ||
  1632. (jack_port_get_total_latency(client1, output_port2) != (512 + output_ext_latency)) ||
  1633. (jack_port_get_latency(jack_port_by_name(client1, inports[0])) != output_ext_latency) ||
  1634. (jack_port_get_total_latency(client1, jack_port_by_name(client1, inports[0])) != (512 + output_ext_latency))
  1635. ) {
  1636. printf("!!! WARNING !!! get_latency functions may have a problem : bad value returned !\n");
  1637. printf("!!! get_latency(output_port1) : %i (must be 256)\n", jack_port_get_latency(output_port1));
  1638. printf("!!! get_total_latency(output_port1) : %i (must be 256 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port1));
  1639. printf("!!! get_latency(output_port2) : %i (must 512)\n", jack_port_get_latency(output_port2));
  1640. printf("!!! get_total_latency(output_port2) : %i (must 512 + output_ext_latency)\n", jack_port_get_total_latency(client1, output_port2));
  1641. printf("!!! get_latency(inports[0])) : %i (must output_ext_latency)\n", jack_port_get_latency(jack_port_by_name(client1, inports[0])));
  1642. 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])));
  1643. } else {
  1644. Log("get_latency & get_total_latency seems quite ok...\n");
  1645. }
  1646. } else {
  1647. printf("No physical port founded : not able to test latency functions...");
  1648. }
  1649. jack_port_disconnect(client1, input_port1);
  1650. jack_port_disconnect(client1, input_port2);
  1651. jack_port_disconnect(client1, output_port1);
  1652. jack_port_disconnect(client1, output_port2);
  1653. jack_sleep(1000);
  1654. jack_free(inports);
  1655. jack_free(outports);
  1656. /**
  1657. * Checking transport API.
  1658. * Simple transport test.
  1659. * Check a transport start with a "slow" client, simulating a delay around 1 sec before becoming ready.
  1660. *
  1661. */
  1662. Log("-----------------------------------------------------------\n");
  1663. Log("---------------------------TRANSPORT-----------------------\n");
  1664. Log("-----------------------------------------------------------\n");
  1665. lineports = linecount;
  1666. if (transport_mode) {
  1667. int wait_count;
  1668. ts = jack_transport_query(client1, &pos);
  1669. if (ts == JackTransportStopped) {
  1670. Log("Transport is stopped...\n");
  1671. } else {
  1672. jack_transport_stop(client1);
  1673. Log("Transport state : %i\n", ts);
  1674. }
  1675. if (jack_set_sync_callback(client2, Jack_Sync_Callback, 0) != 0) {
  1676. printf("error while calling set_sync_callback...\n");
  1677. }
  1678. Log("starting transport...\n");
  1679. starting_state = 1; // Simulate starting state
  1680. jack_transport_start(client1);
  1681. // Wait until sync callback is called
  1682. while (!(sync_called)) {
  1683. jack_sleep(1 * 1000);
  1684. }
  1685. // Wait untill rolling : simulate sync time out
  1686. Log("Simulate a slow-sync client exceeding the time-out\n");
  1687. wait_count = 0;
  1688. do {
  1689. jack_sleep(100); // Wait 100 ms each cycle
  1690. wait_count++;
  1691. if (wait_count == 100) {
  1692. Log("!!! ERROR !!! max time-out exceedeed : sync time-out does not work correctly\n");
  1693. break;
  1694. }
  1695. ts = jack_transport_query(client2, &pos);
  1696. Log("Waiting....pos = %ld\n", pos.frame);
  1697. display_transport_state();
  1698. } while (ts != JackTransportRolling);
  1699. Log("Sync callback have been called %i times.\n", sync_called);
  1700. jack_transport_stop(client1);
  1701. // Wait until stopped
  1702. ts = jack_transport_query(client2, &pos);
  1703. while (ts != JackTransportStopped) {
  1704. jack_sleep(1 * 1000);
  1705. ts = jack_transport_query(client2, &pos);
  1706. }
  1707. // Simulate starting a slow-sync client that rolls after 0.5 sec
  1708. Log("Simulate a slow-sync client that needs 0.5 sec to start\n");
  1709. sync_called = 0;
  1710. wait_count = 0;
  1711. starting_state = 1; // Simulate starting state
  1712. Log("Starting transport...\n");
  1713. jack_transport_start(client1);
  1714. display_transport_state();
  1715. Log("Waiting 0.5 sec...\n");
  1716. jack_sleep(500);
  1717. starting_state = 0; // Simulate end of starting state after 0.5 sec
  1718. // Wait untill rolling
  1719. ts = jack_transport_query(client2, &pos);
  1720. while (ts != JackTransportRolling) {
  1721. jack_sleep(100); // Wait 100 ms each cycle
  1722. wait_count++;
  1723. if (wait_count == 10) {
  1724. Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
  1725. break;
  1726. }
  1727. ts = jack_transport_query(client2, &pos);
  1728. }
  1729. if (sync_called == 0) {
  1730. Log("!!! ERROR !!! starting a slow-sync client does not work correctly\n");
  1731. }
  1732. Log("Sync callback have been called %i times.\n", sync_called);
  1733. display_transport_state();
  1734. // Test jack_transport_locate while rolling
  1735. Log("Test jack_transport_locate while rolling\n");
  1736. ts = jack_transport_query(client2, &pos);
  1737. Log("Transport current frame = %ld\n", pos.frame);
  1738. jack_nframes_t cur_frame = pos.frame;
  1739. wait_count = 0;
  1740. do {
  1741. display_transport_state();
  1742. jack_sleep(10); // 10 ms
  1743. // locate at first...
  1744. wait_count++;
  1745. if (wait_count == 1) {
  1746. Log("Do jack_transport_locate\n");
  1747. jack_transport_locate(client1, cur_frame / 2);
  1748. } else if (wait_count == 100) {
  1749. break;
  1750. }
  1751. ts = jack_transport_query(client2, &pos);
  1752. Log("Locating.... frame = %ld\n", pos.frame);
  1753. } while (pos.frame > cur_frame);
  1754. ts = jack_transport_query(client2, &pos);
  1755. Log("Transport current frame = %ld\n", pos.frame);
  1756. if (wait_count == 100) {
  1757. printf("!!! ERROR !!! jack_transport_locate does not work correctly\n");
  1758. }
  1759. // Test jack_transport_reposition while rolling
  1760. Log("Test jack_transport_reposition while rolling\n");
  1761. ts = jack_transport_query(client2, &pos);
  1762. Log("Transport current frame = %ld\n", pos.frame);
  1763. cur_frame = pos.frame;
  1764. wait_count = 0;
  1765. do {
  1766. display_transport_state();
  1767. jack_sleep(10); // 10 ms
  1768. // locate at first...
  1769. wait_count++;
  1770. if (wait_count == 1) {
  1771. Log("Do jack_transport_reposition\n");
  1772. request_pos.frame = cur_frame / 2;
  1773. jack_transport_reposition(client1, &request_pos);
  1774. } else if (wait_count == 100) {
  1775. break;
  1776. }
  1777. ts = jack_transport_query(client2, &pos);
  1778. Log("Locating.... frame = %ld\n", pos.frame);
  1779. } while (pos.frame > cur_frame);
  1780. ts = jack_transport_query(client2, &pos);
  1781. Log("Transport current frame = %ld\n", pos.frame);
  1782. if (wait_count == 100) {
  1783. printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
  1784. }
  1785. // Test jack_transport_reposition while stopped
  1786. jack_transport_stop(client1);
  1787. ts = jack_transport_query(client2, &pos);
  1788. Log("Transport current frame = %ld\n", pos.frame);
  1789. Log("Test jack_transport_reposition while stopped\n");
  1790. wait_count = 0;
  1791. request_pos.frame = 10000;
  1792. jack_transport_reposition(client1, &request_pos);
  1793. do {
  1794. display_transport_state();
  1795. jack_sleep(100); // 100 ms
  1796. if (wait_count++ == 10)
  1797. break;
  1798. ts = jack_transport_query(client2, &pos);
  1799. Log("Locating.... frame = %ld\n", pos.frame);
  1800. } while (pos.frame != 10000);
  1801. ts = jack_transport_query(client2, &pos);
  1802. Log("Transport current frame = %ld\n", pos.frame);
  1803. if (pos.frame != 10000) {
  1804. printf("!!! ERROR !!! jack_transport_reposition does not work correctly\n");
  1805. }
  1806. jack_transport_stop(client1);
  1807. /* Tell the JACK server that we are ready to roll. Our
  1808. * process() callback will start running now. */
  1809. } else {
  1810. printf("Transport check is disabled...\n");
  1811. }
  1812. time_before_exit = time_to_run;
  1813. while (time_before_exit != 0) {
  1814. jack_sleep (1 * 1000);
  1815. time_before_exit--;
  1816. }
  1817. if (jack_deactivate(client2) != 0) {
  1818. printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
  1819. }
  1820. if (jack_deactivate(client1) != 0) {
  1821. printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
  1822. }
  1823. /**
  1824. * Checking jack_frame_time.
  1825. */
  1826. Log("Testing jack_frame_time...\n");
  1827. jack_set_process_callback(client1, process4, client1);
  1828. jack_activate(client1);
  1829. jack_sleep(2 * 1000);
  1830. /**
  1831. * Checking jack_get_cycle_times.
  1832. */
  1833. Log("Testing jack_get_cycle_times...\n");
  1834. jack_deactivate(client1);
  1835. jack_set_process_callback(client1, process5, client1);
  1836. jack_activate(client1);
  1837. jack_sleep(3 * 1000);
  1838. /**
  1839. * Checking alternate thread model
  1840. */
  1841. Log("Testing alternate thread model...\n");
  1842. jack_deactivate(client1);
  1843. jack_set_process_callback(client1, NULL, NULL); // remove callback
  1844. jack_set_process_thread(client1, jack_thread, client1);
  1845. jack_activate(client1);
  1846. jack_sleep(2 * 1000);
  1847. /**
  1848. * Checking callback exiting : when the return code is != 0, the client is desactivated.
  1849. */
  1850. Log("Testing callback exiting...\n");
  1851. jack_deactivate(client1);
  1852. jack_set_process_thread(client1, NULL, NULL); // remove thread callback
  1853. jack_set_process_callback(client1, process3, 0);
  1854. jack_activate(client1);
  1855. jack_sleep(3 * 1000);
  1856. /**
  1857. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1858. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1859. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1860. Closing program
  1861. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1862. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1863. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
  1864. */
  1865. if (jack_deactivate(client2) != 0) {
  1866. printf("!!! ERROR !!! jack_deactivate does not return 0 for client2 !\n");
  1867. }
  1868. if (jack_deactivate(client1) != 0) {
  1869. printf("!!! ERROR !!! jack_deactivate does not return 0 for client1 !\n");
  1870. }
  1871. if (jack_client_close(client2) != 0) {
  1872. printf("!!! ERROR !!! jack_client_close does not return 0 for client2 !\n");
  1873. }
  1874. if (jack_client_close(client1) != 0) {
  1875. printf("!!! ERROR !!! jack_client_close does not return 0 for client1 !\n");
  1876. }
  1877. if (xrun == 0) {
  1878. Log("No Xrun have been detected during this test... cool !\n");
  1879. } else {
  1880. printf("%i Xrun have been detected during this session (seen callback messages to see where are the problems).\n", xrun);
  1881. }
  1882. free(framecollect);
  1883. free(signal1);
  1884. free(signal2);
  1885. Log("Exiting jack_test...\n");
  1886. fclose(file);
  1887. printf("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n");
  1888. sprintf (filename, "framegraph-%i.gnu", cur_buffer_size);
  1889. file = fopen(filename, "w");
  1890. if (file == NULL) {
  1891. fprintf(stderr, "Error while opening file");
  1892. exit(-1);
  1893. }
  1894. fprintf(file, "reset\n");
  1895. fprintf(file, "set terminal png transparent nocrop enhanced\n");
  1896. fprintf(file, "set output 'framegraph-%i-1.png'\n", cur_buffer_size);
  1897. fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
  1898. 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));
  1899. fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
  1900. fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
  1901. fprintf(file, "set xlabel \"FrameTime\"\n");
  1902. 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);
  1903. 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);
  1904. fprintf(file, "set output 'framegraph-%i-2.png'\n", cur_buffer_size);
  1905. fprintf(file, "set title \"Frame time evolution during jack_test run\"\n");
  1906. 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)));
  1907. fprintf(file, "set xrange [ 0.00000 : %i.0000 ] noreverse nowriteback\n" , linecount - 1);
  1908. fprintf(file, "set ylabel \"Frametime evolution (d(ft)/dt)\"\n");
  1909. fprintf(file, "set xlabel \"FrameTime\"\n");
  1910. 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);
  1911. 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);
  1912. fclose(file);
  1913. return 0;
  1914. }