Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: music now plays back, as one would expect, and the ReosurceManager handles ogg's.
Also the naming has changed a bit, and doxygen tags are complete in ogg_player.h/cc

File size: 3.4 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    /** @param listener the listener in the scene */
80    void setListener(PNode* listener) { this->listener = listener; };
81    void setDopplerValues(ALfloat dopplerFactor, ALfloat dopplerVelocity);
82
83
84    void update();
85
86  // administrative
87    void addBuffer(SoundBuffer* buffer);
88    void removeBuffer(SoundBuffer* buffer);
89    void addSource(SoundSource* source);
90
91    void flushUnusedBuffers();
92    void flushAllBuffers();
93    void flushAllSources();
94    bool initAudio();
95
96  // error handling:
97    static void PrintALErrorString(ALenum err);
98  //  static void PrintALCErrorString(ALenum err);
99
100
101  private:
102    SoundEngine();
103    void listDevices();
104
105  private:
106    static SoundEngine*      singletonRef;             //!< Reference to this class
107
108
109    PNode*                   listener;                 //!< The listener of the Scene
110    tList<BaseObject>*       bufferList;               //!< A list of buffers
111    tList<BaseObject>*       sourceList;               //!< A list for all the sources in the scene.
112
113};
114
115#endif /* _SOUND_ENGINE_H */
Note: See TracBrowser for help on using the repository browser.