From 2a493873aeebb2a20b8d4b99e43782544bf168b9 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 5 Aug 2019 00:38:24 +0200 Subject: [PATCH] Cosmetics --- sources/FilePool.cpp | 31 ++++++++++++++++++++++++++++- sources/FilePool.h | 39 +++---------------------------------- sources/StereoBufferSSE.cpp | 10 +++++----- sources/Synth.cpp | 2 +- 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/sources/FilePool.cpp b/sources/FilePool.cpp index b62b2cb7..eb335b1f 100644 --- a/sources/FilePool.cpp +++ b/sources/FilePool.cpp @@ -1 +1,30 @@ -#include "FilePool.h" \ No newline at end of file +#include "FilePool.h" + +std::optional sfz::FilePool::getFileInformation(std::string_view filename) +{ + std::filesystem::path file { rootDirectory / filename }; + if (!std::filesystem::exists(file)) + return {}; + + SndfileHandle sndFile ( reinterpret_cast(file.c_str()) ); + FileInformation returnedValue; + returnedValue.end = static_cast(sndFile.frames()); + + SF_INSTRUMENT instrumentInfo; + sndFile.command(SFC_GET_INSTRUMENT, &instrumentInfo, sizeof(instrumentInfo)); + + if (instrumentInfo.loop_count == 1) + { + returnedValue.loopBegin = instrumentInfo.loops[0].start; + returnedValue.loopEnd = instrumentInfo.loops[0].end; + } + auto preloadedSize = std::min(returnedValue.end, static_cast(config::preloadSize)); + returnedValue.preloadedData = std::make_shared>(preloadedSize); + sndFile.readf(tempReadBuffer.data(), preloadedSize); + returnedValue.preloadedData->readInterleaved(tempReadBuffer.data(), preloadedSize); + preloadedData[filename] = returnedValue.preloadedData; + // char buffer [2048] ; + // sndFile.command(SFC_GET_LOG_INFO, buffer, sizeof(buffer)) ; + // DBG(buffer); + return returnedValue; +} \ No newline at end of file diff --git a/sources/FilePool.h b/sources/FilePool.h index 3adb1739..3ab962b7 100644 --- a/sources/FilePool.h +++ b/sources/FilePool.h @@ -14,10 +14,8 @@ class FilePool { public: FilePool() = default; - void setRootDirectory(const std::filesystem::path& directory) - { - rootDirectory = directory; - } + void setRootDirectory(const std::filesystem::path& directory) { rootDirectory = directory; } + size_t getNumPreloadedSamples() { return preloadedData.size(); } struct FileInformation { @@ -26,42 +24,11 @@ public: uint32_t loopEnd { Default::loopRange.getEnd() }; std::shared_ptr> preloadedData; }; - - std::optional getFileInformation(std::string_view filename) - { - std::filesystem::path file { rootDirectory / filename }; - if (!std::filesystem::exists(file)) - return {}; - - SndfileHandle sndFile ( reinterpret_cast(file.c_str()) ); - FileInformation returnedValue; - returnedValue.end = static_cast(sndFile.frames()); - - SF_INSTRUMENT instrumentInfo; - sndFile.command(SFC_GET_INSTRUMENT, &instrumentInfo, sizeof(instrumentInfo)); - - if (instrumentInfo.loop_count == 1) - { - returnedValue.loopBegin = instrumentInfo.loops[0].start; - returnedValue.loopEnd = instrumentInfo.loops[0].end; - } - auto preloadedSize = std::min(returnedValue.end, static_cast(config::preloadSize)); - returnedValue.preloadedData = std::make_shared>(preloadedSize); - sndFile.readf(tempReadBuffer.data(), preloadedSize); - returnedValue.preloadedData->readInterleaved(tempReadBuffer.data(), preloadedSize); - preloadedData[filename] = returnedValue.preloadedData; - // char buffer [2048] ; - // sndFile.command(SFC_GET_LOG_INFO, buffer, sizeof(buffer)) ; - // DBG(buffer); - return returnedValue; - } - size_t getNumPreloadedSamples() { return preloadedData.size(); } + std::optional getFileInformation(std::string_view filename); private: std::filesystem::path rootDirectory; Buffer tempReadBuffer { config::preloadSize * 2 }; // std::map>> preloadedData; absl::flat_hash_map>> preloadedData; }; - -static inline FilePool filePool; } \ No newline at end of file diff --git a/sources/StereoBufferSSE.cpp b/sources/StereoBufferSSE.cpp index d494b9a5..d126041f 100644 --- a/sources/StereoBufferSSE.cpp +++ b/sources/StereoBufferSSE.cpp @@ -47,12 +47,12 @@ void StereoBuffer::fill(float value) noexcept const __m128 mmValue = _mm_set_ps1(value); auto [lBegin, rBegin] = getChannels(); auto [lEnd, rEnd] = alignedEnds(); - auto mmLeft = reinterpret_cast<__m128 *>(lBegin); - auto mmRight = reinterpret_cast<__m128 *>(rBegin); - while (mmLeft < reinterpret_cast<__m128 *>(lEnd)) // we should only need to test a single channel + auto mmLeft = reinterpret_cast<__m128*>(lBegin); + auto mmRight = reinterpret_cast<__m128*>(rBegin); + while (mmLeft < reinterpret_cast<__m128*>(lEnd)) // we should only need to test a single channel { - _mm_store_ps(reinterpret_cast(mmLeft), mmValue); - _mm_store_ps(reinterpret_cast(mmRight), mmValue); + _mm_store_ps(reinterpret_cast(mmLeft), mmValue); + _mm_store_ps(reinterpret_cast(mmRight), mmValue); mmLeft++; mmRight++; } diff --git a/sources/Synth.cpp b/sources/Synth.cpp index c74176ad..188179df 100644 --- a/sources/Synth.cpp +++ b/sources/Synth.cpp @@ -156,7 +156,7 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename) currentRegion++; } - + DBG("Removed " << regions.size() - std::distance(regions.begin(), lastRegion) - 1 << " out of " << regions.size() << " regions."); regions.resize(std::distance(regions.begin(), lastRegion) + 1); return parserReturned;