Changeset 6244 for code/branches/presentation2/src/orxonox
- Timestamp:
- Dec 4, 2009, 3:26:08 PM (15 years ago)
- Location:
- code/branches/presentation2/src/orxonox/sound
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/orxonox/sound/SoundManager.cc
r6241 r6244 23 23 * Erwin 'vaiursch' Herrsche 24 24 * Kevin Young 25 * Reto Grieder 25 26 * Co-authors: 26 27 * ... … … 36 37 #include "util/Math.h" 37 38 #include "util/ScopeGuard.h" 38 #include "util/StringUtils.h"39 39 #include "util/Clock.h" 40 40 #include "core/ConfigValueIncludes.h" … … 55 55 RegisterRootObject(SoundManager); 56 56 57 /*58 57 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())); 62 59 Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit); 63 60 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()); 71 79 if (this->device_ == NULL) 72 80 { 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; 74 82 #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; 76 84 #endif 77 85 ThrowException(InitialisationFailed, "Sound: OpenAL error: Could not open sound device."); … … 79 87 Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_); 80 88 81 COUT(3) << "Sound: OpenAL: Sound device opened" << std::endl;89 // Create sound context and make it the currently used one 82 90 this->context_ = alcCreateContext(this->device_, NULL); 83 91 if (this->context_ == NULL) 84 ThrowException(InitialisationFailed, "Sound : OpenAL error: Could not create soundcontext");92 ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context"); 85 93 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; 95 106 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 100 109 // Disarm guards 101 110 alutExitGuard.Dismiss(); 102 /*103 111 closeDeviceGuard.Dismiss(); 104 112 desroyContextGuard.Dismiss(); 105 */106 113 107 114 this->setVolumeInternal(1.0, SoundType::none); … … 114 121 115 122 this->setConfigValues(); 123 124 COUT(4) << "Sound: Initialisation complete" << std::endl; 116 125 } 117 126 … … 119 128 { 120 129 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; 122 134 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 123 146 alcCloseDevice(this->device_); 124 */ 125 alutExit(); 147 #endif 148 if (!alutExit()) 149 COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl; 126 150 } 127 151 … … 150 174 } 151 175 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 152 190 void SoundManager::checkFadeStepValidity() 153 191 { -
code/branches/presentation2/src/orxonox/sound/SoundManager.h
r6237 r6244 23 23 * Erwin 'vaiursch' Herrsche 24 24 * Kevin Young 25 * Reto Grieder 25 26 * Co-authors: 26 27 * ... … … 39 40 #include "util/Singleton.h" 40 41 #include "core/OrxonoxClass.h" 42 43 // forward declaration 44 typedef int ALenum; 41 45 42 46 // tolua_begin … … 75 79 void setConfigValues(); 76 80 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 78 88 79 89 void setListenerPosition(const Vector3& position); … … 92 102 shared_ptr<SoundBuffer> getSoundBuffer(shared_ptr<ResourceInfo> fileInfo); 93 103 void removeBuffer(shared_ptr<ResourceInfo> fileInfo); 104 105 static std::string getALErrorString(ALenum error); 94 106 95 107 private: … … 111 123 float getVolumeInternal(SoundType::Value type); 112 124 113 /* 125 std::vector<std::string> deviceNames_; 114 126 ALCdevice* device_; 115 127 ALCcontext* context_; 116 */117 128 118 129 typedef std::list<std::pair<AmbientSound*, bool> > AmbientList;
Note: See TracChangeset
for help on using the changeset viewer.