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.

145 lines
3.3KB

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <jack/jack.h>
  6. jack_port_t *input_port;
  7. jack_port_t *output_port;
  8. int
  9. process (jack_nframes_t nframes, void *arg)
  10. {
  11. jack_default_audio_sample_t *out = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port, nframes);
  12. jack_default_audio_sample_t *in = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port, nframes);
  13. memcpy (out, in, sizeof (jack_default_audio_sample_t) * nframes);
  14. return 0;
  15. }
  16. int
  17. bufsize (jack_nframes_t nframes, void *arg)
  18. {
  19. printf ("the maximum buffer size is now %lu\n", nframes);
  20. return 0;
  21. }
  22. int
  23. srate (jack_nframes_t nframes, void *arg)
  24. {
  25. printf ("the sample rate is now %lu/sec\n", nframes);
  26. return 0;
  27. }
  28. void
  29. jack_shutdown (void *arg)
  30. {
  31. exit (1);
  32. }
  33. int
  34. main (int argc, char *argv[])
  35. {
  36. jack_client_t *client;
  37. const char **ports;
  38. if (argc < 2) {
  39. fprintf (stderr, "usage: jack_simple_client <name>\n");
  40. return 1;
  41. }
  42. /* try to become a client of the JACK server */
  43. if ((client = jack_client_new (argv[1])) == 0) {
  44. fprintf (stderr, "jack server not running?\n");
  45. return 1;
  46. }
  47. /* tell the JACK server to call `process()' whenever
  48. there is work to be done.
  49. */
  50. jack_set_process_callback (client, process, 0);
  51. /* tell the JACK server to call `bufsize()' whenever
  52. the maximum number of frames that will be passed
  53. to `process()' changes
  54. */
  55. jack_set_buffer_size_callback (client, bufsize, 0);
  56. /* tell the JACK server to call `srate()' whenever
  57. the sample rate of the system changes.
  58. */
  59. jack_set_sample_rate_callback (client, srate, 0);
  60. /* tell the JACK server to call `jack_shutdown()' if
  61. it ever shuts down, either entirely, or if it
  62. just decides to stop calling us.
  63. */
  64. jack_on_shutdown (client, jack_shutdown, 0);
  65. /* display the current sample rate. once the client is activated
  66. (see below), you should rely on your own sample rate
  67. callback (see above) for this value.
  68. */
  69. printf ("engine sample rate: %lu\n", jack_get_sample_rate (client));
  70. /* create two ports */
  71. input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  72. output_port = jack_port_register (client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  73. /* tell the JACK server that we are ready to roll */
  74. if (jack_activate (client)) {
  75. fprintf (stderr, "cannot activate client");
  76. return 1;
  77. }
  78. /* connect the ports. Note: you can't do this before
  79. the client is activated, because we can't allow
  80. connections to be made to clients that aren't
  81. running.
  82. */
  83. if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput)) == NULL) {
  84. fprintf(stderr, "Cannot find any physical capture ports");
  85. exit(1);
  86. }
  87. if (jack_connect (client, ports[0], jack_port_name (input_port))) {
  88. fprintf (stderr, "cannot connect input ports\n");
  89. }
  90. free (ports);
  91. if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) {
  92. fprintf(stderr, "Cannot find any physical playback ports");
  93. exit(1);
  94. }
  95. if (jack_connect (client, jack_port_name (output_port), ports[0])) {
  96. fprintf (stderr, "cannot connect output ports\n");
  97. }
  98. free (ports);
  99. /* Since this is just a toy, run for a few seconds, then finish */
  100. sleep (10);
  101. jack_client_close (client);
  102. exit (0);
  103. }