Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6244


Ignore:
Timestamp:
Dec 4, 2009, 3:26:08 PM (15 years ago)
Author:
rgrieder
Message:

Enhanced startup and shutdown sequence of the SoundManager in respect to error handling.
Also SoundManager::getALErrorString(ALEnum) returns the error as std::string (static function).

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

Legend:

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

    r6241 r6244  
    2323 *       Erwin 'vaiursch' Herrsche
    2424 *       Kevin Young
     25 *       Reto Grieder
    2526 *   Co-authors:
    2627 *      ...
     
    3637#include "util/Math.h"
    3738#include "util/ScopeGuard.h"
    38 #include "util/StringUtils.h"
    3939#include "util/Clock.h"
    4040#include "core/ConfigValueIncludes.h"
     
    5555        RegisterRootObject(SoundManager);
    5656
    57 /*
    5857        if (!alutInitWithoutContext(NULL, NULL))
    59 */
    60         if (!alutInit(NULL, NULL))
    61             ThrowException(InitialisationFailed, "Sound: OpenAL ALUT error: " << alutGetErrorString(alutGetError()));
     58            ThrowException(InitialisationFailed, "Sound Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
    6259        Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
    6360
    64         // Note: Everything related to ALC has been commented because there seem to be
    65         // very serious problems with the unloading sequence (complete freeze on Linux,
    66         // sometimes really everything gone, including response to any signals).
    67         // For the moment ALUT can do everything we need so far.
    68 /*
    69         COUT(3) << "Sound: OpenAL: Opening sound device..." << std::endl;
    70         this->device_ = alcOpenDevice(NULL);
     61        // Get list of available sound devices and display them
     62        const char* devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
     63        std::string renderDevice;
     64        SetConfigValue(renderDevice, devices).description("Sound device used for rendering");
     65        COUT(4) << "Sound: Available devices: ";
     66        while (true)
     67        {
     68            this->deviceNames_.push_back(devices);
     69            COUT(4) << "\"" << devices << "\", ";
     70            devices += strlen(devices) + 1;
     71            if (*devices == '\0')
     72                break;
     73        }
     74        COUT(4) << std::endl;
     75
     76        // Open the selected device
     77        COUT(3) << "Sound: Opening device \"" << renderDevice << "\"" << std::endl;
     78        this->device_ = alcOpenDevice(renderDevice.c_str());
    7179        if (this->device_ == NULL)
    7280        {
    73             COUT(0) << "Sound: OpenaAL: Could not open sound device. Have you installed OpenAL?" << std::endl;
     81            COUT(1) << "Sound: Could not open sound device. Have you installed OpenAL?" << std::endl;
    7482#ifdef ORXONOX_PLATFORM_WINDOWS
    75             COUT(0) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
     83            COUT(1) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
    7684#endif
    7785            ThrowException(InitialisationFailed, "Sound: OpenAL error: Could not open sound device.");
     
    7987        Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
    8088
    81         COUT(3) << "Sound: OpenAL: Sound device opened" << std::endl;
     89        // Create sound context and make it the currently used one
    8290        this->context_ = alcCreateContext(this->device_, NULL);
    8391        if (this->context_ == NULL)
    84             ThrowException(InitialisationFailed, "Sound: OpenAL error: Could not create sound context");
     92            ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context");
    8593        Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);
    86 
    87         if (alcMakeContextCurrent(this->context_) == AL_TRUE)
    88             COUT(3) << "Sound: OpenAL: Context " << this->context_ << " loaded" << std::endl;
    89 
    90         COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
    91 
    92         const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
    93         if (str == NULL)
    94             COUT(2) << "Sound: OpenAL ALUT error: " << alutGetErrorString(alutGetError()) << std::endl;
     94        if (!alcMakeContextCurrent(this->context_))
     95            ThrowException(InitialisationFailed, "Sound Error: Could not use ALC context");
     96
     97        GameMode::setPlaysSound(true);
     98
     99        // Get some information about the sound
     100        if (const char* version = alGetString(AL_VERSION))
     101            COUT(4) << "Sound: --- OpenAL Version: " << version << std::endl;
     102        if (const char* vendor = alGetString(AL_VENDOR))
     103            COUT(4) << "Sound: --- OpenAL Vendor : " << vendor << std::endl;
     104        if (const char* types = alutGetMIMETypes(ALUT_LOADER_BUFFER))
     105            COUT(4) << "Sound: --- Supported MIME Types: " << types << std::endl;
    95106        else
    96             COUT(4) << "Sound: OpenAL ALUT supported MIME types: " << str << std::endl;
    97 */
    98 
    99         GameMode::setPlaysSound(true);
     107            COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
     108
    100109        // Disarm guards
    101110        alutExitGuard.Dismiss();
    102 /*
    103111        closeDeviceGuard.Dismiss();
    104112        desroyContextGuard.Dismiss();
    105 */
    106113       
    107114        this->setVolumeInternal(1.0, SoundType::none);
     
    114121
    115122        this->setConfigValues();
     123
     124        COUT(4) << "Sound: Initialisation complete" << std::endl;
    116125    }
    117126
     
    119128    {
    120129        GameMode::setPlaysSound(false);
    121 /*
     130
     131        // Relieve context to destroy it
     132        if (!alcMakeContextCurrent(NULL))
     133            COUT(1) << "Sound Error: Could not unset ALC context" << std::endl;
    122134        alcDestroyContext(this->context_);
     135        if (ALCenum error = alcGetError(this->device_))
     136        {
     137            if (error == AL_INVALID_OPERATION)
     138                COUT(1) << "Sound Error: Could not destroy ALC context because it is the current one" << std::endl;
     139            else
     140                COUT(1) << "Sound Error: Could not destroy ALC context because it is invalid" << std::endl;
     141        }
     142#ifdef AL_VERSION_1_1
     143        if (!alcCloseDevice(this->device_))
     144            COUT(1) << "Sound Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
     145#else
    123146        alcCloseDevice(this->device_);
    124 */
    125         alutExit();
     147#endif
     148        if (!alutExit())
     149            COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
    126150    }
    127151
     
    150174    }
    151175
     176    std::string SoundManager::getALErrorString(ALenum code)
     177    {
     178        switch (code)
     179        {
     180        case AL_NO_ERROR:          return "No error";
     181        case AL_INVALID_NAME:      return "Invalid AL parameter name";
     182        case AL_INVALID_ENUM:      return "Invalid AL enum";
     183        case AL_INVALID_VALUE:     return "Invalid AL value";
     184        case AL_INVALID_OPERATION: return "Invalid AL operation";
     185        case AL_OUT_OF_MEMORY:     return "AL reports out of memory";
     186        default:                   return "Unknown AL error";
     187        }
     188    }
     189
    152190    void SoundManager::checkFadeStepValidity()
    153191    {
  • code/branches/presentation2/src/orxonox/sound/SoundManager.h

    r6237 r6244  
    2323 *       Erwin 'vaiursch' Herrsche
    2424 *       Kevin Young
     25 *       Reto Grieder
    2526 *   Co-authors:
    2627 *      ...
     
    3940#include "util/Singleton.h"
    4041#include "core/OrxonoxClass.h"
     42
     43// forward declaration
     44typedef int ALenum;
    4145
    4246// tolua_begin
     
    7579        void setConfigValues();
    7680       
    77         static SoundManager& getInstance() { return Singleton<SoundManager>::getInstance(); } // tolua_export
     81        // tolua_begin
     82        static SoundManager& getInstance()
     83            { return Singleton<SoundManager>::getInstance(); }
     84
     85        std::string getDeviceName(unsigned int index) const
     86            { return index < this->deviceNames_.size() ? this->deviceNames_[index] : std::string(); }
     87        // tolua_end
    7888
    7989        void setListenerPosition(const Vector3& position);
     
    92102        shared_ptr<SoundBuffer> getSoundBuffer(shared_ptr<ResourceInfo> fileInfo);
    93103        void removeBuffer(shared_ptr<ResourceInfo> fileInfo);
     104
     105        static std::string getALErrorString(ALenum error);
    94106
    95107    private:
     
    111123        float getVolumeInternal(SoundType::Value type);
    112124
    113 /*
     125        std::vector<std::string> deviceNames_;
    114126        ALCdevice* device_;
    115127        ALCcontext* context_;
    116 */
    117128       
    118129        typedef std::list<std::pair<AmbientSound*, bool> > AmbientList;
Note: See TracChangeset for help on using the changeset viewer.