Cosmetics
This commit is contained in:
parent
8e8ea4f420
commit
5fd7cab909
37 changed files with 1428 additions and 1527 deletions
|
|
@ -1,13 +1,12 @@
|
|||
#include "Globals.h"
|
||||
#include "SIMDHelpers.h"
|
||||
#include "Helpers.h"
|
||||
#include "ADSREnvelope.h"
|
||||
#include "Globals.h"
|
||||
#include "Helpers.h"
|
||||
#include "SIMDHelpers.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace sfz
|
||||
{
|
||||
namespace sfz {
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
void ADSREnvelope<Type>::reset(int attack, int release, Type sustain, int delay, int decay, int hold, Type start, Type depth) noexcept
|
||||
{
|
||||
ASSERT(start <= 1.0f);
|
||||
|
|
@ -32,44 +31,40 @@ void ADSREnvelope<Type>::reset(int attack, int release, Type sustain, int delay,
|
|||
currentState = State::Delay;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
Type ADSREnvelope<Type>::getNextValue() noexcept
|
||||
{
|
||||
if (shouldRelease && releaseDelay-- == 0)
|
||||
{
|
||||
if (shouldRelease && releaseDelay-- == 0) {
|
||||
currentState = State::Release;
|
||||
step = std::exp((std::log(config::virtuallyZero) - std::log(currentValue)) / (release > 0 ? release : 1));
|
||||
}
|
||||
|
||||
switch(currentState)
|
||||
{
|
||||
|
||||
switch (currentState) {
|
||||
case State::Delay:
|
||||
if (delay-- > 0)
|
||||
return start;
|
||||
|
||||
|
||||
currentState = State::Attack;
|
||||
step = (1.0 - currentValue) / (attack > 0 ? attack : 1);
|
||||
[[fallthrough]];
|
||||
case State::Attack:
|
||||
if (attack-- > 0)
|
||||
{
|
||||
if (attack-- > 0) {
|
||||
currentValue += step;
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
|
||||
currentState = State::Hold;
|
||||
currentValue = 1.0;
|
||||
[[fallthrough]];
|
||||
case State::Hold:
|
||||
if (hold-- > 0)
|
||||
return currentValue;
|
||||
|
||||
|
||||
step = std::exp(std::log(sustain) / (decay > 0 ? decay : 1));
|
||||
currentState = State::Decay;
|
||||
[[fallthrough]];
|
||||
case State::Decay:
|
||||
if (decay-- > 0)
|
||||
{
|
||||
if (decay-- > 0) {
|
||||
currentValue *= step;
|
||||
return currentValue;
|
||||
}
|
||||
|
|
@ -80,8 +75,7 @@ Type ADSREnvelope<Type>::getNextValue() noexcept
|
|||
case State::Sustain:
|
||||
return currentValue;
|
||||
case State::Release:
|
||||
if (release-- > 0)
|
||||
{
|
||||
if (release-- > 0) {
|
||||
currentValue *= step;
|
||||
return currentValue;
|
||||
}
|
||||
|
|
@ -94,14 +88,13 @@ Type ADSREnvelope<Type>::getNextValue() noexcept
|
|||
}
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
void ADSREnvelope<Type>::getBlock(absl::Span<Type> output) noexcept
|
||||
{
|
||||
auto originalSpan = output;
|
||||
auto remainingSamples = static_cast<int>(output.size());
|
||||
int length;
|
||||
switch(currentState)
|
||||
{
|
||||
switch (currentState) {
|
||||
case State::Delay:
|
||||
length = min(remainingSamples, delay);
|
||||
::fill<Type>(output, currentValue);
|
||||
|
|
@ -110,7 +103,7 @@ void ADSREnvelope<Type>::getBlock(absl::Span<Type> output) noexcept
|
|||
delay -= length;
|
||||
if (remainingSamples == 0)
|
||||
break;
|
||||
|
||||
|
||||
currentState = State::Attack;
|
||||
step = (peak - start) / (attack > 0 ? attack : 1);
|
||||
[[fallthrough]];
|
||||
|
|
@ -122,7 +115,7 @@ void ADSREnvelope<Type>::getBlock(absl::Span<Type> output) noexcept
|
|||
attack -= length;
|
||||
if (remainingSamples == 0)
|
||||
break;
|
||||
|
||||
|
||||
currentValue = peak;
|
||||
currentState = State::Hold;
|
||||
[[fallthrough]];
|
||||
|
|
@ -134,7 +127,7 @@ void ADSREnvelope<Type>::getBlock(absl::Span<Type> output) noexcept
|
|||
hold -= length;
|
||||
if (remainingSamples == 0)
|
||||
break;
|
||||
|
||||
|
||||
step = std::exp(std::log(sustain) / (decay > 0 ? decay : 1));
|
||||
currentState = State::Decay;
|
||||
[[fallthrough]];
|
||||
|
|
@ -171,15 +164,13 @@ void ADSREnvelope<Type>::getBlock(absl::Span<Type> output) noexcept
|
|||
}
|
||||
::fill<Type>(output, currentValue);
|
||||
|
||||
if (shouldRelease)
|
||||
{
|
||||
if (shouldRelease) {
|
||||
remainingSamples = static_cast<int>(originalSpan.size());
|
||||
if (releaseDelay > remainingSamples)
|
||||
{
|
||||
if (releaseDelay > remainingSamples) {
|
||||
releaseDelay -= remainingSamples;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
originalSpan.remove_prefix(releaseDelay);
|
||||
if (originalSpan.size() > 0)
|
||||
currentValue = originalSpan.front();
|
||||
|
|
@ -191,22 +182,20 @@ void ADSREnvelope<Type>::getBlock(absl::Span<Type> output) noexcept
|
|||
originalSpan.remove_prefix(length);
|
||||
release -= length;
|
||||
|
||||
if (release == 0)
|
||||
{
|
||||
if (release == 0) {
|
||||
currentValue = 0.0;
|
||||
currentState = State::Done;
|
||||
::fill<Type>(originalSpan, 0.0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
bool ADSREnvelope<Type>::isSmoothing() noexcept
|
||||
{
|
||||
return currentState != State::Done;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
void ADSREnvelope<Type>::startRelease(int releaseDelay) noexcept
|
||||
{
|
||||
shouldRelease = true;
|
||||
|
|
|
|||
|
|
@ -1,23 +1,27 @@
|
|||
#pragma once
|
||||
#include <absl/types/span.h>
|
||||
#include "Helpers.h"
|
||||
namespace sfz
|
||||
{
|
||||
#include <absl/types/span.h>
|
||||
namespace sfz {
|
||||
|
||||
template<class Type>
|
||||
class ADSREnvelope
|
||||
{
|
||||
template <class Type>
|
||||
class ADSREnvelope {
|
||||
public:
|
||||
ADSREnvelope() = default;
|
||||
void reset(int attack, int release, Type sustain=1.0, int delay = 0, int decay = 0, int hold = 0, Type start=0.0, Type depth=1) noexcept;
|
||||
void reset(int attack, int release, Type sustain = 1.0, int delay = 0, int decay = 0, int hold = 0, Type start = 0.0, Type depth = 1) noexcept;
|
||||
Type getNextValue() noexcept;
|
||||
void getBlock(absl::Span<Type> output) noexcept;
|
||||
void startRelease(int releaseDelay) noexcept;
|
||||
bool isSmoothing() noexcept;
|
||||
|
||||
private:
|
||||
enum class State
|
||||
{
|
||||
Delay, Attack, Hold, Decay, Sustain, Release, Done
|
||||
enum class State {
|
||||
Delay,
|
||||
Attack,
|
||||
Hold,
|
||||
Decay,
|
||||
Sustain,
|
||||
Release,
|
||||
Done
|
||||
};
|
||||
State currentState { State::Done };
|
||||
Type currentValue { 0.0 };
|
||||
|
|
|
|||
|
|
@ -7,14 +7,13 @@
|
|||
#include <type_traits>
|
||||
#include <utility>
|
||||
template <class Type, unsigned int Alignment = SIMDConfig::defaultAlignment>
|
||||
class Buffer
|
||||
{
|
||||
class Buffer {
|
||||
public:
|
||||
using value_type = std::remove_cv_t<Type>;
|
||||
using pointer = value_type *;
|
||||
using const_pointer = const value_type *;
|
||||
using reference = value_type &;
|
||||
using const_reference = const value_type &;
|
||||
using pointer = value_type*;
|
||||
using const_pointer = const value_type*;
|
||||
using reference = value_type&;
|
||||
using const_reference = const value_type&;
|
||||
using iterator = pointer;
|
||||
using const_iterator = const_pointer;
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
|
|
@ -22,7 +21,7 @@ public:
|
|||
using size_type = size_t;
|
||||
using difference_type = ptrdiff_t;
|
||||
|
||||
Buffer()
|
||||
Buffer()
|
||||
{
|
||||
}
|
||||
Buffer(size_t size)
|
||||
|
|
@ -31,16 +30,14 @@ public:
|
|||
}
|
||||
bool resize(size_t newSize)
|
||||
{
|
||||
if (newSize == 0)
|
||||
{
|
||||
if (newSize == 0) {
|
||||
clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
auto tempSize = newSize + 2 * AlignmentMask; // To ensure that we have leeway at the beginning and at the end
|
||||
auto *newData = paddedData != nullptr ? std::realloc(paddedData, tempSize * sizeof(value_type)) : std::malloc(tempSize * sizeof(value_type));
|
||||
if (newData == nullptr)
|
||||
{
|
||||
auto* newData = paddedData != nullptr ? std::realloc(paddedData, tempSize * sizeof(value_type)) : std::malloc(tempSize * sizeof(value_type));
|
||||
if (newData == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +50,7 @@ public:
|
|||
_alignedEnd = normalEnd + Alignment - endMisalignment;
|
||||
else
|
||||
_alignedEnd = normalEnd;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -71,15 +68,14 @@ public:
|
|||
std::free(paddedData);
|
||||
}
|
||||
|
||||
Buffer(const Buffer<Type> &other)
|
||||
Buffer(const Buffer<Type>& other)
|
||||
{
|
||||
if (resize(other.size()))
|
||||
{
|
||||
if (resize(other.size())) {
|
||||
std::memcpy(this->data(), other.data(), other.size() * sizeof(value_type));
|
||||
}
|
||||
}
|
||||
|
||||
Buffer(Buffer<Type> &&other)
|
||||
Buffer(Buffer<Type>&& other)
|
||||
{
|
||||
largerSize = std::exchange(other.largerSize, 0);
|
||||
alignedSize = std::exchange(other.alignedSize, 0);
|
||||
|
|
@ -89,20 +85,18 @@ public:
|
|||
_alignedEnd = std::exchange(other._alignedEnd, nullptr);
|
||||
}
|
||||
|
||||
Buffer<Type> &operator=(const Buffer<Type> &other)
|
||||
Buffer<Type>& operator=(const Buffer<Type>& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
if (resize(other.size()))
|
||||
std::memcpy(this->data(), other.data(), other.size() * sizeof(value_type));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Buffer<Type> &operator=(Buffer<Type> &&other)
|
||||
Buffer<Type>& operator=(Buffer<Type>&& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
std::free(paddedData);
|
||||
largerSize = std::exchange(other.largerSize, 0);
|
||||
alignedSize = std::exchange(other.alignedSize, 0);
|
||||
|
|
@ -114,7 +108,7 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
Type &operator[](int idx) { return *(normalData + idx); }
|
||||
Type& operator[](int 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; }
|
||||
|
|
@ -123,17 +117,17 @@ public:
|
|||
constexpr pointer alignedEnd() noexcept { return _alignedEnd; }
|
||||
|
||||
private:
|
||||
static constexpr auto AlignmentMask{Alignment - 1};
|
||||
static constexpr auto TypeAlignment{Alignment / sizeof(value_type)};
|
||||
static constexpr auto TypeAlignmentMask{TypeAlignment - 1};
|
||||
static constexpr auto AlignmentMask { Alignment - 1 };
|
||||
static constexpr auto TypeAlignment { Alignment / sizeof(value_type) };
|
||||
static constexpr auto TypeAlignmentMask { TypeAlignment - 1 };
|
||||
static_assert(std::is_arithmetic<value_type>::value, "Type should be arithmetic");
|
||||
static_assert(Alignment == 0 || Alignment == 4 || Alignment == 8 || Alignment == 16, "Bad alignment value");
|
||||
static_assert(TypeAlignment * sizeof(value_type) == Alignment, "The alignment does not appear to be divided by the size of the Type");
|
||||
size_type largerSize{0};
|
||||
size_type alignedSize{0};
|
||||
pointer normalData{nullptr};
|
||||
pointer paddedData{nullptr};
|
||||
pointer normalEnd{nullptr};
|
||||
pointer _alignedEnd{nullptr};
|
||||
size_type largerSize { 0 };
|
||||
size_type alignedSize { 0 };
|
||||
pointer normalData { nullptr };
|
||||
pointer paddedData { nullptr };
|
||||
pointer normalEnd { nullptr };
|
||||
pointer _alignedEnd { nullptr };
|
||||
LEAK_DETECTOR(Buffer);
|
||||
};
|
||||
|
|
@ -1,33 +1,31 @@
|
|||
#pragma once
|
||||
#include <map>
|
||||
#include "Helpers.h"
|
||||
#include <map>
|
||||
|
||||
namespace sfz
|
||||
{
|
||||
template<class ValueType>
|
||||
class CCMap
|
||||
{
|
||||
namespace sfz {
|
||||
template <class ValueType>
|
||||
class CCMap {
|
||||
public:
|
||||
CCMap() = delete;
|
||||
CCMap(const ValueType& defaultValue) : defaultValue(defaultValue) { }
|
||||
CCMap(const ValueType& defaultValue)
|
||||
: defaultValue(defaultValue)
|
||||
{
|
||||
}
|
||||
CCMap(CCMap&&) = default;
|
||||
CCMap(const CCMap&) = default;
|
||||
~CCMap() = default;
|
||||
|
||||
const ValueType &getWithDefault(int index) const noexcept
|
||||
const ValueType& getWithDefault(int index) const noexcept
|
||||
{
|
||||
auto it = container.find(index);
|
||||
if (it == end(container))
|
||||
{
|
||||
if (it == end(container)) {
|
||||
return defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
ValueType &operator[](const int &key) noexcept
|
||||
ValueType& operator[](const int& key) noexcept
|
||||
{
|
||||
if (!contains(key))
|
||||
container.emplace(key, defaultValue);
|
||||
|
|
@ -35,7 +33,7 @@ public:
|
|||
}
|
||||
|
||||
inline bool empty() const { return container.empty(); }
|
||||
const ValueType &at(int index) const { return container.at(index); }
|
||||
const ValueType& at(int index) const { return container.at(index); }
|
||||
bool contains(int index) const noexcept { return container.find(index) != end(container); }
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ void sfz::FilePool::loadingThread()
|
|||
}
|
||||
|
||||
SndfileHandle sndFile(reinterpret_cast<const char*>(file.c_str()));
|
||||
// auto deleteAndTrackBuffers = [this]
|
||||
// auto deleteAndTrackBuffers = [this]
|
||||
std::unique_ptr<StereoBuffer<float>, std::function<void(StereoBuffer<float>*)>> fileLoaded(new StereoBuffer<float>(fileToLoad.numFrames), deleteAndTrackBuffers);
|
||||
auto readBuffer = std::make_unique<Buffer<float>>(fileToLoad.numFrames * 2);
|
||||
sndFile.readf(readBuffer->data(), fileToLoad.numFrames);
|
||||
|
|
|
|||
|
|
@ -1,25 +1,22 @@
|
|||
#pragma once
|
||||
#include "StereoBuffer.h"
|
||||
#include "Defaults.h"
|
||||
#include "StereoBuffer.h"
|
||||
#include "Voice.h"
|
||||
#include <sndfile.hh>
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <absl/container/flat_hash_map.h>
|
||||
#include <map>
|
||||
#include "readerwriterqueue.h"
|
||||
#include <absl/container/flat_hash_map.h>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <sndfile.hh>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
|
||||
namespace sfz
|
||||
{
|
||||
class FilePool
|
||||
{
|
||||
namespace sfz {
|
||||
class FilePool {
|
||||
public:
|
||||
FilePool()
|
||||
: fileLoadingThread(std::thread(&FilePool::loadingThread, this))
|
||||
: fileLoadingThread(std::thread(&FilePool::loadingThread, this))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
~FilePool()
|
||||
|
|
@ -30,8 +27,7 @@ public:
|
|||
void setRootDirectory(const std::filesystem::path& directory) { rootDirectory = directory; }
|
||||
size_t getNumPreloadedSamples() { return preloadedData.size(); }
|
||||
|
||||
struct FileInformation
|
||||
{
|
||||
struct FileInformation {
|
||||
uint32_t end { Default::sampleEndRange.getEnd() };
|
||||
uint32_t loopBegin { Default::loopRange.getStart() };
|
||||
uint32_t loopEnd { Default::loopRange.getEnd() };
|
||||
|
|
@ -40,7 +36,8 @@ public:
|
|||
};
|
||||
std::optional<FileInformation> getFileInformation(std::string_view filename);
|
||||
void enqueueLoading(Voice* voice, std::string_view sample, int numFrames);
|
||||
static void deleteAndTrackBuffers(StereoBuffer<float>* buffer) {
|
||||
static void deleteAndTrackBuffers(StereoBuffer<float>* buffer)
|
||||
{
|
||||
fileBuffers--;
|
||||
delete buffer;
|
||||
};
|
||||
|
|
@ -48,15 +45,15 @@ public:
|
|||
{
|
||||
return fileBuffers.load();
|
||||
}
|
||||
|
||||
private:
|
||||
std::filesystem::path rootDirectory;
|
||||
struct FileLoadingInformation
|
||||
{
|
||||
struct FileLoadingInformation {
|
||||
Voice* voice;
|
||||
std::string_view sample;
|
||||
int numFrames;
|
||||
};
|
||||
|
||||
|
||||
inline static std::atomic<int> fileBuffers { 0 };
|
||||
|
||||
moodycamel::BlockingReaderWriterQueue<FileLoadingInformation> loadingQueue;
|
||||
|
|
@ -64,7 +61,7 @@ private:
|
|||
std::thread fileLoadingThread;
|
||||
bool quitThread { false };
|
||||
Buffer<float> tempReadBuffer { config::preloadSize * 2 };
|
||||
|
||||
|
||||
// std::map<std::string_view, std::shared_ptr<StereoBuffer<float>>> preloadedData;
|
||||
absl::flat_hash_map<std::string_view, std::shared_ptr<StereoBuffer<float>>> preloadedData;
|
||||
LEAK_DETECTOR(FilePool);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
namespace sfz
|
||||
{
|
||||
namespace sfz {
|
||||
|
||||
namespace config
|
||||
{
|
||||
namespace config {
|
||||
constexpr float defaultSampleRate { 48000 };
|
||||
constexpr int defaultSamplesPerBlock { 1024 };
|
||||
constexpr int preloadSize { 8192 };
|
||||
|
|
@ -21,21 +19,20 @@ namespace config
|
|||
|
||||
} // namespace sfz
|
||||
|
||||
namespace SIMDConfig
|
||||
{
|
||||
constexpr unsigned int defaultAlignment { 16 };
|
||||
constexpr bool writeInterleaved { true };
|
||||
constexpr bool readInterleaved { true };
|
||||
constexpr bool fill { true };
|
||||
constexpr bool gain { false };
|
||||
constexpr bool mathfuns { false };
|
||||
constexpr bool loopingSFZIndex { true };
|
||||
constexpr bool linearRamp { false };
|
||||
constexpr bool multiplicativeRamp { true };
|
||||
constexpr bool add { false };
|
||||
namespace SIMDConfig {
|
||||
constexpr unsigned int defaultAlignment { 16 };
|
||||
constexpr bool writeInterleaved { true };
|
||||
constexpr bool readInterleaved { true };
|
||||
constexpr bool fill { true };
|
||||
constexpr bool gain { false };
|
||||
constexpr bool mathfuns { false };
|
||||
constexpr bool loopingSFZIndex { true };
|
||||
constexpr bool linearRamp { false };
|
||||
constexpr bool multiplicativeRamp { true };
|
||||
constexpr bool add { false };
|
||||
#if USE_SIMD
|
||||
constexpr bool useSIMD { true };
|
||||
constexpr bool useSIMD { true };
|
||||
#else
|
||||
constexpr bool useSIMD { false };
|
||||
constexpr bool useSIMD { false };
|
||||
#endif
|
||||
}
|
||||
|
|
@ -3,17 +3,14 @@
|
|||
#include <signal.h>
|
||||
#include <string_view>
|
||||
|
||||
inline void trimInPlace(std::string_view &s)
|
||||
inline void trimInPlace(std::string_view& s)
|
||||
{
|
||||
const auto leftPosition = s.find_first_not_of(" \r\t\n\f\v");
|
||||
if (leftPosition != s.npos)
|
||||
{
|
||||
if (leftPosition != s.npos) {
|
||||
s.remove_prefix(leftPosition);
|
||||
const auto rightPosition = s.find_last_not_of(" \r\t\n\f\v");
|
||||
s.remove_suffix(s.size() - rightPosition - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
s.remove_suffix(s.size());
|
||||
}
|
||||
}
|
||||
|
|
@ -21,14 +18,11 @@ inline void trimInPlace(std::string_view &s)
|
|||
inline std::string_view trim(std::string_view s)
|
||||
{
|
||||
const auto leftPosition = s.find_first_not_of(" \r\t\n\f\v");
|
||||
if (leftPosition != s.npos)
|
||||
{
|
||||
if (leftPosition != s.npos) {
|
||||
s.remove_prefix(leftPosition);
|
||||
const auto rightPosition = s.find_last_not_of(" \r\t\n\f\v");
|
||||
s.remove_suffix(s.size() - rightPosition - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
s.remove_suffix(s.size());
|
||||
}
|
||||
return s;
|
||||
|
|
@ -36,7 +30,7 @@ inline std::string_view trim(std::string_view s)
|
|||
|
||||
inline constexpr unsigned int Fnv1aBasis = 0x811C9DC5;
|
||||
inline constexpr unsigned int Fnv1aPrime = 0x01000193;
|
||||
inline constexpr unsigned int hash(const char *s, unsigned int h = Fnv1aBasis)
|
||||
inline constexpr unsigned int hash(const char* s, unsigned int h = Fnv1aBasis)
|
||||
{
|
||||
return !*s ? h : hash(s + 1, static_cast<unsigned int>((h ^ *s) * static_cast<unsigned long long>(Fnv1aPrime)));
|
||||
}
|
||||
|
|
@ -112,10 +106,9 @@ inline constexpr Type mag2db(Type in)
|
|||
return static_cast<Type>(20.0) * std::log10(in);
|
||||
}
|
||||
|
||||
namespace Random
|
||||
{
|
||||
namespace Random {
|
||||
static inline std::random_device randomDevice;
|
||||
static inline std::mt19937 randomGenerator{randomDevice()};
|
||||
static inline std::mt19937 randomGenerator { randomDevice() };
|
||||
} // namespace Random
|
||||
|
||||
inline float midiNoteFrequency(const int noteNumber)
|
||||
|
|
@ -124,30 +117,28 @@ inline float midiNoteFrequency(const int noteNumber)
|
|||
}
|
||||
|
||||
template <class Type>
|
||||
constexpr Type pi{3.141592653589793238462643383279502884};
|
||||
constexpr Type pi { 3.141592653589793238462643383279502884 };
|
||||
template <class Type>
|
||||
constexpr Type twoPi{2 * pi<Type>};
|
||||
constexpr Type twoPi { 2 * pi<Type> };
|
||||
template <class Type>
|
||||
constexpr Type piTwo{pi<Type> / 2};
|
||||
constexpr Type piTwo { pi<Type> / 2 };
|
||||
|
||||
#include <atomic>
|
||||
template <class Owner>
|
||||
class LeakDetector
|
||||
{
|
||||
class LeakDetector {
|
||||
public:
|
||||
LeakDetector()
|
||||
{
|
||||
objectCounter.count++;
|
||||
}
|
||||
LeakDetector(const LeakDetector &)
|
||||
LeakDetector(const LeakDetector&)
|
||||
{
|
||||
objectCounter.count++;
|
||||
}
|
||||
~LeakDetector()
|
||||
{
|
||||
objectCounter.count--;
|
||||
if (objectCounter.count.load() < 0)
|
||||
{
|
||||
if (objectCounter.count.load() < 0) {
|
||||
DBG("Deleted a dangling pointer for class " << Owner::getClassName());
|
||||
// Deleted a dangling pointer!
|
||||
ASSERTFALSE;
|
||||
|
|
@ -155,19 +146,17 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
struct ObjectCounter
|
||||
{
|
||||
struct ObjectCounter {
|
||||
ObjectCounter() = default;
|
||||
~ObjectCounter()
|
||||
{
|
||||
if (auto residualCount = count.load() > 0)
|
||||
{
|
||||
if (auto residualCount = count.load() > 0) {
|
||||
DBG("Leaked " << residualCount << " instance(s) of class " << Owner::getClassName());
|
||||
// Leaked ojects
|
||||
ASSERTFALSE;
|
||||
}
|
||||
};
|
||||
std::atomic<int> count{0};
|
||||
std::atomic<int> count { 0 };
|
||||
};
|
||||
static inline ObjectCounter objectCounter;
|
||||
};
|
||||
|
|
@ -175,7 +164,7 @@ private:
|
|||
#ifndef NDEBUG
|
||||
#define LEAK_DETECTOR(Class) \
|
||||
friend class LeakDetector<Class>; \
|
||||
static const char *getClassName() { return #Class; } \
|
||||
static const char* getClassName() { return #Class; } \
|
||||
LeakDetector<Class> leakDetector;
|
||||
#else
|
||||
#define LEAK_DETECTOR(Class)
|
||||
|
|
|
|||
|
|
@ -3,56 +3,55 @@
|
|||
#include "SIMDHelpers.h"
|
||||
#include <absl/algorithm/container.h>
|
||||
|
||||
namespace sfz
|
||||
{
|
||||
namespace sfz {
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
LinearEnvelope<Type>::LinearEnvelope()
|
||||
{
|
||||
setMaxCapacity(maxCapacity);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
LinearEnvelope<Type>::LinearEnvelope(int maxCapacity, std::function<Type(Type)> function)
|
||||
{
|
||||
setMaxCapacity(maxCapacity);
|
||||
setFunction(function);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
void LinearEnvelope<Type>::setMaxCapacity(int maxCapacity)
|
||||
{
|
||||
events.reserve(maxCapacity);
|
||||
this->maxCapacity = maxCapacity;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
void LinearEnvelope<Type>::setFunction(std::function<Type(Type)> function)
|
||||
{
|
||||
this->function = function;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
void LinearEnvelope<Type>::registerEvent(int timestamp, Type inputValue)
|
||||
{
|
||||
if (static_cast<int>(events.size()) < maxCapacity)
|
||||
events.emplace_back(timestamp, function(inputValue));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
void LinearEnvelope<Type>::clear()
|
||||
{
|
||||
events.clear();
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
void LinearEnvelope<Type>::reset(Type value)
|
||||
{
|
||||
clear();
|
||||
currentValue = function(value);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
void LinearEnvelope<Type>::getBlock(absl::Span<Type> output)
|
||||
{
|
||||
absl::c_sort(events, [](const auto& lhs, const auto& rhs) {
|
||||
|
|
@ -60,15 +59,13 @@ void LinearEnvelope<Type>::getBlock(absl::Span<Type> output)
|
|||
});
|
||||
int index { 0 };
|
||||
|
||||
for (auto& event: events)
|
||||
{
|
||||
for (auto& event : events) {
|
||||
const auto length = min(event.first, static_cast<int>(output.size())) - index;
|
||||
if (length == 0)
|
||||
{
|
||||
if (length == 0) {
|
||||
currentValue = event.second;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
const auto step = (event.second - currentValue) / length;
|
||||
currentValue = ::linearRamp<Type>(output.subspan(index, length), currentValue, step);
|
||||
index += length;
|
||||
|
|
@ -76,7 +73,7 @@ void LinearEnvelope<Type>::getBlock(absl::Span<Type> output)
|
|||
|
||||
if (index < static_cast<int>(output.size()))
|
||||
::fill<Type>(output.subspan(index), currentValue);
|
||||
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,14 @@
|
|||
#pragma once
|
||||
#include "Globals.h"
|
||||
#include "Helpers.h"
|
||||
#include <type_traits>
|
||||
#include <functional>
|
||||
#include <absl/types/span.h>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
namespace sfz
|
||||
{
|
||||
namespace sfz {
|
||||
|
||||
template<class Type>
|
||||
class LinearEnvelope
|
||||
{
|
||||
template <class Type>
|
||||
class LinearEnvelope {
|
||||
public:
|
||||
LinearEnvelope();
|
||||
LinearEnvelope(int maxCapacity, std::function<Type(Type)> function);
|
||||
|
|
@ -18,8 +16,9 @@ public:
|
|||
void setFunction(std::function<Type(Type)> function);
|
||||
void registerEvent(int timestamp, Type inputValue);
|
||||
void clear();
|
||||
void reset(Type value=0.0);
|
||||
void reset(Type value = 0.0);
|
||||
void getBlock(absl::Span<Type> output);
|
||||
|
||||
private:
|
||||
std::function<Type(Type)> function { [](Type input) { return input; } };
|
||||
static_assert(std::is_arithmetic<Type>::value);
|
||||
|
|
|
|||
|
|
@ -1,20 +1,19 @@
|
|||
#pragma once
|
||||
#include "Globals.h"
|
||||
#include <cmath>
|
||||
#include <absl/types/span.h>
|
||||
#include <cmath>
|
||||
|
||||
template<class Type=float>
|
||||
class OnePoleFilter
|
||||
{
|
||||
template <class Type = float>
|
||||
class OnePoleFilter {
|
||||
public:
|
||||
OnePoleFilter() = default;
|
||||
// Normalized cutoff with respect to the sampling rate
|
||||
template<class C>
|
||||
template <class C>
|
||||
static Type normalizedGain(Type cutoff, C sampleRate)
|
||||
{
|
||||
return std::tan( cutoff / static_cast<Type>(sampleRate) * M_PIf32 );
|
||||
return std::tan(cutoff / static_cast<Type>(sampleRate) * M_PIf32);
|
||||
}
|
||||
|
||||
|
||||
OnePoleFilter(Type gain)
|
||||
{
|
||||
setGain(gain);
|
||||
|
|
@ -23,16 +22,15 @@ public:
|
|||
void setGain(Type gain)
|
||||
{
|
||||
this->gain = gain;
|
||||
G = gain / ( 1 + gain);
|
||||
G = gain / (1 + gain);
|
||||
}
|
||||
|
||||
Type getGain() const { return gain; }
|
||||
|
||||
int processLowpass(absl::Span<const Type> input, absl::Span<Type> lowpass)
|
||||
{
|
||||
for (auto [in, out] = std::pair(input.begin(), lowpass.begin());
|
||||
in < input.end() && out < lowpass.end(); in++, out++)
|
||||
{
|
||||
for (auto [in, out] = std::pair(input.begin(), lowpass.begin());
|
||||
in < input.end() && out < lowpass.end(); in++, out++) {
|
||||
oneLowpass(in, out);
|
||||
}
|
||||
return std::min(input.size(), lowpass.size());
|
||||
|
|
@ -40,9 +38,8 @@ public:
|
|||
|
||||
int processHighpass(absl::Span<const Type> input, absl::Span<Type> highpass)
|
||||
{
|
||||
for (auto [in, out] = std::pair(input.begin(), highpass.begin());
|
||||
in < input.end() && out < highpass.end(); in++, out++)
|
||||
{
|
||||
for (auto [in, out] = std::pair(input.begin(), highpass.begin());
|
||||
in < input.end() && out < highpass.end(); in++, out++) {
|
||||
oneHighpass(in, out);
|
||||
}
|
||||
return std::min(input.size(), highpass.size());
|
||||
|
|
@ -50,35 +47,34 @@ public:
|
|||
|
||||
int processLowpassVariableGain(absl::Span<const Type> input, absl::Span<Type> lowpass, absl::Span<const Type> gain)
|
||||
{
|
||||
for (auto [in, out, g] = std::tuple(input.begin(), lowpass.begin(), gain.begin());
|
||||
in < input.end() && out < lowpass.end() && g < gain.end(); in++, out++, g++)
|
||||
{
|
||||
for (auto [in, out, g] = std::tuple(input.begin(), lowpass.begin(), gain.begin());
|
||||
in < input.end() && out < lowpass.end() && g < gain.end(); in++, out++, g++) {
|
||||
setGain(*g);
|
||||
oneLowpass(in, out);
|
||||
}
|
||||
|
||||
|
||||
return std::min({ input.size(), lowpass.size(), gain.size() });
|
||||
}
|
||||
|
||||
int processHighpassVariableGain(absl::Span<const Type> input, absl::Span<Type> highpass, absl::Span<const Type> gain)
|
||||
{
|
||||
for (auto [in, out, g] = std::tuple(input.begin(), highpass.begin(), gain.begin());
|
||||
in < input.end() && out < highpass.end() && g < gain.end(); in++, out++, g++)
|
||||
{
|
||||
for (auto [in, out, g] = std::tuple(input.begin(), highpass.begin(), gain.begin());
|
||||
in < input.end() && out < highpass.end() && g < gain.end(); in++, out++, g++) {
|
||||
setGain(*g);
|
||||
oneHighpass(in, out);
|
||||
}
|
||||
|
||||
|
||||
return std::min({ input.size(), highpass.size(), gain.size() });
|
||||
}
|
||||
|
||||
void reset() { state = 0.0; }
|
||||
|
||||
private:
|
||||
Type state { 0.0 };
|
||||
Type gain { 0.25 };
|
||||
Type intermediate { 0.0 };
|
||||
Type G { gain / (1 + gain) };
|
||||
|
||||
|
||||
inline void oneLowpass(const Type* in, Type* out)
|
||||
{
|
||||
intermediate = G * (*in - state);
|
||||
|
|
@ -90,6 +86,6 @@ private:
|
|||
{
|
||||
intermediate = G * (*in - state);
|
||||
*out = *in - intermediate - state;
|
||||
state += 2*intermediate;
|
||||
state += 2 * intermediate;
|
||||
}
|
||||
};
|
||||
|
|
@ -1,15 +1,14 @@
|
|||
#include "Opcode.h"
|
||||
|
||||
sfz::Opcode::Opcode(std::string_view inputOpcode, std::string_view inputValue)
|
||||
:opcode(inputOpcode), value(inputValue)
|
||||
: opcode(inputOpcode)
|
||||
, value(inputValue)
|
||||
{
|
||||
if (const auto lastCharIndex = inputOpcode.find_last_not_of("1234567890"); lastCharIndex != inputOpcode.npos)
|
||||
{
|
||||
if (const auto lastCharIndex = inputOpcode.find_last_not_of("1234567890"); lastCharIndex != inputOpcode.npos) {
|
||||
int returnedValue;
|
||||
std::string_view parameterView = inputOpcode;
|
||||
parameterView.remove_prefix(lastCharIndex + 1);
|
||||
if (absl::SimpleAtoi(parameterView, &returnedValue))
|
||||
{
|
||||
if (absl::SimpleAtoi(parameterView, &returnedValue)) {
|
||||
parameter = returnedValue;
|
||||
opcode.remove_suffix(opcode.size() - lastCharIndex - 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,29 @@
|
|||
#pragma once
|
||||
#include "Helpers.h"
|
||||
#include "SfzHelpers.h"
|
||||
#include "Defaults.h"
|
||||
#include "Helpers.h"
|
||||
#include "Range.h"
|
||||
#include <string_view>
|
||||
#include "SfzHelpers.h"
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
// charconv support is still sketchy with clang/gcc so we use abseil's numbers
|
||||
#include "absl/strings/numbers.h"
|
||||
|
||||
namespace sfz
|
||||
{
|
||||
struct Opcode
|
||||
{
|
||||
namespace sfz {
|
||||
struct Opcode {
|
||||
Opcode() = delete;
|
||||
Opcode(std::string_view inputOpcode, std::string_view inputValue);
|
||||
std::string_view opcode{};
|
||||
std::string_view value{};
|
||||
std::string_view opcode {};
|
||||
std::string_view value {};
|
||||
// This is to handle the integer parameter of some opcodes
|
||||
std::optional<uint8_t> parameter;
|
||||
LEAK_DETECTOR(Opcode);
|
||||
};
|
||||
|
||||
template<class ValueType>
|
||||
template <class ValueType>
|
||||
inline std::optional<ValueType> readOpcode(std::string_view value, const Range<ValueType>& validRange)
|
||||
{
|
||||
if constexpr(std::is_integral<ValueType>::value)
|
||||
{
|
||||
if constexpr (std::is_integral<ValueType>::value) {
|
||||
int64_t returnedValue;
|
||||
if (!absl::SimpleAtoi(value, &returnedValue))
|
||||
return {};
|
||||
|
|
@ -37,9 +34,7 @@ inline std::optional<ValueType> readOpcode(std::string_view value, const Range<V
|
|||
returnedValue = std::numeric_limits<ValueType>::min();
|
||||
|
||||
return validRange.clamp(static_cast<ValueType>(returnedValue));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
float returnedValue;
|
||||
if (!absl::SimpleAtof(value, &returnedValue))
|
||||
return std::nullopt;
|
||||
|
|
@ -48,7 +43,7 @@ inline std::optional<ValueType> readOpcode(std::string_view value, const Range<V
|
|||
}
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
template <class ValueType>
|
||||
inline void setValueFromOpcode(const Opcode& opcode, ValueType& target, const Range<ValueType>& validRange)
|
||||
{
|
||||
auto value = readOpcode(opcode.value, validRange);
|
||||
|
|
@ -58,7 +53,7 @@ inline void setValueFromOpcode(const Opcode& opcode, ValueType& target, const Ra
|
|||
target = *value;
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
template <class ValueType>
|
||||
inline void setValueFromOpcode(const Opcode& opcode, std::optional<ValueType>& target, const Range<ValueType>& validRange)
|
||||
{
|
||||
auto value = readOpcode(opcode.value, validRange);
|
||||
|
|
@ -68,7 +63,7 @@ inline void setValueFromOpcode(const Opcode& opcode, std::optional<ValueType>& t
|
|||
target = *value;
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
template <class ValueType>
|
||||
inline void setRangeEndFromOpcode(const Opcode& opcode, Range<ValueType>& target, const Range<ValueType>& validRange)
|
||||
{
|
||||
auto value = readOpcode(opcode.value, validRange);
|
||||
|
|
@ -78,7 +73,7 @@ inline void setRangeEndFromOpcode(const Opcode& opcode, Range<ValueType>& target
|
|||
target.setEnd(*value);
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
template <class ValueType>
|
||||
inline void setRangeStartFromOpcode(const Opcode& opcode, Range<ValueType>& target, const Range<ValueType>& validRange)
|
||||
{
|
||||
auto value = readOpcode(opcode.value, validRange);
|
||||
|
|
@ -88,11 +83,11 @@ inline void setRangeStartFromOpcode(const Opcode& opcode, Range<ValueType>& targ
|
|||
target.setStart(*value);
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
template <class ValueType>
|
||||
inline void setCCPairFromOpcode(const Opcode& opcode, std::optional<CCValuePair>& target, const Range<ValueType>& validRange)
|
||||
{
|
||||
auto value = readOpcode(opcode.value, validRange);
|
||||
if (value && opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter))
|
||||
if (value && opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter))
|
||||
target = std::make_pair(*opcode.parameter, *value);
|
||||
else
|
||||
target = {};
|
||||
|
|
|
|||
|
|
@ -1,143 +1,130 @@
|
|||
#include "Parser.h"
|
||||
#include "Helpers.h"
|
||||
#include "Globals.h"
|
||||
#include "Helpers.h"
|
||||
#include "absl/strings/str_join.h"
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
using svregex_iterator = std::regex_iterator<std::string_view::const_iterator>;
|
||||
using svmatch_results = std::match_results<std::string_view::const_iterator>;
|
||||
|
||||
void removeCommentOnLine(std::string_view &line)
|
||||
void removeCommentOnLine(std::string_view& line)
|
||||
{
|
||||
if (auto position = line.find("//"); position != line.npos)
|
||||
line.remove_suffix(line.size() - position);
|
||||
if (auto position = line.find("//"); position != line.npos)
|
||||
line.remove_suffix(line.size() - position);
|
||||
}
|
||||
|
||||
bool sfz::Parser::loadSfzFile(const std::filesystem::path &file)
|
||||
bool sfz::Parser::loadSfzFile(const std::filesystem::path& file)
|
||||
{
|
||||
const auto sfzFile = file.is_absolute() ? file : rootDirectory / file;
|
||||
if (!std::filesystem::exists(sfzFile))
|
||||
return false;
|
||||
const auto sfzFile = file.is_absolute() ? file : rootDirectory / file;
|
||||
if (!std::filesystem::exists(sfzFile))
|
||||
return false;
|
||||
|
||||
rootDirectory = file.parent_path();
|
||||
std::vector<std::string> lines;
|
||||
readSfzFile(file, lines);
|
||||
rootDirectory = file.parent_path();
|
||||
std::vector<std::string> lines;
|
||||
readSfzFile(file, lines);
|
||||
|
||||
aggregatedContent = absl::StrJoin(lines, " ");
|
||||
const std::string_view aggregatedView{aggregatedContent};
|
||||
aggregatedContent = absl::StrJoin(lines, " ");
|
||||
const std::string_view aggregatedView { aggregatedContent };
|
||||
|
||||
svregex_iterator headerIterator(aggregatedView.cbegin(), aggregatedView.cend(), sfz::Regexes::headers);
|
||||
const auto regexEnd = svregex_iterator();
|
||||
svregex_iterator headerIterator(aggregatedView.cbegin(), aggregatedView.cend(), sfz::Regexes::headers);
|
||||
const auto regexEnd = svregex_iterator();
|
||||
|
||||
std::vector<Opcode> currentMembers;
|
||||
std::vector<Opcode> currentMembers;
|
||||
|
||||
for (; headerIterator != regexEnd; ++headerIterator)
|
||||
{
|
||||
svmatch_results headerMatch = *headerIterator;
|
||||
for (; headerIterator != regexEnd; ++headerIterator) {
|
||||
svmatch_results headerMatch = *headerIterator;
|
||||
|
||||
// Can't use uniform initialization here because it generates narrowing conversions
|
||||
const std::string_view header(&*headerMatch[1].first, headerMatch[1].length());
|
||||
const std::string_view members(&*headerMatch[2].first, headerMatch[2].length());
|
||||
auto paramIterator = svregex_iterator(members.cbegin(), members.cend(), sfz::Regexes::members);
|
||||
// Can't use uniform initialization here because it generates narrowing conversions
|
||||
const std::string_view header(&*headerMatch[1].first, headerMatch[1].length());
|
||||
const std::string_view members(&*headerMatch[2].first, headerMatch[2].length());
|
||||
auto paramIterator = svregex_iterator(members.cbegin(), members.cend(), sfz::Regexes::members);
|
||||
|
||||
// Store or handle members
|
||||
for (; paramIterator != regexEnd; ++paramIterator)
|
||||
{
|
||||
const svmatch_results paramMatch = *paramIterator;
|
||||
const std::string_view opcode(&*paramMatch[1].first, paramMatch[1].length());
|
||||
const std::string_view value(&*paramMatch[2].first, paramMatch[2].length());
|
||||
currentMembers.emplace_back(opcode, value);
|
||||
}
|
||||
callback(header, currentMembers);
|
||||
currentMembers.clear();
|
||||
}
|
||||
// Store or handle members
|
||||
for (; paramIterator != regexEnd; ++paramIterator) {
|
||||
const svmatch_results paramMatch = *paramIterator;
|
||||
const std::string_view opcode(&*paramMatch[1].first, paramMatch[1].length());
|
||||
const std::string_view value(&*paramMatch[2].first, paramMatch[2].length());
|
||||
currentMembers.emplace_back(opcode, value);
|
||||
}
|
||||
callback(header, currentMembers);
|
||||
currentMembers.clear();
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void sfz::Parser::readSfzFile(const std::filesystem::path &fileName, std::vector<std::string> &lines) noexcept
|
||||
void sfz::Parser::readSfzFile(const std::filesystem::path& fileName, std::vector<std::string>& lines) noexcept
|
||||
{
|
||||
std::ifstream fileStream(fileName.c_str());
|
||||
if (!fileStream)
|
||||
return;
|
||||
std::ifstream fileStream(fileName.c_str());
|
||||
if (!fileStream)
|
||||
return;
|
||||
|
||||
// spdlog::info("Including file {}", fileName.string());
|
||||
svmatch_results includeMatch;
|
||||
svmatch_results defineMatch;
|
||||
// spdlog::info("Including file {}", fileName.string());
|
||||
svmatch_results includeMatch;
|
||||
svmatch_results defineMatch;
|
||||
|
||||
std::string tmpString;
|
||||
while (std::getline(fileStream, tmpString))
|
||||
{
|
||||
std::string_view tmpView{tmpString};
|
||||
std::string tmpString;
|
||||
while (std::getline(fileStream, tmpString)) {
|
||||
std::string_view tmpView { tmpString };
|
||||
|
||||
removeCommentOnLine(tmpView);
|
||||
trimInPlace(tmpView);
|
||||
removeCommentOnLine(tmpView);
|
||||
trimInPlace(tmpView);
|
||||
|
||||
if (tmpView.empty())
|
||||
continue;
|
||||
if (tmpView.empty())
|
||||
continue;
|
||||
|
||||
// New #include
|
||||
if (std::regex_search(tmpView.begin(), tmpView.end(), includeMatch, sfz::Regexes::includes))
|
||||
{
|
||||
auto includePath = includeMatch.str(1);
|
||||
std::replace(includePath.begin(), includePath.end(), '\\', '/');
|
||||
const auto newFile = rootDirectory / includePath;
|
||||
auto alreadyIncluded = std::find(includedFiles.begin(), includedFiles.end(), newFile);
|
||||
if (std::filesystem::exists(newFile))
|
||||
{
|
||||
if (alreadyIncluded == includedFiles.end())
|
||||
{
|
||||
includedFiles.push_back(newFile);
|
||||
readSfzFile(newFile, lines);
|
||||
}
|
||||
else if (!recursiveIncludeGuard)
|
||||
{
|
||||
readSfzFile(newFile, lines);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// New #include
|
||||
if (std::regex_search(tmpView.begin(), tmpView.end(), includeMatch, sfz::Regexes::includes)) {
|
||||
auto includePath = includeMatch.str(1);
|
||||
std::replace(includePath.begin(), includePath.end(), '\\', '/');
|
||||
const auto newFile = rootDirectory / includePath;
|
||||
auto alreadyIncluded = std::find(includedFiles.begin(), includedFiles.end(), newFile);
|
||||
if (std::filesystem::exists(newFile)) {
|
||||
if (alreadyIncluded == includedFiles.end()) {
|
||||
includedFiles.push_back(newFile);
|
||||
readSfzFile(newFile, lines);
|
||||
} else if (!recursiveIncludeGuard) {
|
||||
readSfzFile(newFile, lines);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// New #define
|
||||
if (std::regex_search(tmpView.begin(), tmpView.end(), defineMatch, sfz::Regexes::defines))
|
||||
{
|
||||
defines[defineMatch.str(1)] = defineMatch.str(2);
|
||||
continue;
|
||||
}
|
||||
// New #define
|
||||
if (std::regex_search(tmpView.begin(), tmpView.end(), defineMatch, sfz::Regexes::defines)) {
|
||||
defines[defineMatch.str(1)] = defineMatch.str(2);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Replace defined variables starting with $
|
||||
std::string newString;
|
||||
newString.reserve(tmpView.length());
|
||||
std::string::size_type lastPos = 0;
|
||||
std::string::size_type findPos = tmpView.find(sfz::config::defineCharacter, lastPos);
|
||||
// Replace defined variables starting with $
|
||||
std::string newString;
|
||||
newString.reserve(tmpView.length());
|
||||
std::string::size_type lastPos = 0;
|
||||
std::string::size_type findPos = tmpView.find(sfz::config::defineCharacter, lastPos);
|
||||
|
||||
while (findPos < tmpView.npos)
|
||||
{
|
||||
newString.append(tmpView, lastPos, findPos - lastPos);
|
||||
while (findPos < tmpView.npos) {
|
||||
newString.append(tmpView, lastPos, findPos - lastPos);
|
||||
|
||||
for (auto &definePair : defines)
|
||||
{
|
||||
std::string_view candidate = tmpView.substr(findPos, definePair.first.length());
|
||||
if (candidate == definePair.first)
|
||||
{
|
||||
newString += definePair.second;
|
||||
lastPos = findPos + definePair.first.length();
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (auto& definePair : defines) {
|
||||
std::string_view candidate = tmpView.substr(findPos, definePair.first.length());
|
||||
if (candidate == definePair.first) {
|
||||
newString += definePair.second;
|
||||
lastPos = findPos + definePair.first.length();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastPos <= findPos)
|
||||
{
|
||||
newString += sfz::config::defineCharacter;
|
||||
lastPos = findPos + 1;
|
||||
}
|
||||
if (lastPos <= findPos) {
|
||||
newString += sfz::config::defineCharacter;
|
||||
lastPos = findPos + 1;
|
||||
}
|
||||
|
||||
findPos = tmpView.find(sfz::config::defineCharacter, lastPos);
|
||||
}
|
||||
findPos = tmpView.find(sfz::config::defineCharacter, lastPos);
|
||||
}
|
||||
|
||||
// Copy the rest of the string
|
||||
newString += tmpView.substr(lastPos);
|
||||
lines.push_back(std::move(newString));
|
||||
}
|
||||
// Copy the rest of the string
|
||||
newString += tmpView.substr(lastPos);
|
||||
lines.push_back(std::move(newString));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +1,38 @@
|
|||
#pragma once
|
||||
#include "Opcode.h"
|
||||
#include <filesystem>
|
||||
#include <regex>
|
||||
#include <map>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace sfz
|
||||
{
|
||||
namespace Regexes
|
||||
{
|
||||
namespace sfz {
|
||||
namespace Regexes {
|
||||
inline static std::regex includes { R"V(#include\s*"(.*?)".*$)V", std::regex::optimize };
|
||||
inline static std::regex defines { R"(#define\s*(\$[a-zA-Z0-9]+)\s+([a-zA-Z0-9]+)(?=\s|$))", std::regex::optimize };
|
||||
inline static std::regex headers { R"(<(.*?)>(.*?)(?=<|$))", std::regex::optimize };
|
||||
inline static std::regex members { R"(([a-zA-Z0-9_]+)=([a-zA-Z0-9-_#.\/\s\\\(\),\*]+)(?![a-zA-Z0-9_]*=))", std::regex::optimize };
|
||||
inline static std::regex opcodeParameters{ R"(([a-zA-Z0-9_]+?)([0-9]+)$)", std::regex::optimize };
|
||||
inline static std::regex opcodeParameters { R"(([a-zA-Z0-9_]+?)([0-9]+)$)", std::regex::optimize };
|
||||
}
|
||||
|
||||
class Parser
|
||||
{
|
||||
class Parser {
|
||||
public:
|
||||
virtual bool loadSfzFile(const std::filesystem::path& file);
|
||||
const std::map<std::string, std::string>& getDefines() const noexcept { return defines; }
|
||||
const std::vector<std::filesystem::path>& getIncludedFiles() const noexcept { return includedFiles; }
|
||||
void disableRecursiveIncludeGuard() { recursiveIncludeGuard = false; }
|
||||
void enableRecursiveIncludeGuard() { recursiveIncludeGuard = true; }
|
||||
|
||||
protected:
|
||||
virtual void callback(std::string_view header, const std::vector<Opcode>& members) = 0;
|
||||
std::filesystem::path rootDirectory { std::filesystem::current_path() };
|
||||
|
||||
private:
|
||||
bool recursiveIncludeGuard { false };
|
||||
std::map<std::string, std::string> defines;
|
||||
std::vector<std::filesystem::path> includedFiles;
|
||||
std::string aggregatedContent { };
|
||||
std::string aggregatedContent {};
|
||||
void readSfzFile(const std::filesystem::path& fileName, std::vector<std::string>& lines) noexcept;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
#pragma once
|
||||
#include <type_traits>
|
||||
#include <initializer_list>
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
#include <type_traits>
|
||||
|
||||
template<class Type>
|
||||
class Range
|
||||
{
|
||||
template <class Type>
|
||||
class Range {
|
||||
static_assert(std::is_arithmetic<Type>::value, "The Type should be arithmetic");
|
||||
|
||||
public:
|
||||
constexpr Range() = default;
|
||||
// constexpr Range(std::initializer_list<Type> list)
|
||||
|
|
@ -25,11 +25,14 @@ public:
|
|||
// }
|
||||
// }
|
||||
constexpr Range(Type start, Type end) noexcept
|
||||
: _start(start), _end(std::max(start, end)) {}
|
||||
: _start(start)
|
||||
, _end(std::max(start, end))
|
||||
{
|
||||
}
|
||||
~Range() = default;
|
||||
Type getStart() const noexcept { return _start; }
|
||||
Type getEnd() const noexcept { return _end; }
|
||||
std::pair<Type, Type> getPair() const noexcept { return std::make_pair<Type, Type>(_start, _end); }
|
||||
std::pair<Type, Type> getPair() const noexcept { return std::make_pair<Type, Type>(_start, _end); }
|
||||
Range(const Range<Type>& range) = default;
|
||||
Range(Range<Type>&& range) = default;
|
||||
void setStart(Type start) noexcept
|
||||
|
|
@ -48,35 +51,36 @@ public:
|
|||
Type clamp(Type value) const noexcept { return std::clamp(value, _start, _end); }
|
||||
bool containsWithEnd(Type value) const noexcept { return (value >= _start && value <= _end); }
|
||||
bool contains(Type value) const noexcept { return (value >= _start && value < _end); }
|
||||
void shrinkIfSmaller( Type start, Type end)
|
||||
void shrinkIfSmaller(Type start, Type end)
|
||||
{
|
||||
if (start > end)
|
||||
std::swap(start, end);
|
||||
|
||||
|
||||
if (start > _start)
|
||||
_start = start;
|
||||
|
||||
if (end < _end)
|
||||
_end = end;
|
||||
}
|
||||
|
||||
private:
|
||||
Type _start { static_cast<Type>(0.0) };
|
||||
Type _end { static_cast<Type>(0.0) };
|
||||
};
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
bool operator==(const Range<Type>& lhs, const Range<Type>& rhs)
|
||||
{
|
||||
return (lhs.getStart() == rhs.getStart()) && (lhs.getEnd() == rhs.getEnd());
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
bool operator==(const Range<Type>& lhs, const std::pair<Type, Type>& rhs)
|
||||
{
|
||||
return (lhs.getStart() == rhs.first) && (lhs.getEnd() == rhs.second);
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
bool operator==(const std::pair<Type, Type>& lhs, const Range<Type>& rhs)
|
||||
{
|
||||
return rhs == lhs;
|
||||
|
|
|
|||
|
|
@ -4,13 +4,12 @@
|
|||
#include <bits/stdint-uintn.h>
|
||||
#include <random>
|
||||
|
||||
bool sfz::Region::parseOpcode(const Opcode &opcode)
|
||||
bool sfz::Region::parseOpcode(const Opcode& opcode)
|
||||
{
|
||||
switch (hash(opcode.opcode))
|
||||
{
|
||||
switch (hash(opcode.opcode)) {
|
||||
// Sound source: sample playback
|
||||
case hash("sample"):
|
||||
sample = absl::StrReplaceAll(trim(opcode.value), {{"\\", "/"}});
|
||||
sample = absl::StrReplaceAll(trim(opcode.value), { { "\\", "/" } });
|
||||
break;
|
||||
case hash("delay"):
|
||||
setValueFromOpcode(opcode, delay, Default::delayRange);
|
||||
|
|
@ -34,8 +33,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode)
|
|||
break;
|
||||
case hash("loopmode"):
|
||||
case hash("loop_mode"):
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
switch (hash(opcode.value)) {
|
||||
case hash("no_loop"):
|
||||
loopMode = SfzLoopMode::no_loop;
|
||||
break;
|
||||
|
|
@ -70,8 +68,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode)
|
|||
setValueFromOpcode(opcode, offBy, Default::groupRange);
|
||||
break;
|
||||
case hash("off_mode"):
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
switch (hash(opcode.value)) {
|
||||
case hash("fast"):
|
||||
offMode = SfzOffMode::fast;
|
||||
break;
|
||||
|
|
@ -115,8 +112,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode)
|
|||
setRangeEndFromOpcode(opcode, bendRange, Default::bendRange);
|
||||
break;
|
||||
case hash("locc"):
|
||||
if (opcode.parameter)
|
||||
{
|
||||
if (opcode.parameter) {
|
||||
setRangeStartFromOpcode(opcode, ccConditions[*opcode.parameter], Default::ccRange);
|
||||
}
|
||||
break;
|
||||
|
|
@ -146,8 +142,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode)
|
|||
previousKeySwitched = false;
|
||||
break;
|
||||
case hash("sw_vel"):
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
switch (hash(opcode.value)) {
|
||||
case hash("current"):
|
||||
velocityOverride = SfzVelocityOverride::current;
|
||||
break;
|
||||
|
|
@ -186,8 +181,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode)
|
|||
break;
|
||||
// Region logic: triggers
|
||||
case hash("trigger"):
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
switch (hash(opcode.value)) {
|
||||
case hash("attack"):
|
||||
trigger = SfzTrigger::attack;
|
||||
break;
|
||||
|
|
@ -263,8 +257,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode)
|
|||
gainDistribution.param(std::uniform_real_distribution<float>::param_type(-ampRandom, ampRandom));
|
||||
break;
|
||||
case hash("amp_velcurve_"):
|
||||
if (opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter))
|
||||
{
|
||||
if (opcode.parameter && Default::ccRange.containsWithEnd(*opcode.parameter)) {
|
||||
if (auto value = readOpcode(opcode.value, Default::ampVelcurveRange); value)
|
||||
velocityPoints.emplace_back(*opcode.parameter, *value);
|
||||
}
|
||||
|
|
@ -294,8 +287,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode)
|
|||
setRangeEndFromOpcode(opcode, crossfadeVelOutRange, Default::velocityRange);
|
||||
break;
|
||||
case hash("xf_keycurve"):
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
switch (hash(opcode.value)) {
|
||||
case hash("power"):
|
||||
crossfadeKeyCurve = SfzCrossfadeCurve::power;
|
||||
break;
|
||||
|
|
@ -307,8 +299,7 @@ bool sfz::Region::parseOpcode(const Opcode &opcode)
|
|||
}
|
||||
break;
|
||||
case hash("xf_velcurve"):
|
||||
switch (hash(opcode.value))
|
||||
{
|
||||
switch (hash(opcode.value)) {
|
||||
case hash("power"):
|
||||
crossfadeVelCurve = SfzCrossfadeCurve::power;
|
||||
break;
|
||||
|
|
@ -423,10 +414,8 @@ bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity,
|
|||
if (!chanOk)
|
||||
return false;
|
||||
|
||||
if (keyswitchRange.containsWithEnd(noteNumber))
|
||||
{
|
||||
if (keyswitch)
|
||||
{
|
||||
if (keyswitchRange.containsWithEnd(noteNumber)) {
|
||||
if (keyswitch) {
|
||||
if (*keyswitch == noteNumber)
|
||||
keySwitched = true;
|
||||
else
|
||||
|
|
@ -441,8 +430,7 @@ bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity,
|
|||
}
|
||||
|
||||
const bool keyOk = keyRange.containsWithEnd(noteNumber);
|
||||
if (keyOk)
|
||||
{
|
||||
if (keyOk) {
|
||||
// Update the number of notes playing for the region
|
||||
activeNotesInRange++;
|
||||
|
||||
|
|
@ -457,8 +445,7 @@ bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity,
|
|||
if (trigger == SfzTrigger::release_key || velocityOverride == SfzVelocityOverride::previous)
|
||||
lastNoteVelocities[noteNumber] = velocity;
|
||||
|
||||
if (previousNote)
|
||||
{
|
||||
if (previousNote) {
|
||||
if (*previousNote == noteNumber)
|
||||
previousKeySwitched = true;
|
||||
else
|
||||
|
|
@ -481,14 +468,13 @@ bool sfz::Region::registerNoteOn(int channel, int noteNumber, uint8_t velocity,
|
|||
return keyOk && velOk && chanOk && randOk && (attackTrigger || firstLegatoNote || notFirstLegatoNote);
|
||||
}
|
||||
|
||||
bool sfz::Region::registerNoteOff(int channel, int noteNumber, uint8_t velocity[[maybe_unused]], float randValue)
|
||||
bool sfz::Region::registerNoteOff(int channel, int noteNumber, uint8_t velocity [[maybe_unused]], float randValue)
|
||||
{
|
||||
const bool chanOk = channelRange.containsWithEnd(channel);
|
||||
if (!chanOk)
|
||||
return false;
|
||||
|
||||
if (keyswitchRange.containsWithEnd(noteNumber))
|
||||
{
|
||||
if (keyswitchRange.containsWithEnd(noteNumber)) {
|
||||
if (keyswitchDown && *keyswitchDown == noteNumber)
|
||||
keySwitched = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
#pragma once
|
||||
#include "Helpers.h"
|
||||
#include <bits/stdint-uintn.h>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Opcode.h"
|
||||
#include "EGDescription.h"
|
||||
#include "StereoBuffer.h"
|
||||
#include "Defaults.h"
|
||||
#include "CCMap.h"
|
||||
#include "Defaults.h"
|
||||
#include "EGDescription.h"
|
||||
#include "Helpers.h"
|
||||
#include "Opcode.h"
|
||||
#include "StereoBuffer.h"
|
||||
#include <bits/stdint-uintn.h>
|
||||
#include <bitset>
|
||||
#include <optional>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace sfz
|
||||
{
|
||||
struct Region
|
||||
{
|
||||
namespace sfz {
|
||||
struct Region {
|
||||
Region()
|
||||
{
|
||||
ccSwitched.set();
|
||||
|
|
@ -72,14 +70,14 @@ struct Region
|
|||
SfzOffMode offMode { Default::offMode }; // off_mode
|
||||
|
||||
// Region logic: key mapping
|
||||
Range<uint8_t> keyRange{ Default::keyRange }; //lokey, hikey and key
|
||||
Range<uint8_t> velocityRange{ Default::velocityRange }; // hivel and lovel
|
||||
Range<uint8_t> keyRange { Default::keyRange }; //lokey, hikey and key
|
||||
Range<uint8_t> velocityRange { Default::velocityRange }; // hivel and lovel
|
||||
|
||||
// Region logic: MIDI conditions
|
||||
Range<uint8_t> channelRange{ Default::channelRange }; //lochan and hichan
|
||||
Range<int> bendRange{ Default::bendRange }; // hibend and lobend
|
||||
Range<uint8_t> channelRange { Default::channelRange }; //lochan and hichan
|
||||
Range<int> bendRange { Default::bendRange }; // hibend and lobend
|
||||
CCMap<Range<uint8_t>> ccConditions { Default::ccRange };
|
||||
Range<uint8_t> keyswitchRange{ Default::keyRange }; // sw_hikey and sw_lokey
|
||||
Range<uint8_t> keyswitchRange { Default::keyRange }; // sw_hikey and sw_lokey
|
||||
std::optional<uint8_t> keyswitch {}; // sw_last
|
||||
std::optional<uint8_t> keyswitchUp {}; // sw_up
|
||||
std::optional<uint8_t> keyswitchDown {}; // sw_down
|
||||
|
|
@ -87,9 +85,9 @@ struct Region
|
|||
SfzVelocityOverride velocityOverride { Default::velocityOverride }; // sw_vel
|
||||
|
||||
// Region logic: internal conditions
|
||||
Range<uint8_t> aftertouchRange{ Default::aftertouchRange }; // hichanaft and lochanaft
|
||||
Range<float> bpmRange{ Default::bpmRange }; // hibpm and lobpm
|
||||
Range<float> randRange{ Default::randRange }; // hirand and lorand
|
||||
Range<uint8_t> aftertouchRange { Default::aftertouchRange }; // hichanaft and lochanaft
|
||||
Range<float> bpmRange { Default::bpmRange }; // hibpm and lobpm
|
||||
Range<float> randRange { Default::randRange }; // hirand and lorand
|
||||
uint8_t sequenceLength { Default::sequenceLength }; // seq_length
|
||||
uint8_t sequencePosition { Default::sequencePosition }; // seq_position
|
||||
|
||||
|
|
@ -122,10 +120,10 @@ struct Region
|
|||
SfzCrossfadeCurve crossfadeVelCurve { Default::crossfadeVelCurve };
|
||||
|
||||
// Performance parameters: pitch
|
||||
uint8_t pitchKeycenter{Default::pitchKeycenter}; // pitch_keycenter
|
||||
int pitchKeytrack{ Default::pitchKeytrack }; // pitch_keytrack
|
||||
int pitchRandom{ Default::pitchRandom }; // pitch_random
|
||||
int pitchVeltrack{ Default::pitchVeltrack }; // pitch_veltrack
|
||||
uint8_t pitchKeycenter { Default::pitchKeycenter }; // pitch_keycenter
|
||||
int pitchKeytrack { Default::pitchKeytrack }; // pitch_keytrack
|
||||
int pitchRandom { Default::pitchRandom }; // pitch_random
|
||||
int pitchVeltrack { Default::pitchVeltrack }; // pitch_veltrack
|
||||
int transpose { Default::transpose }; // transpose
|
||||
int tune { Default::tune }; // tune
|
||||
|
||||
|
|
@ -137,6 +135,7 @@ struct Region
|
|||
double sampleRate { config::defaultSampleRate };
|
||||
int numChannels { 1 };
|
||||
std::shared_ptr<StereoBuffer<float>> preloadedData { nullptr };
|
||||
|
||||
private:
|
||||
bool keySwitched { true };
|
||||
bool previousKeySwitched { true };
|
||||
|
|
|
|||
|
|
@ -1,79 +1,79 @@
|
|||
#include "SIMDHelpers.h"
|
||||
#include "Helpers.h"
|
||||
#include "SIMDHelpers.h"
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void readInterleaved<float, true>(absl::Span<const float> input, absl::Span<float> outputLeft, absl::Span<float> outputRight) noexcept
|
||||
{
|
||||
readInterleaved<float, false>(input, outputLeft, outputRight);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void writeInterleaved<float, true>(absl::Span<const float> inputLeft, absl::Span<const float> inputRight, absl::Span<float> output) noexcept
|
||||
{
|
||||
writeInterleaved<float, false>(inputLeft, inputRight, output);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void fill<float, true>(absl::Span<float> output, float value) noexcept
|
||||
{
|
||||
fill<float, false>(output, value);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void exp<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||
{
|
||||
exp<float, false>(input, output);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void log<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||
{
|
||||
log<float, false>(input, output);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void sin<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||
{
|
||||
sin<float, false>(input, output);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void cos<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||
{
|
||||
cos<float, false>(input, output);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void applyGain<float, true>(float gain, absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||
{
|
||||
applyGain<float, false>(gain, input, output);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void applyGain<float, true>(absl::Span<const float> gain, absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||
{
|
||||
applyGain<float, false>(gain, input, output);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void loopingSFZIndex<float, true>(absl::Span<const float> jumps, absl::Span<float> leftCoeff, absl::Span<float> rightCoeff, absl::Span<int> indices, float floatIndex, float loopEnd, float loopStart) noexcept
|
||||
{
|
||||
loopingSFZIndex<float, false>(jumps, leftCoeff, rightCoeff, indices, floatIndex, loopEnd, loopStart);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
float linearRamp<float, true>(absl::Span<float> output, float start, float step) noexcept
|
||||
{
|
||||
return linearRamp<float, false>(output, start, step);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
float multiplicativeRamp<float, true>(absl::Span<float> output, float start, float step) noexcept
|
||||
{
|
||||
return multiplicativeRamp<float, false>(output, start, step);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void add<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept
|
||||
{
|
||||
add<float, false>(input, output);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
#pragma once
|
||||
#include "Globals.h"
|
||||
#include <absl/types/span.h>
|
||||
#include <absl/algorithm/container.h>
|
||||
#include "Helpers.h"
|
||||
#include <absl/algorithm/container.h>
|
||||
#include <absl/types/span.h>
|
||||
#include <cmath>
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
inline void snippetRead(const T*& input, T*& outputLeft, T*& outputRight)
|
||||
{
|
||||
*outputLeft++ = *input++;
|
||||
*outputRight++ = *input++;
|
||||
}
|
||||
|
||||
template<class T, bool SIMD=SIMDConfig::readInterleaved>
|
||||
template <class T, bool SIMD = SIMDConfig::readInterleaved>
|
||||
void readInterleaved(absl::Span<const T> input, absl::Span<T> outputLeft, absl::Span<T> outputRight) noexcept
|
||||
{
|
||||
// The size of the output is not big enough for the input...
|
||||
|
|
@ -26,14 +26,14 @@ void readInterleaved(absl::Span<const T> input, absl::Span<T> outputLeft, absl::
|
|||
snippetRead<T>(in, lOut, rOut);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
inline void snippetWrite(T*& output, const T*& inputLeft, const T*& inputRight)
|
||||
{
|
||||
*output++ = *inputLeft++;
|
||||
*output++ = *inputRight++;
|
||||
}
|
||||
|
||||
template<class T, bool SIMD=SIMDConfig::writeInterleaved>
|
||||
template <class T, bool SIMD = SIMDConfig::writeInterleaved>
|
||||
void writeInterleaved(absl::Span<const T> inputLeft, absl::Span<const T> inputRight, absl::Span<T> output) noexcept
|
||||
{
|
||||
ASSERT(inputLeft.size() <= output.size() / 2);
|
||||
|
|
@ -47,21 +47,21 @@ void writeInterleaved(absl::Span<const T> inputLeft, absl::Span<const T> inputRi
|
|||
}
|
||||
|
||||
// Specializations
|
||||
template<>
|
||||
template <>
|
||||
void writeInterleaved<float, true>(absl::Span<const float> inputLeft, absl::Span<const float> inputRight, absl::Span<float> output) noexcept;
|
||||
template<>
|
||||
template <>
|
||||
void readInterleaved<float, true>(absl::Span<const float> input, absl::Span<float> outputLeft, absl::Span<float> outputRight) noexcept;
|
||||
|
||||
template<class T, bool SIMD=SIMDConfig::fill>
|
||||
template <class T, bool SIMD = SIMDConfig::fill>
|
||||
void fill(absl::Span<T> output, T value) noexcept
|
||||
{
|
||||
absl::c_fill(output, value);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void fill<float, true>(absl::Span<float> output, float value) noexcept;
|
||||
|
||||
template<class Type, bool SIMD=SIMDConfig::mathfuns>
|
||||
template <class Type, bool SIMD = SIMDConfig::mathfuns>
|
||||
void exp(absl::Span<const Type> input, absl::Span<Type> output) noexcept
|
||||
{
|
||||
ASSERT(output.size() >= input.size());
|
||||
|
|
@ -70,10 +70,10 @@ void exp(absl::Span<const Type> input, absl::Span<Type> output) noexcept
|
|||
output[i] = std::exp(input[i]);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void exp<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept;
|
||||
|
||||
template<class Type, bool SIMD=SIMDConfig::mathfuns>
|
||||
template <class Type, bool SIMD = SIMDConfig::mathfuns>
|
||||
void log(absl::Span<const Type> input, absl::Span<Type> output) noexcept
|
||||
{
|
||||
ASSERT(output.size() >= input.size());
|
||||
|
|
@ -82,10 +82,10 @@ void log(absl::Span<const Type> input, absl::Span<Type> output) noexcept
|
|||
output[i] = std::log(input[i]);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void log<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept;
|
||||
|
||||
template<class Type, bool SIMD=SIMDConfig::mathfuns>
|
||||
template <class Type, bool SIMD = SIMDConfig::mathfuns>
|
||||
void sin(absl::Span<const Type> input, absl::Span<Type> output) noexcept
|
||||
{
|
||||
ASSERT(output.size() >= input.size());
|
||||
|
|
@ -94,10 +94,10 @@ void sin(absl::Span<const Type> input, absl::Span<Type> output) noexcept
|
|||
output[i] = std::sin(input[i]);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void sin<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept;
|
||||
|
||||
template<class Type, bool SIMD=SIMDConfig::mathfuns>
|
||||
template <class Type, bool SIMD = SIMDConfig::mathfuns>
|
||||
void cos(absl::Span<const Type> input, absl::Span<Type> output) noexcept
|
||||
{
|
||||
ASSERT(output.size() >= input.size());
|
||||
|
|
@ -106,10 +106,10 @@ void cos(absl::Span<const Type> input, absl::Span<Type> output) noexcept
|
|||
output[i] = std::cos(input[i]);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void cos<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept;
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
inline void snippetLoopingIndex(const T*& jump, T*& leftCoeff, T*& rightCoeff, int*& index, T& floatIndex, T loopEnd, T loopStart)
|
||||
{
|
||||
floatIndex += *jump;
|
||||
|
|
@ -124,7 +124,7 @@ inline void snippetLoopingIndex(const T*& jump, T*& leftCoeff, T*& rightCoeff, i
|
|||
jump++;
|
||||
}
|
||||
|
||||
template<class T, bool SIMD=SIMDConfig::loopingSFZIndex>
|
||||
template <class T, bool SIMD = SIMDConfig::loopingSFZIndex>
|
||||
void loopingSFZIndex(absl::Span<const T> jumps, absl::Span<T> leftCoeffs, absl::Span<T> rightCoeffs, absl::Span<int> indices, T floatIndex, T loopEnd, T loopStart) noexcept
|
||||
{
|
||||
ASSERT(indices.size() >= jumps.size());
|
||||
|
|
@ -137,21 +137,21 @@ void loopingSFZIndex(absl::Span<const T> jumps, absl::Span<T> leftCoeffs, absl::
|
|||
auto* jump = jumps.begin();
|
||||
const auto size = min(jumps.size(), indices.size(), leftCoeffs.size(), rightCoeffs.size());
|
||||
auto* sentinel = jumps.begin() + size;
|
||||
|
||||
|
||||
while (jump < sentinel)
|
||||
snippetLoopingIndex<T>(jump, leftCoeff, rightCoeff, index, floatIndex, loopEnd, loopStart);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void loopingSFZIndex<float, true>(absl::Span<const float> jumps, absl::Span<float> leftCoeff, absl::Span<float> rightCoeff, absl::Span<int> indices, float floatIndex, float loopEnd, float loopStart) noexcept;
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
inline void snippetGain(T gain, const T*& input, T*& output)
|
||||
{
|
||||
*output++ = gain * (*input++);
|
||||
}
|
||||
|
||||
template<class T, bool SIMD=SIMDConfig::gain>
|
||||
template <class T, bool SIMD = SIMDConfig::gain>
|
||||
void applyGain(T gain, absl::Span<const T> input, absl::Span<T> output) noexcept
|
||||
{
|
||||
ASSERT(input.size() <= output.size());
|
||||
|
|
@ -162,13 +162,13 @@ void applyGain(T gain, absl::Span<const T> input, absl::Span<T> output) noexcept
|
|||
snippetGain<T>(gain, in, out);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
inline void snippetGainSpan(const T*& gain, const T*& input, T*& output)
|
||||
{
|
||||
*output++ = (*gain++) * (*input++);
|
||||
}
|
||||
|
||||
template<class T, bool SIMD=SIMDConfig::gain>
|
||||
template <class T, bool SIMD = SIMDConfig::gain>
|
||||
void applyGain(absl::Span<const T> gain, absl::Span<const T> input, absl::Span<T> output) noexcept
|
||||
{
|
||||
ASSERT(gain.size() == input.size());
|
||||
|
|
@ -181,69 +181,69 @@ void applyGain(absl::Span<const T> gain, absl::Span<const T> input, absl::Span<T
|
|||
snippetGainSpan<T>(g, in, out);
|
||||
}
|
||||
|
||||
template<class T, bool SIMD=SIMDConfig::gain>
|
||||
template <class T, bool SIMD = SIMDConfig::gain>
|
||||
void applyGain(T gain, absl::Span<T> output) noexcept
|
||||
{
|
||||
applyGain<T, SIMD>(gain, output, output);
|
||||
}
|
||||
|
||||
template<class T, bool SIMD=SIMDConfig::gain>
|
||||
template <class T, bool SIMD = SIMDConfig::gain>
|
||||
void applyGain(absl::Span<const T> gain, absl::Span<T> output) noexcept
|
||||
{
|
||||
applyGain<T, SIMD>(gain, output, output);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void applyGain<float, true>(float gain, absl::Span<const float> input, absl::Span<float> output) noexcept;
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void applyGain<float, true>(absl::Span<const float> gain, absl::Span<const float> input, absl::Span<float> output) noexcept;
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
inline void snippetRampLinear(T*& output, T& value, T step)
|
||||
{
|
||||
value += step;
|
||||
*output++ = value;
|
||||
}
|
||||
|
||||
template<class T, bool SIMD=SIMDConfig::linearRamp>
|
||||
template <class T, bool SIMD = SIMDConfig::linearRamp>
|
||||
T linearRamp(absl::Span<T> output, T start, T step) noexcept
|
||||
{
|
||||
auto* out = output.begin();
|
||||
while(out < output.end())
|
||||
while (out < output.end())
|
||||
snippetRampLinear<T>(out, start, step);
|
||||
return start;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
inline void snippetRampMultiplicative(T*& output, T& value, T step)
|
||||
{
|
||||
value *= step;
|
||||
*output++ = value;
|
||||
}
|
||||
|
||||
template<class T, bool SIMD=SIMDConfig::multiplicativeRamp>
|
||||
template <class T, bool SIMD = SIMDConfig::multiplicativeRamp>
|
||||
T multiplicativeRamp(absl::Span<T> output, T start, T step) noexcept
|
||||
{
|
||||
auto* out = output.begin();
|
||||
while(out < output.end())
|
||||
while (out < output.end())
|
||||
snippetRampMultiplicative<T>(out, start, step);
|
||||
return start;
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
float linearRamp<float, true>(absl::Span<float> output, float start, float step) noexcept;
|
||||
|
||||
template<>
|
||||
template <>
|
||||
float multiplicativeRamp<float, true>(absl::Span<float> output, float start, float step) noexcept;
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
inline void snippetAdd(const T*& input, T*& output)
|
||||
{
|
||||
*output++ += *input++;
|
||||
}
|
||||
|
||||
template<class T, bool SIMD=SIMDConfig::add>
|
||||
template <class T, bool SIMD = SIMDConfig::add>
|
||||
void add(absl::Span<const T> input, absl::Span<T> output) noexcept
|
||||
{
|
||||
ASSERT(output.size() >= input.size());
|
||||
|
|
@ -254,5 +254,5 @@ void add(absl::Span<const T> input, absl::Span<T> output) noexcept
|
|||
snippetAdd(in, out);
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
void add<float, true>(absl::Span<const float> input, absl::Span<float> output) noexcept;
|
||||
|
|
@ -283,13 +283,13 @@ void applyGain<float, true>(absl::Span<const float> gain, absl::Span<const float
|
|||
}
|
||||
|
||||
template <>
|
||||
void loopingSFZIndex<float, true>( absl::Span<const float> jumps,
|
||||
absl::Span<float> leftCoeffs,
|
||||
absl::Span<float> rightCoeffs,
|
||||
absl::Span<int> indices,
|
||||
float floatIndex,
|
||||
float loopEnd,
|
||||
float loopStart) noexcept
|
||||
void loopingSFZIndex<float, true>(absl::Span<const float> jumps,
|
||||
absl::Span<float> leftCoeffs,
|
||||
absl::Span<float> rightCoeffs,
|
||||
absl::Span<int> indices,
|
||||
float floatIndex,
|
||||
float loopEnd,
|
||||
float loopStart) noexcept
|
||||
{
|
||||
ASSERT(indices.size() >= jumps.size());
|
||||
ASSERT(indices.size() == leftCoeffs.size());
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
#include "Synth.h"
|
||||
#include "Helpers.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
|
||||
void sfz::Synth::callback(std::string_view header, const std::vector<Opcode>& members)
|
||||
{
|
||||
switch (hash(header))
|
||||
{
|
||||
switch (hash(header)) {
|
||||
case hash("global"):
|
||||
// We shouldn't have multiple global headers in file
|
||||
ASSERT(!hasGlobal);
|
||||
|
|
@ -23,7 +22,7 @@ void sfz::Synth::callback(std::string_view header, const std::vector<Opcode>& me
|
|||
masterOpcodes = members;
|
||||
numMasters++;
|
||||
break;
|
||||
case hash("group"):
|
||||
case hash("group"):
|
||||
groupOpcodes = members;
|
||||
numGroups++;
|
||||
break;
|
||||
|
|
@ -35,7 +34,7 @@ void sfz::Synth::callback(std::string_view header, const std::vector<Opcode>& me
|
|||
numCurves++;
|
||||
break;
|
||||
case hash("effect"):
|
||||
// TODO: implement curves
|
||||
// TODO: implement effects
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Unknown header: " << header << '\n';
|
||||
|
|
@ -45,9 +44,9 @@ void sfz::Synth::callback(std::string_view header, const std::vector<Opcode>& me
|
|||
void sfz::Synth::buildRegion(const std::vector<Opcode>& regionOpcodes)
|
||||
{
|
||||
auto lastRegion = std::make_unique<Region>();
|
||||
|
||||
|
||||
auto parseOpcodes = [&](const auto& opcodes) {
|
||||
for (auto& opcode: opcodes)
|
||||
for (auto& opcode : opcodes)
|
||||
if (!lastRegion->parseOpcode(opcode))
|
||||
unknownOpcodes.insert(opcode.opcode);
|
||||
};
|
||||
|
|
@ -68,7 +67,7 @@ void sfz::Synth::clear()
|
|||
numMasters = 0;
|
||||
numCurves = 0;
|
||||
defaultSwitch = std::nullopt;
|
||||
for (auto& state: ccState)
|
||||
for (auto& state : ccState)
|
||||
state = 0;
|
||||
ccNames.clear();
|
||||
globalOpcodes.clear();
|
||||
|
|
@ -79,8 +78,7 @@ void sfz::Synth::clear()
|
|||
|
||||
void sfz::Synth::handleGlobalOpcodes(const std::vector<Opcode>& members)
|
||||
{
|
||||
for (auto& member: members)
|
||||
{
|
||||
for (auto& member : members) {
|
||||
if (member.opcode == "sw_default")
|
||||
setValueFromOpcode(member, defaultSwitch, Default::keyRange);
|
||||
}
|
||||
|
|
@ -88,10 +86,8 @@ void sfz::Synth::handleGlobalOpcodes(const std::vector<Opcode>& members)
|
|||
|
||||
void sfz::Synth::handleControlOpcodes(const std::vector<Opcode>& members)
|
||||
{
|
||||
for (auto& member: members)
|
||||
{
|
||||
switch (hash(member.opcode))
|
||||
{
|
||||
for (auto& member : members) {
|
||||
switch (hash(member.opcode)) {
|
||||
case hash("set_cc"):
|
||||
if (member.parameter && Default::ccRange.containsWithEnd(*member.parameter))
|
||||
setValueFromOpcode(member, ccState[*member.parameter], Default::ccRange);
|
||||
|
|
@ -117,7 +113,7 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename)
|
|||
auto parserReturned = sfz::Parser::loadSfzFile(filename);
|
||||
if (!parserReturned)
|
||||
return false;
|
||||
|
||||
|
||||
if (regions.empty())
|
||||
return false;
|
||||
|
||||
|
|
@ -125,19 +121,16 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename)
|
|||
|
||||
auto lastRegion = regions.end() - 1;
|
||||
auto currentRegion = regions.begin();
|
||||
while (currentRegion <= lastRegion)
|
||||
{
|
||||
while (currentRegion <= lastRegion) {
|
||||
auto region = currentRegion->get();
|
||||
|
||||
if (region->isGenerator())
|
||||
{
|
||||
|
||||
if (region->isGenerator()) {
|
||||
currentRegion++;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto fileInformation = filePool.getFileInformation(region->sample);
|
||||
if (!fileInformation)
|
||||
{
|
||||
if (!fileInformation) {
|
||||
DBG("Removing the region with sample " << region->sample);
|
||||
std::iter_swap(currentRegion, lastRegion);
|
||||
lastRegion--;
|
||||
|
|
@ -154,20 +147,19 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename)
|
|||
|
||||
for (auto cc = region->keyRange.getStart(); cc <= region->keyRange.getEnd(); cc++)
|
||||
ccActivationLists[cc].push_back(region);
|
||||
|
||||
|
||||
// Defaults
|
||||
for (int ccIndex = 1; ccIndex < 128; ccIndex++)
|
||||
region->registerCC(region->channelRange.getStart(), ccIndex, ccState[ccIndex]);
|
||||
|
||||
if (defaultSwitch)
|
||||
{
|
||||
if (defaultSwitch) {
|
||||
region->registerNoteOn(region->channelRange.getStart(), *defaultSwitch, 127, 1.0);
|
||||
region->registerNoteOff(region->channelRange.getStart(), *defaultSwitch, 0, 1.0);
|
||||
}
|
||||
region->registerPitchWheel(region->channelRange.getStart(), 0);
|
||||
region->registerAftertouch(region->channelRange.getStart(), 0);
|
||||
region->registerTempo(2.0f);
|
||||
|
||||
|
||||
currentRegion++;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
#include "SfzHelpers.h"
|
||||
#include "StereoSpan.h"
|
||||
#include "absl/types/span.h"
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
#include <random>
|
||||
#include <set>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
using namespace std::literals;
|
||||
|
||||
namespace sfz {
|
||||
|
|
@ -129,7 +129,7 @@ public:
|
|||
void tempo(int delay, float secondsPerQuarter);
|
||||
|
||||
protected:
|
||||
void callback(std::string_view header, const std::vector<Opcode>& members) final;
|
||||
void callback(std::string_view header, const std::vector<Opcode>& members) final;
|
||||
|
||||
private:
|
||||
Voice* findFreeVoice()
|
||||
|
|
@ -177,13 +177,12 @@ private:
|
|||
std::thread garbageCollectionThread { [&]() {
|
||||
while (!threadsShouldQuit) {
|
||||
auto activeVoices { 0 };
|
||||
for (auto& voice : voices)
|
||||
{
|
||||
for (auto& voice : voices) {
|
||||
voice->garbageCollect();
|
||||
if (!voice->isFree())
|
||||
activeVoices++;
|
||||
}
|
||||
DBG("Active voices:" << activeVoices << " | Stray buffers: " << FilePool::getFileBuffers());
|
||||
DBG("Active voices:" << activeVoices << " | Stray buffers: " << FilePool::getFileBuffers());
|
||||
std::this_thread::sleep_for(1s);
|
||||
}
|
||||
} };
|
||||
|
|
@ -192,7 +191,7 @@ private:
|
|||
{
|
||||
return randomDistribution(randomGenerator);
|
||||
}
|
||||
|
||||
|
||||
LEAK_DETECTOR(Synth);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "ADSREnvelope.h"
|
||||
#include "Defaults.h"
|
||||
#include "Globals.h"
|
||||
#include "Region.h"
|
||||
#include "SIMDHelpers.h"
|
||||
|
|
@ -7,7 +8,6 @@
|
|||
#include "StereoBuffer.h"
|
||||
#include "StereoSpan.h"
|
||||
#include "absl/types/span.h"
|
||||
#include "Defaults.h"
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -92,7 +92,6 @@ public:
|
|||
if (ccState[64] < 63)
|
||||
egEnvelope.startRelease(delay);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void registerCC(int delay [[maybe_unused]], int channel [[maybe_unused]], int ccNumber [[maybe_unused]], uint8_t ccValue [[maybe_unused]])
|
||||
|
|
|
|||
|
|
@ -1,21 +1,20 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "../sources/ADSREnvelope.h"
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <absl/types/span.h>
|
||||
#include "catch2/catch.hpp"
|
||||
#include <absl/algorithm/container.h>
|
||||
#include <absl/types/span.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
using namespace Catch::literals;
|
||||
|
||||
template<class Type>
|
||||
inline bool approxEqual(absl::Span<const Type> lhs, absl::Span<const Type> rhs, Type eps=1e-3)
|
||||
template <class Type>
|
||||
inline bool approxEqual(absl::Span<const Type> lhs, absl::Span<const Type> rhs, Type eps = 1e-3)
|
||||
{
|
||||
if (lhs.size() != rhs.size())
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < rhs.size(); ++i)
|
||||
if (rhs[i] != Approx(lhs[i]).epsilon(eps))
|
||||
{
|
||||
if (rhs[i] != Approx(lhs[i]).epsilon(eps)) {
|
||||
std::cerr << lhs[i] << " != " << rhs[i] << " at index " << i << '\n';
|
||||
return false;
|
||||
}
|
||||
|
|
@ -28,13 +27,13 @@ TEST_CASE("[ADSREnvelope] Basic state")
|
|||
sfz::ADSREnvelope<float> envelope;
|
||||
std::array<float, 5> output;
|
||||
std::array<float, 5> expected { 0.0, 0.0, 0.0, 0.0, 0.0 };
|
||||
for (auto& out: output)
|
||||
for (auto& out : output)
|
||||
out = envelope.getNextValue();
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
|
||||
absl::c_fill(output, -1.0);
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
}
|
||||
|
||||
TEST_CASE("[ADSREnvelope] Attack")
|
||||
|
|
@ -43,14 +42,14 @@ TEST_CASE("[ADSREnvelope] Attack")
|
|||
envelope.reset(2, 0);
|
||||
std::array<float, 5> output;
|
||||
std::array<float, 5> expected { 0.5, 1.0, 1.0, 1.0, 1.0 };
|
||||
for (auto& out: output)
|
||||
for (auto& out : output)
|
||||
out = envelope.getNextValue();
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
|
||||
envelope.reset(2, 0);
|
||||
absl::c_fill(output, -1.0);
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
}
|
||||
|
||||
TEST_CASE("[ADSREnvelope] Attack again")
|
||||
|
|
@ -59,14 +58,14 @@ TEST_CASE("[ADSREnvelope] Attack again")
|
|||
envelope.reset(3, 0);
|
||||
std::array<float, 5> output;
|
||||
std::array<float, 5> expected { 0.33333, 0.66667, 1.0, 1.0, 1.0 };
|
||||
for (auto& out: output)
|
||||
for (auto& out : output)
|
||||
out = envelope.getNextValue();
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
|
||||
envelope.reset(3, 0);
|
||||
absl::c_fill(output, -1.0);
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
}
|
||||
|
||||
TEST_CASE("[ADSREnvelope] Release")
|
||||
|
|
@ -76,15 +75,15 @@ TEST_CASE("[ADSREnvelope] Release")
|
|||
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 };
|
||||
for (auto& out: output)
|
||||
for (auto& out : output)
|
||||
out = envelope.getNextValue();
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
|
||||
envelope.reset(2, 4);
|
||||
envelope.startRelease(2);
|
||||
absl::c_fill(output, -1.0);
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
}
|
||||
|
||||
TEST_CASE("[ADSREnvelope] Delay")
|
||||
|
|
@ -94,15 +93,15 @@ TEST_CASE("[ADSREnvelope] Delay")
|
|||
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 };
|
||||
for (auto& out: output)
|
||||
for (auto& out : output)
|
||||
out = envelope.getNextValue();
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
|
||||
envelope.reset(2, 4, 1.0f, 2);
|
||||
envelope.startRelease(4);
|
||||
absl::c_fill(output, -1.0);
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
}
|
||||
|
||||
TEST_CASE("[ADSREnvelope] Lower sustain")
|
||||
|
|
@ -111,14 +110,14 @@ TEST_CASE("[ADSREnvelope] Lower sustain")
|
|||
envelope.reset(2, 4, 0.5, 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 };
|
||||
for (auto& out: output)
|
||||
for (auto& out : output)
|
||||
out = envelope.getNextValue();
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
|
||||
envelope.reset(2, 4, 0.5, 2);
|
||||
absl::c_fill(output, -1.0);
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
}
|
||||
|
||||
TEST_CASE("[ADSREnvelope] Decay")
|
||||
|
|
@ -127,14 +126,14 @@ TEST_CASE("[ADSREnvelope] Decay")
|
|||
envelope.reset(2, 4, 0.5, 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 };
|
||||
for (auto& out: output)
|
||||
for (auto& out : output)
|
||||
out = envelope.getNextValue();
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
|
||||
envelope.reset(2, 4, 0.5, 2, 2);
|
||||
absl::c_fill(output, -1.0);
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
}
|
||||
|
||||
TEST_CASE("[ADSREnvelope] Hold")
|
||||
|
|
@ -143,14 +142,14 @@ TEST_CASE("[ADSREnvelope] Hold")
|
|||
envelope.reset(2, 4, 0.5, 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 };
|
||||
for (auto& out: output)
|
||||
for (auto& out : output)
|
||||
out = envelope.getNextValue();
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
|
||||
envelope.reset(2, 4, 0.5, 2, 2, 2);
|
||||
absl::c_fill(output, -1.0);
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
}
|
||||
|
||||
TEST_CASE("[ADSREnvelope] Hold with release")
|
||||
|
|
@ -159,16 +158,16 @@ TEST_CASE("[ADSREnvelope] Hold with release")
|
|||
envelope.reset(2, 4, 0.5, 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 };
|
||||
for (auto& out: 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 };
|
||||
for (auto& out : output)
|
||||
out = envelope.getNextValue();
|
||||
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
envelope.reset(2, 4, 0.5, 2, 2, 2);
|
||||
envelope.startRelease(8);
|
||||
absl::c_fill(output, -1.0);
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
}
|
||||
|
||||
TEST_CASE("[ADSREnvelope] Hold with release 2")
|
||||
|
|
@ -178,12 +177,12 @@ TEST_CASE("[ADSREnvelope] Hold with release 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 };
|
||||
for (auto& out: output)
|
||||
for (auto& out : output)
|
||||
out = envelope.getNextValue();
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
envelope.reset(2, 4, 0.5, 2, 2, 2);
|
||||
envelope.startRelease(4);
|
||||
absl::c_fill(output, -1.0);
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( approxEqual<float>(output, expected) );
|
||||
REQUIRE(approxEqual<float>(output, expected));
|
||||
}
|
||||
210
tests/FilesT.cpp
210
tests/FilesT.cpp
|
|
@ -1,5 +1,5 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "../sources/Synth.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <filesystem>
|
||||
using namespace Catch::literals;
|
||||
|
||||
|
|
@ -7,76 +7,76 @@ TEST_CASE("[Files] Single region (regions_one.sfz)")
|
|||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Regions/regions_one.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 1 );
|
||||
REQUIRE( synth.getRegionView(0)->sample == "dummy.wav" );
|
||||
REQUIRE(synth.getNumRegions() == 1);
|
||||
REQUIRE(synth.getRegionView(0)->sample == "dummy.wav");
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Multiple regions (regions_many.sfz)")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Regions/regions_many.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 3 );
|
||||
REQUIRE( synth.getRegionView(0)->sample == "dummy.wav" );
|
||||
REQUIRE( synth.getRegionView(1)->sample == "dummy.1.wav" );
|
||||
REQUIRE( synth.getRegionView(2)->sample == "dummy.2.wav" );
|
||||
REQUIRE(synth.getNumRegions() == 3);
|
||||
REQUIRE(synth.getRegionView(0)->sample == "dummy.wav");
|
||||
REQUIRE(synth.getRegionView(1)->sample == "dummy.1.wav");
|
||||
REQUIRE(synth.getRegionView(2)->sample == "dummy.2.wav");
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Basic opcodes (regions_opcodes.sfz)")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Regions/regions_opcodes.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 1 );
|
||||
REQUIRE( synth.getRegionView(0)->channelRange == Range<uint8_t>(2, 14) );
|
||||
REQUIRE(synth.getNumRegions() == 1);
|
||||
REQUIRE(synth.getRegionView(0)->channelRange == Range<uint8_t>(2, 14));
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Underscore opcodes (underscore_opcodes.sfz)")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Regions/underscore_opcodes.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 1 );
|
||||
REQUIRE( synth.getRegionView(0)->loopMode == SfzLoopMode::loop_sustain );
|
||||
REQUIRE(synth.getNumRegions() == 1);
|
||||
REQUIRE(synth.getRegionView(0)->loopMode == SfzLoopMode::loop_sustain);
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Local include")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/root_local.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 1 );
|
||||
REQUIRE( synth.getRegionView(0)->sample == "dummy.wav" );
|
||||
REQUIRE(synth.getNumRegions() == 1);
|
||||
REQUIRE(synth.getRegionView(0)->sample == "dummy.wav");
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Multiple includes")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/multiple_includes.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 2 );
|
||||
REQUIRE( synth.getRegionView(0)->sample == "dummy.wav" );
|
||||
REQUIRE( synth.getRegionView(1)->sample == "dummy2.wav" );
|
||||
REQUIRE(synth.getNumRegions() == 2);
|
||||
REQUIRE(synth.getRegionView(0)->sample == "dummy.wav");
|
||||
REQUIRE(synth.getRegionView(1)->sample == "dummy2.wav");
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Multiple includes with comments")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/multiple_includes_with_comments.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 2 );
|
||||
REQUIRE( synth.getRegionView(0)->sample == "dummy.wav" );
|
||||
REQUIRE( synth.getRegionView(1)->sample == "dummy2.wav" );
|
||||
REQUIRE(synth.getNumRegions() == 2);
|
||||
REQUIRE(synth.getRegionView(0)->sample == "dummy.wav");
|
||||
REQUIRE(synth.getRegionView(1)->sample == "dummy2.wav");
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Subdir include")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/root_subdir.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 1 );
|
||||
REQUIRE( synth.getRegionView(0)->sample == "dummy_subdir.wav" );
|
||||
REQUIRE(synth.getNumRegions() == 1);
|
||||
REQUIRE(synth.getRegionView(0)->sample == "dummy_subdir.wav");
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Subdir include Win")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/root_subdir_win.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 1 );
|
||||
REQUIRE( synth.getRegionView(0)->sample == "dummy_subdir.wav" );
|
||||
REQUIRE(synth.getNumRegions() == 1);
|
||||
REQUIRE(synth.getRegionView(0)->sample == "dummy_subdir.wav");
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Recursive include (with include guard)")
|
||||
|
|
@ -84,9 +84,9 @@ TEST_CASE("[Files] Recursive include (with include guard)")
|
|||
sfz::Synth synth;
|
||||
synth.enableRecursiveIncludeGuard();
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/root_recursive.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 2 );
|
||||
REQUIRE( synth.getRegionView(0)->sample == "dummy_recursive2.wav" );
|
||||
REQUIRE( synth.getRegionView(1)->sample == "dummy_recursive1.wav" );
|
||||
REQUIRE(synth.getNumRegions() == 2);
|
||||
REQUIRE(synth.getRegionView(0)->sample == "dummy_recursive2.wav");
|
||||
REQUIRE(synth.getRegionView(1)->sample == "dummy_recursive1.wav");
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Include loops (with include guard)")
|
||||
|
|
@ -94,88 +94,85 @@ TEST_CASE("[Files] Include loops (with include guard)")
|
|||
sfz::Synth synth;
|
||||
synth.enableRecursiveIncludeGuard();
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/Includes/root_loop.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 2 );
|
||||
REQUIRE( synth.getRegionView(0)->sample == "dummy_loop2.wav" );
|
||||
REQUIRE( synth.getRegionView(1)->sample == "dummy_loop1.wav" );
|
||||
REQUIRE(synth.getNumRegions() == 2);
|
||||
REQUIRE(synth.getRegionView(0)->sample == "dummy_loop2.wav");
|
||||
REQUIRE(synth.getRegionView(1)->sample == "dummy_loop1.wav");
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Define test")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/defines.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 3 );
|
||||
REQUIRE( synth.getRegionView(0)->keyRange == Range<uint8_t>(36, 36) );
|
||||
REQUIRE( synth.getRegionView(1)->keyRange == Range<uint8_t>(38, 38) );
|
||||
REQUIRE( synth.getRegionView(2)->keyRange == Range<uint8_t>(42, 42) );
|
||||
REQUIRE(synth.getNumRegions() == 3);
|
||||
REQUIRE(synth.getRegionView(0)->keyRange == Range<uint8_t>(36, 36));
|
||||
REQUIRE(synth.getRegionView(1)->keyRange == Range<uint8_t>(38, 38));
|
||||
REQUIRE(synth.getRegionView(2)->keyRange == Range<uint8_t>(42, 42));
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("[Files] Group from AVL")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/groups_avl.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 5 );
|
||||
for (int i = 0; i < synth.getNumRegions(); ++i)
|
||||
{
|
||||
REQUIRE( synth.getRegionView(i)->volume == 6.0f );
|
||||
REQUIRE( synth.getRegionView(i)->keyRange == Range<uint8_t>(36, 36) );
|
||||
REQUIRE(synth.getNumRegions() == 5);
|
||||
for (int i = 0; i < synth.getNumRegions(); ++i) {
|
||||
REQUIRE(synth.getRegionView(i)->volume == 6.0f);
|
||||
REQUIRE(synth.getRegionView(i)->keyRange == Range<uint8_t>(36, 36));
|
||||
}
|
||||
REQUIRE( synth.getRegionView(0)->velocityRange == Range<uint8_t>(1, 26) );
|
||||
REQUIRE( synth.getRegionView(1)->velocityRange == Range<uint8_t>(27, 52) );
|
||||
REQUIRE( synth.getRegionView(2)->velocityRange == Range<uint8_t>(53, 77) );
|
||||
REQUIRE( synth.getRegionView(3)->velocityRange == Range<uint8_t>(78, 102) );
|
||||
REQUIRE( synth.getRegionView(4)->velocityRange == Range<uint8_t>(103, 127) );
|
||||
REQUIRE(synth.getRegionView(0)->velocityRange == Range<uint8_t>(1, 26));
|
||||
REQUIRE(synth.getRegionView(1)->velocityRange == Range<uint8_t>(27, 52));
|
||||
REQUIRE(synth.getRegionView(2)->velocityRange == Range<uint8_t>(53, 77));
|
||||
REQUIRE(synth.getRegionView(3)->velocityRange == Range<uint8_t>(78, 102));
|
||||
REQUIRE(synth.getRegionView(4)->velocityRange == Range<uint8_t>(103, 127));
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Full hierarchy")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/basic_hierarchy.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 8 );
|
||||
for (int i = 0; i < synth.getNumRegions(); ++i)
|
||||
{
|
||||
REQUIRE( synth.getRegionView(i)->width == 40.0f );
|
||||
REQUIRE(synth.getNumRegions() == 8);
|
||||
for (int i = 0; i < synth.getNumRegions(); ++i) {
|
||||
REQUIRE(synth.getRegionView(i)->width == 40.0f);
|
||||
}
|
||||
REQUIRE( synth.getRegionView(0)->pan == 30.0f );
|
||||
REQUIRE( synth.getRegionView(0)->delay == 67 );
|
||||
REQUIRE( synth.getRegionView(0)->keyRange == Range<uint8_t>(60, 60) );
|
||||
REQUIRE(synth.getRegionView(0)->pan == 30.0f);
|
||||
REQUIRE(synth.getRegionView(0)->delay == 67);
|
||||
REQUIRE(synth.getRegionView(0)->keyRange == Range<uint8_t>(60, 60));
|
||||
|
||||
REQUIRE( synth.getRegionView(1)->pan == 30.0f );
|
||||
REQUIRE( synth.getRegionView(1)->delay == 67 );
|
||||
REQUIRE( synth.getRegionView(1)->keyRange == Range<uint8_t>(61, 61) );
|
||||
REQUIRE(synth.getRegionView(1)->pan == 30.0f);
|
||||
REQUIRE(synth.getRegionView(1)->delay == 67);
|
||||
REQUIRE(synth.getRegionView(1)->keyRange == Range<uint8_t>(61, 61));
|
||||
|
||||
REQUIRE( synth.getRegionView(2)->pan == 30.0f );
|
||||
REQUIRE( synth.getRegionView(2)->delay == 56 );
|
||||
REQUIRE( synth.getRegionView(2)->keyRange == Range<uint8_t>(50, 50) );
|
||||
REQUIRE(synth.getRegionView(2)->pan == 30.0f);
|
||||
REQUIRE(synth.getRegionView(2)->delay == 56);
|
||||
REQUIRE(synth.getRegionView(2)->keyRange == Range<uint8_t>(50, 50));
|
||||
|
||||
REQUIRE( synth.getRegionView(3)->pan == 30.0f );
|
||||
REQUIRE( synth.getRegionView(3)->delay == 56 );
|
||||
REQUIRE( synth.getRegionView(3)->keyRange == Range<uint8_t>(51, 51) );
|
||||
REQUIRE(synth.getRegionView(3)->pan == 30.0f);
|
||||
REQUIRE(synth.getRegionView(3)->delay == 56);
|
||||
REQUIRE(synth.getRegionView(3)->keyRange == Range<uint8_t>(51, 51));
|
||||
|
||||
REQUIRE( synth.getRegionView(4)->pan == -10.0f );
|
||||
REQUIRE( synth.getRegionView(4)->delay == 47 );
|
||||
REQUIRE( synth.getRegionView(4)->keyRange == Range<uint8_t>(40, 40) );
|
||||
REQUIRE(synth.getRegionView(4)->pan == -10.0f);
|
||||
REQUIRE(synth.getRegionView(4)->delay == 47);
|
||||
REQUIRE(synth.getRegionView(4)->keyRange == Range<uint8_t>(40, 40));
|
||||
|
||||
REQUIRE( synth.getRegionView(5)->pan == -10.0f );
|
||||
REQUIRE( synth.getRegionView(5)->delay == 47 );
|
||||
REQUIRE( synth.getRegionView(5)->keyRange == Range<uint8_t>(41, 41) );
|
||||
REQUIRE(synth.getRegionView(5)->pan == -10.0f);
|
||||
REQUIRE(synth.getRegionView(5)->delay == 47);
|
||||
REQUIRE(synth.getRegionView(5)->keyRange == Range<uint8_t>(41, 41));
|
||||
|
||||
REQUIRE( synth.getRegionView(6)->pan == -10.0f );
|
||||
REQUIRE( synth.getRegionView(6)->delay == 36 );
|
||||
REQUIRE( synth.getRegionView(6)->keyRange == Range<uint8_t>(30, 30) );
|
||||
REQUIRE(synth.getRegionView(6)->pan == -10.0f);
|
||||
REQUIRE(synth.getRegionView(6)->delay == 36);
|
||||
REQUIRE(synth.getRegionView(6)->keyRange == Range<uint8_t>(30, 30));
|
||||
|
||||
REQUIRE( synth.getRegionView(7)->pan == -10.0f );
|
||||
REQUIRE( synth.getRegionView(7)->delay == 36 );
|
||||
REQUIRE( synth.getRegionView(7)->keyRange == Range<uint8_t>(31, 31) );
|
||||
REQUIRE(synth.getRegionView(7)->pan == -10.0f);
|
||||
REQUIRE(synth.getRegionView(7)->delay == 36);
|
||||
REQUIRE(synth.getRegionView(7)->keyRange == Range<uint8_t>(31, 31));
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Reloading files")
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/basic_hierarchy.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 8 );
|
||||
REQUIRE(synth.getNumRegions() == 8);
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/basic_hierarchy.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 8 );
|
||||
REQUIRE(synth.getNumRegions() == 8);
|
||||
}
|
||||
|
||||
TEST_CASE("[Files] Full hierarchy with antislashes")
|
||||
|
|
@ -183,29 +180,29 @@ TEST_CASE("[Files] Full hierarchy with antislashes")
|
|||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/basic_hierarchy.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 8 );
|
||||
REQUIRE( synth.getRegionView(0)->sample == "Regions/dummy.wav" );
|
||||
REQUIRE( synth.getRegionView(1)->sample == "Regions/dummy.1.wav" );
|
||||
REQUIRE( synth.getRegionView(2)->sample == "Regions/dummy.wav" );
|
||||
REQUIRE( synth.getRegionView(3)->sample == "Regions/dummy.1.wav" );
|
||||
REQUIRE( synth.getRegionView(4)->sample == "Regions/dummy.wav" );
|
||||
REQUIRE( synth.getRegionView(5)->sample == "Regions/dummy.1.wav" );
|
||||
REQUIRE( synth.getRegionView(6)->sample == "Regions/dummy.wav" );
|
||||
REQUIRE( synth.getRegionView(7)->sample == "Regions/dummy.1.wav" );
|
||||
REQUIRE(synth.getNumRegions() == 8);
|
||||
REQUIRE(synth.getRegionView(0)->sample == "Regions/dummy.wav");
|
||||
REQUIRE(synth.getRegionView(1)->sample == "Regions/dummy.1.wav");
|
||||
REQUIRE(synth.getRegionView(2)->sample == "Regions/dummy.wav");
|
||||
REQUIRE(synth.getRegionView(3)->sample == "Regions/dummy.1.wav");
|
||||
REQUIRE(synth.getRegionView(4)->sample == "Regions/dummy.wav");
|
||||
REQUIRE(synth.getRegionView(5)->sample == "Regions/dummy.1.wav");
|
||||
REQUIRE(synth.getRegionView(6)->sample == "Regions/dummy.wav");
|
||||
REQUIRE(synth.getRegionView(7)->sample == "Regions/dummy.1.wav");
|
||||
}
|
||||
|
||||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/basic_hierarchy_antislash.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 8 );
|
||||
REQUIRE( synth.getRegionView(0)->sample == "Regions/dummy.wav" );
|
||||
REQUIRE( synth.getRegionView(1)->sample == "Regions/dummy.1.wav" );
|
||||
REQUIRE( synth.getRegionView(2)->sample == "Regions/dummy.wav" );
|
||||
REQUIRE( synth.getRegionView(3)->sample == "Regions/dummy.1.wav" );
|
||||
REQUIRE( synth.getRegionView(4)->sample == "Regions/dummy.wav" );
|
||||
REQUIRE( synth.getRegionView(5)->sample == "Regions/dummy.1.wav" );
|
||||
REQUIRE( synth.getRegionView(6)->sample == "Regions/dummy.wav" );
|
||||
REQUIRE( synth.getRegionView(7)->sample == "Regions/dummy.1.wav" );
|
||||
REQUIRE(synth.getNumRegions() == 8);
|
||||
REQUIRE(synth.getRegionView(0)->sample == "Regions/dummy.wav");
|
||||
REQUIRE(synth.getRegionView(1)->sample == "Regions/dummy.1.wav");
|
||||
REQUIRE(synth.getRegionView(2)->sample == "Regions/dummy.wav");
|
||||
REQUIRE(synth.getRegionView(3)->sample == "Regions/dummy.1.wav");
|
||||
REQUIRE(synth.getRegionView(4)->sample == "Regions/dummy.wav");
|
||||
REQUIRE(synth.getRegionView(5)->sample == "Regions/dummy.1.wav");
|
||||
REQUIRE(synth.getRegionView(6)->sample == "Regions/dummy.wav");
|
||||
REQUIRE(synth.getRegionView(7)->sample == "Regions/dummy.1.wav");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -213,22 +210,21 @@ TEST_CASE("[Files] Pizz basic")
|
|||
{
|
||||
sfz::Synth synth;
|
||||
synth.loadSfzFile(std::filesystem::current_path() / "tests/TestFiles/SpecificBugs/MeatBassPizz/Programs/pizz.sfz");
|
||||
REQUIRE( synth.getNumRegions() == 4 );
|
||||
for (int i = 0; i < synth.getNumRegions(); ++i)
|
||||
{
|
||||
REQUIRE( synth.getRegionView(i)->keyRange == Range<uint8_t>(12, 22) );
|
||||
REQUIRE( synth.getRegionView(i)->velocityRange == Range<uint8_t>(97, 127) );
|
||||
REQUIRE( synth.getRegionView(i)->pitchKeycenter == 21 );
|
||||
REQUIRE( synth.getRegionView(i)->ccConditions.getWithDefault(107) == Range<uint8_t>(0, 13) );
|
||||
REQUIRE(synth.getNumRegions() == 4);
|
||||
for (int i = 0; i < synth.getNumRegions(); ++i) {
|
||||
REQUIRE(synth.getRegionView(i)->keyRange == Range<uint8_t>(12, 22));
|
||||
REQUIRE(synth.getRegionView(i)->velocityRange == Range<uint8_t>(97, 127));
|
||||
REQUIRE(synth.getRegionView(i)->pitchKeycenter == 21);
|
||||
REQUIRE(synth.getRegionView(i)->ccConditions.getWithDefault(107) == Range<uint8_t>(0, 13));
|
||||
}
|
||||
REQUIRE( synth.getRegionView(0)->randRange == Range<float>(0, 0.25) );
|
||||
REQUIRE( synth.getRegionView(1)->randRange == Range<float>(0.25, 0.5) );
|
||||
REQUIRE( synth.getRegionView(2)->randRange == Range<float>(0.5, 0.75) );
|
||||
REQUIRE( synth.getRegionView(3)->randRange == Range<float>(0.75, 1.0) );
|
||||
REQUIRE( synth.getRegionView(0)->sample == R"(../Samples/pizz/a0_vl4_rr1.wav)" );
|
||||
REQUIRE( synth.getRegionView(1)->sample == R"(../Samples/pizz/a0_vl4_rr2.wav)" );
|
||||
REQUIRE( synth.getRegionView(2)->sample == R"(../Samples/pizz/a0_vl4_rr3.wav)" );
|
||||
REQUIRE( synth.getRegionView(3)->sample == R"(../Samples/pizz/a0_vl4_rr4.wav)" );
|
||||
REQUIRE(synth.getRegionView(0)->randRange == Range<float>(0, 0.25));
|
||||
REQUIRE(synth.getRegionView(1)->randRange == Range<float>(0.25, 0.5));
|
||||
REQUIRE(synth.getRegionView(2)->randRange == Range<float>(0.5, 0.75));
|
||||
REQUIRE(synth.getRegionView(3)->randRange == Range<float>(0.75, 1.0));
|
||||
REQUIRE(synth.getRegionView(0)->sample == R"(../Samples/pizz/a0_vl4_rr1.wav)");
|
||||
REQUIRE(synth.getRegionView(1)->sample == R"(../Samples/pizz/a0_vl4_rr2.wav)");
|
||||
REQUIRE(synth.getRegionView(2)->sample == R"(../Samples/pizz/a0_vl4_rr3.wav)");
|
||||
REQUIRE(synth.getRegionView(3)->sample == R"(../Samples/pizz/a0_vl4_rr4.wav)");
|
||||
}
|
||||
|
||||
// TEST_CASE("[Files] sw_default")
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "../sources/Helpers.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <string_view>
|
||||
using namespace Catch::literals;
|
||||
using namespace std::literals::string_view_literals;
|
||||
using namespace std::literals::string_view_literals;
|
||||
|
||||
TEST_CASE("[Helpers] trimInPlace")
|
||||
{
|
||||
|
|
@ -10,28 +10,28 @@ TEST_CASE("[Helpers] trimInPlace")
|
|||
{
|
||||
auto input { "view"sv };
|
||||
trimInPlace(input);
|
||||
REQUIRE( input == "view"sv );
|
||||
REQUIRE(input == "view"sv);
|
||||
}
|
||||
|
||||
SECTION("Trim spaces")
|
||||
{
|
||||
auto input { " view "sv };
|
||||
trimInPlace(input);
|
||||
REQUIRE( input == "view"sv );
|
||||
REQUIRE(input == "view"sv);
|
||||
}
|
||||
|
||||
SECTION("Trim other chars")
|
||||
{
|
||||
auto input { " \tview \t"sv };
|
||||
trimInPlace(input);
|
||||
REQUIRE( input == "view"sv );
|
||||
REQUIRE(input == "view"sv);
|
||||
}
|
||||
|
||||
SECTION("Empty view")
|
||||
{
|
||||
auto input { " "sv };
|
||||
trimInPlace(input);
|
||||
REQUIRE( input.empty() );
|
||||
REQUIRE(input.empty());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -40,24 +40,24 @@ TEST_CASE("[Helpers] trim")
|
|||
SECTION("Trim nothing")
|
||||
{
|
||||
auto input { "view"sv };
|
||||
REQUIRE( trim(input) == "view"sv );
|
||||
REQUIRE(trim(input) == "view"sv);
|
||||
}
|
||||
|
||||
SECTION("Trim spaces")
|
||||
{
|
||||
auto input { " view "sv };
|
||||
REQUIRE( trim(input) == "view"sv );
|
||||
REQUIRE(trim(input) == "view"sv);
|
||||
}
|
||||
|
||||
SECTION("Trim other chars")
|
||||
{
|
||||
auto input { " \tview \t"sv };
|
||||
REQUIRE( trim(input) == "view"sv );
|
||||
REQUIRE(trim(input) == "view"sv);
|
||||
}
|
||||
|
||||
SECTION("Empty view")
|
||||
{
|
||||
auto input { " "sv };
|
||||
REQUIRE( trim(input).empty() );
|
||||
REQUIRE(trim(input).empty());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +1,20 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "../sources/LinearEnvelope.h"
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <absl/types/span.h>
|
||||
#include "catch2/catch.hpp"
|
||||
#include <absl/algorithm/container.h>
|
||||
#include <absl/types/span.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
using namespace Catch::literals;
|
||||
|
||||
template<class Type>
|
||||
inline bool approxEqual(absl::Span<const Type> lhs, absl::Span<const Type> rhs, Type eps=1e-3)
|
||||
template <class Type>
|
||||
inline bool approxEqual(absl::Span<const Type> lhs, absl::Span<const Type> rhs, Type eps = 1e-3)
|
||||
{
|
||||
if (lhs.size() != rhs.size())
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < rhs.size(); ++i)
|
||||
if (rhs[i] != Approx(lhs[i]).epsilon(eps))
|
||||
{
|
||||
if (rhs[i] != Approx(lhs[i]).epsilon(eps)) {
|
||||
std::cerr << lhs[i] << " != " << rhs[i] << " at index " << i << '\n';
|
||||
return false;
|
||||
}
|
||||
|
|
@ -29,7 +28,7 @@ TEST_CASE("[LinearEnvelope] Basic state")
|
|||
std::array<float, 5> output;
|
||||
std::array<float, 5> expected { 0.0, 0.0, 0.0, 0.0, 0.0 };
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[LinearEnvelope] Basic event")
|
||||
|
|
@ -39,7 +38,7 @@ TEST_CASE("[LinearEnvelope] Basic event")
|
|||
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 };
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[LinearEnvelope] 2 events, close")
|
||||
|
|
@ -50,7 +49,7 @@ TEST_CASE("[LinearEnvelope] 2 events, close")
|
|||
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 };
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[LinearEnvelope] 2 events, far")
|
||||
|
|
@ -61,7 +60,7 @@ TEST_CASE("[LinearEnvelope] 2 events, far")
|
|||
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 };
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[LinearEnvelope] 2 events, reversed")
|
||||
|
|
@ -72,7 +71,7 @@ TEST_CASE("[LinearEnvelope] 2 events, reversed")
|
|||
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 };
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[LinearEnvelope] 3 events, overlapping")
|
||||
|
|
@ -84,7 +83,7 @@ TEST_CASE("[LinearEnvelope] 3 events, overlapping")
|
|||
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 };
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[LinearEnvelope] 3 events, out of block")
|
||||
|
|
@ -96,7 +95,7 @@ TEST_CASE("[LinearEnvelope] 3 events, out of block")
|
|||
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 };
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[LinearEnvelope] 3 events, out of block, with another block call")
|
||||
|
|
@ -109,7 +108,7 @@ TEST_CASE("[LinearEnvelope] 3 events, out of block, with another block call")
|
|||
std::array<float, 8> expected { 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 };
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[LinearEnvelope] 2 events, with another block call")
|
||||
|
|
@ -121,17 +120,17 @@ TEST_CASE("[LinearEnvelope] 2 events, with another block call")
|
|||
std::array<float, 8> expected { 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 };
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[LinearEnvelope] 2 events, function")
|
||||
{
|
||||
sfz::LinearEnvelope<float> envelope;
|
||||
envelope.setFunction([](auto x) { return 2*x; });
|
||||
envelope.setFunction([](auto x) { return 2 * x; });
|
||||
envelope.registerEvent(2, 1.0);
|
||||
envelope.registerEvent(6, 2.0);
|
||||
std::array<float, 8> output;
|
||||
std::array<float, 8> expected { 1, 2, 2.5, 3, 3.5, 4.0, 4.0, 4.0 };
|
||||
envelope.getBlock(absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
|
@ -1,21 +1,20 @@
|
|||
#include "../sources/OnePoleFilter.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include "cnpy.h"
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
#include <absl/types/span.h>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
using namespace Catch::literals;
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
inline bool approxEqual(const std::vector<Type>& lhs, const std::vector<Type>& rhs)
|
||||
{
|
||||
if (lhs.size() != rhs.size())
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < rhs.size(); ++i)
|
||||
if (lhs[i] != Approx(rhs[i]).epsilon(1e-3))
|
||||
{
|
||||
if (lhs[i] != Approx(rhs[i]).epsilon(1e-3)) {
|
||||
std::cerr << lhs[i] << " != " << rhs[i] << " at index " << i << '\n';
|
||||
return false;
|
||||
}
|
||||
|
|
@ -23,74 +22,74 @@ inline bool approxEqual(const std::vector<Type>& lhs, const std::vector<Type>& r
|
|||
return true;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
void testLowpass(const std::filesystem::path& inputNumpyFile, const std::filesystem::path& outputNumpyFile, Type gain)
|
||||
{
|
||||
const auto input = cnpy::npy_load(inputNumpyFile.string());
|
||||
REQUIRE( input.word_size == 8 );
|
||||
REQUIRE(input.word_size == 8);
|
||||
const auto inputSpan = absl::MakeSpan(input.data<double>(), input.shape[0]);
|
||||
|
||||
const auto output = cnpy::npy_load(outputNumpyFile.string());
|
||||
REQUIRE( output.word_size == 8 );
|
||||
REQUIRE(output.word_size == 8);
|
||||
const auto outputSpan = absl::MakeSpan(output.data<double>(), output.shape[0]);
|
||||
auto size = std::min(outputSpan.size(), inputSpan.size());
|
||||
REQUIRE( size > 0 );
|
||||
REQUIRE(size > 0);
|
||||
|
||||
std::vector<Type> inputData;
|
||||
std::vector<Type> expectedData;
|
||||
inputData.reserve(size);
|
||||
expectedData.reserve(size);
|
||||
for (auto& data: inputSpan)
|
||||
for (auto& data : inputSpan)
|
||||
inputData.push_back(static_cast<Type>(data));
|
||||
for (auto& data: outputSpan)
|
||||
for (auto& data : outputSpan)
|
||||
expectedData.push_back(static_cast<Type>(data));
|
||||
|
||||
|
||||
OnePoleFilter filter { gain };
|
||||
std::vector<Type> outputData (size);
|
||||
std::vector<Type> outputData(size);
|
||||
filter.processLowpass(inputData, absl::MakeSpan(outputData));
|
||||
REQUIRE( approxEqual(outputData, expectedData) );
|
||||
REQUIRE(approxEqual(outputData, expectedData));
|
||||
|
||||
filter.reset();
|
||||
std::fill(outputData.begin(), outputData.end(), 0.0);
|
||||
std::vector<Type> gains(size);
|
||||
std::fill(gains.begin(), gains.end(), gain);
|
||||
filter.processLowpassVariableGain(inputData, absl::MakeSpan(outputData), gains);
|
||||
REQUIRE( approxEqual(outputData, expectedData) );
|
||||
REQUIRE(approxEqual(outputData, expectedData));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
template <class Type>
|
||||
void testHighpass(const std::filesystem::path& inputNumpyFile, const std::filesystem::path& outputNumpyFile, Type gain)
|
||||
{
|
||||
const auto input = cnpy::npy_load(inputNumpyFile.string());
|
||||
REQUIRE( input.word_size == 8 );
|
||||
REQUIRE(input.word_size == 8);
|
||||
const auto inputSpan = absl::MakeSpan(input.data<double>(), input.shape[0]);
|
||||
|
||||
const auto output = cnpy::npy_load(outputNumpyFile.string());
|
||||
REQUIRE( output.word_size == 8 );
|
||||
REQUIRE(output.word_size == 8);
|
||||
const auto outputSpan = absl::MakeSpan(output.data<double>(), output.shape[0]);
|
||||
auto size = std::min(outputSpan.size(), inputSpan.size());
|
||||
REQUIRE( size > 0 );
|
||||
REQUIRE(size > 0);
|
||||
|
||||
std::vector<Type> inputData;
|
||||
std::vector<Type> expectedData;
|
||||
inputData.reserve(size);
|
||||
expectedData.reserve(size);
|
||||
for (auto& data: inputSpan)
|
||||
for (auto& data : inputSpan)
|
||||
inputData.push_back(static_cast<Type>(data));
|
||||
for (auto& data: outputSpan)
|
||||
for (auto& data : outputSpan)
|
||||
expectedData.push_back(static_cast<Type>(data));
|
||||
|
||||
|
||||
OnePoleFilter filter { gain };
|
||||
std::vector<Type> outputData (size);
|
||||
std::vector<Type> outputData(size);
|
||||
filter.processHighpass(inputData, absl::MakeSpan(outputData));
|
||||
REQUIRE( approxEqual(outputData, expectedData) );
|
||||
REQUIRE(approxEqual(outputData, expectedData));
|
||||
|
||||
filter.reset();
|
||||
std::fill(outputData.begin(), outputData.end(), 0.0);
|
||||
std::vector<Type> gains(size);
|
||||
std::fill(gains.begin(), gains.end(), gain);
|
||||
filter.processHighpassVariableGain(inputData, absl::MakeSpan(outputData), gains);
|
||||
REQUIRE( approxEqual(outputData, expectedData) );
|
||||
REQUIRE(approxEqual(outputData, expectedData));
|
||||
}
|
||||
|
||||
TEST_CASE("[OnePoleFilter] Lowpass Float")
|
||||
|
|
@ -98,28 +97,23 @@ TEST_CASE("[OnePoleFilter] Lowpass Float")
|
|||
testLowpass<float>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.1.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.1.npy",
|
||||
0.1f
|
||||
);
|
||||
0.1f);
|
||||
testLowpass<float>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.3.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.3.npy",
|
||||
0.3f
|
||||
);
|
||||
0.3f);
|
||||
testLowpass<float>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.5.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.5.npy",
|
||||
0.5f
|
||||
);
|
||||
0.5f);
|
||||
testLowpass<float>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.7.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.7.npy",
|
||||
0.7f
|
||||
);
|
||||
0.7f);
|
||||
testLowpass<float>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.9.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.9.npy",
|
||||
0.9f
|
||||
);
|
||||
0.9f);
|
||||
}
|
||||
|
||||
TEST_CASE("[OnePoleFilter] Lowpass Double")
|
||||
|
|
@ -127,28 +121,23 @@ TEST_CASE("[OnePoleFilter] Lowpass Double")
|
|||
testLowpass<double>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.1.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.1.npy",
|
||||
0.1f
|
||||
);
|
||||
0.1f);
|
||||
testLowpass<double>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.3.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.3.npy",
|
||||
0.3f
|
||||
);
|
||||
0.3f);
|
||||
testLowpass<double>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.5.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.5.npy",
|
||||
0.5f
|
||||
);
|
||||
0.5f);
|
||||
testLowpass<double>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.7.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.7.npy",
|
||||
0.7f
|
||||
);
|
||||
0.7f);
|
||||
testLowpass<double>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.9.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_low_gain_0.9.npy",
|
||||
0.9f
|
||||
);
|
||||
0.9f);
|
||||
}
|
||||
|
||||
TEST_CASE("[OnePoleFilter] Highpass Float")
|
||||
|
|
@ -156,28 +145,23 @@ TEST_CASE("[OnePoleFilter] Highpass Float")
|
|||
testHighpass<float>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.1.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.1.npy",
|
||||
0.1f
|
||||
);
|
||||
0.1f);
|
||||
testHighpass<float>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.3.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.3.npy",
|
||||
0.3f
|
||||
);
|
||||
0.3f);
|
||||
testHighpass<float>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.5.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.5.npy",
|
||||
0.5f
|
||||
);
|
||||
0.5f);
|
||||
testHighpass<float>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.7.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.7.npy",
|
||||
0.7f
|
||||
);
|
||||
0.7f);
|
||||
testHighpass<float>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.9.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.9.npy",
|
||||
0.9f
|
||||
);
|
||||
0.9f);
|
||||
}
|
||||
|
||||
TEST_CASE("[OnePoleFilter] Highpass Double")
|
||||
|
|
@ -185,26 +169,21 @@ TEST_CASE("[OnePoleFilter] Highpass Double")
|
|||
testHighpass<double>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.1.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.1.npy",
|
||||
0.1f
|
||||
);
|
||||
0.1f);
|
||||
testHighpass<double>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.3.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.3.npy",
|
||||
0.3f
|
||||
);
|
||||
0.3f);
|
||||
testHighpass<double>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.5.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.5.npy",
|
||||
0.5f
|
||||
);
|
||||
0.5f);
|
||||
testHighpass<double>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.7.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.7.npy",
|
||||
0.7f
|
||||
);
|
||||
0.7f);
|
||||
testHighpass<double>(
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_input_gain_0.9.npy",
|
||||
std::filesystem::current_path() / "tests/TestFiles/OnePoleFilter/OPF_high_gain_0.9.npy",
|
||||
0.9f
|
||||
);
|
||||
0.9f);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,62 +1,62 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "../sources/Region.h"
|
||||
#include "catch2/catch.hpp"
|
||||
using namespace Catch::literals;
|
||||
|
||||
TEST_CASE("[Opcode] Construction")
|
||||
{
|
||||
SECTION("Normal construction")
|
||||
{
|
||||
sfz::Opcode opcode { "sample", "dummy"};
|
||||
REQUIRE( opcode.opcode == "sample" );
|
||||
REQUIRE( opcode.value == "dummy" );
|
||||
REQUIRE( !opcode.parameter );
|
||||
sfz::Opcode opcode { "sample", "dummy" };
|
||||
REQUIRE(opcode.opcode == "sample");
|
||||
REQUIRE(opcode.value == "dummy");
|
||||
REQUIRE(!opcode.parameter);
|
||||
}
|
||||
|
||||
SECTION("Normal construction with underscore")
|
||||
{
|
||||
sfz::Opcode opcode { "sample_underscore", "dummy"};
|
||||
REQUIRE( opcode.opcode == "sample_underscore" );
|
||||
REQUIRE( opcode.value == "dummy" );
|
||||
REQUIRE( !opcode.parameter );
|
||||
sfz::Opcode opcode { "sample_underscore", "dummy" };
|
||||
REQUIRE(opcode.opcode == "sample_underscore");
|
||||
REQUIRE(opcode.value == "dummy");
|
||||
REQUIRE(!opcode.parameter);
|
||||
}
|
||||
|
||||
SECTION("Parameterized opcode")
|
||||
{
|
||||
sfz::Opcode opcode { "sample123", "dummy"};
|
||||
REQUIRE( opcode.opcode == "sample" );
|
||||
REQUIRE( opcode.value == "dummy" );
|
||||
REQUIRE( opcode.parameter );
|
||||
REQUIRE( *opcode.parameter == 123 );
|
||||
sfz::Opcode opcode { "sample123", "dummy" };
|
||||
REQUIRE(opcode.opcode == "sample");
|
||||
REQUIRE(opcode.value == "dummy");
|
||||
REQUIRE(opcode.parameter);
|
||||
REQUIRE(*opcode.parameter == 123);
|
||||
}
|
||||
|
||||
SECTION("Parameterized opcode with underscore")
|
||||
{
|
||||
sfz::Opcode opcode { "sample_underscore123", "dummy"};
|
||||
REQUIRE( opcode.opcode == "sample_underscore" );
|
||||
REQUIRE( opcode.value == "dummy" );
|
||||
REQUIRE( opcode.parameter );
|
||||
REQUIRE( *opcode.parameter == 123 );
|
||||
sfz::Opcode opcode { "sample_underscore123", "dummy" };
|
||||
REQUIRE(opcode.opcode == "sample_underscore");
|
||||
REQUIRE(opcode.value == "dummy");
|
||||
REQUIRE(opcode.parameter);
|
||||
REQUIRE(*opcode.parameter == 123);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Opcode] Note values")
|
||||
{
|
||||
auto noteValue = sfz::readNoteValue("c-1");
|
||||
REQUIRE( noteValue );
|
||||
REQUIRE( *noteValue == 0);
|
||||
REQUIRE(noteValue);
|
||||
REQUIRE(*noteValue == 0);
|
||||
noteValue = sfz::readNoteValue("C-1");
|
||||
REQUIRE( noteValue );
|
||||
REQUIRE( *noteValue == 0);
|
||||
REQUIRE(noteValue);
|
||||
REQUIRE(*noteValue == 0);
|
||||
noteValue = sfz::readNoteValue("g9");
|
||||
REQUIRE( noteValue );
|
||||
REQUIRE( *noteValue == 127);
|
||||
REQUIRE(noteValue);
|
||||
REQUIRE(*noteValue == 127);
|
||||
noteValue = sfz::readNoteValue("G9");
|
||||
REQUIRE( noteValue );
|
||||
REQUIRE( *noteValue == 127);
|
||||
REQUIRE(noteValue);
|
||||
REQUIRE(*noteValue == 127);
|
||||
noteValue = sfz::readNoteValue("c#4");
|
||||
REQUIRE( noteValue );
|
||||
REQUIRE( *noteValue == 61);
|
||||
REQUIRE(noteValue);
|
||||
REQUIRE(*noteValue == 61);
|
||||
noteValue = sfz::readNoteValue("C#4");
|
||||
REQUIRE( noteValue );
|
||||
REQUIRE( *noteValue == 61);
|
||||
REQUIRE(noteValue);
|
||||
REQUIRE(*noteValue == 61);
|
||||
}
|
||||
|
|
|
|||
104
tests/RangeT.cpp
104
tests/RangeT.cpp
|
|
@ -4,88 +4,88 @@ using namespace Catch::literals;
|
|||
|
||||
TEST_CASE("[Range] Equality operators")
|
||||
{
|
||||
Range<int> intRange {1, 1};
|
||||
REQUIRE( intRange == Range<int>(1, 1) );
|
||||
REQUIRE( intRange == std::pair<int, int>(1, 1) );
|
||||
REQUIRE( std::pair<int, int>(1, 1) == intRange );
|
||||
Range<int> intRange { 1, 1 };
|
||||
REQUIRE(intRange == Range<int>(1, 1));
|
||||
REQUIRE(intRange == std::pair<int, int>(1, 1));
|
||||
REQUIRE(std::pair<int, int>(1, 1) == intRange);
|
||||
|
||||
Range<float> floatRange {1.0f, 1.0f};
|
||||
REQUIRE( floatRange == Range<float>(1.0f, 1.0f) );
|
||||
REQUIRE( floatRange == std::pair<float, float>(1.0f, 1.0f) );
|
||||
REQUIRE( std::pair<float, float>(1.0f, 1.0f) == floatRange);
|
||||
Range<float> floatRange { 1.0f, 1.0f };
|
||||
REQUIRE(floatRange == Range<float>(1.0f, 1.0f));
|
||||
REQUIRE(floatRange == std::pair<float, float>(1.0f, 1.0f));
|
||||
REQUIRE(std::pair<float, float>(1.0f, 1.0f) == floatRange);
|
||||
}
|
||||
|
||||
TEST_CASE("[Range] Default ranges for classical types")
|
||||
{
|
||||
Range<int> intRange;
|
||||
REQUIRE( intRange == Range<int>(0, 0) );
|
||||
REQUIRE(intRange == Range<int>(0, 0));
|
||||
Range<int32_t> int32_tRange;
|
||||
REQUIRE( int32_tRange == Range<int32_t>(0, 0) );
|
||||
REQUIRE(int32_tRange == Range<int32_t>(0, 0));
|
||||
Range<uint32_t> uint32_tRange;
|
||||
REQUIRE( uint32_tRange == Range<uint32_t>(0, 0) );
|
||||
REQUIRE(uint32_tRange == Range<uint32_t>(0, 0));
|
||||
Range<int64_t> int64_tRange;
|
||||
REQUIRE( int64_tRange == Range<int64_t>(0, 0) );
|
||||
REQUIRE(int64_tRange == Range<int64_t>(0, 0));
|
||||
Range<uint64_t> uint64_tRange;
|
||||
REQUIRE( uint64_tRange == Range<uint64_t>(0, 0) );
|
||||
REQUIRE(uint64_tRange == Range<uint64_t>(0, 0));
|
||||
Range<float> floatRange;
|
||||
REQUIRE( floatRange == Range<float>(0, 0) );
|
||||
REQUIRE(floatRange == Range<float>(0, 0));
|
||||
Range<double> doubleRange;
|
||||
REQUIRE( doubleRange == Range<double>(0, 0) );
|
||||
REQUIRE(doubleRange == Range<double>(0, 0));
|
||||
}
|
||||
|
||||
TEST_CASE("[Range] Contains")
|
||||
{
|
||||
Range<int> intRange {1, 10};
|
||||
REQUIRE( !intRange.contains(0) );
|
||||
REQUIRE( intRange.contains(1) );
|
||||
REQUIRE( intRange.contains(5) );
|
||||
REQUIRE( !intRange.contains(10) );
|
||||
REQUIRE( !intRange.containsWithEnd(0) );
|
||||
REQUIRE( intRange.containsWithEnd(1) );
|
||||
REQUIRE( intRange.containsWithEnd(5) );
|
||||
REQUIRE( intRange.containsWithEnd(10) );
|
||||
Range<int> intRange { 1, 10 };
|
||||
REQUIRE(!intRange.contains(0));
|
||||
REQUIRE(intRange.contains(1));
|
||||
REQUIRE(intRange.contains(5));
|
||||
REQUIRE(!intRange.contains(10));
|
||||
REQUIRE(!intRange.containsWithEnd(0));
|
||||
REQUIRE(intRange.containsWithEnd(1));
|
||||
REQUIRE(intRange.containsWithEnd(5));
|
||||
REQUIRE(intRange.containsWithEnd(10));
|
||||
|
||||
Range<float> floatRange {1.0, 10.0};
|
||||
REQUIRE( !floatRange.contains(0.0) );
|
||||
REQUIRE( floatRange.contains(1.0) );
|
||||
REQUIRE( floatRange.contains(5.0) );
|
||||
REQUIRE( !floatRange.contains(10.0) );
|
||||
REQUIRE( !floatRange.containsWithEnd(0.0) );
|
||||
REQUIRE( floatRange.containsWithEnd(1.0) );
|
||||
REQUIRE( floatRange.containsWithEnd(5.0) );
|
||||
REQUIRE( floatRange.containsWithEnd(10.0) );
|
||||
Range<float> floatRange { 1.0, 10.0 };
|
||||
REQUIRE(!floatRange.contains(0.0));
|
||||
REQUIRE(floatRange.contains(1.0));
|
||||
REQUIRE(floatRange.contains(5.0));
|
||||
REQUIRE(!floatRange.contains(10.0));
|
||||
REQUIRE(!floatRange.containsWithEnd(0.0));
|
||||
REQUIRE(floatRange.containsWithEnd(1.0));
|
||||
REQUIRE(floatRange.containsWithEnd(5.0));
|
||||
REQUIRE(floatRange.containsWithEnd(10.0));
|
||||
}
|
||||
|
||||
TEST_CASE("[Range] Clamp")
|
||||
{
|
||||
Range<int> intRange {1, 10};
|
||||
REQUIRE( intRange.clamp(0) == 1 );
|
||||
REQUIRE( intRange.clamp(1) == 1 );
|
||||
REQUIRE( intRange.clamp(5) == 5 );
|
||||
REQUIRE( intRange.clamp(10) == 10 );
|
||||
REQUIRE( intRange.clamp(11) == 10 );
|
||||
Range<int> intRange { 1, 10 };
|
||||
REQUIRE(intRange.clamp(0) == 1);
|
||||
REQUIRE(intRange.clamp(1) == 1);
|
||||
REQUIRE(intRange.clamp(5) == 5);
|
||||
REQUIRE(intRange.clamp(10) == 10);
|
||||
REQUIRE(intRange.clamp(11) == 10);
|
||||
|
||||
Range<float> floatRange {1.0, 10.0};
|
||||
REQUIRE( floatRange.clamp(0.0) == 1.0_a );
|
||||
REQUIRE( floatRange.clamp(1.0) == 1.0_a );
|
||||
REQUIRE( floatRange.clamp(5.0) == 5.0_a );
|
||||
REQUIRE( floatRange.clamp(10.0) == 10.0_a );
|
||||
REQUIRE( floatRange.clamp(11.0) == 10.0_a );
|
||||
Range<float> floatRange { 1.0, 10.0 };
|
||||
REQUIRE(floatRange.clamp(0.0) == 1.0_a);
|
||||
REQUIRE(floatRange.clamp(1.0) == 1.0_a);
|
||||
REQUIRE(floatRange.clamp(5.0) == 5.0_a);
|
||||
REQUIRE(floatRange.clamp(10.0) == 10.0_a);
|
||||
REQUIRE(floatRange.clamp(11.0) == 10.0_a);
|
||||
}
|
||||
|
||||
TEST_CASE("[Range] shrinkIfSmaller")
|
||||
{
|
||||
Range<int> intRange {2, 10};
|
||||
Range<int> intRange { 2, 10 };
|
||||
intRange.shrinkIfSmaller(0, 10);
|
||||
REQUIRE( intRange == Range<int>(2, 10) );
|
||||
REQUIRE(intRange == Range<int>(2, 10));
|
||||
intRange.shrinkIfSmaller(2, 11);
|
||||
REQUIRE( intRange == Range<int>(2, 10) );
|
||||
REQUIRE(intRange == Range<int>(2, 10));
|
||||
intRange.shrinkIfSmaller(2, 9);
|
||||
REQUIRE( intRange == Range<int>(2, 9) );
|
||||
REQUIRE(intRange == Range<int>(2, 9));
|
||||
intRange.shrinkIfSmaller(3, 9);
|
||||
REQUIRE( intRange == Range<int>(3, 9) );
|
||||
REQUIRE(intRange == Range<int>(3, 9));
|
||||
intRange.shrinkIfSmaller(4, 7);
|
||||
REQUIRE( intRange == Range<int>(4, 7) );
|
||||
REQUIRE(intRange == Range<int>(4, 7));
|
||||
intRange.shrinkIfSmaller(6, 5);
|
||||
REQUIRE( intRange == Range<int>(5, 6) );
|
||||
REQUIRE(intRange == Range<int>(5, 6));
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "../sources/Parser.h"
|
||||
#include "catch2/catch.hpp"
|
||||
using namespace Catch::literals;
|
||||
|
||||
void includeTest(const std::string& line, const std::string& fileName)
|
||||
|
|
@ -57,7 +57,7 @@ TEST_CASE("[Regex] Header")
|
|||
SECTION("Basic header match")
|
||||
{
|
||||
std::smatch headerMatch;
|
||||
std::string line{"<header>param1=value1 param2=value2<next>"};
|
||||
std::string line { "<header>param1=value1 param2=value2<next>" };
|
||||
auto found = std::regex_search(line, headerMatch, sfz::Regexes::headers);
|
||||
REQUIRE(found);
|
||||
REQUIRE(headerMatch[1] == "header");
|
||||
|
|
@ -66,7 +66,7 @@ TEST_CASE("[Regex] Header")
|
|||
SECTION("EOL header match")
|
||||
{
|
||||
std::smatch headerMatch;
|
||||
std::string line{"<header>param1=value1 param2=value2"};
|
||||
std::string line { "<header>param1=value1 param2=value2" };
|
||||
auto found = std::regex_search(line, headerMatch, sfz::Regexes::headers);
|
||||
REQUIRE(found);
|
||||
REQUIRE(headerMatch[1] == "header");
|
||||
|
|
@ -74,7 +74,7 @@ TEST_CASE("[Regex] Header")
|
|||
}
|
||||
}
|
||||
|
||||
void memberTest(const std::string &line, const std::string &variable, const std::string &value)
|
||||
void memberTest(const std::string& line, const std::string& variable, const std::string& value)
|
||||
{
|
||||
std::smatch memberMatch;
|
||||
auto found = std::regex_search(line, memberMatch, sfz::Regexes::members);
|
||||
|
|
@ -114,7 +114,7 @@ void parameterTest(const std::string& line, const std::string& opcode, const std
|
|||
REQUIRE(parameterMatch[2] == parameter);
|
||||
}
|
||||
|
||||
void parameterFail(const std::string &line)
|
||||
void parameterFail(const std::string& line)
|
||||
{
|
||||
std::smatch parameterMatch;
|
||||
auto found = std::regex_search(line, parameterMatch, sfz::Regexes::opcodeParameters);
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "../sources/Region.h"
|
||||
#include "catch2/catch.hpp"
|
||||
using namespace Catch::literals;
|
||||
|
||||
TEST_CASE("Region activation", "Region tests")
|
||||
{
|
||||
sfz::Region region { };
|
||||
sfz::Region region {};
|
||||
region.parseOpcode({ "sample", "*sine" });
|
||||
SECTION("Basic state")
|
||||
{
|
||||
region.registerCC(1, 4, 0);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
}
|
||||
|
||||
SECTION("Single CC range")
|
||||
|
|
@ -17,19 +17,19 @@ TEST_CASE("Region activation", "Region tests")
|
|||
region.parseOpcode({ "locc4", "56" });
|
||||
region.parseOpcode({ "hicc4", "59" });
|
||||
region.registerCC(1, 4, 0);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerCC(1, 4, 57);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerCC(1, 4, 56);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerCC(1, 4, 59);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerCC(1, 4, 43);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerCC(1, 4, 65);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerCC(1, 6, 57);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
}
|
||||
|
||||
SECTION("Multiple CC ranges")
|
||||
|
|
@ -40,25 +40,25 @@ TEST_CASE("Region activation", "Region tests")
|
|||
region.parseOpcode({ "hicc54", "27" });
|
||||
region.registerCC(1, 4, 0);
|
||||
region.registerCC(1, 54, 0);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerCC(1, 4, 57);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerCC(1, 54, 19);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerCC(1, 54, 18);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerCC(1, 54, 27);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerCC(1, 4, 56);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerCC(1, 4, 59);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerCC(1, 54, 2);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerCC(1, 54, 26);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerCC(1, 4, 65);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
}
|
||||
|
||||
SECTION("Bend ranges")
|
||||
|
|
@ -66,13 +66,13 @@ TEST_CASE("Region activation", "Region tests")
|
|||
region.parseOpcode({ "lobend", "56" });
|
||||
region.parseOpcode({ "hibend", "243" });
|
||||
region.registerPitchWheel(1, 0);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerPitchWheel(1, 56);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerPitchWheel(1, 243);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerPitchWheel(1, 245);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
}
|
||||
|
||||
SECTION("Aftertouch ranges")
|
||||
|
|
@ -80,13 +80,13 @@ TEST_CASE("Region activation", "Region tests")
|
|||
region.parseOpcode({ "lochanaft", "56" });
|
||||
region.parseOpcode({ "hichanaft", "68" });
|
||||
region.registerAftertouch(1, 0);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerAftertouch(1, 56);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerAftertouch(1, 68);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerAftertouch(1, 98);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
}
|
||||
|
||||
SECTION("BPM ranges")
|
||||
|
|
@ -94,26 +94,26 @@ TEST_CASE("Region activation", "Region tests")
|
|||
region.parseOpcode({ "lobpm", "56" });
|
||||
region.parseOpcode({ "hibpm", "68" });
|
||||
region.registerTempo(2.0f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerTempo(0.90f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerTempo(1.01f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerTempo(1.1f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
}
|
||||
|
||||
// TODO: add keyswitches
|
||||
SECTION("Keyswitches: sw_last")
|
||||
{
|
||||
region.parseOpcode({ "sw_last", "40" });
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 41, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 41, 0, 0.5f);
|
||||
}
|
||||
|
||||
|
|
@ -122,20 +122,20 @@ TEST_CASE("Region activation", "Region tests")
|
|||
region.parseOpcode({ "sw_lokey", "30" });
|
||||
region.parseOpcode({ "sw_hikey", "50" });
|
||||
region.parseOpcode({ "sw_last", "40" });
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 60, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 60, 0, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 60, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 60, 0, 0.5f);
|
||||
region.registerNoteOn(1, 41, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 41, 0, 0.5f);
|
||||
}
|
||||
|
||||
|
|
@ -144,20 +144,20 @@ TEST_CASE("Region activation", "Region tests")
|
|||
region.parseOpcode({ "sw_lokey", "30" });
|
||||
region.parseOpcode({ "sw_hikey", "50" });
|
||||
region.parseOpcode({ "sw_down", "40" });
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 60, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 60, 0, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 60, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 60, 0, 0.5f);
|
||||
region.registerNoteOn(1, 41, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 41, 0, 0.5f);
|
||||
}
|
||||
|
||||
|
|
@ -166,103 +166,100 @@ TEST_CASE("Region activation", "Region tests")
|
|||
region.parseOpcode({ "sw_lokey", "30" });
|
||||
region.parseOpcode({ "sw_hikey", "50" });
|
||||
region.parseOpcode({ "sw_up", "40" });
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 41, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
region.registerNoteOff(1, 41, 0, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
}
|
||||
|
||||
SECTION("Keyswitches: sw_previous")
|
||||
{
|
||||
region.parseOpcode({ "sw_previous", "40" });
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 41, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
region.registerNoteOff(1, 41, 0, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 41, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 41, 0, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
}
|
||||
|
||||
|
||||
SECTION("Sequences: length 2, default position")
|
||||
{
|
||||
region.parseOpcode({ "seq_length", "2" });
|
||||
region.parseOpcode({ "seq_position", "1" });
|
||||
region.parseOpcode({ "key", "40" });
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
}
|
||||
SECTION("Sequences: length 2, position 2")
|
||||
{
|
||||
region.parseOpcode({ "seq_length", "2" });
|
||||
region.parseOpcode({ "seq_position", "2" });
|
||||
region.parseOpcode({ "key", "40" });
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
}
|
||||
SECTION("Sequences: length 3, position 2")
|
||||
{
|
||||
region.parseOpcode({ "seq_length", "3" });
|
||||
region.parseOpcode({ "seq_position", "2" });
|
||||
region.parseOpcode({ "key", "40" });
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( !region.isSwitchedOn() );
|
||||
REQUIRE(!region.isSwitchedOn());
|
||||
region.registerNoteOn(1, 40, 64, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
REQUIRE( region.isSwitchedOn() );
|
||||
REQUIRE(region.isSwitchedOn());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "../sources/Region.h"
|
||||
#include "catch2/catch.hpp"
|
||||
using namespace Catch::literals;
|
||||
|
||||
TEST_CASE("Basic triggers", "Region triggers")
|
||||
|
|
@ -9,44 +9,44 @@ TEST_CASE("Basic triggers", "Region triggers")
|
|||
SECTION("key")
|
||||
{
|
||||
region.parseOpcode({ "key", "40" });
|
||||
REQUIRE( region.registerNoteOn(1, 40, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOff(1, 40, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOn(1, 41, 64, 0.5f) );
|
||||
REQUIRE( !region.registerCC(1, 63, 64) );
|
||||
REQUIRE(region.registerNoteOn(1, 40, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOff(1, 40, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOn(1, 41, 64, 0.5f));
|
||||
REQUIRE(!region.registerCC(1, 63, 64));
|
||||
}
|
||||
SECTION("lokey and hikey")
|
||||
{
|
||||
region.parseOpcode({ "lokey", "40" });
|
||||
region.parseOpcode({ "hikey", "42" });
|
||||
REQUIRE( !region.registerNoteOn(1, 39, 64, 0.5f) );
|
||||
REQUIRE( region.registerNoteOn(1, 40, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOff(1, 40, 64, 0.5f) );
|
||||
REQUIRE( region.registerNoteOn(1, 41, 64, 0.5f) );
|
||||
REQUIRE( region.registerNoteOn(1, 42, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOn(1, 43, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOff(1, 42, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOff(1, 42, 64, 0.5f) );
|
||||
REQUIRE( !region.registerCC(1, 63, 64) );
|
||||
REQUIRE(!region.registerNoteOn(1, 39, 64, 0.5f));
|
||||
REQUIRE(region.registerNoteOn(1, 40, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOff(1, 40, 64, 0.5f));
|
||||
REQUIRE(region.registerNoteOn(1, 41, 64, 0.5f));
|
||||
REQUIRE(region.registerNoteOn(1, 42, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOn(1, 43, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOff(1, 42, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOff(1, 42, 64, 0.5f));
|
||||
REQUIRE(!region.registerCC(1, 63, 64));
|
||||
}
|
||||
SECTION("key and release trigger")
|
||||
{
|
||||
region.parseOpcode({ "key", "40" });
|
||||
region.parseOpcode({ "trigger", "release" });
|
||||
REQUIRE( !region.registerNoteOn(1, 40, 64, 0.5f) );
|
||||
REQUIRE( region.registerNoteOff(1, 40, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOn(1, 41, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOff(1, 41, 64, 0.5f) );
|
||||
REQUIRE( !region.registerCC(1, 63, 64) );
|
||||
REQUIRE(!region.registerNoteOn(1, 40, 64, 0.5f));
|
||||
REQUIRE(region.registerNoteOff(1, 40, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOn(1, 41, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOff(1, 41, 64, 0.5f));
|
||||
REQUIRE(!region.registerCC(1, 63, 64));
|
||||
}
|
||||
SECTION("key and release_key trigger")
|
||||
{
|
||||
region.parseOpcode({ "key", "40" });
|
||||
region.parseOpcode({ "trigger", "release_key" });
|
||||
REQUIRE( !region.registerNoteOn(1, 40, 64, 0.5f) );
|
||||
REQUIRE( region.registerNoteOff(1, 40, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOn(1, 41, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOff(1, 41, 64, 0.5f) );
|
||||
REQUIRE( !region.registerCC(1, 63, 64) );
|
||||
REQUIRE(!region.registerNoteOn(1, 40, 64, 0.5f));
|
||||
REQUIRE(region.registerNoteOff(1, 40, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOn(1, 41, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOff(1, 41, 64, 0.5f));
|
||||
REQUIRE(!region.registerCC(1, 63, 64));
|
||||
}
|
||||
// TODO: first and legato triggers
|
||||
SECTION("lovel and hivel")
|
||||
|
|
@ -54,22 +54,22 @@ TEST_CASE("Basic triggers", "Region triggers")
|
|||
region.parseOpcode({ "key", "40" });
|
||||
region.parseOpcode({ "lovel", "60" });
|
||||
region.parseOpcode({ "hivel", "70" });
|
||||
REQUIRE( region.registerNoteOn(1, 40, 64, 0.5f) );
|
||||
REQUIRE( region.registerNoteOn(1, 40, 60, 0.5f) );
|
||||
REQUIRE( region.registerNoteOn(1, 40, 70, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOn(1, 41, 71, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOn(1, 41, 59, 0.5f) );
|
||||
REQUIRE(region.registerNoteOn(1, 40, 64, 0.5f));
|
||||
REQUIRE(region.registerNoteOn(1, 40, 60, 0.5f));
|
||||
REQUIRE(region.registerNoteOn(1, 40, 70, 0.5f));
|
||||
REQUIRE(!region.registerNoteOn(1, 41, 71, 0.5f));
|
||||
REQUIRE(!region.registerNoteOn(1, 41, 59, 0.5f));
|
||||
}
|
||||
SECTION("lochan and hichan")
|
||||
{
|
||||
region.parseOpcode({ "key", "40" });
|
||||
region.parseOpcode({ "lochan", "2" });
|
||||
region.parseOpcode({ "hichan", "4" });
|
||||
REQUIRE( !region.registerNoteOn(1, 40, 64, 0.5f) );
|
||||
REQUIRE( region.registerNoteOn(2, 40, 64, 0.5f) );
|
||||
REQUIRE( region.registerNoteOn(3, 40, 64, 0.5f) );
|
||||
REQUIRE( region.registerNoteOn(4, 40, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOn(5, 40, 64, 0.5f) );
|
||||
REQUIRE(!region.registerNoteOn(1, 40, 64, 0.5f));
|
||||
REQUIRE(region.registerNoteOn(2, 40, 64, 0.5f));
|
||||
REQUIRE(region.registerNoteOn(3, 40, 64, 0.5f));
|
||||
REQUIRE(region.registerNoteOn(4, 40, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOn(5, 40, 64, 0.5f));
|
||||
}
|
||||
|
||||
SECTION("lorand and hirand")
|
||||
|
|
@ -77,37 +77,37 @@ TEST_CASE("Basic triggers", "Region triggers")
|
|||
region.parseOpcode({ "key", "40" });
|
||||
region.parseOpcode({ "lorand", "0.35" });
|
||||
region.parseOpcode({ "hirand", "0.40" });
|
||||
REQUIRE( !region.registerNoteOn(1, 40, 64, 0.34f) );
|
||||
REQUIRE( region.registerNoteOn(1, 40, 64, 0.35f) );
|
||||
REQUIRE( region.registerNoteOn(1, 40, 64, 0.36f) );
|
||||
REQUIRE( region.registerNoteOn(1, 40, 64, 0.37f) );
|
||||
REQUIRE( region.registerNoteOn(1, 40, 64, 0.38f) );
|
||||
REQUIRE( region.registerNoteOn(1, 40, 64, 0.39f) );
|
||||
REQUIRE( !region.registerNoteOn(1, 40, 64, 0.40f) );
|
||||
REQUIRE( !region.registerNoteOn(1, 40, 64, 0.41f) );
|
||||
REQUIRE(!region.registerNoteOn(1, 40, 64, 0.34f));
|
||||
REQUIRE(region.registerNoteOn(1, 40, 64, 0.35f));
|
||||
REQUIRE(region.registerNoteOn(1, 40, 64, 0.36f));
|
||||
REQUIRE(region.registerNoteOn(1, 40, 64, 0.37f));
|
||||
REQUIRE(region.registerNoteOn(1, 40, 64, 0.38f));
|
||||
REQUIRE(region.registerNoteOn(1, 40, 64, 0.39f));
|
||||
REQUIRE(!region.registerNoteOn(1, 40, 64, 0.40f));
|
||||
REQUIRE(!region.registerNoteOn(1, 40, 64, 0.41f));
|
||||
}
|
||||
|
||||
SECTION("lorand and hirand on 1.0f")
|
||||
{
|
||||
region.parseOpcode({ "key", "40" });
|
||||
region.parseOpcode({ "lorand", "0.35" });
|
||||
REQUIRE( !region.registerNoteOn(1, 40, 64, 0.34f) );
|
||||
REQUIRE( region.registerNoteOn(1, 40, 64, 0.35f) );
|
||||
REQUIRE( region.registerNoteOn(1, 40, 64, 1.0f) );
|
||||
REQUIRE(!region.registerNoteOn(1, 40, 64, 0.34f));
|
||||
REQUIRE(region.registerNoteOn(1, 40, 64, 0.35f));
|
||||
REQUIRE(region.registerNoteOn(1, 40, 64, 1.0f));
|
||||
}
|
||||
|
||||
SECTION("on_loccN, on_hiccN")
|
||||
{
|
||||
region.parseOpcode({ "on_locc47", "64" });
|
||||
region.parseOpcode({ "on_hicc47", "68" });
|
||||
REQUIRE( !region.registerCC(1, 47, 63) );
|
||||
REQUIRE( region.registerCC(1, 47, 64) );
|
||||
REQUIRE( region.registerCC(1, 47, 65) );
|
||||
REQUIRE( region.registerCC(1, 47, 66) );
|
||||
REQUIRE( region.registerCC(1, 47, 67) );
|
||||
REQUIRE( region.registerCC(1, 47, 68) );
|
||||
REQUIRE( !region.registerCC(1, 47, 69) );
|
||||
REQUIRE( !region.registerCC(1, 40, 64) );
|
||||
REQUIRE(!region.registerCC(1, 47, 63));
|
||||
REQUIRE(region.registerCC(1, 47, 64));
|
||||
REQUIRE(region.registerCC(1, 47, 65));
|
||||
REQUIRE(region.registerCC(1, 47, 66));
|
||||
REQUIRE(region.registerCC(1, 47, 67));
|
||||
REQUIRE(region.registerCC(1, 47, 68));
|
||||
REQUIRE(!region.registerCC(1, 47, 69));
|
||||
REQUIRE(!region.registerCC(1, 40, 64));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -120,11 +120,11 @@ TEST_CASE("Legato triggers", "Region triggers")
|
|||
region.parseOpcode({ "lokey", "40" });
|
||||
region.parseOpcode({ "hikey", "50" });
|
||||
region.parseOpcode({ "trigger", "first" });
|
||||
REQUIRE( region.registerNoteOn(1, 40, 64, 0.5f) );
|
||||
REQUIRE( !region.registerNoteOn(1, 41, 64, 0.5f) );
|
||||
REQUIRE(region.registerNoteOn(1, 40, 64, 0.5f));
|
||||
REQUIRE(!region.registerNoteOn(1, 41, 64, 0.5f));
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
region.registerNoteOff(1, 41, 0, 0.5f);
|
||||
REQUIRE( region.registerNoteOn(1, 42, 64, 0.5f) );
|
||||
REQUIRE(region.registerNoteOn(1, 42, 64, 0.5f));
|
||||
}
|
||||
|
||||
SECTION("Second note playing")
|
||||
|
|
@ -132,10 +132,10 @@ TEST_CASE("Legato triggers", "Region triggers")
|
|||
region.parseOpcode({ "lokey", "40" });
|
||||
region.parseOpcode({ "hikey", "50" });
|
||||
region.parseOpcode({ "trigger", "legato" });
|
||||
REQUIRE( !region.registerNoteOn(1, 40, 64, 0.5f) );
|
||||
REQUIRE( region.registerNoteOn(1, 41, 64, 0.5f) );
|
||||
REQUIRE(!region.registerNoteOn(1, 40, 64, 0.5f));
|
||||
REQUIRE(region.registerNoteOn(1, 41, 64, 0.5f));
|
||||
region.registerNoteOff(1, 40, 0, 0.5f);
|
||||
region.registerNoteOff(1, 41, 0, 0.5f);
|
||||
REQUIRE( !region.registerNoteOn(1, 42, 64, 0.5f) );
|
||||
REQUIRE(!region.registerNoteOn(1, 42, 64, 0.5f));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "../sources/SIMDHelpers.h"
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <absl/types/span.h>
|
||||
#include "catch2/catch.hpp"
|
||||
#include <absl/algorithm/container.h>
|
||||
#include <absl/types/span.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
using namespace Catch::literals;
|
||||
|
||||
constexpr int smallBufferSize { 3 };
|
||||
|
|
@ -12,15 +12,14 @@ constexpr int bigBufferSize { 4095 };
|
|||
constexpr int medBufferSize { 127 };
|
||||
constexpr double fillValue { 1.3 };
|
||||
|
||||
template<class Type>
|
||||
inline bool approxEqual(absl::Span<const Type> lhs, absl::Span<const Type> rhs, Type eps=1e-3)
|
||||
template <class Type>
|
||||
inline bool approxEqual(absl::Span<const Type> lhs, absl::Span<const Type> rhs, Type eps = 1e-3)
|
||||
{
|
||||
if (lhs.size() != rhs.size())
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < rhs.size(); ++i)
|
||||
if (rhs[i] != Approx(lhs[i]).epsilon(eps))
|
||||
{
|
||||
if (rhs[i] != Approx(lhs[i]).epsilon(eps)) {
|
||||
std::cerr << lhs[i] << " != " << rhs[i] << " at index " << i << '\n';
|
||||
return false;
|
||||
}
|
||||
|
|
@ -30,7 +29,7 @@ inline bool approxEqual(absl::Span<const Type> lhs, absl::Span<const Type> rhs,
|
|||
|
||||
TEST_CASE("[Helpers] fill() - Manual buffer")
|
||||
{
|
||||
std::vector<float> buffer (5);
|
||||
std::vector<float> buffer(5);
|
||||
std::vector<float> expected { fillValue, fillValue, fillValue, fillValue, fillValue };
|
||||
fill<float, false>(absl::MakeSpan(buffer), fillValue);
|
||||
REQUIRE(buffer == expected);
|
||||
|
|
@ -38,8 +37,8 @@ TEST_CASE("[Helpers] fill() - Manual buffer")
|
|||
|
||||
TEST_CASE("[Helpers] fill() - Small buffer")
|
||||
{
|
||||
std::vector<float> buffer (smallBufferSize);
|
||||
std::vector<float> expected (smallBufferSize);
|
||||
std::vector<float> buffer(smallBufferSize);
|
||||
std::vector<float> expected(smallBufferSize);
|
||||
std::fill(expected.begin(), expected.end(), fillValue);
|
||||
|
||||
fill<float, false>(absl::MakeSpan(buffer), fillValue);
|
||||
|
|
@ -48,8 +47,8 @@ TEST_CASE("[Helpers] fill() - Small buffer")
|
|||
|
||||
TEST_CASE("[Helpers] fill() - Big buffer")
|
||||
{
|
||||
std::vector<float> buffer (bigBufferSize);
|
||||
std::vector<float> expected (bigBufferSize);
|
||||
std::vector<float> buffer(bigBufferSize);
|
||||
std::vector<float> expected(bigBufferSize);
|
||||
std::fill(expected.begin(), expected.end(), fillValue);
|
||||
|
||||
fill<float, false>(absl::MakeSpan(buffer), fillValue);
|
||||
|
|
@ -58,8 +57,8 @@ TEST_CASE("[Helpers] fill() - Big buffer")
|
|||
|
||||
TEST_CASE("[Helpers] fill() - Small buffer -- SIMD")
|
||||
{
|
||||
std::vector<float> buffer (smallBufferSize);
|
||||
std::vector<float> expected (smallBufferSize);
|
||||
std::vector<float> buffer(smallBufferSize);
|
||||
std::vector<float> expected(smallBufferSize);
|
||||
std::fill(expected.begin(), expected.end(), fillValue);
|
||||
|
||||
fill<float, true>(absl::MakeSpan(buffer), fillValue);
|
||||
|
|
@ -68,8 +67,8 @@ TEST_CASE("[Helpers] fill() - Small buffer -- SIMD")
|
|||
|
||||
TEST_CASE("[Helpers] fill() - Big buffer -- SIMD")
|
||||
{
|
||||
std::vector<float> buffer (bigBufferSize);
|
||||
std::vector<float> expected (bigBufferSize);
|
||||
std::vector<float> buffer(bigBufferSize);
|
||||
std::vector<float> expected(bigBufferSize);
|
||||
std::fill(expected.begin(), expected.end(), fillValue);
|
||||
|
||||
fill<float, true>(absl::MakeSpan(buffer), fillValue);
|
||||
|
|
@ -78,8 +77,8 @@ TEST_CASE("[Helpers] fill() - Big buffer -- SIMD")
|
|||
|
||||
TEST_CASE("[Helpers] fill() - Small buffer -- doubles")
|
||||
{
|
||||
std::vector<double> buffer (smallBufferSize);
|
||||
std::vector<double> expected (smallBufferSize);
|
||||
std::vector<double> buffer(smallBufferSize);
|
||||
std::vector<double> expected(smallBufferSize);
|
||||
std::fill(expected.begin(), expected.end(), fillValue);
|
||||
|
||||
fill<double, false>(absl::MakeSpan(buffer), fillValue);
|
||||
|
|
@ -88,18 +87,17 @@ TEST_CASE("[Helpers] fill() - Small buffer -- doubles")
|
|||
|
||||
TEST_CASE("[Helpers] fill() - Big buffer -- doubles")
|
||||
{
|
||||
std::vector<double> buffer (bigBufferSize);
|
||||
std::vector<double> expected (bigBufferSize);
|
||||
std::vector<double> buffer(bigBufferSize);
|
||||
std::vector<double> expected(bigBufferSize);
|
||||
std::fill(expected.begin(), expected.end(), fillValue);
|
||||
|
||||
fill<double, false>(absl::MakeSpan(buffer), fillValue);
|
||||
REQUIRE(buffer == expected);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("[Helpers] Interleaved read")
|
||||
{
|
||||
std::array<float, 16> input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f};
|
||||
std::array<float, 16> input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f };
|
||||
std::array<float, 16> expected { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f };
|
||||
std::array<float, 8> leftOutput;
|
||||
std::array<float, 8> rightOutput;
|
||||
|
|
@ -107,50 +105,50 @@ TEST_CASE("[Helpers] Interleaved read")
|
|||
std::array<float, 16> real;
|
||||
|
||||
auto realIdx = 0;
|
||||
for (auto value: leftOutput)
|
||||
for (auto value : leftOutput)
|
||||
real[realIdx++] = value;
|
||||
for (auto value: rightOutput)
|
||||
for (auto value : rightOutput)
|
||||
real[realIdx++] = value;
|
||||
REQUIRE( real == expected );
|
||||
REQUIRE(real == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Interleaved read unaligned end")
|
||||
{
|
||||
std::array<float, 20> input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f};
|
||||
std::array<float, 20> expected { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f};
|
||||
std::array<float, 20> input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f };
|
||||
std::array<float, 20> expected { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f };
|
||||
std::array<float, 10> leftOutput;
|
||||
std::array<float, 10> rightOutput;
|
||||
readInterleaved<float, false>(input, absl::MakeSpan(leftOutput), absl::MakeSpan(rightOutput));
|
||||
std::array<float, 20> real;
|
||||
|
||||
auto realIdx = 0;
|
||||
for (auto value: leftOutput)
|
||||
for (auto value : leftOutput)
|
||||
real[realIdx++] = value;
|
||||
for (auto value: rightOutput)
|
||||
for (auto value : rightOutput)
|
||||
real[realIdx++] = value;
|
||||
REQUIRE( real == expected );
|
||||
REQUIRE(real == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Small interleaved read unaligned end")
|
||||
{
|
||||
std::array<float, 6> input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f};
|
||||
std::array<float, 6> expected { 0.0f, 1.0f, 2.0f, 10.0f, 11.0f, 12.0f};
|
||||
std::array<float, 6> input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f };
|
||||
std::array<float, 6> expected { 0.0f, 1.0f, 2.0f, 10.0f, 11.0f, 12.0f };
|
||||
std::array<float, 3> leftOutput;
|
||||
std::array<float, 3> rightOutput;
|
||||
readInterleaved<float, false>(input, absl::MakeSpan(leftOutput), absl::MakeSpan(rightOutput));
|
||||
std::array<float, 6> real;
|
||||
|
||||
auto realIdx = 0;
|
||||
for (auto value: leftOutput)
|
||||
for (auto value : leftOutput)
|
||||
real[realIdx++] = value;
|
||||
for (auto value: rightOutput)
|
||||
for (auto value : rightOutput)
|
||||
real[realIdx++] = value;
|
||||
REQUIRE( real == expected );
|
||||
REQUIRE(real == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Interleaved read -- SIMD")
|
||||
{
|
||||
std::array<float, 16> input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f};
|
||||
std::array<float, 16> input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f };
|
||||
std::array<float, 16> expected = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f };
|
||||
std::array<float, 8> leftOutput;
|
||||
std::array<float, 8> rightOutput;
|
||||
|
|
@ -158,45 +156,45 @@ TEST_CASE("[Helpers] Interleaved read -- SIMD")
|
|||
std::array<float, 16> real;
|
||||
|
||||
auto realIdx = 0;
|
||||
for (auto value: leftOutput)
|
||||
for (auto value : leftOutput)
|
||||
real[realIdx++] = value;
|
||||
for (auto value: rightOutput)
|
||||
for (auto value : rightOutput)
|
||||
real[realIdx++] = value;
|
||||
REQUIRE( real == expected );
|
||||
REQUIRE(real == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Interleaved read unaligned end -- SIMD")
|
||||
{
|
||||
std::array<float, 20> input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f};
|
||||
std::array<float, 20> expected = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f};
|
||||
std::array<float, 20> input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f };
|
||||
std::array<float, 20> expected = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f };
|
||||
std::array<float, 10> leftOutput;
|
||||
std::array<float, 10> rightOutput;
|
||||
readInterleaved<float, true>(input, absl::MakeSpan(leftOutput), absl::MakeSpan(rightOutput));
|
||||
std::array<float, 20> real;
|
||||
|
||||
auto realIdx = 0;
|
||||
for (auto value: leftOutput)
|
||||
for (auto value : leftOutput)
|
||||
real[realIdx++] = value;
|
||||
for (auto value: rightOutput)
|
||||
for (auto value : rightOutput)
|
||||
real[realIdx++] = value;
|
||||
REQUIRE( real == expected );
|
||||
REQUIRE(real == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Small interleaved read unaligned end -- SIMD")
|
||||
{
|
||||
std::array<float, 6> input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f};
|
||||
std::array<float, 6> expected { 0.0f, 1.0f, 2.0f, 10.0f, 11.0f, 12.0f};
|
||||
std::array<float, 6> input { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f };
|
||||
std::array<float, 6> expected { 0.0f, 1.0f, 2.0f, 10.0f, 11.0f, 12.0f };
|
||||
std::array<float, 3> leftOutput;
|
||||
std::array<float, 3> rightOutput;
|
||||
readInterleaved<float, true>(input, absl::MakeSpan(leftOutput), absl::MakeSpan(rightOutput));
|
||||
std::array<float, 6> real;
|
||||
|
||||
auto realIdx = 0;
|
||||
for (auto value: leftOutput)
|
||||
for (auto value : leftOutput)
|
||||
real[realIdx++] = value;
|
||||
for (auto value: rightOutput)
|
||||
for (auto value : rightOutput)
|
||||
real[realIdx++] = value;
|
||||
REQUIRE( real == expected );
|
||||
REQUIRE(real == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Interleaved read SIMD vs Scalar")
|
||||
|
|
@ -209,68 +207,86 @@ TEST_CASE("[Helpers] Interleaved read SIMD vs Scalar")
|
|||
std::iota(input.begin(), input.end(), 0.0f);
|
||||
readInterleaved<float, false>(input, absl::MakeSpan(leftOutputScalar), absl::MakeSpan(rightOutputScalar));
|
||||
readInterleaved<float, true>(input, absl::MakeSpan(leftOutputSIMD), absl::MakeSpan(rightOutputSIMD));
|
||||
REQUIRE( leftOutputScalar == leftOutputSIMD );
|
||||
REQUIRE( rightOutputScalar == rightOutputSIMD );
|
||||
REQUIRE(leftOutputScalar == leftOutputSIMD);
|
||||
REQUIRE(rightOutputScalar == rightOutputSIMD);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Interleaved write")
|
||||
{
|
||||
std::array<float, 8> leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, };
|
||||
std::array<float, 8> leftInput {
|
||||
0.0f,
|
||||
1.0f,
|
||||
2.0f,
|
||||
3.0f,
|
||||
4.0f,
|
||||
5.0f,
|
||||
6.0f,
|
||||
7.0f,
|
||||
};
|
||||
std::array<float, 8> rightInput { 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f };
|
||||
std::array<float, 16> output;
|
||||
std::array<float, 16> expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f};
|
||||
std::array<float, 16> expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f };
|
||||
writeInterleaved<float, false>(leftInput, rightInput, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Interleaved write unaligned end")
|
||||
{
|
||||
std::array<float, 10> leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f};
|
||||
std::array<float, 10> leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f };
|
||||
std::array<float, 10> rightInput { 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f };
|
||||
std::array<float, 20> output;
|
||||
std::array<float, 20> expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f};
|
||||
std::array<float, 20> expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f };
|
||||
writeInterleaved<float, false>(leftInput, rightInput, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Small interleaved write unaligned end")
|
||||
{
|
||||
std::array<float, 3> leftInput { 0.0f, 1.0f, 2.0f};
|
||||
std::array<float, 3> leftInput { 0.0f, 1.0f, 2.0f };
|
||||
std::array<float, 3> rightInput { 10.0f, 11.0f, 12.0f };
|
||||
std::array<float, 6> output;
|
||||
std::array<float, 6> expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f};
|
||||
std::array<float, 6> expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f };
|
||||
writeInterleaved<float, false>(leftInput, rightInput, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Interleaved write -- SIMD")
|
||||
{
|
||||
std::array<float, 8> leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, };
|
||||
std::array<float, 8> leftInput {
|
||||
0.0f,
|
||||
1.0f,
|
||||
2.0f,
|
||||
3.0f,
|
||||
4.0f,
|
||||
5.0f,
|
||||
6.0f,
|
||||
7.0f,
|
||||
};
|
||||
std::array<float, 8> rightInput { 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f };
|
||||
std::array<float, 16> output;
|
||||
std::array<float, 16> expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f};
|
||||
std::array<float, 16> expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f };
|
||||
writeInterleaved<float, true>(leftInput, rightInput, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Interleaved write unaligned end -- SIMD")
|
||||
{
|
||||
std::array<float, 10> leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f};
|
||||
std::array<float, 10> leftInput { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f };
|
||||
std::array<float, 10> rightInput { 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f };
|
||||
std::array<float, 20> output;
|
||||
std::array<float, 20> expected = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f};
|
||||
std::array<float, 20> expected = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f };
|
||||
writeInterleaved<float, true>(leftInput, rightInput, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Small interleaved write unaligned end -- SIMD")
|
||||
{
|
||||
std::array<float, 3> leftInput { 0.0f, 1.0f, 2.0f};
|
||||
std::array<float, 3> leftInput { 0.0f, 1.0f, 2.0f };
|
||||
std::array<float, 3> rightInput { 10.0f, 11.0f, 12.0f };
|
||||
std::array<float, 6> output;
|
||||
std::array<float, 6> expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f};
|
||||
std::array<float, 6> expected { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f };
|
||||
writeInterleaved<float, true>(leftInput, rightInput, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Interleaved write SIMD vs Scalar")
|
||||
|
|
@ -283,7 +299,7 @@ TEST_CASE("[Helpers] Interleaved write SIMD vs Scalar")
|
|||
std::iota(rightInput.begin(), rightInput.end(), medBufferSize);
|
||||
writeInterleaved<float, false>(leftInput, rightInput, absl::MakeSpan(outputScalar));
|
||||
writeInterleaved<float, true>(leftInput, rightInput, absl::MakeSpan(outputSIMD));
|
||||
REQUIRE( outputScalar == outputSIMD );
|
||||
REQUIRE(outputScalar == outputSIMD);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Gain, single")
|
||||
|
|
@ -292,7 +308,7 @@ TEST_CASE("[Helpers] Gain, single")
|
|||
std::array<float, 5> output { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
std::array<float, 5> expected { fillValue, fillValue, fillValue, fillValue, fillValue };
|
||||
applyGain<float, false>(fillValue, input, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Gain, single and inplace")
|
||||
|
|
@ -300,7 +316,7 @@ TEST_CASE("[Helpers] Gain, single and inplace")
|
|||
std::array<float, 5> buffer { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
std::array<float, 5> expected { fillValue, fillValue, fillValue, fillValue, fillValue };
|
||||
applyGain<float, false>(fillValue, buffer, absl::MakeSpan(buffer));
|
||||
REQUIRE( buffer == expected );
|
||||
REQUIRE(buffer == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Gain, spans")
|
||||
|
|
@ -310,7 +326,7 @@ TEST_CASE("[Helpers] Gain, spans")
|
|||
std::array<float, 5> output { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
std::array<float, 5> expected { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
|
||||
applyGain<float, false>(gain, input, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Gain, spans and inplace")
|
||||
|
|
@ -319,7 +335,7 @@ TEST_CASE("[Helpers] Gain, spans and inplace")
|
|||
std::array<float, 5> gain { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
|
||||
std::array<float, 5> expected { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
|
||||
applyGain<float, false>(gain, buffer, absl::MakeSpan(buffer));
|
||||
REQUIRE( buffer == expected );
|
||||
REQUIRE(buffer == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Gain, single (SIMD)")
|
||||
|
|
@ -328,7 +344,7 @@ TEST_CASE("[Helpers] Gain, single (SIMD)")
|
|||
std::array<float, 5> output { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
std::array<float, 5> expected { fillValue, fillValue, fillValue, fillValue, fillValue };
|
||||
applyGain<float, true>(fillValue, input, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Gain, single and inplace (SIMD)")
|
||||
|
|
@ -336,7 +352,7 @@ TEST_CASE("[Helpers] Gain, single and inplace (SIMD)")
|
|||
std::array<float, 5> buffer { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
std::array<float, 5> expected { fillValue, fillValue, fillValue, fillValue, fillValue };
|
||||
applyGain<float, true>(fillValue, buffer, absl::MakeSpan(buffer));
|
||||
REQUIRE( buffer == expected );
|
||||
REQUIRE(buffer == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Gain, spans (SIMD)")
|
||||
|
|
@ -346,7 +362,7 @@ TEST_CASE("[Helpers] Gain, spans (SIMD)")
|
|||
std::array<float, 5> output { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
std::array<float, 5> expected { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
|
||||
applyGain<float, true>(gain, input, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Gain, spans and inplace (SIMD)")
|
||||
|
|
@ -355,12 +371,12 @@ TEST_CASE("[Helpers] Gain, spans and inplace (SIMD)")
|
|||
std::array<float, 5> gain { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
|
||||
std::array<float, 5> expected { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
|
||||
applyGain<float, true>(gain, buffer, absl::MakeSpan(buffer));
|
||||
REQUIRE( buffer == expected );
|
||||
REQUIRE(buffer == expected);
|
||||
}
|
||||
|
||||
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.0 6.5 8.1
|
||||
std::array<int, 6> indices;
|
||||
std::array<float, 6> leftCoeffs;
|
||||
std::array<float, 6> rightCoeffs;
|
||||
|
|
@ -368,14 +384,14 @@ TEST_CASE("[Helpers] SFZ looping index")
|
|||
std::array<float, 6> expectedLeft { 0.9f, 0.7f, 0.4f, 1.0f, 0.5f, 0.9f };
|
||||
std::array<float, 6> expectedRight { 0.1f, 0.3f, 0.6f, 0.0f, 0.5f, 0.1f };
|
||||
loopingSFZIndex<float, false>(jumps, absl::MakeSpan(leftCoeffs), absl::MakeSpan(rightCoeffs), absl::MakeSpan(indices), 1.0f, 6, 1);
|
||||
REQUIRE( indices == expectedIndices );
|
||||
REQUIRE( approxEqual<float>(leftCoeffs, expectedLeft) );
|
||||
REQUIRE( approxEqual<float>(rightCoeffs, expectedRight) );
|
||||
REQUIRE(indices == expectedIndices);
|
||||
REQUIRE(approxEqual<float>(leftCoeffs, expectedLeft));
|
||||
REQUIRE(approxEqual<float>(rightCoeffs, expectedRight));
|
||||
}
|
||||
|
||||
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.0 6.5 8.1
|
||||
std::array<int, 6> indices;
|
||||
std::array<float, 6> leftCoeffs;
|
||||
std::array<float, 6> rightCoeffs;
|
||||
|
|
@ -383,9 +399,9 @@ TEST_CASE("[Helpers] SFZ looping index (SIMD)")
|
|||
std::array<float, 6> expectedLeft { 0.9f, 0.7f, 0.4f, 1.0f, 0.5f, 0.9f };
|
||||
std::array<float, 6> expectedRight { 0.1f, 0.3f, 0.6f, 0.0f, 0.5f, 0.1f };
|
||||
loopingSFZIndex<float, true>(jumps, absl::MakeSpan(leftCoeffs), absl::MakeSpan(rightCoeffs), absl::MakeSpan(indices), 1.0f, 6, 1);
|
||||
REQUIRE( indices == expectedIndices );
|
||||
REQUIRE( approxEqual<float>(leftCoeffs, expectedLeft) );
|
||||
REQUIRE( approxEqual<float>(rightCoeffs, expectedRight) );
|
||||
REQUIRE(indices == expectedIndices);
|
||||
REQUIRE(approxEqual<float>(leftCoeffs, expectedLeft));
|
||||
REQUIRE(approxEqual<float>(rightCoeffs, expectedRight));
|
||||
}
|
||||
|
||||
// TEST_CASE("[Helpers] SFZ looping index (SIMD vs Scalar)")
|
||||
|
|
@ -397,7 +413,7 @@ TEST_CASE("[Helpers] SFZ looping index (SIMD)")
|
|||
// std::vector<int> indices(bigBufferSize);
|
||||
// std::vector<float> leftCoeffs(bigBufferSize);
|
||||
// std::vector<float> rightCoeffs(bigBufferSize);
|
||||
|
||||
|
||||
// std::vector<int> indicesSIMD(bigBufferSize);
|
||||
// std::vector<float> leftCoeffsSIMD(bigBufferSize);
|
||||
// std::vector<float> rightCoeffsSIMD(bigBufferSize);
|
||||
|
|
@ -413,9 +429,9 @@ TEST_CASE("[Helpers] Linear Ramp")
|
|||
const float start { 0.0f };
|
||||
const float v { fillValue };
|
||||
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} ;
|
||||
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 };
|
||||
linearRamp<float, false>(absl::MakeSpan(output), start, v);
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Linear Ramp (SIMD)")
|
||||
|
|
@ -423,9 +439,9 @@ TEST_CASE("[Helpers] Linear Ramp (SIMD)")
|
|||
const float start { 0.0f };
|
||||
const float v { fillValue };
|
||||
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} ;
|
||||
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 };
|
||||
linearRamp<float, true>(absl::MakeSpan(output), start, v);
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Linear Ramp (SIMD vs scalar)")
|
||||
|
|
@ -435,7 +451,7 @@ TEST_CASE("[Helpers] Linear Ramp (SIMD vs scalar)")
|
|||
std::vector<float> outputSIMD(bigBufferSize);
|
||||
linearRamp<float, false>(absl::MakeSpan(outputScalar), start, fillValue);
|
||||
linearRamp<float, true>(absl::MakeSpan(outputSIMD), start, fillValue);
|
||||
REQUIRE( approxEqual<float>(outputScalar, outputSIMD) );
|
||||
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Linear Ramp unaligned (SIMD vs scalar)")
|
||||
|
|
@ -445,7 +461,7 @@ TEST_CASE("[Helpers] Linear Ramp unaligned (SIMD vs scalar)")
|
|||
std::vector<float> outputSIMD(bigBufferSize);
|
||||
linearRamp<float, false>(absl::MakeSpan(outputScalar).subspan(1), start, fillValue);
|
||||
linearRamp<float, true>(absl::MakeSpan(outputSIMD).subspan(1), start, fillValue);
|
||||
REQUIRE( approxEqual<float>(outputScalar, outputSIMD) );
|
||||
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Multiplicative Ramp")
|
||||
|
|
@ -453,9 +469,9 @@ TEST_CASE("[Helpers] Multiplicative Ramp")
|
|||
const float start { 1.0f };
|
||||
const float v { fillValue };
|
||||
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} ;
|
||||
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 };
|
||||
multiplicativeRamp<float, false>(absl::MakeSpan(output), start, v);
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Multiplicative Ramp (SIMD)")
|
||||
|
|
@ -463,9 +479,9 @@ TEST_CASE("[Helpers] Multiplicative Ramp (SIMD)")
|
|||
const float start { 1.0f };
|
||||
const float v { fillValue };
|
||||
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} ;
|
||||
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 };
|
||||
multiplicativeRamp<float, true>(absl::MakeSpan(output), start, v);
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Multiplicative Ramp (SIMD vs scalar)")
|
||||
|
|
@ -475,7 +491,7 @@ TEST_CASE("[Helpers] Multiplicative Ramp (SIMD vs scalar)")
|
|||
std::vector<float> outputSIMD(bigBufferSize);
|
||||
multiplicativeRamp<float, false>(absl::MakeSpan(outputScalar), start, fillValue);
|
||||
multiplicativeRamp<float, true>(absl::MakeSpan(outputSIMD), start, fillValue);
|
||||
REQUIRE( approxEqual<float>(outputScalar, outputSIMD) );
|
||||
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Multiplicative Ramp unaligned (SIMD vs scalar)")
|
||||
|
|
@ -485,7 +501,7 @@ TEST_CASE("[Helpers] Multiplicative Ramp unaligned (SIMD vs scalar)")
|
|||
std::vector<float> outputSIMD(bigBufferSize);
|
||||
multiplicativeRamp<float, false>(absl::MakeSpan(outputScalar).subspan(1), start, fillValue);
|
||||
multiplicativeRamp<float, true>(absl::MakeSpan(outputSIMD).subspan(1), start, fillValue);
|
||||
REQUIRE( approxEqual<float>(outputScalar, outputSIMD) );
|
||||
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Add")
|
||||
|
|
@ -494,7 +510,7 @@ TEST_CASE("[Helpers] Add")
|
|||
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 };
|
||||
add<float, false>(input, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Add (SIMD)")
|
||||
|
|
@ -503,7 +519,7 @@ TEST_CASE("[Helpers] Add (SIMD)")
|
|||
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 };
|
||||
add<float, true>(input, absl::MakeSpan(output));
|
||||
REQUIRE( output == expected );
|
||||
REQUIRE(output == expected);
|
||||
}
|
||||
|
||||
TEST_CASE("[Helpers] Add (SIMD vs scalar)")
|
||||
|
|
@ -517,5 +533,5 @@ TEST_CASE("[Helpers] Add (SIMD vs scalar)")
|
|||
|
||||
add<float, false>(input, absl::MakeSpan(outputScalar));
|
||||
add<float, true>(input, absl::MakeSpan(outputSIMD));
|
||||
REQUIRE( approxEqual<float>(outputScalar, outputSIMD) );
|
||||
REQUIRE(approxEqual<float>(outputScalar, outputSIMD));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "catch2/catch.hpp"
|
||||
#include "../sources/StereoBuffer.h"
|
||||
#include "catch2/catch.hpp"
|
||||
#include <algorithm>
|
||||
using namespace Catch::literals;
|
||||
|
||||
|
|
@ -33,16 +33,14 @@ TEST_CASE("[StereoBuffer] Access")
|
|||
{
|
||||
const int size { 5 };
|
||||
StereoBuffer<double> doubleBuffer(size);
|
||||
for (auto frameIdx = 0; frameIdx < doubleBuffer.getNumFrames(); ++frameIdx)
|
||||
{
|
||||
for (auto frameIdx = 0; frameIdx < doubleBuffer.getNumFrames(); ++frameIdx) {
|
||||
doubleBuffer.getSample(Channel::left, frameIdx) = static_cast<double>(doubleBuffer.getNumFrames()) + frameIdx;
|
||||
doubleBuffer.getSample(Channel::right, frameIdx) = static_cast<double>(doubleBuffer.getNumFrames()) - frameIdx;
|
||||
}
|
||||
|
||||
for (auto frameIdx = 0; frameIdx < doubleBuffer.getNumFrames(); ++frameIdx)
|
||||
{
|
||||
REQUIRE(doubleBuffer.getSample(Channel::left, frameIdx) == static_cast<double>(doubleBuffer.getNumFrames()) + frameIdx);
|
||||
REQUIRE(doubleBuffer(Channel::left, frameIdx) == static_cast<double>(doubleBuffer.getNumFrames()) + frameIdx);
|
||||
for (auto frameIdx = 0; frameIdx < doubleBuffer.getNumFrames(); ++frameIdx) {
|
||||
REQUIRE(doubleBuffer.getSample(Channel::left, frameIdx) == static_cast<double>(doubleBuffer.getNumFrames()) + frameIdx);
|
||||
REQUIRE(doubleBuffer(Channel::left, frameIdx) == static_cast<double>(doubleBuffer.getNumFrames()) + frameIdx);
|
||||
REQUIRE(doubleBuffer.getSample(Channel::right, frameIdx) == static_cast<double>(doubleBuffer.getNumFrames()) - frameIdx);
|
||||
REQUIRE(doubleBuffer(Channel::right, frameIdx) == static_cast<double>(doubleBuffer.getNumFrames()) - frameIdx);
|
||||
}
|
||||
|
|
@ -56,17 +54,17 @@ TEST_CASE("[StereoBuffer] Iterators")
|
|||
std::fill(buffer.begin(Channel::left), buffer.end(Channel::left), fillValue);
|
||||
std::fill(buffer.begin(Channel::right), buffer.end(Channel::right), fillValue);
|
||||
|
||||
REQUIRE( std::all_of(buffer.begin(Channel::left), buffer.end(Channel::left), [fillValue](auto value) { return value == fillValue; }) );
|
||||
REQUIRE( std::all_of(buffer.begin(Channel::right), buffer.end(Channel::right), [fillValue](auto value) { return value == fillValue; }) );
|
||||
REQUIRE(std::all_of(buffer.begin(Channel::left), buffer.end(Channel::left), [fillValue](auto value) { return value == fillValue; }));
|
||||
REQUIRE(std::all_of(buffer.begin(Channel::right), buffer.end(Channel::right), [fillValue](auto value) { return value == fillValue; }));
|
||||
}
|
||||
|
||||
template<class Type, unsigned int Alignment = 16>
|
||||
template <class Type, unsigned int Alignment = 16>
|
||||
void channelAlignmentTest(int size)
|
||||
{
|
||||
static constexpr auto AlignmentMask { Alignment - 1 };
|
||||
StereoBuffer<Type, Alignment> buffer(size);
|
||||
REQUIRE( ((size_t)buffer.getChannel(Channel::left) & AlignmentMask) == 0 );
|
||||
REQUIRE( ((size_t)buffer.getChannel(Channel::right) & AlignmentMask) == 0 );
|
||||
REQUIRE(((size_t)buffer.getChannel(Channel::left) & AlignmentMask) == 0);
|
||||
REQUIRE(((size_t)buffer.getChannel(Channel::right) & AlignmentMask) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("[StereoBuffer] Channel alignments (floats)")
|
||||
|
|
@ -140,19 +138,18 @@ TEST_CASE("[AudioBuffer] fills")
|
|||
|
||||
for (auto frameIdx = 0; frameIdx < buffer.getNumFrames(); ++frameIdx)
|
||||
real[frameIdx] = buffer(Channel::left, frameIdx);
|
||||
REQUIRE( real == expected );
|
||||
REQUIRE(real == expected);
|
||||
|
||||
for (auto frameIdx = 0; frameIdx < buffer.getNumFrames(); ++frameIdx)
|
||||
real[frameIdx] = buffer(Channel::right, frameIdx);
|
||||
REQUIRE( real == expected );
|
||||
REQUIRE(real == expected);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("[AudioBuffer] Fill a big Audiobuffer")
|
||||
{
|
||||
constexpr int size { 2039247 };
|
||||
StereoBuffer<float> buffer (size);
|
||||
std::vector<float> input (2*size);
|
||||
StereoBuffer<float> buffer(size);
|
||||
std::vector<float> input(2 * size);
|
||||
std::iota(input.begin(), input.end(), 1.0f);
|
||||
buffer.readInterleaved(input);
|
||||
}
|
||||
|
|
@ -160,29 +157,29 @@ TEST_CASE("[AudioBuffer] Fill a big Audiobuffer")
|
|||
TEST_CASE("[StereoBuffer] Interleaved write -- Scalar")
|
||||
{
|
||||
StereoBuffer<float> buffer(10);
|
||||
std::array<float, 20> input = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f};
|
||||
std::array<float, 20> input = { 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f };
|
||||
std::array<float, 20> output { 0.0f };
|
||||
buffer.readInterleaved(input);
|
||||
buffer.writeInterleaved(absl::MakeSpan(output));
|
||||
REQUIRE( output == input );
|
||||
REQUIRE(output == input);
|
||||
}
|
||||
|
||||
TEST_CASE("[StereoBuffer] Interleaved write -- SIMD")
|
||||
{
|
||||
StereoBuffer<float> buffer(10);
|
||||
std::array<float, 20> input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f};
|
||||
std::array<float, 20> input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f, 3.0f, 13.0f, 4.0f, 14.0f, 5.0f, 15.0f, 6.0f, 16.0f, 7.0f, 17.0f, 8.0f, 18.0f, 9.0f, 19.0f };
|
||||
std::array<float, 20> output { 0.0f };
|
||||
buffer.readInterleaved(input);
|
||||
buffer.writeInterleaved(absl::MakeSpan(output));
|
||||
REQUIRE( output == input );
|
||||
REQUIRE(output == input);
|
||||
}
|
||||
|
||||
TEST_CASE("[StereoBuffer] Small interleaved write -- SIMD")
|
||||
{
|
||||
StereoBuffer<float> buffer(3);
|
||||
std::array<float, 6> input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f};
|
||||
std::array<float, 6> input = { 0.0f, 10.0f, 1.0f, 11.0f, 2.0f, 12.0f };
|
||||
std::array<float, 6> output { 0.0f };
|
||||
buffer.readInterleaved(input);
|
||||
buffer.writeInterleaved(absl::MakeSpan(output));
|
||||
REQUIRE( output == input );
|
||||
REQUIRE(output == input);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue