The DirectSound Helper
The following sections document the routines, variables and constants available in our DirectSound helper module for Visual Basic. Use this module in conjunction with Patrice Scribes DirectX TLB's. This is a very basic sound module, providing only simple playback services. Routines facilitating multiple playbacks of one buffer may be added to this module. These routines must be used with DirectX 3.0 or higher. They were compiled and tested using DirectX 5.0
Interface Contents :
Inititalization Functions:
Wave File Functions:
Function Descriptions
dsInit : Initialize the DirectSoundinterface
Sub dsInit(Owner as Form)
Use this routine as a general initialization routine. It initializes the DirectSound interface, and stores it in the dSound variable. It sets SoundOn to TRUE, and sets a normal co-operative level.
dsUnload : Release the DirectSound interface
Sub dsUnload
Use this routine to release the DirectSound system. You must
physically release
any sound buffers you have created, as this routine only releases the dSound interface. Be sure that a sound buffer has been stopped before
you release it.
dsLoadWave : Loads a wave file into a DirectSoundBuffer
Sub dsLoadWave(FileName as String) as DirectSoundBuffer
This routine will load a wave file off a disk file, create a sound buffer for it, and load the wave data onto the buffer. This routine cannot load waves out of a resource.
FileName : The full path to the wave file
Returns Success : The DirectSoundBuffer containg the wave file
Returns Failure : Nothing
dsPlay : Plays a DirectSoundBuffer
Sub dsPlay(dsb as DirectSoundBuffer)
If SoundOn is true, then the sound buffer will be played. If the buffer is already playing, nothing will happen.
dsb : The sound buffer to be played
dsPlayLooped : Plays a DirectSoundBuffer
Sub dsPlayed(dsb as DirectSoundBuffer)
If SoundOn is true, then the sound buffer will be played looping forever. Whenever the end of the buffer is reached, the sound will be started again immediatly. If the buffer is already playing, nothing will happen.
dsb : The sound buffer to be played
dsStop : Stops a buffer playing
Sub dsStop(dsb as DirectSoundBuffer)
Stops a sound buffer from playing, regardless of its current state.
dsb : The sound buffer to be stopped
dsStopCurrent : Stops the last buffer played
Sub dsStopCurrent
Stops the last buffer played using dsPlay or dsPlayLooped. This will have no effect on buffers played directly using the DirectSoundBuffer.Play method.
dsGetVolume : Returns the sound buffers volume
Function dsGetVolume(dsb as DirectSoundBuffer) as Long
Returns the volume of the sound buffer. The volume is measured in hunderths of decibels.
dsb : The sound buffer whose volume you desire
dsIsPlaying : Determines if a buffer is playing
Function dsIsPlaying(dsb as DirectSoundBuffer) as Boolean
Returns TRUE is the sound buffer is currently playing.
dsb : The sound buffer in question
dsDuplicate : Returns a duplicate object for a buffer
Function dsDuplicate(dsb as DirectSoundBuffer) as DirectSoundBuffer
This routine returns a duplicate of the sound buffer. Only the object is duplicated, not the actual wave data. This is used to allow you to play a sound buffer multiple times at once. I.E, if you have an explosion sound, you may want to play it each time something explodes. For each explosion, you'll duplicate the explosion buffer, and set it playing. When you're done, release the duplicated buffer.
dsb : The sound buffer you want to duplicate
dsRewind : Reset the play position
Sub dsRewind(dsb as DirectSoundBuffer)
Resets the current position of a sound buffer to the beginning.
dsb : Sound buffer to reset
dsToggleSound : Turn sound on/off
Sub dsToggleSound
This routine will switch the value of dsSoundOn between TRUE and FALSE. If dsSoundOn becomes FALSE (i.e no sound) the dsStopCurrent is used to stop the last played buffer. Buffers played directly with DirectSoundBuffer.Play will not be stopped.
dsSoundOn : Determines if sounds are played or not
Public dsSoundOn as Boolean
This variable can be used to determine whether sound is on or off. Use dsToggleSound to switch between sound on and sound off. dsPlay and dsPlayLooped will only play a buffer if dsSoundOn is TRUE.
dSound : Main DirectSound interface
Public dSound as DirectSound
This variable can be used to access all the DirectSound interface methods as described in the DirectX SDK documentation.
Copyright © 1998 Digital Zone Software.
All rights reserved.
Author: Mark Hewitt