Skip to content

Commit

Permalink
Use const span to indicate the read-only input #39
Browse files Browse the repository at this point in the history
  • Loading branch information
jurihock committed Nov 28, 2023
1 parent 00ae8a3 commit ef3311e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cpp/StftPitchShift/Dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace stftpitchshift
}

template<class T>
void operator()(const std::span<T> data)
void operator()(const std::span<const T> data)
{
if (fileindex < minindex)
{
Expand Down
8 changes: 4 additions & 4 deletions cpp/StftPitchShift/FFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace stftpitchshift

virtual ~FFT() {}

virtual void fft(const std::span<float> frame, const std::span<std::complex<float>> dft) = 0;
virtual void fft(const std::span<double> frame, const std::span<std::complex<double>> dft) = 0;
virtual void fft(const std::span<const float> frame, const std::span<std::complex<float>> dft) = 0;
virtual void fft(const std::span<const double> frame, const std::span<std::complex<double>> dft) = 0;

virtual void ifft(const std::span<std::complex<float>> dft, const std::span<float> frame) = 0;
virtual void ifft(const std::span<std::complex<double>> dft, const std::span<double> frame) = 0;
virtual void ifft(const std::span<const std::complex<float>> dft, const std::span<float> frame) = 0;
virtual void ifft(const std::span<const std::complex<double>> dft, const std::span<double> frame) = 0;

};
}
4 changes: 2 additions & 2 deletions cpp/StftPitchShift/Normalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Normalizer
{
}

void calibrate(const std::span<std::complex<T>> data)
void calibrate(const std::span<const std::complex<T>> data)
{
target = rms(data);
}
Expand All @@ -42,7 +42,7 @@ class Normalizer

T target;

static T rms(const std::span<std::complex<T>> data)
static T rms(const std::span<const std::complex<T>> data)
{
// without 1/N and sqrt

Expand Down
12 changes: 6 additions & 6 deletions cpp/StftPitchShift/RFFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace stftpitchshift

public:

void fft(const std::span<T> frame, const std::span<std::complex<T>> dft)
void fft(const std::span<const T> frame, const std::span<std::complex<T>> dft)
{
assert(dft.size() == frame.size() / 2 + 1);

Expand Down Expand Up @@ -147,7 +147,7 @@ namespace stftpitchshift
}
}

void ifft(const std::span<std::complex<T>> dft, const std::span<T> frame)
void ifft(const std::span<const std::complex<T>> dft, const std::span<T> frame)
{
assert(dft.size() == frame.size() / 2 + 1);

Expand Down Expand Up @@ -237,22 +237,22 @@ namespace stftpitchshift

public:

void fft(const std::span<float> frame, const std::span<std::complex<float>> dft) override
void fft(const std::span<const float> frame, const std::span<std::complex<float>> dft) override
{
precision.f.fft(frame, dft);
}

void fft(const std::span<double> frame, const std::span<std::complex<double>> dft) override
void fft(const std::span<const double> frame, const std::span<std::complex<double>> dft) override
{
precision.d.fft(frame, dft);
}

void ifft(const std::span<std::complex<float>> dft, const std::span<float> frame) override
void ifft(const std::span<const std::complex<float>> dft, const std::span<float> frame) override
{
precision.f.ifft(dft, frame);
}

void ifft(const std::span<std::complex<double>> dft, const std::span<double> frame) override
void ifft(const std::span<const std::complex<double>> dft, const std::span<double> frame) override
{
precision.d.ifft(dft, frame);
}
Expand Down
14 changes: 7 additions & 7 deletions cpp/StftPitchShift/Resampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace stftpitchshift
linear<T>(x, x);
}

