QuadratureLfo.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * quadraturelfo.h - defination of QuadratureLfo class.
  3. *
  4. * Copyright (c) 2014 David French <dave/dot/french3/at/googlemail/dot/com>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef QUADRATURELFO_H
  25. #define QUADRATURELFO_H
  26. #include "lmms_math.h"
  27. class QuadratureLfo
  28. {
  29. public:
  30. QuadratureLfo( int sampleRate );
  31. ~QuadratureLfo()
  32. {
  33. }
  34. inline void setFrequency( double frequency )
  35. {
  36. if( frequency < 0 || frequency > ( m_samplerate / 2.0 ) || frequency == m_frequency )
  37. {
  38. return;
  39. }
  40. m_frequency = frequency;
  41. m_increment = m_frequency * m_twoPiOverSr;
  42. if( m_phase >= F_2PI )
  43. {
  44. m_phase -= F_2PI;
  45. }
  46. }
  47. inline void restart()
  48. {
  49. m_phase = 0;
  50. }
  51. inline void setSampleRate ( int samplerate )
  52. {
  53. m_samplerate = samplerate;
  54. m_twoPiOverSr = F_2PI / samplerate;
  55. m_increment = m_frequency * m_twoPiOverSr;
  56. }
  57. void tick( float *s, float *c );
  58. private:
  59. double m_frequency;
  60. double m_phase;
  61. double m_increment;
  62. double m_twoPiOverSr;
  63. int m_samplerate;
  64. };
  65. #endif // QUADRATURELFO_H