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.

50 lines
1.1KB

  1. /***************************************************/
  2. /*! \class Modulate
  3. \brief STK periodic/random modulator.
  4. This class combines random and periodic
  5. modulations to give a nice, natural human
  6. modulation function.
  7. by Perry R. Cook and Gary P. Scavone, 1995--2017.
  8. */
  9. /***************************************************/
  10. #include "Modulate.h"
  11. namespace stk {
  12. Modulate :: Modulate( void )
  13. {
  14. vibrato_.setFrequency( 6.0 );
  15. vibratoGain_ = 0.04;
  16. noiseRate_ = (unsigned int) ( 330.0 * Stk::sampleRate() / 22050.0 );
  17. noiseCounter_ = noiseRate_;
  18. randomGain_ = 0.05;
  19. filter_.setPole( 0.999 );
  20. filter_.setGain( randomGain_ );
  21. Stk::addSampleRateAlert( this );
  22. }
  23. Modulate :: ~Modulate( void )
  24. {
  25. Stk::removeSampleRateAlert( this );
  26. }
  27. void Modulate :: sampleRateChanged( StkFloat newRate, StkFloat oldRate )
  28. {
  29. if ( !ignoreSampleRateChange_ )
  30. noiseRate_ = (unsigned int ) ( newRate * noiseRate_ / oldRate );
  31. }
  32. void Modulate :: setRandomGain( StkFloat gain )
  33. {
  34. randomGain_ = gain;
  35. filter_.setGain( randomGain_ );
  36. }
  37. } // stk namespace