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 SoundRec_h_DEFINED 00013 #define SoundRec_h_DEFINED 00014 00015 #include <OPENR/OObject.h> 00016 #include <OPENR/OSubject.h> 00017 #include <OPENR/OObserver.h> 00018 #include <OPENR/ODataFormats.h> 00019 #include "def.h" 00020 00021 enum SoundRecState { 00022 SRS_IDLE, 00023 SRS_START 00024 }; 00025 00026 static const char* const MIC_LOCATOR = "PRM:/r1/c1/c2/c3/m1-Mic:M1"; 00027 00028 class SoundRec : public OObject { 00029 public: 00030 SoundRec(); 00031 virtual ~SoundRec() {} 00032 00033 OSubject* subject[numOfSubject]; 00034 OObserver* observer[numOfObserver]; 00035 00036 virtual OStatus DoInit (const OSystemEvent& event); 00037 virtual OStatus DoStart (const OSystemEvent& event); 00038 virtual OStatus DoStop (const OSystemEvent& event); 00039 virtual OStatus DoDestroy(const OSystemEvent& event); 00040 00041 void Notify(const ONotifyEvent& event); 00042 00043 private: 00044 void ChooseMic(OPrimitiveRequest req); 00045 void NewSoundBuffer(); 00046 void DeleteSoundBuffer(); 00047 int CopyToSoundBuffer(OSoundVectorData* soundVecData); 00048 void SaveSoundBufferAsWAV(char* path); 00049 00050 // 00051 // 16KHz 16bits STEREO 00052 // 00053 // 16 * 2 * 2 = 64 bytes / 1 ms 00054 // 64 * 32 = 2048 bytes / 32 ms 00055 // 00056 // 2048 * 512 = 1048576 bytes 00057 // 32ms * 512 = 16384 ms 00058 // 00059 static const size_t SOUND_BUFFER_SIZE = 1048576; 00060 static const size_t WAVE_HEADER_SIZE = 4 + 8 + 16 + 8; 00061 static const size_t FMTSIZE_WITHOUT_EXTINFO = 16; 00062 00063 SoundRecState soundRecState; 00064 byte* soundBuf; 00065 byte* soundBufPtr; 00066 }; 00067 00068 #endif // SoundRec_h_DEFINED