DirectSound:
Enumeration
By: Jack Hoxley
Written: May 2000
Download:
DS_Enum.zip
(8kb)
Sound drivers can be very important
to enumerate. Good quality sound cards are only just becoming standard in computers,
and there are still plenty out there are just click and beep at you. Allowing
a person to choose which sound driver to use can have a big influence on your
program. For example, my faster computer has 7 different sound drivers, 6 of
which work with Directsound. I dont personally like choosing the first (default)
driver on the basis that it sounds worse (but runs faster), I choose to use
the fourth one - which produces excellent music and sound effects. This is a
perfect example of it being a good thing to allow users to choose their hardware.
Luckily, enumeration is very
simple; requiring under 10 lines of code. Here's what you need to check the
sound drivers and compile them into a list:
Dim DsEnum
As DirectSoundEnum 'This
is the object that gives us information on the hardware.
Sub GetDevices()
Static I As Integer
Set DsEnum = Dx.GetDSEnum
For I = 1 To DsEnum.GetCount
Combo1.AddItem DsEnum.GetDescription(I)
Next I
Combo1.ListIndex = 0
End Sub |
|
|
|
This code will output a list
of devices into a combo box called combo1; should you wish the data to go elsewhere
just modify this code. Dont worry if it only gives you one driver - there's
nothing wrong with the code, it just means that you only have 1 directsound
driver.
This next bit needs to replace
your current line:
'Previously
this line would of been
'Set Ds = Dx.DirectSoundCreate("")
'Now the lines specifies an exact device; rather than let directsound
decide
Set Ds = Dx.DirectSoundCreate(DsEnum.GetGuid(Combo1.ListIndex
+ 1)) |
|
|
|
That's it - Told you it was simple.
You can download a modified version
of the DirectSound: Basics tutorial that includes enumeration either from the
top of the page or from my downloads page.
|