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.

80 lines
2.0KB

  1. #ifndef STK_EFFECT_H
  2. #define STK_EFFECT_H
  3. #include "Stk.h"
  4. #include <cmath>
  5. namespace stk {
  6. /***************************************************/
  7. /*! \class Effect
  8. \brief STK abstract effects parent class.
  9. This class provides common functionality for STK effects
  10. subclasses. It is general enough to support both monophonic and
  11. polyphonic input/output classes.
  12. by Perry R. Cook and Gary P. Scavone, 1995--2017.
  13. */
  14. /***************************************************/
  15. class Effect : public Stk
  16. {
  17. public:
  18. //! Class constructor.
  19. Effect( void ) { lastFrame_.resize( 1, 1, 0.0 ); };
  20. //! Return the number of output channels for the class.
  21. unsigned int channelsOut( void ) const { return lastFrame_.channels(); };
  22. //! Return an StkFrames reference to the last output sample frame.
  23. const StkFrames& lastFrame( void ) const { return lastFrame_; };
  24. //! Reset and clear all internal state.
  25. virtual void clear() = 0;
  26. //! Set the mixture of input and "effected" levels in the output (0.0 = input only, 1.0 = effect only).
  27. virtual void setEffectMix( StkFloat mix );
  28. protected:
  29. // Returns true if argument value is prime.
  30. bool isPrime( unsigned int number );
  31. StkFrames lastFrame_;
  32. StkFloat effectMix_;
  33. };
  34. inline void Effect :: setEffectMix( StkFloat mix )
  35. {
  36. if ( mix < 0.0 ) {
  37. oStream_ << "Effect::setEffectMix: mix parameter is less than zero ... setting to zero!";
  38. handleError( StkError::WARNING );
  39. effectMix_ = 0.0;
  40. }
  41. else if ( mix > 1.0 ) {
  42. oStream_ << "Effect::setEffectMix: mix parameter is greater than 1.0 ... setting to one!";
  43. handleError( StkError::WARNING );
  44. effectMix_ = 1.0;
  45. }
  46. else
  47. effectMix_ = mix;
  48. }
  49. inline bool Effect :: isPrime( unsigned int number )
  50. {
  51. if ( number == 2 ) return true;
  52. if ( number & 1 ) {
  53. for ( int i=3; i<(int)sqrt((double)number)+1; i+=2 )
  54. if ( (number % i) == 0 ) return false;
  55. return true; // prime
  56. }
  57. else return false; // even
  58. }
  59. } // stk namespace
  60. #endif