THEMA DirectSoundControl 1.30

for Game Development

by Maarten van Gompel, THEMA Corporation, July/September 1998

What is the DirectSoundControl?

The THEMA DirectDrawControl 1.30 is an ActiveX control that uses DirectSound, a part of Microsoft's DirectX to play wave files. The special thing about DirectSound is that it works fast and you can play multiple wave files at the same time! The DirectSoundControl helps you with that.

How does the DirectSoundControl work?

The DirectSoundControl works very easy but you have to do it in the right order. When you want to use the DSControl you must execute the "InitDirectSound" method first. Then you can play wave files with the "PlayDirectSound" method and you can stop them again with the "StopDirectSound". When you are finished using DirectSound you must end the execution with the "EndDirectSound" method. In the mean time you can use SetVolume, SetPan and SetFrequency

We'll now give the argument lists of the methods:

Public Sub InitDirectSound(TargetHandle As Long)

Description: Initializes the DirectSoundControl

TargetHandle > TargetHandle is the handle (hWnd property) of the form which uses the DirectSoundControl. So if you want Form1 to use the DirectSoundControl then set TargetHandle to Form1.hWnd

 

Public Sub PlayDirectSound(WaveFile As String, Repeat As Boolean, Channel As Integer)

Description: Plays a Wave file (.wav) in the specified channel, each channel can play one wave file, up to 20 channels can play at the same time

WaveFile > filename of the wavefile that has to be played

Repeat > Determines whether the sound repeats itself.

Channel > Determines the channel where this sound will be played on, there are 20 channels available so that means that you can play 20 wavefile at the same time!

 

Public Sub StopDirectSound(Channel As Integer)

Description: Stops playing the Wave file in the specified channel

Channel > Determines the channel where this sound is played on, there are 20 channels available so that means that you can play 20 wavefile at the same time!

 

Public Sub EndDirectSound()

Description: Ends the DirectSoundControl, this has to be executed before you unload the form or the application, otherwise the system might crash or other programs/ActiveX control won't work properly.

 

Public Sub SetVolume(Channel As Integer, Volume As Long)

Description: Sets the volume of the playing wavefile in the specified channel

Channel > The channelnumber (0-20) where the volume has to be changed

Volume > The volume, a number between -4000 and 0, 0 (default) is the highest number the user allows.

 

Public Sub SetPan(Channel As Integer, Pan As Long)

Description: Sets the panning (speaker balance) of the playing wavefile in the specified channel

Channel > The channelnumber (0-20) where the panning has to be changed

Pan > The panning number (between -4000 and 4000), -4000 = left speaker, 4000 = right speaker

 

 

Public Sub SetFrequency(Channel As Integer, Frequency As Long)

Description: Sets the frequency of the wavefile in the specified channel

Channel > The channelnumber (0-20) where the panning has to be changed

Frequency > The Frequency number (between -4000 and 4000), -4000 = left speaker, 4000 = right speaker

 

Advanced methods:

Public Sub LoadWave(WaveFile As String, Repeat As Boolean, Channel As Integer)

Description: Loads a wave file into a channel but does not play it yet

WaveFile > filename of the wavefile that has to be played

Repeat > Determines whether the sound repeats itself.

Channel > Determines the channel where this sound will be played on, there are 20 channels available so that means that you can play 20 wavefile at the same time!

 

Public Sub PlayLoadedWave(Channel As Integer, Repeat As Boolean)

Description: Plays a wave file in a specific channel that has previously been loaded with LoadWave

Channel > Determines the channel where this sound will be played on, there are 20 channels available so that means that you can play 20 wavefile at the same time!

Repeat > Determines whether the sound repeats itself.

 

Public Sub StopLoadedWave(Channel As Integer)

Description: Stops a wave file in a specific channel but does not unload it!

Channel > Determines the channel where the sound you wanna stop is played in

 

Public Sub UnLoadWave(Channel As Integer)

Description: Unloads a wave file in a specific channel

Channel > Determines the channel where the sound you wanna remove from memory is played in

Example

If you downloaded this DirectSoundControl right you should also have a Visual Basic example included. It is recommended that you look at the example and see how it works.

If you have any questions or comments you can always mail me at: thema@easypost.com

Also do visit the THEMA Homepage at: http://www.geocities.com/SiliconValley/Haven/2118

And if you've made a game or application using the DirectSoundControl, please tell me, i'd like to see what other people do with the control.