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/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..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 @@ -18,7 +19,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 +33,7 @@ public: } } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) { + void TearDown(const ::benchmark::State& /* state */) { } ghc::filesystem::path getPath() @@ -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_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..8cafb079 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 */) { } @@ -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 58fc2b32..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 [[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_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 9d2a2823..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,10 +30,10 @@ 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 [[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..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,11 +202,11 @@ 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()); } - void TearDown(const ::benchmark::State& state [[maybe_unused]]) + void TearDown(const ::benchmark::State& /* state */) { } @@ -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 189af8b5..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,10 +75,10 @@ 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 [[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..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 [[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() @@ -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()); } } 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 a07776c4..599e0db3 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 @@ -37,7 +38,6 @@ #include #include #include -using namespace std::literals; static jack_port_t* midiInputPort; static jack_port_t* outputPort1; @@ -71,9 +71,7 @@ constexpr int buildAndCenterPitch(uint8_t firstByte, uint8_t secondByte) } } -static std::atomic keepRunning [[maybe_unused]] { true }; - -int process(jack_nframes_t numFrames, void* arg [[maybe_unused]]) +int process(jack_nframes_t numFrames, void* arg) { auto synth = reinterpret_cast(arg); @@ -130,7 +128,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; @@ -141,7 +139,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; @@ -154,10 +152,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); @@ -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'; diff --git a/cmake/SfizzConfig.cmake b/cmake/SfizzConfig.cmake index 61ba6a13..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 14 -if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 14) - set(CMAKE_CXX_STANDARD 14) -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/src/external/atomic_queue/atomic_queue.h b/src/external/atomic_queue/atomic_queue.h index 19fdb40d..e7bcf0f2 100644 --- a/src/external/atomic_queue/atomic_queue.h +++ b/src/external/atomic_queue/atomic_queue.h @@ -95,27 +95,44 @@ 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; +} + +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 +321,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); 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/ADSREnvelope.cpp b/src/sfizz/ADSREnvelope.cpp index e795d53f..96333be2 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); }; @@ -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/AudioBuffer.h b/src/sfizz/AudioBuffer.h index 7de52af2..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 @@ -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; @@ -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); } /** 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()) diff --git a/src/sfizz/Buffer.h b/src/sfizz/Buffer.h index 757fe9cd..b7b0ce8d 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) @@ -256,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; } /** @@ -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 }; 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/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/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/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 }; diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index a716d32b..cf80f33b 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::milliseconds(1)); } 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 cba35cb7..c75e6c75 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -44,15 +44,16 @@ 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 { - auto getData() + AudioSpan getData() { if (dataReady) return AudioSpan(fileData); @@ -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; 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)); } } diff --git a/src/sfizz/Logger.h b/src/sfizz/Logger.h index d23cb618..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 @@ -47,10 +48,18 @@ struct ScopedTiming struct FileTime { - Duration waitDuration; - Duration loadDuration; - uint32_t fileSize; - absl::string_view filename; + 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 }; + absl::string_view filename {}; + LEAK_DETECTOR(FileTime); }; struct CallbackBreakdown @@ -62,13 +71,22 @@ struct CallbackBreakdown Duration filters { 0 }; Duration panning { 0 }; Duration effects { 0 }; + LEAK_DETECTOR(CallbackBreakdown); }; struct CallbackTime { - CallbackBreakdown breakdown; - int numVoices; - size_t numSamples; + 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 }; + LEAK_DETECTOR(CallbackTime); }; class Logger @@ -135,6 +153,7 @@ private: std::atomic_flag keepRunning; std::atomic_flag clearFlag; std::thread loggingThread; + LEAK_DETECTOR(Logger); }; } diff --git a/src/sfizz/Macros.h b/src/sfizz/Macros.h new file mode 100644 index 00000000..f610eefb --- /dev/null +++ b/src/sfizz/Macros.h @@ -0,0 +1,25 @@ +// 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) + +#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 + +#if __cplusplus > 201103L +#define CXX14_CONSTEXPR constexpr +#else +#define CXX14_CONSTEXPR +#endif diff --git a/src/sfizz/MathHelpers.h b/src/sfizz/MathHelpers.h index 2f88b2f6..d126992b 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 @@ -17,25 +18,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...)); } /** @@ -124,19 +125,17 @@ 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); - return v; + return max(min(v, hi), lo); } template -constexpr void incrementAll(T& only) +inline CXX14_CONSTEXPR void incrementAll(T& only) { only += Increment; } template -constexpr void incrementAll(T& first, Args&... rest) +inline CXX14_CONSTEXPR void incrementAll(T& first, Args&... rest) { first += Increment; incrementAll(rest...); @@ -148,18 +147,18 @@ 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) }; +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/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/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. * diff --git a/src/sfizz/OnePoleFilter.h b/src/sfizz/OnePoleFilter.h index b9c6d805..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) * pi); + return std::tan(cutoff / static_cast(sampleRate) * pi()); } OnePoleFilter(Type gain) diff --git a/src/sfizz/Opcode.h b/src/sfizz/Opcode.h index 2ac43209..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> = 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> = 0> +template ::value, int> = 0> inline absl::optional readOpcode(absl::string_view value, const Range& validRange) { float returnedValue; diff --git a/src/sfizz/Oversampler.cpp b/src/sfizz/Oversampler.cpp index b2b986ae..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()); @@ -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/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)) { } diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 8dc962b4..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" @@ -66,7 +67,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 +86,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 +238,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 +252,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 +378,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 +387,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 +398,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 +414,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 +428,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 +438,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 +448,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 +458,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 +468,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 +478,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 +492,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 +521,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 +543,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 +578,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 +639,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 +705,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; @@ -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) @@ -1011,7 +1012,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 { diff --git a/src/sfizz/SIMDHelpers.h b/src/sfizz/SIMDHelpers.h index d466933c..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 * (piTwo / (panSize - 1))); + pan[i] = std::cos(i * (piTwo() / (panSize - 1))); for (; i < static_cast(pan.size()); ++i) pan[i] = pan[panSize - 1]; diff --git a/src/sfizz/SIMDNEON.cpp b/src/sfizz/SIMDNEON.cpp index eb79cf7f..6a6dc8d1 100644 --- a/src/sfizz/SIMDNEON.cpp +++ b/src/sfizz/SIMDNEON.cpp @@ -29,10 +29,9 @@ #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 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 74adfb66..1b5c466c 100644 --- a/src/sfizz/SIMDSSE.cpp +++ b/src/sfizz/SIMDSSE.cpp @@ -16,10 +16,9 @@ #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 ByteAlignment { TypeAlignment * sizeof(Type) }; +constexpr uintptr_t ByteAlignmentMask { ByteAlignment - 1 }; struct AlignmentSentinels { float* nextAligned; @@ -623,7 +622,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 +659,7 @@ void sfz::width(absl::Span widthEnvelope, absl::Span); + const auto mmPiFour = _mm_set_ps1(piFour()); __m128 mmCos; __m128 mmSin; while (width < lastAligned) { diff --git a/src/sfizz/SfzHelpers.h b/src/sfizz/SfzHelpers.h index 4a69ba95..a50c3428 100644 --- a/src/sfizz/SfzHelpers.h +++ b/src/sfizz/SfzHelpers.h @@ -10,7 +10,9 @@ //#include #include #include +#include "Macros.h" #include "Config.h" +#include "MathHelpers.h" namespace sfz { @@ -85,7 +87,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 +126,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; } /** @@ -229,7 +231,7 @@ using modFunction = std::function; * @param modifier the modifier value */ template -constexpr void addToBase(T& base, T modifier) +inline CXX14_CONSTEXPR void addToBase(T& base, T modifier) { base += modifier; } @@ -240,7 +242,7 @@ constexpr void addToBase(T& base, T modifier) * @param base * @param modifier */ -constexpr void multiplyByCents(float& base, int modifier) +inline CXX14_CONSTEXPR void multiplyByCents(float& base, int modifier) { base *= centsFactor(modifier); } 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 ) + ); } diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 09d4e965..b02ebd00 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -8,17 +8,18 @@ #include "AtomicGuard.h" #include "Config.h" #include "Debug.h" +#include "Macros.h" #include "MidiState.h" #include "ScopedFTZ.h" #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 +39,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 +84,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 +113,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) @@ -163,20 +164,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); @@ -260,7 +261,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)); @@ -279,7 +280,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(); @@ -342,7 +343,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(); } @@ -409,7 +410,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 +419,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) { @@ -432,7 +433,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++; @@ -452,7 +453,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 +472,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; @@ -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); @@ -851,12 +853,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 +873,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 +893,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); diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index 8f75c25c..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" @@ -45,7 +46,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 +64,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)); @@ -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 @@ -479,7 +485,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 * twoPi() / sampleRate; fill(jumps, step); if (region->bendStep > 1) @@ -496,8 +502,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 / twoPi()); + phase -= twoPi() * static_cast(numTwoPiWraps); } } 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() 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 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; 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")