Microsoft DirectX 9.0

Obtaining the 3-D Listener

Global sound parameters are set and retrieved by using the IDirectSound3DListener8 interface from the primary buffer. There is only one primary buffer in an application, and only one listener.

If your application is not using DirectMusic audiopaths, 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 QueryInterface method on the resulting buffer to obtain a pointer to an IDirectSound3DListener8 interface for that buffer.

The following example function retrieves an interface to the listener.

GetListener(LPDIRECTSOUND8 lpds, LPDIRECTSOUND3DLISTENER8* ppListener)
{
  DSBUFFERDESC             dsbd;
  LPDIRECTSOUNDBUFFER      lpdsbPrimary;  // Cannot be IDirectSoundBuffer8.
  LPDIRECTSOUND3DLISTENER8 lp3DListener = NULL;
  HRESULT hr;
 
  ZeroMemory(&dsbd, sizeof(DSBUFFERDESC));
  dsbd.dwSize = sizeof(DSBUFFERDESC);
  dsbd.dwFlags = DSBCAPS_CTRL3D | DSBCAPS_PRIMARYBUFFER;

  if (SUCCEEDED(hr = lpds->CreateSoundBuffer(&dsbd, &lpdsbPrimary, NULL)))
  {
    hr = lpdsbPrimary->QueryInterface(IID_IDirectSound3DListener8,
                                 (LPVOID *)ppListener);
    lpdsbPrimary->Release();
  }
  return hr;
} 

See Also