Jump to content


CreateSoundBuffer returning DSERR_INVALIDPARAM


1 reply to this topic

#1 kooper

    New Member

  • Members
  • Pip
  • 8 posts

Posted 20 May 2009 - 10:47 AM

Im making a simple 2D game for a university project and when I try to create a sound buffer its returning the error DSERR_INVALIDPARAM and I cant figure out why. I know direct sound is pretty much dead but its what we were told to use so I have to stick with it. Any help would be greatly appreciated.

void Sound::InitializeSound(HWND hWnd)

{


	HRESULT snd = DirectSoundCreate8(NULL, &d3dSound, NULL);


	if (FAILED(snd))

		MessageBox(NULL, "failed to create sound device", "FAIL!", MB_ICONEXCLAMATION | MB_OK);


	HRESULT spr = d3dSound->SetCooperativeLevel(hWnd, DSSCL_NORMAL);


	if (FAILED(spr))

		MessageBox(NULL, "failed to set sound priority", "FAIL!", MB_ICONEXCLAMATION | MB_OK);



	WAVEFORMATEX wfx;

	memset(&wfx, 0, sizeof(WAVEFORMATEX)); 

	wfx.wFormatTag = WAVE_FORMAT_PCM; 

	wfx.nChannels = dwPrimaryChannels; 

	wfx.nSamplesPerSec = dwPrimaryFreq; 

	wfx.wBitsPerSample = dwPrimaryBitRate;

	wfx.nBlockAlign = (wfx.wBitsPerSample / 8 * wfx.nChannels);

	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; 



	LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;

	DSBUFFERDESC dsbd;

    memset( &dsbd, 0, sizeof(DSBUFFERDESC) );

    dsbd.dwSize        = sizeof(DSBUFFERDESC);

    dsbd.dwFlags = DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY | DSBCAPS_PRIMARYBUFFER; 

    dsbd.dwBufferBytes = 0;

    dsbd.lpwfxFormat   = &wfx;

	


	HRESULT csb = d3dSound->CreateSoundBuffer( &dsbd, &pDSBPrimary, NULL );

	if (FAILED(csb))

		MessageBox(NULL, "failed to create sound buffer", "FAIL!", MB_ICONEXCLAMATION | MB_OK);


	if(pDSBPrimary)

		pDSBPrimary->Release();

}


thanks in advance for any help you can give

#2 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 20 May 2009 - 01:37 PM

lpwfxFormat has to be null for primary buffers.
"Stupid bug! You go squish now!!" - Homer Simpson





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users