Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/sound/sound_engine.h @ 4678

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

orxonox/trunk: setClassID implemented in all files

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