CRI ADX  Last Updated: 2024-07-17 10:47 p
Selection of the audio output device

Samples Directory

/CRIWARE/SDK/pc/samples/criatomex/select_device

Sample Description

This sample shows how to select the audio device used in the application.
The Atom library outputs the audio through the sound renderer set in CriAtomExAsrConfig::sound_renderer_type before the initialization.
(By default, the audio is output though CRIATOM_SOUND_RENDERER_NATIVE.)
CRIATOM_SOUND_RENDERER_NATIVE is assigned to the Windows default playback device.
Therefore, if the library is initialized with the default settings, all the sounds played in the application will be output through the default device.
(If the user modifies the Windows settings and changes the default sound device, the sound will then be output from the new device.)
It is also possible to explicitly specify the output device from the application side, ignoring the Windows default device.
Specifically, it is possible to assign any device to CRIATOM_SOUND_RENDERER_NATIVE by calling the criAtom_SetDeviceId_WASAPI function in the application.
Some sample code to do this is shown below:
main()
{
:
/* Assign the device to CRIATOM_SOUND_RENDERER_NATIVE */
CRIATOM_SOUND_RENDERER_NATIVE, device_info[app_obj->selected_device].id);
:
}
@ CRIATOM_SOUND_RENDERER_NATIVE
Definition: cri_le_atom.h:812
void criAtom_SetDeviceId_WASAPI(CriAtomSoundRendererType type, LPCWSTR device_id)
Set sound device.


Remarks:

It is possible to enumerate the available audio devices by calling the criAtom_EnumAudioEndpoints_WASAPI function.
It is possible to receive that information from a callback every time a new device detection is done.
main()
{
:
/* Enumerate the audio devices */
criAtom_EnumAudioEndpoints_WASAPI(user_endpoint_callback, NULL);
:
}
/* Callback triggered when a device is detected */
static void CRIAPI user_endpoint_callback(void *object, IMMDevice *device)
{
:
/* Get device ID */
hr = device->GetId(&device_id);
/* Save device ID */
wcscpy_s(device_info[num_devices].id, MAX_DEVICE_ID_LENGTH, device_id);
/* Free device ID area */
CoTaskMemFree(device_id);
:
}
CriSint32 criAtom_EnumAudioEndpoints_WASAPI(CriAtomAudioEndpointCbFunc_WASAPI callback, void *object)
Enumerate audio endpoints.