Changeset 7317 in orxonox.OLD for trunk/src/lib/sound/sound_source.cc
- Timestamp:
- Apr 17, 2006, 2:25:27 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/sound/sound_source.cc
r7299 r7317 34 34 this->buffer = buffer; 35 35 this->sourceNode = sourceNode; 36 this->resident = false; 36 37 37 38 this->sourceID = 0; 38 39 this->bPlay = false; 39 40 } 41 40 42 41 43 /** … … 53 55 this->buffer = source.buffer; 54 56 this->sourceNode = source.sourceNode; 57 this->resident = source.resident; 55 58 56 59 this->sourceID = 0; … … 63 66 this->bPlay = false; 64 67 } 68 65 69 66 70 /** … … 74 78 this->buffer = source.buffer; 75 79 this->sourceNode = sourceNode; 80 this->resident = source.resident; 76 81 77 82 if (source.bPlay) … … 81 86 } 82 87 88 83 89 /** 84 90 * @brief compares two Sources with each other. … … 94 100 } 95 101 102 96 103 /** 97 104 * @brief deletes a SoundSource … … 100 107 { 101 108 this->stop(); 102 } 109 if (this->sourceID != 0) 110 SoundEngine::getInstance()->pushALSource(this->sourceID); 111 } 112 103 113 104 114 /** … … 107 117 void SoundSource::play() 108 118 { 109 if (this->sourceID == 0) 110 SoundEngine::getInstance()->popALSource(this->sourceID); 111 alSourcePlay(this->sourceID); 112 if (DEBUG >= 3) 113 SoundEngine::checkError("Play Source", __LINE__); 114 this->bPlay = true; 115 } 116 117 /** 118 * Plays back buffer on this Source 119 if (this->retrieveSource()) 120 { 121 alSourcePlay(this->sourceID); 122 if (DEBUG >= 3) 123 SoundEngine::checkError("Play Source", __LINE__); 124 this->bPlay = true; 125 } 126 } 127 128 129 /** 130 * @brief Plays back buffer on this Source 119 131 * @param buffer the buffer to play back on this Source 120 132 */ 121 133 void SoundSource::play(const SoundBuffer* buffer) 122 134 { 123 if (unlikely(this->sourceID == 0)) 124 { 125 SoundEngine::getInstance()->popALSource(this->sourceID); 126 if (sourceID == 0) 127 { 128 PRINTF(2)("No more Free source\n"); 129 return; 130 } 131 } 132 // assert (this->sourceID != 0); 135 if (!this->retrieveSource()) 136 { 137 PRINTF(2)("No more Free sources (You might consider raising the Source-Count).\n"); 138 return; 139 } 133 140 134 141 alSourceStop(this->sourceID); … … 143 150 SoundEngine::checkError("Play Source", __LINE__); 144 151 } 152 145 153 146 154 /** … … 156 164 SoundEngine::checkError("StopSource", __LINE__); 157 165 alSourcei(this->sourceID, AL_BUFFER, 0); 158 SoundEngine::getInstance()->pushALSource(this->sourceID); 166 if (!this->resident) 167 SoundEngine::getInstance()->pushALSource(this->sourceID); 159 168 this->sourceID = 0; 160 169 } 161 170 } 162 171 172 163 173 /** 164 174 * @brief Pauses Playback of a SoundSource … … 171 181 } 172 182 183 173 184 /** 174 185 * @brief Rewinds Playback of a SoundSource … … 181 192 SoundEngine::checkError("Rewind Source", __LINE__); 182 193 } 194 183 195 184 196 /** … … 196 208 } 197 209 210 211 /** 212 * @brief sets the Positional this Source should be attached to. 213 * @param sourceNode the Source this is attached to. 214 * If sourceNode == NULL then the Source will be centered, and Audio will be played on all channels. 215 */ 216 void SoundSource::setSourceNode(const PNode* sourceNode) 217 { 218 this->sourceNode = sourceNode; 219 } 220 221 /** 222 * @brief retrieve a Source. 223 */ 224 bool SoundSource::retrieveSource() 225 { 226 if (this->sourceID != 0) 227 return true; 228 else 229 { 230 SoundEngine::getInstance()->popALSource(this->sourceID); 231 if (this->sourceID != 0) 232 { 233 if (unlikely(this->sourceNode == NULL)) 234 resetSource(this->sourceID); 235 return true; 236 } 237 } 238 return false; 239 } 240 241 242 /** 243 * @brief reset an alSource to its default Values. 244 */ 245 void SoundSource::resetSource(ALuint sourceID) 246 { 247 alSource3f(sourceID, AL_POSITION, 0.0, 0.0, 0.0); 248 alSource3f(sourceID, AL_VELOCITY, 0.0, 0.0, 0.0); 249 alSource3f(sourceID, AL_DIRECTION, 0.0, 0.0, 0.0); 250 alSourcef (sourceID, AL_ROLLOFF_FACTOR, 0.0 ); 251 alSourcei (sourceID, AL_SOURCE_RELATIVE, AL_TRUE ); 252 alSourcef (sourceID, AL_GAIN, SoundEngine::getInstance()->getEffectsVolume()); 253 }
Note: See TracChangeset
for help on using the changeset viewer.