Sign in to follow this  
Tallyho_Chaps

XAudio2 Initialization Fails

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this