SpeakerServer.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_SpeakerServer_h_
00003 #define INCLUDED_SpeakerServer_h_
00004
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "Sound/SoundManager.h"
00007
00008
00009 class SpeakerServer : public BehaviorBase {
00010 public:
00011 static SpeakerServer& getInstance();
00012 virtual ~SpeakerServer();
00013
00014 virtual void doStart();
00015 virtual void doStop();
00016
00017
00018 static int socket_callback(char *buf, int size);
00019
00020 private:
00021 SpeakerServer();
00022 SpeakerServer(const SpeakerServer& rhs);
00023 SpeakerServer& operator=(const SpeakerServer& rhs);
00024 static SpeakerServer* instance;
00025
00026 int GotSocketData(char* data, int dataSize);
00027 class Socket *socket;
00028
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;
00032 static const int RECEIVE_BUFFER_SIZE = 2048;
00033
00034
00035 class Packet {
00036 public:
00037 Packet();
00038 virtual ~Packet();
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);
00053 Packet& operator=(const Packet& rhs);
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