Microsoft DirectX 8.1 (C++)

Obtaining the 3-D Buffer Object

The IDirectSound3DBuffer8 interface is obtained from a secondary DirectSound buffer that has been created with the DSBCAPS_CTRL3D flag in the dwFlags member of the DSBUFFERDESC structure.

If your application is using the DirectMusic performance and audiopaths, you can create an audiopath containing a 3-D buffer by passing DMUS_APATH_DYNAMIC_3D as the dwType parameter to IDirectMusicPerformance8::CreateStandardAudioPath.

You can also create a suitable audiopath from a configuration object. An audiopath configuration can specify 3-D parameters for a buffer. When the audiopath is created, the 3-D properties of the buffer are initialized with these parameters.

To obtain an interface to a 3-D buffer in an audiopath, call IDirectMusicAudioPath8::GetObjectInPath or IDirectMusicSegmentState8::GetObjectInPath, with dwStage set to DMUS_PATH_BUFFER.

The following sample code creates a standard audiopath and retrieves an IDirectSound3DBuffer8 interface:

HRESULT      hr;
IDirectMusicAudioPath8*  g_p3DAudioPath;
IDirectSound3DBuffer8* g_pDS3DBuffer; 

if (FAILED(hr = pPerformance->CreateStandardAudioPath(
    DMUS_APATH_DYNAMIC_3D, 64, TRUE, &g_p3DAudioPath)))
  return hr;
 
if (FAILED(hr = g_p3DAudioPath->GetObjectInPath( 
    DMUS_PCHANNEL_ALL, DMUS_PATH_BUFFER, 0,
    GUID_NULL, 0, IID_IDirectSound3DBuffer8, 
    (LPVOID*) &g_pDS3DBuffer)))
  return hr;
 

If your application is creating and managing its own DirectSound secondary buffers without using the DirectMusic performance, you can retrieve the IDirectSound3DBuffer8 interface by calling the IDirectSoundBuffer8::QueryInterface method on the buffer, as in the following sample code:

// Assume that lpDsbSecondary is a valid IDirectSoundBuffer8
// that has been created with DSBCAPS_CTRL3D.
 
LPDIRECTSOUND3DBUFFER8 lpDs3dBuffer;
 
HRESULT hr = lpDsbSecondary->QueryInterface(IID_IDirectSound3DBuffer8, 
                (LPVOID *)&lpDs3dBuffer);