Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/sound/SoundManager.h @ 12055

Last change on this file since 12055 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 5.4 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
[6417]24 *       Kevin Young
25 *       Reto Grieder
[3060]26 *   Co-authors:
27 *      ...
28 */
[6417]29
[3196]30#ifndef _SoundManager_H__
31#define _SoundManager_H__
[3060]32
33#include "OrxonoxPrereqs.h"
34
[3196]35#include <list>
[6417]36#include <map>
37#include <string>
[11071]38#include <memory>
[6417]39
[3370]40#include "util/Singleton.h"
[9667]41#include "core/config/Configurable.h"
[10624]42#include "core/object/StrongPtr.h"
43#include "core/UpdateListener.h"
[3196]44
[6417]45// tolua_begin
[3060]46namespace orxonox
47{
[6417]48    //! Enum for the sound type.
49    namespace SoundType
[3060]50    {
[6417]51        enum Value
52        {
53            All     = 0,
54            Music   = 1,
55            Effects = 2
56        };
57    }
58
59    //! The SoundManager class manages the OpenAL device, context and listener position.
60    class _OrxonoxExport SoundManager
61    // tolua_end
[10624]62        : public Singleton<SoundManager>, public Configurable, public UpdateListener
[6417]63    { // tolua_export
[3370]64        friend class Singleton<SoundManager>;
[6417]65
[3060]66    public:
67        SoundManager();
68        ~SoundManager();
69
[11071]70        virtual void preUpdate(const Clock& time) override;
71        virtual void postUpdate(const Clock& time) override { /*no action*/ }
[6417]72        void setConfigValues();
73
74        // tolua_begin
75        static SoundManager& getInstance() { return Singleton<SoundManager>::getInstance(); }
[8351]76        static bool exists() { return Singleton<SoundManager>::exists(); }
[6417]77
78        std::string getDeviceName(unsigned int index) const
79            { return index < this->deviceNames_.size() ? this->deviceNames_[index] : std::string(); }
80        // tolua_end
81
[5929]82        void setListenerPosition(const Vector3& position);
83        void setListenerOrientation(const Quaternion& orientation);
84
[6417]85        void registerAmbientSound(AmbientSound* newAmbient);
86        void unregisterAmbientSound(AmbientSound* oldAmbient);
87        void pauseAmbientSound(AmbientSound* ambient);
88
89        // tolua_begin
90        void setVolume(float vol, SoundType::Value type);
91        float getVolume(SoundType::Value type);
92        float getRealVolume(SoundType::Value type);
93
94        void toggleMute(SoundType::Value type);
95        bool getMute(SoundType::Value type);
96        // tolua_end
97
[11071]98        std::shared_ptr<SoundBuffer> getSoundBuffer(const std::string& filename);
99        void releaseSoundBuffer(const std::shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer);
[6417]100
101        ALuint getSoundSource(BaseSound* object);
102        void releaseSoundSource(ALuint source);
103
104        static std::string getALErrorString(ALenum error);
105
[3060]106    private:
[6417]107        void processCrossFading(float dt);
[10624]108        void fadeIn(AmbientSound* sound);
109        void fadeOut(AmbientSound* sound);
[6417]110
111        void checkFadeStepValidity();
112
113        void checkVolumeValidity(SoundType::Value type);
114        void checkSoundVolumeValidity()   { this->checkVolumeValidity(SoundType::All); }
115        void checkAmbientVolumeValidity() { this->checkVolumeValidity(SoundType::Music); }
116        void checkEffectsVolumeValidity() { this->checkVolumeValidity(SoundType::Effects); }
117        void updateVolume(SoundType::Value type);
118
119        unsigned int createSoundSources(unsigned int n);
120
121        // OpenAL device/context related
122        std::vector<std::string> deviceNames_;
[3280]123        ALCdevice* device_;
[3060]124        ALCcontext* context_;
125
[6417]126        // Ambient sound related
[11071]127        typedef std::list<std::pair<AmbientSound*, bool>> AmbientList;
[6417]128        AmbientList                        ambientSounds_;
129        //! Absolute change per second (0.1 means 10% of the nominal volume) for cross fading
130        float                              crossFadeStep_;
[11071]131        std::list<StrongPtr<AmbientSound>> fadeInList_;
132        std::list<StrongPtr<AmbientSound>> fadeOutList_;
[6417]133
134        // Volume related
135        float volume_[3];
136        float mute_[3];
137
138        // Sound buffer related
139        static const unsigned int maxEffectsPoolSize_s = 40 * 1024 * 1024;
140        unsigned int effectsPoolSize_;
[11071]141        typedef std::list<std::shared_ptr<SoundBuffer>> EffectsPoolList;
[6417]142        EffectsPoolList effectsPool_;
[11071]143        typedef std::map<std::string, std::shared_ptr<SoundBuffer>> SoundBufferMap;
[6417]144        SoundBufferMap soundBuffers_;
145
146        // Sound source related
147        unsigned int minSources_;
148        unsigned int maxSources_;
149        std::vector<ALuint> availableSoundSources_;
[11071]150        std::vector<std::pair<ALuint, BaseSound*>> usedSoundSources_;
[7858]151
[7855]152        bool bDestructorCalled_; ///< Becomes true if the destructor is called - used to prevent ambient sounds from registering after the lists were cleared
[6417]153
[3370]154        static SoundManager* singletonPtr_s;
[6417]155    }; // tolua_export
156} // tolua_export
[3060]157
[3196]158#endif /* _SoundManager_H__ */
Note: See TracBrowser for help on using the repository browser.