QAudioDeviceInfo 類

QAudioDeviceInfo 類提供查詢音頻設備及其功能的接口。 更多...

頭: #include <QAudioDeviceInfo>
qmake: QT += multimedia

公共函數

QAudioDeviceInfo (const QAudioDeviceInfo & other )
QAudioDeviceInfo ()
QAudioDeviceInfo & operator= (const QAudioDeviceInfo & other )
~QAudioDeviceInfo ()
QString deviceName () const
bool isFormatSupported (const QAudioFormat & settings ) const
bool isNull () const
QAudioFormat nearestFormat (const QAudioFormat & settings ) const
QAudioFormat preferredFormat () const
QString realm () const
QList<QAudioFormat::Endian> supportedByteOrders () const
QList<int> supportedChannelCounts () const
QStringList supportedCodecs () const
QList<int> supportedSampleRates () const
QList<int> supportedSampleSizes () const
QList<QAudioFormat::SampleType> supportedSampleTypes () const
bool operator!= (const QAudioDeviceInfo & other ) const
bool operator== (const QAudioDeviceInfo & other ) const

靜態公共成員

QList<QAudioDeviceInfo> availableDevices (QAudio::Mode mode )
QAudioDeviceInfo defaultInputDevice ()
QAudioDeviceInfo defaultOutputDevice ()

詳細描述

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.

A QAudioDeviceInfo is used by Qt to construct classes that communicate with the device--such as QAudioInput ,和 QAudioOutput .

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 類。

The values supported by the device for each of these parameters can be fetched with supportedByteOrders (), supportedChannelCounts (), supportedCodecs (), supportedSampleRates (), supportedSampleSizes (),和 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 (). For instance:

QAudioFormat format;
format.setSampleRate(44100);
// ... other format parameters
format.setSampleType(QAudioFormat::SignedInt);
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
if (!info.isFormatSupported(format))
    format = info.nearestFormat(format);
					

靜態函數 defaultInputDevice (), defaultOutputDevice (),和 availableDevices () let you get a list of all available devices. Devices are fetched according to the value of mode this is specified by the QAudio ::Mode enum. The QAudioDeviceInfo returned are only valid for the QAudio ::Mode.

例如:

const auto deviceInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
for (const QAudioDeviceInfo &deviceInfo : deviceInfos)
    qDebug() << "Device name: " << deviceInfo.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 ().

另請參閱 QAudioOutput and QAudioInput .

成員函數文檔編製

QAudioDeviceInfo:: QAudioDeviceInfo (const QAudioDeviceInfo & other )

構造副本為 other .

QAudioDeviceInfo:: QAudioDeviceInfo ()

構造空的 QAudioDeviceInfo 對象。

QAudioDeviceInfo &QAudioDeviceInfo:: operator= (const QAudioDeviceInfo & other )

設置 QAudioDeviceInfo 對象等於 other .

QAudioDeviceInfo:: ~QAudioDeviceInfo ()

銷毀此音頻設備信息。

[static] QList < QAudioDeviceInfo > QAudioDeviceInfo:: availableDevices ( QAudio::Mode mode )

返迴的音頻設備列錶支持 mode .

[static] QAudioDeviceInfo QAudioDeviceInfo:: defaultInputDevice ()

返迴默認輸入音頻設備的信息。所有平颱和音頻插件實現均提供要使用的默認音頻設備。

[static] QAudioDeviceInfo QAudioDeviceInfo:: defaultOutputDevice ()

返迴默認輸齣音頻設備的信息。所有平颱和音頻插件實現均提供要使用的默認音頻設備。

QString QAudioDeviceInfo:: deviceName () const

返迴音頻設備的人類可讀名稱。

設備名稱從屬所使用的平颱/音頻插件。

它們是音頻設備的唯一字符串標識符。

如 default, Intel, U0x46d0x9a4

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

返迴 true 若供給 settings are supported by the audio device described by this QAudioDeviceInfo .

bool QAudioDeviceInfo:: isNull () const

返迴是否此 QAudioDeviceInfo object holds a valid device definition.

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

Returns the closest QAudioFormat to the supplied settings that the system supports.

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

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

QAudioFormat QAudioDeviceInfo:: preferredFormat () const

Returns the default audio format settings for this device.

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

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

A typical audio system would provide something like:

  • 輸入設置:8000Hz 單聲道 8 位。
  • Output settings: 44100Hz stereo 16 bit little endian.

QString QAudioDeviceInfo:: realm () const

Returns the key that represents the audio plugin.

該函數在 Qt 5.14 引入。

另請參閱 QAudioSystemPlugin .

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

返迴支持的字節序列錶。

QList < int > QAudioDeviceInfo:: supportedChannelCounts () const

Returns a list of supported channel counts.

This is typically 1 for mono sound, or 2 for stereo sound.

QStringList QAudioDeviceInfo:: supportedCodecs () const

返迴支持的編解碼器列錶。

所有平颱和插件實現都應提供支持:

audio/pcm - 綫性 PCM

編寫插件以支持額外編解碼器,參考:

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

QList < int > QAudioDeviceInfo:: supportedSampleRates () const

返迴支持的采樣率的列錶 (以赫茲為單位)。

QList < int > QAudioDeviceInfo:: supportedSampleSizes () const

返迴支持的采樣大小的列錶 (以位為單位)。

通常這將包括 8 位和 16 位的采樣大小。

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

Returns a list of supported sample types.

bool QAudioDeviceInfo:: operator!= (const QAudioDeviceInfo & other ) const

返迴 true,若此 QAudioDeviceInfo class represents a different audio device than other

bool QAudioDeviceInfo:: operator== (const QAudioDeviceInfo & other ) const

返迴 true,若此 QAudioDeviceInfo class represents the same audio device as other .