Roessler.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. dsp/Roessler.h
  3. Copyright 2003-4 Tim Goetze <tim@quitte.de>
  4. http://quitte.de/dsp/
  5. Roessler fractal.
  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. #ifndef _DSP_ROESSLER_H_
  22. #define _DSP_ROESSLER_H_
  23. namespace DSP {
  24. class Roessler
  25. {
  26. public:
  27. double x[2], y[2], z[2];
  28. double h, a, b, c;
  29. int I;
  30. public:
  31. Roessler()
  32. {
  33. h = 0.001;
  34. a = .2;
  35. b = .2;
  36. c = 5.7;
  37. }
  38. /* rate is normalized (0 .. 1) */
  39. void set_rate (double r)
  40. {
  41. h = max (.000001, r * .096);
  42. }
  43. void init (double _h = .001, double seed = .0)
  44. {
  45. h = _h;
  46. I = 0;
  47. x[0] = .0001 + .0001 * seed;
  48. y[0] = .0001;
  49. z[0] = .0001;
  50. for (int i = 0; i < 5000; ++i)
  51. get();
  52. }
  53. sample_t get()
  54. {
  55. int J = I ^ 1;
  56. x[J] = x[I] + h * (- y[I] - z[I]);
  57. y[J] = y[I] + h * (x[I] + a * y[I]);
  58. z[J] = z[I] + h * (b + z[I] * (x[I] - c));
  59. I = J;
  60. return x[I] * .01725 + z[I] * .015;
  61. }
  62. double get_x()
  63. {
  64. return x[I];
  65. }
  66. double get_y()
  67. {
  68. return y[I];
  69. }
  70. double get_z()
  71. {
  72. return z[I];
  73. }
  74. };
  75. } /* namespace DSP */
  76. #endif /* _DSP_ROESSLER_H_ */