Skip to content

Latest commit

 

History

History
78 lines (61 loc) · 3.69 KB

nn-spatialaudioclient-ispatialaudioclient2.md

File metadata and controls

78 lines (61 loc) · 3.69 KB
UID tech.root title ms.date targetos description prerelease req.assembly req.construct-type req.ddi-compliance req.header req.idl req.include-header req.max-support req.namespace req.redist req.target-min-winverclnt req.target-min-winversvr req.target-type req.unicode-ansi topic_type api_type api_location api_name f1_keywords dev_langs
NN:spatialaudioclient.ISpatialAudioClient2
CoreAudio
ISpatialAudioClient2
01/31/2022
Windows
The **ISpatialAudioClient2** interface inherits from ISpatialAudioClient and adds methods to query for support for offloading large audio buffers.
false
iface
spatialaudioclient.h
Windows Build 22000
apiref
COM
spatialaudioclient.h
ISpatialAudioClient2
ISpatialAudioClient2
spatialaudioclient/ISpatialAudioClient2
c++

-description

The ISpatialAudioClient2 interface inherits from ISpatialAudioClient and adds methods to query for support for offloading large audio buffers.

-remarks

Audio offloading allows an app to submit a large audio buffer (typically 1 to 2 seconds) to the audio device driver. Without offload, a typical audio buffer only contains 10ms of data, requiring the app to be awakened around 100 times per second to provide additional audio data. Using offloaded large buffers can provide battery savings, particularly for the scenario where the user is listening to audio with the screen off.

To use this feature, the driver for the audio device must support offloading. Query for support by calling IsOffloadCapable. Determine the maximum number of audio frames supported for offloading by calling GetMaxFrameCountForCategory.

ISpatialAudioClient2 was introduced in Windows 11 (Windows Build 22000), so your code should handle the case where it is running on an older version of Windows that doesn't include the interface. The following example illustrates using calling QueryInterface on ISpatialAudioClient to try to obtain an instance of ISpatialAudioClient2 and checking that the retrieved interface is not null before calling its methods.

HRESULT hr;
Microsoft::WRL::ComPtr<IMMDeviceEnumerator> deviceEnum;
Microsoft::WRL::ComPtr<IMMDevice> defaultDevice;

hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&deviceEnum);
hr = deviceEnum->GetDefaultAudioEndpoint(EDataFlow::eRender, eMultimedia, &defaultDevice);

Microsoft::WRL::ComPtr<ISpatialAudioClient> spatialAudioClient;
hr = defaultDevice->Activate(__uuidof(ISpatialAudioClient), CLSCTX_INPROC_SERVER, nullptr, (void**)&spatialAudioClient);

Microsoft::WRL::ComPtr<ISpatialAudioClient2> spatialAudioClient2;
hr = spatialAudioClient->QueryInterface(__uuidof(ISpatialAudioClient2), (void**)&spatialAudioClient2);

if (spatialAudioClient2 != nullptr)
{
    BOOL offloadCapable = false;

    // AudioCategory_Media is just for example purposes.
    // Specify the same audio category that you intend specify in the call toISpatialAudioClient::ActivateSpatialAudioStream
    hr = spatialAudioClient2->IsOffloadCapable(AudioCategory_Media, &offloadCapable);
}

For UWP apps that do not have access to IMMDevice, you should get an instance of ISpatialAudioClient by calling ActivateAudioInterfaceAsync. For an example, see the WindowsAudioSession sample.

-see-also