Skip to content

Commit f9f65df

Browse files
committed
Support asymmetric windows #38
1 parent a026fb9 commit f9f65df

File tree

4 files changed

+103
-14
lines changed

4 files changed

+103
-14
lines changed

cpp/StftPitchShift/StftPitchShift.cpp

+40-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,29 @@ StftPitchShift::StftPitchShift(
1414
const double samplerate,
1515
const bool normalization,
1616
const bool chronometry) :
17-
fft(std::make_shared<RFFT>()),
18-
framesize(framesize),
19-
hopsize(hopsize),
20-
samplerate(samplerate),
21-
normalization(normalization),
22-
chronometry(chronometry)
17+
StftPitchShift(
18+
std::make_shared<RFFT>(),
19+
std::make_tuple(framesize, framesize),
20+
hopsize,
21+
samplerate,
22+
normalization,
23+
chronometry)
24+
{
25+
}
26+
27+
StftPitchShift::StftPitchShift(
28+
const std::tuple<size_t, size_t> framesize,
29+
const size_t hopsize,
30+
const double samplerate,
31+
const bool normalization,
32+
const bool chronometry) :
33+
StftPitchShift(
34+
std::make_shared<RFFT>(),
35+
framesize,
36+
hopsize,
37+
samplerate,
38+
normalization,
39+
chronometry)
2340
{
2441
}
2542

@@ -30,6 +47,23 @@ StftPitchShift::StftPitchShift(
3047
const double samplerate,
3148
const bool normalization,
3249
const bool chronometry) :
50+
StftPitchShift(
51+
fft,
52+
std::make_tuple(framesize, framesize),
53+
hopsize,
54+
samplerate,
55+
normalization,
56+
chronometry)
57+
{
58+
}
59+
60+
StftPitchShift::StftPitchShift(
61+
const std::shared_ptr<FFT> fft,
62+
const std::tuple<size_t, size_t> framesize,
63+
const size_t hopsize,
64+
const double samplerate,
65+
const bool normalization,
66+
const bool chronometry) :
3367
fft(fft),
3468
framesize(framesize),
3569
hopsize(hopsize),

cpp/StftPitchShift/StftPitchShift.h

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <memory>
4+
#include <tuple>
45
#include <vector>
56

67
#include <StftPitchShift/FFT.h>
@@ -16,7 +17,7 @@ namespace stftpitchshift
1617
public:
1718

1819
/**
19-
* @param framesize The STFT frame size in samples.
20+
* @param framesize The STFT frame size in samples (analysis = synthesis).
2021
* @param hopsize The STFT hop size in samples.
2122
* @param samplerate The sample rate of the signal in hertz.
2223
* @param normalization Optionally enable spectral rms normalization.
@@ -29,9 +30,23 @@ namespace stftpitchshift
2930
const bool normalization = false,
3031
const bool chronometry = false);
3132

33+
/**
34+
* @param framesize The STFT frame size in samples (analysis >= synthesis).
35+
* @param hopsize The STFT hop size in samples.
36+
* @param samplerate The sample rate of the signal in hertz.
37+
* @param normalization Optionally enable spectral rms normalization.
38+
* @param chronometry Optionally enable runtime measurements.
39+
*/
40+
StftPitchShift(
41+
const std::tuple<size_t, size_t> framesize,
42+
const size_t hopsize,
43+
const double samplerate,
44+
const bool normalization = false,
45+
const bool chronometry = false);
46+
3247
/**
3348
* @param fft The custom FFT calculation instance.
34-
* @param framesize The STFT frame size in samples.
49+
* @param framesize The STFT frame size in samples (analysis = synthesis).
3550
* @param hopsize The STFT hop size in samples.
3651
* @param samplerate The sample rate of the signal in hertz.
3752
* @param normalization Optionally enable spectral rms normalization.
@@ -45,6 +60,22 @@ namespace stftpitchshift
4560
const bool normalization = false,
4661
const bool chronometry = false);
4762

63+
/**
64+
* @param fft The custom FFT calculation instance.
65+
* @param framesize The STFT frame size in samples (analysis >= synthesis).
66+
* @param hopsize The STFT hop size in samples.
67+
* @param samplerate The sample rate of the signal in hertz.
68+
* @param normalization Optionally enable spectral rms normalization.
69+
* @param chronometry Optionally enable runtime measurements.
70+
*/
71+
StftPitchShift(
72+
const std::shared_ptr<FFT> fft,
73+
const std::tuple<size_t, size_t> framesize,
74+
const size_t hopsize,
75+
const double samplerate,
76+
const bool normalization = false,
77+
const bool chronometry = false);
78+
4879
/**
4980
* @param input The input signal.
5081
* @param output The output signal of the equal size.
@@ -168,7 +199,7 @@ namespace stftpitchshift
168199
private:
169200

170201
const std::shared_ptr<FFT> fft;
171-
const size_t framesize;
202+
const std::tuple<size_t, size_t> framesize;
172203
const size_t hopsize;
173204
const double samplerate;
174205
const bool normalization;

cpp/StftPitchShift/StftPitchShiftCore.h

+29-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ namespace stftpitchshift
2121
const size_t framesize,
2222
const size_t hopsize,
2323
const double samplerate) :
24+
StftPitchShiftCore(
25+
std::make_shared<RFFT>(),
26+
std::make_tuple(framesize, framesize),
27+
hopsize,
28+
samplerate)
29+
{
30+
}
31+
32+
StftPitchShiftCore(
33+
const std::tuple<size_t, size_t> framesize,
34+
const size_t hopsize,
35+
const double samplerate) :
2436
StftPitchShiftCore(
2537
std::make_shared<RFFT>(),
2638
framesize,
@@ -34,14 +46,27 @@ namespace stftpitchshift
3446
const size_t framesize,
3547
const size_t hopsize,
3648
const double samplerate) :
49+
StftPitchShiftCore(
50+
fft,
51+
std::make_tuple(framesize, framesize),
52+
hopsize,
53+
samplerate)
54+
{
55+
}
56+
57+
StftPitchShiftCore(
58+
const std::shared_ptr<FFT> fft,
59+
const std::tuple<size_t, size_t> framesize,
60+
const size_t hopsize,
61+
const double samplerate) :
3762
fft(fft),
3863
framesize(framesize),
3964
hopsize(hopsize),
4065
samplerate(samplerate),
4166
vocoder(framesize, hopsize, samplerate),
42-
pitcher(framesize, samplerate),
43-
cepster(fft, framesize, samplerate),
44-
envelope(framesize / 2 + 1)
67+
pitcher(std::get<0>(framesize), samplerate),
68+
cepster(fft, std::get<0>(framesize), samplerate),
69+
envelope(std::get<0>(framesize) / 2 + 1)
4570
{
4671
}
4772

@@ -147,7 +172,7 @@ namespace stftpitchshift
147172
private:
148173

149174
const std::shared_ptr<FFT> fft;
150-
const size_t framesize;
175+
const std::tuple<size_t, size_t> framesize;
151176
const size_t hopsize;
152177
const double samplerate;
153178

python/stftpitchshift/stftpitchshift.py

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ def isnotnormal(x):
113113
frames = normalize(frames, frames0)
114114

115115
frames = decode(frames, framesize, hopsize, samplerate)
116-
117116
output = istft(frames, framesize, hopsize)
118117

119118
# disable reference count check on resize,

0 commit comments

Comments
 (0)