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.
To obtain a listener interface, you must first create a primary buffer object 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; }