Querying Audio I/O Devices

The following table shows functions that retrieve the number of audio devices on a Windows CE–based device.

Function
Description
waveInGetNumDevs Retrieves the number of waveform audio input devices present in a system
waveOutGetNumDevs Retrieves the number of waveform audio output devices present in a system

After you determine how many devices are present in a system, you can query the capabilities of each device. The following table shows the functions and structures that retrieve this information.

Function
Description
Returned structure
waveInGetDevCaps Retrieves the capabilities of a specified waveform audio input device WAVEINCAPS
waveOutGetDevCaps Retrieves the capabilities of a specified waveform audio output device WAVEOUTCAPS

The waveInGetDevCaps and waveOutGetDevCaps fill the dwFormats member of the WAVEINCAPS and WAVEOUTCAPS structures with flags describing the standard supported sound formats for a specified audio I/O device. Waveform audio I/O devices also support nonstandard features. You can also use the waveInOpen or the waveOutOpen function to determine if a waveform audio I/O device supports a specific format.

    To determine if a waveform audio I/O device supports a standard or nonstandard format

  1. Specify the format you want to query in the WAVEFORMATEX structure.
  2. Pass this structure into waveInOpen or waveOutOpen with the pwfx parameter.
  3. Call waveInOpen or waveOutOpen with the WAVE_FORMAT_QUERY flag set.

    This call does not open the device. Instead, the function returns a message declaring whether or not the audio device supports the specified format.

Note While WAVEFORMATEX supersedes PCMWAVEFORMAT and WAVEFORMAT, Windows CE maintains both structures for backward compatibility.

The following code example shows how to use the waveOutOpen function with the WAVE_FORMAT_QUERY flag to determine if a waveform audio device supports a specified format.

MMRESULT IsFormatSupported (LPWAVEFORMATEX pwfx, UINT uDeviceID) 
{ 
    return waveOutOpen (NULL,               // ptr can be NULL for query
                        uDeviceID,          // The device identifier 
                        pwfx,               // Defines the requested 
                                            // format 
                        NULL,               // No callback 
                        NULL,               // No instance data 
                        WAVE_FORMAT_QUERY); // Query only, do not open
}

The preceding example determines if the specified waveform-audio output device supports a specified waveform-audio format. It returns MMSYSERROR_NOERROR if the device supports the format, WAVERROR_BADFORMAT if the device does not support the format, and one of the other MMSYSERROR codes for other errors.

This technique for determining nonstandard format support also applies to waveform audio input devices. The only difference is that the function will use waveInOpen instead of waveOutOpen to query for format support.

To determine if any waveform audio I/O devices on a system support a particular waveform audio data format, use the technique illustrated in the previous example. However, you must specify the WAVE_MAPPER constant in the uDeviceID parameter.