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.

84 lines
1.8KB

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <unistd.h>
  4. #include <jack/jack.h>
  5. jack_port_t *input_port;
  6. jack_port_t *output_port;
  7. int
  8. process (nframes_t nframes, void *arg)
  9. {
  10. sample_t *out = (sample_t *) jack_port_get_buffer (output_port, nframes);
  11. sample_t *in = (sample_t *) jack_port_get_buffer (input_port, nframes);
  12. memcpy (out, in, sizeof (sample_t) * nframes);
  13. return 0;
  14. }
  15. int
  16. bufsize (nframes_t nframes, void *arg)
  17. {
  18. printf ("the maximum buffer size is now %lu\n", nframes);
  19. return 0;
  20. }
  21. int
  22. srate (nframes_t nframes, void *arg)
  23. {
  24. printf ("the sample rate is now %lu/sec\n", nframes);
  25. return 0;
  26. }
  27. int
  28. main (int argc, char *argv[])
  29. {
  30. jack_client_t *client;
  31. if (argc < 2) {
  32. fprintf (stderr, "usage: aeclient <name>\n");
  33. return 1;
  34. }
  35. if ((client = jack_client_new (argv[1])) == 0) {
  36. fprintf (stderr, "jack server not running?\n");
  37. return 1;
  38. }
  39. jack_set_process_callback (client, process, 0);
  40. jack_set_buffer_size_callback (client, bufsize, 0);
  41. jack_set_sample_rate_callback (client, srate, 0);
  42. printf ("engine sample rate: %lu\n", jack_get_sample_rate (client));
  43. input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  44. output_port = jack_port_register (client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  45. if (jack_activate (client)) {
  46. fprintf (stderr, "cannot activate client");
  47. }
  48. printf ("client activated\n");
  49. if (jack_port_connect (client, "ALSA I/O:Input 1", jack_port_name (input_port))) {
  50. fprintf (stderr, "cannot connect input ports\n");
  51. }
  52. if (jack_port_connect (client, jack_port_name (output_port), "ALSA I/O:Output 1")) {
  53. fprintf (stderr, "cannot connect output ports\n");
  54. }
  55. sleep (5);
  56. printf ("done sleeping, now closing...\n");
  57. jack_client_close (client);
  58. exit (0);
  59. }