diff --git a/sources/AudioBuffer.h b/sources/AudioBuffer.h index 8011d58f..0c33a175 100644 --- a/sources/AudioBuffer.h +++ b/sources/AudioBuffer.h @@ -3,7 +3,7 @@ #include "Helpers.h" #include "Globals.h" -template +template class AudioBuffer { @@ -38,6 +38,19 @@ public: 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 { return channels[channelIndex]; @@ -73,7 +86,7 @@ private: Buffer buffer {}; }; -template +template class SplitAudioBuffer { public: @@ -100,6 +113,19 @@ public: 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 { ASSERT(channelIndex >= 0); diff --git a/sources/Buffer.h b/sources/Buffer.h index 8c5e85cd..b5ffaa69 100644 --- a/sources/Buffer.h +++ b/sources/Buffer.h @@ -4,7 +4,7 @@ #include #include -template +template class Buffer { static_assert(std::is_arithmetic::value, "Type should be arithmetic"); diff --git a/sources/Globals.h b/sources/Globals.h index 91a8411e..193b91a9 100644 --- a/sources/Globals.h +++ b/sources/Globals.h @@ -3,7 +3,7 @@ namespace sfz { -namespace Config +namespace config { inline constexpr double defaultSampleRate { 48000 }; inline constexpr int defaultSamplesPerBlock { 1024 }; @@ -16,7 +16,13 @@ namespace Config inline constexpr double fastReleaseDuration { 0.01 }; inline constexpr char defineCharacter { '$' }; inline constexpr int oversamplingFactor { 2 }; - inline constexpr unsigned int defaultAlignment { 16 }; } // namespace config -} // namespace sfz \ No newline at end of file +} // namespace sfz + +namespace config +{ + inline constexpr unsigned int defaultAlignment { 16 }; + enum class VectorOperations { standard, sse, neon }; + inline constexpr VectorOperations vectorOperation { VectorOperations::standard }; +} // namespace config \ No newline at end of file diff --git a/sources/Parser.cpp b/sources/Parser.cpp index 9f895465..d66cab8b 100644 --- a/sources/Parser.cpp +++ b/sources/Parser.cpp @@ -103,7 +103,7 @@ void sfz::Parser::readSfzFile(const std::filesystem::path& fileName, std::vector std::string newString; newString.reserve(tmpView.length()); 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) { @@ -122,11 +122,11 @@ void sfz::Parser::readSfzFile(const std::filesystem::path& fileName, std::vector if (lastPos <= findPos) { - newString += sfz::Config::defineCharacter; + 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 diff --git a/tests/Buffer.cpp b/tests/Buffer.cpp index 18aa77fd..80467c1f 100644 --- a/tests/Buffer.cpp +++ b/tests/Buffer.cpp @@ -36,7 +36,7 @@ TEST_CASE("[Buffer] 10 floats ") Buffer buffer(10); REQUIRE(!buffer.empty()); 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) element = 0.0f; for (auto& element: buffer) @@ -51,15 +51,15 @@ TEST_CASE("[Buffer] Resize 10 floats ") Buffer buffer(baseSize); REQUIRE(!buffer.empty()); 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); REQUIRE( buffer.resize(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( buffer.resize(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) REQUIRE(buffer[i] == 1.0f); } @@ -72,15 +72,15 @@ TEST_CASE("[Buffer] Resize 4096 floats ") Buffer buffer(baseSize); REQUIRE(!buffer.empty()); 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); REQUIRE( buffer.resize(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( buffer.resize(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) REQUIRE(buffer[i] == 1.0f); } @@ -93,15 +93,15 @@ TEST_CASE("[Buffer] Resize 65536 floats ") Buffer buffer(baseSize); REQUIRE(!buffer.empty()); 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); REQUIRE( buffer.resize(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( buffer.resize(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) REQUIRE(buffer[i] == 1.0f); } \ No newline at end of file