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.

100 lines
2.1KB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <errno.h>
  4. #include <unistd.h>
  5. extern "C"
  6. {
  7. #include <jack/jack.h>
  8. }
  9. #include <FL/Fl.H>
  10. #include <FL/Fl_Window.H>
  11. #include <FL/Fl_Slider.H>
  12. jack_port_t *input_port;
  13. jack_port_t *output_port;
  14. float gain = 0.0; /* slider starts out with zero gain */
  15. int
  16. process (jack_nframes_t nframes, void *arg)
  17. {
  18. jack_default_audio_sample_t *out = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port, nframes);
  19. jack_default_audio_sample_t *in = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port, nframes);
  20. while (nframes--)
  21. out[nframes] = in[nframes] * gain;
  22. return 0;
  23. }
  24. int
  25. bufsize (jack_nframes_t nframes, void *arg)
  26. {
  27. printf ("the maximum buffer size is now %lu\n", nframes);
  28. return 0;
  29. }
  30. int
  31. srate (jack_nframes_t nframes, void *arg)
  32. {
  33. printf ("the sample rate is now %lu/sec\n", nframes);
  34. return 0;
  35. }
  36. void callback(Fl_Slider* s)
  37. {
  38. gain = s->value();
  39. }
  40. int
  41. main (int argc, char *argv[])
  42. {
  43. Fl_Window w(0,0,100,120);
  44. Fl_Slider s(10,10,20,100);
  45. w.show();
  46. s.callback((Fl_Callback*) callback);
  47. jack_client_t *client;
  48. if ((client = jack_client_new ("fltktest")) == 0) {
  49. fprintf (stderr, "jack server not running?\n");
  50. return 1;
  51. }
  52. jack_set_process_callback (client, process, 0);
  53. jack_set_buffer_size_callback (client, bufsize, 0);
  54. jack_set_sample_rate_callback (client, srate, 0);
  55. printf ("engine sample rate: %lu\n", jack_get_sample_rate (client));
  56. input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  57. output_port = jack_port_register (client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  58. if (jack_activate (client)) {
  59. fprintf (stderr, "cannot activate client");
  60. }
  61. printf ("client activated\n");
  62. if (jack_connect (client, "alsa_pcm:capture_1", jack_port_name (input_port))) {
  63. fprintf (stderr, "cannot connect input ports\n");
  64. }
  65. if (jack_connect (client, jack_port_name (output_port), "alsa_pcm:playback_1")) {
  66. fprintf (stderr, "cannot connect output ports\n");
  67. }
  68. Fl::run();
  69. printf ("done sleeping, now closing...\n");
  70. jack_client_close (client);
  71. exit (0);
  72. }