Added logging in callbacks and loading threads
This commit is contained in:
parent
93b07dfac9
commit
2588ec2822
4 changed files with 19 additions and 9 deletions
|
|
@ -84,7 +84,8 @@ void streamFromFile(SndfileHandle& sndFile, uint32_t numFrames, sfz::Oversamplin
|
||||||
oversampler.stream(*baseBuffer, output, filledFrames);
|
oversampler.stream(*baseBuffer, output, filledFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
sfz::FilePool::FilePool()
|
sfz::FilePool::FilePool(sfz::Logger& logger)
|
||||||
|
: logger(logger)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < config::numBackgroundThreads; ++i)
|
for (int i = 0; i < config::numBackgroundThreads; ++i)
|
||||||
threadPool.emplace_back( &FilePool::loadingThread, this );
|
threadPool.emplace_back( &FilePool::loadingThread, this );
|
||||||
|
|
@ -244,8 +245,9 @@ void sfz::FilePool::loadingThread() noexcept
|
||||||
}
|
}
|
||||||
|
|
||||||
threadsLoading++;
|
threadsLoading++;
|
||||||
const auto waitDuration = std::chrono::high_resolution_clock::now() - promise->creationTime;
|
const auto loadStartTime = std::chrono::high_resolution_clock::now();
|
||||||
[[maybe_unused]] const auto waitDurationMillis = std::chrono::duration<double,std::milli>(waitDuration).count();
|
const auto waitDuration = loadStartTime - promise->creationTime;
|
||||||
|
logger.logFileWaitTime(waitDuration);
|
||||||
|
|
||||||
fs::path file { rootDirectory / std::string(promise->filename) };
|
fs::path file { rootDirectory / std::string(promise->filename) };
|
||||||
SndfileHandle sndFile(file.string().c_str());
|
SndfileHandle sndFile(file.string().c_str());
|
||||||
|
|
@ -256,11 +258,12 @@ void sfz::FilePool::loadingThread() noexcept
|
||||||
const auto frames = static_cast<uint32_t>(sndFile.frames());
|
const auto frames = static_cast<uint32_t>(sndFile.frames());
|
||||||
streamFromFile<float>(sndFile, frames, oversamplingFactor, promise->fileData, &promise->availableFrames);
|
streamFromFile<float>(sndFile, frames, oversamplingFactor, promise->fileData, &promise->availableFrames);
|
||||||
promise->dataReady = true;
|
promise->dataReady = true;
|
||||||
|
const auto loadDuration = std::chrono::high_resolution_clock::now() - loadStartTime;
|
||||||
|
logger.logFileLoadTime(loadDuration, frames, promise->filename);
|
||||||
|
|
||||||
threadsLoading--;
|
threadsLoading--;
|
||||||
|
|
||||||
const auto duration = std::chrono::high_resolution_clock::now() - promise->creationTime;
|
|
||||||
[[maybe_unused]] const auto durationMillis = std::chrono::duration<double,std::milli>(duration).count();
|
|
||||||
// DBG("Promise filled in " << durationMillis << " ms (waiting for " << waitDurationMillis << " ms)");
|
|
||||||
|
|
||||||
while (!filledPromiseQueue.try_push(promise)) {
|
while (!filledPromiseQueue.try_push(promise)) {
|
||||||
DBG("[sfizz] Error enqueuing the promise for " << promise->filename << " in the filledPromiseQueue");
|
DBG("[sfizz] Error enqueuing the promise for " << promise->filename << " in the filledPromiseQueue");
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
#include <absl/types/optional.h>
|
#include <absl/types/optional.h>
|
||||||
#include "absl/strings/string_view.h"
|
#include "absl/strings/string_view.h"
|
||||||
#include "atomic_queue/atomic_queue.h"
|
#include "atomic_queue/atomic_queue.h"
|
||||||
|
#include "Logger.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <sndfile.hh>
|
#include <sndfile.hh>
|
||||||
|
|
@ -111,7 +112,7 @@ public:
|
||||||
* This creates the background threads based on config::numBackgroundThreads
|
* This creates the background threads based on config::numBackgroundThreads
|
||||||
* as well as the garbage collection thread.
|
* as well as the garbage collection thread.
|
||||||
*/
|
*/
|
||||||
FilePool();
|
FilePool(Logger& logger);
|
||||||
|
|
||||||
~FilePool();
|
~FilePool();
|
||||||
/**
|
/**
|
||||||
|
|
@ -212,6 +213,7 @@ public:
|
||||||
*/
|
*/
|
||||||
void waitForBackgroundLoading() noexcept;
|
void waitForBackgroundLoading() noexcept;
|
||||||
private:
|
private:
|
||||||
|
Logger& logger;
|
||||||
fs::path rootDirectory;
|
fs::path rootDirectory;
|
||||||
void loadingThread() noexcept;
|
void loadingThread() noexcept;
|
||||||
void clearingThread();
|
void clearingThread();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ namespace sfz
|
||||||
{
|
{
|
||||||
struct Resources
|
struct Resources
|
||||||
{
|
{
|
||||||
FilePool filePool;
|
|
||||||
Logger logger;
|
Logger logger;
|
||||||
|
FilePool filePool { logger };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -377,6 +377,8 @@ void sfz::Synth::setSampleRate(float sampleRate) noexcept
|
||||||
void sfz::Synth::renderBlock(AudioSpan<float> buffer) noexcept
|
void sfz::Synth::renderBlock(AudioSpan<float> buffer) noexcept
|
||||||
{
|
{
|
||||||
ScopedFTZ ftz;
|
ScopedFTZ ftz;
|
||||||
|
const auto callbackStartTime = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
buffer.fill(0.0f);
|
buffer.fill(0.0f);
|
||||||
|
|
||||||
resources.filePool.cleanupPromises();
|
resources.filePool.cleanupPromises();
|
||||||
|
|
@ -397,6 +399,9 @@ void sfz::Synth::renderBlock(AudioSpan<float> buffer) noexcept
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.applyGain(db2mag(volume));
|
buffer.applyGain(db2mag(volume));
|
||||||
|
|
||||||
|
const auto callbackDuration = std::chrono::high_resolution_clock::now() - callbackStartTime;
|
||||||
|
resources.logger.logCallbackTime(callbackDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sfz::Synth::noteOn(int delay, int noteNumber, uint8_t velocity) noexcept
|
void sfz::Synth::noteOn(int delay, int noteNumber, uint8_t velocity) noexcept
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue