1 | /*! |
---|
2 | * @file sound_engine.h |
---|
3 | * Definition of the SoundEngine singleton Class |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _SOUND_ENGINE_H |
---|
7 | #define _SOUND_ENGINE_H |
---|
8 | |
---|
9 | #include "base_object.h" |
---|
10 | #include "alincl.h" |
---|
11 | |
---|
12 | #include "sound_buffer.h" |
---|
13 | #include "sound_source.h" |
---|
14 | |
---|
15 | #include <list> |
---|
16 | |
---|
17 | #define SOUND_DOPPLER_FACTOR 0.001 //!< A factor for the audible doppler effect |
---|
18 | #define SOUND_DOPPLER_VELOCITY 5000000 //!< A factor for the TravelSpeed of sound |
---|
19 | |
---|
20 | // FORWARD DECLARATION |
---|
21 | class PNode; |
---|
22 | class IniParser; |
---|
23 | |
---|
24 | //! A class that handles audio via the openAudioLibrary |
---|
25 | class SoundEngine : public BaseObject { |
---|
26 | |
---|
27 | public: |
---|
28 | virtual ~SoundEngine(); |
---|
29 | /** @returns a Pointer to the only object of this Class */ |
---|
30 | inline static SoundEngine* getInstance() { if (!SoundEngine::singletonRef) SoundEngine::singletonRef = new SoundEngine(); return SoundEngine::singletonRef; }; |
---|
31 | |
---|
32 | void loadSettings(IniParser* iniParser); |
---|
33 | |
---|
34 | SoundSource* createSource(const char* fileName, PNode* sourceNode = NULL); |
---|
35 | |
---|
36 | /** @param listener the listener in the scene */ |
---|
37 | void setListener(PNode* listener) { this->listener = listener; }; |
---|
38 | void setDopplerValues(ALfloat dopplerFactor, ALfloat dopplerVelocity); |
---|
39 | |
---|
40 | |
---|
41 | /** @returns the Music Volume in % */ |
---|
42 | inline float getMusicVolume() { return this->musicVolume; }; |
---|
43 | /** @returns the Effects Volume in % */ |
---|
44 | inline float getEffectsVolume() { return this->effectsVolume; }; |
---|
45 | |
---|
46 | void update(); |
---|
47 | |
---|
48 | // administrative |
---|
49 | void addBuffer(SoundBuffer* buffer); |
---|
50 | void removeBuffer(SoundBuffer* buffer); |
---|
51 | void addSource(SoundSource* source); |
---|
52 | |
---|
53 | void flushUnusedBuffers(); |
---|
54 | void flushAllBuffers(); |
---|
55 | void flushAllSources(); |
---|
56 | bool initAudio(); |
---|
57 | |
---|
58 | // error handling: |
---|
59 | static void PrintALErrorString(ALenum err); |
---|
60 | // static void PrintALCErrorString(ALenum err); |
---|
61 | |
---|
62 | |
---|
63 | private: |
---|
64 | SoundEngine(); |
---|
65 | void listDevices(); |
---|
66 | |
---|
67 | private: |
---|
68 | static SoundEngine* singletonRef; //!< Reference to this class |
---|
69 | |
---|
70 | float musicVolume; //!< the maximum volume of the music in % (0f,1f] |
---|
71 | float effectsVolume; //!< the maximum volume of sound-effects in % (0f,1f] |
---|
72 | PNode* listener; //!< The listener of the Scene |
---|
73 | std::list<BaseObject*>* bufferList; //!< A list of buffers |
---|
74 | std::list<BaseObject*>* sourceList; //!< A list for all the sources in the scene. |
---|
75 | |
---|
76 | }; |
---|
77 | |
---|
78 | #endif /* _SOUND_ENGINE_H */ |
---|