Problems Using Direct Sound
I am trying to use MS direct sound and am having endless problems. I can't
figure out which files I need to include or how to get it to work.
I've been trying to work my way through some MSDN examples and the directx
help files.
I can create the IDirectSound interface, but when I try to create a sound
buffer for streaming, all I get DSERR_INVALIDPARAM as a return value. I'm
using the example from the help files, so I can't figure out what the
problem is.
here'a the create sound buffer code:
AppCreateBasicBuffer(LPDIRECTSOUND lpDirectSound, LPDIRECTSOUNDBUFFER
*lplpDsb)
{
PCMWAVEFORMAT pcmwf;
DSBUFFERDESC dsbdesc;
HRESULT hr;
// Set up wave format structure.
memset(&pcmwf, 0, sizeof(PCMWAVEFORMAT));
pcmwf.wf.wFormatTag = WAVE_FORMAT_PCM;
pcmwf.wf.nChannels = 2;
pcmwf.wf.nSamplesPerSec = 22050;
pcmwf.wf.nBlockAlign = 4;
pcmwf.wf.nAvgBytesPerSec = pcmwf.wf.nSamplesPerSec *
pcmwf.wf.nBlockAlign;
pcmwf.wBitsPerSample = 16;
// Set up DSBUFFERDESC structure.
memset(&dsbdesc, 0, sizeof(DSBUFFERDESC)); // Zero it out.
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
// Need default controls (pan, volume, frequency).
dsbdesc.dwFlags = DSBCAPS_CTRLVOLUME;
// 3-second buffer.
dsbdesc.dwBufferBytes = 3 * pcmwf.wf.nAvgBytesPerSec;
dsbdesc.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf;
// Create buffer.
hr = lpDirectSound->CreateSoundBuffer(NULL/*&dsbdesc*/, lplpDsb, NULL);
if(DS_OK == hr) {
// Succeeded. Valid interface is in *lplpDsb.
return true;
} else {
// Failed.
*lplpDsb = NULL;
return false;
}
Any help or guidance would be greatly appreciated.
Thanks,
Paul Irwin