OscSinCos.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*****************************************************************************
  2. OscSinCos.hpp
  3. By Laurent de Soras
  4. --- Legal stuff ---
  5. This program is free software. It comes without any warranty, to
  6. the extent permitted by applicable law. You can redistribute it
  7. and/or modify it under the terms of the Do What The Fuck You Want
  8. To Public License, Version 2, as published by Sam Hocevar. See
  9. http://sam.zoy.org/wtfpl/COPYING for more details.
  10. *Tab=3***********************************************************************/
  11. #if defined (ffft_OscSinCos_CURRENT_CODEHEADER)
  12. #error Recursive inclusion of OscSinCos code header.
  13. #endif
  14. #define ffft_OscSinCos_CURRENT_CODEHEADER
  15. #if ! defined (ffft_OscSinCos_CODEHEADER_INCLUDED)
  16. #define ffft_OscSinCos_CODEHEADER_INCLUDED
  17. /*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
  18. #include <cmath>
  19. namespace std { }
  20. namespace ffft
  21. {
  22. /*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
  23. template <class T>
  24. OscSinCos <T>::OscSinCos ()
  25. : _pos_cos (1)
  26. , _pos_sin (0)
  27. , _step_cos (1)
  28. , _step_sin (0)
  29. {
  30. // Nothing
  31. }
  32. template <class T>
  33. void OscSinCos <T>::set_step (double angle_rad)
  34. {
  35. using namespace std;
  36. _step_cos = static_cast <DataType> (cos (angle_rad));
  37. _step_sin = static_cast <DataType> (sin (angle_rad));
  38. }
  39. template <class T>
  40. typename OscSinCos <T>::DataType OscSinCos <T>::get_cos () const
  41. {
  42. return (_pos_cos);
  43. }
  44. template <class T>
  45. typename OscSinCos <T>::DataType OscSinCos <T>::get_sin () const
  46. {
  47. return (_pos_sin);
  48. }
  49. template <class T>
  50. void OscSinCos <T>::step ()
  51. {
  52. const DataType old_cos = _pos_cos;
  53. const DataType old_sin = _pos_sin;
  54. _pos_cos = old_cos * _step_cos - old_sin * _step_sin;
  55. _pos_sin = old_cos * _step_sin + old_sin * _step_cos;
  56. }
  57. template <class T>
  58. void OscSinCos <T>::clear_buffers ()
  59. {
  60. _pos_cos = static_cast <DataType> (1);
  61. _pos_sin = static_cast <DataType> (0);
  62. }
  63. /*\\\ PROTECTED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
  64. /*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
  65. } // namespace ffft
  66. #endif // ffft_OscSinCos_CODEHEADER_INCLUDED
  67. #undef ffft_OscSinCos_CURRENT_CODEHEADER
  68. /*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/