00001
00002 #ifndef INCLUDED_MicrophoneServer_h_
00003 #define INCLUDED_MicrophoneServer_h_
00004
00005 #include "Events/EventBase.h"
00006 #include "Behaviors/BehaviorBase.h"
00007
00008
00009 class MicrophoneServer : public BehaviorBase {
00010 public:
00011 static MicrophoneServer* GetInstance();
00012 virtual ~MicrophoneServer();
00013
00014 virtual void DoStart();
00015 virtual void DoStop();
00016 virtual void processEvent(const EventBase& event);
00017
00018 static bool SetMicrophoneUnidirectional(bool unidirectional);
00019 static bool SetMicrophoneAlcEnabled(bool enabled);
00020
00021 private:
00022 static const unsigned int SEND_BUFFER_SIZE = 2048 + 16;
00023
00024 MicrophoneServer();
00025 MicrophoneServer(const MicrophoneServer& rhs);
00026 MicrophoneServer& operator=(const MicrophoneServer& rhs);
00027 static MicrophoneServer* instance;
00028
00029 unsigned int GetResampledFrameSize(
00030 unsigned int samplesSize,
00031 unsigned int newSampleRate,
00032 unsigned int newSampleBits,
00033 bool newStereo);
00034
00035 unsigned int ResampleFrame(
00036 const char* samples,
00037 unsigned int samplesSize,
00038 unsigned int& newSampleRate,
00039 unsigned int& newSampleBits,
00040 bool& newStereo,
00041 void* newSamples,
00042 unsigned int newSamplesSize);
00043
00044 static const char* const MIC_LOCATOR;
00045
00046 class Socket *socket;
00047
00048
00049 template<class T>
00050 inline static void encode(char **dst, const T& value) {
00051 memcpy(*dst, &value, sizeof(T));
00052 (*dst) += sizeof(T);
00053 }
00054
00055
00056 template<class T>
00057 inline static void encode(char **dst, const T * src, int num) {
00058 memcpy(*dst, src, num*sizeof(T));
00059 (*dst) += num*sizeof(T);
00060 }
00061 };
00062 #endif