Changeset 7306 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Apr 16, 2006, 10:12:11 PM (19 years ago)
- Location:
- trunk/src/lib/sound
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/sound/ogg_player.cc
r7305 r7306 49 49 } 50 50 51 /** 52 * @brief deletes the OggPlayer 53 */ 51 54 OggPlayer::~OggPlayer() 52 55 { … … 127 130 SoundEngine::checkError("OggPlayer::open()::SetSourceProperties", __LINE__); 128 131 132 // Set to State Stopped 133 this->state |= OggPlayer::Stopped; 129 134 return true; 130 135 } … … 139 144 if (!(this->state & FileOpened)) 140 145 return false; 146 147 this->state &= ~(OggPlayer::Stopped | OggPlayer::Paused); 141 148 if (this->musicThread == NULL) 142 149 return ((this->musicThread = SDL_CreateThread(OggPlayer::createAudioThread, (void*)this)) != NULL); … … 146 153 147 154 void OggPlayer::stop() 148 {} 155 { 156 this->state &= ~(OggPlayer::Playing | OggPlayer::Paused); 157 this->state |= OggPlayer::Stopped; 158 159 this->suspend(); 160 this->rewind(); 161 } 149 162 150 163 void OggPlayer::pause() 151 {} 152 164 { 165 this->state &= ~OggPlayer::Playing; 166 167 if (!(this->state & OggPlayer::Stopped)) 168 this->state |= OggPlayer::Paused; 169 170 this->suspend(); 171 } 172 173 /** 174 * @brief rewind to the beginning, and play (if already playing) 175 */ 153 176 void OggPlayer::rewind() 154 {} 177 { 178 this->jumpTo(0.0f); 179 } 155 180 156 181 /** … … 160 185 void OggPlayer::jumpTo(float timeCode) 161 186 { 162 if (this->state & FileOpened)187 if (this->state & OggPlayer::FileOpened) 163 188 ov_time_seek(&this->oggStream, timeCode); 164 189 } 190 191 /** 192 * @returns the Length of the Music in Seconds 193 */ 194 float OggPlayer::length() 195 { 196 if (this->state & OggPlayer::FileOpened) 197 return ov_time_total(&this->oggStream, -1); 198 else 199 return 0.0f; 200 } 201 165 202 166 203 /** … … 183 220 // INTERNAL FUNCTIONS // 184 221 //////////////////////// 222 /** 223 * @brief creates a Thread for Playing back the music even if the rest of the Engine is slow 224 * @param oggPlayer the OggPlayer to play back 225 * @returns -1 on error. 226 */ 185 227 int OggPlayer::createAudioThread(void* oggPlayer) 186 228 { … … 190 232 PRINTF(4)("STARTIG AUDIO THREAD\n"); 191 233 192 ogg->playback(); 193 194 while (ogg->state & Playing) 234 if (!ogg->playback()) 235 return -1; 236 237 while (ogg->state & OggPlayer::Playing) 195 238 { 196 239 ogg->update(); … … 200 243 } 201 244 245 202 246 /** 203 247 * @brief plays back the sound … … 206 250 bool OggPlayer::playback() 207 251 { 208 if (!(this->state & FileOpened))209 return false; 210 211 if(this-> isPlaying())252 if (!(this->state & OggPlayer::FileOpened)) 253 return false; 254 255 if(this->state & OggPlayer::Playing) 212 256 return true; 213 this->state |= Playing;257 this->state |= OggPlayer::Playing; 214 258 215 259 if(!this->stream(this->buffers[0]) || !this->stream(this->buffers[1])) … … 233 277 234 278 /** 235 * updates the stream, this has to be done every few parts of a second, for sound-consistency 279 * @brief waits for the AudioThread to be finished. 280 */ 281 void OggPlayer::suspend() 282 { 283 if (this->musicThread != NULL) 284 { 285 assert (!(this->state & Playing)); 286 SDL_WaitThread(this->musicThread, NULL); 287 this->musicThread = NULL; 288 } 289 if (this->state & OggPlayer::SourceAllocated) 290 { 291 alSourceStop(this->source); 292 alSourcei(this->source, AL_BUFFER, 0); 293 } 294 } 295 296 /** 297 * @brief updates the stream, this has to be done every few parts of a second, for sound-consistency 236 298 * @returns true, if the Sound is playing flawlessly 237 299 */ … … 267 329 268 330 /** 269 * gets a new Stream from buffer331 * @brief gets a new Stream from buffer 270 332 * @param buffer the buffer to get the stream from 271 333 * @return true, if everything worked as planed … … 311 373 { 312 374 assert(alIsSource(this->source)); 313 if (this->state & Playing);375 if (this->state & OggPlayer::Playing); 314 376 { 315 alSourceStop(source); 377 this->state &= ~OggPlayer::Playing; 378 // Kill the Music Thread. 379 if (this->musicThread != NULL) 380 this->suspend(); 381 316 382 SoundEngine::checkError("OggPlayer::release()::alSourceStop", __LINE__); 317 this->state & !Playing;318 383 } 319 384 empty(); … … 321 386 SoundEngine::getInstance()->pushALSource(this->source); 322 387 this->source = 0; 323 this->state &= !SourceAllocated;388 this->state &= ~SourceAllocated; 324 389 } 325 390 if (this->state & BuffersAllocated) … … 330 395 this->buffers[0] = 0; 331 396 this->buffers[1] = 0; 332 this->state &= !BuffersAllocated;397 this->state &= ~BuffersAllocated; 333 398 } 334 399 … … 336 401 { 337 402 ov_clear(&oggStream); 338 this->state &= ! FileOpened; 339 } 340 341 // Kill the Music Thread. 342 if (this->musicThread != NULL) 343 { 344 assert (!(this->state & Playing)); 345 SDL_WaitThread(this->musicThread, NULL); 346 this->musicThread = NULL; 347 } 403 this->state &= ~FileOpened; 404 } 405 348 406 } 349 407 -
trunk/src/lib/sound/ogg_player.h
r7305 r7306 20 20 21 21 22 #define OGG_PLAYER_BUFFER_SIZE (8096 * 2)22 #define OGG_PLAYER_BUFFER_SIZE (8096 * 4) 23 23 24 24 … … 33 33 */ 34 34 typedef enum { 35 None = 0x000, 36 FileOpened = 0x100, 37 SourceAllocated = 0x200, 38 BuffersAllocated = 0x400, 39 Stopped = 0x010, 40 Playing = 0x020, 41 Paused = 0x040, 42 Error = 0x001, 35 None = 0x000, //!< Initialized 36 FileOpened = 0x100, //!< File is Opened 37 SourceAllocated = 0x200, //!< Source is Allocated. 38 BuffersAllocated = 0x400, //!< 2 Buffers are Allocated. 39 Stopped = 0x010, //!< OggPlayer is stopped. 40 Playing = 0x020, //!< OggPlayer is Playing. 41 Paused = 0x040, //!< OggPlayer is Paused. 42 Error = 0x001, //!< An Error has occured. 43 43 } State; 44 44 … … 56 56 void jumpTo(float timeCode); 57 57 58 float length(); 58 59 bool isPlaying(); 59 60 bool getState() { return this->state; }; … … 67 68 static int createAudioThread(void* oggPlayer); 68 69 bool playback(); 70 void suspend(); 69 71 bool update(); 70 72
Note: See TracChangeset
for help on using the changeset viewer.