/// <summary> /// Time stretching with auto-derived parameters /// </summary> /// <param name="signal">Signal</param> /// <param name="stretch">Stretch factor (ratio)</param> /// <param name="algorithm">Algorithm for TSM (optional)</param> /// <returns>Time stretched signal</returns> public static DiscreteSignal TimeStretch(DiscreteSignal signal, double stretch, TsmAlgorithm algorithm = TsmAlgorithm.PhaseVocoderPhaseLocking) { if (Math.Abs(stretch - 1.0) < 1e-10) { return(signal.Copy()); } IFilter stretchFilter; var frameSize = MathUtils.NextPowerOfTwo(1024 * signal.SamplingRate / 16000); switch (algorithm) { case TsmAlgorithm.PhaseVocoder: stretchFilter = new PhaseVocoder(stretch, frameSize / 10, frameSize); break; case TsmAlgorithm.PhaseVocoderPhaseLocking: stretchFilter = new PhaseLockingVocoder(stretch, frameSize / 8, frameSize); break; case TsmAlgorithm.PaulStetch: stretchFilter = new PaulStretch(stretch, frameSize / 10, frameSize * 4); break; default: stretchFilter = new Wsola(stretch); break; } return(stretchFilter.ApplyTo(signal, FilteringMethod.Auto)); }
/// <summary> /// Time stretching with parameters set by user /// </summary> /// <param name="signal">Signal</param> /// <param name="stretch">Stretch factor (ratio)</param> /// <param name="windowSize">Window size (for vocoders - FFT size)</param> /// <param name="hopSize">Hop size</param> /// <param name="algorithm">Algorithm for TSM (optional)</param> /// <returns>Time stretched signal</returns> public static DiscreteSignal TimeStretch(DiscreteSignal signal, double stretch, int windowSize, int hopSize, TsmAlgorithm algorithm = TsmAlgorithm.PhaseVocoderPhaseLocking) { if (Math.Abs(stretch - 1.0) < 1e-10) { return(signal.Copy()); } IFilter stretchFilter; switch (algorithm) { case TsmAlgorithm.PhaseVocoder: stretchFilter = new PhaseVocoder(stretch, hopSize, windowSize); break; case TsmAlgorithm.PhaseVocoderPhaseLocking: stretchFilter = new PhaseLockingVocoder(stretch, hopSize, windowSize); break; case TsmAlgorithm.PaulStetch: stretchFilter = new PaulStretch(stretch, hopSize, windowSize); break; default: stretchFilter = new Wsola(stretch, windowSize, hopSize); break; } return(stretchFilter.ApplyTo(signal, FilteringMethod.Auto)); }
/// <summary> /// Time stretching /// </summary> /// <param name="signal">Signal</param> /// <param name="stretch">Stretch factor (scale)</param> /// <param name="fftSize">Size of FFT</param> /// <param name="hopSize">Hop size</param> /// <param name="algorithm">Algorithm for TSM</param> /// <returns></returns> public static DiscreteSignal TimeStretch(DiscreteSignal signal, double stretch, int fftSize = 1024, int hopSize = -1, TsmAlgorithm algorithm = TsmAlgorithm.Wsola) { if (Math.Abs(stretch - 1.0) < 1e-10) { return(signal.Copy()); } var hopAnalysis = hopSize > 0 ? hopSize : fftSize / 4; IFilter stretchFilter; switch (algorithm) { case TsmAlgorithm.PhaseVocoder: stretchFilter = new PhaseVocoder(stretch, hopAnalysis, fftSize); break; default: stretchFilter = new Wsola(stretch, fftSize); break; } return(stretchFilter.ApplyTo(signal, FilteringOptions.Auto)); }
/// <summary> /// Constructor /// </summary> /// <param name="shift"></param> /// <param name="fftSize"></param> /// <param name="tsm"></param> public PitchShiftEffect(double shift, int fftSize = 1024, int hopSize = 128, TsmAlgorithm tsm = TsmAlgorithm.PhaseVocoderPhaseLocking) { _shift = shift; _fftSize = fftSize; _hopSize = hopSize; _tsm = tsm; }
/// <summary> /// Constructs <see cref="PitchShiftEffect"/>. /// </summary> /// <param name="shift">Pitch shift ratio</param> /// <param name="windowSize">Window size (frame length)</param> /// <param name="hopSize">Hop length</param> /// <param name="tsm">Time-scale modification algorithm</param> public PitchShiftEffect(double shift, int windowSize = 1024, int hopSize = 128, TsmAlgorithm tsm = TsmAlgorithm.PhaseVocoderPhaseLocking) { Shift = shift; WindowSize = windowSize; HopSize = hopSize; Tsm = tsm; }
/// <summary> /// Constructor /// </summary> /// <param name="shift"></param> /// <param name="fftSize"></param> /// <param name="tsm"></param> public PitchShiftEffect(double shift, int fftSize = 4096, TsmAlgorithm tsm = TsmAlgorithm.Wsola) { _shift = shift; _fftSize = fftSize; _tsm = tsm; }