Platform SDK: DirectX

Using the Capture Buffer

[C++]

Capturing a sound consists of the following steps:

  1. Start the buffer by calling the IDirectSoundCaptureBuffer::Start method. Audio data from the input device begins filling the buffer from the beginning.
  2. Wait until the desired amount of data is available. For one method of determining when the capture position reaches a certain point, see Capture Buffer Notification.
  3. When sufficient data is available, lock a portion of the capture buffer by calling the IDirectSoundCaptureBuffer::Lock method.

    To make sure you are not attempting to lock a portion of memory that is about to be used for capture, you can first obtain the current read position by calling IDirectSoundCaptureBuffer::GetCurrentPosition. For an explanation of the read position, see Capture Buffer Information.

    As parameters to the Lock method, you pass the size and offset of the block of memory you want to read. The method returns a pointer to the address where the memory block begins, and the size of the block. If the block wraps around from the end of the buffer to the beginning, two pointers are returned, one for each section of the block. The second pointer is NULL if the locked portion of the buffer does not wrap around.

  4. Copy the data from the buffer, using the addresses and block sizes returned by the Lock method.
  5. Unlock the buffer with the IDirectSoundCaptureBuffer::Unlock method.
  6. Repeat steps 2 to 5 until you are ready to stop capturing data. Then call the IDirectSoundCaptureBuffer::Stop method.

Normally the buffer stops capturing automatically when the capture position reaches the end of the buffer. However, if the DSCBSTART_LOOPING flag was set in the dwFlags parameter to the IDirectSoundCaptureBuffer::Start method, the capture will continue until the application calls the IDirectSoundCaptureBuffer::Stop method.

[Visual Basic]

Capturing a sound consists of the following steps.

  1. Start the buffer by calling the DirectSoundCaptureBuffer.Start method. Audio data from the input device begins filling the buffer from the beginning.
  2. Wait until the desired amount of data is available. For one method of determining when the capture position reaches a certain point, see Capture Buffer Notification.
  3. When sufficient data is available, read a portion of the capture buffer by calling the DirectSoundCaptureBuffer.ReadBuffer method.

    To make sure you are not attempting to read a portion of memory that is about to be used for capture, you can obtain the current read position by calling DirectSoundCaptureBuffer.GetCurrentPosition. For an explanation of the read position, see Capture Buffer Information.

  4. Repeat steps 2 and 3 until you are ready to stop capturing data. Then call the DirectSoundCaptureBuffer.Stop method.

By default the buffer stops capturing automatically when the capture position reaches the end of the buffer. However, if the DSCBSTART_LOOPING flag is set in the flags parameter to the DirectSoundCaptureBuffer.Start method, the capture continues until the application calls the DirectSoundCaptureBuffer.Stop method.