#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)
{
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;
Sounds.LoadWAV("TRACK01");
Sounds.LoadWAV("TRACK02");
Sounds.OpenSpeaker();
Sounds.NewSoundVectorData();
Sounds.SetMute(true);
Sounds.SetMute(false);
Sounds.SetVolume(ospkvol10dB);
Sounds.SetWaveType();
return oSUCCESS;
};
OStatus SoundExample::DoStart(const OSystemEvent& event)
{
OSYSDEBUG(("SoundExample::DoStart()\n"));
for (int i = 0; i < Sounds.GetValidRegions(); i++){
if(Sounds.CopyWAVToRegion(i,i) == WAV_SUCCESS)
subject[sbjSOUNDTEST]->SetData(Sounds.GetRegion(i));
}
subject[sbjSOUNDTEST]->NotifyObservers();
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"));
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"));
int tmp = Sounds.FindFreeRegionIndex();
switch(Sound){
case STARWARS :
if(Sounds.CopyWAVToRegion(tmp,0) == WAV_SUCCESS){
subject[sbjSOUNDTEST]->SetData(Sounds.GetRegion(tmp));
subject[sbjSOUNDTEST]->NotifyObservers();
}
else {
OSYSDEBUG(("---NotifySpeaker(): Starwars WaveCopyError\n"));
}
break;
case HELLO:
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"));
}
SoundCounter++;
if(SoundCounter > 1500){
SoundCounter = 0;
Sound = (Tog == 0) ? HELLO : STARWARS;
Tog = (Tog == 0) ? 1 : 0;
Sounds.RewindWAV(0);
Sounds.RewindWAV(1);
}
}
else{
OSYSDEBUG(("---NotifySpeaker:Nix\n"));
}
};