OscSinCos.hpp (2430B)
1 /***************************************************************************** 2 3 OscSinCos.hpp 4 By Laurent de Soras 5 6 --- Legal stuff --- 7 8 This program is free software. It comes without any warranty, to 9 the extent permitted by applicable law. You can redistribute it 10 and/or modify it under the terms of the Do What The Fuck You Want 11 To Public License, Version 2, as published by Sam Hocevar. See 12 http://sam.zoy.org/wtfpl/COPYING for more details. 13 14 *Tab=3***********************************************************************/ 15 16 17 18 #if defined (ffft_OscSinCos_CURRENT_CODEHEADER) 19 #error Recursive inclusion of OscSinCos code header. 20 #endif 21 #define ffft_OscSinCos_CURRENT_CODEHEADER 22 23 #if ! defined (ffft_OscSinCos_CODEHEADER_INCLUDED) 24 #define ffft_OscSinCos_CODEHEADER_INCLUDED 25 26 27 28 /*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ 29 30 #include <cmath> 31 32 namespace std { } 33 34 35 36 namespace ffft 37 { 38 39 40 41 /*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ 42 43 44 45 template <class T> 46 OscSinCos <T>::OscSinCos () 47 : _pos_cos (1) 48 , _pos_sin (0) 49 , _step_cos (1) 50 , _step_sin (0) 51 { 52 // Nothing 53 } 54 55 56 57 template <class T> 58 void OscSinCos <T>::set_step (double angle_rad) 59 { 60 using namespace std; 61 62 _step_cos = static_cast <DataType> (cos (angle_rad)); 63 _step_sin = static_cast <DataType> (sin (angle_rad)); 64 } 65 66 67 68 template <class T> 69 typename OscSinCos <T>::DataType OscSinCos <T>::get_cos () const 70 { 71 return (_pos_cos); 72 } 73 74 75 76 template <class T> 77 typename OscSinCos <T>::DataType OscSinCos <T>::get_sin () const 78 { 79 return (_pos_sin); 80 } 81 82 83 84 template <class T> 85 void OscSinCos <T>::step () 86 { 87 const DataType old_cos = _pos_cos; 88 const DataType old_sin = _pos_sin; 89 90 _pos_cos = old_cos * _step_cos - old_sin * _step_sin; 91 _pos_sin = old_cos * _step_sin + old_sin * _step_cos; 92 } 93 94 95 96 template <class T> 97 void OscSinCos <T>::clear_buffers () 98 { 99 _pos_cos = static_cast <DataType> (1); 100 _pos_sin = static_cast <DataType> (0); 101 } 102 103 104 105 /*\\\ PROTECTED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ 106 107 108 109 /*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ 110 111 112 113 } // namespace ffft 114 115 116 117 #endif // ffft_OscSinCos_CODEHEADER_INCLUDED 118 119 #undef ffft_OscSinCos_CURRENT_CODEHEADER 120 121 122 123 /*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/