Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the SoundEngine into the Trunk.
merged file by file, but merged all the files in favor of the new trunk

File size: 2.8 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
23{
24 public:
25  SoundBuffer(const char* fileName);
26  ~SoundBuffer(void);
27
28  /** \returns the ID of the buffer */
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
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  static SoundEngine* getInstance(void);
74  virtual ~SoundEngine(void);
75
76  SoundSource* createSource(const char* fileName, PNode* sourceNode = NULL);
77
78  void setListener(PNode* listener);
79  void setDopplerValues(ALfloat dopplerFactor, ALfloat dopplerVelocity);
80
81
82  void addBuffer(SoundBuffer* buffer);
83  void removeBuffer(SoundBuffer* buffer);
84  void addSource(SoundSource* source);
85  void removeSource(SoundSource* source);
86
87  void update(void);
88
89  // administrative
90  void flushUnusedBuffers(void);
91  void flushAllBuffers(void);
92  bool initAudio(void);
93
94  // error handling:
95  static void PrintALErrorString(ALenum err);
96  //  static void PrintALCErrorString(ALenum err);
97
98
99 private:
100  SoundEngine(void);
101  static SoundEngine* singletonRef;
102
103
104  PNode* listener;                 //!< The listener of the Scene
105  tList<SoundBuffer>* bufferList;  //!< A list of buffers
106  tList<SoundSource>* sourceList;  //!< A list for all the sources in the scene.
107
108};
109
110#endif /* _SOUND_ENGINE_H */
Note: See TracBrowser for help on using the repository browser.