Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

MicrophoneServer.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_MicrophoneServer_h_
00003 #define INCLUDED_MicrophoneServer_h_
00004 
00005 #include "Events/EventBase.h"
00006 #include "Behaviors/BehaviorBase.h"
00007 
00008 //! Streams audio from the microphone over the network
00009 class MicrophoneServer : public BehaviorBase {
00010   public:
00011     //!enforces singleton status
00012     static MicrophoneServer& getInstance();
00013     virtual ~MicrophoneServer(); //!< destructor
00014     
00015     virtual void doStart();
00016     virtual void doStop();
00017     virtual void doEvent();
00018     
00019     //! makes Aperios-specific call to set microphone mode
00020     static bool SetMicrophoneUnidirectional(bool unidirectional);
00021     //! makes Aperios-specific call to set microphone mode
00022     static bool SetMicrophoneAlcEnabled(bool enabled);
00023     
00024   private:
00025     //! max transmission buffer size for #socket
00026     static const unsigned int SEND_BUFFER_SIZE = 2048 + 16;
00027   
00028     MicrophoneServer(); //!< constructor
00029     MicrophoneServer(const MicrophoneServer& rhs); //!< don't call
00030     MicrophoneServer& operator=(const MicrophoneServer& rhs); //!< don't call
00031     static MicrophoneServer* instance; //!< global instance of the server
00032     
00033     //! returns size of a "frame" at the given sampling rate and resolution
00034     unsigned int GetResampledFrameSize(
00035       unsigned int samplesSize,
00036       unsigned int newSampleRate,
00037       unsigned int newSampleBits,
00038       bool newStereo);
00039     
00040     //! performs sampling to a specified rate and resolution, stores into @a newSamples (which you must allocate)
00041     unsigned int ResampleFrame(
00042       const char* samples,
00043       unsigned int samplesSize,
00044       unsigned int& newSampleRate,
00045       unsigned int& newSampleBits,
00046       bool& newStereo,
00047       void* newSamples,
00048       unsigned int newSamplesSize);
00049     
00050     //! aperios specific identifier for microphone access
00051     static const char* const MIC_LOCATOR;
00052     
00053     //! socket for communication
00054     class Socket *socket;
00055     
00056     //! writes @a value to @a dst and advances @a dst
00057     template<class T>
00058     inline static void encode(char **dst, const T& value) {
00059       memcpy(*dst, &value, sizeof(T));
00060       (*dst) += sizeof(T);
00061     }
00062     
00063     //! writes @a length bytes from @a src to @a dst
00064     template<class T>
00065     inline static void encode(char **dst, const T * src, int num) {
00066       memcpy(*dst, src, num*sizeof(T));
00067       (*dst) += num*sizeof(T);
00068     }
00069 };
00070 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:45 2016 by Doxygen 1.6.3