SoundPlay.cc
Go to the documentation of this file.00001 #include "SoundPlay.h"
00002 #include "Simulator.h"
00003 #include "SharedGlobals.h"
00004 #include "Main.h"
00005 #include "IPC/MessageReceiver.h"
00006 #include "IPC/RegionRegistry.h"
00007 #include "Events/EventRouter.h"
00008 #include "SimConfig.h"
00009 #include "Shared/Config.h"
00010
00011 #if !defined(PLATFORM_APERIOS) && !defined(__APPLE__)
00012 # include "Sound/MaryClient.h"
00013 #endif
00014
00015 SoundPlayThread * SoundPlay::player = NULL;
00016
00017 SoundPlay::SoundPlay()
00018 : Process(getID(),getClassName()),
00019 requests(ipc_setup->registerRegion(getSoundPlayID(),sizeof(sim::SoundPlayQueue_t))),
00020 events(ipc_setup->registerRegion(Main::getEventsID(),sizeof(sim::EventQueue_t))),
00021 statusRequest(ipc_setup->registerRegion(Simulator::getStatusRequestID(),sizeof(sim::StatusRequest_t))),
00022 soundmanager(ipc_setup->registerRegion(getSoundManagerID(),sizeof(SoundManager))),
00023 soundProf(ipc_setup->registerRegion(getSoundProfilerID(),sizeof(soundProfiler_t))),
00024 etrans(NULL), sndrecv(NULL), statusrecv(NULL)
00025 {
00026 new (&(*requests)) sim::SoundPlayQueue_t;
00027 new (&(*soundmanager)) SoundManager;
00028 new (&(*soundProfiler)) soundProfiler_t;
00029 sndman=&(*soundmanager);
00030 ::soundProfiler=&(*soundProf);
00031
00032 #if !defined(PLATFORM_APERIOS) && !defined(__APPLE__)
00033
00034 launchMaryServer();
00035 #endif
00036 }
00037
00038 SoundPlay::~SoundPlay() {}
00039
00040 void SoundPlay::doStart() {
00041 Process::doStart();
00042
00043
00044 if(!sim::config.multiprocess) {
00045
00046 EventTranslator * forwardTrans = new IPCEventTranslator(*events);
00047 forwardTrans->setTrapEventValue(true);
00048 erouter->setForwardingAgent(getID(),forwardTrans);
00049 } else {
00050 etrans=new IPCEventTranslator(*events);
00051 MotionManager::setTranslator(etrans);
00052
00053
00054
00055 for(unsigned int i=0; i<EventBase::numEGIDs; i++)
00056 if(i!=EventBase::erouterEGID)
00057 erouter->addTrapper(etrans,static_cast<EventBase::EventGeneratorID_t>(i));
00058 }
00059
00060 for(unsigned int i=0; i< ::config->sound.preload.size(); i++)
00061 sndman->loadFile(::config->sound.preload[i]);
00062
00063 #ifdef __APPLE__
00064 if(!sim::config.multiprocess)
00065 player = new SoundPlayThread;
00066 else
00067 std::cerr << "WARNING: sound support disabled on OS X when running in Multiprocess mode" << std::endl;
00068 #else
00069 player = new SoundPlayThread;
00070 #endif
00071 if(player!=NULL)
00072 player->reset();
00073 sndrecv=new MessageReceiver(*requests,gotSnd);
00074 statusrecv=new MessageReceiver(*statusRequest,statusReport);
00075 }
00076
00077 void SoundPlay::doStop() {
00078 sndrecv->finish();
00079 statusrecv->finish();
00080
00081 delete sndrecv;
00082 sndrecv=NULL;
00083 delete statusrecv;
00084 statusrecv=NULL;
00085 delete player;
00086 player=NULL;
00087
00088 sndman->stopPlay();
00089
00090 for(unsigned int i=0; i< ::config->sound.preload.size(); i++)
00091 sndman->releaseFile(::config->sound.preload[i]);
00092
00093 if(!sim::config.multiprocess) {
00094 erouter->setForwardingAgent(getID(),NULL);
00095 MotionManager::setTranslator(NULL);
00096 } else {
00097 erouter->removeTrapper(etrans);
00098 delete etrans;
00099 etrans=NULL;
00100 MotionManager::setTranslator(NULL);
00101 }
00102
00103 Process::doStop();
00104 }
00105
00106 bool SoundPlay::gotSnd(RCRegion* msg) {
00107 sndman->ProcessMsg(msg);
00108 if(player!=NULL)
00109 player->reset();
00110 return true;
00111 }
00112
00113
00114
00115
00116
00117
00118