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.

129 lines
2.8KB

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <unistd.h>
  4. #include <jack/jack.h>
  5. #include <glib.h>
  6. #include <jack/port.h>
  7. jack_port_t *input_port;
  8. jack_port_t *output_port;
  9. int
  10. process (nframes_t nframes, void *arg)
  11. {
  12. sample_t *out = (sample_t *) jack_port_get_buffer (output_port, nframes);
  13. sample_t *in = (sample_t *) jack_port_get_buffer (input_port, nframes);
  14. memcpy (out, in, sizeof (sample_t) * nframes);
  15. return 0;
  16. }
  17. int
  18. bufsize (nframes_t nframes, void *arg)
  19. {
  20. printf ("the maximum buffer size is now %lu\n", nframes);
  21. return 0;
  22. }
  23. int
  24. srate (nframes_t nframes, void *arg)
  25. {
  26. printf ("the sample rate is now %lu/sec\n", nframes);
  27. return 0;
  28. }
  29. void
  30. jack_shutdown (void *arg)
  31. {
  32. exit (1);
  33. }
  34. int
  35. main (int argc, char *argv[])
  36. {
  37. jack_client_t *client;
  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 (this may change in the future).
  80. */
  81. if (jack_connect (client, "alsa_pcm:in_1", jack_port_name (input_port))) {
  82. fprintf (stderr, "cannot connect input ports\n");
  83. }
  84. if (jack_connect (client, jack_port_name (output_port), "alsa_pcm:out_1")) {
  85. fprintf (stderr, "cannot connect output ports\n");
  86. }
  87. /* Since this is just a toy, run for a few seconds, then finish */
  88. sleep (10);
  89. jack_client_close (client);
  90. exit (0);
  91. }