And those who were seen dancing were thought to be insane by those who could not hear the music.
– Friedrich Nietzsche
A submix voice is used primarily for performance improvements and effects processing. SourceVoices can be bundles together into the same submix voice, to, for example, easily change the volume of all music files.
The first parameter returns the address of the newly created submix voice. The second parameter specifies the number of input channels, and the third parameter defines the input sample rate. The other parameters have no use for us at the moment.
After having created the submix voices, we have to create an XAUDIO2_SEND_DESCRIPTOR structure, which defines a destination voice that is the target of a send from another voice and specifies whether a filter should be used, as follows:
The first flag, set to 0, means that we do not want to use a filter. The second member of the structure simply specifies the submix voice the voices should be sent to.
With the XAUDIO2_SEND_DESCRIPTOR structure defined, we have to create an XAUDIO2_VOICE_SENDS structure, which defines a set of voices to receive data from a single output voice, as follows:
The first member being set to 1 means that we want to voices to be sent to one submix voice. The second parameter specifies the send descriptor to use.
Combining those steps together, we get something as follows:
Now when loading a file from the hard drive, we simply chose which submix voice to send it to based on whether we are loading a sound effect or a music file.
Changing the volume of all music files is now as easy as this:
As an example, we will allow the player to change the volume of the music and sound effects in the options menu:
This was short and easy. You can download the source code from here.
In the next tutorial, we will learn how to stream music from the hard drive, i.e. how to play audio without having to completely load the entire file into memory first.