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
00012 static MicrophoneServer* GetInstance();
00013 virtual ~MicrophoneServer();
00014
00015 virtual void DoStart();
00016 virtual void DoStop();
00017 virtual void processEvent(const EventBase& event);
00018
00019 static bool SetMicrophoneUnidirectional(bool unidirectional);
00020 static bool SetMicrophoneAlcEnabled(bool enabled);
00021
00022 private:
00023 static const unsigned int SEND_BUFFER_SIZE = 2048 + 16;
00024
00025 MicrophoneServer();
00026 MicrophoneServer(const MicrophoneServer& rhs);
00027 MicrophoneServer& operator=(const MicrophoneServer& rhs);
00028 static MicrophoneServer* instance;
00029
00030 unsigned int GetResampledFrameSize(
00031 unsigned int samplesSize,
00032 unsigned int newSampleRate,
00033 unsigned int newSampleBits,
00034 bool newStereo);
00035
00036 unsigned int ResampleFrame(
00037 const char* samples,
00038 unsigned int samplesSize,
00039 unsigned int& newSampleRate,
00040 unsigned int& newSampleBits,
00041 bool& newStereo,
00042 void* newSamples,
00043 unsigned int newSamplesSize);
00044
00045 static const char* const MIC_LOCATOR;
00046
00047 class Socket *socket;
00048
00049
00050 template<class T>
00051 inline static void encode(char **dst, const T& value) {
00052 memcpy(*dst, &value, sizeof(T));
00053 (*dst) += sizeof(T);
00054 }
00055
00056
00057 template<class T>
00058 inline static void encode(char **dst, const T * src, int num) {
00059 memcpy(*dst, src, num*sizeof(T));
00060 (*dst) += num*sizeof(T);
00061 }
00062 };
00063 #endif