Merge pull request #111 from paulfd/gcc-4.9

GCC 4.9 compatibility
This commit is contained in:
Paul Ferrand 2020-03-14 18:02:19 +01:00 committed by GitHub
commit 4695656ea5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
74 changed files with 391 additions and 332 deletions

View file

@ -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

View file

@ -30,7 +30,7 @@ public:
output.resize(state.range(0));
}
void TearDown(const ::benchmark::State &state[[maybe_unused]])
void TearDown(const ::benchmark::State& /* state */)
{
}

View file

@ -5,6 +5,7 @@
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#include "SIMDHelpers.h"
#include "Macros.h"
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
@ -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<float> input;

View file

@ -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 */) {
}

View file

@ -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 */) {
}

View file

@ -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 */) {
}

View file

@ -25,7 +25,7 @@ public:
sfz::cumsum<float, false>(input, absl::MakeSpan(input));
}
void TearDown(const ::benchmark::State& state [[maybe_unused]]) {
void TearDown(const ::benchmark::State& /* state */) {
}

View file

@ -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 */) {
}

View file

@ -23,7 +23,7 @@ public:
sfz::cumsum<float, false>(input, absl::MakeSpan(input));
}
void TearDown(const ::benchmark::State& state [[maybe_unused]])
void TearDown(const ::benchmark::State& /* state */)
{
}

View file

@ -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 { };

View file

@ -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 { };

View file

@ -10,6 +10,7 @@
#define DR_FLAC_IMPLEMENTATION
#include "dr_flac.h"
#include "ghc/filesystem.hpp"
#include "absl/memory/memory.h"
#include <memory>
#ifndef NDEBUG
#include <iostream>
@ -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<sfz::Buffer<float>>(sndfile.channels() * sndfile.frames());
buffer = absl::make_unique<sfz::Buffer<float>>(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<sfz::Buffer<float>>(flac->channels * flac->totalPCMFrameCount);
buffer = absl::make_unique<sfz::Buffer<float>>(flac->channels * flac->totalPCMFrameCount);
drflac_read_pcm_frames_f32(flac, flac->totalPCMFrameCount, buffer->data());
}
}

View file

@ -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 */) {
}

View file

@ -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 */) {
}

View file

@ -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 */) {
}

View file

@ -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 */) {
}

View file

@ -36,7 +36,7 @@ public:
});
}
void TearDown(const ::benchmark::State& state [[maybe_unused]])
void TearDown(const ::benchmark::State& /* state */)
{
}

View file

@ -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 */)
{
}

View file

@ -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 */)
{
}

View file

@ -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 */)
{
}

View file

@ -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 */) {
}

View file

@ -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 */)
{
}

View file

@ -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<float>(span2, 1.0f);
sfz::add<float>(span1, span2);
sfz::applyGain<float>(piFour<float>, span2);
sfz::applyGain<float>(piFour<float>(), span2);
sfz::cos<float>(span2, span1);
sfz::sin<float>(span2, span2);
sfz::applyGain<float>(span1, absl::MakeSpan(left));

View file

