The basic process of DirectSound recording

The basic process of DirectSound recording

1. Enumerate system recording devices, call DirectSoundCaptureEnumerate function;

2. To create a device object, call DirectSoundCaptureCreate8 or DirectSoundFullDuplexCreate8 function to create it directly;

3. To obtain the performance of the recording device, call the IDirectSoundCapture8::GetCaps method;

4. Create a recording buffer, call the IDirectSoundCapture8::CreateCaptureBuffer function;

5. Get recording buffer information, call IDirectSoundCaptureBuffer8::GetCaps method to get the buffer size, GetFormat method to get the audio data format, GetStatus method to return the current status of the recording buffer, GetCurrentPosition method to get the capture pointer and read pointer in the recording buffer Location (the capture pointer is always in front of the read pointer, and the data before the read pointer is safe and can be copied with confidence);

6. Set the notification mechanism for the recording buffer object. One or more notification events can be set in the buffer through the IDirectSoundNotify8::SetNotificationPositions method, and the recording data will be copied from the buffer when these notification points arrive;

7. To start recording, call the IDirectSoundCaptureBuffer8::Start method to start the recording buffer object, and pass a DSCBSTART_LOOPING flag to the dwFlags member of Start, and the recording buffer will continue to work (circularly fill the buffer).

Precautions

1. The sound capture buffer object (DirectSoundCaptureBuffer) is used to generate a buffer to store the data captured from the input device. This buffer is circular, that is, when the input pointer reaches the end of the buffer, it will start from the beginning.

2. During audio capture, the DirectSound notification mechanism (this function is implemented by the IDirectSoundNotify8 interface) can be notified when the captured data reaches a certain position in the buffer or when the captured data stops. The application can read the recorded data or update the interface in these specific locations.

Guess you like

Origin blog.csdn.net/gkzscs/article/details/53995842