#ifndef _SOUNDBASE_H #define _SOUNDBASE_H #include "Engine.h" #include namespace Engine { class Module; class SoundSample { public: SoundSample() : mChannel (-1), mMixChunk (NULL) { } ~SoundSample(); bool Load(const std::string &filename); void Play(); void Loop(int count); void Stop(); int GetChannel () { return mChannel; }; private: int mChannel; Mix_Chunk *mMixChunk; }; typedef boost::shared_ptr SoundSamplePtr; /** \brief Manages loading, saving and playing of sounds and music * */ class SoundBase : public Module { public: void PlaySound (const std::string &sound_name); /** \brief Plays a sound chunk in a loop * * \note Loops are hard-coded played in channel 4, therefore playing * two loops simultaneously is currently not supported. */ void PlaySoundLoop (const std::string &sound_name, int count); void HaltSoundLoop (const std::string &sound_name); void LoadSound (const std::string &sound_name); void PlayMusic (const std::string &music_name); void HaltMusic (); /** \brief Sets the volume of the music channel to the given value * * \param music_value is a value from 0. (no music) to 1. (maximum volume) */ void SetMusicVolume (const float &music_volume); /** \brief Returns the value of the music (0. - 1.) */ float GetMusicVolume (); /** \brief Sets the volume of the music channel to the given value * * \param music_value is a value from 0. (no music) to 1. (maximum volume) */ void SetEffectsVolume (const float &effects_volume); /** \brief Returns the value of the effects (0. - 1.) */ float GetEffectsVolume (); protected: /** \brief Initializes the system */ virtual int OnInit (int argc, char* argv[]); /** \brief Destroys the system (must be called!) */ virtual void OnDestroy (); std::string mCurrentMusicName; Mix_Music *mCurrentMusic; std::map mSamples; typedef std::map::iterator SampleIter; }; } #endif // _SOUNDBASE_H