Prerequisites
This walkthrough assumes you have basic familiarity with voice chat in PlayFab Party.Platform support
Real-time audio manipulation isn’t available on all platforms. While the methods associated with real-time audio manipulation are present in the unified, cross-platform header, they’re currently only implemented for Windows, XBOX, and PlayStation® 5. The methods will return errors on other platforms.Audio streams
Real-time audio manipulation introduces the concept of audio streams for retrieving audio from or submitting audio to the library. There are two types of audio streams. The first is the source stream. A source stream is used to retrieve audio from a chat control. Each chat control can only have a single source stream, called the voice stream. For a local chat control, this is used to retrieve the microphone input; for a remote chat control, this is used to retrieve incoming voice audio. If the voice stream exists for a chat control, the library will redirect source audio for that chat control to its voice stream rather than handling the audio automatically. For a local chat control, this means redirecting microphone audio to the voice stream instead of automatically encoding and transmitting it; for a remote chat control, this means redirecting incoming voice audio to the voice stream instead of automatically submitting it to each local chat control to be played back. Source streams are represented by thePartyAudioManipulationSourceStream.
The second type of stream is the sink stream. A sink stream is used to submit audio to a chat control. Only local chat controls can have sink streams, and they each can have two. They’re called the capture stream and render stream. If the capture stream exists for a chat control, the library will pull audio from the capture stream to encode and transmit to other chat controls instead of the microphone. If the render stream exists for a chat control, the library will pull audio from the render stream and play it back in addition to the voice chat audio that is automatically played back from remote chat controls. Audio submitted to the capture stream is used as the local chat control’s microphone input; audio submitted to the render stream is played back or “rendered” to the local chat control’s audio output device. Sink streams are represented by the PartyAudioManipulationSinkStream.
Configuring audio streams
By default, the library handles audio retrieval, transport, and playback. Therefore, chat controls are created without any audio streams. You can create one or more streams for a chat control via the stream configuration methods -PartyLocalChatControl::ConfigureAudioManipulationCaptureStream(), PartyLocalChatControl::ConfigureAudioManipulationRenderStream(), and PartyChatControl::ConfigureAudioManipulationVoiceStream(). Once configured, a stream can subsequently be retrieved via PartyLocalChatControl::GetAudioManipulationCaptureStream(), PartyLocalChatControl::GetAudioManipulationRenderStream(), and PartyChatControl::GetAudioManipulationVoiceStream()
Each stream configuration method allows you to specify the format of the audio that you will retrieve from or submit to the stream. For more information about supported formats, see the reference documentation for each stream configuration method.
Retrieving audio from a source stream
You can retrieve audio from a source stream viaPartyAudioManipulationSourceStream::GetNextBuffer(). When voice activity is detected, a new buffer will be available approximately every 40 ms. If no buffers are available, the call will succeed and provide a zero length buffer. The total number of buffers instantaneously available can be retrieved via PartyAudioManipulationSourceStream::GetAvailableBufferCount().
For efficiency, GetNextBuffer() provides a buffer that points to the library’s memory instead of copying the entire buffer. It can optionally be modified in place. Once you’re done processing a buffer, you should release it via PartyAudioManipulationSourceStream::ReturnBuffer() so that the library can reclaim its memory. Multiple buffers can be retrieved before any are returned, and buffers don’t need to be returned in the order they were retrieved.
Submit audio to a sink stream
You can submit audio to a sink stream viaPartyAudioManipulationSinkStream::SubmitBuffer(). The buffer is copied by the library and can be immediately freed after the call completes.
Every 40 ms, the library consumes 40 ms of audio that has been submitted to the sink stream. To prevent audio hiccups, audio should be submitted at a constant rate.
