Changeset 5968 in orxonox.OLD for branches/network/src/lib/sound/sound_engine.cc
- Timestamp:
- Dec 7, 2005, 4:16:51 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/sound/sound_engine.cc
r5832 r5968 27 27 #include "resource_manager.h" 28 28 #include "debug.h" 29 #include " ini_parser.h"29 #include "parser/ini_parser/ini_parser.h" 30 30 #include "globals.h" 31 31 … … 47 47 this->bufferList = NULL; 48 48 this->sourceList = NULL; 49 50 this->device = NULL; 51 this->context = NULL; 52 53 this->maxSourceCount = 32; 49 54 } 50 55 … … 64 69 while (this->sourceList->size() > 0) 65 70 delete dynamic_cast<SoundSource*>(this->sourceList->front()); 71 } 72 73 while(!this->ALSources.empty()) 74 { 75 alDeleteSources(1, &this->ALSources.top()); 76 this->ALSources.pop(); 66 77 } 67 78 … … 86 97 void SoundEngine::loadSettings(IniParser* iniParser) 87 98 { 99 const char* channels = iniParser->getVar(CONFIG_NAME_AUDIO_CHANNELS, CONFIG_SECTION_AUDIO, "32"); 100 this->maxSourceCount = atoi(channels); 88 101 const char* musicVolume = iniParser->getVar(CONFIG_NAME_MUSIC_VOLUME, CONFIG_SECTION_AUDIO, "80"); 89 102 this->musicVolume = atof(musicVolume)/100.0; … … 118 131 119 132 120 /** 121 * adds a SoundBuffer to the bufferList of the SoundEngine 122 * @param buffer The buffer to add to the bufferList 123 */ 124 void SoundEngine::addBuffer(SoundBuffer* buffer) 125 { 126 if (unlikely(this->bufferList == NULL)) 127 this->bufferList = ClassList::getList(CL_SOUND_BUFFER); 128 } 129 130 /** 131 * removes a SoundBuffer from the bufferList of the SoundEngine 132 * @param buffer The buffer to delete from the SoundEngine 133 */ 134 void SoundEngine::removeBuffer(SoundBuffer* buffer) 135 { 136 // look if there are any sources that have the buffer still loaded 137 if (this->sourceList != NULL) 138 { 139 list<BaseObject*>::iterator source; 140 for (source = this->sourceList->begin(); source != this->sourceList->end(); source++) 141 { 142 if (buffer == static_cast<SoundSource*>(*source)->getBuffer()) 143 delete (*source); 133 void SoundEngine::popALSource(ALuint& source) 134 { 135 if (source != 0) 136 return; 137 else 138 { 139 140 /// @TODO try to create more sources if needed 141 if (!this->ALSources.empty()) 142 { 143 144 source = this->ALSources.top(); 145 printf("test: : %d\n", source); 146 this->ALSources.pop(); 144 147 } 145 148 } 146 149 } 147 150 148 /**149 * adds a SoundSource to the sourceList of the SoundEngine150 * @param source The source to add to the sourceList151 */152 void SoundEngine::addSource(SoundSource* source)153 {154 this->sourceList = ClassList::getList(CL_SOUND_SOURCE);155 }156 151 157 152 /** … … 180 175 181 176 // updating all the Sources positions 182 if (likely(this->sourceList != NULL ))183 { 184 list<BaseObject*>:: iterator sourceIT;177 if (likely(this->sourceList != NULL || (this->sourceList = ClassList::getList(CL_SOUND_SOURCE)) != NULL)) 178 { 179 list<BaseObject*>::const_iterator sourceIT; 185 180 SoundSource* source; 186 181 for (sourceIT = this->sourceList->begin(); sourceIT != this->sourceList->end(); sourceIT++) 187 182 { 188 183 source = static_cast<SoundSource*>(*sourceIT); 189 if ( likely(source->getNode() != NULL))184 if (source->isPlaying()) 190 185 { 191 alSource3f(source->getID(), AL_POSITION, 192 source->getNode()->getAbsCoor().x, 193 source->getNode()->getAbsCoor().y, 194 source->getNode()->getAbsCoor().z); 195 alSource3f(source->getID(), AL_VELOCITY, 196 source->getNode()->getVelocity().x, 197 source->getNode()->getVelocity().y, 198 source->getNode()->getVelocity().z); 186 int play; 187 alGetSourcei(source->getID(), AL_SOURCE_STATE, &play); 188 if(play == AL_PLAYING) 189 { 190 if (likely(source->getNode() != NULL)) 191 { 192 alSource3f(source->getID(), AL_POSITION, 193 source->getNode()->getAbsCoor().x, 194 source->getNode()->getAbsCoor().y, 195 source->getNode()->getAbsCoor().z); 196 alSource3f(source->getID(), AL_VELOCITY, 197 source->getNode()->getVelocity().x, 198 source->getNode()->getVelocity().y, 199 source->getNode()->getVelocity().z); 200 } 201 202 } 203 else 204 { 205 source->stop(); 206 } 199 207 } 200 208 } … … 282 290 // INITIALIZING THE DEVICE: 283 291 284 ALchar deviceName[] = 292 #ifdef AL_VERSION_1_1 293 ALubyte deviceName[] = 294 #else 295 ALCchar deviceName[] = 296 #endif 297 285 298 #ifdef __WIN32__ 286 " native";299 "Direct3D"; 287 300 #else 288 "'( ( devices '( native artsnull ) ) )";301 "'( ( devices '( native null ) ) )"; 289 302 #endif 290 303 // … … 297 310 298 311 if ((result = alGetError()) != AL_NO_ERROR) 299 SoundEngine::PrintALErrorString(result);312 PRINTF(2)("%s\n", SoundEngine::getALErrorString(result)); 300 313 301 314 this->setDopplerValues(SOUND_DOPPLER_FACTOR, SOUND_DOPPLER_VELOCITY); 315 } 316 317 318 /** 319 * Allocates openAL sources 320 * @param count how many sources to allocate 321 * @returns true on success, false if at least one source could not be allocated 322 */ 323 bool SoundEngine::allocateSources(unsigned int count) 324 { 325 ALenum result; 326 // Setting default values. 327 for (unsigned int i = 0; i < count; i++) 328 { 329 ALuint source; 330 331 alGenSources(1, &source); 332 if ((result = alGetError()) != AL_NO_ERROR) 333 PRINTF(1)("Error Generating Sources: '%s'\n", SoundEngine::getALErrorString(result)); 334 335 alSourcef (source, AL_PITCH, 1.0 ); 336 alSourcef (source, AL_GAIN, this->getEffectsVolume() ); 337 alSourcei (source, AL_LOOPING, AL_FALSE ); 338 this->ALSources.push(source); 339 } 340 return true; 302 341 } 303 342 … … 306 345 * @param err The error found 307 346 */ 308 void SoundEngine::PrintALErrorString(ALenum err)347 const char* SoundEngine::getALErrorString(ALenum err) 309 348 { 310 349 switch(err) 311 350 { 312 351 case AL_NO_ERROR: 313 PRINTF(4)("AL_NO_ERROR\n"); 314 break; 315 352 return ("AL_NO_ERROR"); 316 353 case AL_INVALID_NAME: 317 PRINTF(2)("AL_INVALID_NAME\n"); 318 break; 319 354 return ("AL_INVALID_NAME"); 320 355 case AL_INVALID_ENUM: 321 PRINTF(2)("AL_INVALID_ENUM\n"); 322 break; 323 356 return ("AL_INVALID_ENUM"); 324 357 case AL_INVALID_VALUE: 325 PRINTF(2)("AL_INVALID_VALUE\n"); 326 break; 327 358 return ("AL_INVALID_VALUE"); 328 359 case AL_INVALID_OPERATION: 329 PRINTF(2)("AL_INVALID_OPERATION\n"); 330 break; 331 360 return ("AL_INVALID_OPERATION"); 332 361 case AL_OUT_OF_MEMORY: 333 PRINTF(2)("AL_OUT_OF_MEMORY\n"); 334 break; 362 return ("AL_OUT_OF_MEMORY"); 335 363 }; 336 364 } … … 338 366 void SoundEngine::listDevices() 339 367 { 340 341 368 printf("%s\n",(const char*)alcGetString(NULL, ALC_DEVICE_SPECIFIER)); 342 369 }
Note: See TracChangeset
for help on using the changeset viewer.