the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > when using IMMDevice: : Activate method open audio devices, if the request is not clearly specify, the flow of data format The device's default data flow format is used, the default format parameters specified by the WAVEFORMATEXTENSIBLE structure returned by the GetMixFormat method. If the wFormatTag field in the WAVEFORMATEXTENSIBLE structure equals 65534(0xFFFE), then this indicates that the data stream format is compressed-based streaming audio format, It is called Extended and Variable-Length Compression Format(EXtensible variable-Length Compression Format, or XVID). The
-
XVID format is a format used to compress audio and includes a 128-bit GUID to identify the format's detailed parameters. Because of its extensibility and variable length, the format can accommodate a variety of compression techniques and audio encoding formats.
-
If you want to manually specify the audio format, you can do so using the pFormat parameter in the IAudioClient::Initialize method. In this case, you need to use valid format parameters. If you specify an invalid parameter, an E_INVALIDARG error occurs. You can use the member of the WAVEFORMATEXTENSIBLE structure to set specific format parameters and pass them to the pFormat parameter of the Initialize method. For example, the following code demonstrates how to initialize the WAVEFORMATEXTENSIBLE structure to specify the PCM 16-bit, 44.1kHz, 2-channel audio format:
WAVEFORMATEXTENSIBLE wfx = { 0 };
wfx.Format.wFormatTag = WAVE_FORMAT_PCM;
wfx.Format.nChannels = 2;
wfx.Format.nSamplesPerSec = 44100;
wfx.Format.nAvgBytesPerSec = 44100 * 2 * 2;
wfx.Format.nBlockAlign = 2 * 2;
wfx.Format.wBitsPerSample = 16;
wfx.Format.cbSize = 0;
wfx.Samples.wValidBitsPerSample = 16;
wfx.dwChannelMask = KSAUDIO_SPEAKER_STEREO;
If you need to use a custom audio format, then you need to carefully understand the parameters of that format and set up the members of the WAVEFORMATEXTENSIBLE structure correctly.