Qt 4.6: QAudioDeviceInfo Class Reference

|  | Home · All Classes · Overviews |

# QAudioDeviceInfo Class Reference
[QtMultimedia module]

The QAudioDeviceInfo class provides an interface to query audio devices and their functionality. More...

     #include <QAudioDeviceInfo>

Inherits QObject.

This class was introduced in Qt 4.6.

- List of all members, including inherited members

## Public Functions

| QAudioDeviceInfo ( const QAudioDeviceId & id, QObject * parent = 0 )
| ~QAudioDeviceInfo ()
QString | deviceName () const
bool | isFormatSupported ( const QAudioFormat & settings ) const
QAudioFormat | nearestFormat ( const QAudioFormat & settings ) const
QAudioFormat | preferredFormat () const
QList<QAudioFormat::Endian> | supportedByteOrders () const
QList<int> | supportedChannels () const
QStringList | supportedCodecs () const
QList<int> | supportedFrequencies () const
QList<int> | supportedSampleSizes () const
QList<QAudioFormat::SampleType> | supportedSampleTypes () const

- 29 public functions inherited from QObject

## Static Public Members

QAudioDeviceId | defaultInputDevice ()
QAudioDeviceId | defaultOutputDevice ()
QList<QAudioDeviceId> | deviceList ( QAudio::Mode mode )

- 5 static public members inherited from QObject

### Additional Inherited Members

- 1 property inherited from QObject
- 1 public slot inherited from QObject
- 1 signal inherited from QObject
- 7 protected functions inherited from QObject

## Detailed Description

The QAudioDeviceInfo class provides an interface to query audio devices and their functionality.

QAudioDeviceInfo lets you query for audio devices--such as sound cards and USB headsets--that are currently available on the system. The audio devices available are dependent on the platform or audio plugins installed.

You can also query each device for the formats it supports. A format in this context is a set consisting of a specific byte order, channel, codec, frequency, sample rate, and sample type. A format is represented by the QAudioFormat class.

The values supported by the the device for each of these parameters can be fetched with supportedByteOrders(), supportedChannels(), supportedCodecs(), supportedFrequencies(), supportedSampleSizes(), and supportedSampleTypes(). The combinations supported are dependent on the platform, audio plugins installed and the audio device capabilities. If you need a specific format, you can check if the device supports it with isFormatSupported(), or fetch a supported format that is as close as possible to the format with nearestFormat().

A QAudioDeviceInfo is constructed with a QAudioDeviceId, which is an identifier for a physical device. It is used by Qt to construct classes that communicate with the device--such as QAudioDeviceInfo, QAudioInput, and QAudioOutput. The static functions defaultInputDevice(), defaultOutputDevice(), and deviceList() let you get a hold of the ids for all available devices. You fetch ids based on whether you will use the device for input or output; this is specified by the QAudio::Mode enum. The QAudioDeviceId returned are only valid for the QAudio::Mode.

For instance:

     foreach(QAudioDeviceId audioId, QAudioDeviceInfo::deviceList(QAudio::AudioOutput)) {
         QAudioDeviceInfo info(audioId);
         qDebug() << "Device name: " << info.deviceName();
     }

In this code sample, we loop through all devices that are able to output sound, i.e., play an audio stream in a supported format. For each device we find, we simply print the deviceName().

See also QAudioOutput, QAudioInput, and QAudioDeviceId.

## Member Function Documentation

### QAudioDeviceInfo::QAudioDeviceInfo ( const QAudioDeviceId & id, QObject * parent = 0 )

Construct a new audio device info and attach it to parent. Using the audio device with the specified id.

### QAudioDeviceInfo::~QAudioDeviceInfo ()

Destroy this audio device info.

### QAudioDeviceId QAudioDeviceInfo::defaultInputDevice () `[static]`

Returns the name of the default input audio device. All platform and audio plugin implementations provide a default audio device to use.

### QAudioDeviceId QAudioDeviceInfo::defaultOutputDevice () `[static]`

Returns the name of the default output audio device. All platform and audio plugin implementations provide a default audio device to use.

### QList<QAudioDeviceId> QAudioDeviceInfo::deviceList ( QAudio::Mode mode ) `[static]`

Returns a list of audio devices that support mode.

### QString QAudioDeviceInfo::deviceName () const

Returns human readable name of audio device.

Device names vary depending on platform/audio plugin being used.

They are a unique string identifiers for the audio device.

eg. default, Intel, U0x46d0x9a4

### bool QAudioDeviceInfo::isFormatSupported ( const QAudioFormat & settings ) const

Returns true if settings are supported by the audio device of this QAudioDeviceInfo.

### QAudioFormat QAudioDeviceInfo::nearestFormat ( const QAudioFormat & settings ) const

Returns closest QAudioFormat to settings that system audio supports.

These settings are provided by the platform/audio plugin being used.

They also are dependent on the QAudio::Mode being used.

### QAudioFormat QAudioDeviceInfo::preferredFormat () const

Returns QAudioFormat of default settings.

These settings are provided by the platform/audio plugin being used.

They also are dependent on the QAudio::Mode being used.

A typical audio system would provide something like:

- Input settings: 8000Hz mono 8 bit.
- Output settings: 44100Hz stereo 16 bit little endian.

### QList<QAudioFormat::Endian> QAudioDeviceInfo::supportedByteOrders () const

Returns a list of supported byte orders.

### QList<int> QAudioDeviceInfo::supportedChannels () const

Returns a list of supported channels.

### QStringList QAudioDeviceInfo::supportedCodecs () const

Returns a list of supported codecs.

All platform and plugin implementations should provide support for:

"audio/pcm" - Linear PCM

For writing plugins to support additional codecs refer to:

http://www.iana.org/assignments/media-types/audio/

### QList<int> QAudioDeviceInfo::supportedFrequencies () const

Returns a list of supported frequencies.

### QList<int> QAudioDeviceInfo::supportedSampleSizes () const

Returns a list of supported sample sizes.

### QList<QAudioFormat::SampleType> QAudioDeviceInfo::supportedSampleTypes () const

Returns a list of supported sample types.