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.

86 lines
2.3KB

  1. /***************************************************/
  2. /*! \class PercFlut
  3. \brief STK percussive flute FM synthesis instrument.
  4. This class implements algorithm 4 of the TX81Z.
  5. \code
  6. Algorithm 4 is : 4->3--\
  7. 2-- + -->1-->Out
  8. \endcode
  9. Control Change Numbers:
  10. - Total Modulator Index = 2
  11. - Modulator Crossfade = 4
  12. - LFO Speed = 11
  13. - LFO Depth = 1
  14. - ADSR 2 & 4 Target = 128
  15. The basic Chowning/Stanford FM patent expired
  16. in 1995, but there exist follow-on patents,
  17. mostly assigned to Yamaha. If you are of the
  18. type who should worry about this (making
  19. money) worry away.
  20. by Perry R. Cook and Gary P. Scavone, 1995--2017.
  21. */
  22. /***************************************************/
  23. #include "PercFlut.h"
  24. namespace stk {
  25. PercFlut :: PercFlut( void )
  26. : FM()
  27. {
  28. // Concatenate the STK rawwave path to the rawwave files
  29. for ( unsigned int i=0; i<3; i++ )
  30. waves_[i] = new FileLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), true );
  31. waves_[3] = new FileLoop( (Stk::rawwavePath() + "fwavblnk.raw").c_str(), true );
  32. this->setRatio(0, 1.50 * 1.000);
  33. this->setRatio(1, 3.00 * 0.995);
  34. this->setRatio(2, 2.99 * 1.005);
  35. this->setRatio(3, 6.00 * 0.997);
  36. gains_[0] = fmGains_[99];
  37. gains_[1] = fmGains_[71];
  38. gains_[2] = fmGains_[93];
  39. gains_[3] = fmGains_[85];
  40. adsr_[0]->setAllTimes( 0.05, 0.05, fmSusLevels_[14], 0.05);
  41. adsr_[1]->setAllTimes( 0.02, 0.50, fmSusLevels_[13], 0.5);
  42. adsr_[2]->setAllTimes( 0.02, 0.30, fmSusLevels_[11], 0.05);
  43. adsr_[3]->setAllTimes( 0.02, 0.05, fmSusLevels_[13], 0.01);
  44. twozero_.setGain( 0.0 );
  45. modDepth_ = 0.005;
  46. }
  47. PercFlut :: ~PercFlut( void )
  48. {
  49. }
  50. void PercFlut :: setFrequency( StkFloat frequency )
  51. {
  52. #if defined(_STK_DEBUG_)
  53. if ( frequency <= 0.0 ) {
  54. oStream_ << "PercFlut::setFrequency: argument is less than or equal to zero!";
  55. handleError( StkError::WARNING ); return;
  56. }
  57. #endif
  58. baseFrequency_ = frequency;
  59. }
  60. void PercFlut :: noteOn( StkFloat frequency, StkFloat amplitude )
  61. {
  62. gains_[0] = amplitude * fmGains_[99] * 0.5;
  63. gains_[1] = amplitude * fmGains_[71] * 0.5;
  64. gains_[2] = amplitude * fmGains_[93] * 0.5;
  65. gains_[3] = amplitude * fmGains_[85] * 0.5;
  66. this->setFrequency( frequency );
  67. this->keyOn();
  68. }
  69. } // stk namespace