Changed the config

This commit is contained in:
Paul Ferrand 2019-07-30 18:26:35 +02:00
parent 5894b6cfb6
commit b2635aa2c2
5 changed files with 51 additions and 19 deletions

View file

@ -3,7 +3,7 @@
#include "Helpers.h" #include "Helpers.h"
#include "Globals.h" #include "Globals.h"
template<class Type, unsigned int NumChannels = sfz::Config::numChannels, unsigned int Alignment = sfz::Config::defaultAlignment> template<class Type, unsigned int NumChannels = sfz::config::numChannels, unsigned int Alignment = config::defaultAlignment>
class AudioBuffer class AudioBuffer
{ {
@ -38,6 +38,19 @@ public:
return *(buffer.data() + numFrames * channelIndex + sampleIndex); return *(buffer.data() + numFrames * channelIndex + sampleIndex);
} }
void fill(Type value) noexcept
{
if constexpr (config::vectorOperation == config::VectorOperations::sse)
{
}
else
{
for(auto i = 0; i < NumChannels; ++i)
std::fill(begin(i), end(i), value);
}
}
Type* getChannel(int channelIndex) noexcept Type* getChannel(int channelIndex) noexcept
{ {
return channels[channelIndex]; return channels[channelIndex];
@ -73,7 +86,7 @@ private:
Buffer<Type, Alignment> buffer {}; Buffer<Type, Alignment> buffer {};
}; };
template<class Type, unsigned int NumChannels = sfz::Config::numChannels, unsigned int Alignment = sfz::Config::defaultAlignment> template<class Type, unsigned int NumChannels = sfz::config::numChannels, unsigned int Alignment = config::defaultAlignment>
class SplitAudioBuffer class SplitAudioBuffer
{ {
public: public:
@ -100,6 +113,19 @@ public:
return resizedOK; return resizedOK;
} }
void fill(Type value) noexcept
{
if constexpr (config::vectorOperation == config::VectorOperations::sse)
{
}
else
{
for(auto i = 0; i < NumChannels; ++i)
std::fill(begin(i), end(i), value);
}
}
Type& getSample(int channelIndex, int sampleIndex) noexcept Type& getSample(int channelIndex, int sampleIndex) noexcept
{ {
ASSERT(channelIndex >= 0); ASSERT(channelIndex >= 0);

View file

@ -4,7 +4,7 @@
#include <cstdlib> #include <cstdlib>
#include <memory> #include <memory>
template<class Type, unsigned int Alignment = sfz::Config::defaultAlignment> template<class Type, unsigned int Alignment = config::defaultAlignment>
class Buffer class Buffer
{ {
static_assert(std::is_arithmetic<Type>::value, "Type should be arithmetic"); static_assert(std::is_arithmetic<Type>::value, "Type should be arithmetic");

View file

@ -3,7 +3,7 @@
namespace sfz namespace sfz
{ {
namespace Config namespace config
{ {
inline constexpr double defaultSampleRate { 48000 }; inline constexpr double defaultSampleRate { 48000 };
inline constexpr int defaultSamplesPerBlock { 1024 }; inline constexpr int defaultSamplesPerBlock { 1024 };
@ -16,7 +16,13 @@ namespace Config
inline constexpr double fastReleaseDuration { 0.01 }; inline constexpr double fastReleaseDuration { 0.01 };
inline constexpr char defineCharacter { '$' }; inline constexpr char defineCharacter { '$' };
inline constexpr int oversamplingFactor { 2 }; inline constexpr int oversamplingFactor { 2 };
inline constexpr unsigned int defaultAlignment { 16 };
} // namespace config } // namespace config
} // namespace sfz } // namespace sfz
namespace config
{
inline constexpr unsigned int defaultAlignment { 16 };
enum class VectorOperations { standard, sse, neon };
inline constexpr VectorOperations vectorOperation { VectorOperations::standard };
} // namespace config

View file

@ -103,7 +103,7 @@ void sfz::Parser::readSfzFile(const std::filesystem::path& fileName, std::vector
std::string newString; std::string newString;
newString.reserve(tmpView.length()); newString.reserve(tmpView.length());
std::string::size_type lastPos = 0; std::string::size_type lastPos = 0;
std::string::size_type findPos = tmpView.find(sfz::Config::defineCharacter, lastPos); std::string::size_type findPos = tmpView.find(sfz::config::defineCharacter, lastPos);
while(findPos < tmpView.npos) while(findPos < tmpView.npos)
{ {
@ -122,11 +122,11 @@ void sfz::Parser::readSfzFile(const std::filesystem::path& fileName, std::vector
if (lastPos <= findPos) if (lastPos <= findPos)
{ {
newString += sfz::Config::defineCharacter; newString += sfz::config::defineCharacter;
lastPos = findPos + 1; lastPos = findPos + 1;
} }
findPos = tmpView.find(sfz::Config::defineCharacter, lastPos); findPos = tmpView.find(sfz::config::defineCharacter, lastPos);
} }
// Copy the rest of the string // Copy the rest of the string

View file

@ -36,7 +36,7 @@ TEST_CASE("[Buffer] 10 floats ")
Buffer<float> buffer(10); Buffer<float> buffer(10);
REQUIRE(!buffer.empty()); REQUIRE(!buffer.empty());
REQUIRE(buffer.size() == 10); REQUIRE(buffer.size() == 10);
REQUIRE(((size_t)buffer.data() & (sfz::Config::defaultAlignment - 1)) == 0); REQUIRE(((size_t)buffer.data() & (config::defaultAlignment - 1)) == 0);
for (auto& element: buffer) for (auto& element: buffer)
element = 0.0f; element = 0.0f;
for (auto& element: buffer) for (auto& element: buffer)
@ -51,15 +51,15 @@ TEST_CASE("[Buffer] Resize 10 floats ")
Buffer<float> buffer(baseSize); Buffer<float> buffer(baseSize);
REQUIRE(!buffer.empty()); REQUIRE(!buffer.empty());
REQUIRE(buffer.size() == baseSize); REQUIRE(buffer.size() == baseSize);
REQUIRE(((size_t)buffer.data() & (sfz::Config::defaultAlignment - 1)) == 0); REQUIRE(((size_t)buffer.data() & (config::defaultAlignment - 1)) == 0);
std::fill(buffer.begin(), buffer.end(), 1.0f); std::fill(buffer.begin(), buffer.end(), 1.0f);
REQUIRE( buffer.resize(smallSize) ); REQUIRE( buffer.resize(smallSize) );
REQUIRE( buffer.size() == smallSize ); REQUIRE( buffer.size() == smallSize );
REQUIRE(((size_t)buffer.data() & (sfz::Config::defaultAlignment - 1)) == 0); REQUIRE(((size_t)buffer.data() & (config::defaultAlignment - 1)) == 0);
REQUIRE( std::all_of(buffer.begin(), buffer.end(), [](auto value) { return value == 1.0f; }) ); REQUIRE( std::all_of(buffer.begin(), buffer.end(), [](auto value) { return value == 1.0f; }) );
REQUIRE( buffer.resize(bigSize) ); REQUIRE( buffer.resize(bigSize) );
REQUIRE( buffer.size() == bigSize ); REQUIRE( buffer.size() == bigSize );
REQUIRE(((size_t)buffer.data() & (sfz::Config::defaultAlignment - 1)) == 0); REQUIRE(((size_t)buffer.data() & (config::defaultAlignment - 1)) == 0);
for (auto i = 0; i < smallSize; ++i) for (auto i = 0; i < smallSize; ++i)
REQUIRE(buffer[i] == 1.0f); REQUIRE(buffer[i] == 1.0f);
} }
@ -72,15 +72,15 @@ TEST_CASE("[Buffer] Resize 4096 floats ")
Buffer<float> buffer(baseSize); Buffer<float> buffer(baseSize);
REQUIRE(!buffer.empty()); REQUIRE(!buffer.empty());
REQUIRE(buffer.size() == baseSize); REQUIRE(buffer.size() == baseSize);
REQUIRE(((size_t)buffer.data() & (sfz::Config::defaultAlignment - 1)) == 0); REQUIRE(((size_t)buffer.data() & (config::defaultAlignment - 1)) == 0);
std::fill(buffer.begin(), buffer.end(), 1.0f); std::fill(buffer.begin(), buffer.end(), 1.0f);
REQUIRE( buffer.resize(smallSize) ); REQUIRE( buffer.resize(smallSize) );
REQUIRE( buffer.size() == smallSize ); REQUIRE( buffer.size() == smallSize );
REQUIRE(((size_t)buffer.data() & (sfz::Config::defaultAlignment - 1)) == 0); REQUIRE(((size_t)buffer.data() & (config::defaultAlignment - 1)) == 0);
REQUIRE( std::all_of(buffer.begin(), buffer.end(), [](auto value) { return value == 1.0f; }) ); REQUIRE( std::all_of(buffer.begin(), buffer.end(), [](auto value) { return value == 1.0f; }) );
REQUIRE( buffer.resize(bigSize) ); REQUIRE( buffer.resize(bigSize) );
REQUIRE( buffer.size() == bigSize ); REQUIRE( buffer.size() == bigSize );
REQUIRE(((size_t)buffer.data() & (sfz::Config::defaultAlignment - 1)) == 0); REQUIRE(((size_t)buffer.data() & (config::defaultAlignment - 1)) == 0);
for (auto i = 0; i < smallSize; ++i) for (auto i = 0; i < smallSize; ++i)
REQUIRE(buffer[i] == 1.0f); REQUIRE(buffer[i] == 1.0f);
} }
@ -93,15 +93,15 @@ TEST_CASE("[Buffer] Resize 65536 floats ")
Buffer<float> buffer(baseSize); Buffer<float> buffer(baseSize);
REQUIRE(!buffer.empty()); REQUIRE(!buffer.empty());
REQUIRE(buffer.size() == baseSize); REQUIRE(buffer.size() == baseSize);
REQUIRE(((size_t)buffer.data() & (sfz::Config::defaultAlignment - 1)) == 0); REQUIRE(((size_t)buffer.data() & (config::defaultAlignment - 1)) == 0);
std::fill(buffer.begin(), buffer.end(), 1.0f); std::fill(buffer.begin(), buffer.end(), 1.0f);
REQUIRE( buffer.resize(smallSize) ); REQUIRE( buffer.resize(smallSize) );
REQUIRE( buffer.size() == smallSize ); REQUIRE( buffer.size() == smallSize );
REQUIRE(((size_t)buffer.data() & (sfz::Config::defaultAlignment - 1)) == 0); REQUIRE(((size_t)buffer.data() & (config::defaultAlignment - 1)) == 0);
REQUIRE( std::all_of(buffer.begin(), buffer.end(), [](auto value) { return value == 1.0f; }) ); REQUIRE( std::all_of(buffer.begin(), buffer.end(), [](auto value) { return value == 1.0f; }) );
REQUIRE( buffer.resize(bigSize) ); REQUIRE( buffer.resize(bigSize) );
REQUIRE( buffer.size() == bigSize ); REQUIRE( buffer.size() == bigSize );
REQUIRE(((size_t)buffer.data() & (sfz::Config::defaultAlignment - 1)) == 0); REQUIRE(((size_t)buffer.data() & (config::defaultAlignment - 1)) == 0);
for (auto i = 0; i < smallSize; ++i) for (auto i = 0; i < smallSize; ++i)
REQUIRE(buffer[i] == 1.0f); REQUIRE(buffer[i] == 1.0f);
} }