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.

reverb.h 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // -----------------------------------------------------------------------
  2. //
  3. // Copyright (C) 2003-2011 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. #ifndef __REVERB_H
  22. #define __REVERB_H
  23. #include "pareq.h"
  24. namespace REV1 {
  25. // -----------------------------------------------------------------------
  26. class Diff1
  27. {
  28. private:
  29. friend class Reverb;
  30. Diff1 (void);
  31. ~Diff1 (void);
  32. void init (int size, float c);
  33. void fini (void);
  34. float process (float x)
  35. {
  36. float z = _line [_i];
  37. x -= _c * z;
  38. _line [_i] = x;
  39. if (++_i == _size) _i = 0;
  40. return z + _c * x;
  41. }
  42. int _i;
  43. float _c;
  44. int _size;
  45. float *_line;
  46. };
  47. // -----------------------------------------------------------------------
  48. class Filt1
  49. {
  50. private:
  51. friend class Reverb;
  52. Filt1 (void) : _slo (0), _shi (0) {}
  53. ~Filt1 (void) {}
  54. void set_params (float del, float tmf, float tlo, float wlo, float thi, float chi);
  55. float process (float x)
  56. {
  57. _slo += _wlo * (x - _slo) + 1e-10f;
  58. x += _glo * _slo;
  59. _shi += _whi * (x - _shi);
  60. return _gmf * _shi;
  61. }
  62. float _gmf;
  63. float _glo;
  64. float _wlo;
  65. float _whi;
  66. float _slo;
  67. float _shi;
  68. };
  69. // -----------------------------------------------------------------------
  70. class Delay
  71. {
  72. private:
  73. friend class Reverb;
  74. Delay (void);
  75. ~Delay (void);
  76. void init (int size);
  77. void fini (void);
  78. float read (void)
  79. {
  80. return _line [_i];
  81. }
  82. void write (float x)
  83. {
  84. _line [_i++] = x;
  85. if (_i == _size) _i = 0;
  86. }
  87. int _i;
  88. int _size;
  89. float *_line;
  90. };
  91. // -----------------------------------------------------------------------
  92. class Vdelay
  93. {
  94. private:
  95. friend class Reverb;
  96. Vdelay (void);
  97. ~Vdelay (void);
  98. void init (int size);
  99. void fini (void);
  100. void set_delay (int del);
  101. float read (void)
  102. {
  103. float x = _line [_ir++];
  104. if (_ir == _size) _ir = 0;
  105. return x;
  106. }
  107. void write (float x)
  108. {
  109. _line [_iw++] = x;
  110. if (_iw == _size) _iw = 0;
  111. }
  112. int _ir;
  113. int _iw;
  114. int _size;
  115. float *_line;
  116. };
  117. // -----------------------------------------------------------------------
  118. class Reverb
  119. {
  120. public:
  121. Reverb (void);
  122. ~Reverb (void);
  123. void init (float fsamp, bool ambis);
  124. void fini (void);
  125. void prepare (int n);
  126. void process (int n, float *inp [], float *out []);
  127. void set_delay (float v) { _ipdel = v; _cntA1++; }
  128. void set_xover (float v) { _xover = v; _cntB1++; }
  129. void set_rtlow (float v) { _rtlow = v; _cntB1++; }
  130. void set_rtmid (float v) { _rtmid = v; _cntB1++; _cntC1++; }
  131. void set_fdamp (float v) { _fdamp = v; _cntB1++; }
  132. void set_opmix (float v) { _opmix = v; _cntC1++; }
  133. void set_rgxyz (float v) { _rgxyz = v; _cntC1++; }
  134. void set_eq1 (float f, float g) { _pareq1.setparam (f, g); }
  135. void set_eq2 (float f, float g) { _pareq2.setparam (f, g); }
  136. private:
  137. float _fsamp;
  138. bool _ambis;
  139. Vdelay _vdelay0;
  140. Vdelay _vdelay1;
  141. Diff1 _diff1 [8];
  142. Filt1 _filt1 [8];
  143. Delay _delay [8];
  144. volatile int _cntA1;
  145. volatile int _cntB1;
  146. volatile int _cntC1;
  147. int _cntA2;
  148. int _cntB2;
  149. int _cntC2;
  150. float _ipdel;
  151. float _xover;
  152. float _rtlow;
  153. float _rtmid;
  154. float _fdamp;
  155. float _opmix;
  156. float _rgxyz;
  157. float _g0, _d0;
  158. float _g1, _d1;
  159. Pareq _pareq1;
  160. Pareq _pareq2;
  161. static float _tdiff1 [8];
  162. static float _tdelay [8];
  163. };
  164. // -----------------------------------------------------------------------
  165. }
  166. #endif