Skip to main content
gamedev.net
🔒 Locked

Basic Direct Sound problem.

Started by Thergothon 7 replies 850+ views
Original Post
Thergothon
Thergothon
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;
  }
Dave Hunt
Dave Hunt
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.
Thergothon
Thergothon
No it is only being created with volume control alone.
Dave Hunt
Dave Hunt
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.
Thergothon
Thergothon
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.
Thergothon
Thergothon
I got a bit sidetracked, but did track down the error that is being generated: DSERR_INVALIDPARAM
Dave Hunt
Dave Hunt
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.
Thergothon
Thergothon
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.

:)

Dave Hunt
Dave Hunt
Doh! I must have looked at that line 10 times and never noticed it.

Well, glad you got it working. Have fun!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.