/*! * @file sound_engine.h * Definition of the SoundEngine singleton Class */ #ifndef _SOUND_ENGINE_H #define _SOUND_ENGINE_H #include "base_object.h" #include "alincl.h" #include "sound_buffer.h" #include "sound_source.h" #include #include #include "threading.h" #define SOUND_DOPPLER_FACTOR 0.001 //!< A factor for the audible doppler effect #define SOUND_DOPPLER_VELOCITY 500 //!< A factor for the TravelSpeed of sound // FORWARD DECLARATION class PNode; namespace OrxSound { //! A class that handles audio via the openAudioLibrary class SoundEngine : public BaseObject { ObjectListDeclaration(SoundEngine); public: virtual ~SoundEngine(); /** @returns a Pointer to the only object of this Class */ inline static SoundEngine* getInstance() { if (!SoundEngine::singletonRef) SoundEngine::singletonRef = new SoundEngine(); return SoundEngine::singletonRef; }; SoundSource* createSource(const std::string& fileName, PNode* sourceNode = NULL); void loadSettings(); bool initAudio(); /** @param listener the listener in the scene */ void setListener(const PNode* listener) { this->listener = listener; }; void setDopplerValues(ALfloat dopplerFactor, ALfloat dopplerVelocity); /** @returns the Music Volume in % */ inline float getMusicVolume() { return this->musicVolume; }; /** @returns the Effects Volume in % */ inline float getEffectsVolume() { return this->effectsVolume; }; void update(); // administrative void popALSource(ALuint& source); void pushALSource(ALuint& source); // error handling: static bool checkError(const std::string& error, unsigned int line); bool checkALCError(const std::string& error, unsigned int line); static const char* getALErrorString(ALenum err); static const char* getALCErrorString(ALenum err); private: SoundEngine(); bool allocateSources(unsigned int count); void listDevices(); private: static SoundEngine* singletonRef; //!< Reference to this class ALCdevice* device; //!< the used audio-device. ALCcontext* context; //!< the context, currently in use. float musicVolume; //!< the maximum volume of the music in % (0f,1f] float effectsVolume; //!< the maximum volume of sound-effects in % (0f,1f] const PNode* listener; //!< The listener of the Scene unsigned int maxSourceCount; //!< How many Sources is the Maximum std::stack ALSources; //!< A list of real openAL-Sources, the engine allocates, and stores for reuse. SDL_mutex* sourceMutex; //!< A mutex so we can not harm the stack }; } #endif /* _SOUND_ENGINE_H */