Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: some minor fixes

File size: 3.1 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#include "sound_buffer.h"
13#include "sound_source.h"
14
15#include <list>
16#include <stack>
17#include "threading.h"
18
19#define SOUND_DOPPLER_FACTOR       0.001          //!< A factor for the audible doppler effect
20#define SOUND_DOPPLER_VELOCITY     500            //!< A factor for the TravelSpeed of sound
21
22// FORWARD DECLARATION
23class PNode;
24namespace OrxSound
25{
26  //! A class that handles audio via the openAudioLibrary
27  class SoundEngine : public BaseObject
28  {
29  public:
30    virtual ~SoundEngine();
31    /** @returns a Pointer to the only object of this Class */
32    inline static SoundEngine* getInstance() { if (!SoundEngine::singletonRef) SoundEngine::singletonRef = new SoundEngine();  return SoundEngine::singletonRef; };
33
34    SoundSource* createSource(const std::string& fileName, PNode* sourceNode = NULL);
35    void loadSettings();
36    bool initAudio();
37
38    /** @param listener the listener in the scene */
39    void setListener(const PNode* listener) { this->listener = listener; };
40    void setDopplerValues(ALfloat dopplerFactor, ALfloat dopplerVelocity);
41
42
43
44    /** @returns the Music Volume in % */
45    inline float getMusicVolume() { return this->musicVolume; };
46    /** @returns the Effects Volume in % */
47    inline float getEffectsVolume() { return this->effectsVolume; };
48
49    void update();
50
51    // administrative
52    void popALSource(ALuint& source);
53    void pushALSource(ALuint& source);
54
55    // error handling:
56    static bool checkError(const std::string& error, unsigned int line);
57    bool checkALCError(const std::string& error, unsigned int line);
58    static const char* getALErrorString(ALenum err);
59    static const char* getALCErrorString(ALenum err);
60
61  private:
62    SoundEngine();
63    bool allocateSources(unsigned int count);
64
65    void listDevices();
66
67  private:
68    static SoundEngine*            singletonRef;             //!< Reference to this class
69
70    ALCdevice*                     device;                   //!< the used audio-device.
71    ALCcontext*                    context;                  //!< the context, currently in use.
72
73    float                          musicVolume;              //!< the maximum volume of the music in % (0f,1f]
74    float                          effectsVolume;            //!< the maximum volume of sound-effects in % (0f,1f]
75    const PNode*                   listener;                 //!< The listener of the Scene
76
77    const std::list<BaseObject*>*  bufferList;               //!< A list of buffers
78    const std::list<BaseObject*>*  sourceList;               //!< A list for all the sources in the scene.
79
80    unsigned int                   maxSourceCount;           //!< How many Sources is the Maximum
81    std::stack<ALuint>             ALSources;                //!< A list of real openAL-Sources, the engine allocates, and stores for reuse.
82
83    SDL_mutex*                     sourceMutex;              //!< A mutex so we can not harm the stack
84  };
85}
86
87#endif /* _SOUND_ENGINE_H */
Note: See TracBrowser for help on using the repository browser.