Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SpeakerServer.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_SpeakerServer_h_
00003 #define INCLUDED_SpeakerServer_h_
00004 
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "Sound/SoundManager.h"
00007 
00008 //! Plays streamed audio via the speaker
00009 class SpeakerServer : public BehaviorBase {
00010   public:
00011     static SpeakerServer& getInstance(); //!< returns global #instance
00012     virtual ~SpeakerServer(); //!< destructor
00013     
00014     virtual void doStart();
00015     virtual void doStop();
00016     
00017     //! registered by doStart() to be called by networking module with incoming data
00018     static int socket_callback(char *buf, int size);
00019   
00020   private:
00021     SpeakerServer(); //!< constructor
00022     SpeakerServer(const SpeakerServer& rhs); //!< don't call
00023     SpeakerServer& operator=(const SpeakerServer& rhs); //!< don't call
00024     static SpeakerServer* instance; //!< global instance of the server (only ever want to have one of these)
00025     
00026     int GotSocketData(char* data, int dataSize); //!< should be called with new sound data from the network
00027     class Socket *socket; //!< network communications socket for receiving sound data
00028     //! returns the next sizeof(short) bytes from @a buf as a short
00029     static short GetShort(const void* buf) { short result; memcpy(&result, buf, sizeof(short)); return result; }
00030     
00031     static const int MAX_PACKET_SIZE = 1024 * 1024; //!< maximum size of sound buffer to send to system
00032     static const int RECEIVE_BUFFER_SIZE = 2048; //!< maximum network packet size to accept
00033   
00034     //! stores information about current sound buffer
00035     class Packet {
00036       public:
00037         Packet(); //!< constructor
00038         virtual ~Packet(); //!< destructor
00039         
00040         class Buffer* header; 
00041         int size;
00042         int type;
00043         bool skipped;
00044         
00045         class Buffer* pcmHeader;
00046         unsigned short sampleRate;
00047         byte sampleBits;
00048         
00049         class Buffer* samples;
00050       
00051       private:
00052         Packet(const Packet& rhs); //!< don't call
00053         Packet& operator=(const Packet& rhs); //!< don't call
00054     };
00055     
00056     Packet packet; 
00057     class Buffer* frame;
00058     class Buffer* resampled;
00059     
00060     void AddPacket(
00061       const void* samples,
00062       int samplesSize,
00063       int sampleRate,
00064       byte sampleBits);
00065     
00066     const void* ResampleForSpeaker(
00067       const void* samples,
00068       int samplesSize,
00069       int sampleRate,
00070       byte bitsPerSample,
00071       int& newSamplesSize);
00072         
00073     void QueueFrame(const char* samples, int samplesSize);
00074     SoundManager::Play_ID channel;
00075 };
00076 #endif

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