Changeset 8181 in orxonox.OLD for branches/atmospheric_engine/src/lib/sound
- Timestamp:
- Jun 7, 2006, 9:36:31 AM (19 years ago)
- Location:
- branches/atmospheric_engine/src/lib/sound
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/sound/sound_source.cc
r8052 r8181 211 211 } 212 212 213 /** 214 * @brief Plays and loops buffer on this Source 215 * @param buffer the buffer to play back on this Source 216 */ 217 void SoundSource::loop(const SoundBuffer* buffer) 218 { 219 if (this->buffer && this->retrieveSource()) 220 { 221 if (this->bPlay) 222 alSourceStop(this->sourceID); 223 224 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 225 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 226 alSourcef (this->sourceID, AL_GAIN, 1); 227 228 alSourcePlay(this->sourceID); 229 230 if (DEBUG_LEVEL >= 3) 231 SoundEngine::checkError("Play LoopSource", __LINE__); 232 this->bPlay = true; 233 } 234 } 235 236 237 /** 238 * @brief Plays and loops buffer on this Source with gain control 239 * @param buffer the buffer to play back on this Source 240 */ 241 void SoundSource::loop(const SoundBuffer* buffer, float gain) 242 { 243 if (this->buffer && this->retrieveSource()) 244 { 245 if (this->bPlay) 246 alSourceStop(this->sourceID); 247 248 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 249 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 250 alSourcef (this->sourceID, AL_GAIN, gain); 251 252 alSourcePlay(this->sourceID); 253 254 if (DEBUG_LEVEL >= 3) 255 SoundEngine::checkError("Play LoopSource", __LINE__); 256 this->bPlay = true; 257 } 258 } 259 260 261 /** 262 * @brief Stops playback of a SoundSource 263 */ 264 void SoundSource::stop() 265 { 266 this->bPlay = false; 267 if (this->sourceID != 0) 213 /** 214 * @brief Plays and loops buffer on this Source 215 * @param buffer the buffer to play back on this Source 216 */ 217 void SoundSource::loop(const SoundBuffer* buffer) 218 { 219 if (this->buffer && this->retrieveSource()) 220 { 221 if (this->bPlay) 222 alSourceStop(this->sourceID); 223 224 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 225 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 226 alSourcef (this->sourceID, AL_GAIN, 1); 227 228 alSourcePlay(this->sourceID); 229 230 if (DEBUG_LEVEL >= 3) 231 SoundEngine::checkError("Loop Source", __LINE__); 232 this->bPlay = true; 233 } 234 } 235 236 237 /** 238 * @brief Plays and loops buffer on this Source with gain control 239 * @param buffer the buffer to play back on this Source 240 */ 241 void SoundSource::loop(const SoundBuffer* buffer, float gain) 242 { 243 if (this->buffer && this->retrieveSource()) 244 { 245 if (this->bPlay) 246 alSourceStop(this->sourceID); 247 248 alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); 249 alSourcei (this->sourceID, AL_LOOPING, AL_TRUE); 250 alSourcef (this->sourceID, AL_GAIN, gain); 251 252 alSourcePlay(this->sourceID); 253 254 if (DEBUG_LEVEL >= 3) 255 SoundEngine::checkError("Loop Source", __LINE__); 256 this->bPlay = true; 257 } 258 } 259 260 261 /** 262 * @brief Stops playback of a SoundSource 263 */ 264 void SoundSource::stop() 268 265 { 269 266 this->bPlay = false; 270 267 if (this->sourceID != 0) 271 268 { 272 alSourceStop(this->sourceID); 273 if (DEBUG_LEVEL >= 3) 274 SoundEngine::checkError("StopSource", __LINE__); 275 alSourcei(this->sourceID, AL_BUFFER, 0); 276 if (!this->resident) 277 SoundEngine::getInstance()->pushALSource(this->sourceID); 278 this->sourceID = 0; 279 } 280 } 281 } 269 this->bPlay = false; 270 if (this->sourceID != 0) 271 { 272 alSourceStop(this->sourceID); 273 if (DEBUG_LEVEL >= 3) 274 SoundEngine::checkError("StopSource", __LINE__); 275 alSourcei(this->sourceID, AL_BUFFER, 0); 276 if (!this->resident) 277 SoundEngine::getInstance()->pushALSource(this->sourceID); 278 this->sourceID = 0; 279 } 280 } 281 } 282 282 283 283 /** … … 362 362 alSourcef (sourceID, AL_GAIN, SoundEngine::getInstance()->getEffectsVolume()); 363 363 } 364 365 366 /** 367 * @brief Fades in a Source over a time period 368 * @param duration time perios to fade in 369 */ 370 void SoundSource::fadein(const SoundBuffer* buffer, ALfloat duration) 371 { 372 //if (this->buffer && this->retrieveSource()) 373 //{ 374 375 for (ALfloat n = 0.0; n < 1.0; n+=.01) 376 { 377 alSourcef(this->sourceID, AL_GAIN, n); 378 // sleep(1); 379 } 380 381 // alSourcePlay(this->sourceID); 382 383 // if (DEBUG_LEVEL >= 3) 384 // SoundEngine::checkError("Loop Source", __LINE__); 385 // this->bPlay = true; 386 //} 387 388 } 389 390 364 391 } -
branches/atmospheric_engine/src/lib/sound/sound_source.h
r8052 r8181 1 1 /*! 2 3 2 * @file sound_source.h 3 * @brief Definition of the SoundSource. 4 4 */ 5 5 … … 14 14 namespace OrxSound 15 15 { 16 class SoundBuffer; 17 //! A class that represents a SoundSource 18 class SoundSource : public BaseObject 19 { 20 public: 21 SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL); 22 SoundSource(const SoundSource& source); 23 SoundSource& operator=(const SoundSource& source); 24 bool operator==(const SoundSource& source); 25 26 virtual ~SoundSource(); 27 28 // user interaction 29 void play(); 30 void play(const SoundBuffer* buffer); 31 void play(const SoundBuffer* buffer, float gain); 32 void loop(); 33 void loop(const SoundBuffer* buffer); 34 void loop(const SoundBuffer* buffer, float gain); 35 void stop(); 36 void pause(); 37 void rewind(); 38 39 // development functions 40 /** @returns The ID of this Source */ 41 inline ALuint getID() const { return this->sourceID; }; 42 /** @returns true, if the Source is Playing */ 43 inline bool isPlaying() const { return this->bPlay; }; 44 void setSourceNode(const PNode* sourceNode); 45 /** @returns the SoundBuffer of this Source */ 46 inline const SoundBuffer* getBuffer() const { return this->buffer; }; 47 /** @returns the SourceNode of this Source */ 48 inline const PNode* getNode() const { return this->sourceNode; }; 49 /** @param resident if the Source is Resident */ 50 inline void setResident(bool resident) { this->resident = resident; }; 51 /** @returns true if the alSource is Resident */ 52 inline bool isResident() const { return this->resident; }; 53 54 void setRolloffFactor(ALfloat rolloffFactor); 55 56 static void resetSource(ALuint sourceID); 57 58 private: 59 bool retrieveSource(); 60 61 private: 62 bool bPlay; //!< If the Source is Playing. 63 bool resident; //!< If the alSource should be resident (if true, the alSource will be returned on deletion). 64 ALuint sourceID; //!< The ID of the Source 65 const SoundBuffer* buffer; //!< The buffer to play in this source. 66 const PNode* sourceNode; //!< The SourceNode representing the position/velocity... of this source. 67 }; 16 class SoundBuffer; 17 //! A class that represents a SoundSource 18 class SoundSource : public BaseObject 19 { 20 public: 21 SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL); 22 SoundSource(const SoundSource& source); 23 SoundSource& operator=(const SoundSource& source); 24 bool operator==(const SoundSource& source); 25 26 virtual ~SoundSource(); 27 28 // user interaction 29 void play(); 30 void play(const SoundBuffer* buffer); 31 void play(const SoundBuffer* buffer, float gain); 32 void loop(); 33 void loop(const SoundBuffer* buffer); 34 void loop(const SoundBuffer* buffer, float gain); 35 void stop(); 36 void pause(); 37 void rewind(); 38 void fadein(const SoundBuffer* buffer, ALfloat duration); 39 40 41 // development functions 42 /** @returns The ID of this Source */ 43 inline ALuint getID() const { return this->sourceID; }; 44 /** @returns true, if the Source is Playing */ 45 inline bool isPlaying() const { return this->bPlay; }; 46 void setSourceNode(const PNode* sourceNode); 47 /** @returns the SoundBuffer of this Source */ 48 inline const SoundBuffer* getBuffer() const { return this->buffer; }; 49 /** @returns the SourceNode of this Source */ 50 inline const PNode* getNode() const { return this->sourceNode; }; 51 /** @param resident if the Source is Resident */ 52 inline void setResident(bool resident) { this->resident = resident; }; 53 /** @returns true if the alSource is Resident */ 54 inline bool isResident() const { return this->resident; }; 55 56 void setRolloffFactor(ALfloat rolloffFactor); 57 58 static void resetSource(ALuint sourceID); 59 60 private: 61 bool retrieveSource(); 62 63 private: 64 bool bPlay; //!< If the Source is Playing. 65 bool resident; //!< If the alSource should be resident (if true, the alSource will be returned on deletion). 66 ALuint sourceID; //!< The ID of the Source 67 const SoundBuffer* buffer; //!< The buffer to play in this source. 68 const PNode* sourceNode; //!< The SourceNode representing the position/velocity... of this source. 69 }; 68 70 } 69 71 #endif /* _SOUND_SOURCE_H */
Note: See TracChangeset
for help on using the changeset viewer.