12#ifndef _VAE_VOICE_MANAGER
13#define _VAE_VOICE_MANAGER
22#include "./../../include/vae/vae.hpp"
29namespace vae {
namespace core {
86 if (!func(i, index)) {
101 if (!func(v)) {
continue; };
135 Size searchStartIndex;
140 searchStartIndex = 0;
152 Size potentialVirtual = ~0;
154 for (
Size i = searchStartIndex; i < searchEndIndex; i++) {
156 if (v.critical) {
continue; }
160 searchStartIndex = i;
165 if (v.gain <= lowestGain) {
167 potentialVirtual = i;
171 if (potentialVirtual < searchEndIndex) {
173 searchStartIndex = potentialVirtual;
178 for (
Size i = searchStartIndex; i < searchEndIndex; i++) {
183 v.source =
event.source;
185 v.listener = listener;
197 v.mixer =
event.mixer;
200 v.gain =
event.gain * gain;
202 v.attenuate =
event.attenuate;
209 v.spatialized =
event.spatial;
234 VAE_DEBUG_VOICES(
"Voice starvation. Can't start voice from event %i:%i", event.
id, bank)
261 VAE_DEBUG_VOICES(
"Virtualized voice from event %i:%i\tactive: %i\tincative: %i",
286 if (virt.HRTF == v.
HRTF) {
287 virt.started =
false;
291 VAE_DEBUG_VOICES(
"Revived voice from event %i:%i\tactive: %i\tincative: %i",
370 template <
typename T>
377 if ((&v)->*member != handle) {
continue; }
385 if ((&v)->*member != handle) {
continue; }
392 template <
typename T>
396 if(v.emitter == emitter) {
397 (&v)->*member = value;
402 template <
typename T>
407 if(v.emitter == emitter) {
Basically a bad std::vector without exceptions which can also work with foreign memory.
There is only one voice pool and VAE and it's managed here.
Size getActiveVoiceCount() const
VoicePan & getVoicePan(Size index)
Result stop(T handle, T Voice::*member, const EmitterHandle emitter=InvalidEmitterHandle)
Stop voice based on a member value and optionally an emitter.
HeapBuffer< Voice > mVoices
Currently playing voice are here.
Size mHRTFVoiceCount
Number of voices reserved for hrtf.
Result stop(Voice &v)
Stops a voice.
Result play(Event &event, const BankHandle bank, const Sample gain, const EmitterHandle emitter, const ListenerHandle listener, const MixerHandle mixer)
void setVoiceProperty(EmitterHandle emitter, T VoiceFilter::*member, const T &value)
Size mHighestFinishedVoice
TODO bad as well.
Size mActiveHRTFVoices
Number of ative hrtf voices.
Size mActiveVoices
Number of currently playing voices.
void setVoiceProperty(EmitterHandle emitter, T Voice::*member, const T &value)
HeapBuffer< Voice > & all()
VoiceFilter & getVoiceFilter(Size index)
HeapBuffer< VoiceFilter > mVoiceFiltered
Data needed for filtering is here.
void forEachVoice(const Func &&func)
Callback provided to iterate voices, needs to return a bool to indicate when a voice needs to be stop...
void forEachFinishedVoice(const Func &&func)
Size mStarvedVoices
Voices which could not play since no other voice could be killed and are lost forever.
Size mFinishedPending
Voices in mFinishedVoiceQueue.
HeapBuffer< Voice > & finished()
HeapBuffer< Voice > mVirtualVoices
Result makeVirtual(Voice &v)
makes provided voice virtual
HeapBuffer< Voice > mFinishedVoiceQueue
voices that finished playing are queued here
Size mInactiveVoices
Number of currenly virtual voices.
Size mHighestVoice
TODO bad.
Result init(const EngineConfig &config)
Size mStoppedQueueOverflow
Voice which did not fit mFinishedVoiceQueue and could not triggered chained events.
HeapBuffer< VoicePan > mVoicePans
Interpolation data for the panning algorithm or manual panning data.
T max(const T &v1, const T &v2)
const char *const voiceHRTFCount
const char *const starvedVoiceCount
const char *const voiceCount
const char *const voiceVirtualCount
const char *const stoppedVoiceOverflow
const char *const voiceFinishedCount
constexpr int _VAE_SIZE_VOICE_MANAGER
Contains Typedefinitions and basic structures use by the public API and internally.
constexpr EmitterHandle InvalidEmitterHandle
unsigned int Size
How the elements are addressed in the heapbuffer.
float Sample
Default sample types used where ever possible, changing this means the engine needs to be recompiled,...
constexpr SourceHandle InvalidSourceHandle
SmallHandle ListenerHandle
constexpr EventHandle InvalidEventHandle
LargeHandle EmitterHandle
Result
Return Types for most engine functions.
@ VoiceStarvation
Could not play sound because of voice limit.
constexpr MixerHandle InvalidMixerHandle
Settings for the engine defined at EnginePimpl::init.
Size finishedVoiceQueueSize
Size of the voice queue for finished voices which need to trigger other events on_end when updating t...
Size voices
Hard limit on concurrent voices, can't be 0 or lower than hrtfVoices.
Size hrtfVoices
Amount of HRTF panned voices audible at any given time.
Size virtualVoices
Hard limit on virtal voices.
An Event is used to control most of the eingines behavior.
bool force_mixer
Prevents overriding the mixer from chained events or fireEvent.
bool HRTF
Listener and event has to have hrtf set.
Additional data needed for filtered voices.
SourceHandle source
If invalid, means voice is not playing.
bool chainedEvents
If this voice triggers events after it stopped playing.
EventHandle event
Which event triggered the voice to be played.
BankHandle bank
Which bank it belongs to.
bool HRTF
If the voice should be rendered using hrtfs.
Data to interpolate panning between blocks or do manual pan.
#define VAE_DEBUG_VOICES(msg,...)
#define VAE_PROFILER_SCOPE_NAMED(name)
Profiles a scope and names it.
#define VAE_PROFILER_SCOPE()
Profiles a scope.
#define VAE_PROFILER_PLOT(name, value)
Records a value.
Internal types used across VAE.