Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/openAL/src/lib/sound/sound_engine.h @ 4207

Last change on this file since 4207 was 4207, checked in by bensch, 19 years ago

orxonox/branches/openAL: added flush-function i talked of in the Wiki

File size: 2.7 KB
Line 
1/*!
2    \file sound_engine.h
3    \brief Definition of the SoundEngine singleton Class
4   
5*/
6
7#ifndef _SOUND_ENGINE_H
8#define _SOUND_ENGINE_H
9
10#include "base_object.h"
11#include "alincl.h"
12
13
14#define SOUND_DOPPLER_FACTOR     0.01          //!< A factor for the audible doppler effect
15#define SOUND_DOPPLER_VELOCITY   500000000     //!< A factor for the TravelSpeed of sound
16
17// FORWARD DEFINITION
18class PNode;
19template<class T> class tList;
20
21
22//! A class that represents a datastructure to play Sounds.
23class SoundBuffer
24{
25 public:
26  SoundBuffer(const char* fileName);
27  ~SoundBuffer(void);
28
29  /** \returns the ID of the buffer */
30  inline ALuint getID(void) { return this->bufferID; }
31
32 private:
33  ALuint bufferID;              //!< The address of the Buffer.
34
35  ALsizei size;                 //!< The size of the Buffer.
36  ALboolean loop;               //!< loop information.
37};
38
39//! A class that represents a SoundSource
40class SoundSource
41{
42 public:
43  SoundSource(SoundBuffer* buffer, PNode* sourceNode = NULL);
44  ~SoundSource(void);
45
46  // user interaction
47  void play();
48  void stop();
49  void pause();
50  void rewind();
51
52  // development functions
53  /** \returns The ID of this Source */
54  inline ALuint getID(void) const { return this->sourceID; }
55  /** \returns the SoundBuffer of this Source */
56  inline SoundBuffer* getBuffer(void) const { return this->buffer; } 
57  /** \returns the SourceNode of this Source */
58  inline PNode* getNode(void) const { return this->sourceNode;}
59
60  void setRolloffFactor(ALfloat rolloffFactor);
61
62 private:
63  ALuint sourceID;              //!< The ID of the Source
64  SoundBuffer* buffer;          //!< The buffer to play in this source.
65  PNode* sourceNode;            //!< The SourceNode represente the position/velocity... of this source.
66};
67
68
69
70//! A class that handles audio via the openAudioLibrary
71class SoundEngine : public BaseObject {
72
73 public:
74  static SoundEngine* getInstance(void);
75  virtual ~SoundEngine(void);
76
77  SoundSource* createSource(const char* fileName, PNode* sourceNode = NULL);
78
79  void setListener(PNode* listener);
80
81  void addBuffer(SoundBuffer* buffer);
82  void removeBuffer(SoundBuffer* buffer);
83  void addSource(SoundSource* source);
84  void removeSource(SoundSource* source);
85
86  void update(void);
87
88  void flushUnusedBuffers(void);
89
90  // error handling:
91  static void PrintALErrorString(ALenum err);
92  //  static void PrintALCErrorString(ALenum err);
93
94 private:
95  SoundEngine(void);
96  static SoundEngine* singletonRef;
97
98  bool initAudio(void);
99
100  PNode* listener;                 //!< The listener of the Scene
101  tList<SoundBuffer>* bufferList;  //!< A list of buffers
102  tList<SoundSource>* sourceList;  //!< A list for all the sources in the scene.
103
104};
105
106#endif /* _SOUND_ENGINE_H */
Note: See TracBrowser for help on using the repository browser.