Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6332


Ignore:
Timestamp:
Dec 13, 2009, 12:11:40 AM (14 years ago)
Author:
rgrieder
Message:

Improved SoundBuffer class design and removed its pooling property (just a boolean).

Location:
code/branches/presentation2/src/orxonox/sound
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/orxonox/sound/SoundBuffer.cc

    r6270 r6332  
    3333#include <vorbis/vorbisfile.h>
    3434
     35#include "util/Clock.h"
     36#include "core/Game.h"
    3537#include "util/Exception.h"
    3638#include "util/StringUtils.h"
     
    4042namespace orxonox
    4143{
    42     SoundBuffer::SoundBuffer(const std::string& filename)
     44    SoundBuffer::SoundBuffer(const std::string& filename, std::list<shared_ptr<SoundBuffer> >::iterator poolIterator)
    4345        : filename_(filename)
    4446        , audioBuffer_(AL_NONE)
     47        , poolIterator_(poolIterator)
    4548    {
    4649        if (this->filename_.empty())
     
    6063        if (getLowercase(extension) == "ogg")
    6164        {
     65            int before = Game::getInstance().getGameClock().getRealMicroseconds();
    6266            // Try ogg loader
    6367            this->loadOgg(fileInfo, dataStream);
     68            int after = Game::getInstance().getGameClock().getRealMicroseconds();
     69            COUT(0) << filename << ": " << (after - before) << std::endl;
    6470        }
    6571        else
     
    8086        ALint size;
    8187        alGetBufferi(this->audioBuffer_, AL_SIZE, &size);
    82         if (!alGetError())
    83             return size;
    84         else
    85             return 0;
     88        return alGetError() ? 0 : size;
    8689    }
    8790
     
    108111    {
    109112        Ogre::DataStream* stream = static_cast<Ogre::DataStream*>(datasource);
    110         int offset_beg = offset;
    111         if (whence == SEEK_CUR)
    112             offset_beg = stream->tell() + offset;
    113         else if (whence == SEEK_END)
    114             offset_beg = stream->size() + offset;
    115         else if (whence != SEEK_SET)
     113        switch (whence)
     114        {
     115        case SEEK_SET:
     116            stream->seek(offset);
     117            break;
     118        case SEEK_CUR:
     119            stream->skip(offset);
     120            break;
     121        case SEEK_END:
     122            stream->seek(stream->size() + offset);
     123            break;
     124        default:
    116125            return -1;
    117         stream->seek(offset_beg);
     126        }
    118127        return 0;
    119128    }
  • code/branches/presentation2/src/orxonox/sound/SoundBuffer.h

    r6270 r6332  
    4242    {
    4343        friend class SoundManager;
     44        // Make sure nobody deletes an instance (using smart pointers)
     45        template <class T>
     46        friend void boost::checked_delete(T*);
    4447
    4548    public:
    46         SoundBuffer(const std::string& filename);
    47         ~SoundBuffer();
    48 
    4949        inline ALuint getBuffer()
    5050            { return this->audioBuffer_; }
     
    5555            { return this->filename_; }
    5656
    57         void setPooling(bool val)
    58             { this->bPooling_ = true; }
    59         bool getPooling() const
    60             { return this->bPooling_; }
    61 
    6257    private:
     58        SoundBuffer(const std::string& filename, std::list<shared_ptr<SoundBuffer> >::iterator poolIterator);
     59        ~SoundBuffer();
    6360        void loadStandard(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream);
    6461        void loadOgg(const shared_ptr<ResourceInfo>& fileInfo, DataStreamPtr dataStream);
     
    6764        ALuint audioBuffer_;
    6865        std::list<shared_ptr<SoundBuffer> >::iterator poolIterator_;
    69         bool bPooling_;
    7066    };
    7167}
  • code/branches/presentation2/src/orxonox/sound/SoundManager.cc

    r6322 r6332  
    6060        Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
    6161
     62/*
    6263        // Get list of available sound devices and display them
    63 /*        const char* devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
     64        const char* devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
    6465        char* device = new char[strlen(devices)+1];
    6566        strcpy(device, devices);
    6667        std::string renderDevice;
    67 //        SetConfigValue(renderDevice, std::string(device)).description("Sound device used for rendering");
     68        SetConfigValue(renderDevice, std::string(device)).description("Sound device used for rendering");
    6869        COUT(4) << "Sound: Available devices: ";
    6970        while (true)
     
    7980        // Open the selected device
    8081        COUT(3) << "Sound: Opening device \"" << renderDevice << "\"" << std::endl;
    81         this->device_ = alcOpenDevice(renderDevice.c_str());*/
     82        this->device_ = alcOpenDevice(renderDevice.c_str());
     83*/
    8284        this->device_ = alcOpenDevice(NULL);
    8385        if (this->device_ == NULL)
     
    573575            try
    574576            {
    575                 buffer.reset(new SoundBuffer(filename));
    576                 buffer->poolIterator_ = this->effectsPool_.end();
     577                buffer.reset(new SoundBuffer(filename, this->effectsPool_.end()));
    577578            }
    578579            catch (...)
  • code/branches/presentation2/src/orxonox/sound/SoundManager.h

    r6322 r6332  
    9292        void unregisterAmbientSound(AmbientSound* oldAmbient);
    9393        void pauseAmbientSound(AmbientSound* ambient);
    94        
     94
    9595        void setVolume(float vol, SoundType::Value type);
    9696        float getVolume(SoundType::Value type); // tolua_export
    97        
     97
    9898        void toggleMute(SoundType::Value type); // tolua_export
    9999        bool getMute(SoundType::Value type); // tolua_export
     
    117117        void checkAmbientVolumeValidity(void);
    118118        void checkEffectsVolumeValidity(void);
    119        
     119
    120120        float checkVolumeRange(float vol);
    121        
     121
    122122        void updateVolume(SoundType::Value type);
    123        
     123
    124124        void setVolumeInternal(float vol, SoundType::Value type);
    125125        float getVolumeInternal(SoundType::Value type);
     
    128128        ALCdevice* device_;
    129129        ALCcontext* context_;
    130        
     130
    131131        typedef std::list<std::pair<AmbientSound*, bool> > AmbientList;
    132132        AmbientList ambientSounds_;
    133        
     133
    134134        float crossFadeStep_;       //!< Absolute change per second (0.1 means 10% of the nominal volume) for cross fading
    135135        std::list<AmbientSound*> fadeInList_;
    136136        std::list<AmbientSound*> fadeOutList_;
    137        
     137
    138138        float soundVolume_;
    139139        float ambientVolume_;
     
    150150        unsigned int maxSources_;
    151151        std::vector<ALuint> soundSources_;
    152        
     152
    153153        static SoundManager* singletonPtr_s;
    154154    }; // tolua_export
Note: See TracChangeset for help on using the changeset viewer.