void linear(const std::span<T> x,
void linear(const std::span<const T> x,
const std::span<T> y) const
{
linear<T>(x, y);
Expand All @@ -46,14 +46,14 @@ namespace stftpitchshift
linear<std::complex<T>>(x, x);
}

void linear(const std::span<std::complex<T>> x,
void linear(const std::span<const std::complex<T>> x,
const std::span<std::complex<T>> y) const
{
linear<std::complex<T>>(x, y);
}

void bilinear(const std::span<T> x0,
const std::span<T> x1,
void bilinear(const std::span<const T> x0,
const std::span<const T> x1,
const std::span<T> y) const
{
assert(x0.size() == y.size());
Expand All @@ -71,8 +71,8 @@ namespace stftpitchshift
}
}

void bilinear(const std::span<std::complex<T>> x0,
const std::span<std::complex<T>> x1,
void bilinear(const std::span<const std::complex<T>> x0,
const std::span<const std::complex<T>> x1,
const std::span<std::complex<T>> y) const
{
assert(x0.size() == y.size());
Expand All @@ -95,7 +95,7 @@ namespace stftpitchshift
double value;

template<class V>
void linear(const std::span<V> x,
void linear(const std::span<const V> x,
const std::span<V> y) const
{
assert(x.size() == y.size());
Expand Down
10 changes: 5 additions & 5 deletions cpp/StftPitchShift/STFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace stftpitchshift
buffer.freq.resize(buffer.size / 2 + 1);
}

void operator()(const std::span<T> input, const std::span<T> output, const std::function<void(std::span<std::complex<T>> dft)> callback)
void operator()(const std::span<const T> input, const std::span<T> output, const std::function<void(std::span<std::complex<T>> dft)> callback)
{
const size_t samples = (std::min)(input.size(), output.size());

Expand All @@ -96,7 +96,7 @@ namespace stftpitchshift
timers.loop.tic();
for (size_t hop = 0; (hop + buffer.size) < samples; hop += hopsize)
{
const std::span<T> src = input.subspan(hop, buffer.size);
const std::span<const T> src = input.subspan(hop, buffer.size);
const std::span<T> dst = output.subspan(hop, buffer.size);

timers.analysis.tic();
Expand Down Expand Up @@ -124,7 +124,7 @@ namespace stftpitchshift
{
for (size_t hop = 0; (hop + buffer.size) < samples; hop += hopsize)
{
const std::span<T> src = input.subspan(hop, buffer.size);
const std::span<const T> src = input.subspan(hop, buffer.size);
const std::span<T> dst = output.subspan(hop, buffer.size);

reject(src, buffer.time, window.analysis);
Expand Down Expand Up @@ -182,15 +182,15 @@ namespace stftpitchshift
fft->ifft(dft, frame);
}

inline void reject(const std::span<T> input, const std::span<T> frame, const std::span<T> window) const
inline void reject(const std::span<const T> input, const std::span<T> frame, const std::span<T> window) const
{
for (size_t i = 0; i < window.size(); ++i)
{
frame[i] = input[i] * window[i];
}
}

inline void inject(const std::span<T> output, const std::span<T> frame, const std::span<T> window) const
inline void inject(const std::span<T> output, const std::span<const T> frame, const std::span<T> window) const
{
for (size_t i = 0; i < window.size(); ++i)
{
Expand Down
8 changes: 4 additions & 4 deletions cpp/StftPitchShift/StftPitchShift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ StftPitchShift::StftPitchShift(
}

void StftPitchShift::shiftpitch(
const std::span<float> input,
const std::span<const float> input,
const std::span<float> output,
const double factor,
const double quefrency,
Expand All @@ -91,7 +91,7 @@ void StftPitchShift::shiftpitch(
}

void StftPitchShift::shiftpitch(
const std::span<double> input,
const std::span<const double> input,
const std::span<double> output,
const double factor,
const double quefrency,
Expand All @@ -108,7 +108,7 @@ void StftPitchShift::shiftpitch(
}

void StftPitchShift::shiftpitch(
const std::span<float> input,
const std::span<const float> input,
const std::span<float> output,
const std::vector<double>& factors,
const double quefrency,
Expand All @@ -133,7 +133,7 @@ void StftPitchShift::shiftpitch(
}

void StftPitchShift::shiftpitch(
const std::span<double> input,
const std::span<const double> input,
const std::span<double> output,
const std::vector<double>& factors,
const double quefrency,
Expand Down
8 changes: 4 additions & 4 deletions cpp/StftPitchShift/StftPitchShift.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace stftpitchshift
* @param distortion The fractional timbre shifting factor.
*/
void shiftpitch(
const std::span<float> input,
const std::span<const float> input,
const std::span<float> output,
const double factor = 1,
const double quefrency = 0,
Expand All @@ -99,7 +99,7 @@ namespace stftpitchshift
* @param distortion The fractional timbre shifting factor.
*/
void shiftpitch(
const std::span<double> input,
const std::span<const double> input,
const std::span<double> output,
const double factor = 1,
const double quefrency = 0,
Expand All @@ -113,7 +113,7 @@ namespace stftpitchshift
* @param distortion The fractional timbre shifting factor.
*/
void shiftpitch(
const std::span<float> input,
const std::span<const float> input,
const std::span<float> output,
const std::vector<double>& factors,
const double quefrency = 0,
Expand All @@ -127,7 +127,7 @@ namespace stftpitchshift
* @param distortion The fractional timbre shifting factor.
*/
void shiftpitch(
const std::span<double> input,
const std::span<const double> input,
const std::span<double> output,
const std::vector<double>& factors,
const double quefrency = 0,
Expand Down

0 comments on commit ef3311e

Please sign in to comment.