Cabinet.cc 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. Cabinet.cc
  3. Copyright 2002-7 Tim Goetze <tim@quitte.de>
  4. http://quitte.de/dsp/
  5. CabinetI - 16th order IIR filters modeled after various impulse responses
  6. from Steve Harris' 'imp' plugin. Limited to 44.1 kHz sample rate.
  7. CabinetII - 32nd order IIR filters modeled after the same impulse responses
  8. using a different algorithm. Versions for 44.1 / 48 / 88.2 / 96 kHz sample
  9. rates, switched at runtime.
  10. */
  11. /*
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23. 02111-1307, USA or point your web browser to http://www.gnu.org.
  24. */
  25. #include "basics.h"
  26. #include "Cabinet.h"
  27. #include "Descriptor.h"
  28. Model16
  29. CabinetI::models [] =
  30. {
  31. {
  32. 1, /* identity */
  33. {1},
  34. {0},
  35. 1,
  36. }, {
  37. 16, /* unmatched, off-axis */
  38. {0.44334744339382504, 0.49764265352620912, 0.19936863766114088, 0.0038388115609433826, -0.072080744430548876, -0.092589757815768933, -0.023760971045285254, 0.058929802988203807, 0.11073296313735595, 0.14389046518738619, 0.052981055774577353, -0.11817321919764193, -0.22957467728465422, -0.26301284181138151, -0.25586853638823448, -0.10768194462289554},
  39. {0.0, 0.71138736215182674, 0.19571088506350195, -0.086897678126924227, -0.18344238266155902, -0.13338660100611671, -0.017424587504494098, 0.062014975470330351, 0.077979014877680469, 0.039134631327482176, -0.046646061538403727, -0.040653480351542266, 0.068462230153713749, 0.14313162261479676, 0.058844200671679531, -0.17878548463526983},
  40. 1 / 4.4,
  41. }, {
  42. 16, /* unmatched */
  43. {0.58952373363852417, 0.43625942509584309, 0.235412203403113, 0.048252951521505258, -0.1002076253350956, -0.14467958356216026, -0.074304873528329402, 0.060945557247412331, 0.15959845551788171, 0.20970924189636411, 0.15361368007229703, 0.025339061869183478, -0.11824836967489599, -0.19384403813690479, -0.19295873693806628, -0.058904754435169508},
  44. {0.0, 0.6596380198994729, 0.20825670531468143, -0.10508784276271754, -0.24698905246649294, -0.21519418569376192, -0.10057489587096909, -0.006175810942624007, -0.0019249936836196989, -0.045827268144865707, -0.10184708094147235, -0.09177820187618313, -0.017740067693127175, 0.058828573780348989, 0.010559807576350673, -0.19412688465216324},
  45. 1 / 5.7,
  46. }, {
  47. 16, /* superchamp */
  48. {0.5335550129666069, 0.61768496153556829, 0.2080126894040209, -0.0067283013134491337, -0.10433152421155355, -0.16159936513841233, -0.10593018443866807, -0.091854930675998661, 0.0023550324496513643, 0.14327516190088724, 0.14688292534697539, 0.089539872443625601, -0.053854769352683005, -0.15693904535289377, -0.083502230074838577, 0.0090113128614708465},
  49. {0.0, 0.67745858591653696, 0.044802106922746734, -0.1932642251200547, -0.18922360327572652, -0.052980570047914469, 0.020446992577988904, -0.028951451474818618, -0.085212072485126716, -0.12241212382510525, -0.089259371449674357, 0.010469056928395087, 0.049019357277555603, 0.037212453438250505, -0.046374612934843573, -0.045133341919937828},
  50. 1 / 4.0,
  51. }, {
  52. 16, /* fender-vibrolux-68 */
  53. {0.68447985102464837, 0.61538710771230021, -0.28804707230137599, -0.23656583372846893, 0.083100874242250655, -0.027792816938813913, 0.055558334440593965, 0.044458161718059774, -0.25467542393376252, -0.33660492613760157, -0.024663941486403884, 0.1172751972420942, -0.021832135450802759, 0.21440383631745469, 0.20828506390107443, -0.10289957687018361},
  54. {0.0, 0.50968169360260451, -0.48159141882733714, -0.10856607456906017, -0.026802006374108955, -0.24967309940249552, -0.21422424792787859, 0.019271890369619571, 0.08065394481240884, -0.061665636719946543, 0.031613782215493547, 0.069574436103950893, -0.07180222507768147, -0.14447996563879059, 0.012044815820150268, -0.0073237976200291044},
  55. 1 / 2.0,
  56. }, {
  57. 16, /* marshall */
  58. {0.38455665328113242, 0.50304089890302783, 0.33653970418909934, 0.085604896315814846, -0.070239383452479598, -0.10479060878654689, -0.060150883776583335, 0.030121882977878822, 0.12441775056532201, 0.18287316824579156, 0.17035705141865287, 0.10315414401519916, 0.036357097566567576, 0.024474446155666255, 0.042359967009557103, 0.059946316626725109},
  59. {0.0, 0.68167571829534335, 0.16877527811114035, -0.17427551663276897, -0.25780056810728452, -0.16065744581310681, -0.032007062964857856, 0.033882840656718101, -0.0038880045892747792, -0.084876415098991506, -0.13865107122780057, -0.10073571899064113, -0.013199668806255366, 0.038170305284592504, -0.026492576852036546, -0.12667775510054707},
  60. 1 / 4.2,
  61. }
  62. };
  63. /* //////////////////////////////////////////////////////////////////////// */
  64. void
  65. CabinetI::init()
  66. {
  67. h = 0;
  68. model = 0;
  69. }
  70. void
  71. CabinetI::switch_model (int m)
  72. {
  73. if (m < 0) m = 0;
  74. else if (m > 5) m = 5;
  75. model = m;
  76. n = models[m].n;
  77. a = models[m].a;
  78. b = models[m].b;
  79. gain = models[m].gain * DSP::db2lin (getport(2));
  80. memset (x, 0, sizeof (x));
  81. memset (y, 0, sizeof (y));
  82. }
  83. void
  84. CabinetI::activate()
  85. {
  86. switch_model ((int) getport(1));
  87. gain = models[model].gain * DSP::db2lin (getport(2));
  88. }
  89. template <sample_func_t F>
  90. void
  91. CabinetI::one_cycle (int frames)
  92. {
  93. sample_t * s = ports[0];
  94. int m = (int) getport (1);
  95. if (m != model) switch_model (m);
  96. sample_t g = models[model].gain * DSP::db2lin (getport(2));
  97. double gf = pow (g / gain, 1 / (double) frames);
  98. sample_t * d = ports[3];
  99. for (int i = 0; i < frames; ++i)
  100. {
  101. register cabinet_float out = s[i] + normal;
  102. x[h] = out;
  103. out *= a[0];
  104. for (int j = 1, z = h - 1; j < n; --z, ++j)
  105. {
  106. z &= 15;
  107. out += a[j] * x[z];
  108. out += b[j] * y[z];
  109. }
  110. y[h] = out;
  111. h = (h + 1) & 15;
  112. F (d, i, gain * out, adding_gain);
  113. gain *= gf;
  114. }
  115. }
  116. /* //////////////////////////////////////////////////////////////////////// */
  117. PortInfo
  118. CabinetI::port_info [] =
  119. {
  120. {
  121. "in",
  122. INPUT | AUDIO,
  123. {BOUNDED, -1, 1}
  124. }, {
  125. "model",
  126. INPUT | CONTROL,
  127. {BOUNDED | INTEGER | DEFAULT_1, 0, 5}
  128. }, {
  129. "gain (dB)",
  130. INPUT | CONTROL,
  131. {BOUNDED | DEFAULT_0, -24, 24}
  132. }, {
  133. "out",
  134. OUTPUT | AUDIO,
  135. {0}
  136. }
  137. };
  138. /* //////////////////////////////////////////////////////////////////////// */
  139. template <> void
  140. Descriptor<CabinetI>::setup()
  141. {
  142. UniqueID = 1766;
  143. Label = "CabinetI";
  144. Properties = HARD_RT;
  145. Name = CAPS "CabinetI - Loudspeaker cabinet emulation";
  146. Maker = "Tim Goetze <tim@quitte.de>";
  147. Copyright = "GPL, 2002-7";
  148. /* fill port info and vtable */
  149. autogen();
  150. }
  151. /* CabinetII ////////////////////////////////////////////////////////////// */
  152. #include "Cabinet-Models32.h"
  153. void
  154. CabinetII::init()
  155. {
  156. if (fs < 46000)
  157. models = models44100;
  158. else if (fs < 72000)
  159. models = models48000;
  160. else if (fs < 92000)
  161. models = models88200;
  162. else
  163. models = models96000;
  164. h = 0;
  165. model = 0;
  166. }
  167. void
  168. CabinetII::switch_model (int m)
  169. {
  170. model = m;
  171. n = models[m].n;
  172. a = models[m].a;
  173. b = models[m].b;
  174. gain = models[m].gain * DSP::db2lin (getport(2));
  175. memset (x, 0, sizeof (x));
  176. memset (y, 0, sizeof (y));
  177. }
  178. void
  179. CabinetII::activate()
  180. {
  181. switch_model ((int) getport(1));
  182. }
  183. template <sample_func_t F>
  184. void
  185. CabinetII::one_cycle (int frames)
  186. {
  187. sample_t * s = ports[0];
  188. int m = (int) getport (1);
  189. if (m != model) switch_model (m);
  190. sample_t g = models[model].gain * DSP::db2lin (getport(2));
  191. double gf = pow (g / gain, 1 / (double) frames);
  192. sample_t * d = ports[3];
  193. for (int i = 0; i < frames; ++i)
  194. {
  195. register cabinet_float out = s[i] + normal;
  196. x[h] = out;
  197. out *= a[0];
  198. for (int j = 1, z = h - 1; j < n; --z, ++j)
  199. {
  200. z &= 31;
  201. out += a[j] * x[z];
  202. out += b[j] * y[z];
  203. }
  204. y[h] = out;
  205. h = (h + 1) & 31;
  206. F (d, i, gain * out, adding_gain);
  207. gain *= gf;
  208. }
  209. }
  210. /* //////////////////////////////////////////////////////////////////////// */
  211. PortInfo
  212. CabinetII::port_info [] =
  213. {
  214. {
  215. "in",
  216. INPUT | AUDIO,
  217. {BOUNDED, -1, 1}
  218. }, {
  219. "model",
  220. INPUT | CONTROL,
  221. {BOUNDED | INTEGER | DEFAULT_1, 0, 7}
  222. }, {
  223. "gain (dB)",
  224. INPUT | CONTROL,
  225. {BOUNDED | DEFAULT_0, -24, 24}
  226. }, {
  227. "out",
  228. OUTPUT | AUDIO,
  229. {0}
  230. }
  231. };
  232. /* //////////////////////////////////////////////////////////////////////// */
  233. template <> void
  234. Descriptor<CabinetII>::setup()
  235. {
  236. UniqueID = 2581;
  237. Label = "CabinetII";
  238. Properties = HARD_RT;
  239. Name = CAPS "CabinetII - Refined loudspeaker cabinet emulation";
  240. Maker = "Tim Goetze <tim@quitte.de>";
  241. Copyright = "GPL, 2002-7";
  242. /* fill port info and vtable */
  243. autogen();
  244. }