Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6184


Ignore:
Timestamp:
Nov 30, 2009, 8:50:44 PM (14 years ago)
Author:
dafrick
Message:

Created capability in SoundManager to set an overall volume, and to also adjust general ambient and effects volumes.
For this to work, you need to delete your config-file (orxonox.ini) so that it can be reset.
It has still som quirks, though.

Location:
code/branches/presentation2/src/orxonox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/orxonox/CMakeLists.txt

    r6117 r6184  
    5959    pickup/BaseItem.h
    6060    pickup/PickupInventory.h
     61    sound/SoundManager.h
    6162  DEFINE_SYMBOL
    6263    "ORXONOX_SHARED_BUILD"
  • code/branches/presentation2/src/orxonox/sound/BaseSound.cc

    r6127 r6184  
    109109        this->volume_ = vol;
    110110        if (alIsSource(this->audioSource_))
    111             alSourcef(this->audioSource_, AL_GAIN, vol);
     111            alSourcef(this->audioSource_, AL_GAIN, this->getEffectiveVolume());
     112    }
     113   
     114    void BaseSound::setVolumeGain(float gain)
     115    {
     116        COUT(1) << "blubb: " << gain << std::endl;
     117        if (gain > 1 || gain < 0)
     118        {
     119            COUT(2) << "Sound warning: volume gain out of range, cropping value." << std::endl;
     120            gain = gain > 1 ? 1 : gain;
     121            gain = gain < 0 ? 0 : gain;
     122        }
     123        this->volumeGain_ = gain;
     124        if (alIsSource(this->audioSource_))
     125            alSourcef(this->audioSource_, AL_GAIN, this->getEffectiveVolume());
     126    }
     127   
     128    float BaseSound::getEffectiveVolume(void)
     129    {
     130        return this->volume_*this->volumeGain_;
    112131    }
    113132
     
    181200
    182201        alSource3f(this->audioSource_, AL_POSITION,  0, 0, 0);
    183         alSourcef (this->audioSource_, AL_GAIN, this->volume_);
     202        alSourcef (this->audioSource_, AL_GAIN, this->getEffectiveVolume());
    184203        alSourcei (this->audioSource_, AL_LOOPING, (this->bLoop_ ? AL_TRUE : AL_FALSE));
    185204        if (this->isPlaying() || this->isPaused())
  • code/branches/presentation2/src/orxonox/sound/BaseSound.h

    r6117 r6184  
    6464        void setVolume(float vol);
    6565        float getVolume() const { return this->volume_; }
     66       
     67        void setVolumeGain(float gain);
     68        inline float getVolumeGain()
     69            { return this->volumeGain_; }
     70           
     71        float getEffectiveVolume(void);
    6672
    6773        bool getLooping() const   { return this->bLoop_; }
     
    8692        std::string     source_;
    8793        float           volume_;
     94        float           volumeGain_;
    8895        bool            bLoop_;
    8996        State           state_;
  • code/branches/presentation2/src/orxonox/sound/SoundManager.cc

    r6183 r6184  
    4343#include "BaseSound.h"
    4444#include "AmbientSound.h"
     45#include "WorldSound.h"
    4546
    4647namespace orxonox
     
    9091        closeDeviceGuard.Dismiss();
    9192        desroyContextGuard.Dismiss();
     93       
     94        this->volume_ = 1.0;
     95        this->ambientVolume_ = 1.0;
     96        this->effectsVolume_ = 1.0;
    9297
    9398        this->setConfigValues();
     
    112117            .description("Determines how fast sounds should fade, per second.")
    113118            .callback(this, &SoundManager::checkFadeStepValidity);
     119           
     120        SetConfigValue(volume_, 1.0f)
     121            .description("Defines the overall volume.")
     122            .callback(this, &SoundManager::checkVolumeValidity);
     123           
     124        SetConfigValue(ambientVolume_, 1.0f)
     125            .description("Defines the ambient volume.")
     126            .callback(this, &SoundManager::checkAmbientVolumeValidity);
     127           
     128        SetConfigValue(effectsVolume_, 1.0f)
     129            .description("Defines the effects volume.")
     130            .callback(this, &SoundManager::checkEffectsVolumeValidity);
    114131    }
    115132
     
    122139        }
    123140        COUT(3) << "SoundManager: fade step set to " << crossFadeStep_ << std::endl;
     141        return;
     142    }
     143   
     144    void SoundManager::checkVolumeValidity()
     145    {
     146        if(volume_ < 0.0 || volume_ > 1.0)
     147        {
     148            COUT(2) << "Sound warning: Sound volume out of range, ignoring change." << std::endl;
     149            ResetConfigValue(volume_);
     150        }
     151       
     152        this->updateVolume();
     153        COUT(3) << "SoundManager: Overall volume set to " << volume_ << std::endl;
     154        return;
     155    }
     156   
     157    void SoundManager::checkAmbientVolumeValidity()
     158    {
     159        if(this->ambientVolume_ < 0.0 || this->ambientVolume_ > 1.0)
     160        {
     161            COUT(2) << "Sound warning: Ambient volume out of range, ignoring change." << std::endl;
     162            ResetConfigValue(ambientVolume_);
     163        }
     164       
     165        this->updateAmbientVolume();
     166        COUT(3) << "SoundManager: Ambient volume set to " << this->ambientVolume_ << std::endl;
     167        return;
     168    }
     169   
     170    void SoundManager::checkEffectsVolumeValidity()
     171    {
     172        if(this->effectsVolume_ < 0.0 || this->effectsVolume_ > 1.0)
     173        {
     174            COUT(2) << "Sound warning: effects volume out of range, ignoring change." << std::endl;
     175            ResetConfigValue(effectsVolume_);
     176        }
     177       
     178        this->updateEffectsVolume();
     179        COUT(3) << "SoundManager: Effects volume set to " << this->effectsVolume_ << std::endl;
    124180        return;
    125181    }
     
    218274            }
    219275        }
     276    }
     277   
     278    void SoundManager::setAmbientVolume(float vol)
     279    {
     280        if (vol > 1 || vol < 0)
     281        {
     282            COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl;
     283            vol = vol > 1 ? 1 : vol;
     284            vol = vol < 0 ? 0 : vol;
     285        }
     286        this->ambientVolume_ = vol;
     287       
     288        this->updateAmbientVolume();
     289    }
     290   
     291    void SoundManager::setEffectsVolume(float vol)
     292    {
     293        if (vol > 1 || vol < 0)
     294        {
     295            COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl;
     296            vol = vol > 1 ? 1 : vol;
     297            vol = vol < 0 ? 0 : vol;
     298        }
     299        this->effectsVolume_ = vol;
     300       
     301        this->updateEffectsVolume();
     302    }
     303   
     304    void SoundManager::setVolume(float vol)
     305    {
     306        if (vol > 1 || vol < 0)
     307        {
     308            COUT(2) << "Sound warning: volume out of range, cropping value." << std::endl;
     309            vol = vol > 1 ? 1 : vol;
     310            vol = vol < 0 ? 0 : vol;
     311        }
     312        this->volume_ = vol;
     313       
     314        this->updateVolume();
     315    }
     316   
     317    float SoundManager::getAmbientVolume(void)
     318    {
     319        return this->ambientVolume_;
     320    }
     321   
     322    float SoundManager::getEffectsVolume(void)
     323    {
     324        return this->effectsVolume_;
     325    }
     326   
     327    float SoundManager::getVolume(void)
     328    {
     329        return this->volume_;
    220330    }
    221331
     
    305415        }
    306416    }
     417   
     418    void SoundManager::updateAmbientVolume(void)
     419    {
     420        for(ObjectList<AmbientSound>::iterator it = ObjectList<AmbientSound>::begin(); it != ObjectList<AmbientSound>::end(); ++it)
     421        {
     422            (*it)->setVolumeGain(this->volume_*this->ambientVolume_);
     423        }
     424    }
     425   
     426    void SoundManager::updateEffectsVolume(void)
     427    {
     428        for (ObjectList<WorldSound>::iterator it = ObjectList<WorldSound>::begin(); it != ObjectList<WorldSound>::end(); ++it)
     429        {
     430            (*it)->setVolumeGain(this->volume_*this->effectsVolume_);
     431        }
     432    }
     433   
     434    void SoundManager::updateVolume(void)
     435    {
     436        for (ObjectList<BaseSound>::iterator it = ObjectList<BaseSound>::begin(); it != ObjectList<BaseSound>::end(); ++it)
     437        {
     438            AmbientSound* ambient = dynamic_cast<AmbientSound*>(*it);
     439            WorldSound* world = dynamic_cast<WorldSound*>(*it);
     440            if(ambient != NULL)
     441            {
     442                ambient->setVolumeGain(this->volume_*this->ambientVolume_);
     443            }
     444            else if(world != NULL)
     445            {
     446                world->setVolumeGain(this->volume_*this->effectsVolume_);
     447            }
     448            else
     449            {
     450                (*it)->setVolumeGain(this->volume_);
     451            }
     452        }
     453    }
    307454}
  • code/branches/presentation2/src/orxonox/sound/SoundManager.h

    r6183 r6184  
    3535#include <string>
    3636#include "util/Singleton.h"
     37#include "core/OrxonoxClass.h"
    3738
     39// tolua_begin
    3840namespace orxonox
    3941{
     
    4345     *
    4446     */
    45     class _OrxonoxExport SoundManager : public Singleton<SoundManager>, public OrxonoxClass
    46     {
     47    class _OrxonoxExport SoundManager
     48    // tolua_end
     49        : public Singleton<SoundManager>, public OrxonoxClass
     50    { // tolua_export
    4751        friend class Singleton<SoundManager>;
    4852
     
    5357        void preUpdate(const Clock& time);
    5458        void setConfigValues();
     59       
     60        static SoundManager& getInstance() { return Singleton<SoundManager>::getInstance(); } // tolua_export
    5561
    5662        void setListenerPosition(const Vector3& position);
     
    6066        void unregisterAmbientSound(AmbientSound* oldAmbient);
    6167        void pauseAmbientSound(AmbientSound* ambient);
     68       
     69        void setAmbientVolume(float vol); // tolua_export
     70        void setEffectsVolume(float vol); // tolua_export
     71        void setVolume(float vol); // tolua_export
     72       
     73        float getAmbientVolume(void); // tolua_export
     74        float getEffectsVolume(void); // tolua_export
     75        float getVolume(void); // tolua_export
    6276
    6377    private:
     
    6781
    6882        void checkFadeStepValidity();
     83        void checkVolumeValidity();
     84        void checkAmbientVolumeValidity();
     85        void checkEffectsVolumeValidity();
     86       
     87        void updateAmbientVolume(void);
     88        void updateEffectsVolume(void);
     89        void updateVolume(void);
    6990
    7091        ALCdevice* device_;
     
    7899        std::list<AmbientSound*> fadeOutList_;
    79100       
     101        float ambientVolume_;
     102        float effectsVolume_;
     103        float volume_;
     104       
    80105        static SoundManager* singletonPtr_s;
    81     };
    82 }
     106    }; // tolua_export
     107} // tolua_export
    83108
    84109#endif /* _SoundManager_H__ */
Note: See TracChangeset for help on using the changeset viewer.