CRI ADX  Last Updated: 2024-07-17 10:47 p
WASAPI Exclusive Mode

Samples Directory

/CRIWARE/SDK/pc/samples/criatomex/wasapi_exclusive


Sample Description

Usage Instructions
To use WASAPI in exclusive mode, you must initialize the library using the following procedure.
-# Use the criAtom_SetAudioClientShareMode_WASAPI function to indicate to the library that you want to use WASAPI in exclusive mode.
-# Specify WAVEFORMATEXTENSIBLE as the sound output format to the criAtom_SetAudioClientFormat_WASAPI function.
-# Use the criAtomEx_Initialize_WASAPI function to initialize the library.
The following is a code example:
:
/* Indicate to initialize WASAPI in exclusive mode */
criAtom_SetAudioClientShareMode_WASAPI(AUDCLNT_SHAREMODE_EXCLUSIVE);
/* Specify the WASAPI output format */
/* Caution: This sample uses 48 kHz 24-bit PCM output, */
/* but there is no guarantee that the specified format can actually be used. */
memset(&output_format, 0, sizeof(output_format));
ex_ptr = (WAVEFORMATEX *)&output_format;
ex_ptr->wFormatTag = WAVE_FORMAT_EXTENSIBLE;
ex_ptr->nChannels = 2;
ex_ptr->nSamplesPerSec = 48000;
ex_ptr->wBitsPerSample = 32;
ex_ptr->nBlockAlign = ex_ptr->wBitsPerSample / 8 * ex_ptr->nChannels;
ex_ptr->nAvgBytesPerSec = ex_ptr->nSamplesPerSec * ex_ptr->nBlockAlign;
ex_ptr->cbSize = 22;
output_format.Samples.wValidBitsPerSample = 24;
output_format.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
criAtom_SetAudioClientFormat_WASAPI((const WAVEFORMATEX *)ex_ptr);
/* Initialize the library for WASAPI output */
/* Initialize the library for WASAPI output */
:
void criAtom_SetAudioClientFormat_WASAPI(const WAVEFORMATEX *format)
Output format specification.
void criAtom_SetAudioClientShareMode_WASAPI(AUDCLNT_SHAREMODE mode)
Sharing mode specification.
void criAtomEx_Initialize_WASAPI(const CriAtomExConfig_WASAPI *config, void *work, CriSint32 work_size)
Library initialization.



[Remarks]
When the library is initialized using the criAtomEx_Initialize_WASAPI function, you must use the criAtomEx_Finalize_WASAPI function to clean up the library when you are finished.
Cautions
Whether or not the specified format can be used to correctly output sound strongly depends on the hardware used.
(In some cases, sound may not be output properly even if there is no error returned from WASAPI.)
Use WASAPI exclusive mode only for games which are hardware-limited (such as PC-based arcade games).
Only one application may use WASAPI exclusive mode per OS.
If multiple applications are launched that attempt to use WASAPI exclusive mode, the library initialization will fail.
When using WASAPI exclusive mode, sound output will be disabled for all other applications.
Any sound playback from outside the Atom library, even within the same application, will also be muted.
The Atom library supports the following three types of quantization bit PCM data formats.
- 16-bit
- 32-bit/24-valid
- IEEE float
If a PCM data format other than those listed above is specified, or If the criAtom_GetAudioClientIsFormatSupported_WASAPI function returns CRI_FALSE even when an above format is specified, sound output cannot be performed.