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.

74 lines
1.7KB

  1. /***************************************************/
  2. /*! \class PoleZero
  3. \brief STK one-pole, one-zero filter class.
  4. This class implements a one-pole, one-zero digital filter. A
  5. method is provided for creating an allpass filter with a given
  6. coefficient. Another method is provided to create a DC blocking
  7. filter.
  8. by Perry R. Cook and Gary P. Scavone, 1995--2017.
  9. */
  10. /***************************************************/
  11. #include "PoleZero.h"
  12. namespace stk {
  13. PoleZero :: PoleZero()
  14. {
  15. // Default setting for pass-through.
  16. b_.resize( 2, 0.0 );
  17. a_.resize( 2, 0.0 );
  18. b_[0] = 1.0;
  19. a_[0] = 1.0;
  20. inputs_.resize( 2, 1, 0.0 );
  21. outputs_.resize( 2, 1, 0.0 );
  22. }
  23. PoleZero :: ~PoleZero()
  24. {
  25. }
  26. void PoleZero :: setCoefficients( StkFloat b0, StkFloat b1, StkFloat a1, bool clearState )
  27. {
  28. if ( std::abs( a1 ) >= 1.0 ) {
  29. oStream_ << "PoleZero::setCoefficients: a1 argument (" << a1 << ") should be less than 1.0!";
  30. handleError( StkError::WARNING ); return;
  31. }
  32. b_[0] = b0;
  33. b_[1] = b1;
  34. a_[1] = a1;
  35. if ( clearState ) this->clear();
  36. }
  37. void PoleZero :: setAllpass( StkFloat coefficient )
  38. {
  39. if ( std::abs( coefficient ) >= 1.0 ) {
  40. oStream_ << "PoleZero::setAllpass: argument (" << coefficient << ") makes filter unstable!";
  41. handleError( StkError::WARNING ); return;
  42. }
  43. b_[0] = coefficient;
  44. b_[1] = 1.0;
  45. a_[0] = 1.0; // just in case
  46. a_[1] = coefficient;
  47. }
  48. void PoleZero :: setBlockZero( StkFloat thePole )
  49. {
  50. if ( std::abs( thePole ) >= 1.0 ) {
  51. oStream_ << "PoleZero::setBlockZero: argument (" << thePole << ") makes filter unstable!";
  52. handleError( StkError::WARNING ); return;
  53. }
  54. b_[0] = 1.0;
  55. b_[1] = -1.0;
  56. a_[0] = 1.0; // just in case
  57. a_[1] = -thePole;
  58. }
  59. } // stk namespace