Click.cc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. Click.cc
  3. Copyright 2002-7 Tim Goetze <tim@quitte.de>
  4. http://quitte.de/dsp/
  5. Plugins playing a sound snippet in regular intervals.
  6. */
  7. /*
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  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., 59 Temple Place - Suite 330, Boston, MA
  19. 02111-1307, USA or point your web browser to http://www.gnu.org.
  20. */
  21. #include "basics.h"
  22. #include "waves/click.h"
  23. #include "waves/money.h"
  24. #include "Click.h"
  25. #include "Descriptor.h"
  26. void
  27. ClickStub::init (float * _wave, int _N)
  28. {
  29. wave = _wave;
  30. N = _N;
  31. bpm = -1;
  32. }
  33. template <sample_func_t F>
  34. void
  35. ClickStub::one_cycle (int frames)
  36. {
  37. bpm = getport(0);
  38. sample_t gain = getport(1) * *ports[1];
  39. lp.set (1 - *ports[2]);
  40. sample_t * d = ports[3];
  41. while (frames)
  42. {
  43. if (period == 0)
  44. {
  45. period = (int) (fs * 60 / bpm);
  46. played = 0;
  47. }
  48. int n = min (frames, period);
  49. if (played < N)
  50. {
  51. n = min (n, N - played);
  52. for (int i = 0; i < n; ++i)
  53. {
  54. sample_t x = gain * wave [played + i] + normal;
  55. F (d, i, lp.process (x), adding_gain);
  56. normal = -normal;
  57. }
  58. played += n;
  59. }
  60. else
  61. {
  62. for (int i = 0; i < n; ++i)
  63. {
  64. F (d, i, lp.process (normal), adding_gain);
  65. normal = -normal;
  66. }
  67. }
  68. period -= n;
  69. frames -= n;
  70. d += n;
  71. }
  72. }
  73. /* //////////////////////////////////////////////////////////////////////// */
  74. PortInfo
  75. ClickStub::port_info [] =
  76. {
  77. {
  78. "bpm",
  79. INPUT | CONTROL,
  80. {BOUNDED | DEFAULT_LOW, 4, 244}
  81. }, {
  82. "volume",
  83. INPUT | CONTROL,
  84. {BOUNDED | DEFAULT_MID, 0, 1}
  85. }, {
  86. "damping",
  87. INPUT | CONTROL,
  88. {BOUNDED | DEFAULT_HIGH, 0, 1}
  89. }, {
  90. "out",
  91. OUTPUT | AUDIO,
  92. {0}
  93. }
  94. };
  95. /* //////////////////////////////////////////////////////////////////////// */
  96. #define LENGTH(W) ((int) (sizeof (W) / sizeof (float)))
  97. void
  98. Click::init()
  99. {
  100. this->ClickStub::init (click, LENGTH (click));
  101. }
  102. template <> void
  103. Descriptor<Click>::setup()
  104. {
  105. UniqueID = 1769;
  106. Label = "Click";
  107. Properties = HARD_RT;
  108. Name = CAPS "Click - Metronome";
  109. Maker = "Tim Goetze <tim@quitte.de>";
  110. Copyright = "GPL, 2004-7";
  111. /* fill port info and vtable */
  112. autogen();
  113. }
  114. /* //////////////////////////////////////////////////////////////////////// */
  115. PortInfo
  116. CEO::port_info [] =
  117. {
  118. {
  119. "mpm",
  120. INPUT | CONTROL,
  121. {BOUNDED | DEFAULT_HIGH, 4, 244}
  122. }, {
  123. "volume",
  124. INPUT | CONTROL,
  125. {BOUNDED | DEFAULT_MID, 0, 1}
  126. }, {
  127. "damping",
  128. INPUT | CONTROL,
  129. {BOUNDED | DEFAULT_MIN, 0, 1}
  130. }, {
  131. "out",
  132. OUTPUT | AUDIO,
  133. {0}
  134. }
  135. };
  136. void
  137. CEO::init()
  138. {
  139. this->ClickStub::init (money, LENGTH (money));
  140. }
  141. template <> void
  142. Descriptor<CEO>::setup()
  143. {
  144. UniqueID = 1770;
  145. Label = "CEO";
  146. Properties = HARD_RT;
  147. Name = CAPS "CEO - Chief Executive Oscillator";
  148. Maker = "Tim Goetze <tim@quitte.de>";
  149. Copyright = "GPL, 2004-7";
  150. /* fill port info and vtable */
  151. autogen();
  152. }
  153. /* //////////////////////////////////////////////////////////////////////// */
  154. float dirac [] = { 1, };
  155. PortInfo
  156. Dirac::port_info [] =
  157. {
  158. {
  159. "ppm",
  160. INPUT | CONTROL,
  161. {BOUNDED | DEFAULT_MIN, 30, 60}
  162. }, {
  163. "volume",
  164. INPUT | CONTROL,
  165. {BOUNDED | DEFAULT_0, 0, 1}
  166. }, {
  167. "damping",
  168. INPUT | CONTROL,
  169. {BOUNDED | DEFAULT_0, 0, 1}
  170. }, {
  171. "out",
  172. OUTPUT | AUDIO,
  173. {0}
  174. }
  175. };
  176. void
  177. Dirac::init()
  178. {
  179. this->ClickStub::init (dirac, LENGTH (dirac));
  180. }
  181. template <> void
  182. Descriptor<Dirac>::setup()
  183. {
  184. UniqueID = 2585;
  185. Label = "Dirac";
  186. Properties = HARD_RT;
  187. Name = CAPS "Dirac - One-sample impulse generator";
  188. Maker = "Tim Goetze <tim@quitte.de>";
  189. Copyright = "GPL, 2004-7";
  190. /* fill port info and vtable */
  191. autogen();
  192. }