How to create IXAudio2VoiceCallback for source voice in Rust

Lucas Philippi 0 Reputation points
2023-10-31T19:28:03.1933333+00:00

How do I create a IXAudio2VoiceCallback for a source voice using windows-rs crate for rust.

let mut result: Option<IXAudio2SourceVoice> = None;
xaudio2.CreateSourceVoice(
	&mut result,
	&waveformatex,
	0,
	XAUDIO2_MAX_FREQ_RATIO,
	None,
	None,
	None,
)?;

It is possible to pass a IXAudio2VoiceCallback to CreateSourceVoice but its unclear how I can instantiate this callback.

How do I instantiate a IXAudio2VoiceCallback ?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,622 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
    2023-11-01T00:14:08.81+00:00

    Hello @Lucas Philippi,

    According to How to: Use Source Voice Callbacks, you need to

    1. Create a class that inherits from the IXAudio2VoiceCallback interface.
    2. Create a source voice with IXAudio2::CreateSourceVoice using an instance of the callback class created previously as the pCallback parameter.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.