| 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 | #include <stack> |
|---|
| 17 | |
|---|
| 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 |
|---|
| 20 | |
|---|
| 21 | // FORWARD DECLARATION |
|---|
| 22 | class PNode; |
|---|
| 23 | class IniParser; |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | //! A class that handles audio via the openAudioLibrary |
|---|
| 27 | class SoundEngine : public BaseObject { |
|---|
| 28 | public: |
|---|
| 29 | virtual ~SoundEngine(); |
|---|
| 30 | /** @returns a Pointer to the only object of this Class */ |
|---|
| 31 | inline static SoundEngine* getInstance() { if (!SoundEngine::singletonRef) SoundEngine::singletonRef = new SoundEngine(); return SoundEngine::singletonRef; }; |
|---|
| 32 | |
|---|
| 33 | void loadSettings(IniParser* iniParser); |
|---|
| 34 | |
|---|
| 35 | SoundSource* createSource(const char* fileName, PNode* sourceNode = NULL); |
|---|
| 36 | |
|---|
| 37 | /** @param listener the listener in the scene */ |
|---|
| 38 | void setListener(PNode* listener) { this->listener = listener; }; |
|---|
| 39 | void setDopplerValues(ALfloat dopplerFactor, ALfloat dopplerVelocity); |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | /** @returns the Music Volume in % */ |
|---|
| 43 | inline float getMusicVolume() { return this->musicVolume; }; |
|---|
| 44 | /** @returns the Effects Volume in % */ |
|---|
| 45 | inline float getEffectsVolume() { return this->effectsVolume; }; |
|---|
| 46 | |
|---|
| 47 | void update(); |
|---|
| 48 | |
|---|
| 49 | // administrative |
|---|
| 50 | void popALSource(ALuint& source); |
|---|
| 51 | void pushALSource(ALuint& source) { if (source != 0) this->ALSources.push(source); }; |
|---|
| 52 | |
|---|
| 53 | void flushUnusedBuffers(); |
|---|
| 54 | void flushAllBuffers(); |
|---|
| 55 | void flushAllSources(); |
|---|
| 56 | |
|---|
| 57 | bool initAudio(); |
|---|
| 58 | bool allocateSources(unsigned int count); |
|---|
| 59 | |
|---|
| 60 | // error handling: |
|---|
| 61 | static const char* getALErrorString(ALenum err); |
|---|
| 62 | |
|---|
| 63 | private: |
|---|
| 64 | SoundEngine(); |
|---|
| 65 | |
|---|
| 66 | void listDevices(); |
|---|
| 67 | |
|---|
| 68 | private: |
|---|
| 69 | static SoundEngine* singletonRef; //!< Reference to this class |
|---|
| 70 | |
|---|
| 71 | ALCdevice* device; //!< the used audio-device. |
|---|
| 72 | ALCcontext* context; //!< the context, currently in use. |
|---|
| 73 | |
|---|
| 74 | float musicVolume; //!< the maximum volume of the music in % (0f,1f] |
|---|
| 75 | float effectsVolume; //!< the maximum volume of sound-effects in % (0f,1f] |
|---|
| 76 | PNode* listener; //!< The listener of the Scene |
|---|
| 77 | |
|---|
| 78 | const std::list<BaseObject*>* bufferList; //!< A list of buffers |
|---|
| 79 | const std::list<BaseObject*>* sourceList; //!< A list for all the sources in the scene. |
|---|
| 80 | |
|---|
| 81 | unsigned int maxSourceCount; //!< How many Sources is the Maximum |
|---|
| 82 | std::stack<ALuint> ALSources; //!< A list of real openAL-Sources, the engine allocates, and stores for reuse. |
|---|
| 83 | }; |
|---|
| 84 | |
|---|
| 85 | #endif /* _SOUND_ENGINE_H */ |
|---|