Game Development Reference
In-Depth Information
IAudioBuffer Interface and AudioBuffer Class
Now that you
s time to play it. IAudioBuffer exposes
methods such as volume control, pausing, and monitoring individual sounds while
they are in memory. IAudioBuffer , and a partial implementation AudioBuffer ,
are meant to be platform agnostic. You ' ll see the DirectSound specific implementa-
tion shortly. Here
'
ve got a sound in memory, it
'
'
s the interface class:
class IAudioBuffer
{
public:
virtual ~IAudioBuffer() { }
virtual void *VGet()=0;
virtual shared_ptr<ResHandle> const VGetResource()=0;
virtual bool VRestore()=0;
virtual bool VPlay(int volume, bool looping)=0;
virtual bool VPause()=0;
virtual bool VStop()=0;
virtual bool VResume()=0;
virtual bool VTogglePause()=0;
virtual bool VIsPlaying()=0;
virtual bool VIsLooping() const=0;
virtual void VSetVolume(int volume)=0;
virtual int VGetVolume() const=0;
virtual float VGetProgress() const=0;
};
The first method is a virtual destructor, which will be overloaded by classes that
implement the interface. If this destructor weren
t virtual, it would be impossible to
release audio resources grabbed for this sound effect.
The next method, VGet() , is used to grab an implementation-specific handle to the
allocated sound. When I say implementation-specific, I
'
m talking about the piece of
data used by the audio system implementation to track sounds internally. In the case
of a DirectSound implementation, this would be a LPDIRECTSOUNDBUFFER . This is
for internal use only, for whatever class implements the IAudio interface to call.
Your high-level game code will never call this method unless it knows what the
implementation is and wants to do something really specific.
The next method, VRestore() , is primarily for Windows games since it is possible
for them to lose control of their sound buffers, requiring their restoration. The audio
system will double-check to see if an audio buffer has been lost before it sends
'
 
Search WWH ::




Custom Search