#include "echoion/core/Logger.hpp" #include #include #include namespace Echoion::Api { AudioBufferPool& AudioBufferPool::instance() { static AudioBufferPool instance; return instance; } void AudioBufferPool::initialize(size_t bufferSize, size_t poolSize) { bufferSize_ = bufferSize; pool_ = std::make_unique>(); // Pre-warm the size-class bucket: acquire then immediately drop // `poolSize` buffers so subsequent acquireBuffer() calls reuse storage. { std::vector warm; warm.reserve(poolSize); for (size_t i = 0; i < poolSize; ++i) { warm.push_back(pool_->acquire(bufferSize)); } } // buffers returned to the pool here ECHOION_LOG_INFO(std::format( "AudioBufferPool initialized: {} buffers of {} samples (~{} KB)", poolSize, bufferSize, (bufferSize * poolSize * sizeof(int16_t)) / 1024)); } void AudioBufferPool::shutdown() { pool_.reset(); ECHOION_LOG_INFO("AudioBufferPool shutdown"); } 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(pool_->stats().allocations) : 0; } } // namespace Echoion::Api