00001 // 00002 // Copyright 2002,2004 Sony Corporation 00003 // 00004 // Permission to use, copy, modify, and redistribute this software for 00005 // non-commercial use is hereby granted. 00006 // 00007 // This software is provided "as is" without warranty of any kind, 00008 // either expressed or implied, including but not limited to the 00009 // implied warranties of fitness for a particular purpose. 00010 // 00011 00012 #ifndef SoundAgent_h_DEFINED 00013 #define SoundAgent_h_DEFINED 00014 00015 #include <OPENR/OObject.h> 00016 #include <OPENR/OSubject.h> 00017 #include <OPENR/OObserver.h> 00018 #include <OPENR/ODataArchive.h> 00019 #include <MoNetData.h> 00020 #include <ODA.h> 00021 #include "WAV.h" 00022 #include "def.h" 00023 00024 enum SoundAgentState { 00025 SAS_IDLE, 00026 SAS_START, 00027 SAS_PLAYING 00028 }; 00029 00030 static const char* const SPEAKER_LOCATOR = "PRM:/r1/c1/c2/c3/s1-Speaker:S1"; 00031 static const char* const SPEAKER_LOCATOR_ERS7 = "PRM:/s1-Speaker:S1"; 00032 00033 class SoundAgent : public OObject { 00034 public: 00035 SoundAgent(); 00036 virtual ~SoundAgent() {} 00037 00038 OSubject* subject[numOfSubject]; 00039 OObserver* observer[numOfObserver]; 00040 00041 virtual OStatus DoInit (const OSystemEvent& event); 00042 virtual OStatus DoStart (const OSystemEvent& event); 00043 virtual OStatus DoStop (const OSystemEvent& event); 00044 virtual OStatus DoDestroy(const OSystemEvent& event); 00045 00046 void NotifyCommand(const ONotifyEvent& event); 00047 void ReadyPlay(const OReadyEvent& event); 00048 00049 private: 00050 MoNetStatus Play(int index, OVRSyncKey syncKey, byte* data); 00051 void OpenSpeaker(); 00052 void NewSoundVectorData(); 00053 void LoadODA(); 00054 void SetPowerAndVolume(); 00055 WAVError CopyWAVTo(RCRegion* region); 00056 RCRegion* FindFreeRegion(); 00057 void ReplyAgentResult(MoNetAgentID agt, int idx, MoNetStatus st); 00058 00059 // 00060 // 8KHz 8bits MONO (8 * 1 * 1 * 32 = 256) 00061 // 16KHz 16bits MONO (16 * 2 * 1 * 32 = 1024) 00062 // 00063 static const size_t SOUND_UNIT_SIZE = 1024; 00064 static const size_t SOUND_NUM_BUFFER = 4; 00065 00066 SoundAgentState soundAgentState; 00067 OPrimitiveID speakerID; 00068 ODesignDataID soundDataID; 00069 ODA soundODA; 00070 int playingIndex; 00071 WAV playingWAV; 00072 RCRegion* region[SOUND_NUM_BUFFER]; 00073 }; 00074 00075 #endif // SoundAgent_h_DEFINED