Microsoft DirectX 8.1 (C++)

Creating a Capture Buffer

Create a capture buffer by calling the IDirectSoundCapture8::CreateCaptureBuffer method.

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.

Note that if your application is using DirectSound as well as DirectSoundCapture, capture buffer creation can fail when the format of the capture buffer is not the same as that of the primary buffer. The reason is that some cards have only a single clock and cannot support capture and playback at two different frequencies.

The following example sets up a capture buffer that will hold 1 second of data:

// pDSC is a valid IDirectSoundCapture8 interface pointer.
 
DSCBUFFERDESC      dscbd;
LPDIRECTSOUNDCAPTUREBUFFER pDSCB;
WAVEFORMATEX     wfx =
  {WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0};
 
  // wFormatTag, nChannels, nSamplesPerSec, mAvgBytesPerSec,
  // nBlockAlign, wBitsPerSample, cbSize
 
dscbd.dwSize = sizeof(DSCBUFFERDESC);
dscbd.dwFlags = 0;
dscbd.dwBufferBytes = wfx.nAvgBytesPerSec;
dscbd.dwReserved = 0;
dscbd.lpwfxFormat = &wfx;
dscbd.dwFXCount = 0;
dscbd.lpDSCFXDesc = NULL;
 
pDSCB = NULL;
 
HRESULT hr = pDSC->CreateCaptureBuffer(&dscbd, 
    &pDSCB, NULL);