TDME2 1.9.121
Audio.h
Go to the documentation of this file.
1#pragma once
2
3#if defined(__APPLE__)
4 #include <OpenAL/alc.h>
5#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(_WIN32) || defined(__HAIKU__)
6 #include <AL/alc.h>
7#endif
8
9#include <map>
10#include <string>
11
12#include <tdme/tdme.h>
13#include <tdme/audio/fwd-tdme.h>
15#include <tdme/math/Vector3.h>
16
17using std::map;
18using std::string;
19
23
24/**
25 * Interface to audio module
26 * @author Andreas Drewke
27 * @version $Id$
28 */
30{
31 friend class AudioBufferManager;
32 friend class AudioStream;
33 friend class Sound;
34
35private:
36 static constexpr int32_t ALBUFFERID_NONE { -1 };
37 static constexpr int32_t ALSOURCEID_NONE { -1 };
39
40 ALCdevice* device { nullptr };
41 ALCcontext* context { nullptr };
42
43 map<string, AudioEntity*> audioEntities;
44
50
51 /**
52 * Private constructor
53 */
54 Audio();
55
56public:
57 /**
58 * @return audio singleton instance
59 */
60 inline static Audio* getInstance() {
61 if (Audio::instance == nullptr) {
62 Audio::instance = new Audio();
63 }
64 return Audio::instance;
65 }
66
67 /**
68 * @return listener position
69 */
70 inline const Vector3& getListenerPosition() const {
71 return listenerPosition;
72 }
73
74 /**
75 * Set listener position
76 * @param listenerPosition listener position
77 */
79 this->listenerPosition = listenerPosition;
80 }
81
82 /**
83 * @return listener velocity
84 */
85 inline const Vector3& getListenerVelocity() const {
86 return listenerVelocity;
87 }
88
89 /**
90 * Set listener velocity
91 * @param listenerVelocity listener velocity
92 */
94 this->listenerVelocity = listenerVelocity;
95 }
96
97 /**
98 * @return listener orientation at
99 */
100 inline const Vector3& getListenerOrientationAt() const {
102 }
103
104 /**
105 * Set listener orientation at
106 * @param listenerOrientationAt listener orientation at
107 */
109 this->listenerOrientationAt = listenerOrientationAt;
110 }
111
112 /**
113 * @return listener orientation up
114 */
115 inline const Vector3& getListenerOrientationUp() const {
117 }
118
119 /**
120 * Set listener orientation up
121 * @return listener orientation up
122 */
124 this->listenerOrientationUp = listenerOrientationUp;
125 }
126
127 /**
128 * Returns an audio entity identified by given id
129 * @param id id
130 * @return audio entity
131 */
132 AudioEntity* getEntity(const string& id);
133
134 /**
135 * Adds a audio entity
136 * @param entity audio entity
137 */
138 void addEntity(AudioEntity* entity);
139
140 /**
141 * Removes an audio entity
142 * @param id id
143 */
144 void removeEntity(const string& id);
145
146 /**
147 * Clears all audio entities
148 */
149 void reset();
150
151 /**
152 * Shuts the audio down
153 */
154 void shutdown();
155
156 /**
157 * Update and transfer audio entity states to open AL
158 */
159 void update();
160
161};
Audio entity base class.
Definition: AudioEntity.h:20
Interface to audio module.
Definition: Audio.h:30
Vector3 listenerOrientationAt
Definition: Audio.h:48
const Vector3 & getListenerVelocity() const
Definition: Audio.h:85
Vector3 listenerPosition
Definition: Audio.h:46
ALCdevice * device
Definition: Audio.h:40
void setListenerOrientationAt(const Vector3 &listenerOrientationAt)
Set listener orientation at.
Definition: Audio.h:108
const Vector3 & getListenerPosition() const
Definition: Audio.h:70
static Audio * getInstance()
Definition: Audio.h:60
void addEntity(AudioEntity *entity)
Adds a audio entity.
Definition: Audio.cpp:57
Vector3 listenerOrientationUp
Definition: Audio.h:49
map< string, AudioEntity * > audioEntities
Definition: Audio.h:43
static constexpr int32_t ALSOURCEID_NONE
Definition: Audio.h:37
void shutdown()
Shuts the audio down.
Definition: Audio.cpp:102
const Vector3 & getListenerOrientationAt() const
Definition: Audio.h:100
void setListenerVelocity(const Vector3 &listenerVelocity)
Set listener velocity.
Definition: Audio.h:93
void setListenerOrientationUp(const Vector3 &listenerOrientationUp)
Set listener orientation up.
Definition: Audio.h:123
void removeEntity(const string &id)
Removes an audio entity.
Definition: Audio.cpp:76
static constexpr int32_t ALBUFFERID_NONE
Definition: Audio.h:36
void update()
Update and transfer audio entity states to open AL.
Definition: Audio.cpp:108
static STATIC_DLL_IMPEXT Audio * instance
Definition: Audio.h:38
AudioEntity * getEntity(const string &id)
Returns an audio entity identified by given id.
Definition: Audio.cpp:50
void reset()
Clears all audio entities.
Definition: Audio.cpp:88
const Vector3 & getListenerOrientationUp() const
Definition: Audio.h:115
Vector3 listenerVelocity
Definition: Audio.h:47
AudioBufferManager audioBufferManager
Definition: Audio.h:45
Audio()
Private constructor.
Definition: Audio.cpp:31
ALCcontext * context
Definition: Audio.h:41
void setListenerPosition(const Vector3 &listenerPosition)
Set listener position.
Definition: Audio.h:78
Sound audio entity implementation.
Definition: Sound.h:20
3D vector 3 class
Definition: Vector3.h:22
#define STATIC_DLL_IMPEXT
Definition: tdme.h:11