Platform SDK: DirectX

Step 2: Set the Capture Format

[Visual Basic]

The information in this topic pertains only to applications written in C and C++. See DirectSound Visual Basic Tutorials.

[C++]

After creating DirectSoundCapture, you should choose a wave format that is supported by the user's device. One way to do this is to start with the highest format and attempt to create a capture buffer in each format until the creation method succeeds. (For an example of how to step through the various formats, see Fdaudio.cpp in the Fdfilter sample program.) In this tutorial you simply check the capabilities of the device to see whether the default 16-bit format (defined in the declaration of the WAVEFORMATEX structure) is supported; if it is not, you select an 8-bit format that is supported by all devices.

The following code is within the InitDSoundCapture function:

    DSCCAPS dsccaps;
 
    dsccaps.dwSize = sizeof(DSCCAPS);
    if FAILED(IDirectSoundCapture_GetCaps(lpdsc, &dsccaps))
        return FALSE;
 
    if ((dsccaps.dwFormats & WAVE_FORMAT_2M16) == 0)
    {
        wfx.nSamplesPerSec = 11025;
        wfx.nAvgBytesPerSec = 11025;
        wfx.nBlockAlign = 1;
        wfx.wBitsPerSample = 8; 
    }
 

Remember that if you are also using DirectSound playback in your application, you must select a capture format that is compatible with the format of the primary buffer. For more information, see the next step Step 3: Create the Capture Buffer