#include "MicExample.h"
#include <OPENR/ODataFormats.h>
#include <OPENR/OPENRAPI.h>
#include <OPENR/OSyslog.h>
#include <OPENR/core_macro.h>
MicExample::MicExample() : State(SYSTEM_IDLE)
{
OSYSDEBUG(("MicExample()\n"));
};
OStatus MicExample::DoInit(const OSystemEvent& event)
{
OSYSDEBUG(("MicExample::DoInit() \n"));
NEW_ALL_SUBJECT_AND_OBSERVER;
REGISTER_ALL_ENTRY;
SET_ALL_READY_AND_NOTIFY_ENTRY;
Mic.OpenMic();
Mic.NewSoundBuffer(15);
return oSUCCESS;
};
OStatus MicExample::DoStart(const OSystemEvent& event)
{
OSYSDEBUG(("MicExample::DoStart()\n"));
State = SYSTEM_START;
ENABLE_ALL_SUBJECT;
ASSERT_READY_TO_ALL_OBSERVER;
return oSUCCESS;
};
OStatus MicExample::DoStop(const OSystemEvent& event)
{
OSYSDEBUG(("MicExample::DoStop()\n"));
DISABLE_ALL_SUBJECT;
DEASSERT_READY_TO_ALL_OBSERVER;
return oSUCCESS;
};
OStatus MicExample::DoDestroy(const OSystemEvent& event)
{
OSYSDEBUG(("MicExample::DoDestroy()\n"));
Mic.DeleteSoundBuffer();
DELETE_ALL_SUBJECT_AND_OBSERVER;
return oSUCCESS;
};
void MicExample::NotifyMic(const ONotifyEvent& event)
{
OSYSDEBUG(("MicExample::NotifyMic()\n"));
static int counter = 0;
if(State == SYSTEM_START){
OSoundVectorData* soundVecData = (OSoundVectorData*)event.Data(0);
Mic.CopyToSoundBuffer(soundVecData);
counter++;
if (counter < Mic.GetNumberOfFrames()) {
observer[event.ObsIndex()]->AssertReady(event.SenderID());
}
else {
OSYSPRINT(("SAVE SOUNDREC.WAV. WAIT ... \n \n"));
Mic.SaveBuffer("/MS/OPEN-R/MW/DATA/P/SOUNDREC.WAV");
OSYSPRINT(("DONE\n"));
}
}
else{
OSYSDEBUG(("---NotifyMic:Nix\n"));
return;
}
};