00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _SOUNDRESOURCEHANDLE_
00019 #define _SOUNDRESOURCEHANDLE_
00020
00021 #include "contrib/libmad/mad.h"
00022
00023 #include "resource/ResourceHandle.h"
00024
00028 struct WaveFormat
00029 {
00030 unsigned short nFormatTag;
00031 unsigned short nChannels;
00032 unsigned long nSamplesPerSec;
00033 unsigned long nAvgBytesPerSec;
00034 unsigned short nBlockAlign;
00035 unsigned short nBitsPerSample;
00036 unsigned short nSize;
00037 };
00038 class ResourceCache;
00039
00040 class SoundResourceHandle : public ResourceHandle
00041 {
00042 friend mad_flow header(void*, const mad_header*);
00043 friend mad_flow output(void*, mad_header const *, mad_pcm *);
00044 private:
00045 WaveFormat m_wavFormat;
00046 char* m_pAudioData;
00047 unsigned int m_nAudioDataSize;
00048 unsigned long m_nSoundLengthInMillis;
00049
00050 bool m_bInitialized;
00051
00052 bool ParseWAVDataFromBuffer();
00053 bool ParseOGGDataFromBuffer();
00054 bool ParseMP3DataFromBuffer();
00055 public:
00056 SoundResourceHandle(const void* pBuffer, const unsigned int nBufferSize, const Resource& resource, ResourceCache* const pResourceCache)
00057 :ResourceHandle(pBuffer, nBufferSize, resource, pResourceCache), m_bInitialized(false), m_pAudioData(0), m_nAudioDataSize(0), m_nSoundLengthInMillis(0)
00058 {
00059 memset(&m_wavFormat, 0, sizeof(WaveFormat));
00060 }
00061
00062 virtual ~SoundResourceHandle();
00063
00064 bool PrepareSoundResource();
00065
00066 const WaveFormat& GetWaveFormat() const { return m_wavFormat; }
00067 bool Initialized() const { return m_bInitialized; }
00068 unsigned int GetAudioDataSize() const { return m_nAudioDataSize; }
00069 unsigned long GetSoundLength() const { return m_nSoundLengthInMillis; }
00070 char* GetAudioData() const { return m_pAudioData; }
00071 };
00072
00073 typedef boost::shared_ptr<SoundResourceHandle> SoundResourceHandlePtr;
00074
00075 #endif