Jump to content
  • Advertisement
Sign in to follow this  
Thergothon

Basic Direct Sound problem.

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

I'm having troubles with this section of my code. I've never programmed direct sound before so its probably a glaringly obvious mistake, but for some reason, the QueryInterface call keeps failing. Any help would be greatly appreciated.
  LPDIRECTSOUNDBUFFER tempBuffer;
  HRESULT hr = dsound->CreateSoundBuffer(&bufferDesc, &tempBuffer, 0);
  if(SUCCEEDED(hr)) {
	  if(FAILED(tempBuffer->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*) soundBuffer))) {
		  SAFE_RELEASE(tempBuffer);
		  return false;
	  }
	  SAFE_RELEASE(tempBuffer);
  }else{
	  return false;
  }

Share this post


Link to post
Share on other sites
Advertisement
Is tempBuffer being created as a primary buffer (dwFlags member of bufferDesc contains DSBCAPS_PRIMARYBUFFER)? You can only obtain an IDirectSoundBuffer8 interface on secondary buffers.

Share this post


Link to post
Share on other sites
Can you show the code that sets up bufferDesc?

Also, you might try checking the return value from QueryInterface to see exactly what error it is returning.

Share this post


Link to post
Share on other sites
This is the code for setting up the wave format struct and initialising the buffer description:


//set up wav format structure
WAVEFORMATEX wfx;
ZeroMemory(&wfx, sizeof(wfx));
wfx.wFormatTag = formatTag;
wfx.nChannels = channels;
wfx.nSamplesPerSec = sampleRate;
wfx.nBlockAlign = blockAlign;
wfx.nAvgBytesPerSec = avgBytesSec;
wfx.wBitsPerSample = bitsPerSample;

//set up buffer description struct
DSBUFFERDESC bufferDesc;
ZeroMemory(&bufferDesc, sizeof(bufferDesc));
bufferDesc.dwSize = sizeof(bufferDesc);
bufferDesc.dwFlags = DSBCAPS_CTRLVOLUME;
bufferDesc.dwBufferBytes = dataSize;
bufferDesc.lpwfxFormat = &wfx;



I'll change the code to find out what error is being generated and post it in a bit.

Share this post


Link to post
Share on other sites
Are you sure the QueryInterface call is failing? That looks more like an error from CreateSoundBuffer and would imply that something isn't right in your bufferDesc and/or wfx structures.

Share this post


Link to post
Share on other sites
Yes, I am sure it was failing. I just fixed it not fifteen minutes ago and am having a blast adding sound to my game. :)

The problem was that I wasn't passing the address of the soundBuffer to the query interface function, which would explain why it was chucking a DSERR_INVALIDPARAM error at me.

I was doing this:

tempBuffer->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*) soundBuffer);

But when I changed it to this, it worked fine:

tempBuffer->QueryInterface(IID_IDirectSoundBuffer8, (LPVOID*) &soundBuffer);


Anyway, thanks for your time, I really do appreciate it.

:)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!