Jump to content
  • Advertisement
Sign in to follow this  
Tallyho_Chaps

XAudio2 Initialization Fails

This topic is 959 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

Hi everybody,

 

I'm currently trying to output a simple sine wave with XAudio2,

but initialization fails when creating my source voice.

Have you any clue why it happens?

Detailed debug info says: "Invalid source format" but i can't see the problem.

 

Thanks guys :)

 

the wave format struct looks as follows:

WAVEFORMATEX waveFormat = {};
waveFormat.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
waveFormat.nChannels = 2;
waveFormat.nSamplesPerSec = 96000;
waveFormat.wBitsPerSample = 32;
waveFormat.nAvgBytesPerSec = (waveFormat.nSamplesPerSec * waveFormat.wBitsPerSample) / 8;
waveFormat.nBlockAlign = (waveFormat.nChannels*waveFormat.wBitsPerSample) / 8;
waveFormat.cbSize = 0;

and initialization code:

static IXAudio2SourceVoice* Win64InitXAudio2(WAVEFORMATEX* waveFormat)
{

	IXAudio2SourceVoice* sourceVoice;

	IXAudio2* xAudio2;
	HRESULT hr = XAudio2Create(
		&xAudio2,
		0,
		XAUDIO2_DEFAULT_PROCESSOR);

	if (SUCCEEDED(hr))
	{
		IXAudio2MasteringVoice* masterVoice;
		hr = xAudio2->CreateMasteringVoice(
			&masterVoice,
			XAUDIO2_DEFAULT_CHANNELS,
			96000);
		if (SUCCEEDED(hr))
		{
			

			hr = xAudio2->CreateSourceVoice(		//returns 0x88960001
				&sourceVoice,
				(WAVEFORMATEX*)waveFormat
			);
			if (SUCCEEDED(hr))
			{
				OutputDebugStringA("xAudio successfully initialized!");
			}
			else
			{
				//TODO: Error handling with hr
			}
		}
		else
		{
			//TODO: Error handling with hr
		}
	}
	else
	{
		//TODO: Error handling with hr
	}

	return sourceVoice;
}
UPDATE:
 
Solved the problem with the format I forgot to involve channel count
in bytes per second:
 
waveFormat.nAvgBytesPerSec = (waveFormat.nSamplesPerSec * waveFormat.wBitsPerSample * 
                              waveFormat.nChannels) / 8;
Edited by Tallyho_Chaps

Share this post


Link to post
Share on other sites
Advertisement
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!