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.

93 lines
2.2KB

  1. /***************************************************/
  2. /*! \class Sitar
  3. \brief STK sitar string model class.
  4. This class implements a sitar plucked string
  5. physical model based on the Karplus-Strong
  6. algorithm.
  7. This is a digital waveguide model, making its
  8. use possibly subject to patents held by
  9. Stanford University, Yamaha, and others.
  10. There exist at least two patents, assigned to
  11. Stanford, bearing the names of Karplus and/or
  12. Strong.
  13. by Perry R. Cook and Gary P. Scavone, 1995-2011.
  14. */
  15. /***************************************************/
  16. #include "Sitar.h"
  17. namespace stk {
  18. Sitar :: Sitar( StkFloat lowestFrequency )
  19. {
  20. if ( lowestFrequency <= 0.0 ) {
  21. oStream_ << "Sitar::Sitar: argument is less than or equal to zero!";
  22. handleError( StkError::FUNCTION_ARGUMENT );
  23. }
  24. unsigned long length = (unsigned long) ( Stk::sampleRate() / lowestFrequency + 1 );
  25. delayLine_.setMaximumDelay( length );
  26. delay_ = 0.5 * length;
  27. delayLine_.setDelay( delay_ );
  28. targetDelay_ = delay_;
  29. loopFilter_.setZero( 0.01 );
  30. loopGain_ = 0.999;
  31. envelope_.setAllTimes( 0.001, 0.04, 0.0, 0.5 );
  32. this->clear();
  33. }
  34. Sitar :: ~Sitar( void )
  35. {
  36. }
  37. void Sitar :: clear( void )
  38. {
  39. delayLine_.clear();
  40. loopFilter_.clear();
  41. }
  42. void Sitar :: setFrequency( StkFloat frequency )
  43. {
  44. #if defined(_STK_DEBUG_)
  45. if ( frequency <= 0.0 ) {
  46. oStream_ << "Sitar::setFrequency: parameter is less than or equal to zero!";
  47. handleError( StkError::WARNING ); return;
  48. }
  49. #endif
  50. targetDelay_ = (Stk::sampleRate() / frequency);
  51. delay_ = targetDelay_ * (1.0 + (0.05 * noise_.tick()));
  52. delayLine_.setDelay( delay_ );
  53. loopGain_ = 0.995 + (frequency * 0.0000005);
  54. if ( loopGain_ > 0.9995 ) loopGain_ = 0.9995;
  55. }
  56. void Sitar :: pluck( StkFloat amplitude )
  57. {
  58. envelope_.keyOn();
  59. }
  60. void Sitar :: noteOn( StkFloat frequency, StkFloat amplitude )
  61. {
  62. this->setFrequency( frequency );
  63. this->pluck( amplitude );
  64. amGain_ = 0.1 * amplitude;
  65. }
  66. void Sitar :: noteOff( StkFloat amplitude )
  67. {
  68. if ( amplitude < 0.0 || amplitude > 1.0 ) {
  69. oStream_ << "Sitar::noteOff: amplitude is out of range!";
  70. handleError( StkError::WARNING ); return;
  71. }
  72. loopGain_ = (StkFloat) 1.0 - amplitude;
  73. }
  74. } // stk namespace