Add a bufferpool to the resources
This commit is contained in:
parent
0cf7b01d6b
commit
406b7a08d7
3 changed files with 49 additions and 0 deletions
46
src/sfizz/BufferPool.h
Normal file
46
src/sfizz/BufferPool.h
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
|
||||||
|
// This code is part of the sfizz library and is licensed under a BSD 2-clause
|
||||||
|
// license. You should have receive a LICENSE.md file along with the code.
|
||||||
|
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "Config.h"
|
||||||
|
#include "Buffer.h"
|
||||||
|
#include <array>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace sfz
|
||||||
|
{
|
||||||
|
|
||||||
|
class BufferPool
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BufferPool()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void setBufferSize(unsigned bufferSize)
|
||||||
|
{
|
||||||
|
for (auto& buffer: buffers) {
|
||||||
|
// Trying to resize a buffer in use
|
||||||
|
ASSERT(buffer.use_count() != 1);
|
||||||
|
buffer->resize(bufferSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<sfz::Buffer<float>> getBuffer()
|
||||||
|
{
|
||||||
|
auto bufferIt = buffers.begin();
|
||||||
|
while (bufferIt < buffers.end()) {
|
||||||
|
if (bufferIt->use_count() == 1)
|
||||||
|
return *bufferIt;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No buffer found; debug message
|
||||||
|
DBG("[sfizz] No free buffer available!");
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::array<std::shared_ptr<sfz::Buffer<float>>, config::bufferPoolSize> buffers;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -28,6 +28,7 @@ namespace config {
|
||||||
constexpr float defaultSampleRate { 48000 };
|
constexpr float defaultSampleRate { 48000 };
|
||||||
constexpr int defaultSamplesPerBlock { 1024 };
|
constexpr int defaultSamplesPerBlock { 1024 };
|
||||||
constexpr int maxBlockSize { 8192 };
|
constexpr int maxBlockSize { 8192 };
|
||||||
|
constexpr int bufferPoolSize { 16 };
|
||||||
constexpr int preloadSize { 8192 };
|
constexpr int preloadSize { 8192 };
|
||||||
constexpr int loggerQueueSize { 256 };
|
constexpr int loggerQueueSize { 256 };
|
||||||
constexpr int voiceLoggerQueueSize { 256 };
|
constexpr int voiceLoggerQueueSize { 256 };
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "FilePool.h"
|
#include "FilePool.h"
|
||||||
|
#include "BufferPool.h"
|
||||||
#include "FilterPool.h"
|
#include "FilterPool.h"
|
||||||
#include "EQPool.h"
|
#include "EQPool.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
@ -17,6 +18,7 @@ class WavetableMulti;
|
||||||
|
|
||||||
struct Resources
|
struct Resources
|
||||||
{
|
{
|
||||||
|
BufferPool bufferPool;
|
||||||
MidiState midiState;
|
MidiState midiState;
|
||||||
Logger logger;
|
Logger logger;
|
||||||
FilePool filePool { logger };
|
FilePool filePool { logger };
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue