VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
vae_mixer_processor.hpp
Go to the documentation of this file.
1#ifndef _VAE_MIXER_PROCESSOR
2#define _VAE_MIXER_PROCESSOR
3
4#include "../vae_types.hpp"
5#include "../pod/vae_bank.hpp"
6#include "../pod/vae_mixer.hpp"
7#include "../vae_voice_manager.hpp"
9
10namespace vae { namespace core {
11
14 public:
15 void init() {
17 }
18 /**
19 * @brief Process the mixers for a single bank
20 *
21 * @param manager
22 * @param banks
23 * @param frames
24 */
25 void mix(
26 VoiceManger& manager, Bank& bank, SampleIndex frames
27 ) {
28 VAE_PROFILER_SCOPE_NAMED("Bank Mixer Processor")
29 VAE_ASSERT(!bank.mixers.empty()) // can't happen
30
31 /**
32 * mix all non master mixers
33 * start from back since mixer can only write to mixer with
34 * a lower id than themselves to avoid recursion
35 */
36 for (Uint i = Uint(bank.mixers.size()) - 1; 0 < i; i--) {
37 VAE_PROFILER_SCOPE_NAMED("Process Mixer Channel")
38 auto& sourceMixer = bank.mixers[i];
39 // skip inactive mixers
40 if (sourceMixer.buffer.validSize() == 0) { continue; }
41
42 for (auto& effect : sourceMixer.effects) {
43 mEffectsProcessor.mix(effect, sourceMixer.buffer);
44 }
45
46 // Apply mixer volume
47 // TODO PERF VAE might be better to apply gain and mix in one go
48 sourceMixer.buffer.multiply(sourceMixer.gain);
49 auto& targetMixer = bank.mixers[sourceMixer.parent];
50
51 // mark mixer as active
52 targetMixer.buffer.setValidSize(frames);
53
54 targetMixer.buffer.add(sourceMixer.buffer);
55
56 // clear current mixer for next block
57 sourceMixer.buffer.set(0);
58 }
59
60 auto& masterMixer = bank.mixers[Mixer::MasterMixerHandle];
61 for (auto& effect : masterMixer.effects) {
62 mEffectsProcessor.mix(effect, masterMixer.buffer);
63 }
64 // Apply gain on master as well
65 masterMixer.buffer.multiply(masterMixer.gain);
66 // Master mixer will be mixed to the final output in the engine and then cleared
67 }
68 };
69
70} } // vae::core
71
72#endif // _VAE_MIXER_PROCESSOR
void mix(Effect &effect, ScratchBuffer &buffer)
void mix(VoiceManger &manager, Bank &bank, SampleIndex frames)
Process the mixers for a single bank.
There is only one voice pool and VAE and it's managed here.
AudioBuffer::Size SampleIndex
Definition: vae_types.hpp:87
unsigned int Uint
Definition: vae_types.hpp:46
Contains Typedefinitions and basic structures use by the public API and internally.
Definition: vae.hpp:31
Bank object containing Sources, Mixers and Events Can be loaded and unloaded at runtime.
Definition: vae_bank.hpp:14
HeapBuffer< Mixer > mixers
Audio Mixers which can have effects ! is presorted !
Definition: vae_bank.hpp:16
static constexpr MixerHandle MasterMixerHandle
This is the master mixer for a bank.
Definition: vae_mixer.hpp:13
#define VAE_PROFILER_SCOPE_NAMED(name)
Profiles a scope and names it.
#define VAE_ASSERT(condition)
Definition: vae_util.hpp:11