Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: the SoundEngine now gets the SoundBuffer- and SoundSource - Lists directly from the ClassList, and therefor we have much less overhead in the process of alocating deleting them (/2)

File size: 3.3 KB
Line 
1/*!
2 * @file sound_engine.h
3 * 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#define SOUND_DOPPLER_FACTOR       0.001          //!< A factor for the audible doppler effect
13#define SOUND_DOPPLER_VELOCITY     5000000        //!< A factor for the TravelSpeed of sound
14
15// FORWARD DEFINITION
16class PNode;
17template<class T> class tList;
18
19
20//! A class that represents a datastructure to play Sounds.
21class SoundBuffer : public BaseObject
22{
23  public:
24    SoundBuffer(const char* fileName);
25    ~SoundBuffer();
26
27    /** @returns the ID of the buffer used in this SoundBuffer */
28    inline ALuint getID() const { return this->bufferID; }
29
30  private:
31    ALuint        bufferID;             //!< The address of the Buffer.
32
33    ALsizei       size;                 //!< The size of the Buffer.
34    ALboolean     loop;                 //!< loop information.
35};
36
37//! A class that represents a SoundSource
38class SoundSource : public BaseObject
39{
40  public:
41    SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL);
42    ~SoundSource();
43
44  // user interaction
45    void play();
46    void play(const SoundBuffer* buffer);
47    void stop();
48    void pause();
49    void rewind();
50
51  // development functions
52    /** @returns The ID of this Source */
53    inline ALuint getID() const { return this->sourceID; }
54    /** @returns the SoundBuffer of this Source */
55    inline const SoundBuffer* getBuffer() const { return this->buffer; }
56    /** @returns the SourceNode of this Source */
57    inline const PNode* getNode() const { return this->sourceNode;}
58
59    void setRolloffFactor(ALfloat rolloffFactor);
60
61  private:
62    ALuint                 sourceID;              //!< The ID of the Source
63    const SoundBuffer*     buffer;                //!< The buffer to play in this source.
64    const 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();
74    /** @returns a Pointer to the only object of this Class */
75    inline static SoundEngine* getInstance() { 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
87    void update();
88
89  // administrative
90    void flushUnusedBuffers();
91    void flushAllBuffers();
92    void flushAllSources();
93    bool initAudio();
94
95  // error handling:
96    static void PrintALErrorString(ALenum err);
97  //  static void PrintALCErrorString(ALenum err);
98
99
100  private:
101    SoundEngine();
102    void listDevices();
103
104  private:
105    static SoundEngine*      singletonRef;             //!< Reference to this class
106
107
108    PNode*                   listener;                 //!< The listener of the Scene
109    tList<BaseObject>*       bufferList;               //!< A list of buffers
110    tList<BaseObject>*       sourceList;               //!< A list for all the sources in the scene.
111
112};
113
114#endif /* _SOUND_ENGINE_H */
Note: See TracBrowser for help on using the repository browser.