VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
vae_pimpl.hpp
Go to the documentation of this file.
1
2#ifndef _VAE_GEN_PIMPL
3#define _VAE_GEN_PIMPL
4#include "./vae.hpp"
5
6#if defined(_WIN32) || defined(__CYGWIN__)
7 #ifdef VAE_DLL_EXPORT
8 #define _VAE_API_EXPORT __declspec(dllexport) __stdcall
9 #else
10 #define _VAE_API_EXPORT __stdcall
11 #endif
12#else
13 #ifdef VAE_DLL_EXPORT
14 #define _VAE_API_EXPORT __attribute__((visibility("default")))
15 #else
16 #define _VAE_API_EXPORT
17 #endif
18#endif
19
20namespace vae {
21/**
22 * @brief Sealed of version of vae::core::Engine
23 * @details There are a few function, which aren't exported
24 * due to the fact that they would pull all the dependencies like
25 * tklb::AudioBuffer back in.
26 * @see vae::core::Engine
27 */
32public:
34
36
37 /**
38 * @brief Initializes the engine and does most of the upfront allocations. Run this before start !
39 * @details Everything will be allocated according to the provided config.
40 * Loading a Bank will still cause an allocation.
41 * If there are already banks loaded, they will be reloaded to have the correct samplerate.
42 * @see start
43 * @param config Optional config to setup the internals.
44 * @return Result
45 */
47 const EngineConfig& config = {}
48 );
49
50 /**
51 * @brief Tries to open default device and start audio thread. Call this after start.
52 * @see init
53 * @return Result
54 */
56
57 /**
58 * @brief Stops processing and waits for audio thead to clean up
59 * @return Result
60 */
62
63 /**
64 * @brief Update function needs to be called regularly to handle outbound events and other housekeeping.
65 * @details If this isn't called regularly events might be lost and chained events not fired.
66 * When EngineConfig::updateInAudioThread is true, this doesn't need to be called manually.
67 * @see EngineConfig::updateInAudioThread
68 */
69 void _VAE_API_EXPORT update ();
70
71 /**
72 * @brief Main mechanism to start and stop sounds
73 * @see Event
74 * @param bankHandle bank id where the event is provided
75 * @param eventHandle id of the event
76 * @param emitterHandle handle of the emitter, needed for spatial audio or controlling the voice
77 * @param gain optional volume factor
78 * @param mixerHandle optional id of mixer channel sound will be routed to, this will override the one set in the event
79 * @param listenerHandle For which listener this event will be adible for, default to all
80 * @return Result
81 */
83 BankHandle bankHandle,
84 EventHandle eventHandle,
85 EmitterHandle emitterHandle,
86 Sample gain = 1.0,
87 MixerHandle mixerHandle = InvalidMixerHandle,
88 ListenerHandle listenerHandle = AllListeners
89 );
90
91 /**
92 * @brief Works like fireEvent but with a global Event identifier
93 * @see fireEvent
94 * @param globalHandle The GlobalEventHandle combines both bank and event id
95 * @param emitterHandle optional handle of the emitter, needed for spatial audio
96 * @param gain optional volume factor
97 * @param mixerHandle id of mixer channel sound will be routed to, this will override the one set in the event
98 * @return Result
99 */
101 GlobalEventHandle globalHandle,
102 EmitterHandle emitterHandle,
103 Sample gain = 1.0,
104 MixerHandle mixerHandle = InvalidMixerHandle,
105 ListenerHandle listenerHandle = AllListeners
106 );
107
108 /**
109 * @brief Get the number of currently playing Voices
110 */
112
113 /**
114 * @brief Set the global output volume before the limiter.
115 * @details The engine can't clip, but if the output is too load
116 * the signal will be squashed in the limiter.
117 * @param volume 1.0 is the default, not interpolated for now
118 */
120 Sample volume
121 );
122
123 /**
124 * @brief Check if the compiled version matches
125 */
127 int major,
128 int minor,
129 int patch
130 );
131
132 /**
133 * @brief Creates an emitter and returns the handle
134 * @return EmitterHandle Random handle
135 */
137
138 /**
139 * @brief Emitter which triggers an event once a listener is close enough
140 *
141 * @param bank
142 * @param event
143 * @param maxDist
144 * @param locDir
145 * @param spread
146 * @return EmitterHandle Handle like a normal emitter
147 */
149 BankHandle bank,
150 EventHandle event,
151 float maxDist,
152 const LocationDirection& locDir,
153 float spread
154 );
155
156 /**
157 * @brief Adds an emitter with a custom handle, can be an internal ID for example
158 * @details migt be desireable to make EmitterHandle the same size as a pointer
159 * so this can simply be the pointer of the entity that is associated with it.
160 * @param h
161 * @return Result
162 */
165 );
166
167 /**
168 * @brief Unregister a emiter an kill all its voices
169 * @param h
170 * @return Result
171 */
174 );
175
176 /**
177 * @brief Set the Emitter position, orientation and spread
178 * @param emitter The emitter
179 * @param locDir The desired location
180 * @param spread The width of the panning (if it's spatial and not HRTF)
181 * @return Result
182 */
184 EmitterHandle emitter,
185 const LocationDirection& locDir,
186 float spread
187 );
188
189 /**
190 * @brief Stop all voices from emitter.
191 * @param emitter
192 * @return Result
193 */
195 EmitterHandle emitter
196 );
197
198 /**
199 * @brief Sets the volume of all active voices with this emitter
200 * @param emitter
201 * @param gain
202 */
204 EmitterHandle emitter,
205 Sample gain
206 );
207
208 /**
209 * @brief Set the current time of all voices with the emitter.
210 * @param emitter
211 * @param time Time in samples
212 */
213 void _VAE_API_EXPORT seek (
214 EmitterHandle emitter,
215 Size time
216 );
217
218 /**
219 * @brief Set the playback speed
220 * @param emitter
221 * @param speed 1.0 is the default speed, pitch will be affected as well.
222 */
224 EmitterHandle emitter,
225 float speed
226 );
227
228 /**
229 * @brief Simple lowpass filter for the voices
230 * @param emitter
231 * @param cutoff 0-1. 0 doesn't filter, 1 filter the wholespektrum
232 */
234 EmitterHandle emitter,
235 float cutoff
236 );
237
238 /**
239 * @brief Simple highpass filter for the voices
240 * @param emitter
241 * @param cutoff 0-1. 0 doesn't filter, 1 filter the wholespektrum
242 */
244 EmitterHandle emitter,
245 float cutoff
246 );
247
248 /**
249 * @brief Create a Listener object
250 * @details TODO make listener 0 implicit
251 * @return ListenerHandle
252 */
254
255 /**
256 * @brief Unregister listener
257 * @param listener
258 */
260 ListenerHandle listener
261 );
262
263 /**
264 * @brief Set the position of a listener
265 * @param listener
266 * @return Result
267 */
269 ListenerHandle listener,
270 const LocationOrientation& locOr
271 );
272
274 const char* path,
275 Size size = 0
276 );
277
278 /**
279 * @brief Load bank from filesystem.
280 * @details This operation might take a little time but won't lock the audio thread
281 * until the bank is inserted. This should be safe to do at any time.
282 * @param path
283 * @return Result
284 */
286 const char* path,
287 Size size = 0
288 );
289
290 /**
291 * @brief Unload bank from handle.
292 * Locks audio thread and stops all voices from that bank.
293 * @param bankHandle
294 * @return Result
295 */
297 BankHandle bankHandle
298 );
299
300 /**
301 * @brief Unload every bank and data associated with it
302 */
304
305}; // class EnginePimpl
306
307} // namespace vae
308#endif // _VAE_GEN_PIMPL
Sealed of version of vae::core::Engine.
Definition: vae_pimpl.hpp:28
static EnginePimpl *_VAE_API_EXPORT create()
Definition: vae_pimpl.cpp:5
EnginePimpl(const EnginePimpl &)
Result _VAE_API_EXPORT loadBank(const char *path, Size size=0)
Load bank from filesystem.
Definition: vae_pimpl.cpp:255
EmitterHandle _VAE_API_EXPORT createAutoEmitter(BankHandle bank, EventHandle event, float maxDist, const LocationDirection &locDir, float spread)
Emitter which triggers an event once a listener is close enough.
Definition: vae_pimpl.cpp:107
void _VAE_API_EXPORT unloadAllBanks()
Unload every bank and data associated with it.
Definition: vae_pimpl.cpp:275
EmitterHandle _VAE_API_EXPORT createEmitter()
Creates an emitter and returns the handle.
Definition: vae_pimpl.cpp:102
Result _VAE_API_EXPORT loadHRTF(const char *path, Size size=0)
Definition: vae_pimpl.cpp:244
Result _VAE_API_EXPORT addEmitter(EmitterHandle h)
Adds an emitter with a custom handle, can be an internal ID for example.
Definition: vae_pimpl.cpp:124
ListenerHandle _VAE_API_EXPORT createListener()
Create a Listener object.
Definition: vae_pimpl.cpp:219
void _VAE_API_EXPORT setMasterVolume(Sample volume)
Set the global output volume before the limiter.
Definition: vae_pimpl.cpp:80
void _VAE_API_EXPORT setVolume(EmitterHandle emitter, Sample gain)
Sets the volume of all active voices with this emitter.
Definition: vae_pimpl.cpp:164
void _VAE_API_EXPORT update()
Update function needs to be called regularly to handle outbound events and other housekeeping.
Definition: vae_pimpl.cpp:34
Result _VAE_API_EXPORT init(const EngineConfig &config={})
Initializes the engine and does most of the upfront allocations.
Definition: vae_pimpl.cpp:15
void _VAE_API_EXPORT setSpeed(EmitterHandle emitter, float speed)
Set the playback speed.
Definition: vae_pimpl.cpp:186
void _VAE_API_EXPORT seek(EmitterHandle emitter, Size time)
Set the current time of all voices with the emitter.
Definition: vae_pimpl.cpp:175
Result _VAE_API_EXPORT stop()
Stops processing and waits for audio thead to clean up.
Definition: vae_pimpl.cpp:29
Result _VAE_API_EXPORT removeEmitter(EmitterHandle h)
Unregister a emiter an kill all its voices.
Definition: vae_pimpl.cpp:133
Result _VAE_API_EXPORT setEmitter(EmitterHandle emitter, const LocationDirection &locDir, float spread)
Set the Emitter position, orientation and spread.
Definition: vae_pimpl.cpp:142
bool _VAE_API_EXPORT checkVersion(int major, int minor, int patch)
Check if the compiled version matches.
Definition: vae_pimpl.cpp:89
Result _VAE_API_EXPORT unloadBankFromId(BankHandle bankHandle)
Unload bank from handle.
Definition: vae_pimpl.cpp:266
void _VAE_API_EXPORT destroy()
Definition: vae_pimpl.cpp:10
Result _VAE_API_EXPORT fireEvent(BankHandle bankHandle, EventHandle eventHandle, EmitterHandle emitterHandle, Sample gain=1.0, MixerHandle mixerHandle=InvalidMixerHandle, ListenerHandle listenerHandle=AllListeners)
Main mechanism to start and stop sounds.
Definition: vae_pimpl.cpp:39
int _VAE_API_EXPORT getActiveVoiceCount()
Get the number of currently playing Voices.
Definition: vae_pimpl.cpp:75
void _VAE_API_EXPORT setHighpass(EmitterHandle emitter, float cutoff)
Simple highpass filter for the voices.
Definition: vae_pimpl.cpp:208
Result _VAE_API_EXPORT stopEmitter(EmitterHandle emitter)
Stop all voices from emitter.
Definition: vae_pimpl.cpp:155
Result _VAE_API_EXPORT removeListener(ListenerHandle listener)
Unregister listener.
Definition: vae_pimpl.cpp:224
void _VAE_API_EXPORT setLowpass(EmitterHandle emitter, float cutoff)
Simple lowpass filter for the voices.
Definition: vae_pimpl.cpp:197
Result _VAE_API_EXPORT fireGlobalEvent(GlobalEventHandle globalHandle, EmitterHandle emitterHandle, Sample gain=1.0, MixerHandle mixerHandle=InvalidMixerHandle, ListenerHandle listenerHandle=AllListeners)
Works like fireEvent but with a global Event identifier.
Definition: vae_pimpl.cpp:58
Result _VAE_API_EXPORT setListener(ListenerHandle listener, const LocationOrientation &locOr)
Set the position of a listener.
Definition: vae_pimpl.cpp:233
Result _VAE_API_EXPORT start()
Tries to open default device and start audio thread.
Definition: vae_pimpl.cpp:24
Contains Typedefinitions and basic structures use by the public API and internally.
Definition: vae.hpp:31
constexpr ListenerHandle AllListeners
Will address all listeners.
Definition: vae.hpp:60
unsigned int Size
How the elements are addressed in the heapbuffer.
Definition: vae.hpp:33
float Sample
Default sample types used where ever possible, changing this means the engine needs to be recompiled,...
Definition: vae.hpp:32
SmallHandle MixerHandle
Definition: vae.hpp:44
SmallHandle BankHandle
Definition: vae.hpp:40
SmallHandle ListenerHandle
Definition: vae.hpp:45
LargeHandle EmitterHandle
Definition: vae.hpp:43
GenericHandle EventHandle
The handle used to address events within a bank.
Definition: vae.hpp:41
Result
Return Types for most engine functions.
Definition: vae.hpp:73
constexpr MixerHandle InvalidMixerHandle
Definition: vae.hpp:58
LargeHandle GlobalEventHandle
Used to globally address events, holds space for BankHandle and EventHandle.
Definition: vae.hpp:47
Settings for the engine defined at EnginePimpl::init.
Definition: vae.hpp:157
Contains all public API types for VAE.
#define _VAE_API_EXPORT
Definition: vae_pimpl.hpp:16