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