Audio plugin host https://kx.studio/carla
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.

jclient.cc 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // ----------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2010 Fons Adriaensen <fons@linuxaudio.org>
  4. // Modified by falkTX on Jan 2015 for inclusion in Carla
  5. //
  6. // This program is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 2 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. //
  20. // ----------------------------------------------------------------------
  21. #include "jclient.h"
  22. namespace REV1 {
  23. Jclient::Jclient (const char *jname, jack_client_t *jclient, bool ambis) :
  24. A_thread ("Jclient"),
  25. _jack_client (jclient),
  26. _active (false),
  27. _jname (0),
  28. _ambis (ambis)
  29. {
  30. init_jack (jname);
  31. }
  32. Jclient::~Jclient (void)
  33. {
  34. if (_jack_client) close_jack ();
  35. }
  36. void Jclient::init_jack (const char *jname)
  37. {
  38. jack_set_process_callback (_jack_client, jack_static_process, (void *) this);
  39. jack_on_shutdown (_jack_client, jack_static_shutdown, (void *) this);
  40. if (jack_activate (_jack_client))
  41. {
  42. fprintf(stderr, "Can't activate JACK.\n");
  43. exit (1);
  44. }
  45. _jname = jack_get_client_name (_jack_client);
  46. _fsamp = jack_get_sample_rate (_jack_client);
  47. _fragm = 1024;
  48. _nsamp = 0;
  49. if (_ambis)
  50. {
  51. _inpports [0] = jack_port_register (_jack_client, "in.L", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  52. _inpports [1] = jack_port_register (_jack_client, "in.R", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  53. _outports [0] = jack_port_register (_jack_client, "out.W", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  54. _outports [1] = jack_port_register (_jack_client, "out.X", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  55. _outports [2] = jack_port_register (_jack_client, "out.Y", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  56. _outports [3] = jack_port_register (_jack_client, "out.Z", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  57. }
  58. else
  59. {
  60. _inpports [0] = jack_port_register (_jack_client, "in.L", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  61. _inpports [1] = jack_port_register (_jack_client, "in.R", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  62. _outports [0] = jack_port_register (_jack_client, "out.L", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  63. _outports [1] = jack_port_register (_jack_client, "out.R", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  64. }
  65. _reverb.init (_fsamp, _ambis);
  66. _active = true;
  67. }
  68. void Jclient::close_jack ()
  69. {
  70. jack_deactivate (_jack_client);
  71. jack_client_close (_jack_client);
  72. }
  73. void Jclient::jack_static_shutdown (void *arg)
  74. {
  75. ((Jclient *) arg)->jack_shutdown ();
  76. }
  77. int Jclient::jack_static_process (jack_nframes_t nframes, void *arg)
  78. {
  79. return ((Jclient *) arg)->jack_process (nframes);
  80. }
  81. void Jclient::jack_shutdown (void)
  82. {
  83. send_event (EV_EXIT, 1);
  84. }
  85. int Jclient::jack_process (int frames)
  86. {
  87. int i, k, n_inp, n_out;
  88. float *inp [2];
  89. float *out [4];
  90. if (!_active) return 0;
  91. n_inp = 2;
  92. n_out = _ambis ? 4 : 2;
  93. for (i = 0; i < n_inp; i++) inp [i] = (float *) jack_port_get_buffer (_inpports [i], frames);
  94. for (i = 0; i < n_out; i++) out [i] = (float *) jack_port_get_buffer (_outports [i], frames);
  95. while (frames)
  96. {
  97. if (!_nsamp)
  98. {
  99. _reverb.prepare (_fragm);
  100. _nsamp = _fragm;
  101. }
  102. k = (_nsamp < frames) ? _nsamp : frames;
  103. _reverb.process (k, inp, out);
  104. for (i = 0; i < n_inp; i++) inp [i] += k;
  105. for (i = 0; i < n_out; i++) out [i] += k;
  106. frames -= k;
  107. _nsamp -= k;
  108. }
  109. return 0;
  110. }
  111. }