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.

53 lines
1.9KB

  1. /***************************************************/
  2. /*! \class LentPitShift
  3. \brief Pitch shifter effect class based on the Lent algorithm.
  4. This class implements a pitch shifter using pitch
  5. tracking and sample windowing and shifting.
  6. by Francois Germain, 2009.
  7. */
  8. /***************************************************/
  9. #include "LentPitShift.h"
  10. namespace stk {
  11. LentPitShift::LentPitShift( StkFloat periodRatio, int tMax )
  12. : inputFrames(0.,tMax,1), outputFrames(0.,tMax,1), ptrFrames(0), inputPtr(0), outputPtr(0.), tMax_(tMax), periodRatio_(periodRatio), zeroFrame(0., tMax, 1)
  13. {
  14. window = new StkFloat[2*tMax_]; // Allocation of the array for the hamming window
  15. threshold_ = 0.1; // Default threshold for pitch tracking
  16. dt = new StkFloat[tMax+1]; // Allocation of the euclidian distance coefficient array. The first one is never used.
  17. cumDt = new StkFloat[tMax+1]; // Allocation of the cumulative sum array
  18. cumDt[0] = 0.; // Initialization of the first coefficient of the cumulative sum
  19. dpt = new StkFloat[tMax+1]; // Allocation of the pitch tracking function coefficient array
  20. dpt[0] = 1.; // Initialization of the first coefficient of dpt which is always the same
  21. // Initialisation of the input and output delay lines
  22. inputLine_.setMaximumDelay( 3 * tMax_ );
  23. // The delay is choosed such as the coefficients are not read before being finalised.
  24. outputLine_.setMaximumDelay( 3 * tMax_ );
  25. outputLine_.setDelay( 3 * tMax_ );
  26. //Initialization of the delay line of pitch tracking coefficients
  27. //coeffLine_ = new Delay[512];
  28. //for(int i=0;i<tMax_;i++)
  29. // coeffLine_[i] = new Delay( tMax_, tMax_ );
  30. }
  31. void LentPitShift :: clear()
  32. {
  33. inputLine_.clear();
  34. outputLine_.clear();
  35. }
  36. void LentPitShift :: setShift( StkFloat shift )
  37. {
  38. if ( shift <= 0.0 ) periodRatio_ = 1.0;
  39. periodRatio_ = 1.0 / shift;
  40. }
  41. } // stk namespace