jack1 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.

694 lines
19KB

  1. /** @file simple_client.c
  2. *
  3. * @brief This simple client demonstrates the basic features of JACK
  4. * as they would be used by many applications.
  5. */
  6. #define _ISOC99_SOURCE 1
  7. #define _XOPEN_SOURCE 600
  8. #include <stdio.h>
  9. #include <errno.h>
  10. #include <unistd.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <alloca.h>
  14. #include <math.h>
  15. #include <jack/jack.h>
  16. #include <jack/jslist.h>
  17. #include "alsa/asoundlib.h"
  18. #include <samplerate.h>
  19. #define SAMPLE_16BIT_SCALING 32767.0f
  20. #define SAMPLE_16BIT_MAX 32767
  21. #define SAMPLE_16BIT_MIN -32767
  22. #define NORMALIZED_FLOAT_MIN -1.0f
  23. #define NORMALIZED_FLOAT_MAX 1.0f
  24. #define f_round(f) lrintf(f)
  25. #define float_16(s, d)\
  26. if ((s) <= NORMALIZED_FLOAT_MIN) {\
  27. (d) = SAMPLE_16BIT_MIN;\
  28. } else if ((s) >= NORMALIZED_FLOAT_MAX) {\
  29. (d) = SAMPLE_16BIT_MAX;\
  30. } else {\
  31. (d) = f_round ((s) * SAMPLE_16BIT_SCALING);\
  32. }
  33. #define OFF_D_SIZE 256
  34. typedef signed short ALSASAMPLE;
  35. // Here are the lists of the jack ports...
  36. JSList *capture_ports = NULL;
  37. JSList *capture_srcs = NULL;
  38. JSList *playback_ports = NULL;
  39. JSList *playback_srcs = NULL;
  40. jack_client_t *client;
  41. // TODO: make the sample format configurable soon...
  42. snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */
  43. snd_pcm_t *alsa_handle;
  44. int jack_sample_rate;
  45. int jack_buffer_size;
  46. double resample_mean = 1.0;
  47. double static_resample_factor = 1.0;
  48. double offset_array[OFF_D_SIZE];
  49. int offset_differential_index = 0;
  50. double offset_integral = 0;
  51. // ------------------------------------------------------ commandline parameters
  52. int sample_rate = 0; /* stream rate */
  53. int num_channels = 2; /* count of channels */
  54. int period_size = 1024;
  55. int num_periods = 2;
  56. int target_delay = 0; /* the delay which the program should try to approach. */
  57. int max_diff = 0; /* the diff value, when a hard readpointer skip should occur */
  58. int catch_factor = 100000;
  59. int catch_factor2 = 10000;
  60. double pclamp = 15.0;
  61. double controlquant = 10000.0;
  62. int good_window=0;
  63. int verbose = 0;
  64. int instrument = 0;
  65. // Debug stuff:
  66. volatile float output_resampling_factor = 1.0;
  67. volatile int output_new_delay = 0;
  68. volatile float output_offset = 0.0;
  69. volatile float output_integral = 0.0;
  70. volatile float output_diff = 0.0;
  71. snd_pcm_uframes_t real_buffer_size;
  72. snd_pcm_uframes_t real_period_size;
  73. // Alsa stuff... i dont want to touch this bullshit in the next years.... please...
  74. static int xrun_recovery(snd_pcm_t *handle, int err) {
  75. // printf( "xrun !!!.... %d\n", err );
  76. if (err == -EPIPE) { /* under-run */
  77. err = snd_pcm_prepare(handle);
  78. if (err < 0)
  79. printf("Can't recovery from underrun, prepare failed: %s\n", snd_strerror(err));
  80. return 0;
  81. } else if (err == -EAGAIN) {
  82. while ((err = snd_pcm_resume(handle)) == -EAGAIN)
  83. usleep(100); /* wait until the suspend flag is released */
  84. if (err < 0) {
  85. err = snd_pcm_prepare(handle);
  86. if (err < 0)
  87. printf("Can't recovery from suspend, prepare failed: %s\n", snd_strerror(err));
  88. }
  89. return 0;
  90. }
  91. return err;
  92. }
  93. static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, snd_pcm_access_t access, int rate, int channels, int period, int nperiods ) {
  94. int err, dir=0;
  95. unsigned int buffer_time;
  96. unsigned int period_time;
  97. unsigned int rrate;
  98. /* choose all parameters */
  99. err = snd_pcm_hw_params_any(handle, params);
  100. if (err < 0) {
  101. printf("Broken configuration for playback: no configurations available: %s\n", snd_strerror(err));
  102. return err;
  103. }
  104. /* set the interleaved read/write format */
  105. err = snd_pcm_hw_params_set_access(handle, params, access);
  106. if (err < 0) {
  107. printf("Access type not available for playback: %s\n", snd_strerror(err));
  108. return err;
  109. }
  110. /* set the sample format */
  111. err = snd_pcm_hw_params_set_format(handle, params, format);
  112. if (err < 0) {
  113. printf("Sample format not available for playback: %s\n", snd_strerror(err));
  114. return err;
  115. }
  116. /* set the count of channels */
  117. err = snd_pcm_hw_params_set_channels(handle, params, channels);
  118. if (err < 0) {
  119. printf("Channels count (%i) not available for record: %s\n", channels, snd_strerror(err));
  120. return err;
  121. }
  122. /* set the stream rate */
  123. rrate = rate;
  124. err = snd_pcm_hw_params_set_rate_near(handle, params, &rrate, 0);
  125. if (err < 0) {
  126. printf("Rate %iHz not available for playback: %s\n", rate, snd_strerror(err));
  127. return err;
  128. }
  129. if (rrate != rate) {
  130. printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, rrate);
  131. return -EINVAL;
  132. }
  133. /* set the buffer time */
  134. buffer_time = 1000000*period*nperiods/rate;
  135. err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, &dir);
  136. if (err < 0) {
  137. printf("Unable to set buffer time %i for playback: %s\n", 1000000*period*nperiods/rate, snd_strerror(err));
  138. return err;
  139. }
  140. err = snd_pcm_hw_params_get_buffer_size( params, &real_buffer_size );
  141. if (err < 0) {
  142. printf("Unable to get buffer size back: %s\n", snd_strerror(err));
  143. return err;
  144. }
  145. if( real_buffer_size != nperiods * period ) {
  146. printf( "WARNING: buffer size does not match: (requested %d, got %d)\n", nperiods * period, (int) real_buffer_size );
  147. }
  148. /* set the period time */
  149. period_time = 1000000*period/rate;
  150. err = snd_pcm_hw_params_set_period_time_near(handle, params, &period_time, &dir);
  151. if (err < 0) {
  152. printf("Unable to set period time %i for playback: %s\n", 1000000*period/rate, snd_strerror(err));
  153. return err;
  154. }
  155. err = snd_pcm_hw_params_get_period_size(params, &real_period_size, NULL );
  156. if (err < 0) {
  157. printf("Unable to get period size back: %s\n", snd_strerror(err));
  158. return err;
  159. }
  160. if( real_period_size != period ) {
  161. printf( "WARNING: period size does not match: (requested %i, got %i)\n", period, (int)real_period_size );
  162. }
  163. /* write the parameters to device */
  164. err = snd_pcm_hw_params(handle, params);
  165. if (err < 0) {
  166. printf("Unable to set hw params for playback: %s\n", snd_strerror(err));
  167. return err;
  168. }
  169. return 0;
  170. }
  171. static int set_swparams(snd_pcm_t *handle, snd_pcm_sw_params_t *swparams, int period, int nperiods) {
  172. int err;
  173. /* get the current swparams */
  174. err = snd_pcm_sw_params_current(handle, swparams);
  175. if (err < 0) {
  176. printf("Unable to determine current swparams for capture: %s\n", snd_strerror(err));
  177. return err;
  178. }
  179. /* start the transfer when the buffer is full */
  180. err = snd_pcm_sw_params_set_start_threshold(handle, swparams, period );
  181. if (err < 0) {
  182. printf("Unable to set start threshold mode for capture: %s\n", snd_strerror(err));
  183. return err;
  184. }
  185. err = snd_pcm_sw_params_set_stop_threshold(handle, swparams, -1 );
  186. if (err < 0) {
  187. printf("Unable to set start threshold mode for capture: %s\n", snd_strerror(err));
  188. return err;
  189. }
  190. /* allow the transfer when at least period_size samples can be processed */
  191. err = snd_pcm_sw_params_set_avail_min(handle, swparams, 1 );
  192. if (err < 0) {
  193. printf("Unable to set avail min for capture: %s\n", snd_strerror(err));
  194. return err;
  195. }
  196. /* align all transfers to 1 sample */
  197. err = snd_pcm_sw_params_set_xfer_align(handle, swparams, 1);
  198. if (err < 0) {
  199. printf("Unable to set transfer align for capture: %s\n", snd_strerror(err));
  200. return err;
  201. }
  202. /* write the parameters to the playback device */
  203. err = snd_pcm_sw_params(handle, swparams);
  204. if (err < 0) {
  205. printf("Unable to set sw params for capture: %s\n", snd_strerror(err));
  206. return err;
  207. }
  208. return 0;
  209. }
  210. // ok... i only need this function to communicate with the alsa bloat api...
  211. static snd_pcm_t *open_audiofd( char *device_name, int capture, int rate, int channels, int period, int nperiods ) {
  212. int err;
  213. snd_pcm_t *handle;
  214. snd_pcm_hw_params_t *hwparams;
  215. snd_pcm_sw_params_t *swparams;
  216. snd_pcm_hw_params_alloca(&hwparams);
  217. snd_pcm_sw_params_alloca(&swparams);
  218. if ((err = snd_pcm_open(&(handle), device_name, capture ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK )) < 0) {
  219. printf("Capture open error: %s\n", snd_strerror(err));
  220. return NULL;
  221. }
  222. if ((err = set_hwparams(handle, hwparams,SND_PCM_ACCESS_RW_INTERLEAVED, rate, channels, period, nperiods )) < 0) {
  223. printf("Setting of hwparams failed: %s\n", snd_strerror(err));
  224. return NULL;
  225. }
  226. if ((err = set_swparams(handle, swparams, period, nperiods)) < 0) {
  227. printf("Setting of swparams failed: %s\n", snd_strerror(err));
  228. return NULL;
  229. }
  230. //snd_pcm_start( handle );
  231. //snd_pcm_wait( handle, 200 );
  232. int num_null_samples = nperiods * period * channels;
  233. ALSASAMPLE *tmp = alloca( num_null_samples * sizeof( ALSASAMPLE ) );
  234. memset( tmp, 0, num_null_samples * sizeof( ALSASAMPLE ) );
  235. snd_pcm_writei( handle, tmp, num_null_samples );
  236. return handle;
  237. }
  238. double hann( double x )
  239. {
  240. return 0.5 * (1.0 - cos( 2*M_PI * x ) );
  241. }
  242. /**
  243. * The process callback for this JACK application.
  244. * It is called by JACK at the appropriate times.
  245. */
  246. int process (jack_nframes_t nframes, void *arg) {
  247. ALSASAMPLE *outbuf;
  248. float *resampbuf;
  249. int rlen;
  250. int err;
  251. snd_pcm_sframes_t delay = target_delay;
  252. int i;
  253. snd_pcm_delay( alsa_handle, &delay );
  254. //delay -= jack_frames_since_cycle_start( client );
  255. // Do it the hard way.
  256. // this is for compensating xruns etc...
  257. if( delay > (target_delay+max_diff) ) {
  258. snd_pcm_rewind( alsa_handle, delay - target_delay );
  259. output_new_delay = (int) delay;
  260. delay = target_delay;
  261. // Set the resample_rate... we need to adjust the offset integral, to do this.
  262. // first look at the PI controller, this code is just a special case, which should never execute once
  263. // everything is swung in.
  264. offset_integral = - (resample_mean - static_resample_factor) * catch_factor * catch_factor2;
  265. // Also clear the array. we are beginning a new control cycle.
  266. for( i=0; i<OFF_D_SIZE; i++ )
  267. offset_array[i] = 0.0;
  268. }
  269. if( delay < (target_delay-max_diff) ) {
  270. ALSASAMPLE *tmp = alloca( (target_delay-delay) * sizeof( ALSASAMPLE ) * num_channels );
  271. memset( tmp, 0, sizeof( ALSASAMPLE ) * num_channels * (target_delay-delay) );
  272. snd_pcm_writei( alsa_handle, tmp, target_delay-delay );
  273. output_new_delay = (int) delay;
  274. delay = target_delay;
  275. // Set the resample_rate... we need to adjust the offset integral, to do this.
  276. offset_integral = - (resample_mean - static_resample_factor) * catch_factor * catch_factor2;
  277. // Also clear the array. we are beginning a new control cycle.
  278. for( i=0; i<OFF_D_SIZE; i++ )
  279. offset_array[i] = 0.0;
  280. }
  281. /* ok... now we should have target_delay +- max_diff on the alsa side.
  282. *
  283. * calculate the number of frames, we want to get.
  284. */
  285. double offset = delay - target_delay;
  286. // Save offset.
  287. offset_array[(offset_differential_index++)% OFF_D_SIZE ] = offset;
  288. // Build the mean of the windowed offset array
  289. // basically fir lowpassing.
  290. double smooth_offset = 0.0;
  291. for( i=0; i<OFF_D_SIZE; i++ )
  292. smooth_offset +=
  293. offset_array[ (i + offset_differential_index-1) % OFF_D_SIZE] * hann( (double) i / ((double) OFF_D_SIZE - 1.0) );
  294. smooth_offset /= (double) OFF_D_SIZE;
  295. // this is the integral of the smoothed_offset
  296. offset_integral += smooth_offset;
  297. // Clamp offset.
  298. // the smooth offset still contains unwanted noise
  299. // which would go straigth onto the resample coeff.
  300. // it only used in the P component and the I component is used for the fine tuning anyways.
  301. if( fabs( smooth_offset ) < pclamp )
  302. smooth_offset = 0.0;
  303. // ok. now this is the PI controller.
  304. // u(t) = K * ( e(t) + 1/T \int e(t') dt' )
  305. // K = 1/catch_factor and T = catch_factor2
  306. double current_resample_factor = static_resample_factor - smooth_offset / (double) catch_factor - offset_integral / (double) catch_factor / (double)catch_factor2;
  307. // now quantize this value around resample_mean, so that the noise which is in the integral component doesnt hurt.
  308. current_resample_factor = floor( (current_resample_factor - resample_mean) * controlquant + 0.5 ) / controlquant + resample_mean;
  309. // Output "instrumentatio" gonna change that to real instrumentation in a few.
  310. output_resampling_factor = (float) current_resample_factor;
  311. output_diff = (float) smooth_offset;
  312. output_integral = (float) offset_integral;
  313. output_offset = (float) offset;
  314. // Clamp a bit.
  315. if( current_resample_factor < 0.25 ) current_resample_factor = 0.25;
  316. if( current_resample_factor > 4 ) current_resample_factor = 4;
  317. // Now Calculate how many samples we need.
  318. rlen = ceil( ((double)nframes) * current_resample_factor )+2;
  319. assert( rlen > 2 );
  320. // Calculate resample_mean so we can init ourselves to saner values.
  321. resample_mean = 0.9999 * resample_mean + 0.0001 * current_resample_factor;
  322. /*
  323. * now this should do it...
  324. */
  325. outbuf = alloca( rlen * sizeof( ALSASAMPLE ) * num_channels );
  326. resampbuf = alloca( rlen * sizeof( float ) );
  327. /*
  328. * render jack ports to the outbuf...
  329. */
  330. int chn = 0;
  331. JSList *node = playback_ports;
  332. JSList *src_node = playback_srcs;
  333. SRC_DATA src;
  334. while ( node != NULL)
  335. {
  336. int i;
  337. jack_port_t *port = (jack_port_t *) node->data;
  338. float *buf = jack_port_get_buffer (port, nframes);
  339. SRC_STATE *src_state = src_node->data;
  340. src.data_in = buf;
  341. src.input_frames = nframes;
  342. src.data_out = resampbuf;
  343. src.output_frames = rlen;
  344. src.end_of_input = 0;
  345. src.src_ratio = current_resample_factor;
  346. src_process( src_state, &src );
  347. for (i=0; i < rlen; i++) {
  348. float_16( resampbuf[i], outbuf[chn+ i*num_channels] );
  349. }
  350. src_node = jack_slist_next (src_node);
  351. node = jack_slist_next (node);
  352. chn++;
  353. }
  354. // now write the output...
  355. again:
  356. err = snd_pcm_writei(alsa_handle, outbuf, src.output_frames_gen);
  357. //err = snd_pcm_writei(alsa_handle, outbuf, src.output_frames_gen);
  358. if( err < 0 ) {
  359. printf( "err = %d\n", err );
  360. if (xrun_recovery(alsa_handle, err) < 0) {
  361. printf("Write error: %s\n", snd_strerror(err));
  362. exit(EXIT_FAILURE);
  363. }
  364. goto again;
  365. }
  366. return 0;
  367. }
  368. /**
  369. * Allocate the necessary jack ports...
  370. */
  371. void alloc_ports( int n_capture, int n_playback ) {
  372. int port_flags = JackPortIsOutput;
  373. int chn;
  374. jack_port_t *port;
  375. char buf[32];
  376. capture_ports = NULL;
  377. for (chn = 0; chn < n_capture; chn++)
  378. {
  379. snprintf (buf, sizeof(buf) - 1, "capture_%u", chn+1);
  380. port = jack_port_register (client, buf,
  381. JACK_DEFAULT_AUDIO_TYPE,
  382. port_flags, 0);
  383. if (!port)
  384. {
  385. printf( "jacknet_client: cannot register port for %s", buf);
  386. break;
  387. }
  388. capture_srcs = jack_slist_append( capture_srcs, src_new( SRC_SINC_FASTEST, 1, NULL ) );
  389. capture_ports = jack_slist_append (capture_ports, port);
  390. }
  391. port_flags = JackPortIsInput;
  392. playback_ports = NULL;
  393. for (chn = 0; chn < n_playback; chn++)
  394. {
  395. snprintf (buf, sizeof(buf) - 1, "playback_%u", chn+1);
  396. port = jack_port_register (client, buf,
  397. JACK_DEFAULT_AUDIO_TYPE,
  398. port_flags, 0);
  399. if (!port)
  400. {
  401. printf( "jacknet_client: cannot register port for %s", buf);
  402. break;
  403. }
  404. playback_srcs = jack_slist_append( playback_srcs, src_new( SRC_SINC_FASTEST, 1, NULL ) );
  405. playback_ports = jack_slist_append (playback_ports, port);
  406. }
  407. }
  408. /**
  409. * This is the shutdown callback for this JACK application.
  410. * It is called by JACK if the server ever shuts down or
  411. * decides to disconnect the client.
  412. */
  413. void jack_shutdown (void *arg) {
  414. exit (1);
  415. }
  416. /**
  417. * be user friendly.
  418. * be user friendly.
  419. * be user friendly.
  420. */
  421. void printUsage() {
  422. fprintf(stderr, "usage: alsa_out [options]\n"
  423. "\n"
  424. " -j <jack name> - reports a different name to jack\n"
  425. " -d <alsa_device> \n"
  426. " -c <channels> \n"
  427. " -p <period_size> \n"
  428. " -n <num_period> \n"
  429. " -r <sample_rate> \n"
  430. " -m <max_diff> \n"
  431. " -t <target_delay> \n"
  432. " -f <catch_factor> \n"
  433. " -i turns on instrumentation\n"
  434. " -v turns on printouts\n"
  435. "\n");
  436. }
  437. /**
  438. * the main function....
  439. */
  440. int main (int argc, char *argv[]) {
  441. char jack_name[30] = "alsa_out";
  442. char alsa_device[30] = "hw:0";
  443. extern char *optarg;
  444. extern int optind, optopt;
  445. int errflg=0;
  446. int c;
  447. while ((c = getopt(argc, argv, "ivj:r:c:p:n:d:m:t:f:F:C:Q:")) != -1) {
  448. switch(c) {
  449. case 'j':
  450. strcpy(jack_name,optarg);
  451. break;
  452. case 'r':
  453. sample_rate = atoi(optarg);
  454. break;
  455. case 'c':
  456. num_channels = atoi(optarg);
  457. break;
  458. case 'p':
  459. period_size = atoi(optarg);
  460. break;
  461. case 'n':
  462. num_periods = atoi(optarg);
  463. break;
  464. case 'd':
  465. strcpy(alsa_device,optarg);
  466. break;
  467. case 't':
  468. target_delay = atoi(optarg);
  469. break;
  470. case 'm':
  471. max_diff = atoi(optarg);
  472. break;
  473. case 'f':
  474. catch_factor = atoi(optarg);
  475. break;
  476. case 'F':
  477. catch_factor2 = atoi(optarg);
  478. break;
  479. case 'C':
  480. pclamp = (double) atoi(optarg);
  481. break;
  482. case 'Q':
  483. controlquant = (double) atoi(optarg);
  484. break;
  485. case 'v':
  486. verbose = 1;
  487. break;
  488. case 'i':
  489. instrument = 1;
  490. break;
  491. case ':':
  492. fprintf(stderr,
  493. "Option -%c requires an operand\n", optopt);
  494. errflg++;
  495. break;
  496. case '?':
  497. fprintf(stderr,
  498. "Unrecognized option: -%c\n", optopt);
  499. errflg++;
  500. }
  501. }
  502. if (errflg) {
  503. printUsage();
  504. exit(2);
  505. }
  506. if ((client = jack_client_new (jack_name)) == 0) {
  507. fprintf (stderr, "jack server not running?\n");
  508. return 1;
  509. }
  510. /* tell the JACK server to call `process()' whenever
  511. there is work to be done.
  512. */
  513. jack_set_process_callback (client, process, 0);
  514. /* tell the JACK server to call `jack_shutdown()' if
  515. it ever shuts down, either entirely, or if it
  516. just decides to stop calling us.
  517. */
  518. jack_on_shutdown (client, jack_shutdown, 0);
  519. // alloc input ports, which are blasted out to alsa...
  520. alloc_ports( 0, num_channels );
  521. // get jack sample_rate
  522. jack_sample_rate = jack_get_sample_rate( client );
  523. if( !sample_rate )
  524. sample_rate = jack_sample_rate;
  525. static_resample_factor = (double) sample_rate / (double) jack_sample_rate;
  526. resample_mean = static_resample_factor;
  527. int i;
  528. for( i=0; i<OFF_D_SIZE; i++ )
  529. offset_array[i] = 0.0;
  530. jack_buffer_size = jack_get_buffer_size( client );
  531. // Setup target delay and max_diff for the normal user, who does not play with them...
  532. if( !target_delay )
  533. target_delay = (num_periods*period_size / 2) - jack_buffer_size/2;
  534. if( !max_diff )
  535. max_diff = target_delay;
  536. if( max_diff > target_delay ) {
  537. fprintf( stderr, "target_delay (%d) cant be smaller than max_diff(%d)\n", target_delay, max_diff );
  538. exit(20);
  539. }
  540. if( (target_delay+max_diff) > (num_periods*period_size) ) {
  541. fprintf( stderr, "target_delay+max_diff (%d) cant be bigger than buffersize(%d)\n", target_delay+max_diff, num_periods*period_size );
  542. exit(20);
  543. }
  544. // now open the alsa fd...
  545. alsa_handle = open_audiofd( alsa_device, 0, sample_rate, num_channels, period_size, num_periods);
  546. if( alsa_handle < 0 )
  547. exit(20);
  548. /* tell the JACK server that we are ready to roll */
  549. if (jack_activate (client)) {
  550. fprintf (stderr, "cannot activate client");
  551. return 1;
  552. }
  553. if( verbose ) {
  554. while(1) {
  555. usleep(500000);
  556. if( output_new_delay ) {
  557. printf( "delay = %d\n", output_new_delay );
  558. output_new_delay = 0;
  559. }
  560. printf( "res: %f, \tdiff = %f, \toffset = %f \n", output_resampling_factor, output_diff, output_offset );
  561. }
  562. } else if( instrument ) {
  563. printf( "# n\tresamp\tdiff\toffseti\tintegral\n");
  564. int n=0;
  565. while(1) {
  566. usleep(1000);
  567. printf( "%d\t%f\t%f\t%f\t%f\n", n++, output_resampling_factor, output_diff, output_offset, output_integral );
  568. }
  569. } else {
  570. while(1) sleep(10);
  571. }
  572. jack_client_close (client);
  573. exit (0);
  574. }