Merge branch 'windows' into develop

This commit is contained in:
Paul Ferrand 2020-01-05 11:41:18 +01:00
commit 3268bcde3a
63 changed files with 683 additions and 536 deletions

View file

@ -39,3 +39,35 @@ git submodule update --init --recursive
```
You can build with `clang`, although in that case the CMakeFile defaults to using `libc++` instead of `libstdc++`.
### Building with MSVC on windows
The simplest is to use `vcpkg` as a package manager, which will give you access to `libsndfile`.
```powershell
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg integrate install
.\vcpkg integrate powershell
```
Assuming you want to build for x64, install the relevant packages as follows
```powershell
.\vcpkg.exe install libsndfile:x64-windows zlib:x64-windows libsamplerate:x64-windows
```
In the sfizz source directory, you can then build with CMake as usual, although you should clone the windows branch:
```powershell
git clone --branch windows --recursive https://github.com/sfztools/sfizz.git
cd sfizz
mkdir build
cd build
cmake .. -DSFIZZ_JACK=OFF "-DCMAKE_TOOLCHAIN_FILE=C:\Users\Paul\source\vcpkg\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows
cmake --build . -j 16 --config Release
```
This builds the lv2 plugin in `build\lv2\Release` and the Turtle files in `build\sfizz.lv2`, but the installation procedure is not entirely automatic yet.
In particular, having the required DLLs along with `sfizz.dll` is actually not helpful because the system cannot find dlls from another dll's root directory.
You thus need to add all of `FLAC.dll`, `libsndfile-1.dll`, `vorbis.dll`, `ogg.dll`, `vorbisenc.dll` in some directory in your `PATH` variable, and manually add `sfizz.dll` to the `sfizz.lv2` directory, and the the `sfizz.lv2` directory to `%APPDATA%\Roaming\LV2`.
Ardour should then find the plugin correctly and load it without issues.

View file

@ -21,8 +21,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <benchmark/benchmark.h>
#include "Config.h"
#include "ADSREnvelope.h"
#include <benchmark/benchmark.h>
#include <algorithm>
#include <random>
#include <numeric>
@ -44,12 +45,12 @@ static void Point(benchmark::State& state) {
for (auto _ : state) {
envelope.reset(attack, release, 1.0, fixedAmount, decay, fixedAmount);
envelope.startRelease(releaseTime);
for(int offset = 0; offset < envelopeSize; offset += state.range(0))
for(int offset = 0; offset < envelopeSize; offset += static_cast<int>(state.range(0)))
for (auto& out: output)
out = envelope.getNextValue();
benchmark::DoNotOptimize(output);
}
state.counters["Per block"] = benchmark::Counter(envelopeSize / state.range(0), benchmark::Counter::kIsRate);
state.counters["Per block"] = benchmark::Counter(envelopeSize / static_cast<double>(state.range(0)), benchmark::Counter::kIsRate);
}
static void Block(benchmark::State& state) {
@ -58,14 +59,14 @@ static void Block(benchmark::State& state) {
for (auto _ : state) {
envelope.reset(attack, release, 1.0, fixedAmount, decay, fixedAmount);
envelope.startRelease(releaseTime);
for(int offset = 0; offset < envelopeSize; offset += state.range(0))
for(int offset = 0; offset < envelopeSize; offset += static_cast<int>(state.range(0)))
envelope.getBlock(absl::MakeSpan(output));
benchmark::DoNotOptimize(output);
}
state.counters["Per block"] = benchmark::Counter(envelopeSize / state.range(0), benchmark::Counter::kIsRate);
state.counters["Per block"] = benchmark::Counter(envelopeSize / static_cast<double>(state.range(0)), benchmark::Counter::kIsRate);
}
BENCHMARK(Point)->RangeMultiplier(2)->Range((2<<6), (2<<11));
BENCHMARK(Block)->RangeMultiplier(2)->Range((2<<6), (2<<11));
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,6 +21,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Config.h"
#include <benchmark/benchmark.h>
#include <absl/types/span.h>
#include <random>
@ -111,7 +112,7 @@ static void Low(benchmark::State& state) {
std::vector<float> output(state.range(0));
std::random_device rd { };
std::mt19937 gen { rd() };
std::normal_distribution<float> dist { };
std::generate(input.begin(), input.end(), [&]() {
return dist(gen);
@ -126,7 +127,7 @@ static void High(benchmark::State& state) {
std::vector<float> output(state.range(0));
std::random_device rd { };
std::mt19937 gen { rd() };
std::normal_distribution<float> dist { };
std::generate(input.begin(), input.end(), [&]() {
return dist(gen);
@ -141,7 +142,7 @@ static void High_Raw(benchmark::State& state) {
std::vector<float> output(state.range(0));
std::random_device rd { };
std::mt19937 gen { rd() };
std::normal_distribution<float> dist { };
std::generate(input.begin(), input.end(), [&]() {
return dist(gen);
@ -156,7 +157,7 @@ static void High_SSE(benchmark::State& state) {
std::vector<float> output(state.range(0));
std::random_device rd { };
std::mt19937 gen { rd() };
std::normal_distribution<float> dist { };
std::generate(input.begin(), input.end(), [&]() {
return dist(gen);
@ -171,4 +172,4 @@ BENCHMARK(Low)->RangeMultiplier(2)->Range((2<<5), (2<<10));
BENCHMARK(High)->RangeMultiplier(2)->Range((2<<5), (2<<10));
BENCHMARK(High_Raw)->RangeMultiplier(2)->Range((2<<5), (2<<10));
BENCHMARK(High_SSE)->RangeMultiplier(2)->Range((2<<5), (2<<10));
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,13 +21,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
#include <vector>
#include <cmath>
#include <iostream>
#include "SIMDHelpers.h"
class AddArray : public benchmark::Fixture {
public:
@ -113,4 +113,4 @@ BENCHMARK_REGISTER_F(AddArray, Scalar)->RangeMultiplier(4)->Range(1 << 2, 1 << 1
BENCHMARK_REGISTER_F(AddArray, SIMD)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(AddArray, Scalar_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(AddArray, SIMD_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,13 +21,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
#include <vector>
#include <cmath>
#include <iostream>
#include "SIMDHelpers.h"
class CopyArray : public benchmark::Fixture {
public:
@ -98,4 +98,4 @@ BENCHMARK_REGISTER_F(CopyArray, SIMD)->RangeMultiplier(4)->Range(1 << 4, 1 << 16
BENCHMARK_REGISTER_F(CopyArray, StdCopy_Unaligned)->RangeMultiplier(4)->Range(1 << 4, 1 << 16);
BENCHMARK_REGISTER_F(CopyArray, Scalar_Unaligned)->RangeMultiplier(4)->Range(1 << 4, 1 << 16);
BENCHMARK_REGISTER_F(CopyArray, SIMD_Unaligned)->RangeMultiplier(4)->Range(1 << 4, 1 << 16);
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,20 +21,20 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
#include <vector>
#include <cmath>
#include <iostream>
#include "SIMDHelpers.h"
class CumArray : public benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& state) {
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 0.1, 1 };
std::uniform_real_distribution<float> dist { 0.1f, 1.0f };
input = std::vector<float>(state.range(0));
output = std::vector<float>(state.range(0));
std::generate(input.begin(), input.end(), [&]() { return dist(gen); });
@ -82,4 +82,4 @@ BENCHMARK_REGISTER_F(CumArray, Sum_Scalar)->RangeMultiplier(4)->Range(1 << 2, 1
BENCHMARK_REGISTER_F(CumArray, Sum_SIMD)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(CumArray, Sum_Scalar_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(CumArray, Sum_SIMD_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,13 +21,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
#include <vector>
#include <cmath>
#include <iostream>
#include "SIMDHelpers.h"
#include "absl/types/span.h"
class DiffArray : public benchmark::Fixture {
@ -35,7 +35,7 @@ public:
void SetUp(const ::benchmark::State& state) {
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 0.1, 1 };
std::uniform_real_distribution<float> dist { 0.1f, 1.0f };
input = std::vector<float>(state.range(0));
output = std::vector<float>(state.range(0));
std::generate(input.begin(), input.end(), [&]() { return dist(gen); });
@ -84,4 +84,4 @@ BENCHMARK_REGISTER_F(DiffArray, Diff_Scalar)->RangeMultiplier(4)->Range(1 << 2,
BENCHMARK_REGISTER_F(DiffArray, Diff_SIMD)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(DiffArray, Diff_Scalar_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(DiffArray, Diff_SIMD_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,13 +21,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
#include <vector>
#include <cmath>
#include <iostream>
#include "SIMDHelpers.h"
class Divide : public benchmark::Fixture {

View file

@ -21,6 +21,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
@ -28,7 +29,6 @@
#include <cmath>
#include <iostream>
#include "EventEnvelopes.h"
#include "SIMDHelpers.h"
#include "absl/types/span.h"
#include "FloatEnvelopes.cpp"
@ -59,7 +59,7 @@ BENCHMARK_DEFINE_F(EnvelopeFixture, Linear)(benchmark::State& state) {
sfz::LinearEnvelope<float> envelope;
for (auto _ : state)
{
envelope.registerEvent(state.range(0) - 1, dist(gen));
envelope.registerEvent(static_cast<int>(state.range(0) - 1), dist(gen));
envelope.getBlock(absl::MakeSpan(output));
}
}
@ -68,7 +68,7 @@ BENCHMARK_DEFINE_F(EnvelopeFixture, LinearQuantized)(benchmark::State& state) {
sfz::LinearEnvelope<float> envelope;
for (auto _ : state)
{
envelope.registerEvent(state.range(0) - 1, dist(gen));
envelope.registerEvent(static_cast<int>(state.range(0) - 1), dist(gen));
envelope.getQuantizedBlock(absl::MakeSpan(output), 0.5);
}
}
@ -77,7 +77,7 @@ BENCHMARK_DEFINE_F(EnvelopeFixture, Multiplicative)(benchmark::State& state) {
sfz::MultiplicativeEnvelope<float> envelope;
for (auto _ : state)
{
envelope.registerEvent(state.range(0) - 1, dist(gen));
envelope.registerEvent(static_cast<int>(state.range(0) - 1), dist(gen));
envelope.getBlock(absl::MakeSpan(output));
}
}
@ -86,7 +86,7 @@ BENCHMARK_DEFINE_F(EnvelopeFixture, MultiplicativeQuantized)(benchmark::State& s
sfz::MultiplicativeEnvelope<float> envelope;
for (auto _ : state)
{
envelope.registerEvent(state.range(0) - 1, dist(gen));
envelope.registerEvent(static_cast<int>(state.range(0) - 1), dist(gen));
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.5);
}
}
@ -96,4 +96,4 @@ BENCHMARK_REGISTER_F(EnvelopeFixture, Linear)->RangeMultiplier(4)->Range(1 << 2,
BENCHMARK_REGISTER_F(EnvelopeFixture, LinearQuantized)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(EnvelopeFixture, Multiplicative)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(EnvelopeFixture, MultiplicativeQuantized)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,8 +21,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <benchmark/benchmark.h>
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include "Buffer.h"
#include <algorithm>
#include <random>
@ -84,4 +84,4 @@ BENCHMARK(FillScalar)->RangeMultiplier(4)->Range((1<<2), (1<<12));
BENCHMARK(FillSIMD)->RangeMultiplier(4)->Range((1<<2), (1<<12));
BENCHMARK(FillScalar_unaligned)->RangeMultiplier(4)->Range((1<<2), (1<<12));
BENCHMARK(FillSIMD_unaligned)->RangeMultiplier(4)->Range((1<<2), (1<<12));
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -20,23 +20,27 @@
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Buffer.h"
#include <benchmark/benchmark.h>
#include <sndfile.hh>
#define DR_FLAC_IMPLEMENTATION
#include "dr_flac.h"
#include "ghc/filesystem.hpp"
#include "Buffer.h"
#include <memory>
#ifndef NDEBUG
#include <iostream>
#endif
#include "libnyquist/Decoders.h"
class FileFixture : public benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& state) {
rootPath1 = getPath() / "sample1.flac";
rootPath2 = getPath() / "sample2.flac";
if (!ghc::filesystem::exists(rootPath1) || !ghc::filesystem::exists(rootPath2)) {
filePath1 = getPath() / "sample1.flac";
filePath2 = getPath() / "sample2.flac";
filePath3 = getPath() / "sample3.flac";
if ( !ghc::filesystem::exists(filePath1)
|| !ghc::filesystem::exists(filePath2)
|| !ghc::filesystem::exists(filePath3) ) {
#ifndef NDEBUG
std::cerr << "Can't find path" << '\n';
#endif
@ -62,15 +66,16 @@ public:
std::unique_ptr<sfz::Buffer<float>> buffer;
ghc::filesystem::path rootPath1;
ghc::filesystem::path rootPath2;
ghc::filesystem::path filePath1;
ghc::filesystem::path filePath2;
ghc::filesystem::path filePath3;
};
BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
for (auto _ : state)
{
SndfileHandle sndfile(rootPath1.c_str());
SndfileHandle sndfile(filePath1.c_str());
buffer = std::make_unique<sfz::Buffer<float>>(sndfile.channels() * sndfile.frames());
sndfile.readf(buffer->data(), sndfile.frames());
}
@ -79,12 +84,23 @@ BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
BENCHMARK_DEFINE_F(FileFixture, DrFlac)(benchmark::State& state) {
for (auto _ : state)
{
auto* flac = drflac_open_file(rootPath2.c_str(), nullptr);
auto* flac = drflac_open_file(filePath2.c_str(), nullptr);
buffer = std::make_unique<sfz::Buffer<float>>(flac->channels * flac->totalPCMFrameCount);
drflac_read_pcm_frames_f32(flac, flac->totalPCMFrameCount, buffer->data());
}
}
BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) {
for (auto _ : state)
{
nqr::AudioData data;
nqr::NyquistIO loader;
loader.Load(&data, filePath3.string());
benchmark::DoNotOptimize(data);
}
}
BENCHMARK_REGISTER_F(FileFixture, SndFile);
BENCHMARK_REGISTER_F(FileFixture, DrFlac);
BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
BENCHMARK_MAIN();

View file

@ -21,13 +21,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
#include <vector>
#include <cmath>
#include <iostream>
#include "SIMDHelpers.h"
class GainSingle : public benchmark::Fixture {
public:
@ -140,4 +140,4 @@ BENCHMARK_REGISTER_F(GainArray, Scalar)->RangeMultiplier(4)->Range(1 << 2, 1 <<
BENCHMARK_REGISTER_F(GainArray, SIMD)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(GainArray, Scalar_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(GainArray, SIMD_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,12 +21,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <vector>
#include <random>
#include <numeric>
#include <absl/algorithm/container.h>
#include "SIMDHelpers.h"
// In this one we have an array of jumps
@ -90,4 +90,4 @@ BENCHMARK_REGISTER_F(InterpolationCast, Scalar)->RangeMultiplier(2)->Range((2<<6
BENCHMARK_REGISTER_F(InterpolationCast, SIMD)->RangeMultiplier(2)->Range((2<<6), (2<<12));
BENCHMARK_REGISTER_F(InterpolationCast, Scalar_Unaligned)->RangeMultiplier(2)->Range((2<<6), (2<<12));
BENCHMARK_REGISTER_F(InterpolationCast, SIMD_Unaligned)->RangeMultiplier(2)->Range((2<<6), (2<<12));
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -22,11 +22,11 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <benchmark/benchmark.h>
#include "SIMDHelpers.h"
#include <vector>
#include <random>
#include <numeric>
#include <absl/algorithm/container.h>
#include "SIMDHelpers.h"
// In this one we have an array of indices
@ -92,4 +92,4 @@ BENCHMARK_REGISTER_F(LoopingFixture, Scalar)->RangeMultiplier(2)->Range((2<<6),
BENCHMARK_REGISTER_F(LoopingFixture, SIMD)->RangeMultiplier(2)->Range((2<<6), (2<<12));
BENCHMARK_REGISTER_F(LoopingFixture, Scalar_Unaligned)->RangeMultiplier(2)->Range((2<<6), (2<<12));
BENCHMARK_REGISTER_F(LoopingFixture, SIMD_Unaligned)->RangeMultiplier(2)->Range((2<<6), (2<<12));
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -36,7 +36,7 @@ public:
{
std::random_device rd {};
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 0.1, 1 };
std::uniform_real_distribution<float> dist { 0.1f, 1.0f };
source = std::vector<float>(state.range(0));
result = std::vector<float>(state.range(0));
std::generate(source.begin(), source.end(), [&]() { return dist(gen); });
@ -162,4 +162,4 @@ BENCHMARK_REGISTER_F(MyFixture, SIMDSin)->RangeMultiplier(4)->Range(1 << 6, 1 <<
BENCHMARK_REGISTER_F(MyFixture, ScalarCos)->RangeMultiplier(4)->Range(1 << 6, 1 << 10);
BENCHMARK_REGISTER_F(MyFixture, SIMDCos)->RangeMultiplier(4)->Range(1 << 6, 1 << 10);
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,13 +21,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
#include <vector>
#include <cmath>
#include <iostream>
#include "SIMDHelpers.h"
class MultiplyAdd : public benchmark::Fixture {
public:
@ -93,4 +93,4 @@ BENCHMARK_REGISTER_F(MultiplyAdd, Scalar)->RangeMultiplier(4)->Range(1 << 2, 1 <
BENCHMARK_REGISTER_F(MultiplyAdd, SIMD)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(MultiplyAdd, Scalar_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(MultiplyAdd, SIMD_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,13 +21,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
#include <vector>
#include <cmath>
#include <iostream>
#include "SIMDHelpers.h"
#include "Config.h"
#include "absl/types/span.h"
@ -36,7 +36,7 @@ public:
void SetUp(const ::benchmark::State& state) {
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 0.001, 1 };
std::uniform_real_distribution<float> dist { 0.001f, 1.0f };
pan = std::vector<float>(state.range(0));
left = std::vector<float>(state.range(0));
right = std::vector<float>(state.range(0));
@ -93,4 +93,4 @@ BENCHMARK_DEFINE_F(PanArray, BlockOps)(benchmark::State& state) {
BENCHMARK_REGISTER_F(PanArray, Scalar)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(PanArray, SIMD)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(PanArray, BlockOps)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,10 +21,10 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include <absl/algorithm/container.h>
#include "SIMDHelpers.h"
#include "absl/types/span.h"
constexpr int bigNumber { 2399132 };
@ -33,8 +33,8 @@ class IterOffset : public benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& state [[maybe_unused]]) {
std::random_device rd { };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 0.001, 1 };
std::mt19937 gen { rd() };
std::uniform_real_distribution<float> dist { 0.001f, 1.0f };
std::uniform_int_distribution<int> jumpDist { 0, 3 };
source = std::vector<float>(bigNumber);
result.resize(state.range(0));
@ -57,7 +57,7 @@ public:
BENCHMARK_DEFINE_F(IterOffset, Pointers)(benchmark::State& state) {
for (auto _ : state)
{
{
sfz::diff<int>(offsets, absl::MakeSpan(jumps));
auto jump = jumps.begin();
auto in = source.begin();
@ -71,7 +71,7 @@ BENCHMARK_DEFINE_F(IterOffset, Pointers)(benchmark::State& state) {
BENCHMARK_DEFINE_F(IterOffset, Offsets)(benchmark::State& state) {
for (auto _ : state)
{
{
auto offset = offsets.begin();
auto out = result.begin();
while (offset < offsets.end())
@ -83,4 +83,4 @@ BENCHMARK_DEFINE_F(IterOffset, Offsets)(benchmark::State& state) {
// Register the function as a benchmark
BENCHMARK_REGISTER_F(IterOffset, Pointers)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK_REGISTER_F(IterOffset, Offsets)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,9 +21,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include "SIMDHelpers.h"
#include "Buffer.h"
@ -204,4 +204,4 @@ BENCHMARK(LogDomainScalar)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK(LogDomainSIMD)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK(LogDomainScalarUnaligned)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK(LogDomainSIMDUnaligned)->RangeMultiplier(4)->Range((1 << 2), (1 << 12));
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -20,11 +20,11 @@
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include "Buffer.h"
#include <benchmark/benchmark.h>
#include <sndfile.hh>
#include "ghc/filesystem.hpp"
#include "Buffer.h"
#include "SIMDHelpers.h"
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"
#include "AudioBuffer.h"

View file

@ -21,9 +21,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <benchmark/benchmark.h>
#include "SIMDHelpers.h"
#include "Buffer.h"
#include <benchmark/benchmark.h>
#include <algorithm>
#include <numeric>
#include <absl/types/span.h>
@ -96,4 +96,4 @@ BENCHMARK(Scalar_Unaligned)->Range((8<<10), (8<<20));
BENCHMARK(SSE_Unaligned)->Range((8<<10), (8<<20));
BENCHMARK(Scalar_Unaligned_2)->Range((8<<10), (8<<20));
BENCHMARK(SSE_Unaligned_2)->Range((8<<10), (8<<20));
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -64,7 +64,7 @@ void upsample2xStage(absl::Span<const float> input, absl::Span<float> output)
ASSERT(output.size() >= 2 * input.size());
hiir::Upsampler2xFpu<coeffsStage2x.size()> upsampler;
upsampler.set_coefs(coeffsStage2x.data());
upsampler.process_block(output.data(), input.data(), input.size());
upsampler.process_block(output.data(), input.data(), static_cast<long>(input.size()));
}
@ -74,7 +74,7 @@ void upsample4xStage(absl::Span<const float> input, absl::Span<float> output)
ASSERT(output.size() >= 2 * input.size());
hiir::Upsampler2xFpu<coeffsStage4x.size()> upsampler;
upsampler.set_coefs(coeffsStage4x.data());
upsampler.process_block(output.data(), input.data(), input.size());
upsampler.process_block(output.data(), input.data(), static_cast<long>(input.size()));
}
template<bool SIMD=false>
@ -83,7 +83,7 @@ void upsample8xStage(absl::Span<const float> input, absl::Span<float> output)
ASSERT(output.size() >= 2 * input.size());
hiir::Upsampler2xFpu<coeffsStage8x.size()> upsampler;
upsampler.set_coefs(coeffsStage8x.data());
upsampler.process_block(output.data(), input.data(), input.size());
upsampler.process_block(output.data(), input.data(), static_cast<long>(input.size()));
}
#if defined(__x86_64__) || defined(__i386__)
@ -94,7 +94,7 @@ void upsample2xStage<true>(absl::Span<const float> input, absl::Span<float> outp
ASSERT(output.size() >= 2 * input.size());
hiir::Upsampler2xSse<coeffsStage2x.size()> upsampler;
upsampler.set_coefs(coeffsStage2x.data());
upsampler.process_block(output.data(), input.data(), input.size());
upsampler.process_block(output.data(), input.data(), static_cast<long>(input.size()));
}
template<>
@ -103,7 +103,7 @@ void upsample4xStage<true>(absl::Span<const float> input, absl::Span<float> outp
ASSERT(output.size() >= 2 * input.size());
hiir::Upsampler2xSse<coeffsStage4x.size()> upsampler;
upsampler.set_coefs(coeffsStage4x.data());
upsampler.process_block(output.data(), input.data(), input.size());
upsampler.process_block(output.data(), input.data(), static_cast<long>(input.size()));
}
template<>
@ -112,7 +112,7 @@ void upsample8xStage<true>(absl::Span<const float> input, absl::Span<float> outp
ASSERT(output.size() >= 2 * input.size());
hiir::Upsampler2xSse<coeffsStage8x.size()> upsampler;
upsampler.set_coefs(coeffsStage8x.data());
upsampler.process_block(output.data(), input.data(), input.size());
upsampler.process_block(output.data(), input.data(), static_cast<long>(input.size()));
}
#elif defined(__arm__) || defined (__aarch64__)
@ -125,7 +125,7 @@ void upsample2xStage<true>(absl::Span<const float> input, absl::Span<float> outp
ASSERT(output.size() >= 2 * input.size());
hiir::Upsampler2xNeon<coeffsStage2x.size()> upsampler;
upsampler.set_coefs(coeffsStage2x.data());
upsampler.process_block(output.data(), input.data(), input.size());
upsampler.process_block(output.data(), input.data(), static_cast<long>(input.size()));
}
template<>
@ -134,7 +134,7 @@ void upsample4xStage<true>(absl::Span<const float> input, absl::Span<float> outp
ASSERT(output.size() >= 2 * input.size());
hiir::Upsampler2xNeon<coeffsStage4x.size()> upsampler;
upsampler.set_coefs(coeffsStage4x.data());
upsampler.process_block(output.data(), input.data(), input.size());
upsampler.process_block(output.data(), input.data(), static_cast<long>(input.size()));
}
template<>
@ -143,7 +143,7 @@ void upsample8xStage<true>(absl::Span<const float> input, absl::Span<float> outp
ASSERT(output.size() >= 2 * input.size());
hiir::Upsampler2xNeon<coeffsStage8x.size()> upsampler;
upsampler.set_coefs(coeffsStage8x.data());
upsampler.process_block(output.data(), input.data(), input.size());
upsampler.process_block(output.data(), input.data(), static_cast<long>(input.size()));
}
#else
@ -170,7 +170,7 @@ std::unique_ptr<sfz::AudioBuffer<T>> upsample2x(const sfz::AudioBuffer<T>& buffe
{
// auto tempBuffer = std::make_unique<sfz::Buffer<T>>(buffer.getNumFrames() * 2);
auto outputBuffer = std::make_unique<sfz::AudioBuffer<T>>(buffer.getNumChannels(), buffer.getNumFrames() * 2);
for (int channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) {
for (size_t channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) {
upsample2xStage<SIMD>(buffer.getConstSpan(channelIdx), outputBuffer->getSpan(channelIdx));
}
return outputBuffer;
@ -181,7 +181,7 @@ std::unique_ptr<sfz::AudioBuffer<T>> upsample4x(const sfz::AudioBuffer<T>& buffe
{
auto tempBuffer = std::make_unique<sfz::Buffer<T>>(buffer.getNumFrames() * 2);
auto outputBuffer = std::make_unique<sfz::AudioBuffer<T>>(buffer.getNumChannels(), buffer.getNumFrames() * 4);
for (int channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) {
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));
}
@ -194,7 +194,7 @@ std::unique_ptr<sfz::AudioBuffer<T>> upsample8x(const sfz::AudioBuffer<T>& buffe
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);
for (int channelIdx = 0; channelIdx < buffer.getNumChannels(); channelIdx++) {
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));
upsample8xStage<SIMD>(absl::MakeConstSpan(*tempBuffer4x), outputBuffer->getSpan(channelIdx));
@ -240,8 +240,8 @@ public:
#endif
}
int numChannels;
int numFrames;
size_t numChannels;
size_t numFrames;
std::unique_ptr<sfz::Buffer<float>> interleavedBuffer;
};
@ -313,9 +313,9 @@ BENCHMARK_DEFINE_F(SndFile, SRC2x_BEST)(benchmark::State& state)
srcData.data_in = interleavedBuffer->data();
srcData.data_out = intermediateBuffer->data();
srcData.src_ratio = 2.0;
srcData.input_frames = numFrames;
srcData.output_frames = 2 * numFrames;
src_simple(&srcData, SRC_SINC_BEST_QUALITY, numChannels);
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);
sfz::readInterleaved<float>(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1));
benchmark::DoNotOptimize(outBuffer);
@ -330,9 +330,9 @@ BENCHMARK_DEFINE_F(SndFile, SRC2x_MEDIUM)(benchmark::State& state)
srcData.data_in = interleavedBuffer->data();
srcData.data_out = intermediateBuffer->data();
srcData.src_ratio = 2.0;
srcData.input_frames = numFrames;
srcData.output_frames = 2 * numFrames;
src_simple(&srcData, SRC_SINC_MEDIUM_QUALITY, numChannels);
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);
sfz::readInterleaved<float>(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1));
benchmark::DoNotOptimize(outBuffer);
@ -347,9 +347,9 @@ BENCHMARK_DEFINE_F(SndFile, SRC2x_FASTEST)(benchmark::State& state)
srcData.data_in = interleavedBuffer->data();
srcData.data_out = intermediateBuffer->data();
srcData.src_ratio = 2.0;
srcData.input_frames = numFrames;
srcData.output_frames = 2 * numFrames;
src_simple(&srcData, SRC_SINC_FASTEST, numChannels);
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);
sfz::readInterleaved<float>(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1));
benchmark::DoNotOptimize(outBuffer);
@ -365,9 +365,9 @@ BENCHMARK_DEFINE_F(SndFile, SRC4x_BEST)(benchmark::State& state)
srcData.data_in = interleavedBuffer->data();
srcData.data_out = intermediateBuffer->data();
srcData.src_ratio = 4.0;
srcData.input_frames = numFrames;
srcData.output_frames = 2 * numFrames;
src_simple(&srcData, SRC_SINC_BEST_QUALITY, numChannels);
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);
sfz::readInterleaved<float>(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1));
benchmark::DoNotOptimize(outBuffer);
@ -382,9 +382,9 @@ BENCHMARK_DEFINE_F(SndFile, SRC4x_MEDIUM)(benchmark::State& state)
srcData.data_in = interleavedBuffer->data();
srcData.data_out = intermediateBuffer->data();
srcData.src_ratio = 4.0;
srcData.input_frames = numFrames;
srcData.output_frames = 2 * numFrames;
src_simple(&srcData, SRC_SINC_MEDIUM_QUALITY, numChannels);
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);
sfz::readInterleaved<float>(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1));
benchmark::DoNotOptimize(outBuffer);
@ -399,9 +399,9 @@ BENCHMARK_DEFINE_F(SndFile, SRC4x_FASTEST)(benchmark::State& state)
srcData.data_in = interleavedBuffer->data();
srcData.data_out = intermediateBuffer->data();
srcData.src_ratio = 4.0;
srcData.input_frames = numFrames;
srcData.output_frames = 2 * numFrames;
src_simple(&srcData, SRC_SINC_FASTEST, numChannels);
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);
sfz::readInterleaved<float>(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1));
benchmark::DoNotOptimize(outBuffer);
@ -416,9 +416,9 @@ BENCHMARK_DEFINE_F(SndFile, SRC8x_BEST)(benchmark::State& state)
srcData.data_in = interleavedBuffer->data();
srcData.data_out = intermediateBuffer->data();
srcData.src_ratio = 8.0;
srcData.input_frames = numFrames;
srcData.output_frames = 2 * numFrames;
src_simple(&srcData, SRC_SINC_BEST_QUALITY, numChannels);
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);
sfz::readInterleaved<float>(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1));
benchmark::DoNotOptimize(outBuffer);
@ -433,9 +433,9 @@ BENCHMARK_DEFINE_F(SndFile, SRC8x_MEDIUM)(benchmark::State& state)
srcData.data_in = interleavedBuffer->data();
srcData.data_out = intermediateBuffer->data();
srcData.src_ratio = 8.0;
srcData.input_frames = numFrames;
srcData.output_frames = 2 * numFrames;
src_simple(&srcData, SRC_SINC_MEDIUM_QUALITY, numChannels);
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);
sfz::readInterleaved<float>(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1));
benchmark::DoNotOptimize(outBuffer);
@ -450,9 +450,9 @@ BENCHMARK_DEFINE_F(SndFile, SRC8x_FASTEST)(benchmark::State& state)
srcData.data_in = interleavedBuffer->data();
srcData.data_out = intermediateBuffer->data();
srcData.src_ratio = 8.0;
srcData.input_frames = numFrames;
srcData.output_frames = 2 * numFrames;
src_simple(&srcData, SRC_SINC_FASTEST, numChannels);
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);
sfz::readInterleaved<float>(*intermediateBuffer, outBuffer->getSpan(0), outBuffer->getSpan(1));
benchmark::DoNotOptimize(outBuffer);

View file

@ -20,11 +20,11 @@
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Buffer.h"
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <sndfile.hh>
#include "ghc/filesystem.hpp"
#include "Buffer.h"
#include "SIMDHelpers.h"
#include "Oversampler.h"
#include "AudioBuffer.h"
#include <memory>
@ -139,14 +139,14 @@ BENCHMARK_DEFINE_F(FileFixture, ResampleAtOnce)(benchmark::State& state) {
sndfile.readf(buffer.data(), numFrames);
sfz::readInterleaved<float>(buffer, output->getSpan(0), output->getSpan(1));
upsampler2x.process_block(temp.data(), output->channelReader(0), numFrames);
upsampler4x.process_block(output->channelWriter(0), temp.data(), numFrames * 2);
upsampler2x.process_block(temp.data(), output->channelReader(0), static_cast<long>(numFrames));
upsampler4x.process_block(output->channelWriter(0), temp.data(), static_cast<long>(numFrames * 2));
upsampler2x.clear_buffers();
upsampler4x.clear_buffers();
upsampler2x.process_block(temp.data(), output->channelReader(1), numFrames);
upsampler4x.process_block(output->channelWriter(1), temp.data(), numFrames * 2);
upsampler2x.process_block(temp.data(), output->channelReader(1), static_cast<long>(numFrames));
upsampler4x.process_block(output->channelWriter(1), temp.data(), static_cast<long>(numFrames * 2));
}
}
@ -189,11 +189,11 @@ BENCHMARK_DEFINE_F(FileFixture, ResampleInChunks)(benchmark::State& state) {
sfz::readInterleaved<float>(bufferChunk, leftSpan, rightSpan);
upsampler2xLeft.process_block(chunkSpan.data(), leftSpan.data(), thisChunkSize);
upsampler4xLeft.process_block(output->channelWriter(0) + outputFrameCounter, chunkSpan.data(), thisChunkSize * 2);
upsampler2xLeft.process_block(chunkSpan.data(), leftSpan.data(), static_cast<long>(thisChunkSize));
upsampler4xLeft.process_block(output->channelWriter(0) + outputFrameCounter, chunkSpan.data(), static_cast<long>(thisChunkSize * 2));
upsampler2xRight.process_block(chunkSpan.data(), rightSpan.data(), thisChunkSize);
upsampler4xRight.process_block(output->channelWriter(1) + outputFrameCounter, chunkSpan.data(), thisChunkSize * 2);
upsampler2xRight.process_block(chunkSpan.data(), rightSpan.data(), static_cast<long>(thisChunkSize));
upsampler4xRight.process_block(output->channelWriter(1) + outputFrameCounter, chunkSpan.data(), static_cast<long>(thisChunkSize * 2));
inputFrameCounter += chunkSize;
outputFrameCounter += chunkSize * 4;

View file

@ -21,12 +21,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <vector>
#include <random>
#include <numeric>
#include <absl/algorithm/container.h>
#include "SIMDHelpers.h"
// In this one we have an array of indices
@ -91,4 +91,4 @@ BENCHMARK_REGISTER_F(SaturatingFixture, Scalar)->RangeMultiplier(2)->Range((2<<6
BENCHMARK_REGISTER_F(SaturatingFixture, SIMD)->RangeMultiplier(2)->Range((2<<6), (2<<12));
BENCHMARK_REGISTER_F(SaturatingFixture, Scalar_Unaligned)->RangeMultiplier(2)->Range((2<<6), (2<<12));
BENCHMARK_REGISTER_F(SaturatingFixture, SIMD_Unaligned)->RangeMultiplier(2)->Range((2<<6), (2<<12));
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -21,13 +21,13 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SIMDHelpers.h"
#include <benchmark/benchmark.h>
#include <random>
#include <numeric>
#include <vector>
#include <cmath>
#include <iostream>
#include "SIMDHelpers.h"
class SubArray : public benchmark::Fixture {
public:
@ -82,4 +82,4 @@ BENCHMARK_REGISTER_F(SubArray, Scalar)->RangeMultiplier(4)->Range(1 << 2, 1 << 1
BENCHMARK_REGISTER_F(SubArray, SIMD)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(SubArray, Scalar_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_REGISTER_F(SubArray, SIMD_Unaligned)->RangeMultiplier(4)->Range(1 << 2, 1 << 12);
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -20,23 +20,27 @@
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Buffer.h"
#include <benchmark/benchmark.h>
#include <sndfile.hh>
#define DR_WAV_IMPLEMENTATION
#include "dr_wav.h"
#include "ghc/filesystem.hpp"
#include "Buffer.h"
#include <memory>
#ifndef NDEBUG
#include <iostream>
#endif
#include "libnyquist/Decoders.h"
class FileFixture : public benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& state) {
rootPath1 = getPath() / "sample1.wav";
rootPath2 = getPath() / "sample2.wav";
if (!ghc::filesystem::exists(rootPath1) || !ghc::filesystem::exists(rootPath2)) {
filePath1 = getPath() / "sample1.wav";
filePath2 = getPath() / "sample2.wav";
filePath3 = getPath() / "sample3.wav";
if ( !ghc::filesystem::exists(filePath1)
|| !ghc::filesystem::exists(filePath2)
|| !ghc::filesystem::exists(filePath3)) {
#ifndef NDEBUG
std::cerr << "Can't find path" << '\n';
#endif
@ -62,15 +66,16 @@ public:
std::unique_ptr<sfz::Buffer<float>> buffer;
ghc::filesystem::path rootPath1;
ghc::filesystem::path rootPath2;
ghc::filesystem::path filePath1;
ghc::filesystem::path filePath2;
ghc::filesystem::path filePath3;
};
BENCHMARK_DEFINE_F(FileFixture, SndFile)(benchmark::State& state) {
for (auto _ : state)
{
SndfileHandle sndfile(rootPath1.c_str());
SndfileHandle sndfile(filePath1.c_str());
buffer = std::make_unique<sfz::Buffer<float>>(sndfile.channels() * sndfile.frames());
sndfile.readf(buffer->data(), sndfile.frames());
}
@ -80,7 +85,7 @@ BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) {
for (auto _ : state)
{
drwav wav;
if (!drwav_init_file(&wav, rootPath2.c_str(), nullptr)) {
if (!drwav_init_file(&wav, filePath2.c_str(), nullptr)) {
#ifndef NDEBUG
std::cerr << "Can't find path" << '\n';
#endif
@ -91,6 +96,17 @@ BENCHMARK_DEFINE_F(FileFixture, DrWav)(benchmark::State& state) {
}
}
BENCHMARK_DEFINE_F(FileFixture, LibNyquist)(benchmark::State& state) {
for (auto _ : state)
{
nqr::AudioData data;
nqr::NyquistIO loader;
loader.Load(&data, filePath3.string());
benchmark::DoNotOptimize(data);
}
}
BENCHMARK_REGISTER_F(FileFixture, SndFile);
BENCHMARK_REGISTER_F(FileFixture, DrWav);
BENCHMARK_REGISTER_F(FileFixture, LibNyquist);
BENCHMARK_MAIN();

View file

@ -21,9 +21,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <benchmark/benchmark.h>
#include "SIMDHelpers.h"
#include "Buffer.h"
#include <benchmark/benchmark.h>
#include <algorithm>
#include <numeric>
#include <absl/types/span.h>
@ -106,4 +106,4 @@ BENCHMARK(Unaligned_Interleaved_Write)->Range((8<<10), (8<<20));
BENCHMARK(Unaligned_Interleaved_Write_SSE)->Range((8<<10), (8<<20));
BENCHMARK(Unaligned_Interleaved_Write_2)->Range((8<<10), (8<<20));
BENCHMARK(Unaligned_Interleaved_Write_SSE_2)->Range((8<<10), (8<<20));
BENCHMARK_MAIN();
BENCHMARK_MAIN();

View file

@ -22,115 +22,133 @@ set(BENCHMARK_SIMD_SOURCES ${SFIZZ_SIMD_SOURCES})
list(TRANSFORM BENCHMARK_SIMD_SOURCES PREPEND "../src/")
add_executable(bm_opf_high_vs_low BM_OPF_high_vs_low.cpp)
target_link_libraries(bm_opf_high_vs_low benchmark absl::span)
target_link_libraries(bm_opf_high_vs_low PRIVATE benchmark absl::span)
target_include_directories(bm_opf_high_vs_low PRIVATE ../src/sfizz ../src/external)
add_executable(bm_write BM_writeInterleaved.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_write benchmark absl::span)
target_link_libraries(bm_write PRIVATE benchmark absl::span)
target_include_directories(bm_write PRIVATE ../src/sfizz ../src/external)
add_executable(bm_read BM_readInterleaved.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_read benchmark absl::span)
target_link_libraries(bm_read PRIVATE benchmark absl::span)
target_include_directories(bm_read PRIVATE ../src/sfizz ../src/external)
add_executable(bm_fill BM_fill.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_fill benchmark absl::span)
target_link_libraries(bm_fill PRIVATE benchmark absl::span)
target_include_directories(bm_fill PRIVATE ../src/sfizz ../src/external)
add_executable(bm_mathfuns BM_mathfuns.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_mathfuns benchmark absl::span)
target_link_libraries(bm_mathfuns PRIVATE benchmark absl::span)
target_include_directories(bm_mathfuns PRIVATE ../src/sfizz ../src/external)
add_executable(bm_gain BM_gain.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_gain benchmark absl::span)
target_link_libraries(bm_gain PRIVATE benchmark absl::span)
target_include_directories(bm_gain PRIVATE ../src/sfizz ../src/external)
add_executable(bm_divide BM_divide.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_divide benchmark absl::span)
target_link_libraries(bm_divide PRIVATE benchmark absl::span)
target_include_directories(bm_divide PRIVATE ../src/sfizz ../src/external)
add_executable(bm_looping BM_looping.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_looping benchmark absl::span absl::algorithm)
target_link_libraries(bm_looping PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_looping PRIVATE ../src/sfizz ../src/external)
add_executable(bm_saturating BM_saturating.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_saturating benchmark absl::span absl::algorithm)
target_link_libraries(bm_saturating PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_saturating PRIVATE ../src/sfizz ../src/external)
add_executable(bm_ramp BM_ramp.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_ramp benchmark absl::span absl::algorithm)
target_link_libraries(bm_ramp PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_ramp PRIVATE ../src/sfizz ../src/external)
add_executable(bm_ADSR BM_ADSR.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_ADSR benchmark absl::span absl::algorithm)
target_link_libraries(bm_ADSR PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_ADSR PRIVATE ../src/sfizz ../src/external)
add_executable(bm_add BM_add.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_add benchmark absl::span absl::algorithm)
target_link_libraries(bm_add PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_add PRIVATE ../src/sfizz ../src/external)
add_executable(bm_multiplyAdd BM_multiplyAdd.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_multiplyAdd benchmark absl::span absl::algorithm)
target_link_libraries(bm_multiplyAdd PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_multiplyAdd PRIVATE ../src/sfizz ../src/external)
add_executable(bm_subtract BM_subtract.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_subtract benchmark absl::span absl::algorithm)
target_link_libraries(bm_subtract PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_subtract PRIVATE ../src/sfizz ../src/external)
add_executable(bm_copy BM_copy.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_copy benchmark absl::span absl::algorithm)
target_link_libraries(bm_copy PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_copy PRIVATE ../src/sfizz ../src/external)
add_executable(bm_pan BM_pan.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_pan benchmark absl::span absl::algorithm)
target_link_libraries(bm_pan PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_pan PRIVATE ../src/sfizz ../src/external)
add_executable(bm_mean BM_mean.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_mean benchmark absl::span absl::algorithm)
target_link_libraries(bm_mean PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_mean PRIVATE ../src/sfizz ../src/external)
add_executable(bm_meanSquared BM_meanSquared.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_meanSquared benchmark absl::span absl::algorithm)
target_link_libraries(bm_meanSquared PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_meanSquared PRIVATE ../src/sfizz ../src/external)
add_executable(bm_cumsum BM_cumsum.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_cumsum benchmark absl::span absl::algorithm)
target_link_libraries(bm_cumsum PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_cumsum PRIVATE ../src/sfizz ../src/external)
add_executable(bm_diff BM_diff.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_diff benchmark absl::span absl::algorithm)
target_link_libraries(bm_diff PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_diff PRIVATE ../src/sfizz ../src/external)
add_executable(bm_interpolationCast BM_interpolationCast.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_interpolationCast benchmark absl::span absl::algorithm)
target_link_libraries(bm_interpolationCast PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_interpolationCast PRIVATE ../src/sfizz ../src/external)
add_executable(bm_pointerIterationOrOffsets BM_pointerIterationOrOffsets.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_pointerIterationOrOffsets benchmark absl::span absl::algorithm)
target_link_libraries(bm_pointerIterationOrOffsets PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_pointerIterationOrOffsets PRIVATE ../src/sfizz ../src/external)
add_executable(bm_resample BM_resample.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_resample benchmark absl::span absl::algorithm sndfile samplerate)
target_link_libraries(bm_resample PRIVATE benchmark absl::span absl::algorithm)
sfizz_link_libsndfile(bm_resample)
sfizz_link_libsamplerate(bm_resample)
target_include_directories(bm_resample PRIVATE ../src/sfizz ../src/external)
add_executable(bm_envelopes BM_envelopes.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_envelopes benchmark absl::span absl::algorithm sndfile samplerate)
target_link_libraries(bm_envelopes PRIVATE benchmark absl::span absl::algorithm)
target_include_directories(bm_envelopes PRIVATE ../src/sfizz ../src/external)
include(FetchContent)
FetchContent_Declare(
libnyquist
GIT_REPOSITORY https://github.com/paulfd/libnyquist
)
FetchContent_GetProperties(libnyquist)
if(NOT libnyquist_POPULATED)
FetchContent_Populate(libnyquist)
add_subdirectory(${libnyquist_SOURCE_DIR} ${libnyquist_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
add_executable(bm_wavfile BM_wavfile.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_wavfile benchmark absl::span absl::algorithm sndfile)
target_link_libraries(bm_wavfile PRIVATE benchmark absl::span absl::algorithm libnyquist)
sfizz_link_libsndfile(bm_wavfile)
target_include_directories(bm_wavfile PRIVATE ../src/sfizz ../src/external)
add_executable(bm_flacfile BM_flacfile.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_flacfile benchmark absl::span absl::algorithm sndfile)
target_link_libraries(bm_flacfile PRIVATE benchmark absl::span absl::algorithm libnyquist)
sfizz_link_libsndfile(bm_flacfile)
target_include_directories(bm_flacfile PRIVATE ../src/sfizz ../src/external)
add_executable(bm_readChunk BM_readChunk.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_readChunk benchmark absl::span absl::algorithm sndfile)
target_link_libraries(bm_readChunk PRIVATE benchmark absl::span absl::algorithm)
sfizz_link_libsndfile(bm_readChunk)
target_include_directories(bm_readChunk PRIVATE ../src/sfizz ../src/external)
add_executable(bm_resampleChunk BM_resampleChunk.cpp ${BENCHMARK_SIMD_SOURCES})
target_link_libraries(bm_resampleChunk benchmark absl::span absl::algorithm sndfile)
target_link_libraries(bm_resampleChunk PRIVATE benchmark absl::span absl::algorithm)
sfizz_link_libsndfile(bm_resampleChunk)
target_include_directories(bm_resampleChunk PRIVATE ../src/sfizz ../src/external)
add_custom_target(sfizz_benchmarks)
@ -166,5 +184,7 @@ add_dependencies(sfizz_benchmarks
file(COPY "sample1.wav" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks)
file(COPY "sample2.wav" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks)
file(COPY "sample3.wav" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks)
file(COPY "sample1.flac" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks)
file(COPY "sample2.flac" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks)
file(COPY "sample3.flac" DESTINATION ${CMAKE_BINARY_DIR}/benchmarks)

BIN
benchmarks/sample3.flac Executable file

Binary file not shown.

BIN
benchmarks/sample3.wav Executable file

Binary file not shown.

View file

@ -16,8 +16,34 @@ if (UNIX)
add_compile_options(-ffast-math)
add_compile_options(-fno-omit-frame-pointer) # For debugging purposes
add_compile_options(-fPIC)
endif()
if (WIN32)
find_package(LibSndFile REQUIRED)
find_path(SNDFILE_INCLUDE_DIR sndfile.hh)
find_path(SAMPLERATE_INCLUDE_DIR samplerate.h)
set(CMAKE_CXX_STANDARD 17)
add_compile_options(/Zc:__cplusplus)
endif()
function(SFIZZ_LINK_LIBSNDFILE TARGET)
if (WIN32)
target_link_libraries (${TARGET} PRIVATE sndfile-shared)
target_include_directories(${TARGET} PRIVATE ${SNDFILE_INCLUDE_DIR})
else()
target_link_libraries(${TARGET} PRIVATE sndfile)
endif()
endfunction(SFIZZ_LINK_LIBSNDFILE)
function(SFIZZ_LINK_LIBSAMPLERATE TARGET)
if (WIN32)
target_link_libraries (${TARGET} PRIVATE samplerate)
target_include_directories(${TARGET} PRIVATE ${SAMPLERATE_INCLUDE_DIR})
else()
target_link_libraries(${TARGET} PRIVATE samplerate)
endif()
endfunction(SFIZZ_LINK_LIBSAMPLERATE)
# If we build with Clang use libc++
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT ANDROID)
set(USE_LIBCPP ON CACHE BOOL "Use libc++ with clang")

View file

@ -45,8 +45,6 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#define DEFAULT_SFZ_FILE "/home/paul/Documents/AVL_Percussions/AVL_Drumkits_Percussion-1.0-Alt.sfz"
#define SFIZZ_URI "http://sfztools.github.io/sfizz"
@ -414,7 +412,7 @@ sfizz_lv2_send_file_path(sfizz_plugin_t *self)
lv2_atom_forge_key(&self->forge, self->patch_property_uri);
lv2_atom_forge_urid(&self->forge, self->sfizz_sfz_file_uri);
lv2_atom_forge_key(&self->forge, self->patch_value_uri);
lv2_atom_forge_path(&self->forge, self->sfz_file_path, strlen(self->sfz_file_path));
lv2_atom_forge_path(&self->forge, self->sfz_file_path, (uint32_t)strlen(self->sfz_file_path));
lv2_atom_forge_pop(&self->forge, &frame);
}
@ -463,7 +461,7 @@ sfizz_lv2_handle_atom_object(sfizz_plugin_t *self, const LV2_Atom_Object *obj)
const uint32_t original_atom_size = lv2_atom_total_size((const LV2_Atom *)atom);
const uint32_t null_terminated_atom_size = original_atom_size + 1;
char atom_buffer[null_terminated_atom_size];
char atom_buffer[MAX_PATH_SIZE];
memcpy(&atom_buffer, atom, original_atom_size);
atom_buffer[original_atom_size] = 0; // Null terminate the string for safety
LV2_Atom *sfz_file_path = (LV2_Atom *)&atom_buffer;

View file

@ -26,7 +26,8 @@ target_include_directories (sfizz PUBLIC external)
target_link_libraries (sfizz PRIVATE sfizz_parser)
find_package (Threads REQUIRED)
target_link_libraries (sfizz PUBLIC absl::strings)
target_link_libraries (sfizz PRIVATE sndfile absl::flat_hash_map Threads::Threads)
target_link_libraries (sfizz PRIVATE absl::flat_hash_map Threads::Threads)
sfizz_link_libsndfile(sfizz)
if (UNIX AND NOT APPLE)
target_link_libraries (sfizz PUBLIC atomic)

View file

@ -6,7 +6,7 @@
#include <atomic>
#if defined(__x86_64__)
#if defined(__x86_64__) || defined(_M_X64)
#include <emmintrin.h>
namespace atomic_queue {
constexpr int CACHE_LINE_SIZE = 64;
@ -30,8 +30,13 @@ static inline void spin_loop_pause() noexcept {
namespace atomic_queue {
#if defined(__GNUC__)
#define ATOMIC_QUEUE_LIKELY(expr) __builtin_expect(static_cast<bool>(expr), 1)
#define ATOMIC_QUEUE_UNLIKELY(expr) __builtin_expect(static_cast<bool>(expr), 0)
#else
#define ATOMIC_QUEUE_LIKELY(expr) expr
#define ATOMIC_QUEUE_UNLIKELY(expr) expr
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View file

@ -35,7 +35,7 @@
#ifdef _MSC_VER /* visual c++ */
# define ALIGN16_BEG __declspec(align(16))
# define ALIGN16_END
# define ALIGN16_END
#else /* gcc or icc */
# define ALIGN16_BEG
# define ALIGN16_END __attribute__((aligned(16)))
@ -77,18 +77,18 @@ _PI32_CONST(2, 2);
_PI32_CONST(4, 4);
_PI32_CONST(0x7f, 0x7f);
_PS_CONST(cephes_SQRTHF, 0.707106781186547524);
_PS_CONST(cephes_log_p0, 7.0376836292E-2);
_PS_CONST(cephes_log_p1, - 1.1514610310E-1);
_PS_CONST(cephes_log_p2, 1.1676998740E-1);
_PS_CONST(cephes_log_p3, - 1.2420140846E-1);
_PS_CONST(cephes_log_p4, + 1.4249322787E-1);
_PS_CONST(cephes_log_p5, - 1.6668057665E-1);
_PS_CONST(cephes_log_p6, + 2.0000714765E-1);
_PS_CONST(cephes_log_p7, - 2.4999993993E-1);
_PS_CONST(cephes_log_p8, + 3.3333331174E-1);
_PS_CONST(cephes_log_q1, -2.12194440e-4);
_PS_CONST(cephes_log_q2, 0.693359375);
_PS_CONST(cephes_SQRTHF, 0.707106781186547524f);
_PS_CONST(cephes_log_p0, 7.0376836292E-2f);
_PS_CONST(cephes_log_p1, - 1.1514610310E-1f);
_PS_CONST(cephes_log_p2, 1.1676998740E-1f);
_PS_CONST(cephes_log_p3, - 1.2420140846E-1f);
_PS_CONST(cephes_log_p4, + 1.4249322787E-1f);
_PS_CONST(cephes_log_p5, - 1.6668057665E-1f);
_PS_CONST(cephes_log_p6, + 2.0000714765E-1f);
_PS_CONST(cephes_log_p7, - 2.4999993993E-1f);
_PS_CONST(cephes_log_p8, + 3.3333331174E-1f);
_PS_CONST(cephes_log_q1, -2.12194440e-4f);
_PS_CONST(cephes_log_q2, 0.693359375f);
#ifndef USE_SSE2
typedef union xmm_mm_union {
@ -108,7 +108,7 @@ typedef union xmm_mm_union {
#endif // USE_SSE2
/* natural logarithm computed for 4 simultaneous float
/* natural logarithm computed for 4 simultaneous float
return NaN for x <= 0
*/
v4sf log_ps(v4sf x) {
@ -148,7 +148,7 @@ v4sf log_ps(v4sf x) {
e = _mm_add_ps(e, one);
/* part2:
/* part2:
if( x < SQRTHF ) {
e -= 1;
x = x + x - 1.0;
@ -183,7 +183,7 @@ v4sf log_ps(v4sf x) {
y = _mm_mul_ps(y, x);
y = _mm_mul_ps(y, z);
tmp = _mm_mul_ps(e, *(v4sf*)_ps_cephes_log_q1);
y = _mm_add_ps(y, tmp);
@ -202,16 +202,16 @@ v4sf log_ps(v4sf x) {
_PS_CONST(exp_hi, 88.3762626647949f);
_PS_CONST(exp_lo, -88.3762626647949f);
_PS_CONST(cephes_LOG2EF, 1.44269504088896341);
_PS_CONST(cephes_exp_C1, 0.693359375);
_PS_CONST(cephes_exp_C2, -2.12194440e-4);
_PS_CONST(cephes_LOG2EF, 1.44269504088896341f);
_PS_CONST(cephes_exp_C1, 0.693359375f);
_PS_CONST(cephes_exp_C2, -2.12194440e-4f);
_PS_CONST(cephes_exp_p0, 1.9875691500E-4);
_PS_CONST(cephes_exp_p1, 1.3981999507E-3);
_PS_CONST(cephes_exp_p2, 8.3334519073E-3);
_PS_CONST(cephes_exp_p3, 4.1665795894E-2);
_PS_CONST(cephes_exp_p4, 1.6666665459E-1);
_PS_CONST(cephes_exp_p5, 5.0000001201E-1);
_PS_CONST(cephes_exp_p0, 1.9875691500E-4f);
_PS_CONST(cephes_exp_p1, 1.3981999507E-3f);
_PS_CONST(cephes_exp_p2, 8.3334519073E-3f);
_PS_CONST(cephes_exp_p3, 4.1665795894E-2f);
_PS_CONST(cephes_exp_p4, 1.6666665459E-1f);
_PS_CONST(cephes_exp_p5, 5.0000001201E-1f);
v4sf exp_ps(v4sf x) {
v4sf tmp = _mm_setzero_ps(), fx;
@ -242,7 +242,7 @@ v4sf exp_ps(v4sf x) {
tmp = _mm_cvtepi32_ps(emm0);
#endif
/* if greater, substract 1 */
v4sf mask = _mm_cmpgt_ps(tmp, fx);
v4sf mask = _mm_cmpgt_ps(tmp, fx);
mask = _mm_and_ps(mask, one);
fx = _mm_sub_ps(tmp, mask);
@ -252,7 +252,7 @@ v4sf exp_ps(v4sf x) {
x = _mm_sub_ps(x, z);
z = _mm_mul_ps(x,x);
v4sf y = *(v4sf*)_ps_cephes_exp_p0;
y = _mm_mul_ps(y, x);
y = _mm_add_ps(y, *(v4sf*)_ps_cephes_exp_p1);
@ -275,10 +275,10 @@ v4sf exp_ps(v4sf x) {
mm1 = _mm_cvttps_pi32(z);
mm0 = _mm_add_pi32(mm0, *(v2si*)_pi32_0x7f);
mm1 = _mm_add_pi32(mm1, *(v2si*)_pi32_0x7f);
mm0 = _mm_slli_pi32(mm0, 23);
mm0 = _mm_slli_pi32(mm0, 23);
mm1 = _mm_slli_pi32(mm1, 23);
v4sf pow2n;
v4sf pow2n;
COPY_MM_TO_XMM(mm0, mm1, pow2n);
_mm_empty();
#else
@ -291,16 +291,16 @@ v4sf exp_ps(v4sf x) {
return y;
}
_PS_CONST(minus_cephes_DP1, -0.78515625);
_PS_CONST(minus_cephes_DP2, -2.4187564849853515625e-4);
_PS_CONST(minus_cephes_DP3, -3.77489497744594108e-8);
_PS_CONST(sincof_p0, -1.9515295891E-4);
_PS_CONST(sincof_p1, 8.3321608736E-3);
_PS_CONST(sincof_p2, -1.6666654611E-1);
_PS_CONST(coscof_p0, 2.443315711809948E-005);
_PS_CONST(coscof_p1, -1.388731625493765E-003);
_PS_CONST(coscof_p2, 4.166664568298827E-002);
_PS_CONST(cephes_FOPI, 1.27323954473516); // 4 / M_PI
_PS_CONST(minus_cephes_DP1, -0.78515625f);
_PS_CONST(minus_cephes_DP2, -2.4187564849853515625e-4f);
_PS_CONST(minus_cephes_DP3, -3.77489497744594108e-8f);
_PS_CONST(sincof_p0, -1.9515295891E-4f);
_PS_CONST(sincof_p1, 8.3321608736E-3f);
_PS_CONST(sincof_p2, -1.6666654611E-1f);
_PS_CONST(coscof_p0, 2.443315711809948E-005f);
_PS_CONST(coscof_p1, -1.388731625493765E-003f);
_PS_CONST(coscof_p2, 4.166664568298827E-002f);
_PS_CONST(cephes_FOPI, 1.27323954473516f); // 4 / M_PI
/* evaluation of 4 sines at onces, using only SSE1+MMX intrinsics so
@ -344,7 +344,7 @@ v4sf sin_ps(v4sf x) { // any x
x = _mm_and_ps(x, *(v4sf*)_ps_inv_sign_mask);
/* extract the sign bit (upper one) */
sign_bit = _mm_and_ps(sign_bit, *(v4sf*)_ps_sign_mask);
/* scale by 4/Pi */
y = _mm_mul_ps(x, *(v4sf*)_ps_cephes_FOPI);
@ -359,7 +359,7 @@ v4sf sin_ps(v4sf x) { // any x
/* get the swap sign flag */
emm0 = _mm_and_si128(emm2, *(v4si*)_pi32_4);
emm0 = _mm_slli_epi32(emm0, 29);
/* get the polynom selection mask
/* get the polynom selection mask
there is one polynom for 0 <= x <= Pi/4
and another one for Pi/4<x<=Pi/2
@ -367,11 +367,11 @@ v4sf sin_ps(v4sf x) { // any x
*/
emm2 = _mm_and_si128(emm2, *(v4si*)_pi32_2);
emm2 = _mm_cmpeq_epi32(emm2, _mm_setzero_si128());
v4sf swap_sign_bit = _mm_castsi128_ps(emm0);
v4sf poly_mask = _mm_castsi128_ps(emm2);
sign_bit = _mm_xor_ps(sign_bit, swap_sign_bit);
#else
/* store the integer part of y in mm0:mm1 */
xmm2 = _mm_movehl_ps(xmm2, y);
@ -399,8 +399,8 @@ v4sf sin_ps(v4sf x) { // any x
sign_bit = _mm_xor_ps(sign_bit, swap_sign_bit);
_mm_empty(); /* good-bye mmx */
#endif
/* The magic pass: "Extended precision modular arithmetic"
/* The magic pass: "Extended precision modular arithmetic"
x = ((x - y * DP1) - y * DP2) - y * DP3; */
xmm1 = *(v4sf*)_ps_minus_cephes_DP1;
xmm2 = *(v4sf*)_ps_minus_cephes_DP2;
@ -425,7 +425,7 @@ v4sf sin_ps(v4sf x) { // any x
v4sf tmp = _mm_mul_ps(z, *(v4sf*)_ps_0p5);
y = _mm_sub_ps(y, tmp);
y = _mm_add_ps(y, *(v4sf*)_ps_1);
/* Evaluate the second polynom (Pi/4 <= x <= 0) */
v4sf y2 = *(v4sf*)_ps_sincof_p0;
@ -437,7 +437,7 @@ v4sf sin_ps(v4sf x) { // any x
y2 = _mm_mul_ps(y2, x);
y2 = _mm_add_ps(y2, x);
/* select the correct result from the two polynoms */
/* select the correct result from the two polynoms */
xmm3 = poly_mask;
y2 = _mm_and_ps(xmm3, y2); //, xmm3);
y = _mm_andnot_ps(xmm3, y);
@ -457,10 +457,10 @@ v4sf cos_ps(v4sf x) { // any x
#endif
/* take the absolute value */
x = _mm_and_ps(x, *(v4sf*)_ps_inv_sign_mask);
/* scale by 4/Pi */
y = _mm_mul_ps(x, *(v4sf*)_ps_cephes_FOPI);
#ifdef USE_SSE2
/* store the integer part of y in mm0 */
emm2 = _mm_cvttps_epi32(y);
@ -470,14 +470,14 @@ v4sf cos_ps(v4sf x) { // any x
y = _mm_cvtepi32_ps(emm2);
emm2 = _mm_sub_epi32(emm2, *(v4si*)_pi32_2);
/* get the swap sign flag */
emm0 = _mm_andnot_si128(emm2, *(v4si*)_pi32_4);
emm0 = _mm_slli_epi32(emm0, 29);
/* get the polynom selection mask */
emm2 = _mm_and_si128(emm2, *(v4si*)_pi32_2);
emm2 = _mm_cmpeq_epi32(emm2, _mm_setzero_si128());
v4sf sign_bit = _mm_castsi128_ps(emm0);
v4sf poly_mask = _mm_castsi128_ps(emm2);
#else
@ -498,7 +498,7 @@ v4sf cos_ps(v4sf x) { // any x
mm2 = _mm_sub_pi32(mm2, *(v2si*)_pi32_2);
mm3 = _mm_sub_pi32(mm3, *(v2si*)_pi32_2);
/* get the swap sign flag in mm0:mm1 and the
/* get the swap sign flag in mm0:mm1 and the
polynom selection mask in mm2:mm3 */
mm0 = _mm_andnot_si64(mm2, *(v2si*)_pi32_4);
@ -517,7 +517,7 @@ v4sf cos_ps(v4sf x) { // any x
COPY_MM_TO_XMM(mm2, mm3, poly_mask);
_mm_empty(); /* good-bye mmx */
#endif
/* The magic pass: "Extended precision modular arithmetic"
/* The magic pass: "Extended precision modular arithmetic"
x = ((x - y * DP1) - y * DP2) - y * DP3; */
xmm1 = *(v4sf*)_ps_minus_cephes_DP1;
xmm2 = *(v4sf*)_ps_minus_cephes_DP2;
@ -528,7 +528,7 @@ v4sf cos_ps(v4sf x) { // any x
x = _mm_add_ps(x, xmm1);
x = _mm_add_ps(x, xmm2);
x = _mm_add_ps(x, xmm3);
/* Evaluate the first polynom (0 <= x <= Pi/4) */
y = *(v4sf*)_ps_coscof_p0;
v4sf z = _mm_mul_ps(x,x);
@ -542,7 +542,7 @@ v4sf cos_ps(v4sf x) { // any x
v4sf tmp = _mm_mul_ps(z, *(v4sf*)_ps_0p5);
y = _mm_sub_ps(y, tmp);
y = _mm_add_ps(y, *(v4sf*)_ps_1);
/* Evaluate the second polynom (Pi/4 <= x <= 0) */
v4sf y2 = *(v4sf*)_ps_sincof_p0;
@ -554,7 +554,7 @@ v4sf cos_ps(v4sf x) { // any x
y2 = _mm_mul_ps(y2, x);
y2 = _mm_add_ps(y2, x);
/* select the correct result from the two polynoms */
/* select the correct result from the two polynoms */
xmm3 = poly_mask;
y2 = _mm_and_ps(xmm3, y2); //, xmm3);
y = _mm_andnot_ps(xmm3, y);
@ -579,10 +579,10 @@ void sincos_ps(v4sf x, v4sf *s, v4sf *c) {
x = _mm_and_ps(x, *(v4sf*)_ps_inv_sign_mask);
/* extract the sign bit (upper one) */
sign_bit_sin = _mm_and_ps(sign_bit_sin, *(v4sf*)_ps_sign_mask);
/* scale by 4/Pi */
y = _mm_mul_ps(x, *(v4sf*)_ps_cephes_FOPI);
#ifdef USE_SSE2
/* store the integer part of y in emm2 */
emm2 = _mm_cvttps_epi32(y);
@ -638,7 +638,7 @@ void sincos_ps(v4sf x, v4sf *s, v4sf *c) {
COPY_MM_TO_XMM(mm2, mm3, poly_mask);
#endif
/* The magic pass: "Extended precision modular arithmetic"
/* The magic pass: "Extended precision modular arithmetic"
x = ((x - y * DP1) - y * DP2) - y * DP3; */
xmm1 = *(v4sf*)_ps_minus_cephes_DP1;
xmm2 = *(v4sf*)_ps_minus_cephes_DP2;
@ -670,7 +670,7 @@ void sincos_ps(v4sf x, v4sf *s, v4sf *c) {
sign_bit_sin = _mm_xor_ps(sign_bit_sin, swap_sign_bit_sin);
/* Evaluate the first polynom (0 <= x <= Pi/4) */
v4sf z = _mm_mul_ps(x,x);
y = *(v4sf*)_ps_coscof_p0;
@ -684,7 +684,7 @@ void sincos_ps(v4sf x, v4sf *s, v4sf *c) {
v4sf tmp = _mm_mul_ps(z, *(v4sf*)_ps_0p5);
y = _mm_sub_ps(y, tmp);
y = _mm_add_ps(y, *(v4sf*)_ps_1);
/* Evaluate the second polynom (Pi/4 <= x <= 0) */
v4sf y2 = *(v4sf*)_ps_sincof_p0;
@ -696,7 +696,7 @@ void sincos_ps(v4sf x, v4sf *s, v4sf *c) {
y2 = _mm_mul_ps(y2, x);
y2 = _mm_add_ps(y2, x);
/* select the correct result from the two polynoms */
/* select the correct result from the two polynoms */
xmm3 = poly_mask;
v4sf ysin2 = _mm_and_ps(xmm3, y2);
v4sf ysin1 = _mm_andnot_ps(xmm3, y);
@ -705,7 +705,7 @@ void sincos_ps(v4sf x, v4sf *s, v4sf *c) {
xmm1 = _mm_add_ps(ysin1,ysin2);
xmm2 = _mm_add_ps(y,y2);
/* update the sign */
*s = _mm_xor_ps(xmm1, sign_bit_sin);
*c = _mm_xor_ps(xmm2, sign_bit_cos);

View file

@ -107,7 +107,7 @@ int sfizz_get_num_curves(sfizz_synth_t* synth);
*
* @return int the number of preloaded samples
*/
int sfizz_get_num_preloaded_samples(sfizz_synth_t* synth);
size_t sfizz_get_num_preloaded_samples(sfizz_synth_t* synth);
/**
* @brief Returns the number of active voices. Note that this function is a
* basic indicator and does not aim to be perfect. In particular, it
@ -116,7 +116,7 @@ int sfizz_get_num_preloaded_samples(sfizz_synth_t* synth);
*
* @param synth The synth
*
* @return int the number of playing voices
* @return size_t the number of playing voices
*/
int sfizz_get_num_active_voices(sfizz_synth_t* synth);

View file

@ -70,7 +70,7 @@ Type ADSREnvelope<Type>::getNextValue() noexcept
return start;
currentState = State::Attack;
step = (1.0 - currentValue) / (attack > 0 ? attack : 1);
step = (static_cast<Type>(1.0) - currentValue) / (attack > 0 ? attack : 1);
[[fallthrough]];
case State::Attack:
if (attack-- > 0) {

View file

@ -42,7 +42,7 @@ namespace sfz
* @tparam MaxChannels the maximum number of channels in the buffer
* @tparam Alignment the alignment for the buffers
*/
template <class Type, int MaxChannels = sfz::config::numChannels, unsigned int Alignment = SIMDConfig::defaultAlignment>
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>;
@ -50,7 +50,6 @@ public:
using const_pointer = const value_type*;
using iterator = pointer;
using const_iterator = const_pointer;
using size_type = size_t;
/**
* @brief Construct a new Audio Buffer object
@ -67,11 +66,11 @@ public:
* @param numChannels
* @param numFrames
*/
AudioBuffer(int numChannels, int numFrames)
AudioBuffer(size_t numChannels, size_t numFrames)
: numChannels(numChannels)
, numFrames(numFrames)
{
for (auto i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
buffers[i] = std::make_unique<buffer_type>(numFrames);
}
@ -82,11 +81,11 @@ public:
* @return true if the resize worked
* @return false otherwise
*/
bool resize(size_type newSize)
bool resize(size_t newSize)
{
bool returnedOK = true;
for (auto i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
returnedOK &= buffers[i]->resize(newSize);
if (returnedOK)
@ -101,7 +100,7 @@ public:
* @param channelIndex
* @return iterator
*/
iterator channelWriter(int channelIndex)
iterator channelWriter(size_t channelIndex)
{
ASSERT(channelIndex < numChannels)
if (channelIndex < numChannels)
@ -116,7 +115,7 @@ public:
* @param channelIndex
* @return iterator
*/
iterator channelWriterEnd(int channelIndex)
iterator channelWriterEnd(size_t channelIndex)
{
ASSERT(channelIndex < numChannels)
if (channelIndex < numChannels)
@ -131,7 +130,7 @@ public:
* @param channelIndex
* @return const_iterator
*/
const_iterator channelReader(int channelIndex) const
const_iterator channelReader(size_t channelIndex) const
{
ASSERT(channelIndex < numChannels)
if (channelIndex < numChannels)
@ -146,7 +145,7 @@ public:
* @param channelIndex
* @return const_iterator
*/
const_iterator channelReaderEnd(int channelIndex) const
const_iterator channelReaderEnd(size_t channelIndex) const
{
ASSERT(channelIndex < numChannels)
if (channelIndex < numChannels)
@ -161,7 +160,7 @@ public:
* @param channelIndex
* @return absl::Span<value_type>
*/
absl::Span<value_type> getSpan(int channelIndex) const
absl::Span<value_type> getSpan(size_t channelIndex) const
{
ASSERT(channelIndex < numChannels)
if (channelIndex < numChannels)
@ -176,7 +175,7 @@ public:
* @param channelIndex
* @return absl::Span<const value_type>
*/
absl::Span<const value_type> getConstSpan(int channelIndex) const
absl::Span<const value_type> getConstSpan(size_t channelIndex) const
{
return getSpan(channelIndex);
}
@ -194,9 +193,9 @@ public:
/**
* @brief Get the number of elements in each buffer
*
* @return size_type
* @return size_t
*/
size_type getNumFrames() const
size_t getNumFrames() const
{
return numFrames;
}
@ -206,7 +205,7 @@ public:
*
* @return int
*/
int getNumChannels() const
size_t getNumChannels() const
{
return numChannels;
}
@ -231,7 +230,7 @@ public:
* @param frameIndex
* @return Type&
*/
Type& getSample(int channelIndex, size_type frameIndex)
Type& getSample(size_t channelIndex, size_t frameIndex)
{
// Uhoh
ASSERT(buffers[channelIndex] != nullptr);
@ -247,7 +246,7 @@ public:
* @param frameIndex
* @return Type&
*/
Type& operator()(int channelIndex, size_type frameIndex)
Type& operator()(size_t channelIndex, size_t frameIndex)
{
return getSample(channelIndex, frameIndex);
}
@ -258,7 +257,7 @@ public:
*/
void reset()
{
for (int i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
buffers[i].reset();
numFrames = 0;
numChannels = 0;
@ -269,10 +268,10 @@ public:
*
* @param numChannels
*/
void addChannels(int numChannels)
void addChannels(size_t numChannels)
{
ASSERT(this->numChannels + numChannels <= MaxChannels);
for (int i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
addChannel();
}
@ -281,7 +280,7 @@ private:
using buffer_ptr = std::unique_ptr<buffer_type>;
static_assert(MaxChannels > 0, "Need a positive number of channels");
std::array<buffer_ptr, MaxChannels> buffers;
int numChannels { 0 };
size_type numFrames { 0 };
size_t numChannels { 0 };
size_t numFrames { 0 };
};
}

View file

@ -86,7 +86,7 @@ namespace sfz
* @tparam Type the underlying buffer type
* @tparam MaxChannels the maximum number of channels. Defaults to sfz::config::numChannels
*/
template <class Type, int MaxChannels = sfz::config::numChannels>
template <class Type, size_t MaxChannels = sfz::config::numChannels>
class AudioSpan {
public:
using size_type = size_t;
@ -102,12 +102,12 @@ public:
* @param offset starting offset for the AudioSpan
* @param numFrames size of the AudioSpan
*/
AudioSpan(const std::array<Type*, MaxChannels>& spans, int numChannels, size_type offset, size_type numFrames)
AudioSpan(const std::array<Type*, MaxChannels>& spans, size_type numChannels, size_type offset, size_type numFrames)
: numFrames(numFrames)
, numChannels(numChannels)
{
ASSERT(numChannels <= MaxChannels);
for (auto i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
this->spans[i] = spans[i] + offset;
}
@ -164,12 +164,12 @@ public:
* @tparam Alignment the alignment block size for the platform
* @param audioBuffer the source AudioBuffer.
*/
template <class U, int 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 = std::enable_if<N <= MaxChannels>, typename = std::enable_if_t<std::is_const<U>::value, int>>
AudioSpan(AudioBuffer<U, N, Alignment>& audioBuffer)
: numFrames(audioBuffer.getNumFrames())
, numChannels(audioBuffer.getNumChannels())
{
for (int i = 0; i < numChannels; i++) {
for (size_t i = 0; i < numChannels; i++) {
this->spans[i] = audioBuffer.channelReader(i);
}
}
@ -185,12 +185,12 @@ public:
* @tparam Alignment the alignment block size for the platform
* @param audioBuffer the source AudioBuffer.
*/
template <class U, int N, unsigned int Alignment, typename = std::enable_if<N <= MaxChannels>>
template <class U, size_t N, unsigned int Alignment, typename = std::enable_if<N <= MaxChannels>>
AudioSpan(AudioBuffer<U, N, Alignment>& audioBuffer)
: numFrames(audioBuffer.getNumFrames())
, numChannels(audioBuffer.getNumChannels())
{
for (int i = 0; i < numChannels; i++) {
for (size_t i = 0; i < numChannels; i++) {
this->spans[i] = audioBuffer.channelWriter(i);
}
}
@ -200,12 +200,12 @@ public:
*
* @param other the other AudioSpan
*/
template <class U, int N, typename = std::enable_if<N <= MaxChannels>>
template <class U, size_t N, typename = std::enable_if<N <= MaxChannels>>
AudioSpan(const AudioSpan<U, N>& other)
: numFrames(other.getNumFrames())
, numChannels(other.getNumChannels())
{
for (int i = 0; i < numChannels; i++) {
for (size_t i = 0; i < numChannels; i++) {
this->spans[i] = other.getChannel(i);
}
}
@ -216,7 +216,7 @@ public:
* @param channelIndex the channel
* @return Type* the raw pointer to the channel
*/
Type* getChannel(int channelIndex)
Type* getChannel(size_t channelIndex)
{
ASSERT(channelIndex < numChannels);
if (channelIndex < numChannels)
@ -231,7 +231,7 @@ public:
* @param channelIndex the channel
* @return absl::Span<Type>
*/
absl::Span<Type> getSpan(int channelIndex)
absl::Span<Type> getSpan(size_t channelIndex)
{
ASSERT(channelIndex < numChannels);
if (channelIndex < numChannels)
@ -246,7 +246,7 @@ public:
* @param channelIndex the channel
* @return absl::Span<const Type>
*/
absl::Span<const Type> getConstSpan(int channelIndex)
absl::Span<const Type> getConstSpan(size_t channelIndex)
{
ASSERT(channelIndex < numChannels);
if (channelIndex < numChannels)
@ -265,7 +265,7 @@ public:
if (numChannels == 0)
return 0.0;
Type result = 0.0;
for (int i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
result += sfz::meanSquared<Type>(getConstSpan(i));
return result / numChannels;
}
@ -278,7 +278,7 @@ public:
void fill(Type value) noexcept
{
static_assert(!std::is_const<Type>::value, "Can't allow mutating operations on const AudioSpans");
for (int i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
sfz::fill<Type>(getSpan(i), value);
}
@ -290,7 +290,7 @@ public:
void applyGain(absl::Span<const Type> gain) noexcept
{
static_assert(!std::is_const<Type>::value, "Can't allow mutating operations on const AudioSpans");
for (int i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
sfz::applyGain<Type>(gain, getSpan(i));
}
@ -302,7 +302,7 @@ public:
void applyGain(Type gain) noexcept
{
static_assert(!std::is_const<Type>::value, "Can't allow mutating operations on const AudioSpans");
for (int i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
sfz::applyGain<Type>(gain, getSpan(i));
}
@ -312,13 +312,13 @@ public:
*
* @param other the other AudioSpan
*/
template <class U, int N, typename = std::enable_if<N <= MaxChannels>>
template <class U, size_t N, typename = std::enable_if<N <= MaxChannels>>
void add(AudioSpan<U, N>& other)
{
static_assert(!std::is_const<Type>::value, "Can't allow mutating operations on const AudioSpans");
ASSERT(other.getNumChannels() == numChannels);
if (other.getNumChannels() == numChannels) {
for (int i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
sfz::add<Type>(other.getConstSpan(i), getSpan(i));
}
}
@ -329,13 +329,13 @@ public:
*
* @param other the other AudioSpan
*/
template <class U, int N, typename = std::enable_if<N <= MaxChannels>>
template <class U, size_t N, typename = std::enable_if<N <= MaxChannels>>
void copy(AudioSpan<U, N>& other)
{
static_assert(!std::is_const<Type>::value, "Can't allow mutating operations on const AudioSpans");
ASSERT(other.getNumChannels() == numChannels);
if (other.getNumChannels() == numChannels) {
for (int i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
sfz::copy<Type>(other.getConstSpan(i), getSpan(i));
}
}
@ -355,7 +355,7 @@ public:
*
* @returns size_type the number of channels in the AudioSpan
*/
int getNumChannels()
size_t getNumChannels()
{
return numChannels;
}
@ -413,6 +413,6 @@ private:
static_assert(MaxChannels > 0, "Need a positive number of channels");
std::array<Type*, MaxChannels> spans;
size_type numFrames { 0 };
int numChannels { 0 };
size_type numChannels { 0 };
};
}

View file

@ -68,6 +68,21 @@ public:
bytes.fetch_sub(size);
}
void bufferDeleted(size_t size)
{
bufferDeleted(static_cast<int>(size));
}
void bufferResized(size_t oldSize, size_t newSize)
{
bufferResized(static_cast<int>(oldSize), static_cast<int>(newSize));
}
void newBuffer(size_t size)
{
newBuffer(static_cast<int>(size));
}
int getNumBuffers() { return numBuffers; }
int getTotalBytes() { return bytes; }
private:
@ -165,7 +180,7 @@ public:
*/
void clear()
{
counter().bufferResized(largerSize * sizeof(value_type), 0);
counter().bufferResized(largerSize * sizeof(value_type), static_cast<size_t>(0));
largerSize = 0;
alignedSize = 0;
std::free(paddedData);
@ -235,7 +250,7 @@ public:
// return *this;
// }
Type& operator[](int idx) { return *(normalData + idx); }
Type& operator[](size_t idx) { return *(normalData + idx); }
constexpr pointer data() const noexcept { return normalData; }
constexpr size_type size() const noexcept { return alignedSize; }
constexpr bool empty() const noexcept { return alignedSize == 0; }

View file

@ -22,6 +22,12 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#ifdef _WIN32
// There's a spurious min/max function in MSVC that makes everything go badly...
#define NOMINMAX
#define _SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING
#endif
#include <cstddef>
namespace sfz {
enum class Oversampling: int {
@ -36,7 +42,7 @@ namespace config {
constexpr int defaultSamplesPerBlock { 1024 };
constexpr int maxBlockSize { 8192 };
constexpr int preloadSize { 8192 };
constexpr int numChannels { 2 };
constexpr size_t numChannels { 2 };
constexpr int numBackgroundThreads { 4 };
constexpr int numVoices { 64 };
constexpr int maxVoices { 256 };
@ -50,12 +56,12 @@ namespace config {
constexpr int halfCCThreshold { 64 };
constexpr int centPerSemitone { 100 };
constexpr float virtuallyZero { 0.00005f };
constexpr float fastReleaseDuration { 0.01 };
constexpr float fastReleaseDuration { 0.01f };
constexpr char defineCharacter { '$' };
constexpr Oversampling defaultOversamplingFactor { Oversampling::x1 };
constexpr float A440 { 440.0 };
constexpr unsigned powerHistoryLength { 16 };
constexpr float voiceStealingThreshold { 0.00001 };
constexpr size_t powerHistoryLength { 16 };
constexpr float voiceStealingThreshold { 0.00001f };
constexpr int numCCs { 143 };
constexpr int chunkSize { 1024 };
} // namespace config

View file

@ -73,7 +73,7 @@ void EventEnvelope<Type>::prepareEvents()
absl::c_sort(events, [](const auto& lhs, const auto& rhs) {
return lhs.first < rhs.first;
});
resetEvents = true;
}
@ -134,7 +134,7 @@ void LinearEnvelope<Type>::getQuantizedBlock(absl::Span<Type> output, Type quant
EventEnvelope<Type>::getQuantizedBlock(output, quantizationStep);
auto& events = EventEnvelope<Type>::events;
auto& currentValue = EventEnvelope<Type>::currentValue;
ASSERT(quantizationStep != 0.0);
int index { 0 };
@ -167,7 +167,7 @@ void LinearEnvelope<Type>::getQuantizedBlock(absl::Span<Type> output, Type quant
continue;
}
const int numSteps = difference / quantizationStep;
const auto numSteps = static_cast<int>(difference / quantizationStep);
const auto stepLength = static_cast<int>(length / numSteps);
for (int i = 0; i < numSteps; ++i) {
fill<Type>(output.subspan(index, stepLength), currentValue);
@ -218,15 +218,15 @@ void MultiplicativeEnvelope<Type>::getQuantizedBlock(absl::Span<Type> output, Ty
EventEnvelope<Type>::getQuantizedBlock(output, quantizationStep);
auto& events = EventEnvelope<Type>::events;
auto& currentValue = EventEnvelope<Type>::currentValue;
ASSERT(quantizationStep != 0.0);
int index { 0 };
const auto logStep = std::log(quantizationStep);
// If we assume that a = b.q^r for b in (1, q) then
// log a log b
// ----- = ----- + r
// log q log q
// log a log b
// ----- = ----- + r
// log q log q
// and log(b)\log(q) is between 0 and 1.
auto quantize = [logStep](Type value) -> Type {
return std::exp(logStep * std::round(std::log(value)/logStep));
@ -257,11 +257,11 @@ void MultiplicativeEnvelope<Type>::getQuantizedBlock(absl::Span<Type> output, Ty
continue;
}
const int numSteps = std::log(difference) / logStep;
const auto numSteps = static_cast<int>(std::log(difference) / logStep);
const auto stepLength = static_cast<int>(length / numSteps);
for (int i = 0; i < numSteps; ++i) {
fill<Type>(output.subspan(index, stepLength), currentValue);
const auto delta = newValue > currentValue ?
const auto delta = newValue > currentValue ?
quantize(currentValue) / currentValue * quantizationStep :
quantize(currentValue) / currentValue / quantizationStep ;
currentValue *= delta;

View file

@ -108,7 +108,7 @@ absl::optional<sfz::FilePool::FileInformation> sfz::FilePool::getFileInformation
if (!fs::exists(file))
return {};
SndfileHandle sndFile(file.c_str());
SndfileHandle sndFile(file.string().c_str());
if (sndFile.channels() != 1 && sndFile.channels() != 2) {
DBG("Missing logic for " << sndFile.channels() << " channels, discarding sample " << filename);
return {};
@ -135,12 +135,12 @@ bool sfz::FilePool::preloadFile(const std::string& filename, uint32_t maxOffset)
if (!fs::exists(file))
return false;
SndfileHandle sndFile(file.c_str());
SndfileHandle sndFile(file.string().c_str());
if (sndFile.channels() != 1 && sndFile.channels() != 2)
return false;
// FIXME: Large offsets will require large preloading; is this OK in practice? Apparently sforzando does the same
const uint32_t frames = sndFile.frames();
const auto frames = static_cast<uint32_t>(sndFile.frames());
const auto framesToLoad = [&]() {
if (preloadSize == 0)
return frames;
@ -196,9 +196,9 @@ void sfz::FilePool::setPreloadSize(uint32_t preloadSize) noexcept
// Update all the preloaded sizes
for (auto& preloadedFile : preloadedFiles) {
const auto numFrames = preloadedFile.second.preloadedData->getNumFrames() / static_cast<int>(oversamplingFactor);
const uint32_t maxOffset = numFrames > this->preloadSize ? numFrames - this->preloadSize : 0;
const auto maxOffset = numFrames > this->preloadSize ? static_cast<uint32_t>(numFrames) - this->preloadSize : 0;
fs::path file { rootDirectory / std::string(preloadedFile.first) };
SndfileHandle sndFile(file.c_str());
SndfileHandle sndFile(file.string().c_str());
preloadedFile.second.preloadedData = readFromFile<float>(sndFile, preloadSize + maxOffset, oversamplingFactor);
}
this->preloadSize = preloadSize;
@ -248,12 +248,12 @@ void sfz::FilePool::loadingThread() noexcept
[[maybe_unused]] const auto waitDurationMillis = std::chrono::duration<double,std::milli>(waitDuration).count();
fs::path file { rootDirectory / std::string(promise->filename) };
SndfileHandle sndFile(file.c_str());
SndfileHandle sndFile(file.string().c_str());
if (sndFile.error() != 0) {
DBG("[sfizz] libsndfile errored for " << promise->filename << " with message " << sndFile.strError());
continue;
}
const uint32_t frames = sndFile.frames();
const auto frames = static_cast<uint32_t>(sndFile.frames());
streamFromFile<float>(sndFile, frames, oversamplingFactor, promise->fileData, &promise->availableFrames);
promise->dataReady = true;
threadsLoading--;
@ -289,17 +289,17 @@ void sfz::FilePool::cleanupPromises() noexcept
// The garbage collection cleared the data from these so we can move them
// back to the empty queue
auto clearedIterator = promisesToClear.begin();
auto clearedSentinel = promisesToClear.end() - 1;
while (clearedIterator != promisesToClear.end()) {
auto clearedSentinel = promisesToClear.rbegin();
while (clearedIterator < clearedSentinel.base()) {
if (clearedIterator->get()->dataReady == false) {
emptyPromises.push_back(*clearedIterator);
std::iter_swap(clearedIterator, clearedSentinel);
clearedSentinel--;
promisesToClear.pop_back();
++clearedSentinel;
} else {
clearedIterator++;
++clearedIterator;
}
}
promisesToClear.resize(std::distance(promisesToClear.begin(), clearedSentinel.base()));
FilePromisePtr promise;
// Remove the promises from the filled queue and put them in a linear
@ -308,17 +308,17 @@ void sfz::FilePool::cleanupPromises() noexcept
temporaryFilePromises.push_back(promise);
auto filledIterator = temporaryFilePromises.begin();
auto filledSentinel = temporaryFilePromises.end() - 1;
while (filledIterator != temporaryFilePromises.end()) {
auto filledSentinel = temporaryFilePromises.rbegin();
while (filledIterator < filledSentinel.base()) {
if (filledIterator->use_count() == 1) {
promisesToClear.push_back(*filledIterator);
std::iter_swap(filledIterator, filledSentinel);
filledSentinel--;
temporaryFilePromises.pop_back();
++filledSentinel;
} else {
filledIterator++;
++filledIterator;
}
}
temporaryFilePromises.resize(std::distance(temporaryFilePromises.begin(), filledSentinel.base()));
}
void sfz::FilePool::setOversamplingFactor(sfz::Oversampling factor) noexcept
@ -326,9 +326,9 @@ void sfz::FilePool::setOversamplingFactor(sfz::Oversampling factor) noexcept
float samplerateChange { static_cast<float>(factor) / static_cast<float>(this->oversamplingFactor) };
for (auto& preloadedFile : preloadedFiles) {
const auto numFrames = preloadedFile.second.preloadedData->getNumFrames() / static_cast<int>(this->oversamplingFactor);
const uint32_t maxOffset = numFrames > this->preloadSize ? numFrames - this->preloadSize : 0;
const uint32_t maxOffset = numFrames > this->preloadSize ? static_cast<uint32_t>(numFrames) - this->preloadSize : 0;
fs::path file { rootDirectory / std::string(preloadedFile.first) };
SndfileHandle sndFile(file.c_str());
SndfileHandle sndFile(file.string().c_str());
preloadedFile.second.preloadedData = readFromFile<float>(sndFile, preloadSize + maxOffset, factor);
preloadedFile.second.sampleRate *= samplerateChange;
}

View file

@ -26,7 +26,7 @@ public:
*
* @param size
*/
void resize(int size)
void resize(size_t size)
{
buffer.resize(size);
fill<ValueType>(absl::MakeSpan(buffer), 0.0);

View file

@ -29,6 +29,7 @@
* @date 2019-11-23
*/
#pragma once
#include "Config.h"
#include <algorithm>
#include <cmath>
#include <cassert>
@ -156,14 +157,14 @@ constexpr ValueType linearInterpolation(ValueType left, ValueType right, ValueTy
}
template <class Type>
constexpr Type pi { 3.141592653589793238462643383279502884 };
constexpr Type pi { static_cast<Type>(3.141592653589793238462643383279502884) };
template <class Type>
constexpr Type twoPi { 2 * pi<Type> };
constexpr Type twoPi { static_cast<Type>(2) * pi<Type> };
template <class Type>
constexpr Type piTwo { pi<Type> / 2 };
constexpr Type piTwo { pi<Type> / static_cast<Type>(2) };
template <class Type>
constexpr Type piFour { pi<Type> / 4 };
constexpr Type piFour { pi<Type> / static_cast<Type>(4) };
template <class Type>
constexpr Type sqrtTwo { 1.414213562373095048801688724209698078569671875376948073176 };
constexpr Type sqrtTwo { static_cast<Type>(1.414213562373095048801688724209698078569671875376948073176) };
template <class Type>
constexpr Type sqrtTwoInv { 0.707106781186547524400844362104849039284835937688474036588 };
constexpr Type sqrtTwoInv { static_cast<Type>(0.707106781186547524400844362104849039284835937688474036588) };

View file

@ -59,7 +59,7 @@ public:
Type getGain() const { return gain; }
int processLowpass(absl::Span<const Type> input, absl::Span<Type> lowpass)
size_t processLowpass(absl::Span<const Type> input, absl::Span<Type> lowpass)
{
auto in = input.begin();
auto out = lowpass.begin();
@ -73,7 +73,7 @@ public:
return size;
}
int processHighpass(absl::Span<const Type> input, absl::Span<Type> highpass)
size_t processHighpass(absl::Span<const Type> input, absl::Span<Type> highpass)
{
auto in = input.begin();
auto out = highpass.begin();
@ -87,7 +87,7 @@ public:
return size;
}
int processLowpassVariableGain(absl::Span<const Type> input, absl::Span<Type> lowpass, absl::Span<const Type> gain)
size_t processLowpassVariableGain(absl::Span<const Type> input, absl::Span<Type> lowpass, absl::Span<const Type> gain)
{
auto in = input.begin();
auto out = lowpass.begin();
@ -104,7 +104,7 @@ public:
return size;
}
int processHighpassVariableGain(absl::Span<const Type> input, absl::Span<Type> highpass, absl::Span<const Type> gain)
size_t processHighpassVariableGain(absl::Span<const Type> input, absl::Span<Type> highpass, absl::Span<const Type> gain)
{
auto in = input.begin();
auto out = highpass.begin();

View file

@ -104,7 +104,7 @@ void sfz::Oversampler::stream(const sfz::AudioBuffer<float>& input, sfz::AudioBu
upsampler.set_coefs(coeffsStage2x.data());
break;
case Oversampling::x1:
for (int i = 0; i < numChannels; ++i)
for (size_t i = 0; i < numChannels; ++i)
copy<float>(input.getConstSpan(i), output.getSpan(i));
return;
}
@ -122,22 +122,22 @@ 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) };
for (int chanIdx = 0; chanIdx < numChannels; chanIdx++) {
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);
if (factor == Oversampling::x2) {
upsampler2x[chanIdx].process_block(outputChunk.data(), inputChunk.data(), thisChunkSize);
upsampler2x[chanIdx].process_block(outputChunk.data(), inputChunk.data(), static_cast<long>(thisChunkSize));
continue;
}
if (factor == Oversampling::x4) {
upsampler2x[chanIdx].process_block(span1.data(), inputChunk.data(), thisChunkSize);
upsampler4x[chanIdx].process_block(outputChunk.data(), span1.data(), thisChunkSize * 2);
upsampler2x[chanIdx].process_block(span1.data(), inputChunk.data(), static_cast<long>(thisChunkSize));
upsampler4x[chanIdx].process_block(outputChunk.data(), span1.data(), static_cast<long>(thisChunkSize * 2));
continue;
}
else if (factor == Oversampling::x8) {
upsampler2x[chanIdx].process_block(span1.data(), inputChunk.data(), thisChunkSize);
upsampler4x[chanIdx].process_block(span2.data(), span1.data(), thisChunkSize * 2);
upsampler8x[chanIdx].process_block(outputChunk.data(), span2.data(), thisChunkSize * 4);
upsampler2x[chanIdx].process_block(span1.data(), inputChunk.data(), static_cast<long>(thisChunkSize));
upsampler4x[chanIdx].process_block(span2.data(), span1.data(), static_cast<long>(thisChunkSize * 2));
upsampler8x[chanIdx].process_block(outputChunk.data(), span2.data(), static_cast<long>(thisChunkSize * 4));
continue;
}
}

View file

@ -22,7 +22,6 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Parser.h"
#include "Config.h"
#include "StringViewHelpers.h"
#include "SfzHelpers.h"
#include "absl/strings/str_join.h"

View file

@ -22,6 +22,7 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "Config.h"
#include "Opcode.h"
#include "ghc/fs_std.hpp"
#include <map>

View file

@ -98,9 +98,9 @@ constexpr float normalizePercents(T percentValue)
* @param bendValue
* @return constexpr float
*/
constexpr float normalizeBend(int bendValue)
constexpr float normalizeBend(float bendValue)
{
return std::min(std::max(static_cast<float>(bendValue), -8191.0f), 8191.0f) / 8191.0f;
return std::min(std::max(bendValue, -8191.0f), 8191.0f) / 8191.0f;
}
/**
@ -145,10 +145,10 @@ absl::optional<uint8_t> readNoteValue(const absl::string_view& value);
* return them, while updating the source by removing this header
* and members from the beginning. The function "consumes" the
* header and its members from the source if found.
*
*
* No check is made to see if the header is "valid" in the sfz sense.
* The output parameters are set only if the method returns true.
*
*
* @param source A source view; can be updated and shortened
* @param header An output view on the header, without the <>
* @param members An output view on the members, untrimmed
@ -161,44 +161,44 @@ bool findHeader(absl::string_view& source, absl::string_view& header, absl::stri
* Return them while updating the source by removing this opcode
* and value from the beginning. The function "consumes" the
* opcode from the source if one is found.
*
*
* No check is made to see if the opcode is "valid" in the sfz sense.
* The output parameters are set only if the method returns true.
*
*
* @param source A source view; can be updated and shortened
* @param opcode An output view on the opcode name
* @param value An output view on the opcode value
* @return true if an opcode was found
* @return false
* @return false
*/
bool findOpcode(absl::string_view& source, absl::string_view& opcode, absl::string_view& value);
/**
* @brief Find an SFZ #define statement on a line and return the variable and value as views.
*
*
* This function assums that there is a single define per line and that the variable and value
* are separated by whitespace.
* The output parameters are set only if the method returns true.
*
*
* @param line The source line
* @param variable An output view on the define variable
* @param value An output view on the define value
* @return true If a define was found
* @return false
* @return false
*/
bool findDefine(absl::string_view line, absl::string_view& variable, absl::string_view& value);
/**
* @brief Find an SFZ #include statement on a line and return included path.
*
*
* This function assums that there is a single include per line and that the
* include path is within quotes.
* The output parameter is set only if the method returns true.
*
*
* @param line The source line
* @param path The path, if found
* @return true If an include was found
* @return false
* @return false
*/
bool findInclude(absl::string_view line, std::string& path);

View file

@ -237,9 +237,9 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
resources.filePool.setRootDirectory(this->originalDirectory);
auto lastRegion = regions.end() - 1;
auto currentRegion = regions.begin();
while (currentRegion <= lastRegion) {
auto lastRegion = regions.rbegin();
while (currentRegion < lastRegion.base()) {
auto region = currentRegion->get();
if (!region->isGenerator()) {
@ -247,7 +247,7 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
if (!fileInformation) {
DBG("Removing the region with sample " << region->sample);
std::iter_swap(currentRegion, lastRegion);
lastRegion--;
++lastRegion;
continue;
}
region->sampleEnd = std::min(region->sampleEnd, fileInformation->end);
@ -298,11 +298,11 @@ bool sfz::Synth::loadSfzFile(const fs::path& filename)
region->registerAftertouch(0);
region->registerTempo(2.0f);
currentRegion++;
++currentRegion;
}
DBG("Removed " << regions.size() - std::distance(regions.begin(), lastRegion) - 1 << " out of " << regions.size() << " regions.");
regions.resize(std::distance(regions.begin(), lastRegion) + 1);
const auto remainingRegions = std::distance(regions.begin(), lastRegion.base());
DBG("Removing " << (regions.size() - remainingRegions) << " out of " << regions.size() << " regions");
regions.resize(remainingRegions);
modificationTime = checkModificationTime();
return parserReturned;

View file

@ -95,10 +95,10 @@ void sfz::Voice::startVoice(Region* region, int delay, int number, uint8_t value
pitchBendEnvelope.setFunction([region](float pitchValue){
const auto normalizedBend = normalizeBend(pitchValue);
const auto bendInCents = normalizedBend > 0 ? normalizedBend * region->bendUp : -normalizedBend * region->bendDown;
const auto bendInCents = normalizedBend > 0.0f ? normalizedBend * region->bendUp : -normalizedBend * region->bendDown;
return centsFactor(bendInCents);
});
pitchBendEnvelope.reset(midiState.getPitchBend());
pitchBendEnvelope.reset(static_cast<float>(midiState.getPitchBend()));
sourcePosition = region->getOffset();
triggerDelay = delay;
@ -209,7 +209,7 @@ void sfz::Voice::registerPitchWheel(int delay, int pitch) noexcept
if (state == State::idle)
return;
pitchBendEnvelope.registerEvent(delay, pitch);
pitchBendEnvelope.registerEvent(delay, static_cast<float>(pitch));
}
void sfz::Voice::registerAftertouch(int delay [[maybe_unused]], uint8_t aftertouch [[maybe_unused]]) noexcept
@ -246,13 +246,13 @@ void sfz::Voice::renderBlock(AudioSpan<float> buffer) noexcept
buffer.fill(0.0f);
if (state == State::idle || region == nullptr) {
powerHistory.push(0.0);
powerHistory.push(0.0f);
return;
}
auto delay = min(static_cast<size_t>(initialDelay), buffer.getNumFrames());
const auto delay = min(static_cast<size_t>(initialDelay), buffer.getNumFrames());
auto delayed_buffer = buffer.subspan(delay);
initialDelay -= delay;
initialDelay -= static_cast<int>(delay);
if (region->isGenerator())
fillWithGenerator(delayed_buffer);

View file

@ -22,8 +22,8 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include "ADSREnvelope.h"
#include "Config.h"
#include "ADSREnvelope.h"
#include "EventEnvelopes.h"
#include "HistoricalBuffer.h"
#include "Region.h"

View file

@ -66,7 +66,7 @@ int sfizz_get_num_curves(sfizz_synth_t* synth)
auto self = reinterpret_cast<sfz::Synth*>(synth);
return self->getNumCurves();
}
int sfizz_get_num_preloaded_samples(sfizz_synth_t* synth)
size_t sfizz_get_num_preloaded_samples(sfizz_synth_t* synth)
{
auto self = reinterpret_cast<sfz::Synth*>(synth);
return self->getNumPreloadedSamples();
@ -220,7 +220,7 @@ char* sfizz_get_unknown_opcodes(sfizz_synth_t* synth)
{
auto self = reinterpret_cast<sfz::Synth*>(synth);
const auto unknownOpcodes = self->getUnknownOpcodes();
int totalLength = 0;
size_t totalLength = 0;
for (auto& opcode: unknownOpcodes)
totalLength += opcode.length() + 1;

View file

@ -54,7 +54,7 @@ TEST_CASE("[ADSREnvelope] Basic state")
out = envelope.getNextValue();
REQUIRE(approxEqual<float>(output, expected));
absl::c_fill(output, -1.0);
absl::c_fill(output, -1.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -64,13 +64,13 @@ TEST_CASE("[ADSREnvelope] Attack")
sfz::ADSREnvelope<float> envelope;
envelope.reset(2, 0);
std::array<float, 5> output;
std::array<float, 5> expected { 0.5, 1.0, 1.0, 1.0, 1.0 };
std::array<float, 5> expected { 0.5f, 1.0f, 1.0f, 1.0f, 1.0f };
for (auto& out : output)
out = envelope.getNextValue();
REQUIRE(approxEqual<float>(output, expected));
envelope.reset(2, 0);
absl::c_fill(output, -1.0);
absl::c_fill(output, -1.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -80,13 +80,13 @@ TEST_CASE("[ADSREnvelope] Attack again")
sfz::ADSREnvelope<float> envelope;
envelope.reset(3, 0);
std::array<float, 5> output;
std::array<float, 5> expected { 0.33333, 0.66667, 1.0, 1.0, 1.0 };
std::array<float, 5> expected { 0.33333f, 0.66667f, 1.0f, 1.0f, 1.0f };
for (auto& out : output)
out = envelope.getNextValue();
REQUIRE(approxEqual<float>(output, expected));
envelope.reset(3, 0);
absl::c_fill(output, -1.0);
absl::c_fill(output, -1.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -97,14 +97,14 @@ TEST_CASE("[ADSREnvelope] Release")
envelope.reset(2, 4);
envelope.startRelease(2);
std::array<float, 8> output;
std::array<float, 8> expected { 0.5, 1.0, 0.08409f, 0.00707f, 0.000594604f, 0.00005f, 0.0f, 0.0f };
std::array<float, 8> expected { 0.5f, 1.0f, 0.08409f, 0.00707f, 0.000594604f, 0.00005f, 0.0f, 0.0f };
for (auto& out : output)
out = envelope.getNextValue();
REQUIRE(approxEqual<float>(output, expected));
envelope.reset(2, 4);
envelope.startRelease(2);
absl::c_fill(output, -1.0);
absl::c_fill(output, -1.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -115,14 +115,14 @@ TEST_CASE("[ADSREnvelope] Delay")
envelope.reset(2, 4, 1.0f, 2);
std::array<float, 10> output;
envelope.startRelease(4);
std::array<float, 10> expected { 0.0, 0.0, 0.5, 1.0, 0.08409f, 0.00707f, 0.000594604f, 0.00005f, 0.0f, 0.0f };
std::array<float, 10> expected { 0.0f, 0.0f, 0.5f, 1.0f, 0.08409f, 0.00707f, 0.000594604f, 0.00005f, 0.0f, 0.0f };
for (auto& out : output)
out = envelope.getNextValue();
REQUIRE(approxEqual<float>(output, expected));
envelope.reset(2, 4, 1.0f, 2);
envelope.startRelease(4);
absl::c_fill(output, -1.0);
absl::c_fill(output, -1.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -130,15 +130,15 @@ TEST_CASE("[ADSREnvelope] Delay")
TEST_CASE("[ADSREnvelope] Lower sustain")
{
sfz::ADSREnvelope<float> envelope;
envelope.reset(2, 4, 0.5, 2);
envelope.reset(2, 4, 0.5f, 2);
std::array<float, 10> output;
std::array<float, 10> expected { 0.0, 0.0, 0.5, 1.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5 };
std::array<float, 10> expected { 0.0f, 0.0f, 0.5f, 1.0f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f };
for (auto& out : output)
out = envelope.getNextValue();
REQUIRE(approxEqual<float>(output, expected));
envelope.reset(2, 4, 0.5, 2);
absl::c_fill(output, -1.0);
absl::c_fill(output, -1.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -146,15 +146,15 @@ TEST_CASE("[ADSREnvelope] Lower sustain")
TEST_CASE("[ADSREnvelope] Decay")
{
sfz::ADSREnvelope<float> envelope;
envelope.reset(2, 4, 0.5, 2, 2);
envelope.reset(2, 4, 0.5f, 2, 2);
std::array<float, 10> output;
std::array<float, 10> expected { 0.0, 0.0, 0.5, 1.0, 0.707107, 0.5, 0.5, 0.5, 0.5, 0.5 };
std::array<float, 10> expected { 0.0f, 0.0f, 0.5f, 1.0f, 0.707107f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5 };
for (auto& out : output)
out = envelope.getNextValue();
REQUIRE(approxEqual<float>(output, expected));
envelope.reset(2, 4, 0.5, 2, 2);
absl::c_fill(output, -1.0);
envelope.reset(2, 4, 0.5f, 2, 2);
absl::c_fill(output, -1.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -162,15 +162,15 @@ TEST_CASE("[ADSREnvelope] Decay")
TEST_CASE("[ADSREnvelope] Hold")
{
sfz::ADSREnvelope<float> envelope;
envelope.reset(2, 4, 0.5, 2, 2, 2);
envelope.reset(2, 4, 0.5f, 2, 2, 2);
std::array<float, 12> output;
std::array<float, 12> expected { 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 0.707107, 0.5, 0.5, 0.5, 0.5, 0.5 };
std::array<float, 12> expected { 0.0f, 0.0f, 0.5f, 1.0f, 1.0f, 1.0f, 0.707107f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f };
for (auto& out : output)
out = envelope.getNextValue();
REQUIRE(approxEqual<float>(output, expected));
envelope.reset(2, 4, 0.5, 2, 2, 2);
absl::c_fill(output, -1.0);
envelope.reset(2, 4, 0.5f, 2, 2, 2);
absl::c_fill(output, -1.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -178,17 +178,17 @@ TEST_CASE("[ADSREnvelope] Hold")
TEST_CASE("[ADSREnvelope] Hold with release")
{
sfz::ADSREnvelope<float> envelope;
envelope.reset(2, 4, 0.5, 2, 2, 2);
envelope.reset(2, 4, 0.5f, 2, 2, 2);
envelope.startRelease(8);
std::array<float, 14> output;
std::array<float, 14> expected { 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 0.707107, 0.5, 0.05, 0.005, 0.0005, 0.00005, 0.0, 0.0 };
std::array<float, 14> expected { 0.0f, 0.0f, 0.5f, 1.0f, 1.0f, 1.0f, 0.707107f, 0.5f, 0.05f, 0.005f, 0.0005f, 0.00005f, 0.0f, 0.0f };
for (auto& out : output)
out = envelope.getNextValue();
REQUIRE(approxEqual<float>(output, expected));
envelope.reset(2, 4, 0.5, 2, 2, 2);
envelope.reset(2, 4, 0.5f, 2, 2, 2);
envelope.startRelease(8);
absl::c_fill(output, -1.0);
absl::c_fill(output, -1.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -196,16 +196,16 @@ TEST_CASE("[ADSREnvelope] Hold with release")
TEST_CASE("[ADSREnvelope] Hold with release 2")
{
sfz::ADSREnvelope<float> envelope;
envelope.reset(2, 4, 0.5, 2, 2, 2);
envelope.reset(2, 4, 0.5f, 2, 2, 2);
envelope.startRelease(4);
std::array<float, 14> output;
std::array<float, 14> expected { 0.0, 0.0, 0.5, 1.0, 0.08409, 0.00707, 0.000594604, 0.00005, 0.0, 0.0, 0.0, 0.0 };
std::array<float, 14> expected { 0.0f, 0.0f, 0.5f, 1.0f, 0.08409f, 0.00707f, 0.000594604f, 0.00005f, 0.0f, 0.0f, 0.0f, 0.0 };
for (auto& out : output)
out = envelope.getNextValue();
REQUIRE(approxEqual<float>(output, expected));
envelope.reset(2, 4, 0.5, 2, 2, 2);
envelope.reset(2, 4, 0.5f, 2, 2, 2);
envelope.startRelease(4);
absl::c_fill(output, -1.0);
absl::c_fill(output, -1.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
}

View file

@ -61,15 +61,15 @@ TEST_CASE("[AudioBuffer] Access")
const int size { 5 };
sfz::AudioBuffer<float> buffer(2, size);
for (size_t frameIdx = 0; frameIdx < buffer.getNumFrames(); ++frameIdx) {
buffer.getSample(0, frameIdx) = static_cast<double>(buffer.getNumFrames()) + frameIdx;
buffer.getSample(1, frameIdx) = static_cast<double>(buffer.getNumFrames()) - frameIdx;
buffer.getSample(0, frameIdx) = static_cast<float>(buffer.getNumFrames()) + frameIdx;
buffer.getSample(1, frameIdx) = static_cast<float>(buffer.getNumFrames()) - frameIdx;
}
for (size_t frameIdx = 0; frameIdx < buffer.getNumFrames(); ++frameIdx) {
REQUIRE(buffer.getSample(0, frameIdx) == static_cast<double>(buffer.getNumFrames()) + frameIdx);
REQUIRE(buffer(0, frameIdx) == static_cast<double>(buffer.getNumFrames()) + frameIdx);
REQUIRE(buffer.getSample(1, frameIdx) == static_cast<double>(buffer.getNumFrames()) - frameIdx);
REQUIRE(buffer(1, frameIdx) == static_cast<double>(buffer.getNumFrames()) - frameIdx);
REQUIRE(buffer.getSample(0, frameIdx) == static_cast<float>(buffer.getNumFrames()) + frameIdx);
REQUIRE(buffer(0, frameIdx) == static_cast<float>(buffer.getNumFrames()) + frameIdx);
REQUIRE(buffer.getSample(1, frameIdx) == static_cast<float>(buffer.getNumFrames()) - frameIdx);
REQUIRE(buffer(1, frameIdx) == static_cast<float>(buffer.getNumFrames()) - frameIdx);
}
}
@ -98,5 +98,5 @@ TEST_CASE("[AudioSpan] Constructions")
sfz::AudioSpan<float> manualSpan { { buffer.channelWriter(0), buffer.channelWriter(1) }, buffer.getNumFrames() };
sfz::AudioSpan<const float> manualConstSpan { { buffer.channelReader(0), buffer.channelReader(1) }, buffer.getNumFrames() };
sfz::AudioSpan<float> manualSpan2 { {buffer.getSpan(0), buffer.getSpan(1) } };
sfz::AudioSpan<const float> manualConstSpan2 { {buffer.getConstSpan(0), buffer.getConstSpan(1) } };
}
sfz::AudioSpan<const float> manualConstSpan2 { { buffer.getConstSpan(0), buffer.getConstSpan(1) } };
}

View file

@ -28,17 +28,14 @@ set(SFIZZ_TEST_SOURCES
find_package(ZLIB REQUIRED)
add_library(cnpy cnpy/cnpy.cpp)
target_link_libraries(cnpy PRIVATE ZLIB::ZLIB)
target_link_libraries(cnpy PUBLIC ZLIB::ZLIB)
target_include_directories(cnpy PUBLIC cnpy)
add_executable(sfizz_tests ${SFIZZ_TEST_SOURCES})
target_link_libraries(sfizz_tests PRIVATE sfizz::sfizz)
sfizz_link_libsndfile(sfizz_tests)
# Per OS properties
if(UNIX)
target_link_libraries(sfizz_tests PRIVATE atomic)
endif(UNIX)
target_link_libraries(sfizz_tests PRIVATE absl::strings absl::str_format absl::flat_hash_map sndfile cnpy absl::span absl::algorithm)
target_link_libraries(sfizz_tests PRIVATE absl::strings absl::str_format absl::flat_hash_map cnpy absl::span absl::algorithm)
target_include_directories(sfizz_tests SYSTEM PRIVATE sources)
sfizz_enable_lto_if_needed(sfizz_tests)

View file

@ -31,7 +31,7 @@ TEST_CASE("[EGDescription] Attack range")
sfz::EGDescription eg;
sfz::SfzCCArray ccArray { 0 };
eg.attack = 1;
eg.vel2attack = -1.27;
eg.vel2attack = -1.27f;
eg.ccAttack = { 63, 1.27f };
REQUIRE( eg.getAttack(ccArray, 0) == 1.0f );
REQUIRE( eg.getAttack(ccArray, 127) == 0.0f );
@ -47,7 +47,7 @@ TEST_CASE("[EGDescription] Delay range")
sfz::EGDescription eg;
sfz::SfzCCArray ccArray { 0 };
eg.delay = 1;
eg.vel2delay = -1.27;
eg.vel2delay = -1.27f;
eg.ccDelay = { 63, 1.27f };
REQUIRE( eg.getDelay(ccArray, 0) == 1.0f );
REQUIRE( eg.getDelay(ccArray, 127) == 0.0f );
@ -79,7 +79,7 @@ TEST_CASE("[EGDescription] Release range")
sfz::EGDescription eg;
sfz::SfzCCArray ccArray { 0 };
eg.release = 1;
eg.vel2release = -1.27;
eg.vel2release = -1.27f;
eg.ccRelease = { 63, 1.27f };
REQUIRE( eg.getRelease(ccArray, 0) == 1.0f );
REQUIRE( eg.getRelease(ccArray, 127) == 0.0f );
@ -95,7 +95,7 @@ TEST_CASE("[EGDescription] Hold range")
sfz::EGDescription eg;
sfz::SfzCCArray ccArray { 0 };
eg.hold = 1;
eg.vel2hold = -1.27;
eg.vel2hold = -1.27f;
eg.ccHold = { 63, 1.27f };
REQUIRE( eg.getHold(ccArray, 0) == 1.0f );
REQUIRE( eg.getHold(ccArray, 127) == 0.0f );

View file

@ -51,7 +51,7 @@ TEST_CASE("[LinearEnvelope] Basic state")
{
sfz::LinearEnvelope<float> envelope;
std::array<float, 5> output;
std::array<float, 5> expected { 0.0, 0.0, 0.0, 0.0, 0.0 };
std::array<float, 5> expected { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -59,9 +59,9 @@ TEST_CASE("[LinearEnvelope] Basic state")
TEST_CASE("[LinearEnvelope] Basic event")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(4, 1.0);
envelope.registerEvent(4, 1.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.25, 0.5, 0.75, 1.0, 1.0, 1.0, 1.0, 1.0 };
std::array<float, 8> expected { 0.25f, 0.5f, 0.75f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -69,10 +69,10 @@ TEST_CASE("[LinearEnvelope] Basic event")
TEST_CASE("[LinearEnvelope] 2 events, close")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(4, 1.0);
envelope.registerEvent(5, 2.0);
envelope.registerEvent(4, 1.0f);
envelope.registerEvent(5, 2.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.25, 0.5, 0.75, 1.0, 2.0, 2.0, 2.0, 2.0 };
std::array<float, 8> expected { 0.25f, 0.5f, 0.75f, 1.0f, 2.0f, 2.0f, 2.0f, 2.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -80,10 +80,10 @@ TEST_CASE("[LinearEnvelope] 2 events, close")
TEST_CASE("[LinearEnvelope] 2 events, far")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(2, 1.0);
envelope.registerEvent(6, 2.0);
envelope.registerEvent(2, 1.0f);
envelope.registerEvent(6, 2.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.5, 1, 1.25, 1.5, 1.75, 2.0, 2.0, 2.0 };
std::array<float, 8> expected { 0.5f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f, 2.0f, 2.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -91,10 +91,10 @@ TEST_CASE("[LinearEnvelope] 2 events, far")
TEST_CASE("[LinearEnvelope] 2 events, reversed")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(6, 2.0);
envelope.registerEvent(2, 1.0);
envelope.registerEvent(6, 2.0f);
envelope.registerEvent(2, 1.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.5, 1, 1.25, 1.5, 1.75, 2.0, 2.0, 2.0 };
std::array<float, 8> expected { 0.5f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f, 2.0f, 2.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -102,11 +102,11 @@ TEST_CASE("[LinearEnvelope] 2 events, reversed")
TEST_CASE("[LinearEnvelope] 3 events, overlapping")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(2, 1.0);
envelope.registerEvent(6, 2.0);
envelope.registerEvent(6, 3.0);
envelope.registerEvent(2, 1.0f);
envelope.registerEvent(6, 2.0f);
envelope.registerEvent(6, 3.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.5, 1, 1.25, 1.5, 1.75, 2.0, 3.0, 3.0 };
std::array<float, 8> expected { 0.5f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f, 3.0f, 3.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -114,11 +114,11 @@ TEST_CASE("[LinearEnvelope] 3 events, overlapping")
TEST_CASE("[LinearEnvelope] 3 events, out of block")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(2, 1.0);
envelope.registerEvent(6, 2.0);
envelope.registerEvent(10, 3.0);
envelope.registerEvent(2, 1.0f);
envelope.registerEvent(6, 2.0f);
envelope.registerEvent(10, 3.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.5, 1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0 };
std::array<float, 8> expected { 0.5f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f, 2.5f, 3.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -126,11 +126,11 @@ TEST_CASE("[LinearEnvelope] 3 events, out of block")
TEST_CASE("[LinearEnvelope] 3 events, out of block, with another block call")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(2, 1.0);
envelope.registerEvent(6, 2.0);
envelope.registerEvent(10, 3.0);
envelope.registerEvent(2, 1.0f);
envelope.registerEvent(6, 2.0f);
envelope.registerEvent(10, 3.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 };
std::array<float, 8> expected { 3.0f, 3.0f, 3.0f, 3.0f, 3.0f, 3.0f, 3.0f, 3.0f };
envelope.getBlock(absl::MakeSpan(output));
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output == expected);
@ -139,10 +139,10 @@ TEST_CASE("[LinearEnvelope] 3 events, out of block, with another block call")
TEST_CASE("[LinearEnvelope] 2 events, with another block call")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(2, 1.0);
envelope.registerEvent(6, 2.0);
envelope.registerEvent(2, 1.0f);
envelope.registerEvent(6, 2.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 };
std::array<float, 8> expected { 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f };
envelope.getBlock(absl::MakeSpan(output));
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output == expected);
@ -152,10 +152,10 @@ TEST_CASE("[LinearEnvelope] 2 events, function")
{
sfz::LinearEnvelope<float> envelope;
envelope.setFunction([](auto x) { return 2 * x; });
envelope.registerEvent(2, 1.0);
envelope.registerEvent(6, 2.0);
envelope.registerEvent(2, 1.0f);
envelope.registerEvent(6, 2.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 1, 2, 2.5, 3, 3.5, 4.0, 4.0, 4.0 };
std::array<float, 8> expected { 1.0f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.0f, 4.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -163,10 +163,10 @@ TEST_CASE("[LinearEnvelope] 2 events, function")
TEST_CASE("[LinearEnvelope] Get quantized")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(2, 1.0);
envelope.registerEvent(6, 2.0);
envelope.registerEvent(2, 1.0f);
envelope.registerEvent(6, 2.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0 };
std::array<float, 8> expected { 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.0f);
REQUIRE(output == expected);
}
@ -174,10 +174,10 @@ TEST_CASE("[LinearEnvelope] Get quantized")
TEST_CASE("[LinearEnvelope] Get quantized with unquantized targets")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(2, 1.1);
envelope.registerEvent(6, 1.9);
envelope.registerEvent(2, 1.1f);
envelope.registerEvent(6, 1.9f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0 };
std::array<float, 8> expected { 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.0f);
REQUIRE(output == expected);
}
@ -185,10 +185,10 @@ TEST_CASE("[LinearEnvelope] Get quantized with unquantized targets")
TEST_CASE("[LinearEnvelope] Get quantized with 2 steps")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(2, 1.0);
envelope.registerEvent(6, 3.0);
envelope.registerEvent(2, 1.0f);
envelope.registerEvent(6, 3.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0 };
std::array<float, 8> expected { 0.0f, 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f, 3.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.0f);
REQUIRE(output == expected);
}
@ -196,12 +196,12 @@ TEST_CASE("[LinearEnvelope] Get quantized with 2 steps")
TEST_CASE("[LinearEnvelope] Get quantized with 2 steps and an unquantized out of block step")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(2, 1.0);
envelope.registerEvent(6, 3.0);
envelope.registerEvent(10, 4.2);
envelope.registerEvent(2, 1.0f);
envelope.registerEvent(6, 3.0f);
envelope.registerEvent(10, 4.2f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0 };
std::array<float, 8> expected2 { 4.0, 4.0, 4.0,4.0, 4.0, 4.0, 4.0, 4.0 };
std::array<float, 8> expected { 0.0f, 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f, 3.0f };
std::array<float, 8> expected2 { 4.0f, 4.0f, 4.0f,4.0f, 4.0f, 4.0f, 4.0f, 4.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.0f);
REQUIRE(output == expected);
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.0f);
@ -212,11 +212,11 @@ TEST_CASE("[LinearEnvelope] Get quantized with 2 steps and an unquantized out of
TEST_CASE("[LinearEnvelope] Going down quantized with 2 steps")
{
sfz::LinearEnvelope<float> envelope;
envelope.reset(3.0);
envelope.registerEvent(2, 2.0);
envelope.registerEvent(6, 0.0);
envelope.reset(3.0f);
envelope.registerEvent(2, 2.0f);
envelope.registerEvent(6, 0.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 3.0, 2.0, 2.0, 1.0, 1.0, 0.0, 0.0, 0.0 };
std::array<float, 8> expected { 3.0f, 2.0f, 2.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.0f);
REQUIRE(output == expected);
}
@ -224,11 +224,11 @@ TEST_CASE("[LinearEnvelope] Going down quantized with 2 steps")
TEST_CASE("[LinearEnvelope] Get quantized with 2 steps and starting unquantized")
{
sfz::LinearEnvelope<float> envelope;
envelope.reset(0.1);
envelope.registerEvent(3, 1.0);
envelope.registerEvent(7, 3.0);
envelope.reset(0.1f);
envelope.registerEvent(3, 1.0f);
envelope.registerEvent(7, 3.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.1, 0.1, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0 };
std::array<float, 8> expected { 0.1f, 0.1f, 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.0f);
REQUIRE(output == expected);
}
@ -237,11 +237,11 @@ TEST_CASE("[LinearEnvelope] Get quantized with 2 steps and starting unquantized"
TEST_CASE("[LinearEnvelope] Going down quantized with 2 steps and starting unquantized")
{
sfz::LinearEnvelope<float> envelope;
envelope.reset(3.6);
envelope.registerEvent(4, 1.0);
envelope.reset(3.6f);
envelope.registerEvent(4, 1.0f);
envelope.registerEvent(7, 0.0);
std::array<float, 8> output;
std::array<float, 8> expected { 3.6, 3.0, 2.0, 2.0, 1.0, 1.0, 0.0, 0.0 };
std::array<float, 8> expected { 3.6f, 3.0f, 2.0f, 2.0f, 1.0f, 1.0f, 0.0f, 0.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.0f);
REQUIRE(output == expected);
}
@ -249,10 +249,10 @@ TEST_CASE("[LinearEnvelope] Going down quantized with 2 steps and starting unqua
TEST_CASE("[LinearEnvelope] Get quantized with unclean events")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(2, 1.2);
envelope.registerEvent(6, 2.5);
envelope.registerEvent(2, 1.2f);
envelope.registerEvent(6, 2.5f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0 };
std::array<float, 8> expected { 0.0f, 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f, 3.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.0f);
REQUIRE(output == expected);
}
@ -260,12 +260,12 @@ TEST_CASE("[LinearEnvelope] Get quantized with unclean events")
TEST_CASE("[LinearEnvelope] Get quantized 3 events, one out of block")
{
sfz::LinearEnvelope<float> envelope;
envelope.registerEvent(2, 1.0);
envelope.registerEvent(6, 2.0);
envelope.registerEvent(10, 3.0);
envelope.registerEvent(2, 1.0f);
envelope.registerEvent(6, 2.0f);
envelope.registerEvent(10, 3.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0 };
std::array<float, 8> expected2 { 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 };
std::array<float, 8> expected { 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f };
std::array<float, 8> expected2 { 3.0f, 3.0f, 3.0f, 3.0f, 3.0f, 3.0f, 3.0f, 3.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.0f);
REQUIRE(output == expected);
envelope.getQuantizedBlock(absl::MakeSpan(output), 1.0f);
@ -277,7 +277,7 @@ TEST_CASE("[MultiplicativeEnvelope] Basic state")
{
sfz::MultiplicativeEnvelope<float> envelope;
std::array<float, 5> output;
std::array<float, 5> expected { 1.0, 1.0, 1.0, 1.0, 1.0 };
std::array<float, 5> expected { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -285,9 +285,9 @@ TEST_CASE("[MultiplicativeEnvelope] Basic state")
TEST_CASE("[MultiplicativeEnvelope] Basic event")
{
sfz::MultiplicativeEnvelope<float> envelope;
envelope.registerEvent(4, 2.0);
envelope.registerEvent(4, 2.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 1.1892, 1.4142, 1.68176, 2.0, 2.0, 2.0, 2.0, 2.0 };
std::array<float, 8> expected { 1.1892f, 1.4142f, 1.68176f, 2.0f, 2.0f, 2.0f, 2.0f, 2.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -295,10 +295,10 @@ TEST_CASE("[MultiplicativeEnvelope] Basic event")
TEST_CASE("[MultiplicativeEnvelope] 2 events")
{
sfz::MultiplicativeEnvelope<float> envelope;
envelope.registerEvent(4, 2.0);
envelope.registerEvent(5, 4.0);
envelope.registerEvent(4, 2.0f);
envelope.registerEvent(5, 4.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 1.1892, 1.4142, 1.68176, 2.0, 4.0, 4.0, 4.0, 4.0 };
std::array<float, 8> expected { 1.1892f, 1.4142f, 1.68176f, 2.0f, 4.0f, 4.0f, 4.0f, 4.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -306,10 +306,10 @@ TEST_CASE("[MultiplicativeEnvelope] 2 events")
TEST_CASE("[MultiplicativeEnvelope] 2 events, far")
{
sfz::MultiplicativeEnvelope<float> envelope;
envelope.registerEvent(2, 2.0);
envelope.registerEvent(6, 4.0);
envelope.registerEvent(2, 2.0f);
envelope.registerEvent(6, 4.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 1.4142, 2.0, 2.37841, 2.82843, 3.36358, 4.0, 4.0, 4.0 };
std::array<float, 8> expected { 1.4142f, 2.0f, 2.37841f, 2.82843f, 3.36358f, 4.0f, 4.0f, 4.0f };
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
}
@ -317,10 +317,10 @@ TEST_CASE("[MultiplicativeEnvelope] 2 events, far")
TEST_CASE("[MultiplicativeEnvelope] Get quantized with 2 steps")
{
sfz::MultiplicativeEnvelope<float> envelope;
envelope.registerEvent(2, 2.0);
envelope.registerEvent(6, 4.0);
envelope.registerEvent(2, 2.0f);
envelope.registerEvent(6, 4.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 1.0, 2.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0 };
std::array<float, 8> expected { 1.0f, 2.0f, 2.0f, 2.0f, 2.0f, 4.0f, 4.0f, 4.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 2.0f);
REQUIRE(output == expected);
}
@ -328,12 +328,12 @@ TEST_CASE("[MultiplicativeEnvelope] Get quantized with 2 steps")
TEST_CASE("[MultiplicativeEnvelope] Get quantized with an unquantized out of range step")
{
sfz::MultiplicativeEnvelope<float> envelope;
envelope.registerEvent(2, 2.0);
envelope.registerEvent(6, 4.0);
envelope.registerEvent(10, 8.2);
envelope.registerEvent(2, 2.0f);
envelope.registerEvent(6, 4.0f);
envelope.registerEvent(10, 8.2f);
std::array<float, 8> output;
std::array<float, 8> expected { 1.0, 2.0, 2.0, 2.0, 2.0, 4.0, 4.0, 4.0 };
std::array<float, 8> expected2 { 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0, 8.0 };
std::array<float, 8> expected { 1.0f, 2.0f, 2.0f, 2.0f, 2.0f, 4.0f, 4.0f, 4.0f };
std::array<float, 8> expected2 { 8.0f, 8.0f, 8.0f, 8.0f, 8.0f, 8.0f, 8.0f, 8.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 2.0f);
REQUIRE(output == expected);
envelope.getQuantizedBlock(absl::MakeSpan(output), 2.0f);
@ -343,11 +343,11 @@ TEST_CASE("[MultiplicativeEnvelope] Get quantized with an unquantized out of ran
TEST_CASE("[MultiplicativeEnvelope] Going down quantized with 2 steps")
{
sfz::MultiplicativeEnvelope<float> envelope;
envelope.reset(4.0);
envelope.registerEvent(2, 2.0);
envelope.registerEvent(6, 0.5);
envelope.reset(4.0f);
envelope.registerEvent(2, 2.0f);
envelope.registerEvent(6, 0.5f);
std::array<float, 8> output;
std::array<float, 8> expected { 4.0, 2.0, 2.0, 1.0, 1.0, 0.5, 0.5, 0.5 };
std::array<float, 8> expected { 4.0f, 2.0f, 2.0f, 1.0f, 1.0f, 0.5f, 0.5f, 0.5f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 2.0f);
REQUIRE(output == expected);
}
@ -355,10 +355,10 @@ TEST_CASE("[MultiplicativeEnvelope] Going down quantized with 2 steps")
TEST_CASE("[MultiplicativeEnvelope] Get quantized with unclean events")
{
sfz::MultiplicativeEnvelope<float> envelope;
envelope.registerEvent(2, 1.2);
envelope.registerEvent(6, 2.5);
envelope.registerEvent(2, 1.2f);
envelope.registerEvent(6, 2.5f);
std::array<float, 8> output;
std::array<float, 8> expected { 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0 };
std::array<float, 8> expected { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 2.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 2.0f);
REQUIRE(output == expected);
}
@ -366,11 +366,11 @@ TEST_CASE("[MultiplicativeEnvelope] Get quantized with unclean events")
TEST_CASE("[MultiplicativeEnvelope] Get quantized with 2 steps and starting unquantized")
{
sfz::MultiplicativeEnvelope<float> envelope;
envelope.reset(0.9);
envelope.registerEvent(3, 1.0);
envelope.registerEvent(7, 4.0);
envelope.reset(0.9f);
envelope.registerEvent(3, 1.0f);
envelope.registerEvent(7, 4.0f);
std::array<float, 8> output;
std::array<float, 8> expected { 0.9, 0.9, 1.0, 1.0, 2.0, 2.0, 4.0, 4.0 };
std::array<float, 8> expected { 0.9f, 0.9f, 1.0f, 1.0f, 2.0f, 2.0f, 4.0f, 4.0f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 2.0f);
REQUIRE(output == expected);
}
@ -379,11 +379,11 @@ TEST_CASE("[MultiplicativeEnvelope] Get quantized with 2 steps and starting unqu
TEST_CASE("[MultiplicativeEnvelope] Going down quantized with 2 steps and starting unquantized")
{
sfz::MultiplicativeEnvelope<float> envelope;
envelope.reset(4.6);
envelope.registerEvent(4, 1.0);
envelope.registerEvent(7, 0.25);
envelope.reset(4.6f);
envelope.registerEvent(4, 1.0f);
envelope.registerEvent(7, 0.25f);
std::array<float, 8> output;
std::array<float, 8> expected { 4.6, 2.0, 1.0, 1.0, 0.5, 0.5, 0.25, 0.25 };
std::array<float, 8> expected { 4.6f, 2.0f, 1.0f, 1.0f, 0.5f, 0.5f, 0.25f, 0.25f };
envelope.getQuantizedBlock(absl::MakeSpan(output), 2.0f);
REQUIRE(output == expected);
}
@ -394,13 +394,13 @@ TEST_CASE("[MultiplicativeEnvelope] Pitch envelope basic function")
sfz::MultiplicativeEnvelope<float> envelope;
envelope.setFunction([](float pitchValue){
const auto normalizedBend = sfz::normalizeBend(pitchValue);
const auto bendInCents = normalizedBend * 200;
const auto bendInCents = normalizedBend * 200.0f;
return sfz::centsFactor(bendInCents);
});
envelope.reset(0);
envelope.reset(0.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output[255] == 1.0_a);
envelope.registerEvent(252, -6020);
envelope.registerEvent(252, -6020.0f);
envelope.getBlock(absl::MakeSpan(output));
REQUIRE(output[255] == Approx(0.9168).epsilon(0.01));
}

View file

@ -61,6 +61,15 @@ TEST_CASE("[Files] Underscore opcodes (underscore_opcodes.sfz)")
REQUIRE(synth.getRegionView(0)->loopMode == SfzLoopMode::loop_sustain);
}
TEST_CASE("[Files] (regions_bad.sfz)")
{
sfz::Synth synth;
synth.loadSfzFile(fs::current_path() / "tests/TestFiles/Regions/regions_bad.sfz");
REQUIRE(synth.getNumRegions() == 2);
REQUIRE(synth.getRegionView(0)->sample == "dummy.wav");
REQUIRE(synth.getRegionView(1)->sample == "dummy.wav");
}
TEST_CASE("[Files] Local include")
{
sfz::Synth synth;

View file

@ -73,7 +73,7 @@ void testLowpass(const fs::path& inputNumpyFile, const fs::path& outputNumpyFile
REQUIRE(approxEqual(outputData, expectedData));
filter.reset();
std::fill(outputData.begin(), outputData.end(), 0.0);
std::fill(outputData.begin(), outputData.end(), 0.0f);
std::vector<Type> gains(size);
std::fill(gains.begin(), gains.end(), gain);
filter.processLowpassVariableGain(inputData, absl::MakeSpan(outputData), gains);
@ -108,7 +108,7 @@ void testHighpass(const fs::path& inputNumpyFile, const fs::path& outputNumpyFil
REQUIRE(approxEqual(outputData, expectedData));
filter.reset();
std::fill(outputData.begin(), outputData.end(), 0.0);
std::fill(outputData.begin(), outputData.end(), 0.0f);
std::vector<Type> gains(size);
std::fill(gains.begin(), gains.end(), gain);
filter.processHighpassVariableGain(inputData, absl::MakeSpan(outputData), gains);

View file

@ -33,7 +33,7 @@ using namespace Catch::literals;
constexpr int smallBufferSize { 3 };
constexpr int bigBufferSize { 4095 };
constexpr int medBufferSize { 127 };
constexpr double fillValue { 1.3 };
constexpr float fillValue { 1.3f };
template <class Type>
inline bool approxEqualMargin(absl::Span<const Type> lhs, absl::Span<const Type> rhs, Type eps = 1e-3)
@ -334,7 +334,7 @@ TEST_CASE("[Helpers] Interleaved write SIMD vs Scalar")
std::array<float, medBufferSize * 2> outputScalar;
std::array<float, medBufferSize * 2> outputSIMD;
std::iota(leftInput.begin(), leftInput.end(), 0.0f);
std::iota(rightInput.begin(), rightInput.end(), medBufferSize);
std::iota(rightInput.begin(), rightInput.end(), static_cast<float>(medBufferSize));
sfz::writeInterleaved<float, false>(leftInput, rightInput, absl::MakeSpan(outputScalar));
sfz::writeInterleaved<float, true>(leftInput, rightInput, absl::MakeSpan(outputSIMD));
REQUIRE(outputScalar == outputSIMD);
@ -414,7 +414,7 @@ TEST_CASE("[Helpers] Gain, spans and inplace (SIMD)")
TEST_CASE("[Helpers] SFZ looping index")
{
std::array<float, 6> jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0 6.5 8.1
std::array<float, 6> jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0f 6.5 8.1
std::array<int, 6> indices;
std::array<float, 6> leftCoeffs;
std::array<float, 6> rightCoeffs;
@ -429,7 +429,7 @@ TEST_CASE("[Helpers] SFZ looping index")
TEST_CASE("[Helpers] SFZ looping index (SIMD)")
{
std::array<float, 6> jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0 6.5 8.1
std::array<float, 6> jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0f 6.5 8.1
std::array<int, 6> indices;
std::array<float, 6> leftCoeffs;
std::array<float, 6> rightCoeffs;
@ -458,13 +458,13 @@ TEST_CASE("[Helpers] SFZ looping index (SIMD)")
// sfz::loopingSFZIndex<float, false>(jumps, absl::MakeSpan(leftCoeffs), absl::MakeSpan(rightCoeffs), absl::MakeSpan(indices), 1.0f, medBufferSize, 1);
// sfz::loopingSFZIndex<float, true>(jumps, absl::MakeSpan(leftCoeffsSIMD), absl::MakeSpan(rightCoeffsSIMD), absl::MakeSpan(indicesSIMD), 1.0f, medBufferSize, 1);
// for (int i = 0; i < bigBufferSize; ++i)
// REQUIRE( ((static_cast<float>(indices[i]) + rightCoeffs[i] == Approx(static_cast<float>(indicesSIMD[i]) + rightCoeffsSIMD[i]).margin(1e-2))
// REQUIRE( ((static_cast<float>(indices[i]) + rightCoeffs[i] == Approx(static_cast<float>(indicesSIMD[i]) + rightCoeffsSIMD[i]).margin(1e-2))
// || (static_cast<float>(indices[i]) + rightCoeffs[i] == Approx(static_cast<float>(indicesSIMD[i]) + rightCoeffsSIMD[i] - static_cast<float>(medBufferSize)).margin(2e-2))) );
// }
TEST_CASE("[Helpers] SFZ saturating index")
{
std::array<float, 6> jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0 6.5 8.1
std::array<float, 6> jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0f 6.5 8.1
std::array<int, 6> indices;
std::array<float, 6> leftCoeffs;
std::array<float, 6> rightCoeffs;
@ -479,7 +479,7 @@ TEST_CASE("[Helpers] SFZ saturating index")
TEST_CASE("[Helpers] SFZ saturating index (SIMD)")
{
std::array<float, 6> jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0 6.5 8.1
std::array<float, 6> jumps { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0f 6.5 8.1
std::array<int, 6> indices;
std::array<float, 6> leftCoeffs;
std::array<float, 6> rightCoeffs;
@ -558,7 +558,7 @@ TEST_CASE("[Helpers] Multiplicative Ramp")
std::array<float, 6> output;
std::array<float, 6> expected { v, v * v, v * v * v, v * v * v * v, v * v * v * v * v, v * v * v * v * v * v };
sfz::multiplicativeRamp<float, false>(absl::MakeSpan(output), start, v);
REQUIRE(output == expected);
REQUIRE(approxEqual<float>(output, expected));
}
TEST_CASE("[Helpers] Multiplicative Ramp (SIMD)")
@ -568,7 +568,7 @@ TEST_CASE("[Helpers] Multiplicative Ramp (SIMD)")
std::array<float, 6> output;
std::array<float, 6> expected { v, v * v, v * v * v, v * v * v * v, v * v * v * v * v, v * v * v * v * v * v };
sfz::multiplicativeRamp<float, true>(absl::MakeSpan(output), start, v);
REQUIRE(output == expected);
REQUIRE(approxEqual<float>(output, expected));
}
TEST_CASE("[Helpers] Multiplicative Ramp (SIMD vs scalar)")
@ -595,7 +595,7 @@ TEST_CASE("[Helpers] Add")
{
std::array<float, 5> input { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
std::array<float, 5> output { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
std::array<float, 5> expected { 2.0, 3.0, 4.0, 5.0, 6.0 };
std::array<float, 5> expected { 2.0f, 3.0f, 4.0f, 5.0f, 6.0f };
sfz::add<float, false>(input, absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -604,7 +604,7 @@ TEST_CASE("[Helpers] Add (SIMD)")
{
std::array<float, 5> input { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
std::array<float, 5> output { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
std::array<float, 5> expected { 2.0, 3.0, 4.0, 5.0, 6.0 };
std::array<float, 5> expected { 2.0f, 3.0f, 4.0f, 5.0f, 6.0f };
sfz::add<float, true>(input, absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -614,9 +614,9 @@ TEST_CASE("[Helpers] Add (SIMD vs scalar)")
std::vector<float> input(bigBufferSize);
std::vector<float> outputScalar(bigBufferSize);
std::vector<float> outputSIMD(bigBufferSize);
absl::c_iota(input, 0.0);
absl::c_fill(outputScalar, 0.0);
absl::c_fill(outputSIMD, 0.0);
absl::c_iota(input, 0.0f);
absl::c_fill(outputScalar, 0.0f);
absl::c_fill(outputSIMD, 0.0f);
sfz::add<float, false>(input, absl::MakeSpan(outputScalar));
sfz::add<float, true>(input, absl::MakeSpan(outputSIMD));
@ -627,7 +627,7 @@ TEST_CASE("[Helpers] Subtract")
{
std::array<float, 5> input { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
std::array<float, 5> output { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
std::array<float, 5> expected { 0.0, -1.0, -2.0, -3.0, -4.0 };
std::array<float, 5> expected { 0.0f, -1.0f, -2.0f, -3.0f, -4.0f };
sfz::subtract<float, false>(input, absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -635,7 +635,7 @@ TEST_CASE("[Helpers] Subtract")
TEST_CASE("[Helpers] Subtract 2")
{
std::array<float, 5> output { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
std::array<float, 5> expected { 0.0, 1.0, 2.0, 3.0, 4.0 };
std::array<float, 5> expected { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f };
sfz::subtract<float, false>(1.0f, absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -645,7 +645,7 @@ TEST_CASE("[Helpers] Subtract (SIMD)")
{
std::array<float, 5> input { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
std::array<float, 5> output { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
std::array<float, 5> expected { 0.0, -1.0, -2.0, -3.0, -4.0 };
std::array<float, 5> expected { 0.0f, -1.0f, -2.0f, -3.0f, -4.0f };
sfz::subtract<float, true>(input, absl::MakeSpan(output));
REQUIRE(output == expected);
}
@ -655,9 +655,9 @@ TEST_CASE("[Helpers] Subtract (SIMD vs scalar)")
std::vector<float> input(bigBufferSize);
std::vector<float> outputScalar(bigBufferSize);
std::vector<float> outputSIMD(bigBufferSize);
absl::c_iota(input, 0.0);
absl::c_fill(outputScalar, 0.0);
absl::c_fill(outputSIMD, 0.0);
absl::c_iota(input, 0.0f);
absl::c_fill(outputScalar, 0.0f);
absl::c_fill(outputSIMD, 0.0f);
sfz::subtract<float, false>(input, absl::MakeSpan(outputScalar));
sfz::subtract<float, true>(input, absl::MakeSpan(outputSIMD));
@ -668,8 +668,8 @@ TEST_CASE("[Helpers] Subtract 2 (SIMD vs scalar)")
{
std::vector<float> outputScalar(bigBufferSize);
std::vector<float> outputSIMD(bigBufferSize);
absl::c_iota(outputScalar, 0.0);
absl::c_iota(outputSIMD, 0.0);
absl::c_iota(outputScalar, 0.0f);
absl::c_iota(outputSIMD, 0.0f);
sfz::subtract<float, false>(1.2f, absl::MakeSpan(outputScalar));
sfz::subtract<float, true>(1.2f, absl::MakeSpan(outputSIMD));
@ -697,9 +697,9 @@ TEST_CASE("[Helpers] copy (SIMD vs scalar)")
std::vector<float> input(bigBufferSize);
std::vector<float> outputScalar(bigBufferSize);
std::vector<float> outputSIMD(bigBufferSize);
absl::c_iota(input, 0.0);
absl::c_fill(outputScalar, 0.0);
absl::c_fill(outputSIMD, 0.0);
absl::c_iota(input, 0.0f);
absl::c_fill(outputScalar, 0.0f);
absl::c_fill(outputSIMD, 0.0f);
sfz::add<float, false>(input, absl::MakeSpan(outputScalar));
sfz::add<float, true>(input, absl::MakeSpan(outputSIMD));
@ -716,7 +716,7 @@ TEST_CASE("[Helpers] Mean")
TEST_CASE("[Helpers] Mean (SIMD vs scalar)")
{
std::vector<float> input(bigBufferSize);
absl::c_iota(input, 0.0);
absl::c_iota(input, 0.0f);
REQUIRE(sfz::mean<float, false>(input) == Approx(sfz::mean<float, true>(input)).margin(0.001));
}
@ -730,14 +730,14 @@ TEST_CASE("[Helpers] Mean Squared")
TEST_CASE("[Helpers] Mean Squared (SIMD vs scalar)")
{
std::vector<float> input(medBufferSize);
absl::c_iota(input, 0.0);
absl::c_iota(input, 0.0f);
REQUIRE(sfz::meanSquared<float, false>(input) == sfz::meanSquared<float, true>(input));
}
TEST_CASE("[Helpers] Cumulative sum ")
{
std::array<float, 6> input { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0 6.5 8.1
std::array<float, 6> output;
std::array<float, 6> input { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f }; // 1.1 2.3 3.6 5.0f 6.5 8.1
std::array<float, 6> output;
std::array<float, 6> expected { 1.1f, 2.3f, 3.6f, 5.0f, 6.5f, 8.1f };
sfz::cumsum<float, false>(input, absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
@ -748,7 +748,7 @@ TEST_CASE("[Helpers] Cumulative sum (SIMD vs Scalar)")
std::vector<float> input(bigBufferSize);
std::vector<float> outputScalar(bigBufferSize);
std::vector<float> outputSIMD(bigBufferSize);
sfz::linearRamp<float>(absl::MakeSpan(input), 0.0, 0.1);
sfz::linearRamp<float>(absl::MakeSpan(input), 0.0f, 0.1f);
sfz::cumsum<float, false>(input, absl::MakeSpan(outputScalar));
sfz::cumsum<float, true>(input, absl::MakeSpan(outputSIMD));
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
@ -757,7 +757,7 @@ TEST_CASE("[Helpers] Cumulative sum (SIMD vs Scalar)")
TEST_CASE("[Helpers] Diff ")
{
std::array<float, 6> input { 1.1f, 2.3f, 3.6f, 5.0f, 6.5f, 8.1f };
std::array<float, 6> output;
std::array<float, 6> output;
std::array<float, 6> expected { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f };
sfz::diff<float, false>(input, absl::MakeSpan(output));
REQUIRE(approxEqual<float>(output, expected));
@ -768,8 +768,8 @@ TEST_CASE("[Helpers] Diff (SIMD vs Scalar)")
std::vector<float> input(bigBufferSize);
std::vector<float> outputScalar(bigBufferSize);
std::vector<float> outputSIMD(bigBufferSize);
sfz::linearRamp<float>(absl::MakeSpan(input), 0.0, 0.1);
sfz::linearRamp<float>(absl::MakeSpan(input), 0.0f, 0.1f);
sfz::diff<float, false>(input, absl::MakeSpan(outputScalar));
sfz::diff<float, true>(input, absl::MakeSpan(outputSIMD));
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
}
}

View file

@ -0,0 +1,4 @@
<region> sample=dummy.wav
<region> sample=nonexistent.wav
<region> sample=nonexistent.wav
<region> sample=dummy.wav