Lorenz.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. Lorenz.cc
  3. Copyright 2002-11 Tim Goetze <tim@quitte.de>
  4. http://quitte.de/dsp/
  5. the sound of a Lorenz attractor.
  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 <stdlib.h>
  22. #include "basics.h"
  23. #include "Lorenz.h"
  24. #include "Descriptor.h"
  25. void
  26. Lorenz::init()
  27. {
  28. lorenz.init (h = .001, 0.1 * frandom());
  29. gain = 0;
  30. }
  31. template <sample_func_t F>
  32. void
  33. Lorenz::one_cycle (int frames)
  34. {
  35. lorenz.set_rate (*ports[0]);
  36. double g = (gain == *ports[4]) ?
  37. 1 : pow (getport(4) / gain, 1. / (double) frames);
  38. sample_t * d = ports[5];
  39. sample_t x, sx = getport(1), sy = getport(2), sz = getport(3);
  40. for (int i = 0; i < frames; ++i)
  41. {
  42. lorenz.step();
  43. x = sx * lorenz.get_x() + sy * lorenz.get_y() + sz * lorenz.get_z();
  44. F (d, i, gain * x, adding_gain);
  45. gain *= g;
  46. }
  47. gain = getport(4);
  48. }
  49. /* //////////////////////////////////////////////////////////////////////// */
  50. PortInfo
  51. Lorenz::port_info [] =
  52. {
  53. {
  54. "h",
  55. INPUT | CONTROL,
  56. {BOUNDED | DEFAULT_LOW, 0, 1}
  57. }, {
  58. "x",
  59. INPUT | CONTROL,
  60. {BOUNDED | DEFAULT_1, 0, 1}
  61. }, {
  62. "y",
  63. INPUT | CONTROL,
  64. {BOUNDED | DEFAULT_0, 0, 1}
  65. }, {
  66. "z",
  67. INPUT | CONTROL,
  68. {BOUNDED | DEFAULT_0, 0, 1}
  69. }, {
  70. "volume",
  71. INPUT | CONTROL,
  72. {BOUNDED | DEFAULT_MID, MIN_GAIN, 1}
  73. }, {
  74. "out",
  75. OUTPUT | AUDIO,
  76. {0}
  77. }
  78. };
  79. template <> void
  80. Descriptor<Lorenz>::setup()
  81. {
  82. UniqueID = 1774;
  83. Label = "Lorenz";
  84. Properties = HARD_RT;
  85. Name = CAPS "Lorenz - The sound of a Lorenz attractor";
  86. Maker = "Tim Goetze <tim@quitte.de>";
  87. Copyright = "GPL, 2004-7";
  88. /* fill port info and vtable */
  89. autogen();
  90. }