2010-10-18 00:40:50 +02:00
|
|
|
#ifndef _SOUNDBASE_H
|
|
|
|
#define _SOUNDBASE_H
|
|
|
|
|
|
|
|
#include "Engine.h"
|
|
|
|
#include <SDL/SDL_mixer.h>
|
|
|
|
|
|
|
|
namespace Engine {
|
|
|
|
|
|
|
|
class Module;
|
|
|
|
|
|
|
|
class SoundSample {
|
|
|
|
public:
|
|
|
|
SoundSample() :
|
|
|
|
mMixChunk (NULL),
|
|
|
|
mChannel (-1) {
|
|
|
|
}
|
|
|
|
~SoundSample();
|
|
|
|
|
|
|
|
bool Load(const std::string &filename);
|
|
|
|
void Play();
|
|
|
|
void Loop(int count);
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int mChannel;
|
|
|
|
Mix_Chunk *mMixChunk;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef boost::shared_ptr<SoundSample> SoundSamplePtr;
|
|
|
|
|
|
|
|
/** \brief Manages loading, saving and playing of sounds and music
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class SoundBase : public Module {
|
|
|
|
public:
|
|
|
|
void PlaySound (const std::string &sound_name);
|
|
|
|
void PlaySoundLoop (const std::string &sound_name, int count);
|
|
|
|
void HaltSoundLoop (const std::string &sound_name);
|
|
|
|
void PlayMusic (const std::string &music_name);
|
2010-11-01 22:22:50 +01:00
|
|
|
void HaltMusic ();
|
2010-10-18 00:40:50 +02:00
|
|
|
|
|
|
|
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<std::string, SoundSamplePtr> mSamples;
|
|
|
|
typedef std::map<std::string, SoundSamplePtr>::iterator SampleIter;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _SOUNDBASE_H
|