• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1021
  • Last Modified:

Problem creating DirectSound primary buffer

I'm trying to learn how to use DirectSound so that I can use it in a game engine I am working on. I'm using MSVC++ 2008 (Without MFC) and the DXSDK March 2008.

The problem I am having is that when I attempt to create the primary buffer using the IDirectSound8::CreateSoundBuffer function the returned HRESULT is always E_INVALIDARG. Since I am relatively inexperienced with C++ chances are it's a quick-fix solution, but I've searched MSDN, Google and Experts-Exchange and I've found nothing to help me.

Thanks in advance.
//Globals
LPDIRECTSOUND8 pDSound = NULL;
LPDIRECTSOUNDBUFFER pDsndPrimary = NULL;
LPDIRECTSOUNDBUFFER8 pDsndSecondary = NULL;
 
int InitDSound(HWND hWnd)
{
	HRESULT hr = CoInitialize(NULL);
 
	hr = DirectSoundCreate8(NULL,&pDSound,NULL);
	if(FAILED(hr))
		return 1;
 
	hr = pDSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL);
	if(FAILED(hr))
		return 1;
 
//The 'problem' portion of my DSound function
	//Set up the wave format
	WAVEFORMATEX wvf;
	ZeroMemory(&wvf, sizeof(WAVEFORMATEX));
 
	wvf.nChannels = 1;
	wvf.wFormatTag = WAVE_FORMAT_PCM;
	wvf.nSamplesPerSec = 11025;
	wvf.wBitsPerSample = 16;
	wvf.nBlockAlign = ((wvf.nChannels*wvf.wBitsPerSample)/8);
	wvf.nAvgBytesPerSec = (wvf.nBlockAlign*wvf.nSamplesPerSec);
	wvf.cbSize = 0;
	
	//Create the buffer description
	DSBUFFERDESC dsDesc;
	ZeroMemory(&dsDesc, sizeof(DSBUFFERDESC));
 
	dsDesc.dwSize = sizeof(dsDesc);
	dsDesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
	dsDesc.guid3DAlgorithm = GUID_NULL;
	dsDesc.lpwfxFormat = &wvf;
	dsDesc.dwBufferBytes = 0;
	dsDesc.dwReserved = NULL;
	
	//Create the buffer
	hr = pDSound->CreateSoundBuffer(&dsDesc, &pDsndPrimary, NULL);
	if(FAILED(hr))
		return 1; //Here hr is equal to E_INVALIDARG and the program quits
 
	return 0;
}

Open in new window

0
Glen A.
Asked:
Glen A.
1 Solution
 
Glen A.IT Project ManagerAuthor Commented:
This problem has been solved:

It seems that the lpwfxFormat member can't be specified in the DSBUFFERDESC structure when you are creating a buffer with the DSBCAPS_PRIMARYBUFFER flag.

This question can be closed.
0
 
ee_autoCommented:
Question PAQ'd, 500 points refunded, and stored in the solution database.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now