Changeset 5386 in orxonox.OLD for trunk/src/lib/sound/sound_source.cc
- Timestamp:
- Oct 15, 2005, 11:44:14 PM (19 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/sound/sound_source.cc
r5382 r5386 10 10 11 11 ### File Specific: 12 main-programmer: ...12 main-programmer: Benjamin Grauer 13 13 co-programmer: ... 14 14 */ 15 15 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND 17 17 18 #include "proto_class.h" 18 #include "sound_source.h" 19 #include "sound_engine.h" 20 #include "alincl.h" 21 #include "compiler.h" 19 22 20 23 using namespace std; 21 24 25 /** 26 * creates a SoundSource at position sourceNode with the SoundBuffer buffer 27 */ 28 SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer) 29 { 30 this->setClassID(CL_SOUND_SOURCE, "SoundSource"); 31 32 ALenum result; 33 34 // adding the Source to the SourcesList of the SoundEngine 35 SoundEngine::getInstance()->addSource(this); 36 37 this->buffer = buffer; 38 this->sourceNode = sourceNode; 39 40 alGenSources(1, &this->sourceID); 41 if ((result = alGetError()) != AL_NO_ERROR) 42 SoundEngine::PrintALErrorString(result); 43 if (this->buffer != NULL) 44 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 45 alSourcef (this->sourceID, AL_PITCH, 1.0 ); 46 alSourcef (this->sourceID, AL_GAIN, SoundEngine::getInstance()->getEffectsVolume() ); 47 alSourcei (sourceID, AL_LOOPING, AL_FALSE ); 48 } 22 49 23 50 /** 24 * standard constructor 25 * @todo this constructor is not jet implemented - do it 26 */ 27 ProtoClass::ProtoClass () 51 * deletes a SoundSource 52 */ 53 SoundSource::~SoundSource() 28 54 { 29 this->setClassID(CL_PROTO_ID, "ProtoClass"); 30 31 /* If you make a new class, what is most probably the case when you write this file 32 don't forget to: 33 1. Add the new file new_class.cc to the ./src/Makefile.am 34 2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS 35 36 Advanced Topics: 37 - if you want to let your object be managed via the ObjectManager make sure to read 38 the object_manager.h header comments. You will use this most certanly only if you 39 make many objects of your class, like a weapon bullet. 40 */ 55 //SoundEngine::getInstance()->removeSource(this); 56 alDeleteSources(1, &this->sourceID); 41 57 } 42 58 59 /** 60 * Plays back a SoundSource 61 */ 62 void SoundSource::play() 63 { 64 alSourcePlay(this->sourceID); 65 } 43 66 44 67 /** 45 * standard deconstructor 46 */ 47 ProtoClass::~ProtoClass () 68 * Plays back buffer on this Source 69 * @param buffer the buffer to play back on this Source 70 */ 71 void SoundSource::play(const SoundBuffer* buffer) 48 72 { 49 // delete what has to be deleted here 73 alSourceStop(this->sourceID); 74 alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); 75 alSourcePlay(this->sourceID); 76 77 if (unlikely(this->buffer != NULL)) 78 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 50 79 } 80 81 /** 82 * Stops playback of a SoundSource 83 */ 84 void SoundSource::stop() 85 { 86 alSourceStop(this->sourceID); 87 } 88 89 /** 90 * Pauses Playback of a SoundSource 91 */ 92 void SoundSource::pause() 93 { 94 alSourcePause(this->sourceID); 95 } 96 97 /** 98 * Rewinds Playback of a SoundSource 99 */ 100 void SoundSource::rewind() 101 { 102 alSourceRewind(this->sourceID); 103 } 104 105 /** 106 * sets the RolloffFactor of the Sound emitted from the SoundSource 107 * @param rolloffFactor The Factor described 108 109 this tells openAL how fast the Sounds decay outward from the Source 110 */ 111 void SoundSource::setRolloffFactor(ALfloat rolloffFactor) 112 { 113 alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor); 114 } 115
Note: See TracChangeset
for help on using the changeset viewer.