#include "SoundExample.h" #include <OPENR/ODataFormats.h> #include <OPENR/OPENRAPI.h> #include <OPENR/OSyslog.h> #include <OPENR/core_macro.h> SoundExample::SoundExample() : State(SYSTEM_IDLE), Sound(STARWARS) { // init class variables SoundCounter = 0; Tog = 0; }; OStatus SoundExample::DoInit(const OSystemEvent& event) { OSYSDEBUG(("SoundExample::DoInit() \n")); NEW_ALL_SUBJECT_AND_OBSERVER; REGISTER_ALL_ENTRY; SET_ALL_READY_AND_NOTIFY_ENTRY; // load wave files // TRACKXX must be defined in DESIGNDB.CFG Sounds.LoadWAV("TRACK01"); Sounds.LoadWAV("TRACK02"); // open speaker primitive Sounds.OpenSpeaker(); // create sound vectors Sounds.NewSoundVectorData(); // set mute on Sounds.SetMute(true); // turn on motor power // done in LedsExample // MotorPowerOn(); // set mute off Sounds.SetMute(false); //set volume Sounds.SetVolume(ospkvol10dB); // determine wave type Sounds.SetWaveType(); return oSUCCESS; }; OStatus SoundExample::DoStart(const OSystemEvent& event) { OSYSDEBUG(("SoundExample::DoStart()\n")); // load waves to regions!!!!!!!!!!!!!!!!!!!!!!!!!!! // you have to do this vor every region!!! for (int i = 0; i < Sounds.GetValidRegions(); i++){ if(Sounds.CopyWAVToRegion(i,i) == WAV_SUCCESS) subject[sbjSOUNDTEST]->SetData(Sounds.GetRegion(i)); } // notify sound play back subject[sbjSOUNDTEST]->NotifyObservers(); // start system State = SYSTEM_START; ENABLE_ALL_SUBJECT; ASSERT_READY_TO_ALL_OBSERVER; return oSUCCESS; }; OStatus SoundExample::DoStop(const OSystemEvent& event) { OSYSDEBUG(("SoundExample::DoStop()\n")); DISABLE_ALL_SUBJECT; DEASSERT_READY_TO_ALL_OBSERVER; return oSUCCESS; }; OStatus SoundExample::DoDestroy(const OSystemEvent& event) { OSYSDEBUG(("SoundExample::DoDestroy()\n")); //Sounds.DeleteWaves(); DELETE_ALL_SUBJECT_AND_OBSERVER; return oSUCCESS; }; void SoundExample::NotifySpeaker(const OReadyEvent& event) { OSYSDEBUG(("SoundExample::NotifySpeaker()\n")); if(State == SYSTEM_START){ OSYSDEBUG(("---NotifySpeaker:Play\n")); // locate free memory region int tmp = Sounds.FindFreeRegionIndex(); // switch to the sound which should be played switch(Sound){ case STARWARS : // copy wav to memory region if(Sounds.CopyWAVToRegion(tmp,0) == WAV_SUCCESS){ // set region subject[sbjSOUNDTEST]->SetData(Sounds.GetRegion(tmp)); // notify OVirtualRobotAudioComm.Speaker.OSoundVectorData.O subject[sbjSOUNDTEST]->NotifyObservers(); } else { OSYSDEBUG(("---NotifySpeaker(): Starwars WaveCopyError\n")); } break; case HELLO: // same as STARWARS if(Sounds.CopyWAVToRegion(tmp,1) == WAV_SUCCESS){ subject[sbjSOUNDTEST]->SetData(Sounds.GetRegion(tmp)); subject[sbjSOUNDTEST]->NotifyObservers(); } else { OSYSDEBUG(("---NotifySpeaker(): hello WaveCopyError\n")); } break; case SOUNDS_IDLE : OSYSDEBUG(("---NotifySpeaker:Nothing to play\n")); break; default: OSYSDEBUG(("---NotifySpeaker:Nothing to play\n")); } // increase counter SoundCounter++; // if counter > 1500 switch played sound if(SoundCounter > 1500){ SoundCounter = 0; Sound = (Tog == 0) ? HELLO : STARWARS; Tog = (Tog == 0) ? 1 : 0; // rewind waves // that they start at the beginning Sounds.RewindWAV(0); Sounds.RewindWAV(1); } } else{ OSYSDEBUG(("---NotifySpeaker:Nix\n")); } };
![]() |
Generated Thu Jan 19 11:54:29 2006 by
![]() |