diff --git a/cpp/StftPitchShift/StftPitchShift.cpp b/cpp/StftPitchShift/StftPitchShift.cpp index 212e2b3..08a9a6e 100644 --- a/cpp/StftPitchShift/StftPitchShift.cpp +++ b/cpp/StftPitchShift/StftPitchShift.cpp @@ -14,12 +14,29 @@ StftPitchShift::StftPitchShift( const double samplerate, const bool normalization, const bool chronometry) : - fft(std::make_shared()), - framesize(framesize), - hopsize(hopsize), - samplerate(samplerate), - normalization(normalization), - chronometry(chronometry) + StftPitchShift( + std::make_shared(), + std::make_tuple(framesize, framesize), + hopsize, + samplerate, + normalization, + chronometry) +{ +} + +StftPitchShift::StftPitchShift( + const std::tuple framesize, + const size_t hopsize, + const double samplerate, + const bool normalization, + const bool chronometry) : + StftPitchShift( + std::make_shared(), + framesize, + hopsize, + samplerate, + normalization, + chronometry) { } @@ -30,6 +47,23 @@ StftPitchShift::StftPitchShift( const double samplerate, const bool normalization, const bool chronometry) : + StftPitchShift( + fft, + std::make_tuple(framesize, framesize), + hopsize, + samplerate, + normalization, + chronometry) +{ +} + +StftPitchShift::StftPitchShift( + const std::shared_ptr fft, + const std::tuple framesize, + const size_t hopsize, + const double samplerate, + const bool normalization, + const bool chronometry) : fft(fft), framesize(framesize), hopsize(hopsize), diff --git a/cpp/StftPitchShift/StftPitchShift.h b/cpp/StftPitchShift/StftPitchShift.h index 3a0c4a4..5ad51da 100644 --- a/cpp/StftPitchShift/StftPitchShift.h +++ b/cpp/StftPitchShift/StftPitchShift.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -16,7 +17,7 @@ namespace stftpitchshift public: /** - * @param framesize The STFT frame size in samples. + * @param framesize The STFT frame size in samples (analysis = synthesis). * @param hopsize The STFT hop size in samples. * @param samplerate The sample rate of the signal in hertz. * @param normalization Optionally enable spectral rms normalization. @@ -29,9 +30,23 @@ namespace stftpitchshift const bool normalization = false, const bool chronometry = false); + /** + * @param framesize The STFT frame size in samples (analysis >= synthesis). + * @param hopsize The STFT hop size in samples. + * @param samplerate The sample rate of the signal in hertz. + * @param normalization Optionally enable spectral rms normalization. + * @param chronometry Optionally enable runtime measurements. + */ + StftPitchShift( + const std::tuple framesize, + const size_t hopsize, + const double samplerate, + const bool normalization = false, + const bool chronometry = false); + /** * @param fft The custom FFT calculation instance. - * @param framesize The STFT frame size in samples. + * @param framesize The STFT frame size in samples (analysis = synthesis). * @param hopsize The STFT hop size in samples. * @param samplerate The sample rate of the signal in hertz. * @param normalization Optionally enable spectral rms normalization. @@ -45,6 +60,22 @@ namespace stftpitchshift const bool normalization = false, const bool chronometry = false); + /** + * @param fft The custom FFT calculation instance. + * @param framesize The STFT frame size in samples (analysis >= synthesis). + * @param hopsize The STFT hop size in samples. + * @param samplerate The sample rate of the signal in hertz. + * @param normalization Optionally enable spectral rms normalization. + * @param chronometry Optionally enable runtime measurements. + */ + StftPitchShift( + const std::shared_ptr fft, + const std::tuple framesize, + const size_t hopsize, + const double samplerate, + const bool normalization = false, + const bool chronometry = false); + /** * @param input The input signal. * @param output The output signal of the equal size. @@ -168,7 +199,7 @@ namespace stftpitchshift private: const std::shared_ptr fft; - const size_t framesize; + const std::tuple framesize; const size_t hopsize; const double samplerate; const bool normalization; diff --git a/cpp/StftPitchShift/StftPitchShiftCore.h b/cpp/StftPitchShift/StftPitchShiftCore.h index b5e3db3..8f3eae1 100644 --- a/cpp/StftPitchShift/StftPitchShiftCore.h +++ b/cpp/StftPitchShift/StftPitchShiftCore.h @@ -21,6 +21,18 @@ namespace stftpitchshift const size_t framesize, const size_t hopsize, const double samplerate) : + StftPitchShiftCore( + std::make_shared(), + std::make_tuple(framesize, framesize), + hopsize, + samplerate) + { + } + + StftPitchShiftCore( + const std::tuple framesize, + const size_t hopsize, + const double samplerate) : StftPitchShiftCore( std::make_shared(), framesize, @@ -34,14 +46,27 @@ namespace stftpitchshift const size_t framesize, const size_t hopsize, const double samplerate) : + StftPitchShiftCore( + fft, + std::make_tuple(framesize, framesize), + hopsize, + samplerate) + { + } + + StftPitchShiftCore( + const std::shared_ptr fft, + const std::tuple framesize, + const size_t hopsize, + const double samplerate) : fft(fft), framesize(framesize), hopsize(hopsize), samplerate(samplerate), vocoder(framesize, hopsize, samplerate), - pitcher(framesize, samplerate), - cepster(fft, framesize, samplerate), - envelope(framesize / 2 + 1) + pitcher(std::get<0>(framesize), samplerate), + cepster(fft, std::get<0>(framesize), samplerate), + envelope(std::get<0>(framesize) / 2 + 1) { } @@ -147,7 +172,7 @@ namespace stftpitchshift private: const std::shared_ptr fft; - const size_t framesize; + const std::tuple framesize; const size_t hopsize; const double samplerate; diff --git a/python/stftpitchshift/stftpitchshift.py b/python/stftpitchshift/stftpitchshift.py index ca04e14..572a50d 100644 --- a/python/stftpitchshift/stftpitchshift.py +++ b/python/stftpitchshift/stftpitchshift.py @@ -113,7 +113,6 @@ def isnotnormal(x): frames = normalize(frames, frames0) frames = decode(frames, framesize, hopsize, samplerate) - output = istft(frames, framesize, hopsize) # disable reference count check on resize,