2020-01-25 10:04:31 +01:00
|
|
|
// SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
2020-01-25 13:13:07 +01:00
|
|
|
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
|
|
|
|
// license. You should have receive a LICENSE.md file along with the code.
|
|
|
|
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
2019-08-30 00:49:58 +02:00
|
|
|
|
2020-04-06 19:26:39 +02:00
|
|
|
#include "sfizz/ModifierHelpers.h"
|
2020-01-18 17:35:27 +01:00
|
|
|
#include "sfizz/Buffer.h"
|
2019-08-25 14:01:03 +02:00
|
|
|
#include "catch2/catch.hpp"
|
|
|
|
|
#include <absl/algorithm/container.h>
|
|
|
|
|
#include <absl/types/span.h>
|
2019-08-22 23:39:26 +02:00
|
|
|
#include <algorithm>
|
2019-08-25 14:01:03 +02:00
|
|
|
#include <array>
|
2019-08-22 23:39:26 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
using namespace Catch::literals;
|
|
|
|
|
|
2019-08-25 14:01:03 +02:00
|
|
|
template <class Type>
|
|
|
|
|
inline bool approxEqual(absl::Span<const Type> lhs, absl::Span<const Type> rhs, Type eps = 1e-3)
|
2019-08-22 23:39:26 +02:00
|
|
|
{
|
|
|
|
|
if (lhs.size() != rhs.size())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < rhs.size(); ++i)
|
2019-08-25 14:01:03 +02:00
|
|
|
if (rhs[i] != Approx(lhs[i]).epsilon(eps)) {
|
2019-08-22 23:39:26 +02:00
|
|
|
std::cerr << lhs[i] << " != " << rhs[i] << " at index " << i << '\n';
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 10:46:12 +02:00
|
|
|
const auto idModifier = [](float x) { return x; };
|
|
|
|
|
const auto twiceModifier = [](float x) { return 2 * x; };
|
|
|
|
|
const auto expModifier = [](float x) { return std::exp(x); };
|
2020-03-31 00:18:24 +02:00
|
|
|
|
|
|
|
|
TEST_CASE("[Envelopes] Empty")
|
2019-08-22 23:39:26 +02:00
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 0.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-08-22 23:39:26 +02:00
|
|
|
std::array<float, 5> output;
|
2020-01-05 00:19:08 +01:00
|
|
|
std::array<float, 5> expected { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
|
2020-03-31 00:18:24 +02:00
|
|
|
std::array<float, 5> expectedMul { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
|
|
|
|
|
linearEnvelope(events, absl::MakeSpan(output), idModifier);
|
|
|
|
|
REQUIRE(output == expected);
|
|
|
|
|
linearEnvelope(events, absl::MakeSpan(output), idModifier, 1.0f);
|
2019-08-25 14:01:03 +02:00
|
|
|
REQUIRE(output == expected);
|
2020-03-31 00:18:24 +02:00
|
|
|
multiplicativeEnvelope(events, absl::MakeSpan(output), expModifier);
|
|
|
|
|
REQUIRE(output == expectedMul);
|
|
|
|
|
multiplicativeEnvelope(events, absl::MakeSpan(output), expModifier, 2.0f);
|
|
|
|
|
REQUIRE(output == expectedMul);
|
2019-08-22 23:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-31 00:18:24 +02:00
|
|
|
TEST_CASE("[Envelopes] Linear basic")
|
2019-08-22 23:39:26 +02:00
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 0.0f },
|
|
|
|
|
{ 4, 1.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
|
|
|
|
std::array<float, 9> output;
|
|
|
|
|
std::array<float, 9> expected { 0.0f, 0.25f, 0.5f, 0.75f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
|
|
|
|
|
linearEnvelope(events, absl::MakeSpan(output), idModifier);
|
2019-08-25 14:01:03 +02:00
|
|
|
REQUIRE(output == expected);
|
2019-08-22 23:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[LinearEnvelope] 2 events, close")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 0.0f },
|
|
|
|
|
{ 4, 1.0f },
|
|
|
|
|
{ 5, 2.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
|
|
|
|
std::array<float, 9> output;
|
|
|
|
|
std::array<float, 9> expected { 0.0f, 0.25f, 0.5f, 0.75f, 1.0f, 2.0f, 2.0f, 2.0f, 2.0f };
|
|
|
|
|
linearEnvelope(events, absl::MakeSpan(output), idModifier);
|
2019-08-25 14:01:03 +02:00
|
|
|
REQUIRE(output == expected);
|
2019-08-22 23:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-31 00:18:24 +02:00
|
|
|
TEST_CASE("[LinearEnvelope] 2 events, far")
|
2019-08-22 23:39:26 +02:00
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 0.0f },
|
|
|
|
|
{ 2, 1.0f },
|
|
|
|
|
{ 6, 2.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
|
|
|
|
std::array<float, 9> output;
|
|
|
|
|
std::array<float, 9> expected { 0.0f, 0.5f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f, 2.0f, 2.0f };
|
|
|
|
|
linearEnvelope(events, absl::MakeSpan(output), idModifier);
|
2019-08-25 14:01:03 +02:00
|
|
|
REQUIRE(output == expected);
|
2019-08-22 23:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[LinearEnvelope] 3 events, out of block")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 0.0f },
|
|
|
|
|
{ 2, 1.0f },
|
|
|
|
|
{ 6, 2.0f },
|
|
|
|
|
{ 10, 3.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
|
|
|
|
std::array<float, 9> output;
|
|
|
|
|
std::array<float, 9> expected { 0.0f, 0.5f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f, 2.5f, 3.0f };
|
|
|
|
|
linearEnvelope(events, absl::MakeSpan(output), idModifier);
|
2019-08-25 14:01:03 +02:00
|
|
|
REQUIRE(output == expected);
|
2019-08-22 23:39:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[LinearEnvelope] 2 events, function")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 0.0f },
|
|
|
|
|
{ 2, 1.0f },
|
|
|
|
|
{ 6, 2.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
|
|
|
|
std::array<float, 9> output;
|
|
|
|
|
std::array<float, 9> expected { 0.0f, 1.0f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.0f, 4.0f };
|
|
|
|
|
linearEnvelope(events, absl::MakeSpan(output), twiceModifier);
|
2019-08-25 14:01:03 +02:00
|
|
|
REQUIRE(output == expected);
|
2019-12-12 18:27:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[LinearEnvelope] Get quantized")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 0.0f },
|
|
|
|
|
{ 2, 1.0f },
|
|
|
|
|
{ 6, 2.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-12 18:27:18 +01:00
|
|
|
std::array<float, 8> output;
|
2020-03-31 00:18:24 +02:00
|
|
|
std::array<float, 8> expected { 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, 2.0f };
|
|
|
|
|
linearEnvelope(events, absl::MakeSpan(output), idModifier, 1.0f);
|
2019-12-12 18:27:18 +01:00
|
|
|
REQUIRE(output == expected);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-13 01:55:24 +01:00
|
|
|
TEST_CASE("[LinearEnvelope] Get quantized with unquantized targets")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 0.0f },
|
|
|
|
|
{ 2, 1.1f },
|
|
|
|
|
{ 6, 1.9f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-13 01:55:24 +01:00
|
|
|
std::array<float, 8> output;
|
2020-04-07 00:21:47 +02:00
|
|
|
std::array<float, 8> expected { 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
|
2020-03-31 00:18:24 +02:00
|
|
|
linearEnvelope(events, absl::MakeSpan(output), idModifier, 1.0f);
|
2019-12-13 01:55:24 +01:00
|
|
|
REQUIRE(output == expected);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-12 18:27:18 +01:00
|
|
|
TEST_CASE("[LinearEnvelope] Get quantized with 2 steps")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 0.0f },
|
|
|
|
|
{ 2, 1.0f },
|
|
|
|
|
{ 6, 3.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-12 18:27:18 +01:00
|
|
|
std::array<float, 8> output;
|
2020-03-31 00:18:24 +02:00
|
|
|
std::array<float, 8> expected { 0.0f, 0.0f, 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 3.0f };
|
|
|
|
|
linearEnvelope(events, absl::MakeSpan(output), idModifier, 1.0f);
|
2019-12-12 18:27:18 +01:00
|
|
|
REQUIRE(output == expected);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-13 14:21:27 +01:00
|
|
|
TEST_CASE("[LinearEnvelope] Get quantized with 2 steps and an unquantized out of block step")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 0.0f },
|
|
|
|
|
{ 2, 1.0f },
|
|
|
|
|
{ 6, 3.0f },
|
|
|
|
|
{ 10, 4.2f },
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-13 14:21:27 +01:00
|
|
|
std::array<float, 8> output;
|
2020-03-31 00:18:24 +02:00
|
|
|
std::array<float, 8> expected { 0.0f, 0.0f, 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 4.0f };
|
|
|
|
|
linearEnvelope(events, absl::MakeSpan(output), idModifier, 1.0f);
|
2019-12-13 14:21:27 +01:00
|
|
|
REQUIRE(output == expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-12-13 01:55:24 +01:00
|
|
|
TEST_CASE("[LinearEnvelope] Going down quantized with 2 steps")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 3.0f },
|
|
|
|
|
{ 2, 2.0f },
|
|
|
|
|
{ 6, 0.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-12 18:27:18 +01:00
|
|
|
std::array<float, 8> output;
|
2020-03-31 00:18:24 +02:00
|
|
|
std::array<float, 8> expected { 3.0f, 3.0f, 2.0f, 2.0f, 1.0f, 1.0f, 0.0f, 0.0f };
|
|
|
|
|
linearEnvelope(events, absl::MakeSpan(output), idModifier, 1.0f);
|
2019-12-13 01:55:24 +01:00
|
|
|
REQUIRE(output == expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[MultiplicativeEnvelope] Basic event")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 1.0f },
|
|
|
|
|
{ 4, 2.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-13 01:55:24 +01:00
|
|
|
std::array<float, 8> output;
|
2020-03-31 00:18:24 +02:00
|
|
|
std::array<float, 8> expected { 1.0f, 1.1892f, 1.4142f, 1.68176f, 2.0f, 2.0f, 2.0f, 2.0f };
|
|
|
|
|
multiplicativeEnvelope(events, absl::MakeSpan(output), idModifier);
|
2019-12-13 01:55:24 +01:00
|
|
|
REQUIRE(approxEqual<float>(output, expected));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[MultiplicativeEnvelope] 2 events")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 1.0f },
|
|
|
|
|
{ 4, 2.0f },
|
|
|
|
|
{ 5, 4.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-13 01:55:24 +01:00
|
|
|
std::array<float, 8> output;
|
2020-03-31 10:46:12 +02:00
|
|
|
std::array<float, 8> expected { 1.0f, 1.1892f, 1.4142f, 1.68176f, 2.0f, 4.0f, 4.0f, 4.0f };
|
2020-03-31 00:18:24 +02:00
|
|
|
multiplicativeEnvelope(events, absl::MakeSpan(output), idModifier);
|
2019-12-13 01:55:24 +01:00
|
|
|
REQUIRE(approxEqual<float>(output, expected));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[MultiplicativeEnvelope] 2 events, far")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 1.0f },
|
|
|
|
|
{ 2, 2.0f },
|
|
|
|
|
{ 6, 4.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-13 01:55:24 +01:00
|
|
|
std::array<float, 8> output;
|
2020-03-31 10:46:12 +02:00
|
|
|
std::array<float, 8> expected { 1.0f, 1.4142f, 2.0f, 2.37841f, 2.82843f, 3.36358f, 4.0f, 4.0f };
|
2020-03-31 00:18:24 +02:00
|
|
|
multiplicativeEnvelope(events, absl::MakeSpan(output), idModifier);
|
2019-12-13 01:55:24 +01:00
|
|
|
REQUIRE(approxEqual<float>(output, expected));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[MultiplicativeEnvelope] Get quantized with 2 steps")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 1.0f },
|
|
|
|
|
{ 2, 2.0f },
|
|
|
|
|
{ 6, 4.0f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-13 01:55:24 +01:00
|
|
|
std::array<float, 8> output;
|
2020-03-31 10:46:12 +02:00
|
|
|
std::array<float, 8> expected { 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 2.0f, 4.0f, 4.0f };
|
2020-03-31 00:18:24 +02:00
|
|
|
multiplicativeEnvelope(events, absl::MakeSpan(output), idModifier, 2.0f);
|
2019-12-13 01:55:24 +01:00
|
|
|
REQUIRE(output == expected);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-13 14:21:27 +01:00
|
|
|
TEST_CASE("[MultiplicativeEnvelope] Get quantized with an unquantized out of range step")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 1.0f },
|
|
|
|
|
{ 2, 2.0f },
|
|
|
|
|
{ 6, 4.0f },
|
|
|
|
|
{ 10, 8.2f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-13 14:21:27 +01:00
|
|
|
std::array<float, 8> output;
|
2020-03-31 00:18:24 +02:00
|
|
|
std::array<float, 8> expected { 1.0f, 1.0f, 2.0f, 2.0f, 2.0f, 2.0f, 4.0f, 8.0f };
|
|
|
|
|
multiplicativeEnvelope(events, absl::MakeSpan(output), idModifier, 2.0f);
|
2019-12-13 14:21:27 +01:00
|
|
|
REQUIRE(output == expected);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-13 01:55:24 +01:00
|
|
|
TEST_CASE("[MultiplicativeEnvelope] Going down quantized with 2 steps")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 4.0f },
|
|
|
|
|
{ 2, 2.0f },
|
|
|
|
|
{ 6, 0.5f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-13 01:55:24 +01:00
|
|
|
std::array<float, 8> output;
|
2020-03-31 00:18:24 +02:00
|
|
|
std::array<float, 8> expected { 4.0f, 4.0f, 2.0f, 2.0f, 1.0f, 1.0f, 0.5f, 0.5f };
|
|
|
|
|
multiplicativeEnvelope(events, absl::MakeSpan(output), idModifier, 2.0f);
|
2019-12-13 01:55:24 +01:00
|
|
|
REQUIRE(output == expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[MultiplicativeEnvelope] Get quantized with unclean events")
|
|
|
|
|
{
|
2020-03-31 00:18:24 +02:00
|
|
|
sfz::EventVector events {
|
2020-03-31 10:46:12 +02:00
|
|
|
{ 0, 1.0f },
|
|
|
|
|
{ 2, 1.2f },
|
|
|
|
|
{ 6, 2.5f }
|
2020-03-31 00:18:24 +02:00
|
|
|
};
|
2019-12-13 01:55:24 +01:00
|
|
|
std::array<float, 8> output;
|
2020-03-31 00:18:24 +02:00
|
|
|
std::array<float, 8> expected { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, 2.0f };
|
|
|
|
|
multiplicativeEnvelope(events, absl::MakeSpan(output), idModifier, 2.0f);
|
2019-12-13 01:55:24 +01:00
|
|
|
REQUIRE(output == expected);
|
|
|
|
|
}
|
2020-04-06 20:12:59 +02:00
|
|
|
|
|
|
|
|
TEST_CASE("[linearModifiers] Compare with envelopes")
|
|
|
|
|
{
|
|
|
|
|
sfz::Resources resources;
|
|
|
|
|
resources.curves = sfz::CurveSet::createPredefined();
|
|
|
|
|
|
|
|
|
|
sfz::CCData<sfz::Modifier> ccData;
|
|
|
|
|
ccData.cc = 20;
|
|
|
|
|
ccData.data.value = 100.0f;
|
|
|
|
|
|
|
|
|
|
resources.midiState.ccEvent(5, 20, 0.1);
|
|
|
|
|
resources.midiState.ccEvent(10, 20, 0.2);
|
|
|
|
|
|
|
|
|
|
std::array<float, 16> output;
|
|
|
|
|
std::array<float, 16> envelope;
|
|
|
|
|
|
|
|
|
|
linearEnvelope(resources.midiState.getCCEvents(20), absl::MakeSpan(envelope), [&ccData](float x) {
|
|
|
|
|
return ccData.data.value * x;
|
|
|
|
|
});
|
|
|
|
|
linearModifier(resources, absl::MakeSpan(output), ccData);
|
|
|
|
|
REQUIRE(approxEqual<float>(output, envelope));
|
|
|
|
|
|
|
|
|
|
ccData.data.curve = 1;
|
|
|
|
|
linearEnvelope(resources.midiState.getCCEvents(20), absl::MakeSpan(envelope), [&ccData](float x) {
|
|
|
|
|
return ccData.data.value * (2 * x - 1);
|
|
|
|
|
});
|
|
|
|
|
linearModifier(resources, absl::MakeSpan(output), ccData);
|
|
|
|
|
REQUIRE(approxEqual<float>(output, envelope));
|
|
|
|
|
|
|
|
|
|
ccData.data.curve = 3;
|
|
|
|
|
ccData.data.value = 10.0f;
|
|
|
|
|
linearEnvelope(resources.midiState.getCCEvents(20), absl::MakeSpan(envelope), [&ccData](float x) {
|
|
|
|
|
return ccData.data.value * (1 - 2 * x);
|
|
|
|
|
});
|
|
|
|
|
linearModifier(resources, absl::MakeSpan(output), ccData);
|
|
|
|
|
REQUIRE(approxEqual<float>(output, envelope));
|
|
|
|
|
|
|
|
|
|
ccData.data.curve = 2;
|
|
|
|
|
ccData.data.value = 20.0f;
|
2020-04-14 13:41:24 +02:00
|
|
|
ccData.data.step = 2.0f;
|
2020-04-06 20:12:59 +02:00
|
|
|
linearEnvelope(resources.midiState.getCCEvents(20), absl::MakeSpan(envelope), [&ccData](float x) {
|
|
|
|
|
return ccData.data.value * (1 - x);
|
2020-04-14 13:41:24 +02:00
|
|
|
}, ccData.data.step);
|
2020-04-06 20:12:59 +02:00
|
|
|
linearModifier(resources, absl::MakeSpan(output), ccData);
|
|
|
|
|
REQUIRE(approxEqual<float>(output, envelope));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_CASE("[multiplicativeModifiers] Compare with envelopes")
|
|
|
|
|
{
|
|
|
|
|
sfz::Resources resources;
|
|
|
|
|
resources.curves = sfz::CurveSet::createPredefined();
|
|
|
|
|
|
|
|
|
|
sfz::CCData<sfz::Modifier> ccData;
|
|
|
|
|
ccData.cc = 20;
|
|
|
|
|
ccData.data.value = 100.0f;
|
|
|
|
|
|
|
|
|
|
resources.midiState.ccEvent(5, 20, 0.1);
|
2020-04-07 00:50:30 +02:00
|
|
|
resources.midiState.ccEvent(10, 20, 0.8);
|
2020-04-06 20:12:59 +02:00
|
|
|
|
|
|
|
|
std::array<float, 16> output;
|
|
|
|
|
std::array<float, 16> envelope;
|
|
|
|
|
|
|
|
|
|
multiplicativeEnvelope(resources.midiState.getCCEvents(20), absl::MakeSpan(envelope), [&ccData](float x) {
|
|
|
|
|
return db2mag(ccData.data.value * x);
|
|
|
|
|
});
|
|
|
|
|
multiplicativeModifier(resources, absl::MakeSpan(output), ccData, [](float x) {
|
|
|
|
|
return db2mag(x);
|
|
|
|
|
});
|
|
|
|
|
REQUIRE(approxEqual<float>(output, envelope));
|
|
|
|
|
|
|
|
|
|
ccData.data.curve = 1;
|
|
|
|
|
multiplicativeEnvelope(resources.midiState.getCCEvents(20), absl::MakeSpan(envelope), [&ccData](float x) {
|
|
|
|
|
return db2mag(ccData.data.value * (2 * x - 1));
|
|
|
|
|
});
|
|
|
|
|
multiplicativeModifier(resources, absl::MakeSpan(output), ccData, [](float x) {
|
|
|
|
|
return db2mag(x);
|
|
|
|
|
});
|
|
|
|
|
REQUIRE(approxEqual<float>(output, envelope));
|
|
|
|
|
|
|
|
|
|
ccData.data.curve = 3;
|
|
|
|
|
ccData.data.value = 10.0f;
|
|
|
|
|
multiplicativeEnvelope(resources.midiState.getCCEvents(20), absl::MakeSpan(envelope), [&ccData](float x) {
|
|
|
|
|
return db2mag(ccData.data.value * (1 - 2 * x));
|
|
|
|
|
});
|
|
|
|
|
multiplicativeModifier(resources, absl::MakeSpan(output), ccData, [](float x) {
|
|
|
|
|
return db2mag(x);
|
|
|
|
|
});
|
|
|
|
|
REQUIRE(approxEqual<float>(output, envelope));
|
|
|
|
|
|
|
|
|
|
ccData.data.curve = 2;
|
|
|
|
|
ccData.data.value = 20.0f;
|
2020-04-14 13:41:24 +02:00
|
|
|
ccData.data.step = 2.0f;
|
2020-04-06 20:12:59 +02:00
|
|
|
multiplicativeEnvelope(resources.midiState.getCCEvents(20), absl::MakeSpan(envelope), [&ccData](float x) {
|
|
|
|
|
return db2mag(ccData.data.value * (1 - x));
|
2020-04-14 13:41:24 +02:00
|
|
|
}, db2mag(ccData.data.step) );
|
2020-04-06 20:12:59 +02:00
|
|
|
multiplicativeModifier(resources, absl::MakeSpan(output), ccData, [](float x) {
|
|
|
|
|
return db2mag(x);
|
|
|
|
|
});
|
|
|
|
|
REQUIRE(approxEqual<float>(output, envelope));
|
|
|
|
|
}
|
|
|
|
|
|