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
3.0KB

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