Game Development Reference
In-Depth Information
The concept of streaming sound, compressed or otherwise, is beyond the scope of this
chapter. The sound system described here uses the resource cache to load the sound
data from a resource file, decompresses it if necessary, and manages DirectSound audio
buffers if you happen to have the same sound being played multiple times. As usual, I
m
exchanging clarity for performance, specifically memory usage, so take this into account
when looking at this system. A commercial grade sound system would only load the
compressed sound into memory and use a thread to decompress bits of it as it is played,
saving a ton of memory. With that caveat in mind, the first thing to do is define three
classes to help the resource cache load and decompress WAV and OGG files::
'
class SoundResourceExtraData : public IResourceExtraData
{
friend class WaveResourceLoader;
friend class OggResourceLoader;
public:
SoundResourceExtraData();
virtual ~SoundResourceExtraData() { }
virtual std::string VToString() { return
SoundResourceExtraData
;}
enum SoundType GetSoundType() { return m_SoundType; }
WAVEFORMATEX const *GetFormat() { return &m_WavFormatEx; }
int GetLengthMilli() const { return m_LengthMilli; }
protected:
enum SoundType m_SoundType;
// is this an Ogg, WAV, etc.?
bool m_bInitialized;
// has the sound been initialized
WAVEFORMATEX m_WavFormatEx;
// description of the PCM format
int m_LengthMilli;
// how long the sound is in milliseconds
};
class WaveResourceLoader : public IResourceLoader
{
public:
virtual bool VUseRawFile() { return false; }
virtual unsigned int VGetLoadedResourceSize(char *rawBuffer,
unsigned int rawSize);
virtual bool VLoadResource(char *rawBuffer, unsigned int rawSize,
shared_ptr<ResHandle> handle);
virtual std::string VGetPattern() { return
*.wav
;}
protected:
bool ParseWave(char *wavStream, size_t length,
shared_ptr<ResHandle> handle);
};
 
Search WWH ::




Custom Search