From 17f696750926898b50ff0940c1c6a874fa9c8cee Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 13:30:43 +0100 Subject: [PATCH 01/49] constexpr hash compatible with c++11 --- src/sfizz/StringViewHelpers.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/sfizz/StringViewHelpers.h b/src/sfizz/StringViewHelpers.h index ed630c94..141881a9 100644 --- a/src/sfizz/StringViewHelpers.h +++ b/src/sfizz/StringViewHelpers.h @@ -56,10 +56,7 @@ constexpr uint64_t Fnv1aPrime = 0x01000193; */ constexpr uint64_t hash(absl::string_view s, uint64_t h = Fnv1aBasis) { - if (s.length() > 0) - return hash( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime ); - - return h; + return (s.length() == 0) ? h : hash( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime ); } /** @@ -73,12 +70,9 @@ constexpr uint64_t hash(absl::string_view s, uint64_t h = Fnv1aBasis) */ constexpr uint64_t hashNoAmpersand(absl::string_view s, uint64_t h = Fnv1aBasis) { - if (s.length() > 0) { - if (s.front() == '&') - return hashNoAmpersand( { s.data() + 1, s.length() - 1 }, h ); - else - return hashNoAmpersand( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime ); - } - - return h; + return (s.length() == 0) ? h : ( + (s.front() == '&') + ? hashNoAmpersand( { s.data() + 1, s.length() - 1 }, h ) + : hashNoAmpersand( { s.data() + 1, s.length() - 1 }, (h ^ s.front()) * Fnv1aPrime ) + ); } From 76561bd186931778e9b888f5745cd515c1b7b3a8 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 13:32:36 +0100 Subject: [PATCH 02/49] Minimum c++11 --- cmake/SfizzConfig.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/SfizzConfig.cmake b/cmake/SfizzConfig.cmake index 61ba6a13..31af5c4b 100644 --- a/cmake/SfizzConfig.cmake +++ b/cmake/SfizzConfig.cmake @@ -1,6 +1,6 @@ # Do not override the C++ standard if set to more than 14 -if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 14) - set(CMAKE_CXX_STANDARD 14) +if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 11) + set(CMAKE_CXX_STANDARD 11) endif() # Export the compile_commands.json file From 57868c13dbb3cea8a3beb5d09bda17bdc6c638c7 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 13:32:52 +0100 Subject: [PATCH 03/49] Use a constexpr min --- src/sfizz/MathHelpers.h | 8 ++++---- src/sfizz/Range.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sfizz/MathHelpers.h b/src/sfizz/MathHelpers.h index 2f88b2f6..bab1c0bd 100644 --- a/src/sfizz/MathHelpers.h +++ b/src/sfizz/MathHelpers.h @@ -17,25 +17,25 @@ template constexpr T max(T op1, T op2) { - return std::max(op1, op2); + return op1 > op2 ? op1 : op2; } template constexpr T max(T op1, Args... rest) { - return std::max(op1, max(rest...)); + return max(op1, max(rest...)); } template constexpr T min(T op1, T op2) { - return std::min(op1, op2); + return op1 > op2 ? op2 : op1; } template constexpr T min(T op1, Args... rest) { - return std::min(op1, min(rest...)); + return min(op1, min(rest...)); } /** diff --git a/src/sfizz/Range.h b/src/sfizz/Range.h index 35e8e1b4..b39b7c0d 100644 --- a/src/sfizz/Range.h +++ b/src/sfizz/Range.h @@ -24,7 +24,7 @@ public: constexpr Range() = default; constexpr Range(Type start, Type end) noexcept : _start(start) - , _end(std::max(start, end)) + , _end(max(start, end)) { } From 3d7ff1bca900e5685e3a27de9ce247da1ac7b7a0 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 13:33:57 +0100 Subject: [PATCH 04/49] Changes to the Buffer --- src/sfizz/Buffer.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/sfizz/Buffer.h b/src/sfizz/Buffer.h index 757fe9cd..ca3b7363 100644 --- a/src/sfizz/Buffer.h +++ b/src/sfizz/Buffer.h @@ -31,6 +31,8 @@ #include #include #include +#include + #ifdef DEBUG #include #endif @@ -92,6 +94,8 @@ private: std::atomic bytes { 0 }; }; + + /** * @brief A heap buffer structure that tries to align its beginning and * adds a small offset at the end for alignment too. @@ -109,7 +113,7 @@ private: template class Buffer { public: - using value_type = std::remove_cv_t; + using value_type = typename std::remove_cv::type; using pointer = value_type*; using const_pointer = const value_type*; using reference = value_type&; @@ -165,7 +169,7 @@ public: largerSize = tempSize; alignedSize = newSize; paddedData = static_cast(newData); - normalData = static_cast(std::align(Alignment, alignedSize, newData, tempSize)); + normalData = static_cast(align(Alignment, alignedSize, newData, tempSize)); normalEnd = normalData + alignedSize; auto endMisalignment = (alignedSize & TypeAlignmentMask); if (endMisalignment != 0) @@ -274,12 +278,22 @@ public: return counter; } private: - static constexpr auto AlignmentMask { Alignment - 1 }; - static constexpr auto TypeAlignment { Alignment / sizeof(value_type) }; - static constexpr auto TypeAlignmentMask { TypeAlignment - 1 }; + static constexpr int AlignmentMask { Alignment - 1 }; + static constexpr int TypeAlignment { Alignment / sizeof(value_type) }; + static constexpr int TypeAlignmentMask { TypeAlignment - 1 }; static_assert(std::is_arithmetic::value, "Type should be arithmetic"); static_assert(Alignment == 0 || Alignment == 4 || Alignment == 8 || Alignment == 16, "Bad alignment value"); static_assert(TypeAlignment * sizeof(value_type) == Alignment, "The alignment does not appear to be divided by the size of the Type"); + void* align(std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space ) + { + std::uintptr_t pn = reinterpret_cast< std::uintptr_t>( ptr ); + std::uintptr_t aligned = ( pn + alignment - 1 ) & - alignment; + std::size_t padding = aligned - pn; + if ( space < size + padding ) return nullptr; + space -= padding; + return ptr = reinterpret_cast< void * >( aligned ); + } + size_type largerSize { 0 }; size_type alignedSize { 0 }; pointer normalData { nullptr }; From 9a49348274e3ceca30a4edcb87cfdec779773898 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 13:35:07 +0100 Subject: [PATCH 05/49] Use a constexpr minmax in SfzHelpers --- src/sfizz/SfzHelpers.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sfizz/SfzHelpers.h b/src/sfizz/SfzHelpers.h index 4a69ba95..188574f4 100644 --- a/src/sfizz/SfzHelpers.h +++ b/src/sfizz/SfzHelpers.h @@ -11,6 +11,7 @@ #include #include #include "Config.h" +#include "MathHelpers.h" namespace sfz { @@ -85,7 +86,7 @@ template constexpr float normalizeCC(T ccValue) { static_assert(std::is_integral::value, "Requires an integral T"); - return static_cast(std::min(std::max(ccValue, static_cast(0)), static_cast(127))) / 127.0f; + return static_cast(min(max(ccValue, static_cast(0)), static_cast(127))) / 127.0f; } /** @@ -124,7 +125,7 @@ constexpr float normalizePercents(T percentValue) */ constexpr float normalizeBend(float bendValue) { - return std::min(std::max(bendValue, -8191.0f), 8191.0f) / 8191.0f; + return min(max(bendValue, -8191.0f), 8191.0f) / 8191.0f; } /** From 20475047a108f7711fc655e3d483a008a017e538 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 13:35:52 +0100 Subject: [PATCH 06/49] Remove the constexpr for multiplyByCents --- src/sfizz/SfzHelpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sfizz/SfzHelpers.h b/src/sfizz/SfzHelpers.h index 188574f4..5ccf8363 100644 --- a/src/sfizz/SfzHelpers.h +++ b/src/sfizz/SfzHelpers.h @@ -241,7 +241,7 @@ constexpr void addToBase(T& base, T modifier) * @param base * @param modifier */ -constexpr void multiplyByCents(float& base, int modifier) +void multiplyByCents(float& base, int modifier) { base *= centsFactor(modifier); } From f54117986471ebee69575b8e1e7e36512c7cb218 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 13:36:20 +0100 Subject: [PATCH 07/49] Use the verbose type_trait check in Opcode.h --- src/sfizz/Opcode.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sfizz/Opcode.h b/src/sfizz/Opcode.h index 2ac43209..7edbe9ac 100644 --- a/src/sfizz/Opcode.h +++ b/src/sfizz/Opcode.h @@ -45,7 +45,7 @@ struct Opcode { * @param validRange the range of admitted values * @return absl::optional the cast value, or null */ -template ::value, int> = 0> +template ::value, int>::type = 0> inline absl::optional readOpcode(absl::string_view value, const Range& validRange) { int64_t returnedValue; @@ -74,7 +74,7 @@ inline absl::optional readOpcode(absl::string_view value, const Range * @param validRange the range of admitted values * @return absl::optional the cast value, or null */ -template ::value, int> = 0> +template ::value, int>::type = 0> inline absl::optional readOpcode(absl::string_view value, const Range& validRange) { float returnedValue; From 9065f8233910783b43190f77551f5452bcff2702 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 13:37:45 +0100 Subject: [PATCH 08/49] Use the verbose type_trait in AudioBuffer --- src/sfizz/AudioBuffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sfizz/AudioBuffer.h b/src/sfizz/AudioBuffer.h index 7de52af2..3d376a0d 100644 --- a/src/sfizz/AudioBuffer.h +++ b/src/sfizz/AudioBuffer.h @@ -28,7 +28,7 @@ namespace sfz template class AudioBuffer { public: - using value_type = std::remove_cv_t; + using value_type = typename std::remove_cv::type; using pointer = value_type*; using const_pointer = const value_type*; using iterator = pointer; From 7e696828a757c13b86bba4cd9e5edfe13d0c67b1 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 13:50:21 +0100 Subject: [PATCH 09/49] Change in math constants --- src/sfizz/MathHelpers.h | 29 +++++++++++++++-------------- src/sfizz/OnePoleFilter.h | 2 +- src/sfizz/SIMDHelpers.h | 2 +- src/sfizz/Voice.cpp | 6 +++--- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/sfizz/MathHelpers.h b/src/sfizz/MathHelpers.h index bab1c0bd..a8c97be6 100644 --- a/src/sfizz/MathHelpers.h +++ b/src/sfizz/MathHelpers.h @@ -124,8 +124,8 @@ inline float midiNoteFrequency(const int noteNumber) template constexpr T clamp( T v, T lo, T hi ) { - v = std::min(v, hi); - v = std::max(v, lo); + v = min(v, hi); + v = max(v, lo); return v; } @@ -148,18 +148,19 @@ constexpr ValueType linearInterpolation(ValueType left, ValueType right, ValueTy return left * leftCoeff + right * rightCoeff; } -template -constexpr Type pi { static_cast(3.141592653589793238462643383279502884) }; -template -constexpr Type twoPi { static_cast(2) * pi }; -template -constexpr Type piTwo { pi / static_cast(2) }; -template -constexpr Type piFour { pi / static_cast(4) }; -template -constexpr Type sqrtTwo { static_cast(1.414213562373095048801688724209698078569671875376948073176) }; -template -constexpr Type sqrtTwoInv { static_cast(0.707106781186547524400844362104849039284835937688474036588) }; +constexpr double dPi { 3.141592653589793238462643383279502884}; +constexpr double dTwoPi { dPi * 2 }; +constexpr double dPiTwo { dPi / 2 }; +constexpr double dPiFour { dPi / 4 }; +constexpr double dSqrtTwo { 1.414213562373095048801688724209698078569671875376948073176 }; +constexpr double dSqrtTwoInv { 0.707106781186547524400844362104849039284835937688474036588 }; + +constexpr float fPi { 3.141592653589793238462643383279502884}; +constexpr float fTwoPi { fPi * 2 }; +constexpr float fPiTwo { fPi / 2 }; +constexpr float fPiFour { fPi / 4 }; +constexpr float fSqrtTwo { 1.414213562373095048801688724209698078569671875376948073176 }; +constexpr float fSqrtTwoInv { 0.707106781186547524400844362104849039284835937688474036588 }; /** @brief A fraction which is parameterized by integer type diff --git a/src/sfizz/OnePoleFilter.h b/src/sfizz/OnePoleFilter.h index b9c6d805..46791ef4 100644 --- a/src/sfizz/OnePoleFilter.h +++ b/src/sfizz/OnePoleFilter.h @@ -26,7 +26,7 @@ public: template static Type normalizedGain(Type cutoff, C sampleRate) { - return std::tan(cutoff / static_cast(sampleRate) * pi); + return std::tan(cutoff / static_cast(sampleRate) * fPi); } OnePoleFilter(Type gain) diff --git a/src/sfizz/SIMDHelpers.h b/src/sfizz/SIMDHelpers.h index d466933c..253c125a 100644 --- a/src/sfizz/SIMDHelpers.h +++ b/src/sfizz/SIMDHelpers.h @@ -748,7 +748,7 @@ namespace _internals { int i = 0; for (; i < panSize; ++i) - pan[i] = std::cos(i * (piTwo / (panSize - 1))); + pan[i] = std::cos(i * (dPiTwo / (panSize - 1))); for (; i < static_cast(pan.size()); ++i) pan[i] = pan[panSize - 1]; diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index 8f75c25c..d74c8964 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -479,7 +479,7 @@ void sfz::Voice::fillWithGenerator(AudioSpan buffer) noexcept auto bends = tempSpan2.first(buffer.getNumFrames()); auto phases = tempSpan2.first(buffer.getNumFrames()); - const float step = baseFrequency * twoPi / sampleRate; + const float step = baseFrequency * fTwoPi / sampleRate; fill(jumps, step); if (region->bendStep > 1) @@ -496,8 +496,8 @@ void sfz::Voice::fillWithGenerator(AudioSpan buffer) noexcept copy(leftSpan, rightSpan); // Wrap the phase so we don't loose too much precision on longer notes - const auto numTwoPiWraps = static_cast(phase / twoPi); - phase -= twoPi * static_cast(numTwoPiWraps); + const auto numTwoPiWraps = static_cast(phase / fTwoPi); + phase -= fTwoPi * static_cast(numTwoPiWraps); } } From cc01fcfe4e4773a4d53886ea279bff0b2ecc7d24 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 13:50:30 +0100 Subject: [PATCH 10/49] use absl::make_unique --- src/sfizz/AudioBuffer.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sfizz/AudioBuffer.h b/src/sfizz/AudioBuffer.h index 3d376a0d..3bc919d0 100644 --- a/src/sfizz/AudioBuffer.h +++ b/src/sfizz/AudioBuffer.h @@ -10,7 +10,7 @@ #include "Debug.h" #include "LeakDetector.h" #include "absl/types/span.h" -#include +#include "absl/memory/memory.h" #include namespace sfz @@ -54,7 +54,7 @@ public: , numFrames(numFrames) { for (size_t i = 0; i < numChannels; ++i) - buffers[i] = std::make_unique(numFrames); + buffers[i] = absl::make_unique(numFrames); } /** @@ -170,7 +170,7 @@ public: void addChannel() { if (numChannels < MaxChannels) - buffers[numChannels++] = std::make_unique(numFrames); + buffers[numChannels++] = absl::make_unique(numFrames); } /** From 81ee0f00fd1034c2d2fe57f76d43f9957fd3ded6 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 13:50:41 +0100 Subject: [PATCH 11/49] make_unique and chrono literals --- src/sfizz/Synth.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 09d4e965..62c0efc6 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -13,12 +13,12 @@ #include "StringViewHelpers.h" #include "pugixml.hpp" #include "absl/algorithm/container.h" +#include "absl/memory/memory.h" #include "absl/strings/str_replace.h" #include #include #include #include -using namespace std::literals; sfz::Synth::Synth() : Synth(config::numVoices) @@ -38,7 +38,7 @@ sfz::Synth::~Synth() { AtomicDisabler callbackDisabler { canEnterCallback }; while (inCallback) { - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } for (auto& voice: voices) @@ -83,9 +83,9 @@ void sfz::Synth::callback(absl::string_view header, const std::vector& m void sfz::Synth::buildRegion(const std::vector& regionOpcodes) { - auto lastRegion = std::make_unique(resources.midiState, defaultPath); + auto lastRegion = absl::make_unique(resources.midiState, defaultPath); - auto parseOpcodes = [&](const auto& opcodes) { + auto parseOpcodes = [&](const std::vector& opcodes) { for (auto& opcode : opcodes) { const auto unknown = absl::c_find_if(unknownOpcodes, [&](absl::string_view sv) { return sv.compare(opcode.opcode) == 0; }); if (unknown != unknownOpcodes.end()) { @@ -112,7 +112,7 @@ void sfz::Synth::clear() { AtomicDisabler callbackDisabler { canEnterCallback }; while (inCallback) { - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } for (auto &voice: voices) @@ -279,7 +279,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& file) { AtomicDisabler callbackDisabler { canEnterCallback }; while (inCallback) { - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } clear(); @@ -452,7 +452,7 @@ void sfz::Synth::setSamplesPerBlock(int samplesPerBlock) noexcept AtomicDisabler callbackDisabler { canEnterCallback }; while (inCallback) { - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } this->samplesPerBlock = samplesPerBlock; @@ -471,7 +471,7 @@ void sfz::Synth::setSampleRate(float sampleRate) noexcept { AtomicDisabler callbackDisabler { canEnterCallback }; while (inCallback) { - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } this->sampleRate = sampleRate; @@ -851,12 +851,12 @@ void sfz::Synth::resetVoices(int numVoices) { AtomicDisabler callbackDisabler{ canEnterCallback }; while (inCallback) { - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } voices.clear(); for (int i = 0; i < numVoices; ++i) - voices.push_back(std::make_unique(resources)); + voices.push_back(absl::make_unique(resources)); for (auto& voice: voices) { voice->setSampleRate(this->sampleRate); @@ -871,7 +871,7 @@ void sfz::Synth::setOversamplingFactor(sfz::Oversampling factor) noexcept { AtomicDisabler callbackDisabler{ canEnterCallback }; while (inCallback) { - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } for (auto& voice: voices) @@ -891,7 +891,7 @@ void sfz::Synth::setPreloadSize(uint32_t preloadSize) noexcept { AtomicDisabler callbackDisabler{ canEnterCallback }; while (inCallback) { - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } resources.filePool.setPreloadSize(preloadSize); From 542bd28a283fe0c9886c16fd5c00b7cf63ccc2f6 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 14:12:46 +0100 Subject: [PATCH 12/49] Use @falktx's way for the math constants --- src/sfizz/MathHelpers.h | 29 +++++++++++++---------------- src/sfizz/SIMDHelpers.h | 2 +- src/sfizz/Voice.cpp | 6 +++--- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/sfizz/MathHelpers.h b/src/sfizz/MathHelpers.h index a8c97be6..ac755a11 100644 --- a/src/sfizz/MathHelpers.h +++ b/src/sfizz/MathHelpers.h @@ -124,9 +124,7 @@ inline float midiNoteFrequency(const int noteNumber) template constexpr T clamp( T v, T lo, T hi ) { - v = min(v, hi); - v = max(v, lo); - return v; + return max(min(v, hi), lo); } template @@ -148,19 +146,18 @@ constexpr ValueType linearInterpolation(ValueType left, ValueType right, ValueTy return left * leftCoeff + right * rightCoeff; } -constexpr double dPi { 3.141592653589793238462643383279502884}; -constexpr double dTwoPi { dPi * 2 }; -constexpr double dPiTwo { dPi / 2 }; -constexpr double dPiFour { dPi / 4 }; -constexpr double dSqrtTwo { 1.414213562373095048801688724209698078569671875376948073176 }; -constexpr double dSqrtTwoInv { 0.707106781186547524400844362104849039284835937688474036588 }; - -constexpr float fPi { 3.141592653589793238462643383279502884}; -constexpr float fTwoPi { fPi * 2 }; -constexpr float fPiTwo { fPi / 2 }; -constexpr float fPiFour { fPi / 4 }; -constexpr float fSqrtTwo { 1.414213562373095048801688724209698078569671875376948073176 }; -constexpr float fSqrtTwoInv { 0.707106781186547524400844362104849039284835937688474036588 }; +template +constexpr Type pi() { return static_cast(3.141592653589793238462643383279502884); }; +template +constexpr Type twoPi() { return pi() * 2; }; +template +constexpr Type piTwo() { return pi() / 2; }; +template +constexpr Type piFour() { return pi() / 4; }; +template +constexpr Type sqrtTwo() { return static_cast(1.414213562373095048801688724209698078569671875376948073176); }; +template +constexpr Type sqrtTwoInv() { return static_cast(0.707106781186547524400844362104849039284835937688474036588); }; /** @brief A fraction which is parameterized by integer type diff --git a/src/sfizz/SIMDHelpers.h b/src/sfizz/SIMDHelpers.h index 253c125a..00761dae 100644 --- a/src/sfizz/SIMDHelpers.h +++ b/src/sfizz/SIMDHelpers.h @@ -748,7 +748,7 @@ namespace _internals { int i = 0; for (; i < panSize; ++i) - pan[i] = std::cos(i * (dPiTwo / (panSize - 1))); + pan[i] = std::cos(i * (twoPi() / (panSize - 1))); for (; i < static_cast(pan.size()); ++i) pan[i] = pan[panSize - 1]; diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index d74c8964..f92ec40b 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -479,7 +479,7 @@ void sfz::Voice::fillWithGenerator(AudioSpan buffer) noexcept auto bends = tempSpan2.first(buffer.getNumFrames()); auto phases = tempSpan2.first(buffer.getNumFrames()); - const float step = baseFrequency * fTwoPi / sampleRate; + const float step = baseFrequency * twoPi() / sampleRate; fill(jumps, step); if (region->bendStep > 1) @@ -496,8 +496,8 @@ void sfz::Voice::fillWithGenerator(AudioSpan buffer) noexcept copy(leftSpan, rightSpan); // Wrap the phase so we don't loose too much precision on longer notes - const auto numTwoPiWraps = static_cast(phase / fTwoPi); - phase -= fTwoPi * static_cast(numTwoPiWraps); + const auto numTwoPiWraps = static_cast(phase / twoPi()); + phase -= twoPi() * static_cast(numTwoPiWraps); } } From 91495d29d406e7a5b3dd14ae3948a3eb798dcc22 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 14:19:11 +0100 Subject: [PATCH 13/49] Use verbose type_trait --- src/sfizz/AudioSpan.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sfizz/AudioSpan.h b/src/sfizz/AudioSpan.h index f1bd0f91..e11e2ebb 100644 --- a/src/sfizz/AudioSpan.h +++ b/src/sfizz/AudioSpan.h @@ -148,7 +148,7 @@ public: * @tparam Alignment the alignment block size for the platform * @param audioBuffer the source AudioBuffer. */ - template , typename = std::enable_if_t::value, int>> + template ::type, typename = typename std::enable_if::value, int>::type> AudioSpan(AudioBuffer& audioBuffer) : numFrames(audioBuffer.getNumFrames()) , numChannels(audioBuffer.getNumChannels()) From d70268e1d80ff475168aa2a236aaeb4e6139b36b Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 14:19:20 +0100 Subject: [PATCH 14/49] Can't use auto return values --- src/sfizz/FilePool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sfizz/FilePool.h b/src/sfizz/FilePool.h index cba35cb7..84b68687 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -52,7 +52,7 @@ struct PreloadedFileHandle struct FilePromise { - auto getData() + AudioSpan getData() { if (dataReady) return AudioSpan(fileData); From c919cc9c90c6a47315888a9fbe3796290f807dd6 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 14:19:32 +0100 Subject: [PATCH 15/49] Can't use auto in lambda params --- src/sfizz/Synth.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 62c0efc6..06b075af 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -260,7 +260,7 @@ void sfz::Synth::handleEffectOpcodes(const std::vector& members) void addEndpointsToVelocityCurve(sfz::Region& region) { if (region.velocityPoints.size() > 0) { - absl::c_sort(region.velocityPoints, [](auto& lhs, auto& rhs) { return lhs.first < rhs.first; }); + absl::c_sort(region.velocityPoints, [](const std::pair& lhs, const std::pair& rhs) { return lhs.first < rhs.first; }); if (region.ampVeltrack > 0) { if (region.velocityPoints.back().first != sfz::Default::velocityRange.getEnd()) region.velocityPoints.push_back(std::make_pair(127, 1.0f)); @@ -409,7 +409,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& file) sfz::Voice* sfz::Synth::findFreeVoice() noexcept { - auto freeVoice = absl::c_find_if(voices, [](const auto& voice) { return voice->isFree(); }); + auto freeVoice = absl::c_find_if(voices, [](const std::unique_ptr& voice) { return voice->isFree(); }); if (freeVoice != voices.end()) return freeVoice->get(); @@ -418,7 +418,7 @@ sfz::Voice* sfz::Synth::findFreeVoice() noexcept for (auto& voice : voices) if (voice->canBeStolen()) voiceViewArray.push_back(voice.get()); - absl::c_sort(voiceViewArray, [](const auto& lhs, const auto& rhs) { return lhs->getSourcePosition() > rhs->getSourcePosition(); }); + absl::c_sort(voiceViewArray, [](Voice* lhs, Voice* rhs) { return lhs->getSourcePosition() > rhs->getSourcePosition(); }); for (auto* voice : voiceViewArray) { if (voice->getMeanSquaredAverage() < config::voiceStealingThreshold) { From a31ded07977e2229ceec22b326b4b82cb3802851 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 14:30:27 +0100 Subject: [PATCH 16/49] Tentative atomic_queue patch --- src/external/atomic_queue/atomic_queue.h | 33 +++++++++++------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/external/atomic_queue/atomic_queue.h b/src/external/atomic_queue/atomic_queue.h index 19fdb40d..bcbd29a9 100644 --- a/src/external/atomic_queue/atomic_queue.h +++ b/src/external/atomic_queue/atomic_queue.h @@ -95,27 +95,24 @@ constexpr T& map(T* elements, unsigned index) noexcept { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +template +constexpr T decrement(T x) { return x - 1; } +template +constexpr T increment(T x) { return x + 1; } +template +constexpr T or_equal(T x, unsigned u) { return (x | x >> u); } +template +constexpr T or_equal(T x, unsigned u, Args... rest) +{ + return or_equal(or_equal(x, u), rest...); +} + constexpr uint32_t round_up_to_power_of_2(uint32_t a) noexcept { - --a; - a |= a >> 1; - a |= a >> 2; - a |= a >> 4; - a |= a >> 8; - a |= a >> 16; - ++a; - return a; + return increment(or_equal(decrement(a), 1, 2, 4, 8, 16)); } constexpr uint64_t round_up_to_power_of_2(uint64_t a) noexcept { - --a; - a |= a >> 1; - a |= a >> 2; - a |= a >> 4; - a |= a >> 8; - a |= a >> 16; - a |= a >> 32; - ++a; - return a; + return increment(or_equal(decrement(a), 1, 2, 4, 8, 16, 32)); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -304,7 +301,7 @@ public: static_cast(*this).do_push(std::forward(element), head); } - auto pop() noexcept { + Derived& pop() noexcept { unsigned tail; if(Derived::spsc_) { tail = tail_.load(X); From a1606d951bf62eb3931be451ce7d4dce00322f57 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Tue, 10 Mar 2020 15:54:46 +0100 Subject: [PATCH 17/49] Comment in CMake for CXX STANDARD Co-Authored-By: JP Cimalando --- cmake/SfizzConfig.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/SfizzConfig.cmake b/cmake/SfizzConfig.cmake index 31af5c4b..52a2a587 100644 --- a/cmake/SfizzConfig.cmake +++ b/cmake/SfizzConfig.cmake @@ -1,4 +1,4 @@ -# Do not override the C++ standard if set to more than 14 +# Do not override the C++ standard if set to more than 11 if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 11) set(CMAKE_CXX_STANDARD 11) endif() From e158e9e381cc8935ec7e92db4a01248975326984 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 15:56:05 +0100 Subject: [PATCH 18/49] multiplyByCents is inline --- src/sfizz/SfzHelpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sfizz/SfzHelpers.h b/src/sfizz/SfzHelpers.h index 5ccf8363..bbf89ae6 100644 --- a/src/sfizz/SfzHelpers.h +++ b/src/sfizz/SfzHelpers.h @@ -241,7 +241,7 @@ constexpr void addToBase(T& base, T modifier) * @param base * @param modifier */ -void multiplyByCents(float& base, int modifier) +inline void multiplyByCents(float& base, int modifier) { base *= centsFactor(modifier); } From 89c26f462f2da30c979d614fc7e6a832d8cb30af Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 15:56:56 +0100 Subject: [PATCH 19/49] Corrected an error introduced in dce954 --- src/sfizz/SIMDHelpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sfizz/SIMDHelpers.h b/src/sfizz/SIMDHelpers.h index 00761dae..e8134809 100644 --- a/src/sfizz/SIMDHelpers.h +++ b/src/sfizz/SIMDHelpers.h @@ -748,7 +748,7 @@ namespace _internals { int i = 0; for (; i < panSize; ++i) - pan[i] = std::cos(i * (twoPi() / (panSize - 1))); + pan[i] = std::cos(i * (piTwo() / (panSize - 1))); for (; i < static_cast(pan.size()); ++i) pan[i] = pan[panSize - 1]; From de189371f5566147ce454dca2dd6c7c13d8ccc80 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 17:51:54 +0100 Subject: [PATCH 20/49] Force C99 (@falktx) --- lv2/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lv2/CMakeLists.txt b/lv2/CMakeLists.txt index aa732cb4..240298fe 100644 --- a/lv2/CMakeLists.txt +++ b/lv2/CMakeLists.txt @@ -3,6 +3,9 @@ set (LV2PLUGIN_PRJ_NAME "${PROJECT_NAME}_lv2") # Set the build directory as /lv2/.lv2/ set (PROJECT_BINARY_DIR "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.lv2") +# C99 or higher is needed +set(CMAKE_C_STANDARD 99) + # LV2 plugin specific settings include (LV2Config) From 2daf53ab6c42cff9a3168c312744b091947f40bf Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 17:52:41 +0100 Subject: [PATCH 21/49] chrono literals --- src/sfizz/EQPool.cpp | 3 +-- src/sfizz/Effects.cpp | 8 ++++---- src/sfizz/FilterPool.cpp | 3 +-- src/sfizz/Logger.cpp | 4 +--- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/sfizz/EQPool.cpp b/src/sfizz/EQPool.cpp index dca5ad1c..da8c9c2b 100644 --- a/src/sfizz/EQPool.cpp +++ b/src/sfizz/EQPool.cpp @@ -3,7 +3,6 @@ #include #include "absl/algorithm/container.h" #include "SIMDHelpers.h" -using namespace std::chrono_literals; sfz::EQHolder::EQHolder(const MidiState& state) :midiState(state) @@ -114,7 +113,7 @@ size_t sfz::EQPool::setnumEQs(size_t numEQs) AtomicDisabler disabler { canGiveOutEQs }; while(givingOutEQs) - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); auto eqIterator = eqs.begin(); auto eqSentinel = eqs.rbegin(); diff --git a/src/sfizz/Effects.cpp b/src/sfizz/Effects.cpp index 71494d1d..7031582f 100644 --- a/src/sfizz/Effects.cpp +++ b/src/sfizz/Effects.cpp @@ -44,21 +44,21 @@ std::unique_ptr EffectFactory::makeEffect(absl::Span membe if (!opcode) { DBG("The effect does not specify a type"); - return std::make_unique(); + return absl::make_unique(); } const absl::string_view type = opcode->value; - const auto it = absl::c_find_if(_entries, [&](auto&& entry) { return entry.name == type; }); + const auto it = absl::c_find_if(_entries, [&](const FactoryEntry& entry) { return entry.name == type; }); if (it == _entries.end()) { DBG("Unsupported effect type: " << type); - return std::make_unique(); + return absl::make_unique(); } auto fx = it->make(members); if (!fx) { DBG("Could not instantiate effect of type: " << type); - return std::make_unique(); + return absl::make_unique(); } return fx; diff --git a/src/sfizz/FilterPool.cpp b/src/sfizz/FilterPool.cpp index 0f87104e..3be79d7f 100644 --- a/src/sfizz/FilterPool.cpp +++ b/src/sfizz/FilterPool.cpp @@ -4,7 +4,6 @@ #include "AtomicGuard.h" #include #include -using namespace std::chrono_literals; sfz::FilterHolder::FilterHolder(const MidiState& midiState) : midiState(midiState) @@ -113,7 +112,7 @@ size_t sfz::FilterPool::setNumFilters(size_t numFilters) AtomicDisabler disabler { canGiveOutFilters }; while(givingOutFilters) - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); auto filterIterator = filters.begin(); auto filterSentinel = filters.rbegin(); diff --git a/src/sfizz/Logger.cpp b/src/sfizz/Logger.cpp index 15b7fa86..fa1defd7 100644 --- a/src/sfizz/Logger.cpp +++ b/src/sfizz/Logger.cpp @@ -13,8 +13,6 @@ #include #include -using namespace std::chrono_literals; - template void printStatistics(std::vector& data) { @@ -141,7 +139,7 @@ void sfz::Logger::moveEvents() noexcept callbackTimes.clear(); } - std::this_thread::sleep_for(10ms); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } From bc8d2b61b879d979da2d22d221ca7d5e403e6d66 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 17:53:54 +0100 Subject: [PATCH 22/49] chrono literals and changes file handles to enable aggregate initialization --- src/sfizz/FilePool.cpp | 27 +++++++++++++-------------- src/sfizz/FilePool.h | 7 ++++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index a716d32b..f240d3dd 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -32,10 +32,10 @@ #include "AtomicGuard.h" #include "absl/types/span.h" #include "absl/strings/match.h" +#include "absl/memory/memory.h" #include #include #include -using namespace std::chrono_literals; template void readBaseFile(SndfileHandle& sndFile, sfz::AudioBuffer& output, uint32_t numFrames) @@ -57,13 +57,13 @@ void readBaseFile(SndfileHandle& sndFile, sfz::AudioBuffer& output, uint32_t template std::unique_ptr> readFromFile(SndfileHandle& sndFile, uint32_t numFrames, sfz::Oversampling factor) { - auto baseBuffer = std::make_unique>(); + auto baseBuffer = absl::make_unique>(); readBaseFile(sndFile, *baseBuffer, numFrames); if (factor == sfz::Oversampling::x1) return baseBuffer; - auto outputBuffer = std::make_unique>(sndFile.channels(), numFrames * static_cast(factor)); + auto outputBuffer = absl::make_unique>(sndFile.channels(), numFrames * static_cast(factor)); sfz::Oversampler oversampler { factor }; oversampler.stream(*baseBuffer, *outputBuffer); return outputBuffer; @@ -216,10 +216,9 @@ bool sfz::FilePool::preloadFile(const std::string& filename, uint32_t maxOffset) preloadedFiles[filename].preloadedData = readFromFile(sndFile, framesToLoad, oversamplingFactor); } } else { - preloadedFiles.insert_or_assign(filename, { - readFromFile(sndFile, framesToLoad, oversamplingFactor), - static_cast(oversamplingFactor) * static_cast(sndFile.samplerate()) - }); + const float sourceSampleRate { static_cast(oversamplingFactor) * static_cast(sndFile.samplerate()) }; + PreloadedFileHandle handle { readFromFile(sndFile, framesToLoad, oversamplingFactor), sourceSampleRate }; + preloadedFiles.insert_or_assign(filename, handle); } return true; @@ -272,7 +271,7 @@ void sfz::FilePool::tryToClearPromises() AtomicDisabler disabler { canAddPromisesToClear }; while (addingPromisesToClear) - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); for (auto& promise: promisesToClear) { if (promise->dataReady) @@ -284,7 +283,7 @@ void sfz::FilePool::clearingThread() { while (!quitThread) { tryToClearPromises(); - std::this_thread::sleep_for(50ms); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); } } @@ -302,7 +301,7 @@ void sfz::FilePool::loadingThread() noexcept } if (!promiseQueue.try_pop(promise)) { - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); continue; } @@ -326,7 +325,7 @@ void sfz::FilePool::loadingThread() noexcept while (!filledPromiseQueue.try_push(promise)) { DBG("[sfizz] Error enqueuing the promise for " << promise->filename << " in the filledPromiseQueue"); - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } promise.reset(); @@ -412,7 +411,7 @@ void sfz::FilePool::emptyFileLoadingQueues() noexcept { emptyQueue = true; while (emptyQueue) - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::microseconds(100)); } void sfz::FilePool::waitForBackgroundLoading() noexcept @@ -421,11 +420,11 @@ void sfz::FilePool::waitForBackgroundLoading() noexcept // of the files we need to load still. // Spinlocking on the size of the background queue while (!promiseQueue.was_empty()){ - std::this_thread::sleep_for(0.1ms); + std::this_thread::sleep_for(std::chrono::microseconds(100)); } // Spinlocking on the threads possibly logging in the background while (threadsLoading > 0) { - std::this_thread::sleep_for(0.1ms); + std::this_thread::sleep_for(std::chrono::microseconds(100)); } } diff --git a/src/sfizz/FilePool.h b/src/sfizz/FilePool.h index 84b68687..c75e6c75 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -44,10 +44,11 @@ namespace sfz { using AudioBufferPtr = std::shared_ptr>; +// Strict C++11 disallows member initialization if aggregate initialization is to be used... struct PreloadedFileHandle { - std::shared_ptr> preloadedData {}; - float sampleRate { config::defaultSampleRate }; + std::shared_ptr> preloadedData; + float sampleRate; }; struct FilePromise @@ -78,7 +79,7 @@ struct FilePromise AudioBuffer fileData {}; float sampleRate { config::defaultSampleRate }; Oversampling oversamplingFactor { config::defaultOversamplingFactor }; - std::atomic_size_t availableFrames { 0 }; + std::atomic availableFrames { 0 }; std::atomic dataReady { false }; std::chrono::time_point creationTime; From 624f014dec5b627a22ae948d5b921775aea5d5fc Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 17:54:28 +0100 Subject: [PATCH 23/49] absl's type traits --- src/sfizz/Opcode.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sfizz/Opcode.h b/src/sfizz/Opcode.h index 7edbe9ac..c510f5a8 100644 --- a/src/sfizz/Opcode.h +++ b/src/sfizz/Opcode.h @@ -11,6 +11,7 @@ #include "SfzHelpers.h" #include "StringViewHelpers.h" #include +#include "absl/meta/type_traits.h" #include #include #include @@ -45,7 +46,7 @@ struct Opcode { * @param validRange the range of admitted values * @return absl::optional the cast value, or null */ -template ::value, int>::type = 0> +template ::value, int> = 0> inline absl::optional readOpcode(absl::string_view value, const Range& validRange) { int64_t returnedValue; @@ -74,7 +75,7 @@ inline absl::optional readOpcode(absl::string_view value, const Range * @param validRange the range of admitted values * @return absl::optional the cast value, or null */ -template ::value, int>::type = 0> +template ::value, int> = 0> inline absl::optional readOpcode(absl::string_view value, const Range& validRange) { float returnedValue; From 2d74e0c77658870249249eefbb2f1d4e5d6b7fec Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 17:55:22 +0100 Subject: [PATCH 24/49] absl's make unique --- src/sfizz/effects/Lofi.cpp | 6 +++--- src/sfizz/sfizz.cpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sfizz/effects/Lofi.cpp b/src/sfizz/effects/Lofi.cpp index 60b66949..f29d9950 100644 --- a/src/sfizz/effects/Lofi.cpp +++ b/src/sfizz/effects/Lofi.cpp @@ -37,7 +37,7 @@ #include "Lofi.h" #include "Opcode.h" -#include +#include "absl/memory/memory.h" #include #include #include @@ -79,7 +79,7 @@ namespace fx { std::unique_ptr Lofi::makeInstance(absl::Span members) { - auto fx = std::make_unique(); + auto fx = absl::make_unique(); for (const Opcode& opcode : members) { switch (opcode.lettersOnlyHash) { @@ -92,7 +92,7 @@ namespace fx { } } - return fx; + return std::move(fx); } /// diff --git a/src/sfizz/sfizz.cpp b/src/sfizz/sfizz.cpp index 9115f318..61e5a0c5 100644 --- a/src/sfizz/sfizz.cpp +++ b/src/sfizz/sfizz.cpp @@ -6,10 +6,11 @@ #include "Synth.h" #include "sfizz.hpp" +#include "absl/memory/memory.h" sfz::Sfizz::Sfizz() { - synth = std::make_unique(); + synth = absl::make_unique(); } sfz::Sfizz::~Sfizz() From 0814d67337e297f39d09afbe22e1071bb7a758f9 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 17:55:58 +0100 Subject: [PATCH 25/49] Don't initialize member arrays --- src/sfizz/MidiState.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sfizz/MidiState.h b/src/sfizz/MidiState.h index b629c88a..badb0e17 100644 --- a/src/sfizz/MidiState.h +++ b/src/sfizz/MidiState.h @@ -134,13 +134,13 @@ private: * @brief Stores the note on times. * */ - MidiNoteArray noteOnTimes { }; + MidiNoteArray noteOnTimes; /** * @brief Stores the velocity of the note ons for currently * depressed notes. * */ - MidiNoteArray lastNoteVelocities { }; + MidiNoteArray lastNoteVelocities; /** * @brief Current known values for the CCs. * From f405e2c23fd7e8f4c29b1d8c825e5b9480367574 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 17:56:07 +0100 Subject: [PATCH 26/49] auto and braces --- src/sfizz/Oversampler.cpp | 2 +- src/sfizz/Synth.cpp | 4 ++-- src/sfizz/Voice.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sfizz/Oversampler.cpp b/src/sfizz/Oversampler.cpp index b2b986ae..2a98fc0b 100644 --- a/src/sfizz/Oversampler.cpp +++ b/src/sfizz/Oversampler.cpp @@ -105,7 +105,7 @@ void sfz::Oversampler::stream(const sfz::AudioBuffer& input, sfz::AudioBu { // std::cout << "Input frames: " << inputFrameCounter << "/" << numFrames << '\n'; const auto thisChunkSize = std::min(chunkSize, numFrames - inputFrameCounter); - const auto outputChunkSize { thisChunkSize * static_cast(factor) }; + const auto outputChunkSize = thisChunkSize * static_cast(factor); for (size_t chanIdx = 0; chanIdx < numChannels; chanIdx++) { const auto inputChunk = input.getSpan(chanIdx).subspan(inputFrameCounter, thisChunkSize); const auto outputChunk = output.getSpan(chanIdx).subspan(outputFrameCounter, outputChunkSize); diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 06b075af..e2c7ea0f 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -342,7 +342,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& file) region->isStereo = true; // TODO: adjust with LFO targets - const auto maxOffset { region->offset + region->offsetRandom }; + const auto maxOffset = region->offset + region->offsetRandom; if (!resources.filePool.preloadFile(region->sample, maxOffset)) removeCurrentRegion(); } @@ -432,7 +432,7 @@ sfz::Voice* sfz::Synth::findFreeVoice() noexcept int sfz::Synth::getNumActiveVoices() const noexcept { - auto activeVoices { 0 }; + auto activeVoices = 0; for (const auto& voice : voices) { if (!voice->isFree()) activeVoices++; diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index f92ec40b..149003c5 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -45,7 +45,7 @@ void sfz::Voice::startVoice(Region* region, int delay, int number, uint8_t value pitchRatio = region->getBasePitchVariation(number, value); baseVolumedB = region->getBaseVolumedB(number); - auto volumedB { baseVolumedB }; + auto volumedB = baseVolumedB; if (region->volumeCC) volumedB += normalizeCC(resources.midiState.getCCValue(region->volumeCC->cc)) * region->volumeCC->value; volumeEnvelope.reset(db2mag(Default::volumeRange.clamp(volumedB))); @@ -63,19 +63,19 @@ void sfz::Voice::startVoice(Region* region, int delay, int number, uint8_t value crossfadeEnvelope.reset(Default::normalizedRange.clamp(crossfadeGain)); basePan = normalizePercents(region->pan); - auto pan { basePan }; + auto pan = basePan; if (region->panCC) pan += normalizeCC(resources.midiState.getCCValue(region->panCC->cc)) * normalizePercents(region->panCC->value); panEnvelope.reset(Default::symmetricNormalizedRange.clamp(pan)); basePosition = normalizePercents(region->position); - auto position { basePosition }; + auto position = basePosition; if (region->positionCC) position += normalizeCC(resources.midiState.getCCValue(region->positionCC->cc)) * normalizePercents(region->positionCC->value); positionEnvelope.reset(Default::symmetricNormalizedRange.clamp(position)); baseWidth = normalizePercents(region->width); - auto width { baseWidth }; + auto width = baseWidth; if (region->widthCC) width += normalizeCC(resources.midiState.getCCValue(region->widthCC->cc)) * normalizePercents(region->widthCC->value); widthEnvelope.reset(Default::symmetricNormalizedRange.clamp(width)); From 70743900b518724d3d520ca4f4867ae98c36faa7 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 17:56:34 +0100 Subject: [PATCH 27/49] auto in lambdas --- src/sfizz/ADSREnvelope.cpp | 2 +- src/sfizz/EventEnvelopes.cpp | 2 +- src/sfizz/Region.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sfizz/ADSREnvelope.cpp b/src/sfizz/ADSREnvelope.cpp index e795d53f..edc708aa 100644 --- a/src/sfizz/ADSREnvelope.cpp +++ b/src/sfizz/ADSREnvelope.cpp @@ -14,7 +14,7 @@ namespace sfz { template void ADSREnvelope::reset(const Region& region, const MidiState& state, int delay, uint8_t velocity, float sampleRate) noexcept { - auto secondsToSamples = [sampleRate](auto timeInSeconds) { + auto secondsToSamples = [sampleRate](Type timeInSeconds) { return static_cast(timeInSeconds * sampleRate); }; diff --git a/src/sfizz/EventEnvelopes.cpp b/src/sfizz/EventEnvelopes.cpp index e42abcd0..c64a5415 100644 --- a/src/sfizz/EventEnvelopes.cpp +++ b/src/sfizz/EventEnvelopes.cpp @@ -53,7 +53,7 @@ void EventEnvelope::prepareEvents(int blockLength) if (resetEvents) clear(); - absl::c_stable_sort(events, [](const auto& lhs, const auto& rhs) { + absl::c_stable_sort(events, [](const std::pair& lhs, const std::pair& rhs) { return lhs.first < rhs.first; }); diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 8dc962b4..7daa4f63 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -1011,7 +1011,7 @@ float sfz::Region::velocityCurve(uint8_t velocity) const noexcept float gain { 1.0f }; if (velocityPoints.size() > 0) { // Custom velocity curve - auto after = std::find_if(velocityPoints.begin(), velocityPoints.end(), [velocity](auto& val) { return val.first >= velocity; }); + auto after = std::find_if(velocityPoints.begin(), velocityPoints.end(), [velocity](const std::pair& val) { return val.first >= velocity; }); auto before = after == velocityPoints.begin() ? velocityPoints.begin() : after - 1; // Linear interpolation float relativePositionInSegment { From 543c6389269a9eccd8a30866aaf1a8530c684671 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 17:56:27 +0100 Subject: [PATCH 28/49] constexpr variables --- src/sfizz/OnePoleFilter.h | 2 +- src/sfizz/SIMDSSE.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sfizz/OnePoleFilter.h b/src/sfizz/OnePoleFilter.h index 46791ef4..99ddc754 100644 --- a/src/sfizz/OnePoleFilter.h +++ b/src/sfizz/OnePoleFilter.h @@ -26,7 +26,7 @@ public: template static Type normalizedGain(Type cutoff, C sampleRate) { - return std::tan(cutoff / static_cast(sampleRate) * fPi); + return std::tan(cutoff / static_cast(sampleRate) * pi()); } OnePoleFilter(Type gain) diff --git a/src/sfizz/SIMDSSE.cpp b/src/sfizz/SIMDSSE.cpp index 74adfb66..bec05f09 100644 --- a/src/sfizz/SIMDSSE.cpp +++ b/src/sfizz/SIMDSSE.cpp @@ -623,7 +623,7 @@ void sfz::pan(absl::Span panEnvelope, absl::Span); + const auto mmPiFour = _mm_set_ps1(piFour()); __m128 mmCos; __m128 mmSin; while (pan < lastAligned) { @@ -660,7 +660,7 @@ void sfz::width(absl::Span widthEnvelope, absl::Span); + const auto mmPiFour = _mm_set_ps1(piFour()); __m128 mmCos; __m128 mmSin; while (width < lastAligned) { From 29aa23196073bbd14ec911e4c25bb567f7b8eda0 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 18:02:00 +0100 Subject: [PATCH 29/49] Updated tests --- tests/AudioBufferT.cpp | 4 ++-- tests/BufferT.cpp | 10 +++++----- tests/EventEnvelopesT.cpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/AudioBufferT.cpp b/tests/AudioBufferT.cpp index bdd40671..ff483b13 100644 --- a/tests/AudioBufferT.cpp +++ b/tests/AudioBufferT.cpp @@ -64,8 +64,8 @@ TEST_CASE("[AudioBuffer] Iterators") std::fill(buffer.channelWriter(0), buffer.channelWriterEnd(0), fillValue); std::fill(buffer.channelWriter(1), buffer.channelWriterEnd(1), fillValue); - REQUIRE(std::all_of(buffer.channelReader(0), buffer.channelReaderEnd(0), [fillValue](auto value) { return value == fillValue; })); - REQUIRE(std::all_of(buffer.channelReader(1), buffer.channelReaderEnd(1), [fillValue](auto value) { return value == fillValue; })); + REQUIRE(std::all_of(buffer.channelReader(0), buffer.channelReaderEnd(0), [fillValue](float value) { return value == fillValue; })); + REQUIRE(std::all_of(buffer.channelReader(1), buffer.channelReaderEnd(1), [fillValue](float value) { return value == fillValue; })); } TEST_CASE("[AudioSpan] Constructions") diff --git a/tests/BufferT.cpp b/tests/BufferT.cpp index de98f482..04e38724 100644 --- a/tests/BufferT.cpp +++ b/tests/BufferT.cpp @@ -73,7 +73,7 @@ TEST_CASE("[Buffer] Resize 10 floats ") REQUIRE(buffer.resize(smallSize)); checkBoundaries(buffer, smallSize); - REQUIRE(std::all_of(buffer.begin(), buffer.end(), [](auto value) { return value == 1.0f; })); + REQUIRE(std::all_of(buffer.begin(), buffer.end(), [](float value) { return value == 1.0f; })); REQUIRE(buffer.resize(bigSize)); checkBoundaries(buffer, bigSize); @@ -95,7 +95,7 @@ TEST_CASE("[Buffer] Resize 4096 floats ") REQUIRE(buffer.resize(smallSize)); checkBoundaries(buffer, smallSize); - REQUIRE(std::all_of(buffer.begin(), buffer.end(), [](auto value) { return value == 1.0f; })); + REQUIRE(std::all_of(buffer.begin(), buffer.end(), [](float value) { return value == 1.0f; })); REQUIRE(buffer.resize(bigSize)); checkBoundaries(buffer, bigSize); @@ -117,7 +117,7 @@ TEST_CASE("[Buffer] Resize 65536 floats ") REQUIRE(buffer.resize(smallSize)); checkBoundaries(buffer, smallSize); - REQUIRE(std::all_of(buffer.begin(), buffer.end(), [](auto value) { return value == 1.0f; })); + REQUIRE(std::all_of(buffer.begin(), buffer.end(), [](float value) { return value == 1.0f; })); REQUIRE(buffer.resize(bigSize)); checkBoundaries(buffer, bigSize); @@ -134,11 +134,11 @@ TEST_CASE("[Buffer] Copy and move") std::fill(copied.begin(), copied.end(), 2.0f); copied = buffer; checkBoundaries(copied, baseSize); - REQUIRE(std::all_of(copied.begin(), copied.end(), [](auto value) { return value == 1.0f; })); + REQUIRE(std::all_of(copied.begin(), copied.end(), [](float value) { return value == 1.0f; })); sfz::Buffer copyConstructed { buffer }; checkBoundaries(copyConstructed, baseSize); - REQUIRE(std::all_of(copyConstructed.begin(), copyConstructed.end(), [](auto value) { return value == 1.0f; })); + REQUIRE(std::all_of(copyConstructed.begin(), copyConstructed.end(), [](float value) { return value == 1.0f; })); // sfz::Buffer moveConstructed { std::move(buffer) }; // REQUIRE(buffer.empty()); diff --git a/tests/EventEnvelopesT.cpp b/tests/EventEnvelopesT.cpp index 07218423..936f6dbf 100644 --- a/tests/EventEnvelopesT.cpp +++ b/tests/EventEnvelopesT.cpp @@ -134,7 +134,7 @@ TEST_CASE("[LinearEnvelope] 2 events, with another block call") TEST_CASE("[LinearEnvelope] 2 events, function") { sfz::LinearEnvelope envelope; - envelope.setFunction([](auto x) { return 2 * x; }); + envelope.setFunction([](float x) { return 2 * x; }); envelope.registerEvent(2, 1.0f); envelope.registerEvent(6, 2.0f); std::array output; From d1706c4df44de6f2a26a49ec3dee2f7c202fde02 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Tue, 10 Mar 2020 18:50:31 +0100 Subject: [PATCH 30/49] chrono literals --- clients/jack_client.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clients/jack_client.cpp b/clients/jack_client.cpp index a07776c4..7aee82d2 100644 --- a/clients/jack_client.cpp +++ b/clients/jack_client.cpp @@ -37,7 +37,6 @@ #include #include #include -using namespace std::literals; static jack_port_t* midiInputPort; static jack_port_t* outputPort1; @@ -290,7 +289,7 @@ int main(int argc, char** argv) std::cout << "Allocated buffers: " << synth.getAllocatedBuffers() << '\n'; std::cout << "Total size: " << synth.getAllocatedBytes() << '\n'; #endif - std::this_thread::sleep_for(2s); + std::this_thread::sleep_for(std::chrono::seconds(2)); } std::cout << "Closing..." << '\n'; From 0b90ab722fb264ff279a865e51867ea5c5f432c6 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 11 Mar 2020 00:00:52 +0100 Subject: [PATCH 31/49] Fallthroughs --- src/sfizz/ADSREnvelope.cpp | 22 +++++++------- src/sfizz/Oversampler.cpp | 4 +-- src/sfizz/Region.cpp | 62 +++++++++++++++++++------------------- src/sfizz/Synth.cpp | 6 ++-- 4 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/sfizz/ADSREnvelope.cpp b/src/sfizz/ADSREnvelope.cpp index edc708aa..96333be2 100644 --- a/src/sfizz/ADSREnvelope.cpp +++ b/src/sfizz/ADSREnvelope.cpp @@ -54,7 +54,7 @@ Type ADSREnvelope::getNextValue() noexcept currentState = State::Attack; step = (peak - currentValue) / (attack > 0 ? attack : 1); - [[fallthrough]]; + // fallthrough case State::Attack: if (attack-- > 0) { currentValue += step; @@ -63,14 +63,14 @@ Type ADSREnvelope::getNextValue() noexcept currentState = State::Hold; currentValue = peak; - [[fallthrough]]; + // fallthrough case State::Hold: if (hold-- > 0) return currentValue; step = std::exp(std::log(sustain + config::virtuallyZero) / (decay > 0 ? decay : 1)); currentState = State::Decay; - [[fallthrough]]; + // fallthrough case State::Decay: if (decay-- > 0) { currentValue *= step; @@ -79,7 +79,7 @@ Type ADSREnvelope::getNextValue() noexcept currentState = State::Sustain; currentValue = sustain; - [[fallthrough]]; + // fallthrough case State::Sustain: if (freeRunning) shouldRelease = true; @@ -92,7 +92,7 @@ Type ADSREnvelope::getNextValue() noexcept currentState = State::Done; currentValue = 0.0; - [[fallthrough]]; + // fallthrough default: return 0.0; } @@ -116,7 +116,7 @@ void ADSREnvelope::getBlock(absl::Span output) noexcept currentState = State::Attack; step = (peak - start) / (attack > 0 ? attack : 1); - [[fallthrough]]; + // fallthrough case State::Attack: length = min(remainingSamples, attack); currentValue = linearRamp(output, currentValue, step); @@ -128,7 +128,7 @@ void ADSREnvelope::getBlock(absl::Span output) noexcept currentValue = peak; currentState = State::Hold; - [[fallthrough]]; + // fallthrough case State::Hold: length = min(remainingSamples, hold); fill(output, currentValue); @@ -140,7 +140,7 @@ void ADSREnvelope::getBlock(absl::Span output) noexcept step = std::exp(std::log(sustain + config::virtuallyZero) / (decay > 0 ? decay : 1)); currentState = State::Decay; - [[fallthrough]]; + // fallthrough case State::Decay: length = min(remainingSamples, decay); currentValue = multiplicativeRamp(output, currentValue, step); @@ -152,7 +152,7 @@ void ADSREnvelope::getBlock(absl::Span output) noexcept currentValue = sustain; currentState = State::Sustain; - [[fallthrough]]; + // fallthrough case State::Sustain: if (freeRunning) shouldRelease = true; @@ -168,9 +168,9 @@ void ADSREnvelope::getBlock(absl::Span output) noexcept currentValue = 0.0; currentState = State::Done; - [[fallthrough]]; + // fallthrough case State::Done: - [[fallthrough]]; + // fallthrough default: break; } diff --git a/src/sfizz/Oversampler.cpp b/src/sfizz/Oversampler.cpp index 2a98fc0b..422e5250 100644 --- a/src/sfizz/Oversampler.cpp +++ b/src/sfizz/Oversampler.cpp @@ -78,11 +78,11 @@ void sfz::Oversampler::stream(const sfz::AudioBuffer& input, sfz::AudioBu case Oversampling::x8: for (auto& upsampler: upsampler8x) upsampler.set_coefs(coeffsStage8x.data()); - [[fallthrough]]; + // fallthrough case Oversampling::x4: for (auto& upsampler: upsampler4x) upsampler.set_coefs(coeffsStage4x.data()); - [[fallthrough]]; + // fallthrough case Oversampling::x2: for (auto& upsampler: upsampler2x) upsampler.set_coefs(coeffsStage2x.data()); diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 7daa4f63..d9651eca 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -66,7 +66,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) case hash("count"): setValueFromOpcode(opcode, sampleCount, Default::sampleCountRange); break; - case hash("loopmode"): [[fallthrough]]; + case hash("loopmode"): // fallthrough case hash("loop_mode"): switch (hash(opcode.value)) { case hash("no_loop"): @@ -85,21 +85,21 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) DBG("Unkown loop mode:" << std::string(opcode.value)); } break; - case hash("loopend"): [[fallthrough]]; + case hash("loopend"): // fallthrough case hash("loop_end"): setRangeEndFromOpcode(opcode, loopRange, Default::loopRange); break; - case hash("loopstart"): [[fallthrough]]; + case hash("loopstart"): // fallthrough case hash("loop_start"): setRangeStartFromOpcode(opcode, loopRange, Default::loopRange); break; // Instrument settings: voice lifecycle - case hash("group"): [[fallthrough]]; + case hash("group"): // fallthrough case hash("polyphony_group"): setValueFromOpcode(opcode, group, Default::groupRange); break; - case hash("offby"): [[fallthrough]]; + case hash("offby"): // fallthrough case hash("off_by"): setValueFromOpcode(opcode, offBy, Default::groupRange); break; @@ -237,11 +237,11 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) DBG("Unknown trigger mode: " << std::string(opcode.value)); } break; - case hash("on_locc&"): [[fallthrough]]; + case hash("on_locc&"): // fallthrough case hash("start_locc&"): setRangeStartFromOpcode(opcode, ccTriggers[opcode.parameters.back()], Default::ccTriggerValueRange); break; - case hash("on_hicc&"): [[fallthrough]]; + case hash("on_hicc&"): // fallthrough case hash("start_hicc&"): setRangeEndFromOpcode(opcode, ccTriggers[opcode.parameters.back()], Default::ccTriggerValueRange); break; @@ -251,14 +251,14 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) setValueFromOpcode(opcode, volume, Default::volumeRange); break; case hash("gain_cc&"): - case hash("gain_oncc&"): [[fallthrough]]; + case hash("gain_oncc&"): // fallthrough case hash("volume_oncc&"): setCCPairFromOpcode(opcode, volumeCC, Default::volumeCCRange); break; case hash("amplitude"): setValueFromOpcode(opcode, amplitude, Default::amplitudeRange); break; - case hash("amplitude_cc&"): [[fallthrough]]; + case hash("amplitude_cc&"): // fallthrough case hash("amplitude_oncc&"): setCCPairFromOpcode(opcode, amplitudeCC, Default::amplitudeRange); break; @@ -377,7 +377,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) break; // Performance parameters: filters - case hash("cutoff"): [[fallthrough]]; + case hash("cutoff"): // fallthrough case hash("cutoff&"): { const auto filterIndex = opcode.parameters.empty() ? 0 : (opcode.parameters.back() - 1); @@ -386,7 +386,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) setValueFromOpcode(opcode, filters[filterIndex].cutoff, Default::filterCutoffRange); } break; - case hash("resonance"): [[fallthrough]]; + case hash("resonance"): // fallthrough case hash("resonance&"): { const auto filterIndex = opcode.parameters.empty() ? 0 : (opcode.parameters.back() - 1); @@ -397,7 +397,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) break; case hash("cutoff_oncc&"): case hash("cutoff_cc&"): - case hash("cutoff&_oncc&"): [[fallthrough]]; + case hash("cutoff&_oncc&"): // fallthrough case hash("cutoff&_cc&"): { const auto filterIndex = opcode.parameters.size() == 1 ? 0 : (opcode.parameters.front() - 1); @@ -413,7 +413,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) break; case hash("resonance&_oncc&"): case hash("resonance&_cc&"): - case hash("resonance_oncc&"): [[fallthrough]]; + case hash("resonance_oncc&"): // fallthrough case hash("resonance_cc&"): { const auto filterIndex = opcode.parameters.size() == 1 ? 0 : (opcode.parameters.front() - 1); @@ -427,7 +427,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) ); } break; - case hash("fil_keytrack"): [[fallthrough]]; + case hash("fil_keytrack"): // fallthrough case hash("fil&_keytrack"): { const auto filterIndex = opcode.parameters.empty() ? 0 : (opcode.parameters.front() - 1); @@ -437,7 +437,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) setValueFromOpcode(opcode, filters[filterIndex].keytrack, Default::filterKeytrackRange); } break; - case hash("fil_keycenter"): [[fallthrough]]; + case hash("fil_keycenter"): // fallthrough case hash("fil&_keycenter"): { const auto filterIndex = opcode.parameters.empty() ? 0 : (opcode.parameters.front() - 1); @@ -447,7 +447,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) setValueFromOpcode(opcode, filters[filterIndex].keycenter, Default::keyRange); } break; - case hash("fil_veltrack"): [[fallthrough]]; + case hash("fil_veltrack"): // fallthrough case hash("fil&_veltrack"): { const auto filterIndex = opcode.parameters.empty() ? 0 : (opcode.parameters.front() - 1); @@ -457,7 +457,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) setValueFromOpcode(opcode, filters[filterIndex].veltrack, Default::filterVeltrackRange); } break; - case hash("fil_random"): [[fallthrough]]; + case hash("fil_random"): // fallthrough case hash("fil&_random"): { const auto filterIndex = opcode.parameters.empty() ? 0 : (opcode.parameters.front() - 1); @@ -467,7 +467,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) setValueFromOpcode(opcode, filters[filterIndex].random, Default::filterRandomRange); } break; - case hash("fil_gain"): [[fallthrough]]; + case hash("fil_gain"): // fallthrough case hash("fil&_gain"): { const auto filterIndex = opcode.parameters.empty() ? 0 : (opcode.parameters.front() - 1); @@ -477,7 +477,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) setValueFromOpcode(opcode, filters[filterIndex].gain, Default::filterGainRange); } break; - case hash("fil_gaincc&"): [[fallthrough]]; + case hash("fil_gaincc&"): // fallthrough case hash("fil&_gaincc&"): { const auto filterIndex = opcode.parameters.size() == 1 ? 0 : (opcode.parameters.front() - 1); @@ -491,7 +491,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) ); } break; - case hash("fil_type"): [[fallthrough]]; + case hash("fil_type"): // fallthrough case hash("fil&_type"): { const auto filterIndex = opcode.parameters.empty() ? 0 : (opcode.parameters.front() - 1); @@ -520,7 +520,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) setValueFromOpcode(opcode, equalizers[eqNumber - 1].bandwidth, Default::eqBandwidthRange); } break; - case hash("eq&_bw_oncc&"): [[fallthrough]]; + case hash("eq&_bw_oncc&"): // fallthrough case hash("eq&_bwcc&"): { const auto eqNumber = opcode.parameters.front(); @@ -542,7 +542,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) setValueFromOpcode(opcode, equalizers[eqNumber - 1].frequency, Default::eqFrequencyRange); } break; - case hash("eq&_freq_oncc&"): [[fallthrough]]; + case hash("eq&_freq_oncc&"): // fallthrough case hash("eq&_freqcc&"): { const auto eqNumber = opcode.parameters.front(); @@ -577,7 +577,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) setValueFromOpcode(opcode, equalizers[eqNumber - 1].gain, Default::eqGainRange); } break; - case hash("eq&_gain_oncc&"): [[fallthrough]]; + case hash("eq&_gain_oncc&"): // fallthrough case hash("eq&_gaincc&"): { const auto eqNumber = opcode.parameters.front(); @@ -638,7 +638,7 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) case hash("transpose"): setValueFromOpcode(opcode, transpose, Default::transposeRange); break; - case hash("tune"): [[fallthrough]]; + case hash("tune"): // fallthrough case hash("pitch"): setValueFromOpcode(opcode, tune, Default::tuneRange); break; @@ -704,31 +704,31 @@ bool sfz::Region::parseOpcode(const Opcode& opcode) return false; // Was not vel2... setValueFromOpcode(opcode, amplitudeEG.vel2sustain, Default::egOnCCPercentRange); break; - case hash("ampeg_attackcc&"): [[fallthrough]]; + case hash("ampeg_attackcc&"): // fallthrough case hash("ampeg_attack_oncc&"): setCCPairFromOpcode(opcode, amplitudeEG.ccAttack, Default::egOnCCTimeRange); break; - case hash("ampeg_decaycc&"): [[fallthrough]]; + case hash("ampeg_decaycc&"): // fallthrough case hash("ampeg_decay_oncc&"): setCCPairFromOpcode(opcode, amplitudeEG.ccDecay, Default::egOnCCTimeRange); break; - case hash("ampeg_delaycc&"): [[fallthrough]]; + case hash("ampeg_delaycc&"): // fallthrough case hash("ampeg_delay_oncc&"): setCCPairFromOpcode(opcode, amplitudeEG.ccDelay, Default::egOnCCTimeRange); break; - case hash("ampeg_holdcc&"): [[fallthrough]]; + case hash("ampeg_holdcc&"): // fallthrough case hash("ampeg_hold_oncc&"): setCCPairFromOpcode(opcode, amplitudeEG.ccHold, Default::egOnCCTimeRange); break; - case hash("ampeg_releasecc&"): [[fallthrough]]; + case hash("ampeg_releasecc&"): // fallthrough case hash("ampeg_release_oncc&"): setCCPairFromOpcode(opcode, amplitudeEG.ccRelease, Default::egOnCCTimeRange); break; - case hash("ampeg_startcc&"): [[fallthrough]]; + case hash("ampeg_startcc&"): // fallthrough case hash("ampeg_start_oncc&"): setCCPairFromOpcode(opcode, amplitudeEG.ccStart, Default::egOnCCPercentRange); break; - case hash("ampeg_sustaincc&"): [[fallthrough]]; + case hash("ampeg_sustaincc&"): // fallthrough case hash("ampeg_sustain_oncc&"): setCCPairFromOpcode(opcode, amplitudeEG.ccSustain, Default::egOnCCPercentRange); break; diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index e2c7ea0f..a5f5b36f 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -163,20 +163,20 @@ void sfz::Synth::handleControlOpcodes(const std::vector& members) { for (auto& member : members) { switch (member.lettersOnlyHash) { - case hash("Set_cc&"): [[fallthrough]]; + case hash("Set_cc&"): // fallthrough case hash("set_cc&"): if (Default::ccNumberRange.containsWithEnd(member.parameters.back())) { const auto ccValue = readOpcode(member.value, Default::ccValueRange).value_or(0); resources.midiState.ccEvent(0, member.parameters.back(), ccValue); } break; - case hash("Label_cc&"): [[fallthrough]]; + case hash("Label_cc&"): // fallthrough case hash("label_cc&"): if (Default::ccNumberRange.containsWithEnd(member.parameters.back())) ccNames.emplace_back(member.parameters.back(), std::string(member.value)); break; case hash("Default_path"): - [[fallthrough]]; + // fallthrough case hash("default_path"): defaultPath = absl::StrReplaceAll(trim(member.value), { { "\\", "/" } }); DBG("Changing default sample path to " << defaultPath); From a26fc7a1fb462d70a6f8c23f315828ab9ec35b52 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 11 Mar 2020 00:18:18 +0100 Subject: [PATCH 32/49] Changed maybe unused into comments or macros --- benchmarks/BM_ADSR.cpp | 2 +- benchmarks/BM_add.cpp | 5 +++-- benchmarks/BM_clock.cpp | 4 ++-- benchmarks/BM_copy.cpp | 2 +- benchmarks/BM_cumsum.cpp | 2 +- benchmarks/BM_diff.cpp | 2 +- benchmarks/BM_divide.cpp | 2 +- benchmarks/BM_envelopes.cpp | 2 +- benchmarks/BM_filterModulation.cpp | 2 +- benchmarks/BM_filterStereoMono.cpp | 2 +- benchmarks/BM_flacfile.cpp | 4 ++-- benchmarks/BM_gain.cpp | 4 ++-- benchmarks/BM_interpolationCast.cpp | 2 +- benchmarks/BM_logger.cpp | 4 ++-- benchmarks/BM_looping.cpp | 2 +- benchmarks/BM_maps.cpp | 2 +- benchmarks/BM_mathfuns.cpp | 2 +- benchmarks/BM_mean.cpp | 2 +- benchmarks/BM_meanSquared.cpp | 2 +- benchmarks/BM_multiplyAdd.cpp | 2 +- benchmarks/BM_multiplyAddFixedGain.cpp | 2 +- benchmarks/BM_pan.cpp | 2 +- benchmarks/BM_pointerIterationOrOffsets.cpp | 4 ++-- benchmarks/BM_readChunk.cpp | 2 +- benchmarks/BM_resample.cpp | 2 +- benchmarks/BM_resampleChunk.cpp | 2 +- benchmarks/BM_saturating.cpp | 2 +- benchmarks/BM_subtract.cpp | 2 +- benchmarks/BM_wavfile.cpp | 4 ++-- benchmarks/BM_widthPos.cpp | 2 +- clients/jack_client.cpp | 12 +++++++----- src/sfizz/EGDescription.h | 4 +++- src/sfizz/Macros.h | 9 +++++++++ src/sfizz/MidiState.cpp | 5 +++-- src/sfizz/Region.cpp | 3 ++- src/sfizz/SIMDNEON.cpp | 8 ++++---- src/sfizz/SIMDSSE.cpp | 8 ++++---- src/sfizz/Synth.cpp | 4 +++- src/sfizz/Voice.cpp | 12 +++++++++--- src/sfizz/sfizz_wrapper.cpp | 2 +- 40 files changed, 83 insertions(+), 59 deletions(-) create mode 100644 src/sfizz/Macros.h diff --git a/benchmarks/BM_ADSR.cpp b/benchmarks/BM_ADSR.cpp index c74735b6..4b781070 100644 --- a/benchmarks/BM_ADSR.cpp +++ b/benchmarks/BM_ADSR.cpp @@ -30,7 +30,7 @@ public: output.resize(state.range(0)); } - void TearDown(const ::benchmark::State &state[[maybe_unused]]) + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_add.cpp b/benchmarks/BM_add.cpp index 9a78a9e2..893b2392 100644 --- a/benchmarks/BM_add.cpp +++ b/benchmarks/BM_add.cpp @@ -5,6 +5,7 @@ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz #include "SIMDHelpers.h" +#include "Macros.h" #include #include #include @@ -24,8 +25,8 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { - + void TearDown(const ::benchmark::State& state) { + UNUSED(state); } std::vector input; diff --git a/benchmarks/BM_clock.cpp b/benchmarks/BM_clock.cpp index e1a263a3..ea4028b7 100644 --- a/benchmarks/BM_clock.cpp +++ b/benchmarks/BM_clock.cpp @@ -9,11 +9,11 @@ class Clock : public benchmark::Fixture { public: - void SetUp(const ::benchmark::State& state) { + void SetUp(const ::benchmark::State& /* state */) { } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_copy.cpp b/benchmarks/BM_copy.cpp index e3c8a5b5..20d4f088 100644 --- a/benchmarks/BM_copy.cpp +++ b/benchmarks/BM_copy.cpp @@ -24,7 +24,7 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_cumsum.cpp b/benchmarks/BM_cumsum.cpp index 9b3523e6..c8626848 100644 --- a/benchmarks/BM_cumsum.cpp +++ b/benchmarks/BM_cumsum.cpp @@ -23,7 +23,7 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_diff.cpp b/benchmarks/BM_diff.cpp index 44fcfe03..af50441d 100644 --- a/benchmarks/BM_diff.cpp +++ b/benchmarks/BM_diff.cpp @@ -25,7 +25,7 @@ public: sfz::cumsum(input, absl::MakeSpan(input)); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_divide.cpp b/benchmarks/BM_divide.cpp index 370c0e33..b4fed561 100644 --- a/benchmarks/BM_divide.cpp +++ b/benchmarks/BM_divide.cpp @@ -26,7 +26,7 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_envelopes.cpp b/benchmarks/BM_envelopes.cpp index 63b9582d..67ec5dcf 100644 --- a/benchmarks/BM_envelopes.cpp +++ b/benchmarks/BM_envelopes.cpp @@ -23,7 +23,7 @@ public: sfz::cumsum(input, absl::MakeSpan(input)); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_filterModulation.cpp b/benchmarks/BM_filterModulation.cpp index e03a3d5e..9326e21f 100644 --- a/benchmarks/BM_filterModulation.cpp +++ b/benchmarks/BM_filterModulation.cpp @@ -32,7 +32,7 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } std::random_device rd { }; diff --git a/benchmarks/BM_filterStereoMono.cpp b/benchmarks/BM_filterStereoMono.cpp index 40ab97ba..16185812 100644 --- a/benchmarks/BM_filterStereoMono.cpp +++ b/benchmarks/BM_filterStereoMono.cpp @@ -35,7 +35,7 @@ public: std::generate(inputRight.begin(), inputRight.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } std::random_device rd { }; diff --git a/benchmarks/BM_flacfile.cpp b/benchmarks/BM_flacfile.cpp index f13c2323..e6fbd18e 100644 --- a/benchmarks/BM_flacfile.cpp +++ b/benchmarks/BM_flacfile.cpp @@ -18,7 +18,7 @@ class FileFixture : public benchmark::Fixture { public: - void SetUp(const ::benchmark::State& state [[maybe_unused]]) { + void SetUp(const ::benchmark::State& state) { filePath1 = getPath() / "sample1.flac"; filePath2 = getPath() / "sample2.flac"; filePath3 = getPath() / "sample3.flac"; @@ -32,7 +32,7 @@ public: } } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } ghc::filesystem::path getPath() diff --git a/benchmarks/BM_gain.cpp b/benchmarks/BM_gain.cpp index 0aafea1e..cb355f1f 100644 --- a/benchmarks/BM_gain.cpp +++ b/benchmarks/BM_gain.cpp @@ -24,7 +24,7 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } @@ -46,7 +46,7 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_interpolationCast.cpp b/benchmarks/BM_interpolationCast.cpp index 409bd62d..ea12845a 100644 --- a/benchmarks/BM_interpolationCast.cpp +++ b/benchmarks/BM_interpolationCast.cpp @@ -28,7 +28,7 @@ public: absl::c_generate(floatJumps, [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_logger.cpp b/benchmarks/BM_logger.cpp index a52bef57..0a1dc12e 100644 --- a/benchmarks/BM_logger.cpp +++ b/benchmarks/BM_logger.cpp @@ -10,11 +10,11 @@ class Logger : public benchmark::Fixture { public: - void SetUp(const ::benchmark::State& state) { + void SetUp(const ::benchmark::State& /* state */) { } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_looping.cpp b/benchmarks/BM_looping.cpp index 7558a8ce..6a465ffc 100644 --- a/benchmarks/BM_looping.cpp +++ b/benchmarks/BM_looping.cpp @@ -30,7 +30,7 @@ public: absl::c_generate(jumps, [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_maps.cpp b/benchmarks/BM_maps.cpp index 88edd380..d15d5419 100644 --- a/benchmarks/BM_maps.cpp +++ b/benchmarks/BM_maps.cpp @@ -36,7 +36,7 @@ public: }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_mathfuns.cpp b/benchmarks/BM_mathfuns.cpp index 245a283f..aa11b966 100644 --- a/benchmarks/BM_mathfuns.cpp +++ b/benchmarks/BM_mathfuns.cpp @@ -26,7 +26,7 @@ public: std::generate(source.begin(), source.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_mean.cpp b/benchmarks/BM_mean.cpp index 38df9d08..5ea0cc93 100644 --- a/benchmarks/BM_mean.cpp +++ b/benchmarks/BM_mean.cpp @@ -23,7 +23,7 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_meanSquared.cpp b/benchmarks/BM_meanSquared.cpp index e1741f5f..41468cc0 100644 --- a/benchmarks/BM_meanSquared.cpp +++ b/benchmarks/BM_meanSquared.cpp @@ -23,7 +23,7 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_multiplyAdd.cpp b/benchmarks/BM_multiplyAdd.cpp index 9f70897b..4bb01e3b 100644 --- a/benchmarks/BM_multiplyAdd.cpp +++ b/benchmarks/BM_multiplyAdd.cpp @@ -26,7 +26,7 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_multiplyAddFixedGain.cpp b/benchmarks/BM_multiplyAddFixedGain.cpp index 919516b2..e05635ba 100644 --- a/benchmarks/BM_multiplyAddFixedGain.cpp +++ b/benchmarks/BM_multiplyAddFixedGain.cpp @@ -26,7 +26,7 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_pan.cpp b/benchmarks/BM_pan.cpp index b3f522e8..130f466e 100644 --- a/benchmarks/BM_pan.cpp +++ b/benchmarks/BM_pan.cpp @@ -33,7 +33,7 @@ public: span2 = absl::MakeSpan(temp2); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_pointerIterationOrOffsets.cpp b/benchmarks/BM_pointerIterationOrOffsets.cpp index 58fc2b32..0e157af9 100644 --- a/benchmarks/BM_pointerIterationOrOffsets.cpp +++ b/benchmarks/BM_pointerIterationOrOffsets.cpp @@ -14,7 +14,7 @@ constexpr int bigNumber { 2399132 }; class IterOffset : public benchmark::Fixture { public: - void SetUp(const ::benchmark::State& state [[maybe_unused]]) { + void SetUp(const ::benchmark::State& /* state */) { std::random_device rd { }; std::mt19937 gen { rd() }; std::uniform_real_distribution dist { 0.001f, 1.0f }; @@ -28,7 +28,7 @@ public: sfz::cumsum(jumps, absl::MakeSpan(offsets)); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_readChunk.cpp b/benchmarks/BM_readChunk.cpp index 9d2a2823..9ee46ffe 100644 --- a/benchmarks/BM_readChunk.cpp +++ b/benchmarks/BM_readChunk.cpp @@ -33,7 +33,7 @@ public: output = std::make_unique>(sndfile.channels(), sndfile.frames()); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } ghc::filesystem::path getPath() diff --git a/benchmarks/BM_resample.cpp b/benchmarks/BM_resample.cpp index f3d763ca..17233b78 100644 --- a/benchmarks/BM_resample.cpp +++ b/benchmarks/BM_resample.cpp @@ -206,7 +206,7 @@ public: sndfile.readf(interleavedBuffer->data(), sndfile.frames()); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_resampleChunk.cpp b/benchmarks/BM_resampleChunk.cpp index 189af8b5..b5c37905 100644 --- a/benchmarks/BM_resampleChunk.cpp +++ b/benchmarks/BM_resampleChunk.cpp @@ -78,7 +78,7 @@ public: output = std::make_unique>(sndfile.channels(), numFrames * 4); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } ghc::filesystem::path getPath() diff --git a/benchmarks/BM_saturating.cpp b/benchmarks/BM_saturating.cpp index c69ad18b..d6bb2427 100644 --- a/benchmarks/BM_saturating.cpp +++ b/benchmarks/BM_saturating.cpp @@ -29,7 +29,7 @@ public: absl::c_generate(jumps, [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_subtract.cpp b/benchmarks/BM_subtract.cpp index 3bfd75d1..afc8fc95 100644 --- a/benchmarks/BM_subtract.cpp +++ b/benchmarks/BM_subtract.cpp @@ -24,7 +24,7 @@ public: std::generate(input.begin(), input.end(), [&]() { return dist(gen); }); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/benchmarks/BM_wavfile.cpp b/benchmarks/BM_wavfile.cpp index badc4e5d..d7d590c2 100644 --- a/benchmarks/BM_wavfile.cpp +++ b/benchmarks/BM_wavfile.cpp @@ -17,7 +17,7 @@ class FileFixture : public benchmark::Fixture { public: - void SetUp(const ::benchmark::State& state [[maybe_unused]]) { + void SetUp(const ::benchmark::State& state) { filePath1 = getPath() / "sample1.wav"; filePath2 = getPath() / "sample2.wav"; filePath3 = getPath() / "sample3.wav"; @@ -31,7 +31,7 @@ public: } } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } ghc::filesystem::path getPath() diff --git a/benchmarks/BM_widthPos.cpp b/benchmarks/BM_widthPos.cpp index 312a029a..1ab9fa7d 100644 --- a/benchmarks/BM_widthPos.cpp +++ b/benchmarks/BM_widthPos.cpp @@ -37,7 +37,7 @@ public: span3 = absl::MakeSpan(temp3); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } diff --git a/clients/jack_client.cpp b/clients/jack_client.cpp index 7aee82d2..f8ad63f8 100644 --- a/clients/jack_client.cpp +++ b/clients/jack_client.cpp @@ -22,6 +22,7 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "sfizz/Synth.h" +#include "sfizz/Macros.h" #include #include #include @@ -70,9 +71,9 @@ constexpr int buildAndCenterPitch(uint8_t firstByte, uint8_t secondByte) } } -static std::atomic keepRunning [[maybe_unused]] { true }; +static std::atomic keepRunning { true }; -int process(jack_nframes_t numFrames, void* arg [[maybe_unused]]) +int process(jack_nframes_t numFrames, void* arg) { auto synth = reinterpret_cast(arg); @@ -129,7 +130,7 @@ int process(jack_nframes_t numFrames, void* arg [[maybe_unused]]) return 0; } -int sampleBlockChanged(jack_nframes_t nframes, void* arg [[maybe_unused]]) +int sampleBlockChanged(jack_nframes_t nframes, void* arg) { if (arg == nullptr) return 0; @@ -140,7 +141,7 @@ int sampleBlockChanged(jack_nframes_t nframes, void* arg [[maybe_unused]]) return 0; } -int sampleRateChanged(jack_nframes_t nframes, void* arg [[maybe_unused]]) +int sampleRateChanged(jack_nframes_t nframes, void* arg) { if (arg == nullptr) return 0; @@ -153,10 +154,11 @@ int sampleRateChanged(jack_nframes_t nframes, void* arg [[maybe_unused]]) static bool shouldClose { false }; -static void done(int sig [[maybe_unused]]) +static void done(int sig) { std::cout << "Signal received" << '\n'; shouldClose = true; + UNUSED(sig); // if (client != nullptr) // exit(0); diff --git a/src/sfizz/EGDescription.h b/src/sfizz/EGDescription.h index afaa32c8..f9c422f7 100644 --- a/src/sfizz/EGDescription.h +++ b/src/sfizz/EGDescription.h @@ -26,6 +26,7 @@ #pragma once #include "Config.h" #include "Defaults.h" +#include "Macros.h" #include "LeakDetector.h" #include "SfzHelpers.h" #include @@ -134,8 +135,9 @@ struct EGDescription * @param velocity * @return float */ - float getStart(const SfzCCArray &ccValues, uint8_t velocity [[maybe_unused]]) const noexcept + float getStart(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { + UNUSED(velocity); return Default::egPercentRange.clamp(ccSwitchedValue(ccValues, ccStart, start)); } /** diff --git a/src/sfizz/Macros.h b/src/sfizz/Macros.h new file mode 100644 index 00000000..bf0d9fbb --- /dev/null +++ b/src/sfizz/Macros.h @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: BSD-2-Clause + +// This code is part of the sfizz library and is licensed under a BSD 2-clause +// license. You should have receive a LICENSE.md file along with the code. +// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz + +#pragma once + +#define UNUSED(x) (void)(x) diff --git a/src/sfizz/MidiState.cpp b/src/sfizz/MidiState.cpp index d128c6e3..0c812af4 100644 --- a/src/sfizz/MidiState.cpp +++ b/src/sfizz/MidiState.cpp @@ -5,6 +5,7 @@ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz #include "MidiState.h" +#include "Macros.h" #include "Debug.h" sfz::MidiState::MidiState() @@ -25,11 +26,11 @@ void sfz::MidiState::noteOnEvent(int delay, int noteNumber, uint8_t velocity) no } -void sfz::MidiState::noteOffEvent(int delay, int noteNumber, uint8_t velocity [[maybe_unused]]) noexcept +void sfz::MidiState::noteOffEvent(int delay, int noteNumber, uint8_t velocity) noexcept { ASSERT(noteNumber >= 0 && noteNumber <= 127); ASSERT(velocity >= 0 && velocity <= 127); - + UNUSED(velocity); if (noteNumber >= 0 && noteNumber < 128) { if (activeNotes > 0) activeNotes--; diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index d9651eca..10c5415a 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -7,6 +7,7 @@ #include "Region.h" #include "Defaults.h" #include "MathHelpers.h" +#include "Macros.h" #include "Debug.h" #include "Opcode.h" #include "StringViewHelpers.h" @@ -817,7 +818,7 @@ bool sfz::Region::registerNoteOn(int noteNumber, uint8_t velocity, float randVal return keyOk && velOk && randOk && (attackTrigger || firstLegatoNote || notFirstLegatoNote); } -bool sfz::Region::registerNoteOff(int noteNumber, uint8_t velocity [[maybe_unused]], float randValue) noexcept +bool sfz::Region::registerNoteOff(int noteNumber, uint8_t velocity, float randValue) noexcept { if (keyswitchRange.containsWithEnd(noteNumber)) { if (keyswitchDown && *keyswitchDown == noteNumber) diff --git a/src/sfizz/SIMDNEON.cpp b/src/sfizz/SIMDNEON.cpp index eb79cf7f..d5212904 100644 --- a/src/sfizz/SIMDNEON.cpp +++ b/src/sfizz/SIMDNEON.cpp @@ -29,10 +29,10 @@ #include using Type = float; -[[maybe_unused]] constexpr uintptr_t TypeAlignment { 4 }; -[[maybe_unused]] constexpr uintptr_t TypeAlignmentMask { TypeAlignment - 1 }; -[[maybe_unused]] constexpr uintptr_t ByteAlignment { TypeAlignment * sizeof(Type) }; -[[maybe_unused]] constexpr uintptr_t ByteAlignmentMask { ByteAlignment - 1 }; +constexpr uintptr_t TypeAlignment { 4 }; +constexpr uintptr_t TypeAlignmentMask { TypeAlignment - 1 }; +constexpr uintptr_t ByteAlignment { TypeAlignment * sizeof(Type) }; +constexpr uintptr_t ByteAlignmentMask { ByteAlignment - 1 }; float* nextAligned(const float* ptr) { diff --git a/src/sfizz/SIMDSSE.cpp b/src/sfizz/SIMDSSE.cpp index bec05f09..2eda8969 100644 --- a/src/sfizz/SIMDSSE.cpp +++ b/src/sfizz/SIMDSSE.cpp @@ -16,10 +16,10 @@ #include "mathfuns/sse_mathfun.h" using Type = float; -[[maybe_unused]] constexpr uintptr_t TypeAlignment { 4 }; -[[maybe_unused]] constexpr uintptr_t TypeAlignmentMask { TypeAlignment - 1 }; -[[maybe_unused]] constexpr uintptr_t ByteAlignment { TypeAlignment * sizeof(Type) }; -[[maybe_unused]] constexpr uintptr_t ByteAlignmentMask { ByteAlignment - 1 }; +constexpr uintptr_t TypeAlignment { 4 }; +constexpr uintptr_t TypeAlignmentMask { TypeAlignment - 1 }; +constexpr uintptr_t ByteAlignment { TypeAlignment * sizeof(Type) }; +constexpr uintptr_t ByteAlignmentMask { ByteAlignment - 1 }; struct AlignmentSentinels { float* nextAligned; diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index a5f5b36f..b02ebd00 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -8,6 +8,7 @@ #include "AtomicGuard.h" #include "Config.h" #include "Debug.h" +#include "Macros.h" #include "MidiState.h" #include "ScopedFTZ.h" #include "StringViewHelpers.h" @@ -589,10 +590,11 @@ void sfz::Synth::noteOn(int delay, int noteNumber, uint8_t velocity) noexcept noteOnDispatch(delay, noteNumber, velocity); } -void sfz::Synth::noteOff(int delay, int noteNumber, uint8_t velocity [[maybe_unused]]) noexcept +void sfz::Synth::noteOff(int delay, int noteNumber, uint8_t velocity) noexcept { ASSERT(noteNumber < 128); ASSERT(noteNumber >= 0); + UNUSED(velocity); ScopedTiming logger { dispatchDuration, ScopedTiming::Operation::addToDuration }; resources.midiState.noteOffEvent(delay, noteNumber, velocity); diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index 149003c5..e6bb2f94 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -4,6 +4,7 @@ // license. You should have receive a LICENSE.md file along with the code. // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz +#include "Macros.h" #include "Voice.h" #include "AudioSpan.h" #include "Config.h" @@ -129,8 +130,9 @@ void sfz::Voice::release(int delay, bool fastRelease) noexcept } } -void sfz::Voice::registerNoteOff(int delay, int noteNumber, uint8_t velocity [[maybe_unused]]) noexcept +void sfz::Voice::registerNoteOff(int delay, int noteNumber, uint8_t velocity) noexcept { + UNUSED(velocity); if (region == nullptr) return; @@ -207,14 +209,18 @@ void sfz::Voice::registerPitchWheel(int delay, int pitch) noexcept pitchBendEnvelope.registerEvent(delay, static_cast(pitch)); } -void sfz::Voice::registerAftertouch(int delay [[maybe_unused]], uint8_t aftertouch [[maybe_unused]]) noexcept +void sfz::Voice::registerAftertouch(int delay, uint8_t aftertouch) noexcept { // TODO + UNUSED(delay); + UNUSED(aftertouch); } -void sfz::Voice::registerTempo(int delay [[maybe_unused]], float secondsPerQuarter [[maybe_unused]]) noexcept +void sfz::Voice::registerTempo(int delay, float secondsPerQuarter) noexcept { // TODO + UNUSED(delay); + UNUSED(secondsPerQuarter); } void sfz::Voice::setSampleRate(float sampleRate) noexcept diff --git a/src/sfizz/sfizz_wrapper.cpp b/src/sfizz/sfizz_wrapper.cpp index 7168e510..32ab355a 100644 --- a/src/sfizz/sfizz_wrapper.cpp +++ b/src/sfizz/sfizz_wrapper.cpp @@ -5,10 +5,10 @@ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz #include "Config.h" +#include "Macros.h" #include "Synth.h" #include "sfizz.h" -#define UNUSED(x) (void)(x) #ifdef __cplusplus extern "C" { #endif From 1f95f90d26a9b7c006e59fb02d82ab2dfc9dd099 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 11 Mar 2020 00:20:41 +0100 Subject: [PATCH 33/49] Added member initializers to Logger data structures --- src/sfizz/Logger.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sfizz/Logger.h b/src/sfizz/Logger.h index d23cb618..13f9e351 100644 --- a/src/sfizz/Logger.h +++ b/src/sfizz/Logger.h @@ -47,10 +47,10 @@ struct ScopedTiming struct FileTime { - Duration waitDuration; - Duration loadDuration; - uint32_t fileSize; - absl::string_view filename; + Duration waitDuration { 0 }; + Duration loadDuration { 0 }; + uint32_t fileSize { 0 }; + absl::string_view filename {}; }; struct CallbackBreakdown @@ -66,9 +66,9 @@ struct CallbackBreakdown struct CallbackTime { - CallbackBreakdown breakdown; - int numVoices; - size_t numSamples; + CallbackBreakdown breakdown {}; + int numVoices { 0 }; + size_t numSamples { 0 }; }; class Logger From 5e008cf684ddd896de4118aad90f022a99680f11 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 11 Mar 2020 00:55:18 +0100 Subject: [PATCH 34/49] List constructors You can remove the default move/copy guys but I suspect that in this case the objects will never be moved in the queue but copied. --- src/sfizz/Logger.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/sfizz/Logger.h b/src/sfizz/Logger.h index 13f9e351..b44a818b 100644 --- a/src/sfizz/Logger.h +++ b/src/sfizz/Logger.h @@ -47,6 +47,13 @@ struct ScopedTiming struct FileTime { + FileTime() = default; + FileTime(Duration waitDuration, Duration loadDuration, uint32_t fileSize, absl::string_view filename) + : waitDuration(waitDuration), loadDuration(loadDuration), fileSize(fileSize), filename(filename) { } + FileTime(const FileTime&) = default; + FileTime& operator=(const FileTime&) = default; + FileTime(FileTime&&) = default; + FileTime& operator=(FileTime&&) = default; Duration waitDuration { 0 }; Duration loadDuration { 0 }; uint32_t fileSize { 0 }; @@ -66,6 +73,13 @@ struct CallbackBreakdown struct CallbackTime { + CallbackTime() = default; + CallbackTime(const CallbackBreakdown& breakdown, int numVoices, size_t numSamples) + : breakdown(breakdown), numVoices(numVoices), numSamples(numSamples) { } + CallbackTime(const CallbackTime&) = default; + CallbackTime& operator=(const CallbackTime&) = default; + CallbackTime(CallbackTime&&) = default; + CallbackTime& operator=(CallbackTime&&) = default; CallbackBreakdown breakdown {}; int numVoices { 0 }; size_t numSamples { 0 }; From 17c4f87d4b768c3b93e82c126380df69e1cff5c0 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 11 Mar 2020 01:05:50 +0100 Subject: [PATCH 35/49] Move EXPORT_SYMBOLS into Macros.h --- src/sfizz.h | 11 +---------- src/sfizz.hpp | 11 +---------- src/sfizz/Macros.h | 10 ++++++++++ 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/sfizz.h b/src/sfizz.h index 54558b0b..c9da6d85 100644 --- a/src/sfizz.h +++ b/src/sfizz.h @@ -12,20 +12,11 @@ #pragma once #include #include +#include "sfizz/Macros.h" #ifdef __cplusplus extern "C" { #endif -#if defined SFIZZ_EXPORT_SYMBOLS - #if defined _WIN32 - #define SFIZZ_EXPORTED_API __declspec(dllexport) - #else - #define SFIZZ_EXPORTED_API __attribute__ ((visibility ("default"))) - #endif -#else - #define SFIZZ_EXPORTED_API -#endif - typedef struct sfizz_synth_t sfizz_synth_t; typedef enum { SFIZZ_OVERSAMPLING_X1 = 1, diff --git a/src/sfizz.hpp b/src/sfizz.hpp index 25d2e932..be2785b3 100644 --- a/src/sfizz.hpp +++ b/src/sfizz.hpp @@ -7,16 +7,7 @@ #include #include #include - -#if defined SFIZZ_EXPORT_SYMBOLS - #if defined _WIN32 - #define SFIZZ_EXPORTED_API __declspec(dllexport) - #else - #define SFIZZ_EXPORTED_API __attribute__ ((visibility ("default"))) - #endif -#else - #define SFIZZ_EXPORTED_API -#endif +#include "sfizz/Macros.h" namespace sfz { diff --git a/src/sfizz/Macros.h b/src/sfizz/Macros.h index bf0d9fbb..31f60de2 100644 --- a/src/sfizz/Macros.h +++ b/src/sfizz/Macros.h @@ -7,3 +7,13 @@ #pragma once #define UNUSED(x) (void)(x) + +#if defined SFIZZ_EXPORT_SYMBOLS + #if defined _WIN32 + #define SFIZZ_EXPORTED_API __declspec(dllexport) + #else + #define SFIZZ_EXPORTED_API __attribute__ ((visibility ("default"))) + #endif +#else + #define SFIZZ_EXPORTED_API +#endif From ad44c2cea93aa30a0086c142b84286f8b5dcad1f Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 11 Mar 2020 01:06:05 +0100 Subject: [PATCH 36/49] Switch between inline and constexpr for c++ version --- src/sfizz/Macros.h | 6 ++++++ src/sfizz/MathHelpers.h | 5 +++-- src/sfizz/SfzHelpers.h | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/sfizz/Macros.h b/src/sfizz/Macros.h index 31f60de2..fd2225c1 100644 --- a/src/sfizz/Macros.h +++ b/src/sfizz/Macros.h @@ -17,3 +17,9 @@ #else #define SFIZZ_EXPORTED_API #endif + +#if __cplusplus > 201103L +#define CONSTEXPR_OR_INLINE constexpr +#else +#define CONSTEXPR_OR_INLINE inline +#endif diff --git a/src/sfizz/MathHelpers.h b/src/sfizz/MathHelpers.h index ac755a11..ca58b62e 100644 --- a/src/sfizz/MathHelpers.h +++ b/src/sfizz/MathHelpers.h @@ -10,6 +10,7 @@ */ #pragma once #include "Config.h" +#include "Macros.h" #include #include #include @@ -128,13 +129,13 @@ constexpr T clamp( T v, T lo, T hi ) } template -constexpr void incrementAll(T& only) +CONSTEXPR_OR_INLINE void incrementAll(T& only) { only += Increment; } template -constexpr void incrementAll(T& first, Args&... rest) +CONSTEXPR_OR_INLINE void incrementAll(T& first, Args&... rest) { first += Increment; incrementAll(rest...); diff --git a/src/sfizz/SfzHelpers.h b/src/sfizz/SfzHelpers.h index bbf89ae6..10ddcbe3 100644 --- a/src/sfizz/SfzHelpers.h +++ b/src/sfizz/SfzHelpers.h @@ -10,6 +10,7 @@ //#include #include #include +#include "Macros.h" #include "Config.h" #include "MathHelpers.h" @@ -230,7 +231,7 @@ using modFunction = std::function; * @param modifier the modifier value */ template -constexpr void addToBase(T& base, T modifier) +CONSTEXPR_OR_INLINE void addToBase(T& base, T modifier) { base += modifier; } @@ -241,7 +242,7 @@ constexpr void addToBase(T& base, T modifier) * @param base * @param modifier */ -inline void multiplyByCents(float& base, int modifier) +CONSTEXPR_OR_INLINE void multiplyByCents(float& base, int modifier) { base *= centsFactor(modifier); } From fbb6b18f0a3783e2fcf0e30bc8ff584ccecbc712 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 11 Mar 2020 01:11:25 +0100 Subject: [PATCH 37/49] absl's make_unique in wavfile --- benchmarks/BM_flacfile.cpp | 5 +- benchmarks/BM_pan.cpp | 2 +- benchmarks/BM_pointerIterationOrOffsets.cpp | 2 +- benchmarks/BM_random.cpp | 0 benchmarks/BM_readChunk.cpp | 4 +- benchmarks/BM_resample.cpp | 68 ++++++++++----------- benchmarks/BM_resampleChunk.cpp | 4 +- benchmarks/BM_wavfile.cpp | 8 +-- 8 files changed, 47 insertions(+), 46 deletions(-) create mode 100644 benchmarks/BM_random.cpp diff --git a/benchmarks/BM_flacfile.cpp b/benchmarks/BM_flacfile.cpp index e6fbd18e..9d17de3a 100644 --- a/benchmarks/BM_flacfile.cpp +++ b/benchmarks/BM_flacfile.cpp @@ -10,6 +10,7 @@ #define DR_FLAC_IMPLEMENTATION #include "dr_flac.h" #include "ghc/filesystem.hpp" +#include "absl/memory/memory.h" #include #ifndef NDEBUG #include @@ -60,7 +61,7 @@ BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) { for (auto _ : state) { SndfileHandle sndfile(filePath1.c_str()); - buffer = std::make_unique>(sndfile.channels() * sndfile.frames()); + buffer = absl::make_unique>(sndfile.channels() * sndfile.frames()); sndfile.readf(buffer->data(), sndfile.frames()); } } @@ -69,7 +70,7 @@ BENCHMARK_DEFINE_F(FileFixture, DrFlac)(benchmark::State& state) { for (auto _ : state) { auto* flac = drflac_open_file(filePath2.c_str(), nullptr); - buffer = std::make_unique>(flac->channels * flac->totalPCMFrameCount); + buffer = absl::make_unique>(flac->channels * flac->totalPCMFrameCount); drflac_read_pcm_frames_f32(flac, flac->totalPCMFrameCount, buffer->data()); } } diff --git a/benchmarks/BM_pan.cpp b/benchmarks/BM_pan.cpp index 130f466e..8cafb079 100644 --- a/benchmarks/BM_pan.cpp +++ b/benchmarks/BM_pan.cpp @@ -69,7 +69,7 @@ BENCHMARK_DEFINE_F(PanArray, BlockOps)(benchmark::State& state) { { sfz::fill(span2, 1.0f); sfz::add(span1, span2); - sfz::applyGain(piFour, span2); + sfz::applyGain(piFour(), span2); sfz::cos(span2, span1); sfz::sin(span2, span2); sfz::applyGain(span1, absl::MakeSpan(left)); diff --git a/benchmarks/BM_pointerIterationOrOffsets.cpp b/benchmarks/BM_pointerIterationOrOffsets.cpp index 0e157af9..33afb4ab 100644 --- a/benchmarks/BM_pointerIterationOrOffsets.cpp +++ b/benchmarks/BM_pointerIterationOrOffsets.cpp @@ -14,7 +14,7 @@ constexpr int bigNumber { 2399132 }; class IterOffset : public benchmark::Fixture { public: - void SetUp(const ::benchmark::State& /* state */) { + void SetUp(const ::benchmark::State& state) { std::random_device rd { }; std::mt19937 gen { rd() }; std::uniform_real_distribution dist { 0.001f, 1.0f }; diff --git a/benchmarks/BM_random.cpp b/benchmarks/BM_random.cpp new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/BM_readChunk.cpp b/benchmarks/BM_readChunk.cpp index 9ee46ffe..4cdc2068 100644 --- a/benchmarks/BM_readChunk.cpp +++ b/benchmarks/BM_readChunk.cpp @@ -12,7 +12,7 @@ #define DR_WAV_IMPLEMENTATION #include "dr_wav.h" #include "AudioBuffer.h" -#include +#include "absl/memory/memory.h" #ifndef NDEBUG #include #endif @@ -30,7 +30,7 @@ public: sndfile = SndfileHandle(rootPath.c_str()); numFrames = static_cast(sndfile.frames()); - output = std::make_unique>(sndfile.channels(), sndfile.frames()); + output = absl::make_unique>(sndfile.channels(), sndfile.frames()); } void TearDown(const ::benchmark::State& /* state */) { diff --git a/benchmarks/BM_resample.cpp b/benchmarks/BM_resample.cpp index 17233b78..75101ac3 100644 --- a/benchmarks/BM_resample.cpp +++ b/benchmarks/BM_resample.cpp @@ -8,7 +8,7 @@ #include "AudioBuffer.h" #include "SIMDHelpers.h" #include -#include +#include "absl/memory/memory.h" #include #include #include "ghc/filesystem.hpp" @@ -151,8 +151,8 @@ void upsample8xStage(absl::Span input, absl::Span outp template std::unique_ptr> upsample2x(const sfz::AudioBuffer& buffer) { - // auto tempBuffer = std::make_unique>(buffer.getNumFrames() * 2); - auto outputBuffer = std::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 2); + // auto tempBuffer = absl::make_unique>(buffer.getNumFrames() * 2); + auto outputBuffer = absl::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 2); for (size_t channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) { upsample2xStage(buffer.getConstSpan(channelIdx), outputBuffer->getSpan(channelIdx)); } @@ -162,8 +162,8 @@ std::unique_ptr> upsample2x(const sfz::AudioBuffer& buffe template std::unique_ptr> upsample4x(const sfz::AudioBuffer& buffer) { - auto tempBuffer = std::make_unique>(buffer.getNumFrames() * 2); - auto outputBuffer = std::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 4); + auto tempBuffer = absl::make_unique>(buffer.getNumFrames() * 2); + auto outputBuffer = absl::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 4); for (size_t channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) { upsample2xStage(buffer.getConstSpan(channelIdx), absl::MakeSpan(*tempBuffer)); upsample4xStage(absl::MakeConstSpan(*tempBuffer), outputBuffer->getSpan(channelIdx)); @@ -174,9 +174,9 @@ std::unique_ptr> upsample4x(const sfz::AudioBuffer& buffe template std::unique_ptr> upsample8x(const sfz::AudioBuffer& buffer) { - auto tempBuffer2x = std::make_unique>(buffer.getNumFrames() * 2); - auto tempBuffer4x = std::make_unique>(buffer.getNumFrames() * 4); - auto outputBuffer = std::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 8); + auto tempBuffer2x = absl::make_unique>(buffer.getNumFrames() * 2); + auto tempBuffer4x = absl::make_unique>(buffer.getNumFrames() * 4); + auto outputBuffer = absl::make_unique>(buffer.getNumChannels(), buffer.getNumFrames() * 8); for (size_t channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) { upsample2xStage(buffer.getConstSpan(channelIdx), absl::MakeSpan(*tempBuffer2x)); upsample4xStage(absl::MakeConstSpan(*tempBuffer2x), absl::MakeSpan(*tempBuffer4x)); @@ -202,7 +202,7 @@ public: SndfileHandle sndfile(rootPath.c_str()); numFrames = sndfile.frames(); numChannels = sndfile.channels(); - interleavedBuffer = std::make_unique>(numChannels * numFrames); + interleavedBuffer = absl::make_unique>(numChannels * numFrames); sndfile.readf(interleavedBuffer->data(), sndfile.frames()); } @@ -231,7 +231,7 @@ public: BENCHMARK_DEFINE_F(SndFile, HIIR2X_scalar)(benchmark::State& state) { for (auto _ : state) { - auto baseBuffer = std::make_unique>(numChannels, numFrames); + auto baseBuffer = absl::make_unique>(numChannels, numFrames); sfz::readInterleaved(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1)); auto outBuffer = upsample2x(*baseBuffer); benchmark::DoNotOptimize(outBuffer); @@ -241,7 +241,7 @@ BENCHMARK_DEFINE_F(SndFile, HIIR2X_scalar)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, HIIR4X_scalar)(benchmark::State& state) { for (auto _ : state) { - auto baseBuffer = std::make_unique>(numChannels, numFrames); + auto baseBuffer = absl::make_unique>(numChannels, numFrames); sfz::readInterleaved(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1)); auto outBuffer = upsample4x(*baseBuffer); benchmark::DoNotOptimize(outBuffer); @@ -251,7 +251,7 @@ BENCHMARK_DEFINE_F(SndFile, HIIR4X_scalar)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, HIIR8X_scalar)(benchmark::State& state) { for (auto _ : state) { - auto baseBuffer = std::make_unique>(numChannels, numFrames); + auto baseBuffer = absl::make_unique>(numChannels, numFrames); sfz::readInterleaved(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1)); auto outBuffer = upsample8x(*baseBuffer); benchmark::DoNotOptimize(outBuffer); @@ -261,7 +261,7 @@ BENCHMARK_DEFINE_F(SndFile, HIIR8X_scalar)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, HIIR2X_vector)(benchmark::State& state) { for (auto _ : state) { - auto baseBuffer = std::make_unique>(numChannels, numFrames); + auto baseBuffer = absl::make_unique>(numChannels, numFrames); sfz::readInterleaved(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1)); auto outBuffer = upsample2x(*baseBuffer); benchmark::DoNotOptimize(outBuffer); @@ -271,7 +271,7 @@ BENCHMARK_DEFINE_F(SndFile, HIIR2X_vector)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, HIIR4X_vector)(benchmark::State& state) { for (auto _ : state) { - auto baseBuffer = std::make_unique>(numChannels, numFrames); + auto baseBuffer = absl::make_unique>(numChannels, numFrames); sfz::readInterleaved(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1)); auto outBuffer = upsample4x(*baseBuffer); benchmark::DoNotOptimize(outBuffer); @@ -281,7 +281,7 @@ BENCHMARK_DEFINE_F(SndFile, HIIR4X_vector)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, HIIR8X_vector)(benchmark::State& state) { for (auto _ : state) { - auto baseBuffer = std::make_unique>(numChannels, numFrames); + auto baseBuffer = absl::make_unique>(numChannels, numFrames); sfz::readInterleaved(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1)); auto outBuffer = upsample8x(*baseBuffer); benchmark::DoNotOptimize(outBuffer); @@ -291,7 +291,7 @@ BENCHMARK_DEFINE_F(SndFile, HIIR8X_vector)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, SRC2x_BEST)(benchmark::State& state) { for (auto _ : state) { - auto intermediateBuffer = std::make_unique>(2 * numChannels * numFrames); + auto intermediateBuffer = absl::make_unique>(2 * numChannels * numFrames); SRC_DATA srcData; srcData.data_in = interleavedBuffer->data(); srcData.data_out = intermediateBuffer->data(); @@ -299,7 +299,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC2x_BEST)(benchmark::State& state) srcData.input_frames = static_cast(numFrames); srcData.output_frames = static_cast(2 * numFrames); src_simple(&srcData, SRC_SINC_BEST_QUALITY, static_cast(numChannels)); - auto outBuffer = std::make_unique>(numChannels, 2 * numFrames); + auto outBuffer = absl::make_unique>(numChannels, 2 * numFrames); sfz::readInterleaved(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1)); benchmark::DoNotOptimize(outBuffer); } @@ -308,7 +308,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC2x_BEST)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, SRC2x_MEDIUM)(benchmark::State& state) { for (auto _ : state) { - auto intermediateBuffer = std::make_unique>(2 * numChannels * numFrames); + auto intermediateBuffer = absl::make_unique>(2 * numChannels * numFrames); SRC_DATA srcData; srcData.data_in = interleavedBuffer->data(); srcData.data_out = intermediateBuffer->data(); @@ -316,7 +316,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC2x_MEDIUM)(benchmark::State& state) srcData.input_frames = static_cast(numFrames); srcData.output_frames = static_cast(2 * numFrames); src_simple(&srcData, SRC_SINC_MEDIUM_QUALITY, static_cast(numChannels)); - auto outBuffer = std::make_unique>(numChannels, 2 * numFrames); + auto outBuffer = absl::make_unique>(numChannels, 2 * numFrames); sfz::readInterleaved(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1)); benchmark::DoNotOptimize(outBuffer); } @@ -325,7 +325,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC2x_MEDIUM)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, SRC2x_FASTEST)(benchmark::State& state) { for (auto _ : state) { - auto intermediateBuffer = std::make_unique>(2 * numChannels * numFrames); + auto intermediateBuffer = absl::make_unique>(2 * numChannels * numFrames); SRC_DATA srcData; srcData.data_in = interleavedBuffer->data(); srcData.data_out = intermediateBuffer->data(); @@ -333,7 +333,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC2x_FASTEST)(benchmark::State& state) srcData.input_frames = static_cast(numFrames); srcData.output_frames = static_cast(2 * numFrames); src_simple(&srcData, SRC_SINC_FASTEST, static_cast(numChannels)); - auto outBuffer = std::make_unique>(numChannels, 2 * numFrames); + auto outBuffer = absl::make_unique>(numChannels, 2 * numFrames); sfz::readInterleaved(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1)); benchmark::DoNotOptimize(outBuffer); } @@ -343,7 +343,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC2x_FASTEST)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, SRC4x_BEST)(benchmark::State& state) { for (auto _ : state) { - auto intermediateBuffer = std::make_unique>(2 * numChannels * numFrames); + auto intermediateBuffer = absl::make_unique>(2 * numChannels * numFrames); SRC_DATA srcData; srcData.data_in = interleavedBuffer->data(); srcData.data_out = intermediateBuffer->data(); @@ -351,7 +351,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC4x_BEST)(benchmark::State& state) srcData.input_frames = static_cast(numFrames); srcData.output_frames = static_cast(2 * numFrames); src_simple(&srcData, SRC_SINC_BEST_QUALITY, static_cast(numChannels)); - auto outBuffer = std::make_unique>(numChannels, 2 * numFrames); + auto outBuffer = absl::make_unique>(numChannels, 2 * numFrames); sfz::readInterleaved(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1)); benchmark::DoNotOptimize(outBuffer); } @@ -360,7 +360,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC4x_BEST)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, SRC4x_MEDIUM)(benchmark::State& state) { for (auto _ : state) { - auto intermediateBuffer = std::make_unique>(2 * numChannels * numFrames); + auto intermediateBuffer = absl::make_unique>(2 * numChannels * numFrames); SRC_DATA srcData; srcData.data_in = interleavedBuffer->data(); srcData.data_out = intermediateBuffer->data(); @@ -368,7 +368,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC4x_MEDIUM)(benchmark::State& state) srcData.input_frames = static_cast(numFrames); srcData.output_frames = static_cast(2 * numFrames); src_simple(&srcData, SRC_SINC_MEDIUM_QUALITY, static_cast(numChannels)); - auto outBuffer = std::make_unique>(numChannels, 2 * numFrames); + auto outBuffer = absl::make_unique>(numChannels, 2 * numFrames); sfz::readInterleaved(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1)); benchmark::DoNotOptimize(outBuffer); } @@ -377,7 +377,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC4x_MEDIUM)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, SRC4x_FASTEST)(benchmark::State& state) { for (auto _ : state) { - auto intermediateBuffer = std::make_unique>(2 * numChannels * numFrames); + auto intermediateBuffer = absl::make_unique>(2 * numChannels * numFrames); SRC_DATA srcData; srcData.data_in = interleavedBuffer->data(); srcData.data_out = intermediateBuffer->data(); @@ -385,7 +385,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC4x_FASTEST)(benchmark::State& state) srcData.input_frames = static_cast(numFrames); srcData.output_frames = static_cast(2 * numFrames); src_simple(&srcData, SRC_SINC_FASTEST, static_cast(numChannels)); - auto outBuffer = std::make_unique>(numChannels, 2 * numFrames); + auto outBuffer = absl::make_unique>(numChannels, 2 * numFrames); sfz::readInterleaved(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1)); benchmark::DoNotOptimize(outBuffer); } @@ -394,7 +394,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC4x_FASTEST)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, SRC8x_BEST)(benchmark::State& state) { for (auto _ : state) { - auto intermediateBuffer = std::make_unique>(2 * numChannels * numFrames); + auto intermediateBuffer = absl::make_unique>(2 * numChannels * numFrames); SRC_DATA srcData; srcData.data_in = interleavedBuffer->data(); srcData.data_out = intermediateBuffer->data(); @@ -402,7 +402,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC8x_BEST)(benchmark::State& state) srcData.input_frames = static_cast(numFrames); srcData.output_frames = static_cast(2 * numFrames); src_simple(&srcData, SRC_SINC_BEST_QUALITY, static_cast(numChannels)); - auto outBuffer = std::make_unique>(numChannels, 2 * numFrames); + auto outBuffer = absl::make_unique>(numChannels, 2 * numFrames); sfz::readInterleaved(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1)); benchmark::DoNotOptimize(outBuffer); } @@ -411,7 +411,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC8x_BEST)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, SRC8x_MEDIUM)(benchmark::State& state) { for (auto _ : state) { - auto intermediateBuffer = std::make_unique>(2 * numChannels * numFrames); + auto intermediateBuffer = absl::make_unique>(2 * numChannels * numFrames); SRC_DATA srcData; srcData.data_in = interleavedBuffer->data(); srcData.data_out = intermediateBuffer->data(); @@ -419,7 +419,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC8x_MEDIUM)(benchmark::State& state) srcData.input_frames = static_cast(numFrames); srcData.output_frames = static_cast(2 * numFrames); src_simple(&srcData, SRC_SINC_MEDIUM_QUALITY, static_cast(numChannels)); - auto outBuffer = std::make_unique>(numChannels, 2 * numFrames); + auto outBuffer = absl::make_unique>(numChannels, 2 * numFrames); sfz::readInterleaved(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1)); benchmark::DoNotOptimize(outBuffer); } @@ -428,7 +428,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC8x_MEDIUM)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, SRC8x_FASTEST)(benchmark::State& state) { for (auto _ : state) { - auto intermediateBuffer = std::make_unique>(2 * numChannels * numFrames); + auto intermediateBuffer = absl::make_unique>(2 * numChannels * numFrames); SRC_DATA srcData; srcData.data_in = interleavedBuffer->data(); srcData.data_out = intermediateBuffer->data(); @@ -436,7 +436,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC8x_FASTEST)(benchmark::State& state) srcData.input_frames = static_cast(numFrames); srcData.output_frames = static_cast(2 * numFrames); src_simple(&srcData, SRC_SINC_FASTEST, static_cast(numChannels)); - auto outBuffer = std::make_unique>(numChannels, 2 * numFrames); + auto outBuffer = absl::make_unique>(numChannels, 2 * numFrames); sfz::readInterleaved(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1)); benchmark::DoNotOptimize(outBuffer); } @@ -445,7 +445,7 @@ BENCHMARK_DEFINE_F(SndFile, SRC8x_FASTEST)(benchmark::State& state) BENCHMARK_DEFINE_F(SndFile, HIIR8X_default)(benchmark::State& state) { for (auto _ : state) { - auto baseBuffer = std::make_unique>(numChannels, numFrames); + auto baseBuffer = absl::make_unique>(numChannels, numFrames); sfz::readInterleaved(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1)); auto outBuffer = upsample8x(*baseBuffer); benchmark::DoNotOptimize(outBuffer); diff --git a/benchmarks/BM_resampleChunk.cpp b/benchmarks/BM_resampleChunk.cpp index b5c37905..a75c06c5 100644 --- a/benchmarks/BM_resampleChunk.cpp +++ b/benchmarks/BM_resampleChunk.cpp @@ -11,7 +11,7 @@ #include "ghc/filesystem.hpp" #include "Oversampler.h" #include "AudioBuffer.h" -#include +#include "absl/memory/memory.h" #include @@ -75,7 +75,7 @@ public: sndfile = SndfileHandle(rootPath.c_str()); numFrames = static_cast(sndfile.frames()); - output = std::make_unique>(sndfile.channels(), numFrames * 4); + output = absl::make_unique>(sndfile.channels(), numFrames * 4); } void TearDown(const ::benchmark::State& /* state */) { diff --git a/benchmarks/BM_wavfile.cpp b/benchmarks/BM_wavfile.cpp index d7d590c2..a4533195 100644 --- a/benchmarks/BM_wavfile.cpp +++ b/benchmarks/BM_wavfile.cpp @@ -9,7 +9,7 @@ #define DR_WAV_IMPLEMENTATION #include "dr_wav.h" #include "ghc/filesystem.hpp" -#include +#include "absl/memory/memory.h" #ifndef NDEBUG #include #endif @@ -17,7 +17,7 @@ class FileFixture : public benchmark::Fixture { public: - void SetUp(const ::benchmark::State& state) { + void SetUp(const ::benchmark::State& /* state */) { filePath1 = getPath() / "sample1.wav"; filePath2 = getPath() / "sample2.wav"; filePath3 = getPath() / "sample3.wav"; @@ -59,7 +59,7 @@ BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) { for (auto _ : state) { SndfileHandle sndfile(filePath1.c_str()); - buffer = std::make_unique>(sndfile.channels() * sndfile.frames()); + buffer = absl::make_unique>(sndfile.channels() * sndfile.frames()); sndfile.readf(buffer->data(), sndfile.frames()); } } @@ -74,7 +74,7 @@ BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) { #endif std::terminate(); } - buffer = std::make_unique>(wav.channels * wav.totalPCMFrameCount); + buffer = absl::make_unique>(wav.channels * wav.totalPCMFrameCount); drwav_read_pcm_frames_f32(&wav, wav.totalPCMFrameCount, buffer->data()); } } From 3d1cf4ac1e5a36e92eccd04c163fbe2795274307 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 11 Mar 2020 01:21:08 +0100 Subject: [PATCH 38/49] Explicit const on member functions of Buffer --- src/sfizz/Buffer.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sfizz/Buffer.h b/src/sfizz/Buffer.h index ca3b7363..b7b0ce8d 100644 --- a/src/sfizz/Buffer.h +++ b/src/sfizz/Buffer.h @@ -260,9 +260,9 @@ public: constexpr pointer data() const noexcept { return normalData; } constexpr size_type size() const noexcept { return alignedSize; } constexpr bool empty() const noexcept { return alignedSize == 0; } - constexpr iterator begin() noexcept { return data(); } - constexpr iterator end() noexcept { return normalEnd; } - constexpr pointer alignedEnd() noexcept { return _alignedEnd; } + constexpr iterator begin() const noexcept { return data(); } + constexpr iterator end() const noexcept { return normalEnd; } + constexpr pointer alignedEnd() const noexcept { return _alignedEnd; } /** From dcca4c1cce6424c4ddb0e113089464c141ca7914 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 11 Mar 2020 01:32:23 +0100 Subject: [PATCH 39/49] Added leak detectors in Logger --- src/sfizz/Logger.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sfizz/Logger.h b/src/sfizz/Logger.h index b44a818b..04bea8fc 100644 --- a/src/sfizz/Logger.h +++ b/src/sfizz/Logger.h @@ -6,6 +6,7 @@ #pragma once #include "Config.h" +#include "LeakDetector.h" #include "atomic_queue/atomic_queue.h" #include #include @@ -58,6 +59,7 @@ struct FileTime Duration loadDuration { 0 }; uint32_t fileSize { 0 }; absl::string_view filename {}; + LEAK_DETECTOR(FileTime); }; struct CallbackBreakdown @@ -69,6 +71,7 @@ struct CallbackBreakdown Duration filters { 0 }; Duration panning { 0 }; Duration effects { 0 }; + LEAK_DETECTOR(CallbackBreakdown); }; struct CallbackTime @@ -83,6 +86,7 @@ struct CallbackTime CallbackBreakdown breakdown {}; int numVoices { 0 }; size_t numSamples { 0 }; + LEAK_DETECTOR(CallbackTime); }; class Logger @@ -149,6 +153,7 @@ private: std::atomic_flag keepRunning; std::atomic_flag clearFlag; std::thread loggingThread; + LEAK_DETECTOR(Logger); }; } From bd93955fb33d8e6464dfb300a2c5927e4e117d70 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 11 Mar 2020 01:58:55 +0100 Subject: [PATCH 40/49] Try to save the OSX build --- cmake/SfizzConfig.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/SfizzConfig.cmake b/cmake/SfizzConfig.cmake index 52a2a587..2b4886a1 100644 --- a/cmake/SfizzConfig.cmake +++ b/cmake/SfizzConfig.cmake @@ -1,3 +1,10 @@ +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND (CMAKE_CXX_STANDARD LESS 14 OR NOT CMAKE_CXX_STANDARD)) + # There is a strange segfault in clang in c++11 when instantiating the + # envelopes in FloatEnvelopes.cpp. + message("Forcing C++14 to bypass a clang segfault") + set(CMAKE_CXX_STANDARD 14) +endif() + # Do not override the C++ standard if set to more than 11 if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 11) set(CMAKE_CXX_STANDARD 11) From 8ba825d3ddb089e4e4fd651a36281e3c47cc9628 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Wed, 11 Mar 2020 09:50:04 +0100 Subject: [PATCH 41/49] Clean up changes to the atomic_queue --- src/external/atomic_queue/atomic_queue.h | 30 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/external/atomic_queue/atomic_queue.h b/src/external/atomic_queue/atomic_queue.h index bcbd29a9..e7bcf0f2 100644 --- a/src/external/atomic_queue/atomic_queue.h +++ b/src/external/atomic_queue/atomic_queue.h @@ -95,15 +95,35 @@ constexpr T& map(T* elements, unsigned index) noexcept { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Implement a "bit-twiddling hack" for finding the next power of 2 +// in either 32 bits or 64 bits in C++11 compatible constexpr functions + +// "Runtime" version for 32 bits +// --a; +// a |= a >> 1; +// a |= a >> 2; +// a |= a >> 4; +// a |= a >> 8; +// a |= a >> 16; +// ++a; + template -constexpr T decrement(T x) { return x - 1; } +constexpr T decrement(T x) { + return x - 1; +} + template -constexpr T increment(T x) { return x + 1; } +constexpr T increment(T x) { + return x + 1; +} + template -constexpr T or_equal(T x, unsigned u) { return (x | x >> u); } +constexpr T or_equal(T x, unsigned u) { + return (x | x >> u); +} + template -constexpr T or_equal(T x, unsigned u, Args... rest) -{ +constexpr T or_equal(T x, unsigned u, Args... rest) { return or_equal(or_equal(x, u), rest...); } From b44b4efad3dcc60fc49e5714df7ee0083a5a6b0e Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Wed, 11 Mar 2020 11:31:16 +0100 Subject: [PATCH 42/49] Magic by @jpcima to solve the clang segfault --- src/sfizz/EventEnvelopes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sfizz/EventEnvelopes.h b/src/sfizz/EventEnvelopes.h index c9631014..c56d1dd6 100644 --- a/src/sfizz/EventEnvelopes.h +++ b/src/sfizz/EventEnvelopes.h @@ -94,7 +94,7 @@ protected: Type currentValue { 0.0 }; private: static_assert(std::is_arithmetic::value, "Type should be arithmetic"); - std::function function { [](Type input) { return input; } }; + std::function function { [](Type input) -> Type { return input; } }; int maxCapacity { config::defaultSamplesPerBlock }; void prepareEvents(int blockLength); bool resetEvents { false }; From dc25c5282e954d30ce35ac17dc917ef6b378ca58 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Wed, 11 Mar 2020 11:32:18 +0100 Subject: [PATCH 43/49] Remove the clang specifics in cmake and use the default XCode --- .travis.yml | 1 - cmake/SfizzConfig.cmake | 7 ------- 2 files changed, 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0c653e66..44e5035e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -129,7 +129,6 @@ jobs: - name: "macOS" os: osx - osx_image: xcode10.1 env: - INSTALL_DIR="sfizz-${TRAVIS_BRANCH}-${TRAVIS_OS_NAME}-${TRAVIS_CPU_ARCH}" install: .travis/install_osx.sh diff --git a/cmake/SfizzConfig.cmake b/cmake/SfizzConfig.cmake index 2b4886a1..52a2a587 100644 --- a/cmake/SfizzConfig.cmake +++ b/cmake/SfizzConfig.cmake @@ -1,10 +1,3 @@ -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND (CMAKE_CXX_STANDARD LESS 14 OR NOT CMAKE_CXX_STANDARD)) - # There is a strange segfault in clang in c++11 when instantiating the - # envelopes in FloatEnvelopes.cpp. - message("Forcing C++14 to bypass a clang segfault") - set(CMAKE_CXX_STANDARD 14) -endif() - # Do not override the C++ standard if set to more than 11 if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 11) set(CMAKE_CXX_STANDARD 11) From cedc72a707dc574babd131d4f71955fb0860f89b Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Wed, 11 Mar 2020 11:35:25 +0100 Subject: [PATCH 44/49] Unused constexpr --- src/sfizz/SIMDNEON.cpp | 1 - src/sfizz/SIMDSSE.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/sfizz/SIMDNEON.cpp b/src/sfizz/SIMDNEON.cpp index d5212904..6a6dc8d1 100644 --- a/src/sfizz/SIMDNEON.cpp +++ b/src/sfizz/SIMDNEON.cpp @@ -30,7 +30,6 @@ using Type = float; constexpr uintptr_t TypeAlignment { 4 }; -constexpr uintptr_t TypeAlignmentMask { TypeAlignment - 1 }; constexpr uintptr_t ByteAlignment { TypeAlignment * sizeof(Type) }; constexpr uintptr_t ByteAlignmentMask { ByteAlignment - 1 }; diff --git a/src/sfizz/SIMDSSE.cpp b/src/sfizz/SIMDSSE.cpp index 2eda8969..1b5c466c 100644 --- a/src/sfizz/SIMDSSE.cpp +++ b/src/sfizz/SIMDSSE.cpp @@ -17,7 +17,6 @@ using Type = float; constexpr uintptr_t TypeAlignment { 4 }; -constexpr uintptr_t TypeAlignmentMask { TypeAlignment - 1 }; constexpr uintptr_t ByteAlignment { TypeAlignment * sizeof(Type) }; constexpr uintptr_t ByteAlignmentMask { ByteAlignment - 1 }; From 3ed225323d3cdeb30fd8c6d82fe69742e72971cd Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Wed, 11 Mar 2020 11:35:53 +0100 Subject: [PATCH 45/49] unused variable --- clients/jack_client.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/clients/jack_client.cpp b/clients/jack_client.cpp index f8ad63f8..599e0db3 100644 --- a/clients/jack_client.cpp +++ b/clients/jack_client.cpp @@ -71,8 +71,6 @@ constexpr int buildAndCenterPitch(uint8_t firstByte, uint8_t secondByte) } } -static std::atomic keepRunning { true }; - int process(jack_nframes_t numFrames, void* arg) { auto synth = reinterpret_cast(arg); From f5a47b8f677b1f8cf7e13bda4ceade17919605a8 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Wed, 11 Mar 2020 11:58:06 +0100 Subject: [PATCH 46/49] Compile VST3 targets with c++14 --- vst/cmake/Vst3.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/vst/cmake/Vst3.cmake b/vst/cmake/Vst3.cmake index 544a34e6..5aa28432 100644 --- a/vst/cmake/Vst3.cmake +++ b/vst/cmake/Vst3.cmake @@ -36,6 +36,7 @@ function(plugin_add_vst3sdk NAME) "${VST3SDK_BASEDIR}/public.sdk/source/common/threadchecker_win32.cpp" "${VST3SDK_BASEDIR}/public.sdk/source/vst/vstgui_win32_bundle_support.cpp" "${VST3SDK_BASEDIR}/public.sdk/source/main/dllmain.cpp") + set_property(TARGET "${NAME}" PROPERTY CXX_STANDARD 14) elseif(APPLE) target_sources("${NAME}" PRIVATE "${VST3SDK_BASEDIR}/public.sdk/source/main/macmain.cpp") From 976385976c5adf9181e3e1770c5feae7e3705357 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Wed, 11 Mar 2020 14:53:25 +0100 Subject: [PATCH 47/49] Changed CONSTEXPR_OR_INLINE to CXX14_CONSTEXPR --- src/sfizz/Macros.h | 4 ++-- src/sfizz/MathHelpers.h | 4 ++-- src/sfizz/SfzHelpers.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sfizz/Macros.h b/src/sfizz/Macros.h index fd2225c1..f610eefb 100644 --- a/src/sfizz/Macros.h +++ b/src/sfizz/Macros.h @@ -19,7 +19,7 @@ #endif #if __cplusplus > 201103L -#define CONSTEXPR_OR_INLINE constexpr +#define CXX14_CONSTEXPR constexpr #else -#define CONSTEXPR_OR_INLINE inline +#define CXX14_CONSTEXPR #endif diff --git a/src/sfizz/MathHelpers.h b/src/sfizz/MathHelpers.h index ca58b62e..d126992b 100644 --- a/src/sfizz/MathHelpers.h +++ b/src/sfizz/MathHelpers.h @@ -129,13 +129,13 @@ constexpr T clamp( T v, T lo, T hi ) } template -CONSTEXPR_OR_INLINE void incrementAll(T& only) +inline CXX14_CONSTEXPR void incrementAll(T& only) { only += Increment; } template -CONSTEXPR_OR_INLINE void incrementAll(T& first, Args&... rest) +inline CXX14_CONSTEXPR void incrementAll(T& first, Args&... rest) { first += Increment; incrementAll(rest...); diff --git a/src/sfizz/SfzHelpers.h b/src/sfizz/SfzHelpers.h index 10ddcbe3..a50c3428 100644 --- a/src/sfizz/SfzHelpers.h +++ b/src/sfizz/SfzHelpers.h @@ -231,7 +231,7 @@ using modFunction = std::function; * @param modifier the modifier value */ template -CONSTEXPR_OR_INLINE void addToBase(T& base, T modifier) +inline CXX14_CONSTEXPR void addToBase(T& base, T modifier) { base += modifier; } @@ -242,7 +242,7 @@ CONSTEXPR_OR_INLINE void addToBase(T& base, T modifier) * @param base * @param modifier */ -CONSTEXPR_OR_INLINE void multiplyByCents(float& base, int modifier) +inline CXX14_CONSTEXPR void multiplyByCents(float& base, int modifier) { base *= centsFactor(modifier); } From 57d9598ab3b9a7de1d0b12b503047b637488cf98 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Wed, 11 Mar 2020 15:06:14 +0100 Subject: [PATCH 48/49] Restore the initial sleep time in the emptyFileLoadingQueues() --- src/sfizz/FilePool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index f240d3dd..cf80f33b 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -411,7 +411,7 @@ void sfz::FilePool::emptyFileLoadingQueues() noexcept { emptyQueue = true; while (emptyQueue) - std::this_thread::sleep_for(std::chrono::microseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } void sfz::FilePool::waitForBackgroundLoading() noexcept From 26afbcd4557cbf4367626028b77e2ef180fba0ad Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Wed, 11 Mar 2020 15:32:32 +0100 Subject: [PATCH 49/49] Move and clean up standards --- cmake/SfizzConfig.cmake | 6 ++---- lv2/CMakeLists.txt | 3 --- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/cmake/SfizzConfig.cmake b/cmake/SfizzConfig.cmake index 52a2a587..81184a87 100644 --- a/cmake/SfizzConfig.cmake +++ b/cmake/SfizzConfig.cmake @@ -1,7 +1,5 @@ -# Do not override the C++ standard if set to more than 11 -if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 11) - set(CMAKE_CXX_STANDARD 11) -endif() +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_C_STANDARD 99) # Export the compile_commands.json file set (CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/lv2/CMakeLists.txt b/lv2/CMakeLists.txt index 240298fe..aa732cb4 100644 --- a/lv2/CMakeLists.txt +++ b/lv2/CMakeLists.txt @@ -3,9 +3,6 @@ set (LV2PLUGIN_PRJ_NAME "${PROJECT_NAME}_lv2") # Set the build directory as /lv2/.lv2/ set (PROJECT_BINARY_DIR "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.lv2") -# C99 or higher is needed -set(CMAKE_C_STANDARD 99) - # LV2 plugin specific settings include (LV2Config)