Changeset 7308 in orxonox.OLD for trunk/src/lib/sound
- Timestamp:
- Apr 16, 2006, 11:08:25 PM (19 years ago)
- Location:
- trunk/src/lib/sound
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/sound/ogg_player.cc
r7307 r7308 35 35 this->setClassID(CL_SOUND_OGG_PLAYER, "OggPlayer"); 36 36 37 this->state = None;37 this->state = OggPlayer::None; 38 38 39 39 this->source = 0; 40 40 this->buffers[0] = 0; 41 41 this->buffers[1] = 0; 42 this->musicThread = NULL; 42 this->musicThreadID = NULL; 43 this->musicMutex = SDL_CreateMutex(); 43 44 44 45 if (!fileName.empty()) … … 47 48 this->setName(fileName); 48 49 } 50 49 51 } 50 52 … … 55 57 { 56 58 this->release(); 59 SDL_DestroyMutex(this->musicMutex); 57 60 } 58 61 … … 67 70 { 68 71 // release old Ogg-File (if loaded) 69 if (this->state & FileOpened)72 if (this->state & OggPlayer::FileOpened) 70 73 this->release(); 71 74 … … 75 78 SoundEngine::checkError("Allocating Buffers", __LINE__); 76 79 if (this->buffers[0] != 0 && this->buffers[1] != 0) 77 state |= BuffersAllocated;80 state |= OggPlayer::BuffersAllocated; 78 81 else 79 82 { … … 86 89 SoundEngine::getInstance()->popALSource(this->source); 87 90 if (this->source != 0) 88 state |= SourceAllocated;91 state |= OggPlayer::SourceAllocated; 89 92 else 90 93 { … … 110 113 return false; 111 114 } 112 this->state |= FileOpened;115 this->state |= OggPlayer::FileOpened; 113 116 114 117 // acquiring the vorbis-properties. … … 142 145 bool OggPlayer::play() 143 146 { 144 if (!(this->state & FileOpened))147 if (!(this->state & OggPlayer::FileOpened)) 145 148 return false; 146 149 … … 150 153 return false; 151 154 152 if (this->musicThread == NULL)153 return ((this->musicThread = SDL_CreateThread(OggPlayer::createAudioThread, (void*)this)) != NULL);155 if (this->musicThreadID == NULL) 156 return ((this->musicThreadID = SDL_CreateThread(OggPlayer::musicThread, (void*)this)) != NULL); 154 157 return true; 155 158 } … … 189 192 void OggPlayer::jumpTo(float timeCode) 190 193 { 194 191 195 if (this->state & OggPlayer::FileOpened) 196 { 197 SDL_mutexP(this->musicMutex); 192 198 ov_time_seek(&this->oggStream, timeCode); 199 SDL_mutexV(this->musicMutex); 200 } 193 201 } 194 202 … … 210 218 bool OggPlayer::isPlaying() 211 219 { 212 if (!(this->state & FileOpened))220 if (!(this->state & OggPlayer::FileOpened)) 213 221 return false; 214 222 ALenum state; … … 229 237 * @returns -1 on error. 230 238 */ 231 int OggPlayer:: createAudioThread(void* oggPlayer)239 int OggPlayer::musicThread(void* oggPlayer) 232 240 { 233 241 if (oggPlayer == NULL) 234 242 return -1; 235 243 OggPlayer* ogg = (OggPlayer*)oggPlayer; 244 236 245 PRINTF(4)("STARTIG AUDIO THREAD\n"); 237 238 246 while (ogg->state & OggPlayer::Playing) 239 247 { 248 SDL_mutexP(ogg->musicMutex); 240 249 ogg->update(); 250 SDL_mutexV(ogg->musicMutex); 241 251 SDL_Delay(1); 242 252 } … … 264 274 if (DEBUG >= 3) 265 275 SoundEngine::checkError("OggPlayer::playback()::alSourceQueueBuffers", __LINE__); 266 if (!alIsBuffer(this->buffers[0])) printf("AHA0\n"); 267 if (!alIsBuffer(this->buffers[1])) printf("AHA1\n"); 268 269 if (!alIsSource(this->source)) printf("AHA2\n"); 270 SoundEngine::checkError("SKJFLKSDJF",__LINE__); 276 271 277 272 278 alSourcePlay(this->source); … … 282 288 void OggPlayer::suspend() 283 289 { 284 if (this->musicThread != NULL)290 if (this->musicThreadID != NULL) 285 291 { 286 292 assert (!(this->state & Playing)); 287 293 this->printState(); 288 SDL_WaitThread(this->musicThread , NULL);289 this->musicThread = NULL;294 SDL_WaitThread(this->musicThreadID, NULL); 295 this->musicThreadID = NULL; 290 296 } 291 297 if (this->state & OggPlayer::SourceAllocated) … … 302 308 bool OggPlayer::update() 303 309 { 304 if (unlikely(!(this->state & Playing))) 305 return false; 306 307 int processed; 310 int processed = 0; 308 311 bool active = true; 309 312 … … 372 375 void OggPlayer::release() 373 376 { 374 if (this->state & SourceAllocated)377 if (this->state & OggPlayer::SourceAllocated) 375 378 { 376 379 assert(alIsSource(this->source)); … … 379 382 this->state &= ~OggPlayer::Playing; 380 383 // Kill the Music Thread. 381 if (this->musicThread != NULL)384 if (this->musicThreadID != NULL) 382 385 this->suspend(); 383 386 … … 390 393 this->state &= ~SourceAllocated; 391 394 } 392 if (this->state & BuffersAllocated)395 if (this->state & OggPlayer::BuffersAllocated) 393 396 { 394 397 assert (this->buffers[0] != 0 && this->buffers[1] != 0); … … 397 400 this->buffers[0] = 0; 398 401 this->buffers[1] = 0; 399 this->state &= ~ BuffersAllocated;400 } 401 402 if (this->state & FileOpened)402 this->state &= ~OggPlayer::BuffersAllocated; 403 } 404 405 if (this->state & OggPlayer::FileOpened) 403 406 { 404 407 ov_clear(&oggStream); 405 this->state &= ~ FileOpened;408 this->state &= ~OggPlayer::FileOpened; 406 409 } 407 410 … … 457 460 { 458 461 PRINTF(0)("OggPlayer is in the following States: "); 459 if (this->state & FileOpened)462 if (this->state & OggPlayer::FileOpened) 460 463 PRINT(0)("FileOpened "); 461 if (this->state & SourceAllocated)464 if (this->state & OggPlayer::SourceAllocated) 462 465 PRINT(0)("SourceAllocated "); 463 if (this->state & BuffersAllocated)466 if (this->state & OggPlayer::BuffersAllocated) 464 467 PRINT(0)("BuffersAllocated "); 465 if (this->state & Stopped)468 if (this->state & OggPlayer::Stopped) 466 469 PRINT(0)("Stopped "); 467 if (this->state & Playing)470 if (this->state & OggPlayer::Playing) 468 471 PRINT(0)("Playing "); 469 if (this->state & Paused)472 if (this->state & OggPlayer::Paused) 470 473 PRINT(0)("Paused "); 471 if (this->state & Error)474 if (this->state & OggPlayer::Error) 472 475 PRINT(0)("Error "); 473 476 PRINT(0)("\n"); -
trunk/src/lib/sound/ogg_player.h
r7307 r7308 20 20 21 21 22 #define OGG_PLAYER_BUFFER_SIZE (8096 * 4)22 #define OGG_PLAYER_BUFFER_SIZE (8096 * 2) 23 23 24 24 … … 66 66 67 67 private: 68 static int createAudioThread(void* oggPlayer);68 static int musicThread(void* oggPlayer); 69 69 bool playback(); 70 70 void suspend(); … … 87 87 unsigned int state; //!< The States the OggPlayer is in (this can be multiple entries from OggPlayer::State). 88 88 89 SDL_Thread* musicThread; //!< The Thread in which music is Played back. 89 SDL_Thread* musicThreadID; //!< The Thread in which music is Played back. 90 SDL_mutex* musicMutex; //!< A Mutex so that the two threads do not interfere. 90 91 }; 91 92
Note: See TracChangeset
for help on using the changeset viewer.