CRI ADX  Last Updated: 2024-07-17 10:47 p
Audio output through multiple devices

Samples Directory

/CRIWARE/SDK/pc/samples/criatomex/multi_device

Sample Description

This sample shows how to play sound through multiple audio devices.
It differs from the "select_device" sample in that the audio is output simultaneously through multiple devices.
When playing back the sound, it is necessary to prepare an independent mixer for each device. Therefore, an additional ASR rack must be created as a mixer.
In this sample, we created 4 ASR racks (the default ASR and 3 additional ASRs) and assign the output of each ASR rack to a different device.
The program flow is as follows:
  1. Enumerate devices by calling the criAtom_EnumAudioEndpoints_WASAPI function.
  2. Assign the devices found from CRIATOM_SOUND_RENDERER_HW1 to CRIATOM_SOUND_RENDERER_HW4 by calling the criAtom_SetDeviceId_WASAPI function.
  3. Initialize the Atom library and set the output of the default ASR rack to CRIATOM_SOUND_RENDERER_HW1.
  4. Create three additional ASR racks and set the output of each ASR rack from CRIATOM_SOUND_RENDERER_HW2 to CRIATOM_SOUND_RENDERER_HW4.
  5. At the start of the audio playback, specify the destination ASR rack by calling the criAtomExPlayer_SetAsrRackId function.
Some sample code to do this is shown below:
/* Max number of devices */
#define MAX_DEVICES (4)
/* Number of actually found devices */
static CriSint32 num_devices = 0;
/* Type of hardware sound renderer assigned to each device */
static const CriAtomSoundRendererType sound_renderer_table[MAX_DEVICES] = {
};
/* Main process */
main()
{
:
/* Enumerate the audio devices */
criAtom_EnumAudioEndpoints_WASAPI(user_endpoint_callback, NULL);
:
:
/* Initialize the library */
lib_config.asr.sound_renderer_type = CRIATOM_SOUND_RENDERER_HW1;
criAtomEx_Initialize_WASAPI(&lib_config, NULL, 0);
/* Create ASR racks for additional devices */
for (i = 1; i < MAX_DEVICES; i++) {
asr_rack_config.sound_renderer_type = sound_renderer_table[i];
app_obj->asr_rack_id[i] = criAtomExAsrRack_Create(&asr_rack_config, NULL, 0);
}
:
:
/* Assign the destination ID of the ASR */
criAtomExPlayer_SetAsrRackId(app_obj->player, app_obj->selected_device);
/* Start playback */
app_obj->playback_id = criAtomExPlayer_Start(app_obj->player);
:
}
/* Callback triggered when a device is detected */
static void CRIAPI user_endpoint_callback(void *object, IMMDevice *device)
{
:
/* Get device ID */
device->GetId(&device_id);
/* Link sound renderer and hardware */
criAtom_SetDeviceId_WASAPI(sound_renderer_table[num_devices], device_id);
/* Free device ID area */
CoTaskMemFree(device_id);
:
}
CriAtomExAsrRackId criAtomExAsrRack_Create(const CriAtomExAsrRackConfig *config, void *work, CriSint32 work_size)
Creating the ASR rack.
CriAtomExPlaybackId criAtomExPlayer_Start(CriAtomExPlayerHn player)
Start the playback.
void criAtomExPlayer_SetAsrRackId(CriAtomExPlayerHn player, CriSint32 rack_id)
Specifying the ASR Rack ID.
#define criAtomExAsrRack_SetDefaultConfig(p_config)
Setting default parameters for CriAtomAsrConfig.
Definition: cri_le_atom_asr.h:2119
enum CriAtomSoundRendererTypeTag CriAtomSoundRendererType
Sound renderer type.
@ CRIATOM_SOUND_RENDERER_HW1
Definition: cri_le_atom.h:817
@ CRIATOM_SOUND_RENDERER_HW3
Definition: cri_le_atom.h:819
@ CRIATOM_SOUND_RENDERER_HW2
Definition: cri_le_atom.h:818
@ CRIATOM_SOUND_RENDERER_HW4
Definition: cri_le_atom.h:820
void criAtomEx_Initialize_WASAPI(const CriAtomExConfig_WASAPI *config, void *work, CriSint32 work_size)
Library initialization.
CriSint32 criAtom_EnumAudioEndpoints_WASAPI(CriAtomAudioEndpointCbFunc_WASAPI callback, void *object)
Enumerate audio endpoints.
void criAtom_SetDeviceId_WASAPI(CriAtomSoundRendererType type, LPCWSTR device_id)
Set sound device.
#define criAtomEx_SetDefaultConfig_WASAPI(p_config)
Assign the default values to the configuration structure used for the library's initialization.
Definition: cri_le_atom_wasapi.h:75
Attention
CRIATOM_SOUND_RENDERER_HW1 and CRIATOM_SOUND_RENDERER_NATIVE refer to the same sound renderer.
Therefore, after assigning a device to CRIATOM_SOUND_RENDERER_HW1, if you also assign a device to CRIATOM_SOUND_RENDERER_NATIVE, the setting for CRIATOM_SOUND_RENDERER_HW1 will be overwritten.
(Please use only one of them in the application.)