VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
vae::core::BankManager Class Reference

Holds all the banks. More...

#include <vae_bank_manager.hpp>

Collaboration diagram for vae::core::BankManager:

Public Member Functions

void init (const char *rootPath, int sampleRate)
 Will unload all the banks. More...
 
HeapBuffer< Bank > & all ()
 
void lock ()
 
void unlock ()
 
Bankget (BankHandle bank)
 
bool has (BankHandle bank)
 
template<class Func >
void forEach (const Func &&func)
 Iterate all loaded banks. More...
 
Result load (const char *path, Size size, const char *rootPath, int sampleRate)
 
Result load (Bank &bank, int sampleRate)
 
Result addSource (BankHandle bankHandle, Source &source, int sampleRate)
 
Result addEvent (BankHandle bankHandle, Event &event)
 
Result addMixer (BankHandle bankHandle, Mixer &mixer)
 
Result addBank (Bank &bank)
 
Result unloadFromId (BankHandle bankHandle)
 
void unloadAll ()
 

Private Member Functions

void initMixer (Mixer &mixer, Size sampleRate)
 

Private Attributes

HeapBuffer< BankmBanks
 
BankLoader mBankLoader
 

Detailed Description

Holds all the banks.

Definition at line 15 of file vae_bank_manager.hpp.

Member Function Documentation

◆ addBank()

Result vae::core::BankManager::addBank ( Bank bank)
inline

Definition at line 159 of file vae_bank_manager.hpp.

159 {
160 if (mBanks.size() < bank.id) {
161 mBanks.resize(bank.id);
162 }
163 mBanks[bank.id] = std::move(bank);
164 return Result::Success;
165 }
HeapBuffer< Bank > mBanks
Here is the caller graph for this function:

◆ addEvent()

Result vae::core::BankManager::addEvent ( BankHandle  bankHandle,
Event event 
)
inline

Definition at line 135 of file vae_bank_manager.hpp.

135 {
137 auto& bank = mBanks[bankHandle];
138 Lock l(mMutex);
139 if (bank.events.size() <= event.id) {
140 bank.events.resize(event.id + 1);
141 }
142 bank.events[event.id] = std::move(event);
143 return Result::Success;
144 }
std::unique_lock< Mutex > Lock
Definition: vae_types.hpp:53
#define VAE_PROFILER_SCOPE()
Profiles a scope.
Here is the caller graph for this function:

◆ addMixer()

Result vae::core::BankManager::addMixer ( BankHandle  bankHandle,
Mixer mixer 
)
inline

Definition at line 146 of file vae_bank_manager.hpp.

146 {
148 // TODO init mixer effects
149 mixer.buffer.resize(StaticConfig::MaxBlock, StaticConfig::MaxChannels);
150 Lock l(mMutex);
151 auto& bank = mBanks[bankHandle];
152 if (bank.mixers.size() <= mixer.id) {
153 bank.mixers.resize(mixer.id + 1);
154 }
155 bank.mixers[mixer.id] = std::move(mixer);
156 return Result::Success;
157 }
constexpr Size MaxBlock
Maximum block size.
Definition: vae.hpp:276
constexpr unsigned char MaxChannels
Maximum channel count used to pre allocate buffers.
Definition: vae.hpp:268
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addSource()

Result vae::core::BankManager::addSource ( BankHandle  bankHandle,
Source source,
int  sampleRate 
)
inline

Definition at line 121 of file vae_bank_manager.hpp.

121 {
123 if (source.resample && source.signal.sampleRate && source.signal.sampleRate != sampleRate) {
124 tklb::ResamplerTpl<Sample, AudioBuffer>::resample(source.signal, sampleRate);
125 }
126 auto& bank = mBanks[bankHandle];
127 Lock l(mMutex);
128 if (bank.sources.size() <= source.id) {
129 bank.sources.resize(source.id + 1);
130 }
131 bank.sources[source.id] = std::move(source);
132 return Result::Success;
133 }
static void resample(Buffer &buffer, const uint rateOut, const uchar quality=5)
Resamples the provided buffer from its sampleRate to the target rate.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ all()

HeapBuffer< Bank > & vae::core::BankManager::all ( )
inline

Definition at line 48 of file vae_bank_manager.hpp.

48{ return mBanks; }

◆ forEach()

template<class Func >
void vae::core::BankManager::forEach ( const Func &&  func)
inline

Iterate all loaded banks.

Template Parameters
FuncCallable type
Parameters
funcCallable

Definition at line 65 of file vae_bank_manager.hpp.

65 {
66 VAE_PROFILER_SCOPE_NAMED("Foreach Bank")
67 Lock l(mMutex);
68 for (auto& i : mBanks) {
69 if (i.id == InvalidBankHandle) { continue; }
70 func(i);
71 }
72 }
constexpr BankHandle InvalidBankHandle
Definition: vae.hpp:57
#define VAE_PROFILER_SCOPE_NAMED(name)
Profiles a scope and names it.
Here is the caller graph for this function:

◆ get()

Bank & vae::core::BankManager::get ( BankHandle  bank)
inline

Definition at line 51 of file vae_bank_manager.hpp.

51{ return mBanks[bank]; }
Here is the caller graph for this function:

◆ has()

bool vae::core::BankManager::has ( BankHandle  bank)
inline

Definition at line 52 of file vae_bank_manager.hpp.

52 {
53 const auto size = mBanks.size();
54 if (size <= bank) { return false; }
55 return mBanks[bank].id != InvalidBankHandle;
56 }
Here is the caller graph for this function:

◆ init()

void vae::core::BankManager::init ( const char *  rootPath,
int  sampleRate 
)
inline