@ -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<float> dist { 0.001f, 1.0f };
@ -28,7 +28,7 @@ public:
sfz::cumsum<int>(jumps, absl::MakeSpan(offsets));
}
void TearDown(const ::benchmark::State& state [[maybe_unused]]) {
void TearDown(const ::benchmark::State& /* state */) {
}

0
benchmarks/BM_random.cpp Normal file
View file

View file

@ -12,7 +12,7 @@
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"
#include "AudioBuffer.h"
#include <memory>
#include "absl/memory/memory.h"
#ifndef NDEBUG
#include <iostream>
#endif
@ -30,10 +30,10 @@ public:
sndfile = SndfileHandle(rootPath.c_str());
numFrames = static_cast<size_t>(sndfile.frames());
output = std::make_unique<sfz::AudioBuffer<float>>(sndfile.channels(), sndfile.frames());
output = absl::make_unique<sfz::AudioBuffer<float>>(sndfile.channels(), sndfile.frames());
}
void TearDown(const ::benchmark::State& state [[maybe_unused]]) {
void TearDown(const ::benchmark::State& /* state */) {
}
ghc::filesystem::path getPath()

View file

@ -8,7 +8,7 @@
#include "AudioBuffer.h"
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <memory>
#include "absl/memory/memory.h"
#include <samplerate.h>
#include <sndfile.hh>
#include "ghc/filesystem.hpp"
@ -151,8 +151,8 @@ void upsample8xStage<true>(absl::Span<const float> input, absl::Span<float> outp
template <class T, bool SIMD=false>
std::unique_ptr<sfz::AudioBuffer<T>> upsample2x(const sfz::AudioBuffer<T>& buffer)
{
// auto tempBuffer = std::make_unique<sfz::Buffer<T>>(buffer.getNumFrames() * 2);
auto outputBuffer = std::make_unique<sfz::AudioBuffer<T>>(buffer.getNumChannels(), buffer.getNumFrames() * 2);
// auto tempBuffer = absl::make_unique<sfz::Buffer<T>>(buffer.getNumFrames() * 2);
auto outputBuffer = absl::make_unique<sfz::AudioBuffer<T>>(buffer.getNumChannels(), buffer.getNumFrames() * 2);
for (size_t channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) {
upsample2xStage<SIMD>(buffer.getConstSpan(channelIdx), outputBuffer->getSpan(channelIdx));
}
@ -162,8 +162,8 @@ std::unique_ptr<sfz::AudioBuffer<T>> upsample2x(const sfz::AudioBuffer<T>& buffe
template <class T, bool SIMD=false>
std::unique_ptr<sfz::AudioBuffer<T>> upsample4x(const sfz::AudioBuffer<T>& buffer)
{
auto tempBuffer = std::make_unique<sfz::Buffer<T>>(buffer.getNumFrames() * 2);
auto outputBuffer = std::make_unique<sfz::AudioBuffer<T>>(buffer.getNumChannels(), buffer.getNumFrames() * 4);
auto tempBuffer = absl::make_unique<sfz::Buffer<T>>(buffer.getNumFrames() * 2);
auto outputBuffer = absl::make_unique<sfz::AudioBuffer<T>>(buffer.getNumChannels(), buffer.getNumFrames() * 4);
for (size_t channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) {
upsample2xStage<SIMD>(buffer.getConstSpan(channelIdx), absl::MakeSpan(*tempBuffer));
upsample4xStage<SIMD>(absl::MakeConstSpan(*tempBuffer), outputBuffer->getSpan(channelIdx));
@ -174,9 +174,9 @@ std::unique_ptr<sfz::AudioBuffer<T>> upsample4x(const sfz::AudioBuffer<T>& buffe
template <class T, bool SIMD=false>
std::unique_ptr<sfz::AudioBuffer<T>> upsample8x(const sfz::AudioBuffer<T>& buffer)
{
auto tempBuffer2x = std::make_unique<sfz::Buffer<T>>(buffer.getNumFrames() * 2);
auto tempBuffer4x = std::make_unique<sfz::Buffer<T>>(buffer.getNumFrames() * 4);
auto outputBuffer = std::make_unique<sfz::AudioBuffer<T>>(buffer.getNumChannels(), buffer.getNumFrames() * 8);
auto tempBuffer2x = absl::make_unique<sfz::Buffer<T>>(buffer.getNumFrames() * 2);
auto tempBuffer4x = absl::make_unique<sfz::Buffer<T>>(buffer.getNumFrames() * 4);
auto outputBuffer = absl::make_unique<sfz::AudioBuffer<T>>(buffer.getNumChannels(), buffer.getNumFrames() * 8);
for (size_t channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) {
upsample2xStage<SIMD>(buffer.getConstSpan(channelIdx), absl::MakeSpan(*tempBuffer2x));
upsample4xStage<SIMD>(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<sfz::Buffer<float>>(numChannels * numFrames);
interleavedBuffer = absl::make_unique<sfz::Buffer<float>>(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<sfz::AudioBuffer<float>>(numChannels, numFrames);
auto baseBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, numFrames);
sfz::readInterleaved<float>(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1));
auto outBuffer = upsample2x<float, false>(*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<sfz::AudioBuffer<float>>(numChannels, numFrames);
auto baseBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, numFrames);
sfz::readInterleaved<float>(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1));
auto outBuffer = upsample4x<float, false>(*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<sfz::AudioBuffer<float>>(numChannels, numFrames);
auto baseBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, numFrames);
sfz::readInterleaved<float>(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1));
auto outBuffer = upsample8x<float, false>(*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<sfz::AudioBuffer<float>>(numChannels, numFrames);
auto baseBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, numFrames);
sfz::readInterleaved<float>(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1));
auto outBuffer = upsample2x<float, true>(*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<sfz::AudioBuffer<float>>(numChannels, numFrames);
auto baseBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, numFrames);
sfz::readInterleaved<float>(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1));
auto outBuffer = upsample4x<float, true>(*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<sfz::AudioBuffer<float>>(numChannels, numFrames);
auto baseBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, numFrames);
sfz::readInterleaved<float>(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1));
auto outBuffer = upsample8x<float, true>(*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<sfz::Buffer<float>>(2 * numChannels * numFrames);
auto intermediateBuffer = absl::make_unique<sfz::Buffer<float>>(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<long>(numFrames);
srcData.output_frames = static_cast<long>(2 * numFrames);
src_simple(&srcData, SRC_SINC_BEST_QUALITY, static_cast<int>(numChannels));
auto outBuffer = std::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
auto outBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
sfz::readInterleaved<float>(*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<sfz::Buffer<float>>(2 * numChannels * numFrames);
auto intermediateBuffer = absl::make_unique<sfz::Buffer<float>>(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<long>(numFrames);
srcData.output_frames = static_cast<long>(2 * numFrames);
src_simple(&srcData, SRC_SINC_MEDIUM_QUALITY, static_cast<int>(numChannels));
auto outBuffer = std::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
auto outBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
sfz::readInterleaved<float>(*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<sfz::Buffer<float>>(2 * numChannels * numFrames);
auto intermediateBuffer = absl::make_unique<sfz::Buffer<float>>(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<long>(numFrames);
srcData.output_frames = static_cast<long>(2 * numFrames);
src_simple(&srcData, SRC_SINC_FASTEST, static_cast<int>(numChannels));
auto outBuffer = std::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
auto outBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
sfz::readInterleaved<float>(*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<sfz::Buffer<float>>(2 * numChannels * numFrames);
auto intermediateBuffer = absl::make_unique<sfz::Buffer<float>>(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<long>(numFrames);
srcData.output_frames = static_cast<long>(2 * numFrames);
src_simple(&srcData, SRC_SINC_BEST_QUALITY, static_cast<int>(numChannels));
auto outBuffer = std::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
auto outBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
sfz::readInterleaved<float>(*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<sfz::Buffer<float>>(2 * numChannels * numFrames);
auto intermediateBuffer = absl::make_unique<sfz::Buffer<float>>(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<long>(numFrames);
srcData.output_frames = static_cast<long>(2 * numFrames);
src_simple(&srcData, SRC_SINC_MEDIUM_QUALITY, static_cast<int>(numChannels));
auto outBuffer = std::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
auto outBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
sfz::readInterleaved<float>(*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<sfz::Buffer<float>>(2 * numChannels * numFrames);
auto intermediateBuffer = absl::make_unique<sfz::Buffer<float>>(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<long>(numFrames);
srcData.output_frames = static_cast<long>(2 * numFrames);
src_simple(&srcData, SRC_SINC_FASTEST, static_cast<int>(numChannels));
auto outBuffer = std::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
auto outBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
sfz::readInterleaved<float>(*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<sfz::Buffer<float>>(2 * numChannels * numFrames);
auto intermediateBuffer = absl::make_unique<sfz::Buffer<float>>(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<long>(numFrames);
srcData.output_frames = static_cast<long>(2 * numFrames);
src_simple(&srcData, SRC_SINC_BEST_QUALITY, static_cast<int>(numChannels));
auto outBuffer = std::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
auto outBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
sfz::readInterleaved<float>(*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<sfz::Buffer<float>>(2 * numChannels * numFrames);
auto intermediateBuffer = absl::make_unique<sfz::Buffer<float>>(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<long>(numFrames);
srcData.output_frames = static_cast<long>(2 * numFrames);
src_simple(&srcData, SRC_SINC_MEDIUM_QUALITY, static_cast<int>(numChannels));
auto outBuffer = std::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
auto outBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
sfz::readInterleaved<float>(*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<sfz::Buffer<float>>(2 * numChannels * numFrames);
auto intermediateBuffer = absl::make_unique<sfz::Buffer<float>>(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<long>(numFrames);
srcData.output_frames = static_cast<long>(2 * numFrames);
src_simple(&srcData, SRC_SINC_FASTEST, static_cast<int>(numChannels));
auto outBuffer = std::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
auto outBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, 2 * numFrames);
sfz::readInterleaved<float>(*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<sfz::AudioBuffer<float>>(numChannels, numFrames);
auto baseBuffer = absl::make_unique<sfz::AudioBuffer<float>>(numChannels, numFrames);
sfz::readInterleaved<float>(*interleavedBuffer, baseBuffer->getSpan(0), baseBuffer->getSpan(1));
auto outBuffer = upsample8x<float>(*baseBuffer);
benchmark::DoNotOptimize(outBuffer);

View file

@ -11,7 +11,7 @@
#include "ghc/filesystem.hpp"
#include "Oversampler.h"
#include "AudioBuffer.h"
#include <memory>
#include "absl/memory/memory.h"
#include <iostream>
@ -75,10 +75,10 @@ public:
sndfile = SndfileHandle(rootPath.c_str());
numFrames = static_cast<size_t>(sndfile.frames());
output = std::make_unique<sfz::AudioBuffer<float>>(sndfile.channels(), numFrames * 4);
output = absl::make_unique<sfz::AudioBuffer<float>>(sndfile.channels(), numFrames * 4);
}
void TearDown(const ::benchmark::State& state [[maybe_unused]]) {
void TearDown(const ::benchmark::State& /* state */) {
}
ghc::filesystem::path getPath()

View file

@ -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 */) {
}

View file

@ -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 */) {
}

View file

@ -9,7 +9,7 @@
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"
#include "ghc/filesystem.hpp"
#include <memory>
#include "absl/memory/memory.h"
#ifndef NDEBUG
#include <iostream>
#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<sfz::Buffer<float>>(sndfile.channels() * sndfile.frames());
buffer = absl::make_unique<sfz::Buffer<float>>(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<sfz::Buffer<float>>(wav.channels * wav.totalPCMFrameCount);
buffer = absl::make_unique<sfz::Buffer<float>>(wav.channels * wav.totalPCMFrameCount);
drwav_read_pcm_frames_f32(&wav, wav.totalPCMFrameCount, buffer->data());
}
}

View file

@ -37,7 +37,7 @@ public:
span3 = absl::MakeSpan(temp3);
}
void TearDown(const ::benchmark::State& state [[maybe_unused]]) {
void TearDown(const ::benchmark::State& /* state */) {
}

View file

@ -22,6 +22,7 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "sfizz/Synth.h"
#include "sfizz/Macros.h"
#include <absl/flags/parse.h>
#include <absl/flags/flag.h>
#include <absl/types/span.h>
@ -37,7 +38,6 @@
#include <string_view>
#include <chrono>
#include <thread>
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<bool> 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<sfz::Synth*>(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';

View file

@ -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)

View file

@ -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<class T>
constexpr T decrement(T x) {
return x - 1;
}
template<class T>
constexpr T increment(T x) {
return x + 1;
}
template<class T>
constexpr T or_equal(T x, unsigned u) {
return (x | x >> u);
}
template<class T, class... Args>
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<Derived&>(*this).do_push(std::forward<T>(element), head);
}
auto pop() noexcept {
Derived& pop() noexcept {
unsigned tail;
if(Derived::spsc_) {
tail = tail_.load(X);

View file

@ -12,20 +12,11 @@
#pragma once
#include <stddef.h>
#include <stdbool.h>
#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,

View file

@ -7,16 +7,7 @@
#include <string>
#include <vector>
#include <memory>
#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
{

View file

@ -14,7 +14,7 @@ namespace sfz {
template <class Type>
void ADSREnvelope<Type>::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<int>(timeInSeconds * sampleRate);
};
@ -54,7 +54,7 @@ Type ADSREnvelope<Type>::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<Type>::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<Type>::getNextValue() noexcept
currentState = State::Sustain;
currentValue = sustain;
[[fallthrough]];
// fallthrough
case State::Sustain:
if (freeRunning)
shouldRelease = true;
@ -92,7 +92,7 @@ Type ADSREnvelope<Type>::getNextValue() noexcept
currentState = State::Done;
currentValue = 0.0;
[[fallthrough]];
// fallthrough
default:
return 0.0;
}
@ -116,7 +116,7 @@ void ADSREnvelope<Type>::getBlock(absl::Span<Type> output) noexcept
currentState = State::Attack;
step = (peak - start) / (attack > 0 ? attack : 1);
[[fallthrough]];
// fallthrough
case State::Attack:
length = min(remainingSamples, attack);
currentValue = linearRamp<Type>(output, currentValue, step);
@ -128,7 +128,7 @@ void ADSREnvelope<Type>::getBlock(absl::Span<Type> output) noexcept
currentValue = peak;
currentState = State::Hold;
[[fallthrough]];
// fallthrough
case State::Hold:
length = min(remainingSamples, hold);
fill<Type>(output, currentValue);
@ -140,7 +140,7 @@ void ADSREnvelope<Type>::getBlock(absl::Span<Type> 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<Type>(output, currentValue, step);
@ -152,7 +152,7 @@ void ADSREnvelope<Type>::getBlock(absl::Span<Type> output) noexcept
currentValue = sustain;
currentState = State::Sustain;
[[fallthrough]];
// fallthrough
case State::Sustain:
if (freeRunning)
shouldRelease = true;
@ -168,9 +168,9 @@ void ADSREnvelope<Type>::getBlock(absl::Span<Type> output) noexcept
currentValue = 0.0;
currentState = State::Done;
[[fallthrough]];
// fallthrough
case State::Done:
[[fallthrough]];
// fallthrough
default:
break;
}

View file

@ -10,7 +10,7 @@
#include "Debug.h"
#include "LeakDetector.h"
#include "absl/types/span.h"
#include <memory>
#include "absl/memory/memory.h"
#include <array>
namespace sfz
@ -28,7 +28,7 @@ namespace sfz
template <class Type, size_t MaxChannels = sfz::config::numChannels, unsigned int Alignment = SIMDConfig::defaultAlignment>
class AudioBuffer {
public:
using value_type = std::remove_cv_t<Type>;
using value_type = typename std::remove_cv<Type>::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<buffer_type>(numFrames);
buffers[i] = absl::make_unique<buffer_type>(numFrames);
}
/**
@ -170,7 +170,7 @@ public:
void addChannel()
{
if (numChannels < MaxChannels)
buffers[numChannels++] = std::make_unique<buffer_type>(numFrames);
buffers[numChannels++] = absl::make_unique<buffer_type>(numFrames);
}
/**

View file

@ -148,7 +148,7 @@ public:
* @tparam Alignment the alignment block size for the platform
* @param audioBuffer the source AudioBuffer.
*/
template <class U, size_t N, unsigned int Alignment, typename = std::enable_if<N <= MaxChannels>, typename = std::enable_if_t<std::is_const<U>::value, int>>
template <class U, size_t N, unsigned int Alignment, typename = typename std::enable_if<N <= MaxChannels>::type, typename = typename std::enable_if<std::is_const<U>::value, int>::type>
AudioSpan(AudioBuffer<U, N, Alignment>& audioBuffer)
: numFrames(audioBuffer.getNumFrames())
, numChannels(audioBuffer.getNumChannels())

View file

@ -31,6 +31,8 @@
#include <memory>
#include <type_traits>
#include <utility>
#include <atomic>
#ifdef DEBUG
#include <iostream>
#endif
@ -92,6 +94,8 @@ private:
std::atomic<int> 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 Type, unsigned int Alignment = SIMDConfig::defaultAlignment>
class Buffer {
public:
using value_type = std::remove_cv_t<Type>;
using value_type = typename std::remove_cv<Type>::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<pointer>(newData);
normalData = static_cast<pointer>(std::align(Alignment, alignedSize, newData, tempSize));
normalData = static_cast<pointer>(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>::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 };

View file

@ -26,6 +26,7 @@
#pragma once
#include "Config.h"
#include "Defaults.h"
#include "Macros.h"
#include "LeakDetector.h"
#include "SfzHelpers.h"
#include <absl/types/optional.h>
@ -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));
}
/**

View file

@ -3,7 +3,6 @@
#include <thread>
#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();

View file

@ -44,21 +44,21 @@ std::unique_ptr<Effect> EffectFactory::makeEffect(absl::Span<const Opcode> membe
if (!opcode) {
DBG("The effect does not specify a type");
return std::make_unique<sfz::fx::Nothing>();
return absl::make_unique<sfz::fx::Nothing>();
}
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<sfz::fx::Nothing>();
return absl::make_unique<sfz::fx::Nothing>();
}
auto fx = it->make(members);
if (!fx) {
DBG("Could not instantiate effect of type: " << type);
return std::make_unique<sfz::fx::Nothing>();
return absl::make_unique<sfz::fx::Nothing>();
}
return fx;

View file

@ -53,7 +53,7 @@ void EventEnvelope<Type>::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<int, Type>& lhs, const std::pair<int, Type>& rhs) {
return lhs.first < rhs.first;
});

View file

@ -94,7 +94,7 @@ protected:
Type currentValue { 0.0 };
private:
static_assert(std::is_arithmetic<Type>::value, "Type should be arithmetic");
std::function<Type(Type)> function { [](Type input) { return input; } };
std::function<Type(Type)> function { [](Type input) -> Type { return input; } };
int maxCapacity { config::defaultSamplesPerBlock };
void prepareEvents(int blockLength);
bool resetEvents { false };

View file

@ -32,10 +32,10 @@
#include "AtomicGuard.h"
#include "absl/types/span.h"
#include "absl/strings/match.h"
#include "absl/memory/memory.h"
#include <memory>
#include <sndfile.hh>
#include <thread>
using namespace std::chrono_literals;
template <class T>
void readBaseFile(SndfileHandle& sndFile, sfz::AudioBuffer<T>& output, uint32_t numFrames)
@ -57,13 +57,13 @@ void readBaseFile(SndfileHandle& sndFile, sfz::AudioBuffer<T>& output, uint32_t
template <class T>
std::unique_ptr<sfz::AudioBuffer<T>> readFromFile(SndfileHandle& sndFile, uint32_t numFrames, sfz::Oversampling factor)
{
auto baseBuffer = std::make_unique<sfz::AudioBuffer<T>>();
auto baseBuffer = absl::make_unique<sfz::AudioBuffer<T>>();
readBaseFile(sndFile, *baseBuffer, numFrames);
if (factor == sfz::Oversampling::x1)
return baseBuffer;
auto outputBuffer = std::make_unique<sfz::AudioBuffer<T>>(sndFile.channels(), numFrames * static_cast<int>(factor));
auto outputBuffer = absl::make_unique<sfz::AudioBuffer<T>>(sndFile.channels(), numFrames * static_cast<int>(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<float>(sndFile, framesToLoad, oversamplingFactor);
}
} else {
preloadedFiles.insert_or_assign(filename, {
readFromFile<float>(sndFile, framesToLoad, oversamplingFactor),
static_cast<float>(oversamplingFactor) * static_cast<float>(sndFile.samplerate())
});
const float sourceSampleRate { static_cast<float>(oversamplingFactor) * static_cast<float>(sndFile.samplerate()) };
PreloadedFileHandle handle { readFromFile<float>(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));
}
}

View file

@ -44,15 +44,16 @@ namespace sfz {
using AudioBufferPtr = std::shared_ptr<AudioBuffer<float>>;
// Strict C++11 disallows member initialization if aggregate initialization is to be used...
struct PreloadedFileHandle
{
std::shared_ptr<AudioBuffer<float>> preloadedData {};
float sampleRate { config::defaultSampleRate };
std::shared_ptr<AudioBuffer<float>> preloadedData;
float sampleRate;
};
struct FilePromise
{
auto getData()
AudioSpan<const float> getData()
{
if (dataReady)
return AudioSpan<const float>(fileData);
@ -78,7 +79,7 @@ struct FilePromise
AudioBuffer<float> fileData {};
float sampleRate { config::defaultSampleRate };
Oversampling oversamplingFactor { config::defaultOversamplingFactor };
std::atomic_size_t availableFrames { 0 };
std::atomic<size_t> availableFrames { 0 };
std::atomic<bool> dataReady { false };
std::chrono::time_point<std::chrono::high_resolution_clock> creationTime;

View file

@ -4,7 +4,6 @@
#include "AtomicGuard.h"
#include <thread>
#include <chrono>
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();

View file

@ -13,8 +13,6 @@
#include <sstream>
#include <cmath>
using namespace std::chrono_literals;
template<class T>
void printStatistics(std::vector<T>& 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));
}
}

View file

@ -6,6 +6,7 @@
#pragma once
#include "Config.h"
#include "LeakDetector.h"
#include "atomic_queue/atomic_queue.h"
#include <vector>
#include <string>
@ -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);
};
}

25
src/sfizz/Macros.h Normal file
View file

@ -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

View file

@ -10,6 +10,7 @@
*/
#pragma once
#include "Config.h"
#include "Macros.h"
#include <algorithm>
#include <cmath>
#include <random>
@ -17,25 +18,25 @@
template<class T>
constexpr T max(T op1, T op2)
{
return std::max(op1, op2);
return op1 > op2 ? op1 : op2;
}
template<class T, class... Args>
constexpr T max(T op1, Args... rest)
{
return std::max(op1, max(rest...));
return max(op1, max(rest...));
}
template<class T>
constexpr T min(T op1, T op2)
{
return std::min(op1, op2);
return op1 > op2 ? op2 : op1;
}
template<class T, class... Args>
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<class T>
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<int Increment = 1, class T>
constexpr void incrementAll(T& only)
inline CXX14_CONSTEXPR void incrementAll(T& only)
{
only += Increment;
}
template<int Increment = 1, class T, class... Args>
constexpr void incrementAll(T& first, Args&... rest)
inline CXX14_CONSTEXPR void incrementAll(T& first, Args&... rest)
{
first += Increment;
incrementAll<Increment>(rest...);
@ -148,18 +147,18 @@ constexpr ValueType linearInterpolation(ValueType left, ValueType right, ValueTy
return left * leftCoeff + right * rightCoeff;
}
template <class Type>
constexpr Type pi { static_cast<Type>(3.141592653589793238462643383279502884) };
template <class Type>
constexpr Type twoPi { static_cast<Type>(2) * pi<Type> };
template <class Type>
constexpr Type piTwo { pi<Type> / static_cast<Type>(2) };
template <class Type>
constexpr Type piFour { pi<Type> / static_cast<Type>(4) };
template <class Type>
constexpr Type sqrtTwo { static_cast<Type>(1.414213562373095048801688724209698078569671875376948073176) };
template <class Type>
constexpr Type sqrtTwoInv { static_cast<Type>(0.707106781186547524400844362104849039284835937688474036588) };
template<class Type>
constexpr Type pi() { return static_cast<Type>(3.141592653589793238462643383279502884); };
template<class Type>
constexpr Type twoPi() { return pi<Type>() * 2; };
template<class Type>
constexpr Type piTwo() { return pi<Type>() / 2; };
template<class Type>
constexpr Type piFour() { return pi<Type>() / 4; };
template<class Type>
constexpr Type sqrtTwo() { return static_cast<Type>(1.414213562373095048801688724209698078569671875376948073176); };
template<class Type>
constexpr Type sqrtTwoInv() { return static_cast<Type>(0.707106781186547524400844362104849039284835937688474036588); };
/**
@brief A fraction which is parameterized by integer type

View file

@ -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--;

View file

@ -134,13 +134,13 @@ private:
* @brief Stores the note on times.
*
*/
MidiNoteArray<NoteOnTime> noteOnTimes { };
MidiNoteArray<NoteOnTime> noteOnTimes;
/**
* @brief Stores the velocity of the note ons for currently
* depressed notes.
*
*/
MidiNoteArray<uint8_t> lastNoteVelocities { };
MidiNoteArray<uint8_t> lastNoteVelocities;
/**
* @brief Current known values for the CCs.
*

View file

@ -26,7 +26,7 @@ public:
template <class C>
static Type normalizedGain(Type cutoff, C sampleRate)
{
return std::tan(cutoff / static_cast<Type>(sampleRate) * pi<float>);
return std::tan(cutoff / static_cast<Type>(sampleRate) * pi<float>());
}
OnePoleFilter(Type gain)

View file

@ -11,6 +11,7 @@
#include "SfzHelpers.h"
#include "StringViewHelpers.h"
#include <absl/types/optional.h>
#include "absl/meta/type_traits.h"
#include <string_view>
#include <vector>
#include <type_traits>
@ -45,7 +46,7 @@ struct Opcode {
* @param validRange the range of admitted values
* @return absl::optional<ValueType> the cast value, or null
*/
template <typename ValueType, std::enable_if_t<std::is_integral<ValueType>::value, int> = 0>
template <typename ValueType, absl::enable_if_t<std::is_integral<ValueType>::value, int> = 0>
inline absl::optional<ValueType> readOpcode(absl::string_view value, const Range<ValueType>& validRange)
{
int64_t returnedValue;
@ -74,7 +75,7 @@ inline absl::optional<ValueType> readOpcode(absl::string_view value, const Range
* @param validRange the range of admitted values
* @return absl::optional<ValueType> the cast value, or null
*/
template <typename ValueType, std::enable_if_t<std::is_floating_point<ValueType>::value, int> = 0>
template <typename ValueType, absl::enable_if_t<std::is_floating_point<ValueType>::value, int> = 0>
inline absl::optional<ValueType> readOpcode(absl::string_view value, const Range<ValueType>& validRange)
{
float returnedValue;

View file

@ -78,11 +78,11 @@ void sfz::Oversampler::stream(const sfz::AudioBuffer<float>& 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<float>& input, sfz::AudioBu
{
// std::cout << "Input frames: " << inputFrameCounter << "/" << numFrames << '\n';
const auto thisChunkSize = std::min(chunkSize, numFrames - inputFrameCounter);
const auto outputChunkSize { thisChunkSize * static_cast<int>(factor) };
const auto outputChunkSize = thisChunkSize * static_cast<int>(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);

View file

@ -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))
{
}

View file

@ -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<int, float>& val) { return val.first >= velocity; });
auto before = after == velocityPoints.begin() ? velocityPoints.begin() : after - 1;
// Linear interpolation
float relativePositionInSegment {

View file

@ -748,7 +748,7 @@ namespace _internals {
int i = 0;
for (; i < panSize; ++i)
pan[i] = std::cos(i * (piTwo<double> / (panSize - 1)));
pan[i] = std::cos(i * (piTwo<double>() / (panSize - 1)));
for (; i < static_cast<int>(pan.size()); ++i)
pan[i] = pan[panSize - 1];

View file

@ -29,10 +29,9 @@
#include <arm_neon.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 };
float* nextAligned(const float* ptr)
{

View file

@ -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<float, true>(absl::Span<const float> panEnvelope, absl::Span<float
}
const auto mmOne = _mm_set_ps1(1.0f);
const auto mmPiFour = _mm_set_ps1(piFour<float>);
const auto mmPiFour = _mm_set_ps1(piFour<float>());
__m128 mmCos;
__m128 mmSin;
while (pan < lastAligned) {
@ -660,7 +659,7 @@ void sfz::width<float, true>(absl::Span<const float> widthEnvelope, absl::Span<f
incrementAll(width, left, right);
}
const auto mmPiFour = _mm_set_ps1(piFour<float>);
const auto mmPiFour = _mm_set_ps1(piFour<float>());
__m128 mmCos;
__m128 mmSin;
while (width < lastAligned) {

View file

@ -10,7 +10,9 @@
//#include <string>
#include <array>
#include <cmath>
#include "Macros.h"
#include "Config.h"
#include "MathHelpers.h"
namespace sfz
{
@ -85,7 +87,7 @@ template<class T>
constexpr float normalizeCC(T ccValue)
{
static_assert(std::is_integral<T>::value, "Requires an integral T");
return static_cast<float>(std::min(std::max(ccValue, static_cast<T>(0)), static_cast<T>(127))) / 127.0f;
return static_cast<float>(min(max(ccValue, static_cast<T>(0)), static_cast<T>(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<void(T&, U)>;
* @param modifier the modifier value
*/
template<class T>
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);
}

View file

@ -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 )
);
}

View file

@ -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 <algorithm>
#include <chrono>
#include <iostream>
#include <utility>
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<Opcode>& m
void sfz::Synth::buildRegion(const std::vector<Opcode>& regionOpcodes)
{
auto lastRegion = std::make_unique<Region>(resources.midiState, defaultPath);
auto lastRegion = absl::make_unique<Region>(resources.midiState, defaultPath);
auto parseOpcodes = [&](const auto& opcodes) {
auto parseOpcodes = [&](const std::vector<Opcode>& 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<Opcode>& 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<Opcode>& 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<int, float>& lhs, const std::pair<int, float>& 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<int, float>(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>& 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<Voice>(resources));
voices.push_back(absl::make_unique<Voice>(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);

View file

@ -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<float>(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<float> buffer) noexcept
auto bends = tempSpan2.first(buffer.getNumFrames());
auto phases = tempSpan2.first(buffer.getNumFrames());
const float step = baseFrequency * twoPi<float> / sampleRate;
const float step = baseFrequency * twoPi<float>() / sampleRate;
fill<float>(jumps, step);
if (region->bendStep > 1)
@ -496,8 +502,8 @@ void sfz::Voice::fillWithGenerator(AudioSpan<float> buffer) noexcept
copy<float>(leftSpan, rightSpan);
// Wrap the phase so we don't loose too much precision on longer notes
const auto numTwoPiWraps = static_cast<int>(phase / twoPi<float>);
phase -= twoPi<float> * static_cast<float>(numTwoPiWraps);
const auto numTwoPiWraps = static_cast<int>(phase / twoPi<float>());
phase -= twoPi<float>() * static_cast<float>(numTwoPiWraps);
}
}

View file

@ -37,7 +37,7 @@
#include "Lofi.h"
#include "Opcode.h"
#include <memory>
#include "absl/memory/memory.h"
#include <algorithm>
#include <cstring>
#include <cmath>
@ -79,7 +79,7 @@ namespace fx {
std::unique_ptr<Effect> Lofi::makeInstance(absl::Span<const Opcode> members)
{
auto fx = std::make_unique<Lofi>();
auto fx = absl::make_unique<Lofi>();
for (const Opcode& opcode : members) {
switch (opcode.lettersOnlyHash) {
@ -92,7 +92,7 @@ namespace fx {
}
}
return fx;
return std::move(fx);
}
///

View file

@ -6,10 +6,11 @@
#include "Synth.h"
#include "sfizz.hpp"
#include "absl/memory/memory.h"
sfz::Sfizz::Sfizz()
{
synth = std::make_unique<sfz::Synth>();
synth = absl::make_unique<sfz::Synth>();
}
sfz::Sfizz::~Sfizz()

View file

@ -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

View file

@ -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")

View file

@ -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<float> 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<float> moveConstructed { std::move(buffer) };
// REQUIRE(buffer.empty());

View file

@ -134,7 +134,7 @@ TEST_CASE("[LinearEnvelope] 2 events, with another block call")
TEST_CASE("[LinearEnvelope] 2 events, function")
{
sfz::LinearEnvelope<float> 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<float, 8> output;

View file

@ -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")