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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // ----------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2010 Fons Adriaensen <fons@linuxaudio.org>
  4. // Modified by falkTX on Jan-Apr 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 (jack_client_t *jclient, bool ambis) :
  24. A_thread ("Jclient"),
  25. _jack_client (jclient),
  26. _active (false),
  27. _ambis (ambis)
  28. {
  29. init_jack ();
  30. }
  31. Jclient::~Jclient (void)
  32. {
  33. if (_jack_client) close_jack ();
  34. }
  35. void Jclient::init_jack (void)
  36. {
  37. jack_set_process_callback (_jack_client, jack_static_process, (void *) this);
  38. jack_on_shutdown (_jack_client, jack_static_shutdown, (void *) this);
  39. jack_activate (_jack_client);
  40. _fsamp = jack_get_sample_rate (_jack_client);
  41. _fragm = 1024;
  42. _nsamp = 0;
  43. if (_ambis)
  44. {
  45. _inpports [0] = jack_port_register (_jack_client, "in.L", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  46. _inpports [1] = jack_port_register (_jack_client, "in.R", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  47. _outports [0] = jack_port_register (_jack_client, "out.W", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  48. _outports [1] = jack_port_register (_jack_client, "out.X", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  49. _outports [2] = jack_port_register (_jack_client, "out.Y", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  50. _outports [3] = jack_port_register (_jack_client, "out.Z", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  51. }
  52. else
  53. {
  54. _inpports [0] = jack_port_register (_jack_client, "in.L", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  55. _inpports [1] = jack_port_register (_jack_client, "in.R", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  56. _outports [0] = jack_port_register (_jack_client, "out.L", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  57. _outports [1] = jack_port_register (_jack_client, "out.R", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
  58. }
  59. _reverb.init (_fsamp, _ambis);
  60. _active = true;
  61. }
  62. void Jclient::close_jack ()
  63. {
  64. jack_deactivate (_jack_client);
  65. jack_client_close (_jack_client);
  66. }
  67. void Jclient::jack_static_shutdown (void *arg)
  68. {
  69. ((Jclient *) arg)->jack_shutdown ();
  70. }
  71. int Jclient::jack_static_process (jack_nframes_t nframes, void *arg)
  72. {
  73. return ((Jclient *) arg)->jack_process (nframes);
  74. }
  75. void Jclient::jack_shutdown (void)
  76. {
  77. send_event (EV_EXIT, 1);
  78. }
  79. int Jclient::jack_process (int frames)
  80. {
  81. int i, k, n_inp, n_out;
  82. float *inp [2];
  83. float *out [4];
  84. if (!_active) return 0;
  85. n_inp = 2;
  86. n_out = _ambis ? 4 : 2;
  87. for (i = 0; i < n_inp; i++) inp [i] = (float *) jack_port_get_buffer (_inpports [i], frames);
  88. for (i = 0; i < n_out; i++) out [i] = (float *) jack_port_get_buffer (_outports [i], frames);
  89. while (frames)
  90. {
  91. if (!_nsamp)
  92. {
  93. _reverb.prepare (_fragm);
  94. _nsamp = _fragm;
  95. }
  96. k = (_nsamp < frames) ? _nsamp : frames;
  97. _reverb.process (k, inp, out);
  98. for (i = 0; i < n_inp; i++) inp [i] += k;
  99. for (i = 0; i < n_out; i++) out [i] += k;
  100. frames -= k;
  101. _nsamp -= k;
  102. }
  103. return 0;
  104. }
  105. }