Will unload all the banks.

Parameters
rootPath
sampleRate

Definition at line 40 of file vae_bank_manager.hpp.

40 {
41 VAE_PROFILER_SCOPE_NAMED("Bankmanager Init")
42 for (auto& i : mBanks) {
43 if (i.id != InvalidBankHandle) { continue; }
44 unloadFromId(i.id);
45 }
46 }
Result unloadFromId(BankHandle bankHandle)
Here is the call graph for this function:

◆ initMixer()

void vae::core::BankManager::initMixer ( Mixer mixer,
Size  sampleRate 
)
inlineprivate

Definition at line 20 of file vae_bank_manager.hpp.

20 {
21 VAE_PROFILER_SCOPE_NAMED("Mixer Init")
22 mixer.buffer.resize(StaticConfig::MaxBlock, StaticConfig::MaxChannels);
23 for (auto& i : mixer.effects) {
24 if (i.name.empty()) { continue; }
25 i.effect = effect::EffectsFactory::create(i.name);
26 if (i.effect == nullptr) {
27 VAE_ERROR("Effect %s could not be loaded.", i.name.c_str())
28 continue;
29 }
30 i.effect->init(sampleRate);
31 }
32 }
void init(const char *rootPath, int sampleRate)
Will unload all the banks.
static EffectBase * create(IdString &id)
#define VAE_ERROR(msg,...)
Definition: vae_logger.hpp:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load() [1/2]

Result vae::core::BankManager::load ( Bank bank,
int  sampleRate 
)
inline

Definition at line 86 of file vae_bank_manager.hpp.

86 {
88 // TODO init mixer effects
89
90 if (bank.mixers.empty()) {
91 // Ensure there's a master channel per bank
92 bank.mixers.resize(1);
93 bank.mixers[0].id = 0;
94 bank.mixers[0].name = "Bank Master";
95 }
96
97 for (auto& m : bank.mixers) {
98 initMixer(m, sampleRate);
99 }
100
101 {
102 VAE_PROFILER_SCOPE_NAMED("Offline resampling")
103 for (auto& s : bank.sources) {
104 if (s.resample && s.signal.sampleRate && s.signal.sampleRate != sampleRate) {
106 }
107 }
108 }
109
110 {
111 Lock l(mMutex);
112 if (mBanks.size() < bank.id + 1) {
113 mBanks.resize(bank.id + 1);
114 }
115 mBanks[bank.id] = std::move(bank);
116 }
117 VAE_INFO("Bank %s loaded.", mBanks[bank.id].name.c_str())
118 return Result::Success;
119 }
void initMixer(Mixer &mixer, Size sampleRate)
Result
Return Types for most engine functions.
Definition: vae.hpp:73
#define VAE_INFO(msg,...)
Definition: vae_logger.hpp:84
Here is the call graph for this function:

◆ load() [2/2]

Result vae::core::BankManager::load ( const char *  path,
Size  size,
const char *  rootPath,
int  sampleRate 
)
inline

Definition at line 74 of file vae_bank_manager.hpp.

74 {
76 VAE_INFO("Loading bank from file %s%s", rootPath, path)
77 Bank bank;
78 auto result = mBankLoader.load(path, size, rootPath, bank);
79 if (result != Result::Success) {
80 VAE_ERROR("Failed to load bank from file %s%s", rootPath, path)
81 return result;
82 }
83 return load(bank, sampleRate);
84 }
Result load(const char *path, Size size, const char *rootPath, int sampleRate)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lock()

void vae::core::BankManager::lock ( )
inline

Definition at line 49 of file vae_bank_manager.hpp.

49{ mMutex.lock(); }
Here is the caller graph for this function:

◆ unloadAll()

void vae::core::BankManager::unloadAll ( )
inline

Definition at line 189 of file vae_bank_manager.hpp.

189 {
191 for (auto& i : mBanks) {
192 if (i.id == InvalidBankHandle) { continue; }
193 unloadFromId(i.id);
194 }
195 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unloadFromId()

Result vae::core::BankManager::unloadFromId ( BankHandle  bankHandle)
inline

Definition at line 167 of file vae_bank_manager.hpp.

167 {
169 Lock l(mMutex);
170 if (mBanks.size() <= bankHandle) {
171 VAE_WARN("Could not unload bank with handle %i", bankHandle)
173 }
174 auto& bank = mBanks[bankHandle];
175 VAE_ASSERT(bank.id == bankHandle)
176 VAE_INFO("Unloading bank %s", bank.name.c_str())
177 // TODO use a smart pointer or something
178 for (auto& m : bank.mixers) {
179 for (auto& e : m.effects) {
180 if (e.effect != nullptr) {
181 delete e.effect;
182 }
183 }
184 }
185 bank = { }; // should free all the memory
186 return Result::Success;
187 }
@ ElementNotFound
Referenced data not found.
#define VAE_WARN(msg,...)
Definition: vae_logger.hpp:85
#define VAE_ASSERT(condition)
Definition: vae_util.hpp:11
Here is the caller graph for this function:

◆ unlock()

void vae::core::BankManager::unlock ( )
inline

Definition at line 50 of file vae_bank_manager.hpp.

50{ mMutex.unlock(); }
Here is the caller graph for this function:

Member Data Documentation

◆ mBankLoader

BankLoader vae::core::BankManager::mBankLoader
private

Definition at line 18 of file vae_bank_manager.hpp.

◆ mBanks

HeapBuffer<Bank> vae::core::BankManager::mBanks
private

Definition at line 16 of file vae_bank_manager.hpp.


The documentation for this class was generated from the following file: