Jump to content
  • Advertisement
Sign in to follow this  

XAudio2 CreateSourceVoice crashing sometimes

This topic is 658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is probably the worst kind of question one could ask but I am a kind of stuck. I am experimenting with XAudio2 in an attempt to understand the API as I need to integrate some Steam Voice chat code into our game. It is just a simple application that loads and plays some sounds.

The application creates two XAudio2 objects and then loads 2 and "attaches" two sounds to the first one and two to the second one. Dll sounds are played in a loop "simultaneously", sometimes some sounds are "missing" and half of the time on creating the second Source Voice the app crashes.

IXAudio2SourceVoice* XAudio2Engine::GetSourceVoice(WAVEFORMATEX const* format)
    assert(nullptr != m_XAudio2Engine);

    IXAudio2SourceVoice* sourceVoice = nullptr;
    auto hresult = m_XAudio2Engine->CreateSourceVoice(&sourceVoice, format);
    if (FAILED(hresult))
        return nullptr;

    return sourceVoice;

WAVEFORMATEX appears to be intact all the time. 

Here is a copy of the call stack. Do you see any clues what might be wrong?

 	msvcrt.dll!memcpy()	Unknown
 	XAudio2_9.dll!XAudio2WaveHelp::AllocateWaveFormatCopy(struct tWAVEFORMATEX const *)	Unknown
 	XAudio2_9.dll!LEAPCORE::CSWVoice::Initialize(struct tWAVEFORMATEX const *,struct IUnknown *,struct IUnknown *,__int64)	Unknown
 	XAudio2_9.dll!LEAPCORE::CLeapSystem::CreateVoice(struct tWAVEFORMATEX const *,unsigned int,struct IUnknown *,struct IUnknown *,struct ILeapFilter *,__int64,struct ILeapVoiceCallback *,unsigned int,struct ILeapVoice * *)	Unknown
 	XAudio2_9.dll!XAUDIO2::CX2SourceVoice::Initialize(unsigned int,float,struct tWAVEFORMATEX const *,struct XAUDIO2_VOICE_SENDS const *,struct XAUDIO2_EFFECT_CHAIN const *)	Unknown
 	XAudio2_9.dll!XAUDIO2::CX2Engine::CreateSourceVoice(struct IXAudio2SourceVoice * *,struct tWAVEFORMATEX const *,unsigned int,float,struct IXAudio2VoiceCallback *,struct XAUDIO2_VOICE_SENDS const *,struct XAUDIO2_EFFECT_CHAIN const *)	Unknown
>	XAudio2_DualEngine.exe!XAudio2Engine::GetSourceVoice(const tWAVEFORMATEX * format) Line 140	C++
 	XAudio2_DualEngine.exe!PcmSound::Attach(XAudio2Engine & xAudio2Engine) Line 192	C++
 	XAudio2_DualEngine.exe!main(int args, char * * argc) Line 42	C++

I can post a link to the source code but I doubt anyone would be interested.

EDIT: I created a new simpler test sample. I just load the wave file, create, submit and play the sound then I just "chained" several sounds and there is no crash whatsoever. So the crash might be my fault after all.
Edited by Zingam

Share this post

Link to post
Share on other sites

Apparently I had to do something like that:

    auto waveFormatExSize = sizeof(WAVEFORMATEX) + m_Wave.GetFormat()->cbSize;
    Format = reinterpret_cast<WAVEFORMATEX*>(new CHAR[waveFormatExSize]);
    ZeroMemory(Format, waveFormatExSize);
    memcpy_s(Format, waveFormatExSize, m_Wave.GetFormat(), waveFormatExSize);

Share this post

Link to post
Share on other sites

In case you were wondering: the reason for that is that the WAVEFORMATEX can store extra data after it in memory. This extra data differs depending on what format you're using - eg. if your WAVE data is ADPCM-encoded, then the extra data will have the ADPCM coefficient table that's needed to decode the data. I've found empirically that there are certain WAV formats that XAudio2 cannot handle - particularly ADPCM formats with large compression block sizes.


I seem to recall that the cbSize field on the WAVEFORMATEX structure actually includes the extra data, but I may be misremembering and you should double-check that.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!