Platform SDK: DirectX

Step 2: Obtain the Listener

In addition to the global variables introduced in Step 1, Tutorial 2 uses the following global variables:

Dim m_ds3dBuffer(2) As DirectSound3DBuffer
Dim m_dsPrimaryBuffer As DirectSoundBuffer
Dim m_dsListener As DirectSound3DListener

After you create the DirectSound object, the next step in setting up a 3-D sound environment is to obtain the DirectSound3DListener object. This object is used to control global sound parameters including the position and orientation of the virtual listener in the environment.

The listener is obtained from the primary buffer, so you must create a suitable DirectSoundBuffer object. Two flags have to be set for this buffer so that it is created as a primary buffer with 3-D capabilities. The WAVEFORMATEX type retrieves the default wave format of the primary buffer; you don't have to initialize it.

Dim primDesc As DSBUFFERDESC 
Dim format As WAVEFORMATEX
 
primDesc.lFlags = DSBCAPS_CTRL3D Or DSBCAPS_PRIMARYBUFFER
Set m_dsPrimaryBuffer = m_ds.CreateSoundBuffer(primDesc, format)

Next call DirectSoundBuffer.GetDirectSound3DListener to obtain the listener from the primary buffer.

Set m_dsListener = m_dsPrimaryBuffer.GetDirectSound3DListener()

The DirectSound3DListener is not used in the Tutorial 2 sample. However, it can be used to change the position and orientation of the listener in relation to the sound buffers, to change global sound parameters such as the rolloff factor, and to commit deferred settings for all 3-D buffers.

Next: Step 3: Load a Wave File into a 3-D Buffer