diff --git a/src/sfizz/FilePool.cpp b/src/sfizz/FilePool.cpp index a716d32b..f240d3dd 100644 --- a/src/sfizz/FilePool.cpp +++ b/src/sfizz/FilePool.cpp @@ -32,10 +32,10 @@ #include "AtomicGuard.h" #include "absl/types/span.h" #include "absl/strings/match.h" +#include "absl/memory/memory.h" #include #include #include -using namespace std::chrono_literals; template void readBaseFile(SndfileHandle& sndFile, sfz::AudioBuffer& output, uint32_t numFrames) @@ -57,13 +57,13 @@ void readBaseFile(SndfileHandle& sndFile, sfz::AudioBuffer& output, uint32_t template std::unique_ptr> readFromFile(SndfileHandle& sndFile, uint32_t numFrames, sfz::Oversampling factor) { - auto baseBuffer = std::make_unique>(); + auto baseBuffer = absl::make_unique>(); readBaseFile(sndFile, *baseBuffer, numFrames); if (factor == sfz::Oversampling::x1) return baseBuffer; - auto outputBuffer = std::make_unique>(sndFile.channels(), numFrames * static_cast(factor)); + auto outputBuffer = absl::make_unique>(sndFile.channels(), numFrames * static_cast(factor)); sfz::Oversampler oversampler { factor }; oversampler.stream(*baseBuffer, *outputBuffer); return outputBuffer; @@ -216,10 +216,9 @@ bool sfz::FilePool::preloadFile(const std::string& filename, uint32_t maxOffset) preloadedFiles[filename].preloadedData = readFromFile(sndFile, framesToLoad, oversamplingFactor); } } else { - preloadedFiles.insert_or_assign(filename, { - readFromFile(sndFile, framesToLoad, oversamplingFactor), - static_cast(oversamplingFactor) * static_cast(sndFile.samplerate()) - }); + const float sourceSampleRate { static_cast(oversamplingFactor) * static_cast(sndFile.samplerate()) }; + PreloadedFileHandle handle { readFromFile(sndFile, framesToLoad, oversamplingFactor), sourceSampleRate }; + preloadedFiles.insert_or_assign(filename, handle); } return true; @@ -272,7 +271,7 @@ void sfz::FilePool::tryToClearPromises() AtomicDisabler disabler { canAddPromisesToClear }; while (addingPromisesToClear) - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); for (auto& promise: promisesToClear) { if (promise->dataReady) @@ -284,7 +283,7 @@ void sfz::FilePool::clearingThread() { while (!quitThread) { tryToClearPromises(); - std::this_thread::sleep_for(50ms); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); } } @@ -302,7 +301,7 @@ void sfz::FilePool::loadingThread() noexcept } if (!promiseQueue.try_pop(promise)) { - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); continue; } @@ -326,7 +325,7 @@ void sfz::FilePool::loadingThread() noexcept while (!filledPromiseQueue.try_push(promise)) { DBG("[sfizz] Error enqueuing the promise for " << promise->filename << " in the filledPromiseQueue"); - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } promise.reset(); @@ -412,7 +411,7 @@ void sfz::FilePool::emptyFileLoadingQueues() noexcept { emptyQueue = true; while (emptyQueue) - std::this_thread::sleep_for(1ms); + std::this_thread::sleep_for(std::chrono::microseconds(100)); } void sfz::FilePool::waitForBackgroundLoading() noexcept @@ -421,11 +420,11 @@ void sfz::FilePool::waitForBackgroundLoading() noexcept // of the files we need to load still. // Spinlocking on the size of the background queue while (!promiseQueue.was_empty()){ - std::this_thread::sleep_for(0.1ms); + std::this_thread::sleep_for(std::chrono::microseconds(100)); } // Spinlocking on the threads possibly logging in the background while (threadsLoading > 0) { - std::this_thread::sleep_for(0.1ms); + std::this_thread::sleep_for(std::chrono::microseconds(100)); } } diff --git a/src/sfizz/FilePool.h b/src/sfizz/FilePool.h index 84b68687..c75e6c75 100644 --- a/src/sfizz/FilePool.h +++ b/src/sfizz/FilePool.h @@ -44,10 +44,11 @@ namespace sfz { using AudioBufferPtr = std::shared_ptr>; +// Strict C++11 disallows member initialization if aggregate initialization is to be used... struct PreloadedFileHandle { - std::shared_ptr> preloadedData {}; - float sampleRate { config::defaultSampleRate }; + std::shared_ptr> preloadedData; + float sampleRate; }; struct FilePromise @@ -78,7 +79,7 @@ struct FilePromise AudioBuffer fileData {}; float sampleRate { config::defaultSampleRate }; Oversampling oversamplingFactor { config::defaultOversamplingFactor }; - std::atomic_size_t availableFrames { 0 }; + std::atomic availableFrames { 0 }; std::atomic dataReady { false }; std::chrono::time_point creationTime;