Changeset 5386 in orxonox.OLD for trunk/src/lib/sound/sound_engine.cc
- Timestamp:
- Oct 15, 2005, 11:44:14 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/sound/sound_engine.cc
r5385 r5386 17 17 */ 18 18 19 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY 19 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND 20 20 21 21 #include "sound_engine.h" … … 31 31 32 32 using namespace std; 33 34 //////////////////35 /* SOUND-BUFFER */36 //////////////////37 /**38 * Creates a Soundbuffer out of an inputfile39 * @param fileName The name of the File40 */41 SoundBuffer::SoundBuffer(const char* fileName)42 {43 this->setClassID(CL_SOUND_BUFFER, "SoundBuffer");44 this->setName(fileName);45 46 SoundEngine::getInstance()->addBuffer(this);47 48 ALenum format;49 ALvoid* data;50 ALsizei freq;51 52 ALenum result;53 54 // generate a Buffer55 alGenBuffers(1, &this->bufferID);56 if ((result = alGetError()) != AL_NO_ERROR)57 SoundEngine::PrintALErrorString(result);58 59 // read in the wav data60 /* according to http://www.edenwaith.com/products/pige/tutorials/openal.php the alutLoadWAVFile differs from platform to platform*/61 #ifdef __APPLE__62 alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq);63 #elif defined __WIN32__64 alutLoadWAVFile(fileName, &format, &data, &size, &freq, &this->loop);65 #else66 alutLoadWAVFile((ALbyte*)fileName, &format, &data, &this->size, &freq, &this->loop);67 #endif68 if ((result = alGetError()) != AL_NO_ERROR)69 SoundEngine::PrintALErrorString(result);70 71 // send the loaded wav data to the buffer72 alBufferData(this->bufferID, format, data, this->size, freq);73 if ((result = alGetError()) != AL_NO_ERROR)74 SoundEngine::PrintALErrorString(result);75 76 // remove the wav data (redundant)77 alutUnloadWAV(format, data, this->size, freq);78 if ((result = alGetError()) != AL_NO_ERROR)79 SoundEngine::PrintALErrorString(result);80 }81 82 SoundBuffer::~SoundBuffer()83 {84 // SoundEngine::getInstance()->removeBuffer(this);85 alDeleteBuffers(1, &this->bufferID);86 }87 88 //////////////////89 /* SOUND-SOURCE */90 //////////////////91 /**92 * creates a SoundSource at position sourceNode with the SoundBuffer buffer93 */94 SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer)95 {96 this->setClassID(CL_SOUND_SOURCE, "SoundSource");97 98 ALenum result;99 100 // adding the Source to the SourcesList of the SoundEngine101 SoundEngine::getInstance()->addSource(this);102 103 this->buffer = buffer;104 this->sourceNode = sourceNode;105 106 alGenSources(1, &this->sourceID);107 if ((result = alGetError()) != AL_NO_ERROR)108 SoundEngine::PrintALErrorString(result);109 if (this->buffer != NULL)110 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());111 alSourcef (this->sourceID, AL_PITCH, 1.0 );112 alSourcef (this->sourceID, AL_GAIN, SoundEngine::getInstance()->getEffectsVolume() );113 alSourcei (sourceID, AL_LOOPING, AL_FALSE );114 }115 116 /**117 * deletes a SoundSource118 */119 SoundSource::~SoundSource()120 {121 //SoundEngine::getInstance()->removeSource(this);122 alDeleteSources(1, &this->sourceID);123 }124 125 /**126 * Plays back a SoundSource127 */128 void SoundSource::play()129 {130 alSourcePlay(this->sourceID);131 }132 133 /**134 * Plays back buffer on this Source135 * @param buffer the buffer to play back on this Source136 */137 void SoundSource::play(const SoundBuffer* buffer)138 {139 alSourceStop(this->sourceID);140 alSourcei (this->sourceID, AL_BUFFER, buffer->getID());141 alSourcePlay(this->sourceID);142 143 if (unlikely(this->buffer != NULL))144 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());145 }146 147 /**148 * Stops playback of a SoundSource149 */150 void SoundSource::stop()151 {152 alSourceStop(this->sourceID);153 }154 155 /**156 * Pauses Playback of a SoundSource157 */158 void SoundSource::pause()159 {160 alSourcePause(this->sourceID);161 }162 163 /**164 * Rewinds Playback of a SoundSource165 */166 void SoundSource::rewind()167 {168 alSourceRewind(this->sourceID);169 }170 171 /**172 * sets the RolloffFactor of the Sound emitted from the SoundSource173 * @param rolloffFactor The Factor described174 175 this tells openAL how fast the Sounds decay outward from the Source176 */177 void SoundSource::setRolloffFactor(ALfloat rolloffFactor)178 {179 alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor);180 }181 182 33 183 34 … … 439 290 const char* devWalk = deviceList; 440 291 if (alcIsExtensionPresent(NULL, (ALubyte*)"ALC_ENUMERATION_EXT") == AL_TRUE) { // try out enumeration extension 441 printf("Enumeration-extension found\n");442 443 printf("Default device: %s\n", defaultDevice);292 PRINTF(3)("Enumeration-extension found\n"); 293 294 PRINTF(3)("Default device: %s\n", defaultDevice); 444 295 do 445 296 { 446 printf("%s\n", devWalk);297 PRINTF(3)("%s\n", devWalk); 447 298 devWalk += strlen(devWalk)+1; 448 299 } while (devWalk[0] != '\0');
Note: See TracChangeset
for help on using the changeset viewer.