Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6368 was 6349, checked in by rgrieder, 15 years ago

Overriding preDestroy() in AmbientSound to make them fade out when the level unloads.
@Kevin: this should also prevent the random bug you showed me when reloading a level with ambient sound.

  • Property svn:eol-style set to native
File size: 4.8 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;
[6186]52   
53    //! Enum for the sound type.
54    namespace SoundType
55    {
56        enum Value
57        {
58            none,
59            ambient,
60            effects
61        };
62    }
63   
[3060]64    /**
65     * The SoundManager class manages the OpenAL device, context and listener
[5929]66     * position. It is a singleton.
[3060]67     *
68     */
[6184]69    class _OrxonoxExport SoundManager
70    // tolua_end
71        : public Singleton<SoundManager>, public OrxonoxClass
72    { // tolua_export
[3370]73        friend class Singleton<SoundManager>;
[6117]74
[3060]75    public:
76        SoundManager();
77        ~SoundManager();
78
[6183]79        void preUpdate(const Clock& time);
[6117]80        void setConfigValues();
[6184]81       
[6244]82        // tolua_begin
[6278]83        static SoundManager& getInstance() { return Singleton<SoundManager>::getInstance(); }
[6117]84
[6244]85        std::string getDeviceName(unsigned int index) const
86            { return index < this->deviceNames_.size() ? this->deviceNames_[index] : std::string(); }
87        // tolua_end
88
[5929]89        void setListenerPosition(const Vector3& position);
90        void setListenerOrientation(const Quaternion& orientation);
91
[6117]92        void registerAmbientSound(AmbientSound* newAmbient);
93        void unregisterAmbientSound(AmbientSound* oldAmbient);
94        void pauseAmbientSound(AmbientSound* ambient);
[6332]95
[6194]96        void setVolume(float vol, SoundType::Value type);
[6186]97        float getVolume(SoundType::Value type); // tolua_export
[6332]98
[6186]99        void toggleMute(SoundType::Value type); // tolua_export
100        bool getMute(SoundType::Value type); // tolua_export
[6117]101
[6270]102        shared_ptr<SoundBuffer> getSoundBuffer(const std::string& filename);
[6254]103        void releaseSoundBuffer(const shared_ptr<SoundBuffer>& buffer, bool bPoolBuffer);
[6203]104
[6322]105        ALuint getSoundSource();
106        void releaseSoundSource(ALuint source);
107
[6244]108        static std::string getALErrorString(ALenum error);
109
[3060]110    private:
[6117]111        void processCrossFading(float dt);
[6349]112        void fadeIn(const SmartPtr<AmbientSound>& sound);
113        void fadeOut(const SmartPtr<AmbientSound>& sound);
[6117]114
115        void checkFadeStepValidity();
[6186]116        bool checkVolumeValidity(SoundType::Value type);
117        void checkSoundVolumeValidity(void);
118        void checkAmbientVolumeValidity(void);
119        void checkEffectsVolumeValidity(void);
[6332]120
[6186]121        float checkVolumeRange(float vol);
[6332]122
[6186]123        void updateVolume(SoundType::Value type);
[6332]124
[6186]125        void setVolumeInternal(float vol, SoundType::Value type);
126        float getVolumeInternal(SoundType::Value type);
[6117]127
[6244]128        std::vector<std::string> deviceNames_;
[3280]129        ALCdevice* device_;
[3060]130        ALCcontext* context_;
[6332]131
[6117]132        typedef std::list<std::pair<AmbientSound*, bool> > AmbientList;
133        AmbientList ambientSounds_;
[6332]134
[6117]135        float crossFadeStep_;       //!< Absolute change per second (0.1 means 10% of the nominal volume) for cross fading
[6349]136        std::list<SmartPtr<AmbientSound> > fadeInList_;
137        std::list<SmartPtr<AmbientSound> > fadeOutList_;
[6332]138
[6186]139        float soundVolume_;
[6184]140        float ambientVolume_;
141        float effectsVolume_;
[6186]142        std::map<SoundType::Value, bool> mute_;
[6203]143
[6254]144        static const unsigned int maxEffectsPoolSize_s = 40 * 1024 * 1024;
145        unsigned int effectsPoolSize_;
146        typedef std::list<shared_ptr<SoundBuffer> > EffectsPoolList;
147        EffectsPoolList effectsPool_;
148        typedef std::map<std::string, shared_ptr<SoundBuffer> > SoundBufferMap;
149        SoundBufferMap soundBuffers_;
[6322]150
151        unsigned int maxSources_;
152        std::vector<ALuint> soundSources_;
[6332]153
[3370]154        static SoundManager* singletonPtr_s;
[6184]155    }; // tolua_export
156} // tolua_export
[3060]157
[3196]158#endif /* _SoundManager_H__ */
Note: See TracBrowser for help on using the repository browser.