Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/heathaze/src/lib/sound/sound_engine.h @ 10772

Last change on this file since 10772 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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