From bb4884fd0aeefe4e84412505ccbcd1a363c7c0ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ju=CC=88rgen=20Hock?= Date: Fri, 17 Nov 2023 14:21:17 +0100 Subject: [PATCH] Use std::span instead of std::vector #39 --- cpp/StftPitchShift/BrewStftPitchShift.cmake | 0 cpp/StftPitchShift/CLI.h | 0 cpp/StftPitchShift/Cepster.h | 5 +- cpp/StftPitchShift/ConfigStftPitchShift.cmake | 0 .../ConfigStftPitchShift.cmake.template | 0 cpp/StftPitchShift/DebStftPitchShift.cmake | 0 cpp/StftPitchShift/Dump.h | 4 +- cpp/StftPitchShift/ETC.h | 1 + cpp/StftPitchShift/FFT.h | 10 +- cpp/StftPitchShift/IO.cpp | 0 cpp/StftPitchShift/IO.h | 0 cpp/StftPitchShift/LibStftPitchShift.cmake | 2 +- cpp/StftPitchShift/Normalizer.h | 8 +- cpp/StftPitchShift/Pitcher.h | 6 +- cpp/StftPitchShift/RFFT.h | 15 +-- cpp/StftPitchShift/Resampler.h | 32 ++++--- cpp/StftPitchShift/STFT.h | 39 ++++---- cpp/StftPitchShift/StftPitchShift.cpp | 94 ++----------------- cpp/StftPitchShift/StftPitchShift.h | 81 ++-------------- cpp/StftPitchShift/StftPitchShiftCore.h | 2 +- cpp/StftPitchShift/TheStftPitchShift.cmake | 2 +- cpp/StftPitchShift/Timer.h | 0 cpp/StftPitchShift/VcpkgStftPitchShift.cmake | 0 cpp/StftPitchShift/Version.h | 0 cpp/StftPitchShift/Vocoder.h | 5 +- cpp/StftPitchShift/WasmStftPitchShift.cmake | 1 + cpp/StftPitchShift/cxxopts/CMakeLists.txt | 0 cpp/StftPitchShift/cxxopts/LICENSE | 0 cpp/StftPitchShift/cxxopts/README | 0 cpp/StftPitchShift/cxxopts/cxxopts.hpp | 0 cpp/StftPitchShift/dr_libs/CMakeLists.txt | 0 cpp/StftPitchShift/dr_libs/LICENSE | 0 cpp/StftPitchShift/dr_libs/README | 0 cpp/StftPitchShift/dr_libs/dr_wav.h | 0 cpp/StftPitchShift/main.cpp | 8 +- cpp/StftPitchShift/wasm.cpp | 5 +- examples/CMakeLists.txt | 4 +- 37 files changed, 96 insertions(+), 228 deletions(-) mode change 100644 => 100755 cpp/StftPitchShift/BrewStftPitchShift.cmake mode change 100644 => 100755 cpp/StftPitchShift/CLI.h mode change 100644 => 100755 cpp/StftPitchShift/Cepster.h mode change 100644 => 100755 cpp/StftPitchShift/ConfigStftPitchShift.cmake mode change 100644 => 100755 cpp/StftPitchShift/ConfigStftPitchShift.cmake.template mode change 100644 => 100755 cpp/StftPitchShift/DebStftPitchShift.cmake mode change 100644 => 100755 cpp/StftPitchShift/Dump.h mode change 100644 => 100755 cpp/StftPitchShift/ETC.h mode change 100644 => 100755 cpp/StftPitchShift/FFT.h mode change 100644 => 100755 cpp/StftPitchShift/IO.cpp mode change 100644 => 100755 cpp/StftPitchShift/IO.h mode change 100644 => 100755 cpp/StftPitchShift/LibStftPitchShift.cmake mode change 100644 => 100755 cpp/StftPitchShift/Normalizer.h mode change 100644 => 100755 cpp/StftPitchShift/Pitcher.h mode change 100644 => 100755 cpp/StftPitchShift/RFFT.h mode change 100644 => 100755 cpp/StftPitchShift/Resampler.h mode change 100644 => 100755 cpp/StftPitchShift/STFT.h mode change 100644 => 100755 cpp/StftPitchShift/StftPitchShift.cpp mode change 100644 => 100755 cpp/StftPitchShift/StftPitchShift.h mode change 100644 => 100755 cpp/StftPitchShift/StftPitchShiftCore.h mode change 100644 => 100755 cpp/StftPitchShift/TheStftPitchShift.cmake mode change 100644 => 100755 cpp/StftPitchShift/Timer.h mode change 100644 => 100755 cpp/StftPitchShift/VcpkgStftPitchShift.cmake mode change 100644 => 100755 cpp/StftPitchShift/Version.h mode change 100644 => 100755 cpp/StftPitchShift/Vocoder.h mode change 100644 => 100755 cpp/StftPitchShift/WasmStftPitchShift.cmake mode change 100644 => 100755 cpp/StftPitchShift/cxxopts/CMakeLists.txt mode change 100644 => 100755 cpp/StftPitchShift/cxxopts/LICENSE mode change 100644 => 100755 cpp/StftPitchShift/cxxopts/README mode change 100644 => 100755 cpp/StftPitchShift/cxxopts/cxxopts.hpp mode change 100644 => 100755 cpp/StftPitchShift/dr_libs/CMakeLists.txt mode change 100644 => 100755 cpp/StftPitchShift/dr_libs/LICENSE mode change 100644 => 100755 cpp/StftPitchShift/dr_libs/README mode change 100644 => 100755 cpp/StftPitchShift/dr_libs/dr_wav.h mode change 100644 => 100755 cpp/StftPitchShift/main.cpp mode change 100644 => 100755 cpp/StftPitchShift/wasm.cpp mode change 100644 => 100755 examples/CMakeLists.txt diff --git a/cpp/StftPitchShift/BrewStftPitchShift.cmake b/cpp/StftPitchShift/BrewStftPitchShift.cmake old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/CLI.h b/cpp/StftPitchShift/CLI.h old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/Cepster.h b/cpp/StftPitchShift/Cepster.h old mode 100644 new mode 100755 index 31e3e71..f4f95b2 --- a/cpp/StftPitchShift/Cepster.h +++ b/cpp/StftPitchShift/Cepster.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -36,7 +37,7 @@ namespace stftpitchshift cutoff = static_cast(quefrency * samplerate); } - void lifter(std::vector& envelope) + void lifter(const std::span envelope) { assert(envelope.size() == spectrum.size()); @@ -71,7 +72,7 @@ namespace stftpitchshift std::vector> spectrum; std::vector cepstrum; - static void lowpass(std::vector& cepstrum, const size_t cutoff) + static void lowpass(const std::span cepstrum, const size_t cutoff) { for (size_t i = 1; i < std::min(cutoff, cepstrum.size()); ++i) { diff --git a/cpp/StftPitchShift/ConfigStftPitchShift.cmake b/cpp/StftPitchShift/ConfigStftPitchShift.cmake old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/ConfigStftPitchShift.cmake.template b/cpp/StftPitchShift/ConfigStftPitchShift.cmake.template old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/DebStftPitchShift.cmake b/cpp/StftPitchShift/DebStftPitchShift.cmake old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/Dump.h b/cpp/StftPitchShift/Dump.h old mode 100644 new mode 100755 index c42370f..e52dae7 --- a/cpp/StftPitchShift/Dump.h +++ b/cpp/StftPitchShift/Dump.h @@ -3,8 +3,8 @@ #include #include #include +#include #include -#include namespace stftpitchshift { @@ -22,7 +22,7 @@ namespace stftpitchshift } template - void operator()(const std::vector& data) + void operator()(const std::span data) { if (fileindex < minindex) { diff --git a/cpp/StftPitchShift/ETC.h b/cpp/StftPitchShift/ETC.h old mode 100644 new mode 100755 index 2e27048..ae6a0d3 --- a/cpp/StftPitchShift/ETC.h +++ b/cpp/StftPitchShift/ETC.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/cpp/StftPitchShift/FFT.h b/cpp/StftPitchShift/FFT.h old mode 100644 new mode 100755 index 239e8ed..226218d --- a/cpp/StftPitchShift/FFT.h +++ b/cpp/StftPitchShift/FFT.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace stftpitchshift { @@ -12,11 +12,11 @@ namespace stftpitchshift virtual ~FFT() {} - virtual void fft(const std::vector& frame, std::vector>& dft) = 0; - virtual void fft(const std::vector& frame, std::vector>& dft) = 0; + virtual void fft(const std::span frame, const std::span> dft) = 0; + virtual void fft(const std::span frame, const std::span> dft) = 0; - virtual void ifft(const std::vector>& dft, std::vector& frame) = 0; - virtual void ifft(const std::vector>& dft, std::vector& frame) = 0; + virtual void ifft(const std::span> dft, const std::span frame) = 0; + virtual void ifft(const std::span> dft, const std::span frame) = 0; }; } diff --git a/cpp/StftPitchShift/IO.cpp b/cpp/StftPitchShift/IO.cpp old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/IO.h b/cpp/StftPitchShift/IO.h old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/LibStftPitchShift.cmake b/cpp/StftPitchShift/LibStftPitchShift.cmake old mode 100644 new mode 100755 index 24dcf37..e0b66d2 --- a/cpp/StftPitchShift/LibStftPitchShift.cmake +++ b/cpp/StftPitchShift/LibStftPitchShift.cmake @@ -63,7 +63,7 @@ target_include_directories(${PROJECT_NAME} ) target_compile_features(${PROJECT_NAME} - PRIVATE cxx_std_11 + PRIVATE cxx_std_20 ) install( diff --git a/cpp/StftPitchShift/Normalizer.h b/cpp/StftPitchShift/Normalizer.h old mode 100644 new mode 100755 index f68542f..177c27f --- a/cpp/StftPitchShift/Normalizer.h +++ b/cpp/StftPitchShift/Normalizer.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include template class Normalizer @@ -15,12 +15,12 @@ class Normalizer { } - void calibrate(const std::vector>& data) + void calibrate(const std::span> data) { target = rms(data); } - void normalize(std::vector>& data) const + void normalize(const std::span> data) const { const T a = target; const T b = rms(data); @@ -42,7 +42,7 @@ class Normalizer T target; - static T rms(const std::vector>& data) + static T rms(const std::span> data) { // without 1/N and sqrt diff --git a/cpp/StftPitchShift/Pitcher.h b/cpp/StftPitchShift/Pitcher.h old mode 100644 new mode 100755 index 4dc8407..ad8db79 --- a/cpp/StftPitchShift/Pitcher.h +++ b/cpp/StftPitchShift/Pitcher.h @@ -1,8 +1,10 @@ #pragma once +#include #include #include #include +#include #include #include @@ -41,7 +43,7 @@ namespace stftpitchshift } } - void shiftpitch(std::vector>& dft) + void shiftpitch(const std::span> dft) { if (values.empty()) { @@ -69,7 +71,7 @@ namespace stftpitchshift } } - dft = buffer[0]; + std::copy(buffer[0].begin(), buffer[0].end(), dft.begin()); return; } diff --git a/cpp/StftPitchShift/RFFT.h b/cpp/StftPitchShift/RFFT.h old mode 100644 new mode 100755 index 148199b..e1f9023 --- a/cpp/StftPitchShift/RFFT.h +++ b/cpp/StftPitchShift/RFFT.h @@ -3,10 +3,13 @@ #include #include +#include #include #include +#include #include #include +#include namespace stftpitchshift { @@ -116,7 +119,7 @@ namespace stftpitchshift public: - void fft(const std::vector& frame, std::vector>& dft) + void fft(const std::span frame, const std::span> dft) { assert(dft.size() == frame.size() / 2 + 1); @@ -144,7 +147,7 @@ namespace stftpitchshift } } - void ifft(const std::vector>& dft, std::vector& frame) + void ifft(const std::span> dft, const std::span frame) { assert(dft.size() == frame.size() / 2 + 1); @@ -234,22 +237,22 @@ namespace stftpitchshift public: - void fft(const std::vector& frame, std::vector>& dft) override + void fft(const std::span frame, const std::span> dft) override { precision.f.fft(frame, dft); } - void fft(const std::vector& frame, std::vector>& dft) override + void fft(const std::span frame, const std::span> dft) override { precision.d.fft(frame, dft); } - void ifft(const std::vector>& dft, std::vector& frame) override + void ifft(const std::span> dft, const std::span frame) override { precision.f.ifft(dft, frame); } - void ifft(const std::vector>& dft, std::vector& frame) override + void ifft(const std::span> dft, const std::span frame) override { precision.d.ifft(dft, frame); } diff --git a/cpp/StftPitchShift/Resampler.h b/cpp/StftPitchShift/Resampler.h old mode 100644 new mode 100755 index 8edac4a..b808f9a --- a/cpp/StftPitchShift/Resampler.h +++ b/cpp/StftPitchShift/Resampler.h @@ -1,8 +1,10 @@ #pragma once +#include #include #include #include +#include #include namespace stftpitchshift @@ -28,31 +30,31 @@ namespace stftpitchshift value = factor; } - void linear(std::vector& x) const + void linear(const std::span x) const { linear(x, x); } - void linear(const std::vector& x, - std::vector& y) const + void linear(const std::span x, + const std::span y) const { linear(x, y); } - void linear(std::vector>& x) const + void linear(const std::span> x) const { linear>(x, x); } - void linear(const std::vector>& x, - std::vector>& y) const + void linear(const std::span> x, + const std::span> y) const { linear>(x, y); } - void bilinear(const std::vector& x0, - const std::vector& x1, - std::vector& y) const + void bilinear(const std::span x0, + const std::span x1, + const std::span y) const { assert(x0.size() == y.size()); assert(x1.size() == y.size()); @@ -69,9 +71,9 @@ namespace stftpitchshift } } - void bilinear(const std::vector>& x0, - const std::vector>& x1, - std::vector>& y) const + void bilinear(const std::span> x0, + const std::span> x1, + const std::span> y) const { assert(x0.size() == y.size()); assert(x1.size() == y.size()); @@ -93,8 +95,8 @@ namespace stftpitchshift double value; template - void linear(const std::vector& x, - std::vector& y) const + void linear(const std::span x, + const std::span y) const { assert(x.size() == y.size()); @@ -149,7 +151,7 @@ namespace stftpitchshift } else if (x.data() != y.data()) { - y = x; + std::copy(x.begin(), x.end(), y.begin()); } } diff --git a/cpp/StftPitchShift/STFT.h b/cpp/StftPitchShift/STFT.h old mode 100644 new mode 100755 index 9372567..8522fce --- a/cpp/StftPitchShift/STFT.h +++ b/cpp/StftPitchShift/STFT.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -61,18 +62,14 @@ namespace stftpitchshift [unitygain](T value) { return value * unitygain; }); } - void operator()(const std::vector& input, std::vector& output, const std::function>& dft)> callback) const + void operator()(const std::span input, const std::span output, const std::function> dft)> callback) const { - (*this)(input.size(), input.data(), output.data(), callback); - } + const size_t samples = (std::min)(input.size(), output.size()); - void operator()(const size_t size, const T* input, T* const output, const std::function>& dft)> callback) const - { - const auto analysis_window_size = std::get<0>(framesize); - const auto synthesis_window_size = std::get<1>(framesize); + const size_t analysis_window_size = std::get<0>(framesize); + const size_t synthesis_window_size = std::get<1>(framesize); - // TODO preemptively clear output memory #30 - std::fill(output, output + size, T(0)); + std::fill(output.begin(), output.end(), T(0)); // clear output #30 std::vector frame(analysis_window_size); std::vector> dft(analysis_window_size / 2 + 1); @@ -89,10 +86,10 @@ namespace stftpitchshift timers; timers.loop.tic(); - for (size_t hop = 0; (hop + synthesis_window_size) < size; hop += hopsize) + for (size_t hop = 0; (hop + synthesis_window_size) < samples; hop += hopsize) { timers.analysis.tic(); - reject(input + hop, frame, windows.analysis); + reject(input.subspan(hop, synthesis_window_size), frame, windows.analysis); transform(frame, dft); timers.analysis.toc(); @@ -102,7 +99,7 @@ namespace stftpitchshift timers.synthesis.tic(); transform(dft, frame); - inject(output + hop, frame, windows.synthesis); + inject(output.subspan(hop, synthesis_window_size), frame, windows.synthesis); timers.synthesis.toc(); } timers.loop.toc(); @@ -114,15 +111,15 @@ namespace stftpitchshift } else { - for (size_t hop = 0; (hop + synthesis_window_size) < size; hop += hopsize) + for (size_t hop = 0; (hop + synthesis_window_size) < samples; hop += hopsize) { - reject(input + hop, frame, windows.analysis); + reject(input.subspan(hop, synthesis_window_size), frame, windows.analysis); transform(frame, dft); callback(dft); transform(dft, frame); - inject(output + hop, frame, windows.synthesis); + inject(output.subspan(hop, synthesis_window_size), frame, windows.synthesis); } } } @@ -141,7 +138,7 @@ namespace stftpitchshift } windows; - inline void transform(std::vector& frame, std::vector>& dft) const + inline void transform(const std::span frame, const std::span> dft) const { fft->fft(frame, dft); @@ -152,7 +149,7 @@ namespace stftpitchshift } } - inline void transform(std::vector>& dft, std::vector& frame) const + inline void transform(const std::span> dft, const std::span frame) const { if (true) // optionally zero dc and nyquist { @@ -163,17 +160,17 @@ namespace stftpitchshift fft->ifft(dft, frame); } - inline void reject(const T* input, std::vector& frame, const std::vector& window) const + inline void reject(const std::span input, const std::span frame, const std::vector& window) const { - for (size_t i = 0; i < frame.size(); ++i) + for (size_t i = 0; i < window.size(); ++i) { frame[i] = input[i] * window[i]; } } - inline void inject(T* const output, const std::vector& frame, const std::vector& window) const + inline void inject(const std::span output, const std::span frame, const std::vector& window) const { - for (size_t i = 0; i < frame.size(); ++i) + for (size_t i = 0; i < window.size(); ++i) { output[i] += frame[i] * window[i]; } diff --git a/cpp/StftPitchShift/StftPitchShift.cpp b/cpp/StftPitchShift/StftPitchShift.cpp old mode 100644 new mode 100755 index 08a9a6e..eb84756 --- a/cpp/StftPitchShift/StftPitchShift.cpp +++ b/cpp/StftPitchShift/StftPitchShift.cpp @@ -74,8 +74,8 @@ StftPitchShift::StftPitchShift( } void StftPitchShift::shiftpitch( - const std::vector& input, - std::vector& output, + const std::span input, + const std::span output, const double factor, const double quefrency, const double distortion) @@ -83,44 +83,6 @@ void StftPitchShift::shiftpitch( const std::vector factors = { factor }; shiftpitch( - input.size(), - input.data(), - output.data(), - factors, - quefrency, - distortion); -} - -void StftPitchShift::shiftpitch( - const std::vector& input, - std::vector& output, - const double factor, - const double quefrency, - const double distortion) -{ - const std::vector factors = { factor }; - - shiftpitch( - input.size(), - input.data(), - output.data(), - factors, - quefrency, - distortion); -} - -void StftPitchShift::shiftpitch( - const size_t size, - const float* input, - float* const output, - const double factor, - const double quefrency, - const double distortion) -{ - const std::vector factors = { factor }; - - shiftpitch( - size, input, output, factors, @@ -129,9 +91,8 @@ void StftPitchShift::shiftpitch( } void StftPitchShift::shiftpitch( - const size_t size, - const double* input, - double* const output, + const std::span input, + const std::span output, const double factor, const double quefrency, const double distortion) @@ -139,7 +100,6 @@ void StftPitchShift::shiftpitch( const std::vector factors = { factor }; shiftpitch( - size, input, output, factors, @@ -148,41 +108,8 @@ void StftPitchShift::shiftpitch( } void StftPitchShift::shiftpitch( - const std::vector& input, - std::vector& output, - const std::vector& factors, - const double quefrency, - const double distortion) -{ - shiftpitch( - input.size(), - input.data(), - output.data(), - factors, - quefrency, - distortion); -} - -void StftPitchShift::shiftpitch( - const std::vector& input, - std::vector& output, - const std::vector& factors, - const double quefrency, - const double distortion) -{ - shiftpitch( - input.size(), - input.data(), - output.data(), - factors, - quefrency, - distortion); -} - -void StftPitchShift::shiftpitch( - const size_t size, - const float* input, - float* const output, + const std::span input, + const std::span output, const std::vector& factors, const double quefrency, const double distortion) @@ -196,16 +123,15 @@ void StftPitchShift::shiftpitch( STFT stft(fft, framesize, hopsize, chronometry); - stft(size, input, output, [&](std::vector>& dft) + stft(input, output, [&](std::span> dft) { core.shiftpitch(dft); }); } void StftPitchShift::shiftpitch( - const size_t size, - const double* input, - double* const output, + const std::span input, + const std::span output, const std::vector& factors, const double quefrency, const double distortion) @@ -219,7 +145,7 @@ void StftPitchShift::shiftpitch( STFT stft(fft, framesize, hopsize, chronometry); - stft(size, input, output, [&](std::vector>& dft) + stft(input, output, [&](std::span> dft) { core.shiftpitch(dft); }); diff --git a/cpp/StftPitchShift/StftPitchShift.h b/cpp/StftPitchShift/StftPitchShift.h old mode 100644 new mode 100755 index 5ad51da..18571ed --- a/cpp/StftPitchShift/StftPitchShift.h +++ b/cpp/StftPitchShift/StftPitchShift.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -84,8 +85,8 @@ namespace stftpitchshift * @param distortion The fractional timbre shifting factor. */ void shiftpitch( - const std::vector& input, - std::vector& output, + const std::span input, + const std::span output, const double factor = 1, const double quefrency = 0, const double distortion = 1); @@ -98,74 +99,13 @@ namespace stftpitchshift * @param distortion The fractional timbre shifting factor. */ void shiftpitch( - const std::vector& input, - std::vector& output, + const std::span input, + const std::span output, const double factor = 1, const double quefrency = 0, const double distortion = 1); /** - * @param size The total number of signal values, not bytes. - * @param input The input signal. - * @param output The output signal of the equal size. - * @param factor The fractional pitch shifting factor. - * @param quefrency The optional formant lifter quefrency in seconds. - * @param distortion The fractional timbre shifting factor. - */ - void shiftpitch( - const size_t size, - const float* input, - float* const output, - const double factor = 1, - const double quefrency = 0, - const double distortion = 1); - - /** - * @param size The total number of signal values, not bytes. - * @param input The input signal. - * @param output The output signal of the equal size. - * @param factor The fractional pitch shifting factor. - * @param quefrency The optional formant lifter quefrency in seconds. - * @param distortion The fractional timbre shifting factor. - */ - void shiftpitch( - const size_t size, - const double* input, - double* const output, - const double factor = 1, - const double quefrency = 0, - const double distortion = 1); - - /** - * @param input The input signal. - * @param output The output signal of the equal size. - * @param factors The fractional pitch shifting factors. - * @param quefrency The optional formant lifter quefrency in seconds. - * @param distortion The fractional timbre shifting factor. - */ - void shiftpitch( - const std::vector& input, - std::vector& output, - const std::vector& factors, - const double quefrency = 0, - const double distortion = 1); - - /** - * @param input The input signal. - * @param output The output signal of the equal size. - * @param factors The fractional pitch shifting factors. - * @param quefrency The optional formant lifter quefrency in seconds. - * @param distortion The fractional timbre shifting factor. - */ - void shiftpitch( - const std::vector& input, - std::vector& output, - const std::vector& factors, - const double quefrency = 0, - const double distortion = 1); - - /** - * @param size The total number of signal values, not bytes. * @param input The input signal. * @param output The output signal of the equal size. * @param factors The fractional pitch shifting factors. @@ -173,15 +113,13 @@ namespace stftpitchshift * @param distortion The fractional timbre shifting factor. */ void shiftpitch( - const size_t size, - const float* input, - float* const output, + const std::span input, + const std::span output, const std::vector& factors, const double quefrency = 0, const double distortion = 1); /** - * @param size The total number of signal values, not bytes. * @param input The input signal. * @param output The output signal of the equal size. * @param factors The fractional pitch shifting factors. @@ -189,9 +127,8 @@ namespace stftpitchshift * @param distortion The fractional timbre shifting factor. */ void shiftpitch( - const size_t size, - const double* input, - double* const output, + const std::span input, + const std::span output, const std::vector& factors, const double quefrency = 0, const double distortion = 1); diff --git a/cpp/StftPitchShift/StftPitchShiftCore.h b/cpp/StftPitchShift/StftPitchShiftCore.h old mode 100644 new mode 100755 index 8f3eae1..2105775 --- a/cpp/StftPitchShift/StftPitchShiftCore.h +++ b/cpp/StftPitchShift/StftPitchShiftCore.h @@ -117,7 +117,7 @@ namespace stftpitchshift } } - void shiftpitch(std::vector>& dft) + void shiftpitch(const std::span> dft) { vocoder.encode(dft); diff --git a/cpp/StftPitchShift/TheStftPitchShift.cmake b/cpp/StftPitchShift/TheStftPitchShift.cmake old mode 100644 new mode 100755 index 44d3e8d..bc3828b --- a/cpp/StftPitchShift/TheStftPitchShift.cmake +++ b/cpp/StftPitchShift/TheStftPitchShift.cmake @@ -34,7 +34,7 @@ target_link_libraries(${PROJECT_NAME} ) target_compile_features(${PROJECT_NAME} - PRIVATE cxx_std_11 + PRIVATE cxx_std_20 ) install( diff --git a/cpp/StftPitchShift/Timer.h b/cpp/StftPitchShift/Timer.h old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/VcpkgStftPitchShift.cmake b/cpp/StftPitchShift/VcpkgStftPitchShift.cmake old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/Version.h b/cpp/StftPitchShift/Version.h old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/Vocoder.h b/cpp/StftPitchShift/Vocoder.h old mode 100644 new mode 100755 index 284890d..0edaa5c --- a/cpp/StftPitchShift/Vocoder.h +++ b/cpp/StftPitchShift/Vocoder.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -40,7 +41,7 @@ namespace stftpitchshift } } - void encode(std::vector>& dft) + void encode(const std::span> dft) { assert(dft.size() == encode_phase_buffer.size()); @@ -66,7 +67,7 @@ namespace stftpitchshift } } - void decode(std::vector>& dft) + void decode(const std::span> dft) { assert(dft.size() == decode_phase_buffer.size()); diff --git a/cpp/StftPitchShift/WasmStftPitchShift.cmake b/cpp/StftPitchShift/WasmStftPitchShift.cmake old mode 100644 new mode 100755 index 6c81509..7e6a88e --- a/cpp/StftPitchShift/WasmStftPitchShift.cmake +++ b/cpp/StftPitchShift/WasmStftPitchShift.cmake @@ -14,6 +14,7 @@ add_custom_command( -s EXPORTED_RUNTIME_METHODS=allocateUTF8,UTF8ToString -s EXPORTED_FUNCTIONS=_malloc,_free -O2 + -std=c++20 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" DEPENDS "${CMAKE_CURRENT_LIST_DIR}/wasm.cpp" VERBATIM) diff --git a/cpp/StftPitchShift/cxxopts/CMakeLists.txt b/cpp/StftPitchShift/cxxopts/CMakeLists.txt old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/cxxopts/LICENSE b/cpp/StftPitchShift/cxxopts/LICENSE old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/cxxopts/README b/cpp/StftPitchShift/cxxopts/README old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/cxxopts/cxxopts.hpp b/cpp/StftPitchShift/cxxopts/cxxopts.hpp old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/dr_libs/CMakeLists.txt b/cpp/StftPitchShift/dr_libs/CMakeLists.txt old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/dr_libs/LICENSE b/cpp/StftPitchShift/dr_libs/LICENSE old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/dr_libs/README b/cpp/StftPitchShift/dr_libs/README old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/dr_libs/dr_wav.h b/cpp/StftPitchShift/dr_libs/dr_wav.h old mode 100644 new mode 100755 diff --git a/cpp/StftPitchShift/main.cpp b/cpp/StftPitchShift/main.cpp old mode 100644 new mode 100755 index 5e16f17..a445876 --- a/cpp/StftPitchShift/main.cpp +++ b/cpp/StftPitchShift/main.cpp @@ -7,8 +7,7 @@ using namespace stftpitchshift; -const int OK = 0; -const int NOK = 1; +const int OK = 0, NOK = 1; int main(int argc, char** argv) { @@ -61,8 +60,8 @@ int main(int argc, char** argv) for (size_t channel = 0; channel < channels; ++channel) { const size_t size = indata.size() / channels; - const double* input = indata.data() + channel * size; - double* const output = outdata.data() + channel * size; + const std::span input = { indata.data() + channel * size, size }; + const std::span output = { outdata.data() + channel * size, size }; StftPitchShift stft( cli.framesize, @@ -72,7 +71,6 @@ int main(int argc, char** argv) cli.chronometry); stft.shiftpitch( - size, input, output, cli.factors, diff --git a/cpp/StftPitchShift/wasm.cpp b/cpp/StftPitchShift/wasm.cpp old mode 100644 new mode 100755 index 7156aa8..a18067f --- a/cpp/StftPitchShift/wasm.cpp +++ b/cpp/StftPitchShift/wasm.cpp @@ -125,9 +125,8 @@ extern "C" cli.chronometry); stft.shiftpitch( - samples, - input, - output, + { input, static_cast(samples) }, + { output, static_cast(samples) }, cli.factors, cli.quefrency, cli.distortion); diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt old mode 100644 new mode 100755 index 8323d12..9e4f304 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,8 +4,8 @@ project(StftPitchShiftExample) add_executable(example "${CMAKE_CURRENT_LIST_DIR}/example.cpp") -# at least C++ 11 is mandatory -target_compile_features(example PRIVATE cxx_std_11) +# at least C++ 20 is mandatory +target_compile_features(example PRIVATE cxx_std_20) # just the case of default build e.g. if LibStftPitchShift.cmake is already included target_link_libraries(example stftpitchshift)