1#ifndef _VAE_BANK_MANAGER
2#define _VAE_BANK_MANAGER
8#include "../../external/tklb/src/types/audio/resampler/TResampler.hpp"
10namespace vae {
namespace core {
23 for (
auto& i : mixer.effects) {
24 if (i.name.empty()) {
continue; }
26 if (i.effect ==
nullptr) {
27 VAE_ERROR(
"Effect %s could not be loaded.", i.name.c_str())
30 i.effect->init(sampleRate);
40 void init(
const char* rootPath,
int sampleRate) {
49 void lock() { mMutex.lock(); }
53 const auto size =
mBanks.size();
54 if (size <= bank) {
return false; }
74 Result load(
const char* path,
Size size,
const char* rootPath,
int sampleRate) {
76 VAE_INFO(
"Loading bank from file %s%s", rootPath, path)
80 VAE_ERROR(
"Failed to load bank from file %s%s", rootPath, path)
83 return load(bank, sampleRate);
94 bank.
mixers[0].name =
"Bank Master";
97 for (
auto& m : bank.
mixers) {
104 if (s.resample && s.signal.sampleRate && s.signal.sampleRate != sampleRate) {
126 auto& bank =
mBanks[bankHandle];
128 if (bank.sources.size() <= source.
id) {
129 bank.sources.resize(source.
id + 1);
131 bank.sources[source.
id] = std::move(source);
137 auto& bank =
mBanks[bankHandle];
139 if (bank.events.size() <= event.
id) {
140 bank.events.resize(event.
id + 1);
142 bank.events[
event.id] = std::move(event);
151 auto& bank =
mBanks[bankHandle];
152 if (bank.mixers.size() <= mixer.
id) {
153 bank.mixers.resize(mixer.
id + 1);
155 bank.mixers[mixer.
id] = std::move(mixer);
170 if (
mBanks.size() <= bankHandle) {
171 VAE_WARN(
"Could not unload bank with handle %i", bankHandle)
174 auto& bank =
mBanks[bankHandle];
176 VAE_INFO(
"Unloading bank %s", bank.name.c_str())
178 for (
auto& m : bank.mixers) {
179 for (
auto& e : m.effects) {
180 if (e.effect !=
nullptr) {
bool resize(const Size length, uchar channels)
! Will not keep the contents! Resizes the buffer to the desired length and channel count.
ushort sampleRate
Only relevant for resampling and oversampling.
Basically a bad std::vector without exceptions which can also work with foreign memory.
static void resample(Buffer &buffer, const uint rateOut, const uchar quality=5)
Resamples the provided buffer from its sampleRate to the target rate.
Result load(const char *path, Size length, const char *rootPath, Bank &bank)
Load a bank.json and all wav files referenced in it.
Result load(const char *path, Size size, const char *rootPath, int sampleRate)
Result unloadFromId(BankHandle bankHandle)
Result addEvent(BankHandle bankHandle, Event &event)
void initMixer(Mixer &mixer, Size sampleRate)
HeapBuffer< Bank > & all()
Result addMixer(BankHandle bankHandle, Mixer &mixer)
HeapBuffer< Bank > mBanks
Bank & get(BankHandle bank)
void forEach(const Func &&func)
Iterate all loaded banks.
Result addSource(BankHandle bankHandle, Source &source, int sampleRate)
Result addBank(Bank &bank)
Result load(Bank &bank, int sampleRate)
void init(const char *rootPath, int sampleRate)
Will unload all the banks.
bool has(BankHandle bank)
static EffectBase * create(IdString &id)
constexpr Size MaxBlock
Maximum block size.
constexpr unsigned char MaxChannels
Maximum channel count used to pre allocate buffers.
constexpr int _VAE_SIZE_BANK_MANAGER
std::unique_lock< Mutex > Lock
Contains Typedefinitions and basic structures use by the public API and internally.
unsigned int Size
How the elements are addressed in the heapbuffer.
Result
Return Types for most engine functions.
@ ElementNotFound
Referenced data not found.
constexpr BankHandle InvalidBankHandle
Bank object containing Sources, Mixers and Events Can be loaded and unloaded at runtime.
HeapBuffer< Mixer > mixers
Audio Mixers which can have effects ! is presorted !
HeapBuffer< Source > sources
Audio sources defined.
An Event is used to control most of the eingines behavior.
MixerHandle id
The handle of the mixer the signal will be routed to.
AudioBuffer signal
Audio signal itself loaded by SourceLoader.
bool resample
Whether the sound will be resampled when loading it.
#define VAE_ERROR(msg,...)
#define VAE_WARN(msg,...)
#define VAE_INFO(msg,...)
#define VAE_PROFILER_SCOPE_NAMED(name)
Profiles a scope and names it.
#define VAE_PROFILER_MUTEX(type, name, desc)
#define VAE_PROFILER_SCOPE()
Profiles a scope.
Internal types used across VAE.
#define VAE_ASSERT(condition)