Audio plugin host https://kx.studio/carla
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.

Envelope.cpp 1.7KB

11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /***************************************************/
  2. /*! \class Envelope
  3. \brief STK linear line envelope class.
  4. This class implements a simple linear line envelope generator
  5. which is capable of ramping to an arbitrary target value by a
  6. specified \e rate. It also responds to simple \e keyOn and \e
  7. keyOff messages, ramping to 1.0 on keyOn and to 0.0 on keyOff.
  8. by Perry R. Cook and Gary P. Scavone, 1995-2011.
  9. */
  10. /***************************************************/
  11. #include "Envelope.h"
  12. namespace stk {
  13. Envelope :: Envelope( void ) : Generator()
  14. {
  15. target_ = 0.0;
  16. value_ = 0.0;
  17. rate_ = 0.001;
  18. state_ = 0;
  19. Stk::addSampleRateAlert( this );
  20. }
  21. Envelope :: ~Envelope( void )
  22. {
  23. Stk::removeSampleRateAlert( this );
  24. }
  25. Envelope& Envelope :: operator= ( const Envelope& e )
  26. {
  27. if ( this != &e ) {
  28. target_ = e.target_;
  29. value_ = e.value_;
  30. rate_ = e.rate_;
  31. state_ = e.state_;
  32. }
  33. return *this;
  34. }
  35. void Envelope :: sampleRateChanged( StkFloat newRate, StkFloat oldRate )
  36. {
  37. if ( !ignoreSampleRateChange_ )
  38. rate_ = oldRate * rate_ / newRate;
  39. }
  40. void Envelope :: setRate( StkFloat rate )
  41. {
  42. if ( rate < 0.0 ) {
  43. oStream_ << "Envelope::setRate: argument must be >= 0.0!";
  44. handleError( StkError::WARNING ); return;
  45. }
  46. rate_ = rate;
  47. }
  48. void Envelope :: setTime( StkFloat time )
  49. {
  50. if ( time <= 0.0 ) {
  51. oStream_ << "Envelope::setTime: argument must be > 0.0!";
  52. handleError( StkError::WARNING ); return;
  53. }
  54. rate_ = 1.0 / ( time * Stk::sampleRate() );
  55. }
  56. void Envelope :: setTarget( StkFloat target )
  57. {
  58. target_ = target;
  59. if ( value_ != target_ ) state_ = 1;
  60. }
  61. void Envelope :: setValue( StkFloat value )
  62. {
  63. state_ = 0;
  64. target_ = value;
  65. value_ = value;
  66. lastFrame_[0] = value_;
  67. }
  68. } // stk namespace