Microsoft DirectX 8.1 (Visual Basic)

Creating a Capture Buffer

Create a capture buffer by calling the DirectSoundCapture8.CreateCaptureBuffer method.

One of the parameters to the method is a DSCBUFFERDESC type that describes the characteristics of the desired buffer. The fxFormat member is a WAVEFORMATEX type, which must be initialized with the details of the desired wave format.

Note that if your application is using DirectSound8 as well as DirectSoundCapture8, 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:

' dsc is a DirectSoundCapture8 object.
 
Dim dscbd As DSCBUFFERDESC
Dim dscb As DirectSoundCaptureBuffer8
 
' Set up the wave format.
With dscbd.fxFormat
  .nFormatTag = WAVE_FORMAT_PCM
  .nChannels = 2
  .lSamplesPerSec = 22050
  .nBitsPerSample = 16
  .nBlockAlign = _
    .nBitsPerSample / 8 * WaveFormat.nChannels
  .lAvgBytesPerSec = _
     waveFormat.lSamplesPerSec * waveFormat.nBlockAlign
  .nSize = 0  ' Ignored for WAVE_FORMAT_PCM.
End With
 
dscbd.lFlags = DSCBCAPS_DEFAULT
dscbd.lBufferBytes = dscbd.fxFormat.lAvgBytesPerSec
 
Set dscb = dsc.CreateCaptureBuffer (dscbd)