Microsoft DirectX 8.1 (C++) |
Global sound parameters are set and retrieved by using the IDirectSound3DListener8 interface, which is an interface to the
If you are using the DirectMusic performance and audiopaths to play your 3-D sounds, you can obtain the listener from any audiopath by using IDirectMusicAudioPath8::GetObjectInPath or IDirectMusicSegmentState8::GetObjectInPath, setting the dwStage parameter to DMUS_PATH_PRIMARY_BUFFER. In the following example, g_p3DAudioPath is a pointer to an IDirectMusicAudioPath8 interface:
IDirectSound3DListener8* g_pDSListener;
HRESULT hr = g_p3DAudioPath->GetObjectInPath(
0, DMUS_PATH_PRIMARY_BUFFER, 0,
GUID_NULL, 0, IID_IDirectSound3DListener8,
(LPVOID*) &g_pDSListener));
If your application is creating and managing its own sound buffers, using only the DirectSound API, you must create a primary buffer object and then obtain the listener interface from that.
Create the primary buffer by using the IDirectSound8::CreateSoundBuffer method, specifying the DSBCAPS_CTRL3D and DSBCAPS_PRIMARYBUFFER flags in the dwFlags member of the DSBUFFERDESC structure. Call the IDirectSoundBuffer::QueryInterface method on the resulting buffer to obtain a pointer to an IDirectSound3DListener8 interface for that buffer.
In the following example, lpds is an IDirectSound8 interface pointer:
DSBUFFERDESC dsbd;
LPDIRECTSOUNDBUFFER lpdsbPrimary;
LPDIRECTSOUNDLISTENER8 lp3DListener;
ZeroMemory(&dsbd, sizeof(DSBUFFERDESC));
dsbd.dwSize = sizeof(DSBUFFERDESC);
dsbd.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER;
if SUCCEEDED(lpds->CreateSoundBuffer(&dsbd, &lpdsbPrimary, NULL))
{
// Get listener interface.
if FAILED(lpdsbPrimary->QueryInterface(
IID_IDirectSound3DListener8,
(LPVOID *)&lp3DListener))
{
lpdsbPrimary->Release();
}
}
Once the listener has been obtained, the IDirectSoundBuffer interface to the primary buffer is not needed and can be released.