VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
main.cpp File Reference
#include "vae/vae.hpp"
#include <cstdlib>
#include <stdio.h>
#include <thread>
#include "../src/core/vae_engine.hpp"
#include "./vae_def.hpp"
Include dependency graph for main.cpp:

Go to the source code of this file.

Macros

#define VAE_FORCE_LOG
 

Functions

void eventTriggered (const EventCallbackData *data)
 
LocationDirection randomVec ()
 
void sleep (double ms)
 
void benchmarkBasicVoice (vae::core::Engine &engine)
 
void benchmark (vae::core::Engine &engine)
 
void filterTest (vae::core::Engine &engine)
 
int main ()
 

Variables

constexpr int test = sizeof(core::Engine)
 
constexpr int rate = 44100
 
const double step = 1.0 / double(rate)
 

Macro Definition Documentation

◆ VAE_FORCE_LOG

#define VAE_FORCE_LOG

Definition at line 1 of file main.cpp.

Function Documentation

◆ benchmark()

void benchmark ( vae::core::Engine engine)

Definition at line 45 of file main.cpp.

45 {
46 const int emitterCount = 10000;
47 EmitterHandle emitters[emitterCount];
48 for (auto& i : emitters) {
49 i = engine.createEmitter();
50 float spread = rand() / float(RAND_MAX);
51
52 engine.setEmitter(i, randomVec(), spread);
53 }
54 for (int i = 0; i < 2000; i++) {
55 sleep(2);
56 float t = i * 0.1;
57 engine.setEmitter(emitters[rand() % emitterCount], randomVec(), 0.5);
58 engine.fireGlobalEvent(vaeb::Bank1::JumpRand, emitters[rand() % emitterCount]);
59 if (i % 3 == 0) {
60 auto em = emitters[rand() % emitterCount];
62 }
63 engine.update();
64 }
65}
Result _VAE_PUBLIC_API 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_engine.hpp:510
EmitterHandle _VAE_PUBLIC_API createEmitter()
Creates an emitter and returns the handle.
Definition: vae_engine.hpp:570
void _VAE_PUBLIC_API update()
Update function needs to be called regularly to handle outbound events and other housekeeping.
Definition: vae_engine.hpp:317
Result _VAE_PUBLIC_API setEmitter(EmitterHandle emitter, const LocationDirection &locDir, float spread)
Set the Emitter position, orientation and spread.
Definition: vae_engine.hpp:619
LocationDirection randomVec()
Definition: main.cpp:22
void sleep(double ms)
Definition: main.cpp:29
const char *const emitters
LargeHandle EmitterHandle
Definition: vae.hpp:43
static constexpr vae::GlobalEventHandle JumpRand
Definition: vae_def.hpp:19
static constexpr vae::GlobalEventHandle Ambience1
Definition: vae_def.hpp:8
Here is the call graph for this function:

◆ benchmarkBasicVoice()

void benchmarkBasicVoice ( vae::core::Engine engine)

Definition at line 35 of file main.cpp.

35 {
36 auto emitter = engine.createEmitter();
37 for (int i = 0; i < 2000; i++) {
38 sleep(1);
40 engine.update();
41 }
42}
Here is the call graph for this function:

◆ eventTriggered()

void eventTriggered ( const EventCallbackData data)

Definition at line 12 of file main.cpp.

12 {
13 // printf("callback event %ifrom bank %i\n", (int) data->event, (int) data->bank);
14}
Here is the caller graph for this function:

◆ filterTest()

void filterTest ( vae::core::Engine engine)

Definition at line 67 of file main.cpp.

67 {
68 auto emitter = engine.createEmitter();
69 auto emitter2 = engine.createEmitter();
70 engine.fireGlobalEvent(vaeb::Bank2::Music, emitter2);
71 // engine.fireGlobalEvent(vaeb::Bank1::ShortSineLoop, emitter, 0.3);
72 for (int i = 0; i < 2000; i++) {
73 sleep(30);
74 // engine.setHighpass(emitter, sin(i * 0.1) * 0.5 + 0.5);
75 engine.setSpeed(emitter, sin(i * 0.3) * 0.2 + 1.0);
76 if (i % 100 == 0) {
77 // engine.fireGlobalEvent(vaeb::Bank1::JumpRand, emitter);
78 }
79 engine.setMixerEffectParameter(0, 3, 0, 3, sin(i) * 0.45 + 0.5);
80 }
81}
Result setMixerEffectParameter(BankHandle bank, MixerHandle mixer, Size index, Size param, Sample value)
Set the Mixer Effect Parameter.
Definition: vae_engine.hpp:719
void _VAE_PUBLIC_API setSpeed(EmitterHandle emitter, float speed)
Set the playback speed.
Definition: vae_engine.hpp:657
static constexpr vae::GlobalEventHandle Music
Definition: vae_def.hpp:12
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( )

