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.

89 lines
2.2KB

  1. /***************************************************/
  2. /*! \class PitShift
  3. \brief STK simple pitch shifter effect class.
  4. This class implements a simple pitch shifter
  5. using delay lines.
  6. by Perry R. Cook and Gary P. Scavone, 1995-2011.
  7. */
  8. /***************************************************/
  9. #include "PitShift.h"
  10. #include <cmath>
  11. namespace stk {
  12. PitShift :: PitShift( void )
  13. {
  14. delayLength_ = maxDelay - 24;
  15. halfLength_ = delayLength_ / 2;
  16. delay_[0] = 12;
  17. delay_[1] = maxDelay / 2;
  18. delayLine_[0].setMaximumDelay( maxDelay );
  19. delayLine_[0].setDelay( delay_[0] );
  20. delayLine_[1].setMaximumDelay( maxDelay );
  21. delayLine_[1].setDelay( delay_[1] );
  22. effectMix_ = 0.5;
  23. rate_ = 1.0;
  24. }
  25. void PitShift :: clear()
  26. {
  27. delayLine_[0].clear();
  28. delayLine_[1].clear();
  29. lastFrame_[0] = 0.0;
  30. }
  31. void PitShift :: setShift( StkFloat shift )
  32. {
  33. if ( shift < 1.0 ) {
  34. rate_ = 1.0 - shift;
  35. }
  36. else if ( shift > 1.0 ) {
  37. rate_ = 1.0 - shift;
  38. }
  39. else {
  40. rate_ = 0.0;
  41. delay_[0] = halfLength_ + 12;
  42. }
  43. }
  44. StkFrames& PitShift :: tick( StkFrames& frames, unsigned int channel )
  45. {
  46. #if defined(_STK_DEBUG_)
  47. if ( channel >= frames.channels() ) {
  48. oStream_ << "PitShift::tick(): channel and StkFrames arguments are incompatible!";
  49. handleError( StkError::FUNCTION_ARGUMENT );
  50. }
  51. #endif
  52. StkFloat *samples = &frames[channel];
  53. unsigned int hop = frames.channels();
  54. for ( unsigned int i=0; i<frames.frames(); i++, samples += hop )
  55. *samples = tick( *samples );
  56. return frames;
  57. }
  58. StkFrames& PitShift :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
  59. {
  60. #if defined(_STK_DEBUG_)
  61. if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() ) {
  62. oStream_ << "PitShift::tick(): channel and StkFrames arguments are incompatible!";
  63. handleError( StkError::FUNCTION_ARGUMENT );
  64. }
  65. #endif
  66. StkFloat *iSamples = &iFrames[iChannel];
  67. StkFloat *oSamples = &oFrames[oChannel];
  68. unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
  69. for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop )
  70. *oSamples = tick( *iSamples );
  71. return iFrames;
  72. }
  73. } // stk namespace