AUDIO_STREAM_CATEGORY 需要多个 XAudio2 实例?

Multiple XAudio2 instances needed for AUDIO_STREAM_CATEGORY?

在 Windows 8 和 10 的较新的 XAudio2 API 中,AUDIO_STREAM_CATEGORY 被传递给 IXAudio2::CreateMasteringVoice

文档继续说明这些应该如何用于不同类型的音频。但是一个 IXAudio2 只允许有一个主语音。要做到这一点,需要完全独立的 IXAudio2 实例以及所需的所有相关接口,或者可以通过某种方式在音频图中的其他地方指定类别?

Games should categorize their music streams as AudioCategory_GameMedia so that game music mutes automatically if another application plays music in the background. Music or video applications should categorize their streams as AudioCategory_Media or AudioCategory_Movie so they will take priority over AudioCategory_GameMedia streams. Game audio for in-game cinematics or cutscenes, when the audio is premixed or for creative reasons should take priority over background audio, should also be categorized as Media or Movie.

您可以在一个流程中创建多个 IXAudio2 实例,这样每个实例都有自己的主语音。如果你想从一个进程中输出不止一类音频,你需要创建多个 IXAudio2 实例。

通常你可以只使用一个并始终使用 AudioCategory_GameMedia

I know this design is a bit of a kludge but the category is set on the WASAPI output voice, which is where XAudio2 sends it's mastering voice stuff to. Any other design would have required annotating category data within the internal XAudio audio graph which would have been quite complicated to implement for not a lot of value. We choose instead to just let applications have more than one audio-graph active at once each with it's own mastering voice and therefore it's own category.

您选择如何支持 WASAPI 的音频类别功能取决于您,当然最好的用户体验取决于您的应用程序实际做什么。