very low settings

Definition at line 83 of file main.cpp.

83 {
84 EngineConfig config;
85 #ifdef _MSC_VER
86 config.rootPath = "../../../dev/";
87 #else
88 config.rootPath = "../../dev/";
89 #endif
91 config.internalSampleRate = rate;
92
93 /**
94 * @brief very low settings
95 */
96 // config.hrtfVoices = 0;
97 // config.voices = 8;
98 // config.preAllocatedEmitters = 128;
99 // config.virtualVoices = 32;
100 // config.bufferPeriods = 2;
101 // config.finishedVoiceQueueSize = 16;
102 // config.preferredBufferSize = 128;
103
104 core::Engine engine;
105 engine.init(config);
106 engine.setMasterVolume(4);
107
108 auto listener = engine.createListener();
109 engine.setListener(listener, {});
110 auto hrtf = engine.loadHRTF("hrtf.json");
111 engine.start();
112
113 auto result = engine.loadBank("bank1");
114 if (result != Result::Success) { return 1; }
115 result = engine.loadBank("bank2");
116 if (result != Result::Success) { return 1; }
117
118 // benchmarkBasicVoice(engine);
119 // benchmark(engine);
120 filterTest(engine);
121 engine.unloadBankFromId(0);
122
123 engine.stop();
124
125 return 0;
126}
Central class handling all outside communication.
Definition: vae_engine.hpp:48
Result _VAE_PUBLIC_API init(const EngineConfig &config={})
Initializes the engine and does most of the upfront allocations.
Definition: vae_engine.hpp:230
void _VAE_PUBLIC_API setMasterVolume(Sample volume)
Set the global output volume before the limiter.
Definition: vae_engine.hpp:543
Result _VAE_PUBLIC_API stop()
Stops processing and waits for audio thead to clean up.
Definition: vae_engine.hpp:286
Result _VAE_PUBLIC_API loadBank(const char *path, Size size=0)
Load bank from filesystem.
Definition: vae_engine.hpp:786
Result _VAE_PUBLIC_API loadHRTF(const char *path, Size size=0)
Definition: vae_engine.hpp:763
Result _VAE_PUBLIC_API start()
Tries to open default device and start audio thread.
Definition: vae_engine.hpp:251
Result _VAE_PUBLIC_API unloadBankFromId(BankHandle bankHandle)
Unload bank from handle.
Definition: vae_engine.hpp:835
ListenerHandle _VAE_PUBLIC_API createListener()
Create a Listener object.
Definition: vae_engine.hpp:742
Result _VAE_PUBLIC_API setListener(ListenerHandle listener, const LocationOrientation &locOr)
Set the position of a listener.
Definition: vae_engine.hpp:759
constexpr int rate
Definition: main.cpp:19
void eventTriggered(const EventCallbackData *data)
Definition: main.cpp:12
void filterTest(vae::core::Engine &engine)
Definition: main.cpp:67
Settings for the engine defined at EnginePimpl::init.
Definition: vae.hpp:157
const char * rootPath
Path where the bank files are located, needs to end with a trailing /.
Definition: vae.hpp:161
EventCallback eventCallback
Each time a event of the type emit gets triggered Used to get information about ending sounds and sim...
Definition: vae.hpp:174
Size internalSampleRate
Samplerate requested from device.
Definition: vae.hpp:168
Here is the call graph for this function:

◆ randomVec()

LocationDirection randomVec ( )

Definition at line 22 of file main.cpp.

22 {
23 float x = (rand() / float(RAND_MAX) - 0.5) * 10;
24 float y = (rand() / float(RAND_MAX) - 0.5) * 10;
25 float z = (rand() / float(RAND_MAX) - 0.5) * 10;
26 return {{ x, y, z }, {} };
27}
Here is the caller graph for this function:

◆ sleep()

void sleep ( double  ms)

Definition at line 29 of file main.cpp.

29 {
30 std::this_thread::sleep_for(std::chrono::duration<double, std::milli>(ms));
31}
Here is the caller graph for this function:

Variable Documentation

◆ rate

constexpr int rate = 44100
constexpr

Definition at line 19 of file main.cpp.

◆ step

const double step = 1.0 / double(rate)

Definition at line 20 of file main.cpp.

◆ test

constexpr int test = sizeof(core::Engine)
constexpr

Definition at line 17 of file main.cpp.