Create a capture buffer by calling the IDirectSoundCapture::CreateCaptureBuffer method of the DirectSoundCapture object.
One of the parameters to the method is a DSCBUFFERDESC structure that describes the characteristics of the desired buffer. The last member of this structure is a WAVEFORMATEX structure, which must be initialized with the details of the desired wave format. See the reference for WAVEFORMATEX in the Win32 API section of the Platform SDK for information on the members of that structure.
The following example sets up a capture buffer that will hold about 1 second of data:
DSCBUFFERDESC dscbd;
LPDIRECTSOUNDCAPTUREBUFFER pDSCB;
WAVEFORMATEX wfx =
{
// wFormatTag, nChannels, nSamplesPerSec, mAvgBytesPerSec,
// nBlockAlign, wBitsPerSample, cbSize
{WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0},
};
dscbd.dwSize = sizeof(DSCBUFFERDESC);
dscbd.dwFlags = 0;
// We're going to capture one second's worth of audio
dscbd.dwBufferBytes = wfx.nAvgBytesPerSec;
dscbd.dwReserved = 0;
dscbd.lpwfxFormat = &wfx;
pDSCB = NULL;
// pDSC is the pointer to the DirectSoundCapture object
HRESULT hr = pDSC->CreateCaptureBuffer(&dscbd,
&pDSCB, NULL);