You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4KB

  1. /***************************************************/
  2. /*! \class OnePole
  3. \brief STK one-pole filter class.
  4. This class implements a one-pole digital filter. A method is
  5. provided for setting the pole position along the real axis of the
  6. z-plane while maintaining a constant peak filter gain.
  7. by Perry R. Cook and Gary P. Scavone, 1995--2017.
  8. */
  9. /***************************************************/
  10. #include "OnePole.h"
  11. namespace stk {
  12. OnePole :: OnePole( StkFloat thePole )
  13. {
  14. b_.resize( 1 );
  15. a_.resize( 2 );
  16. a_[0] = 1.0;
  17. inputs_.resize( 1, 1, 0.0 );
  18. outputs_.resize( 2, 1, 0.0 );
  19. this->setPole( thePole );
  20. }
  21. OnePole :: ~OnePole()
  22. {
  23. }
  24. void OnePole :: setPole( StkFloat thePole )
  25. {
  26. if ( std::abs( thePole ) >= 1.0 ) {
  27. oStream_ << "OnePole::setPole: argument (" << thePole << ") should be less than 1.0!";
  28. handleError( StkError::WARNING ); return;
  29. }
  30. // Normalize coefficients for peak unity gain.
  31. if ( thePole > 0.0 )
  32. b_[0] = (StkFloat) (1.0 - thePole);
  33. else
  34. b_[0] = (StkFloat) (1.0 + thePole);
  35. a_[1] = -thePole;
  36. }
  37. void OnePole :: setCoefficients( StkFloat b0, StkFloat a1, bool clearState )
  38. {
  39. if ( std::abs( a1 ) >= 1.0 ) {
  40. oStream_ << "OnePole::setCoefficients: a1 argument (" << a1 << ") should be less than 1.0!";
  41. handleError( StkError::WARNING ); return;
  42. }
  43. b_[0] = b0;
  44. a_[1] = a1;
  45. if ( clearState ) this->clear();
  46. }
  47. } // stk namespace