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;
}
🔒 Locked
Basic Direct Sound problem.
Advertisement
Original Post
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.
No it is only being created with volume control alone.
This is the code for setting up the wave format struct and initialising the buffer description:
I'll change the code to find out what error is being generated and post it in a bit.
//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.
I got a bit sidetracked, but did track down the error that is being generated: DSERR_INVALIDPARAM
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.
:)
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.
:)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement