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.

54 lines
1.3KB

  1. /***************************************************/
  2. /*! \class SingWave
  3. \brief STK "singing" looped soundfile class.
  4. This class loops a specified soundfile and modulates it both
  5. periodically and randomly to produce a pitched musical sound, like
  6. a simple voice or violin. In general, it is not be used alone
  7. because of "munchkinification" effects from pitch shifting.
  8. Within STK, it is used as an excitation source for other
  9. instruments.
  10. by Perry R. Cook and Gary P. Scavone, 1995-2011.
  11. */
  12. /***************************************************/
  13. #include "SingWave.h"
  14. namespace stk {
  15. SingWave :: SingWave( std::string fileName, bool raw )
  16. {
  17. // An exception could be thrown here.
  18. wave_.openFile( fileName, raw );
  19. rate_ = 1.0;
  20. sweepRate_ = 0.001;
  21. modulator_.setVibratoRate( 6.0 );
  22. modulator_.setVibratoGain( 0.04 );
  23. modulator_.setRandomGain( 0.005 );
  24. this->setFrequency( 75.0 );
  25. pitchEnvelope_.setRate( 1.0 );
  26. this->tick();
  27. this->tick();
  28. pitchEnvelope_.setRate( sweepRate_ * rate_ );
  29. }
  30. SingWave :: ~SingWave()
  31. {
  32. }
  33. void SingWave :: setFrequency( StkFloat frequency )
  34. {
  35. StkFloat temp = rate_;
  36. rate_ = wave_.getSize() * frequency / Stk::sampleRate();
  37. temp -= rate_;
  38. if ( temp < 0) temp = -temp;
  39. pitchEnvelope_.setTarget( rate_ );
  40. pitchEnvelope_.setRate( sweepRate_ * temp );
  41. }
  42. } // stk namespace