Skip to content

Commit

Permalink
Support asymmetric windows #38
Browse files Browse the repository at this point in the history
  • Loading branch information
jurihock committed Nov 15, 2023
1 parent a026fb9 commit f9f65df
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 14 deletions.
46 changes: 40 additions & 6 deletions cpp/StftPitchShift/StftPitchShift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,29 @@ StftPitchShift::StftPitchShift(
const double samplerate,
const bool normalization,
const bool chronometry) :
fft(std::make_shared<RFFT>()),
framesize(framesize),
hopsize(hopsize),
samplerate(samplerate),
normalization(normalization),
chronometry(chronometry)
StftPitchShift(
std::make_shared<RFFT>(),
std::make_tuple(framesize, framesize),
hopsize,
samplerate,
normalization,
chronometry)
{
}

StftPitchShift::StftPitchShift(
const std::tuple<size_t, size_t> framesize,
const size_t hopsize,
const double samplerate,
const bool normalization,
const bool chronometry) :
StftPitchShift(
std::make_shared<RFFT>(),
framesize,
hopsize,
samplerate,
normalization,
chronometry)
{
}

Expand All @@ -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> fft,
const std::tuple<size_t, size_t> framesize,
const size_t hopsize,
const double samplerate,
const bool normalization,
const bool chronometry) :
fft(fft),
framesize(framesize),
hopsize(hopsize),
Expand Down
37 changes: 34 additions & 3 deletions cpp/StftPitchShift/StftPitchShift.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <memory>
#include <tuple>
#include <vector>

#include <StftPitchShift/FFT.h>
Expand All @@ -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.
Expand All @@ -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<size_t, size_t> 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.
Expand All @@ -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> fft,
const std::tuple<size_t, size_t> 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.
Expand Down Expand Up @@ -168,7 +199,7 @@ namespace stftpitchshift
private:

const std::shared_ptr<FFT> fft;
const size_t framesize;
const std::tuple<size_t, size_t> framesize;
const size_t hopsize;
const double samplerate;
const bool normalization;
Expand Down
33 changes: 29 additions & 4 deletions cpp/StftPitchShift/StftPitchShiftCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ namespace stftpitchshift
const size_t framesize,
const size_t hopsize,
const double samplerate) :
StftPitchShiftCore(
std::make_shared<RFFT>(),
std::make_tuple(framesize, framesize),
hopsize,
samplerate)
{
}

StftPitchShiftCore(
const std::tuple<size_t, size_t> framesize,
const size_t hopsize,
const double samplerate) :
StftPitchShiftCore(
std::make_shared<RFFT>(),
framesize,
Expand All @@ -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> fft,
const std::tuple<size_t, size_t> 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)
{
}

Expand Down Expand Up @@ -147,7 +172,7 @@ namespace stftpitchshift
private:

const std::shared_ptr<FFT> fft;
const size_t framesize;
const std::tuple<size_t, size_t> framesize;
const size_t hopsize;
const double samplerate;

Expand Down
1 change: 0 additions & 1 deletion python/stftpitchshift/stftpitchshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f9f65df

Please sign in to comment.