Native DirectX Audio for Windows Store Apps

headphonesTo play wave files in Mahjong Solitaire for Windows 8 I used SharpDX. When I noticed pops and clicks during animations, I tried a few things like delaying a bit so animations could finish but the audio still did not perform as well as I wanted. Together with Inge Schepers who also experienced some problems with playing waves in her Takuzu game I did something I have not done in 20 years…I wrote C++ code! Luckily we found some WP8 samples we could convert to WinRT.

I wrapped everything together in a demo project you can find on Git.

I you want to use native DirectX audio, you need to do the folowing:

size_t XAudio2SoundPlayer::LoadSounds() {
char16* SOUND_FILE_LIST [] = {
	L"Wavs\\match.wav",
	L"Wavs\\startup.wav",
	nullptr
};
private void Button_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) {
    XPlayer.Instance.PlayWave(0);
}

In this version you have to add the wavs in the C++ project manually to the SOUND_FILE_LIST. If you can help me improve this code in a way that you can pass the wavs from your main project, we can make it more generic. Let me know if you do!

Happy wave making!