Migrate core infrastructure to VoidLibrary
This commit is contained in:
1 parent
53801f2b53
commit
2bdb63766d
65 files changed
+16109
-12011
No files matched your search
+50
-37
@@ -1,47 +1,60 @@
|
||||
#include "echoion/api/MemoryPool.hpp"
|
||||
#include "echoion/core/Logger.hpp"
|
||||
#include <MemoryPool.hpp>
|
||||
#include <format>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Api {
|
||||
namespace Echoion::Api
|
||||
{
|
||||
|
||||
AudioBufferPool& AudioBufferPool::instance() {
|
||||
static AudioBufferPool instance;
|
||||
return instance;
|
||||
}
|
||||
AudioBufferPool& AudioBufferPool::instance()
|
||||
{
|
||||
static AudioBufferPool instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void AudioBufferPool::initialize(size_t bufferSize, size_t poolSize) {
|
||||
bufferSize_ = bufferSize;
|
||||
pool_ = std::make_unique<MemoryPool<int16_t>>(bufferSize, poolSize);
|
||||
ECHOION_LOG_INFO(std::format("AudioBufferPool initialized: {} buffers of {} samples (~{} KB)",
|
||||
poolSize, bufferSize, (bufferSize * poolSize * sizeof(int16_t)) / 1024));
|
||||
}
|
||||
void AudioBufferPool::initialize(size_t bufferSize, size_t poolSize)
|
||||
{
|
||||
bufferSize_ = bufferSize;
|
||||
pool_ = std::make_unique<Void::BufferPool::BufferPool<int16_t>>();
|
||||
|
||||
void AudioBufferPool::shutdown() {
|
||||
pool_.reset();
|
||||
ECHOION_LOG_INFO("AudioBufferPool shutdown");
|
||||
}
|
||||
// Pre-warm the size-class bucket: acquire then immediately drop
|
||||
// `poolSize` buffers so subsequent acquireBuffer() calls reuse storage.
|
||||
{
|
||||
std::vector<AudioSampleBuffer> warm;
|
||||
warm.reserve(poolSize);
|
||||
for (size_t i = 0; i < poolSize; ++i) {
|
||||
warm.push_back(pool_->acquire(bufferSize));
|
||||
}
|
||||
} // buffers returned to the pool here
|
||||
|
||||
PooledPtr<int16_t> AudioBufferPool::acquireBuffer() {
|
||||
if (!pool_) {
|
||||
return PooledPtr<int16_t>();
|
||||
}
|
||||
|
||||
int16_t* ptr = pool_->acquire();
|
||||
if (!ptr) {
|
||||
ECHOION_LOG_WARNING("AudioBufferPool exhausted - consider increasing pool size");
|
||||
return PooledPtr<int16_t>();
|
||||
}
|
||||
|
||||
return PooledPtr<int16_t>(ptr, pool_.get());
|
||||
}
|
||||
ECHOION_LOG_INFO(std::format(
|
||||
"AudioBufferPool initialized: {} buffers of {} samples (~{} KB)",
|
||||
poolSize, bufferSize,
|
||||
(bufferSize * poolSize * sizeof(int16_t)) / 1024));
|
||||
}
|
||||
|
||||
size_t AudioBufferPool::getAvailableBuffers() const {
|
||||
if (!pool_) return 0;
|
||||
return pool_->available();
|
||||
}
|
||||
void AudioBufferPool::shutdown()
|
||||
{
|
||||
pool_.reset();
|
||||
ECHOION_LOG_INFO("AudioBufferPool shutdown");
|
||||
}
|
||||
|
||||
size_t AudioBufferPool::getTotalBuffers() const {
|
||||
if (!pool_) return 0;
|
||||
return pool_->capacity();
|
||||
}
|
||||
AudioSampleBuffer AudioBufferPool::acquireBuffer()
|
||||
{
|
||||
if (!pool_) {
|
||||
return AudioSampleBuffer{};
|
||||
}
|
||||
return pool_->acquire(bufferSize_);
|
||||
}
|
||||
|
||||
size_t AudioBufferPool::getAvailableBuffers() const
|
||||
{
|
||||
return pool_ ? pool_->stats().pooled : 0;
|
||||
}
|
||||
|
||||
size_t AudioBufferPool::getTotalBuffers() const
|
||||
{
|
||||
return pool_ ? static_cast<size_t>(pool_->stats().allocations) : 0;
|
||||
}
|
||||
|
||||
} // namespace Echoion::Api
|
||||
Reference in new issue
Block a user