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.

2153 lines
84KB

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