Changeset 9849
- Timestamp:
- 03/03/09 18:37:48 (4 years ago)
- Location:
- OpenSceneGraph/trunk/examples/osgmovie
- Files:
-
- 2 modified
-
CMakeLists.txt (modified) (1 diff)
-
osgmovie.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgmovie/CMakeLists.txt
r9847 r9849 1 1 # INCLUDE_DIRECTORIES( ${OPENAL_INCLUDE_DIR} ) 2 # SET(TARGET_EXTERNAL_LIBRARIES ${OPENAL_LIBRARY} alut) 3 4 IF (SDL_FOUND) 5 SET(TARGET_EXTERNAL_LIBRARIES ${SDL_LIBRARY} ) 6 INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR} ) 7 ADD_DEFINITIONS(-DUSE_SDL) 8 ENDIF(SDL_FOUND) 2 9 3 10 SET(TARGET_SRC osgmovie.cpp ) 4 11 SET(TARGET_ADDED_LIBRARIES osgGA ) 5 12 6 # SET(TARGET_EXTERNAL_LIBRARIES ${OPENAL_LIBRARY} alut) 13 7 14 8 15 #### end var setup ### -
OpenSceneGraph/trunk/examples/osgmovie/osgmovie.cpp
r9847 r9849 321 321 } 322 322 323 class CustomAudioSink : public osg::AudioSink 323 #if USE_SDL 324 325 #include "SDL.h" 326 327 class SDLAudioSink : public osg::AudioSink 324 328 { 325 329 public: 326 330 327 CustomAudioSink(osg::AudioStream* audioStream):331 SDLAudioSink(osg::AudioStream* audioStream): 328 332 _playing(false), 329 333 _audioStream(audioStream) {} 330 334 335 ~SDLAudioSink() 336 { 337 if (_playing) 338 { 339 340 SDL_PauseAudio(1); 341 SDL_CloseAudio(); 342 343 osg::notify(osg::NOTICE)<<"~SDLAudioSink() destructor, but still playing"<<std::endl; 344 } 345 } 346 331 347 virtual void startPlaying() 332 348 { 333 349 _playing = true; 334 osg::notify(osg::NOTICE)<<" CustomAudioSink()::startPlaying()"<<std::endl;350 osg::notify(osg::NOTICE)<<"SDLAudioSink()::startPlaying()"<<std::endl; 335 351 336 352 osg::notify(osg::NOTICE)<<" audioFrequency()="<<_audioStream->audioFrequency()<<std::endl; … … 338 354 osg::notify(osg::NOTICE)<<" audioSampleFormat()="<<_audioStream->audioSampleFormat()<<std::endl; 339 355 356 SDL_AudioSpec specs = { 0 }; 357 SDL_AudioSpec wanted_specs = { 0 }; 358 359 wanted_specs.freq = _audioStream->audioFrequency(); 360 wanted_specs.format = AUDIO_S16SYS; 361 wanted_specs.channels = _audioStream->audioNbChannels(); 362 wanted_specs.silence = 0; 363 wanted_specs.samples = 1024; 364 wanted_specs.callback = soundReadCallback; 365 wanted_specs.userdata = this; 366 367 if (SDL_OpenAudio(&wanted_specs, &specs) < 0) 368 throw "SDL_OpenAudio() failed (" + std::string(SDL_GetError()) + ")"; 369 370 SDL_PauseAudio(0); 371 340 372 } 341 373 virtual bool playing() const { return _playing; } 374 375 static void soundReadCallback(void * user_data, uint8_t * data, int datalen); 342 376 343 377 bool _playing; 344 378 osg::observer_ptr<osg::AudioStream> _audioStream; 345 379 }; 380 381 382 void SDLAudioSink::soundReadCallback(void * const user_data, Uint8 * const data, const int datalen) 383 { 384 osg::notify(osg::NOTICE)<<"SDLAudioSink::soundReadCallback"<<std::endl; 385 386 SDLAudioSink * sink = reinterpret_cast<SDLAudioSink*>(user_data); 387 osg::ref_ptr<osg::AudioStream> as = sink->_audioStream.get(); 388 if (as.valid()) 389 { 390 as->consumeAudioBuffer(data, datalen); 391 } 392 } 393 394 #endif 346 395 347 396 int main(int argc, char** argv) … … 451 500 bool xyPlane = fullscreen; 452 501 453 bool use OpenALAudio= false;454 while(arguments.read("-- OpenAL")) { useOpenALAudio= true; }502 bool useAudioSink = false; 503 while(arguments.read("--audio")) { useAudioSink = true; } 455 504 456 505 for(int i=1;i<arguments.argc();++i) … … 463 512 { 464 513 osg::ImageStream::AudioStreams& audioStreams = imagestream->getAudioStreams(); 465 if (use OpenALAudio&& !audioStreams.empty())514 if (useAudioSink && !audioStreams.empty()) 466 515 { 467 516 osg::AudioStream* audioStream = audioStreams[0].get(); 468 517 osg::notify(osg::NOTICE)<<"AudioStream read ["<<audioStream->getName()<<"]"<<std::endl; 469 audioStream->setAudioSink(new CustomAudioSink(audioStream)); 518 #if USE_SDL 519 audioStream->setAudioSink(new SDLAudioSink(audioStream)); 520 #endif 470 521 } 471 522
