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.

99 lines
2.0KB

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