Monogame: XAudio2 crash on audio file set below Best quality in Content Pipeline

Created on 5 Apr 2019  路  7Comments  路  Source: MonoGame/MonoGame


I have an MP3 file processed as a Sound Effect. To reduce build size, I set the quality to Medium in the content pipeline. On DesktopGL builds, I have no issues, but on a WindowsDX build, the game always crashes when trying to play that sound effect. The game also crashes if the quality is set to Low. However, when I set the quality to Best, it does not crash.

I did indeed change the platform to Windows in the content pipeline before processing the content for the Windows build.

Stack Trace:
   at SharpDX.Result.CheckError()
   at SharpDX.XAudio2.XAudio2.CreateSourceVoice_(SourceVoice sourceVoiceOut, IntPtr sourceFormatRef, VoiceFlags flags, Single maxFrequencyRatio, IntPtr callbackRef, Nullable`1 sendListRef, Nullable`1 effectChainRef)
   at SharpDX.XAudio2.SourceVoice.CreateSourceVoice(XAudio2 device, WaveFormat sourceFormat, VoiceFlags flags, Single maxFrequencyRatio, IntPtr callback, EffectDescriptor[] effectDescriptors)
   at Microsoft.Xna.Framework.Audio.SoundEffect.PlatformSetupInstance(SoundEffectInstance inst)
   at Microsoft.Xna.Framework.Audio.SoundEffect.CreateInstance()

What version of MonoGame does the bug occur on:

  • MonoGame 3.7 (develop)

What operating system are you using:

  • Windows

What MonoGame platform are you using:

  • WindowsDX
Audio ContentPipeline

Most helpful comment

Here's a barebones project reproducing the issue. Simply load up the game and press the Space bar to crash it.
TestXAudioCrash.zip

You can change the content import settings and see that setting it to Best won't crash but Medium and Low does.

The sound used in the test is royalty-free from here. The one used in my actual project is completely different, outside of also being an MP3, and crashes as well.

All 7 comments

Do you happen to have a SharpDX error code with the exception message?

Does it crash with absolutely all files and only some of them (if so, could you share one that fails?).

This is what I can gather from the crash:

HRESULT: [0x88960001], Module: [SharpDX.XAudio2], ApiCode: [XAUDIO2_E_INVALID_CALL/InvalidCall], Message: Unknown

Later today or tomorrow, I'll test on an empty project with a few files and report back.

Here's a barebones project reproducing the issue. Simply load up the game and press the Space bar to crash it.
TestXAudioCrash.zip

You can change the content import settings and see that setting it to Best won't crash but Medium and Low does.

The sound used in the test is royalty-free from here. The one used in my actual project is completely different, outside of also being an MP3, and crashes as well.

Medium and Low settings produce adpcm wave file with SamplesPerBlock higher then 512.

Medium and Low settings produce adpcm wave file with SamplesPerBlock higher then 512.
FFmpeg fault.

If I manually convert the file with the same settings and play it via an audio player (Ex. Windows Media Player), it plays just fine. To my knowledge, msAdpcm and ImaAdcpm are very similar, and the formats are the only difference for the file between WindowsDX and DesktopGL when they're processed by the content pipeline.

Sorry that I did not make myself clear.
XAudio2 uses a modified version of the Microsoft ADPCM codec. FFmpeg output vanilla Microsoft ADPCM file. The difference is in SamplesPerBlock, where XAudio2 smallest block size is 32 samples, and the highest is 512 samples. Microsoft ADPCM can have much larger size, FFmpeg output 1k samples.
XAudio2 library is very strict about the format of the data becuase xbox uses the same library and decode sound via hardware dsp so creating XAudio2 object without proper adpcm data will end with an exception like in your example.

Thanks for the explanation! Would we need to lower the settings in FFmpeg for platforms using XAudio2 to fix this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Halofreak1990 picture Halofreak1990  路  4Comments

bjornenalfa picture bjornenalfa  路  5Comments

NET-D3v3l0p3r picture NET-D3v3l0p3r  路  3Comments

monsieurmax picture monsieurmax  路  5Comments

harry-cpp picture harry-cpp  路  5Comments