Saga
Saga Game Engine
Loading...
Searching...
No Matches
audioEngine.h
Go to the documentation of this file.
1#pragma once
2
3
4#include "fmod.h"
5#include "fmod_studio.h"
6#include <map>
7#include <string>
8#include <glm/vec3.hpp>
9#include <memory>
10
11namespace Saga {
18 FMOD_STUDIO_SYSTEM* studioSystem = nullptr;
19
20 typedef std::map<std::string, FMOD_STUDIO_EVENTDESCRIPTION *> EventMap;
21 typedef std::map<std::string, FMOD_STUDIO_BANK*> BankMap;
22
27 };
28
34 using AudioEventInstance = FMOD_STUDIO_EVENTINSTANCE*;
35
40 namespace AudioEngine {
43
47 const int maxChannels = 32;
48
52 float value;
56 };
57
60 glm::vec3 position, velocity, forward, up;
61
67
76 EventAttributes(glm::vec3 position, glm::vec3 velocity, glm::vec3 forward, glm::vec3 up);
77 };
78
85 bool init();
86
91 void update();
92
99 bool release();
100
108 void loadBank(const std::string& bankFileName, FMOD_STUDIO_LOAD_BANK_FLAGS flags = FMOD_STUDIO_LOAD_BANK_NORMAL);
109
115 void unloadBank(const std::string& bankName);
116
125 void loadEvent(const std::string& eventName, bool loadSampleData = false);
126
135 void loadSampleData(const std::string& eventName);
136
143 void unloadSampleData(const std::string& eventName);
144
151 AudioEventInstance playEvent(const std::string& eventName);
152
159 AudioEventInstance createInstance(const std::string& eventName);
160
166 void playEvent(AudioEventInstance event);
167
174 void stopEvent(AudioEventInstance event, bool immediate = false);
175
182
188 void releaseAllEventInstances(const std::string& eventName);
189
197 void unloadEvent(const std::string& eventName, bool unloadSampleData = false);
198
206 void setParameter(AudioEventInstance instance, const std::string& parameterName, float value);
207
215 ParameterValue getParameter(AudioEventInstance instance, const std::string& parameterName);
216
224 void setLabeledParameter(AudioEventInstance instance, const std::string& parameterName, std::string label);
225
233 std::string getLabeledParameter(AudioEventInstance instance, const std::string& parameterName);
234
241 void setGlobalParameter(const std::string& parameterName, float value);
242
250 ParameterValue getGlobalParameter(const std::string& parameterName);
251
258 void setGlobalLabeledParameter(const std::string& parameterName, std::string label);
259
266 std::string getGlobalLabeledParameter(const std::string& parameterName);
267
273 void setListenerData(const EventAttributes &attributes);
274
281 void set3DAttributes(AudioEventInstance instance, const EventAttributes &attributes);
282
289 FMOD_VECTOR vectorToFmod(const glm::vec3& vPosition);
290 }
291};
FMOD_STUDIO_EVENTINSTANCE * AudioEventInstance
An audio instance equivalent to an instance of a sound. Can be start and stop. For correct 3D positio...
Definition: audioEngine.h:34
void setGlobalLabeledParameter(const std::string &parameterName, std::string label)
Set the value of a global parameter by label.
Definition: audioEngine.cpp:352
void loadSampleData(const std::string &eventName)
Load an event's sample data, allowing for event instances to be spawned and play instantaneously....
Definition: audioEngine.cpp:197
void setLabeledParameter(AudioEventInstance instance, const std::string &parameterName, std::string label)
Set a parameter on an event instance to a labeled value.
Definition: audioEngine.cpp:305
void releaseAllEventInstances(const std::string &eventName)
Release all event instances associated with this event.
Definition: audioEngine.cpp:265
ParameterValue getGlobalParameter(const std::string &parameterName)
Get the value of a global parameter.
Definition: audioEngine.cpp:342
void setParameter(AudioEventInstance instance, const std::string &parameterName, float value)
Set a parameter on an event instance.
Definition: audioEngine.cpp:285
void loadEvent(const std::string &eventName, bool loadSample)
Load an event from a loaded bank.
Definition: audioEngine.cpp:183
AudioImplementation implementation
Data used for operating the AudioEngine.
Definition: audioEngine.cpp:7
FMOD_VECTOR vectorToFmod(const glm::vec3 &vPosition)
Convert a glm vector to an fmod vector.
Definition: audioEngine.cpp:404
void set3DAttributes(AudioEventInstance instance, const EventAttributes &attributes)
Set the 3D attributes of an audio event instance.
Definition: audioEngine.cpp:389
AudioEventInstance playEvent(const std::string &eventName)
Play an event. If this event is not loaded, loadEvent will be called.
Definition: audioEngine.cpp:220
void unloadSampleData(const std::string &eventName)
Unload an event's sample data.
Definition: audioEngine.cpp:208
void stopEvent(AudioEventInstance event, bool immediate)
Stop an event that's playing.
Definition: audioEngine.cpp:246
std::string getGlobalLabeledParameter(const std::string &parameterName)
Get the label value of a global parameter.
Definition: audioEngine.cpp:360
void unloadEvent(const std::string &eventName, bool unloadSample)
Unload an event. This effectively removes the ability to create instances of the event until it is lo...
Definition: audioEngine.cpp:274
void loadBank(const std::string &bankName, FMOD_STUDIO_LOAD_BANK_FLAGS flags)
Load a bank of audio. By default, sample data will not be loaded. It is important that both the bank ...
Definition: audioEngine.cpp:154
ParameterValue getParameter(AudioEventInstance instance, const std::string &parameterName)
Get the value of an event.
Definition: audioEngine.cpp:294
void update()
Update the Audio Engine. Needs to be run every frame for accurate result.
Definition: audioEngine.cpp:136
AudioEventInstance createInstance(const std::string &eventName)
Create an instance of a sound event. If this event has not been loaded, loadEvent will be called.
Definition: audioEngine.cpp:227
bool init()
Initialize the Audio Engine. Must be called before any other audio operation.
Definition: audioEngine.cpp:118
const int maxChannels
Maximum channels we will use for FMOD. Usually you don't need that many (probably 4-5 would be ok).
Definition: audioEngine.h:47
void setListenerData(const EventAttributes &attributes)
Set the 3D position of the listener.
Definition: audioEngine.cpp:373
void unloadBank(const std::string &bankName)
Unload bank.
Definition: audioEngine.cpp:170
void setGlobalParameter(const std::string &parameterName, float value)
Set a global parameter.
Definition: audioEngine.cpp:334
std::string getLabeledParameter(AudioEventInstance instance, const std::string &parameterName)
Get the label-value of a parameter.
Definition: audioEngine.cpp:314
void releaseEvent(AudioEventInstance event)
Release an event instance. After this, the event instance is unusable.
Definition: audioEngine.cpp:256
bool release()
Release the Audio Engine. Must be called after init, and no audio operation should work after this ca...
Definition: audioEngine.cpp:144
Definition: app.cpp:8
A collection of vectors that specify an object in 3D space. This allows the AudioEngine to determine ...
Definition: audioEngine.h:59
glm::vec3 velocity
Definition: audioEngine.h:60
EventAttributes()
Construct a new Event Attributes object.
Definition: audioEngine.cpp:406
glm::vec3 position
Definition: audioEngine.h:60
glm::vec3 up
Definition: audioEngine.h:60
glm::vec3 forward
Definition: audioEngine.h:60
Value of a parameter in FMOD. Whenever a parameter is retrieved from an event (or globally),...
Definition: audioEngine.h:50
float finalValue
final value after automation, modulation, seek speed, and parameter velocity are taken into account....
Definition: audioEngine.h:55
float value
value of the parameter that's set by the API
Definition: audioEngine.h:52
Stores data for implementing the Audio Engine. This includes various maps to fmod events and banks,...
Definition: audioEngine.h:16
FMOD_STUDIO_SYSTEM * studioSystem
FMOD studio system used to interact with Fmod studio.
Definition: audioEngine.h:18
BankMap banks
Maps bank names (filename relative to run directory) to bank pointers.
Definition: audioEngine.h:24
std::map< std::string, FMOD_STUDIO_EVENTDESCRIPTION * > EventMap
Definition: audioEngine.h:20
EventMap events
Maps event names (Usually in the form: "event:/Name") as strings to event descriptions,...
Definition: audioEngine.h:26
std::map< std::string, FMOD_STUDIO_BANK * > BankMap
Definition: audioEngine.h:21