Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/orxonox/sound/SoundManager.h @ 6387

Last change on this file since 6387 was 6387, checked in by rgrieder, 14 years ago

Found some non empty new lines.

  • Property svn:eol-style set to native
File size: 5.0 KB
RevLine 
[3060]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *       Erwin 'vaiursch' Herrsche
[6117]24 *       Kevin Young
[6244]25 *       Reto Grieder
[3060]26 *   Co-authors:
27 *      ...
28 */
[6117]29
[3196]30#ifndef _SoundManager_H__
31#define _SoundManager_H__
[3060]32
33#include "OrxonoxPrereqs.h"
34
[3196]35#include <list>
[6203]36#include <map>
[6117]37#include <string>
[6254]38#include <boost/shared_ptr.hpp>
[6203]39
[3370]40#include "util/Singleton.h"
[6184]41#include "core/OrxonoxClass.h"
[6349]42#include "core/SmartPtr.h"
[3196]43
[6244]44// forward declaration
45typedef int ALenum;
46
[6184]47// tolua_begin
[3060]48namespace orxonox
49{
[6203]50    // forward declaration
51    class SoundBuffer;
[6370]52
[6186]53    //! Enum for the sound type.
54    namespace SoundType
55    {
56        enum Value
57        {
[6370]58            All     = 0,
59            Music   = 1,
60            Effects = 2
[6186]61        };
62    }
[6370]63
64    //! The SoundManager class manages the OpenAL device, context and listener position.
[6184]65    class _OrxonoxExport SoundManager
66    // tolua_end
67        : public Singleton<SoundManager>, public OrxonoxClass
68    { // tolua_export
[3370]69        friend class Singleton<SoundManager>;
[6117]70
[3060]71    public:
72        SoundManager();
73        ~SoundManager();
74
[6183]75        void preUpdate(const Clock& time);
[6117]76        void setConfigValues();
[6387]77
[6244]78        // tolua_begin
[6278]79        static SoundManager& getInstance() { return Singleton<SoundManager>::getInstance(); }
[6117]80
[6244]81        std::string getDeviceName(unsigned int index) const
82            { return index < this->deviceNames_.size() ? this->deviceNames_[index] : std::string(); }
83        // tolua_end
84
[5929]85        void setListenerPosition(const Vector3& position);
86        void setListenerOrientation(const Quaternion& orientation);
87
[6117]88        void registerAmbientSound(AmbientSound* newAmbient);
89        void unregisterAmbientSound(AmbientSound* oldAmbient);
90        void pauseAmbientSound(AmbientSound* ambient);
[6332]91
[6370]92        // tolua_begin
[6194]93        void setVolume(float vol, SoundType::Value type);
[6370]94        float getVolume(SoundType::Value type);
95        float getRealVolume(SoundType::Value type);
[6332]96
[6370]97        void toggleMute(SoundType::Value type);
98        bool getMute(SoundType::Value type);
99        // tolua_end
[6117]100
[6270]101        shared_ptr<SoundBuffer> getSoundBuffer(const std::string& filename);
[6254]102        void releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer);
[6203]103
[6383]104        ALuint getSoundSource(BaseSound* object);
[6322]105        void releaseSoundSource(ALuint source);
106
[6244]107        static std::string getALErrorString(ALenum error);
108
[3060]109    private:
[6117]110        void processCrossFading(float dt);
[6349]111        void fadeIn(const SmartPtr<AmbientSound>& sound);
112        void fadeOut(const SmartPtr<AmbientSound>& sound);
[6117]113
114        void checkFadeStepValidity();
[6332]115
[6370]116        void checkVolumeValidity(SoundType::Value type);
117        void checkSoundVolumeValidity()   { this->checkVolumeValidity(SoundType::All); }
118        void checkAmbientVolumeValidity() { this->checkVolumeValidity(SoundType::Music); }
119        void checkEffectsVolumeValidity() { this->checkVolumeValidity(SoundType::Effects); }
[6186]120        void updateVolume(SoundType::Value type);
[6332]121
[6370]122        // OpenAL device/context related
[6244]123        std::vector<std::string> deviceNames_;
[3280]124        ALCdevice* device_;
[3060]125        ALCcontext* context_;
[6332]126
[6370]127        // Ambient sound related
[6117]128        typedef std::list<std::pair<AmbientSound*, bool> > AmbientList;
[6370]129        AmbientList                        ambientSounds_;
130        //! Absolute change per second (0.1 means 10% of the nominal volume) for cross fading
131        float                              crossFadeStep_;
[6349]132        std::list<SmartPtr<AmbientSound> > fadeInList_;
133        std::list<SmartPtr<AmbientSound> > fadeOutList_;
[6332]134
[6370]135        // Volume related
136        float volume_[3];
137        float mute_[3];
[6203]138
[6370]139        // Sound buffer related
[6254]140        static const unsigned int maxEffectsPoolSize_s = 40 * 1024 * 1024;
141        unsigned int effectsPoolSize_;
142        typedef std::list<shared_ptr<SoundBuffer> > EffectsPoolList;
143        EffectsPoolList effectsPool_;
144        typedef std::map<std::string, shared_ptr<SoundBuffer> > SoundBufferMap;
145        SoundBufferMap soundBuffers_;
[6322]146
[6370]147        // Sound source related
[6322]148        unsigned int maxSources_;
[6383]149        std::vector<ALuint> availableSoundSources_;
150        std::vector<std::pair<ALuint, BaseSound*> > usedSoundSources_;
[6332]151
[3370]152        static SoundManager* singletonPtr_s;
[6184]153    }; // tolua_export
154} // tolua_export
[3060]155
[3196]156#endif /* _SoundManager_H__ */
Note: See TracBrowser for help on using the repository browser.