QAudioDevice 类

QAudioDevice 类提供音频设备及其功能的有关信息。 更多...

头: #include <QAudioDevice>
CMake: find_package(Qt6 COMPONENTS Multimedia REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia

公共类型

enum Mode { Null, Input, Output }

公共函数

  QAudioDevice (QAudioDevice && other )
  QAudioDevice (const QAudioDevice & other )
  QAudioDevice ()
QAudioDevice & operator= (const QAudioDevice & other )
QAudioDevice & operator= (QAudioDevice && other )
  ~QAudioDevice ()
QString description () const
QByteArray id () const
bool isDefault () const
bool isFormatSupported (const QAudioFormat & settings ) const
bool isNull () const
int maximumChannelCount () const
int maximumSampleRate () const
int minimumChannelCount () const
int minimumSampleRate () const
QAudioDevice::Mode mode () const
QAudioFormat preferredFormat () const
QList<QAudioFormat::SampleFormat> supportedSampleFormats () const
bool operator!= (const QAudioDevice & other ) const
bool operator== (const QAudioDevice & other ) const

详细描述

QAudioDevice describes an audio device available in the system, either for input or for playback.

A QAudioDevice is used by Qt to construct classes that communicate with the device -- such as QAudioSource ,和 QAudioSink . It is also used to determine the input or output device to use in a capture session or during media playback.

You can also query each device for the formats it supports. A format in this context is a set consisting of a channel count, 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 minimumChannelCount (), maximumChannelCount (), minimumSampleRate (), maximumSampleRate () 和 supportedSampleFormats (). The combinations supported are dependent on 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.setSampleFormat(QAudioFormat::Int16);
					

The set of available devices can be retrieved from the QMediaDevices 类。

例如:

const auto deviceInfos = QMediaDevices::availableDevices(QAudioDevice::Output);
for (const QAudioDevice &deviceInfo : deviceInfos)
    qDebug() << "Device: " << deviceInfo.description();
					

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().

另请参阅 QAudioSink and QAudioSource .

成员类型文档编制

enum QAudioDevice:: Mode

Describes the mode of a QAudioDevice

常量 描述
QAudioDevice::Null 0 A null device.
QAudioDevice::Input 1 An input device.
QAudioDevice::Output 2 An output device.

成员函数文档编制

QAudioDevice:: QAudioDevice ( QAudioDevice && other )

Move constructs from other .

QAudioDevice:: QAudioDevice (const QAudioDevice & other )

构造副本为 other .

QAudioDevice:: QAudioDevice ()

Constructs a null QAudioDevice object.

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

设置 QAudioDevice 对象等于 other .

QAudioDevice &QAudioDevice:: operator= ( QAudioDevice && other )

移动 other 到此 QAudioDevice 对象。

QAudioDevice:: ~QAudioDevice ()

销毁此音频设备信息。

QString QAudioDevice:: description () const

Returns a human readable name of the audio device.

Use this string to present the device to the user.

注意: Getter function for property description.

QByteArray QAudioDevice:: id () const

Returns an identifier for the audio device.

设备名称从属所使用的平台/音频插件。

They are a unique identifier for the audio device.

注意: Getter function for property id.

bool QAudioDevice:: isDefault () const

Returns true if this is the default audio device.

注意: Getter function for property isDefault.

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

返回 true 若供给 settings are supported by the audio device described by this QAudioDevice .

bool QAudioDevice:: isNull () const

Returns whether this QAudioDevice object holds a valid device definition.

int QAudioDevice:: maximumChannelCount () const

Returns the maximum number of supported channel counts.

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

int QAudioDevice:: maximumSampleRate () const

Returns the maximum supported sample rate (in Hertz).

int QAudioDevice:: minimumChannelCount () const

Returns the minimum number of supported channel counts.

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

int QAudioDevice:: minimumSampleRate () const

Returns the minimum supported sample rate (in Hertz).

QAudioDevice::Mode QAudioDevice:: mode () const

returns whether this device is an input or output device.

注意: Getter function for property mode.

QAudioFormat QAudioDevice:: 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:

  • Input settings: 48000Hz mono 16 bit.
  • Output settings: 48000Hz stereo 16 bit.

QList < QAudioFormat::SampleFormat > QAudioDevice:: supportedSampleFormats () const

Returns a list of supported sample types.

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

返回 true,若此 QAudioDevice class represents a different audio device than other

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

返回 true,若此 QAudioDevice class represents the same audio device as other .