[3655] | 1 | /*! |
---|
[4195] | 2 | \file sound_engine.h |
---|
| 3 | \brief Definition of the SoundEngine singleton Class |
---|
[3655] | 4 | |
---|
| 5 | */ |
---|
| 6 | |
---|
[4195] | 7 | #ifndef _SOUND_ENGINE_H |
---|
| 8 | #define _SOUND_ENGINE_H |
---|
[3655] | 9 | |
---|
| 10 | #include "base_object.h" |
---|
[4196] | 11 | #include "alincl.h" |
---|
[3655] | 12 | |
---|
[4194] | 13 | // FORWARD DEFINITION |
---|
[4196] | 14 | class PNode; |
---|
| 15 | template<class T> class tList; |
---|
[3655] | 16 | |
---|
[4196] | 17 | |
---|
| 18 | //! A class that represents a datastructure to play Sounds. |
---|
| 19 | class SoundBuffer |
---|
| 20 | { |
---|
| 21 | public: |
---|
| 22 | SoundBuffer(const char* fileName); |
---|
| 23 | ~SoundBuffer(void); |
---|
| 24 | |
---|
[4197] | 25 | inline ALuint getID(void) { return this->bufferID; } |
---|
| 26 | |
---|
[4196] | 27 | private: |
---|
| 28 | ALuint bufferID; //!< The address of the Buffer. |
---|
| 29 | |
---|
| 30 | ALsizei size; //!< The size of the Buffer. |
---|
| 31 | ALboolean loop; //!< loop information. |
---|
| 32 | }; |
---|
| 33 | |
---|
| 34 | //! A class that represents a SoundSource |
---|
| 35 | class SoundSource |
---|
| 36 | { |
---|
| 37 | public: |
---|
| 38 | SoundSource(SoundBuffer* buffer, PNode* sourceNode = NULL); |
---|
| 39 | ~SoundSource(void); |
---|
| 40 | |
---|
[4197] | 41 | // user interaction |
---|
| 42 | void play(); |
---|
| 43 | void stop(); |
---|
| 44 | void pause(); |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | // development functions |
---|
[4196] | 48 | /** \retruns The ID of the Source */ |
---|
| 49 | inline ALuint getID(void) { return this->sourceID; } |
---|
| 50 | /** \returns the SourceNode of this Source */ |
---|
| 51 | inline PNode* getNode(void) { return this->sourceNode;} |
---|
| 52 | |
---|
| 53 | private: |
---|
| 54 | ALuint sourceID; //!< The ID of the Source |
---|
| 55 | SoundBuffer* buffer; //!< The buffer to play in this source. |
---|
| 56 | PNode* sourceNode; //!< The SourceNode represente the position/velocity... of this source. |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | //! A class that handles audio via the openAudioLibrary |
---|
[4195] | 62 | class SoundEngine : public BaseObject { |
---|
[3655] | 63 | |
---|
| 64 | public: |
---|
[4195] | 65 | static SoundEngine* getInstance(void); |
---|
| 66 | virtual ~SoundEngine(void); |
---|
[3655] | 67 | |
---|
[4196] | 68 | void setListener(PNode* listener); |
---|
| 69 | |
---|
| 70 | void addBuffer(SoundBuffer* buffer); |
---|
| 71 | void removeBuffer(SoundBuffer* buffer); |
---|
| 72 | void addSource(SoundSource* source); |
---|
| 73 | void removeSource(SoundSource* source); |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | void update(void); |
---|
| 77 | |
---|
[3655] | 78 | private: |
---|
[4195] | 79 | SoundEngine(void); |
---|
| 80 | static SoundEngine* singletonRef; |
---|
[4196] | 81 | |
---|
| 82 | bool initAudio(void); |
---|
| 83 | |
---|
| 84 | PNode* listener; //!< The listener of the Scene |
---|
| 85 | tList<SoundBuffer>* bufferList; //!< A list of buffers |
---|
| 86 | tList<SoundSource>* sourceList; //!< A list for all the sources in the scene. |
---|
| 87 | |
---|
[3655] | 88 | }; |
---|
| 89 | |
---|
[4195] | 90 | #endif /* _SOUND_ENGINE_H */ |
---|