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.

89 lines
2.1KB

  1. /***************************************************/
  2. /*! \class Drone
  3. \brief STK "drone" plucked string model.
  4. This class implements a simple 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--2017.
  14. */
  15. /***************************************************/
  16. #include "Drone.h"
  17. #include <sstream>
  18. namespace stk {
  19. Drone :: Drone( StkFloat lowestFrequency )
  20. {
  21. if ( lowestFrequency <= 0.0 ) {
  22. oStream_ << "Drone::Drone: argument is less than or equal to zero!";
  23. handleError( StkError::FUNCTION_ARGUMENT );
  24. }
  25. unsigned long delays = (unsigned long) ( Stk::sampleRate() / lowestFrequency );
  26. delayLine_.setMaximumDelay( delays + 1 );
  27. this->setFrequency( 220.0 );
  28. envelope_.setAllTimes( 2.0, 0.5, 0.0, 0.5 );
  29. this->clear();
  30. }
  31. Drone :: ~Drone( void )
  32. {
  33. }
  34. void Drone :: clear( void )
  35. {
  36. delayLine_.clear();
  37. loopFilter_.clear();
  38. }
  39. void Drone :: setFrequency( StkFloat frequency )
  40. {
  41. #if defined(_STK_DEBUG_)
  42. if ( frequency <= 0.0 ) {
  43. oStream_ << "Drone::setFrequency: argument is less than or equal to zero!";
  44. handleError( StkError::WARNING ); return;
  45. }
  46. #endif
  47. // Delay = length - approximate filter delay.
  48. StkFloat delay = (Stk::sampleRate() / frequency) - 0.5;
  49. delayLine_.setDelay( delay );
  50. loopGain_ = 0.997 + (frequency * 0.000002);
  51. if ( loopGain_ >= 1.0 ) loopGain_ = 0.99999;
  52. }
  53. void Drone :: pluck( StkFloat amplitude )
  54. {
  55. envelope_.keyOn();
  56. }
  57. void Drone :: noteOn( StkFloat frequency, StkFloat amplitude )
  58. {
  59. this->setFrequency( frequency );
  60. this->pluck( amplitude );
  61. }
  62. void Drone :: noteOff( StkFloat amplitude )
  63. {
  64. if ( amplitude < 0.0 || amplitude > 1.0 ) {
  65. oStream_ << "Plucked::noteOff: amplitude is out of range!";
  66. handleError( StkError::WARNING ); return;
  67. }
  68. loopGain_ = 1.0 - amplitude;
  69. }
  70. } // stk namespace