00001
00002 #ifndef INCLUDED_SpeakerServer_h_
00003 #define INCLUDED_SpeakerServer_h_
00004
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "SoundPlay/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 static int socket_callback(char *buf, int size);
00018
00019 private:
00020 SpeakerServer();
00021 SpeakerServer(const SpeakerServer& rhs);
00022 SpeakerServer& operator=(const SpeakerServer& rhs);
00023 static SpeakerServer* instance;
00024
00025 int GotSocketData(char* data, int dataSize);
00026 class Socket *socket;
00027 static short GetShort(const void* buf) { short result; memcpy(&result, buf, sizeof(short)); return result; }
00028
00029 static const int MAX_PACKET_SIZE = 1024 * 1024;
00030 static const int RECEIVE_BUFFER_SIZE = 2048;
00031
00032 class Packet {
00033 public:
00034 Packet();
00035 virtual ~Packet();
00036
00037 class Buffer* header;
00038 int size;
00039 int type;
00040 bool skipped;
00041
00042 class Buffer* pcmHeader;
00043 unsigned short sampleRate;
00044 byte sampleBits;
00045
00046 class Buffer* samples;
00047
00048 private:
00049 Packet(const Packet& rhs);
00050 Packet& operator=(const Packet& rhs);
00051 };
00052
00053 Packet packet;
00054 class Buffer* frame;
00055 class Buffer* resampled;
00056
00057 void AddPacket(
00058 const void* samples, int samplesSize, int sampleRate, byte sampleBits);
00059 const void* ResampleForSpeaker(
00060 const void* samples,
00061 int samplesSize,
00062 int sampleRate,
00063 byte bitsPerSample,
00064 int& newSamplesSize);
00065
00066 void QueueFrame(const char* samples, int samplesSize);
00067 SoundManager::Play_ID channel;
00068 };
00069 #endif