Platform SDK: DirectX

Obtaining the DirectSound3DBuffer Object

[C++]

To obtain a pointer to an IDirectSound3DBuffer interface, you must first create a secondary 3-D sound buffer. Do this by using the IDirectSound::CreateSoundBuffer method, specifying the DSBCAPS_CTRL3D flag in the dwFlags member of the DSBUFFERDESC structure. Then use the IDirectSoundBuffer::QueryInterface method on the resulting buffer to obtain a pointer to an IDirectSound3DBuffer interface for that buffer.

The following example calls the QueryInterface method with the C++ syntax:

// LPDIRECTSOUNDBUFFER lpDsbSecondary;
// The buffer has been created with DSBCAPS_CTRL3D. 
LPDIRECTSOUND3DBUFFER lpDs3dBuffer;
 
HRESULT hr = lpDsbSecondary->QueryInterface(IID_IDirectSound3DBuffer, 
                                            (LPVOID *)&lpDs3dBuffer); 
if SUCCEEDED(hr) 
{ 
    // Set 3-D parameters of this sound. 
    . 
    . 
    . 
} 
 
[Visual Basic]

To obtain a DirectSound3DBuffer object, you must first create a secondary 3-D sound buffer. Do this by using the DirectSound.CreateSoundBuffer method, specifying the DSBCAPS_CTRL3D flag in the lFlags member of the DSBUFFERDESC type. Then call the DirectSoundBuffer.GetDirectSound3DBuffer method on the resulting buffer.

The following example shows how to create a DirectSound3DBuffer object.

Dim dsbd As DSBUFFERDESC
Dim dsBuffer As DirectSoundBuffer
Dim waveFormat As WAVEFORMATEX
Dim ds3dBuffer As DirectSound3DBuffer
 
' Set up the wave format.
 
With waveFormat
    .nSize = LenB(waveFormat)
    .nFormatTag = WAVE_FORMAT_PCM
    .nChannels = 2
    .lSamplesPerSec = 22050
    .nBitsPerSample = 16
    .nBlockAlign = _
            waveFormat.nBitsPerSample / 8 * waveFormat.nChannels
    .lAvgBytesPerSec = _
            waveFormat.lSamplesPerSec * waveFormat.nBlockAlign
End With 
 
' Create the secondary buffer.
 
dsbd.lFlags = DSBCAPS_CTRL3D
Set dsBuffer = m_ds.CreateSoundBuffer(dsbd, waveFormat)
 
' Obtain the 3-D buffer object.
 
Set ds3dBuffer = dsBuffer.GetDirectSound3DBuffer