QAudioDevice 类
QAudioDevice 类提供有关音频设备及其功能的信息。更多...
| 头文件 | #include <QAudioDevice> | 
| CMake | find_package(Qt6 REQUIRED COMPONENTS Multimedia) target_link_libraries(mytarget PRIVATE Qt6::Multimedia) | 
| qmake | QT += multimedia | 
公共类型
| 枚举 | 模式 { Null, Input, Output } | 
属性
公共函数
| QAudioDevice() | |
| QAudioDevice(const QAudioDevice &other) | |
| QAudioDevice(QAudioDevice &&other) | |
| ~QAudioDevice() | |
| QAudioFormat::ChannelConfig | channelConfiguration() const | 
| QString | 描述() const | 
| QByteArray | id() const | 
| bool | 是否默认() const | 
| bool | isFormatSupported(const QAudioFormat &settings) const | 
| bool | isNull() const | 
| int | maximumChannelCount() const | 
| int | maximumSampleRate() const | 
| int | minimumChannelCount() const | 
| int | minimumSampleRate() const | 
| QAudioDevice::Mode | 模式() const | 
| QAudioFormat | preferredFormat() const | 
| QList<QAudioFormat::SampleFormat> | supportedSampleFormats() const | 
| void | swap(QAudioDevice &other) | 
| bool | operator!=(const QAudioDevice &other) const | 
| QAudioDevice & | operator=(QAudioDevice &&other) | 
| QAudioDevice & | operator=(const QAudioDevice &other) | 
| bool | operator==(const QAudioDevice &other) const | 
详细说明
QAudioDevice 描述了系统中的音频设备,无论是输入还是回放。
Qt 使用 QAudioDevice 构建与设备通信的类,例如 QAudioSource 和 QAudioSink。它还可以用于确定在捕获会话或媒体播放期间使用的输入或输出设备。
您还可以查询每个设备支持的格式。在此上下文中,格式是一个包含通道数、采样率和采样类型的集合。格式由 QAudioFormat 类表示。
设备支持这些参数的值可以通过 minimumChannelCount()、maximumChannelCount()、minimumSampleRate()、maximumSampleRate() 和 supportedSampleFormats 获取。支持的组合取决于音频设备的特性。如果您需要特定格式,可以检查设备是否支持它,使用 isFormatSupported。例如
{
    sourceFile.setFileName("/tmp/test.raw");
    sourceFile.open(QIODevice::ReadOnly);
    QAudioFormat format;
    // Set up the format, eg.
    format.setSampleRate(8000);
    format.setChannelCount(1);
    format.setSampleFormat(QAudioFormat::UInt8);
    QAudioDevice info(QMediaDevices::defaultAudioOutput());
    if (!info.isFormatSupported(format)) {
        qWarning() << "Raw audio format not supported by backend, cannot play audio.";
        return;
    }
    audio = new QAudioSink(format, this);
    connect(audio, QAudioSink::stateChanged, this, &AudioInputExample::handleStateChanged);
    audio->start(&sourceFile);
}可用的设备集可以从 QMediaDevices 类中检索。
例如
const auto devices = QMediaDevices::audioOutputs(); for (const QAudioDevice &device : devices) qDebug() << "Device: " << device.description();
在这个代码示例中,我们遍历所有能够输出声音的设备,即以支持格式播放音频流。对于找到的每个设备,我们简单打印 deviceName()。
另请参阅 QAudioSink、QAudioSource 和 QAudioFormat。
成员类型文档
enum QAudioDevice::Mode
描述此设备的模式。
| 常量 | 值 | 描述 | 
|---|---|---|
| QAudioDevice::Null | 0 | 空设备。 | 
| QAudioDevice::Input | 1 | 输入设备。 | 
| QAudioDevice::Output | 2 | 输出设备。 | 
属性文档
[只读] description : const QString
返回音频设备的人 readable 名称。
使用此字符串向用户显示设备。
访问函数
| QString | description() const | 
[只读] id : const QByteArray
返回音频设备的标识符。
设备名称取决于所使用的平台/音频插件。
它们是音频设备的唯一标识符。
访问函数
| QByteArray | id() const | 
[只读] isDefault : const bool
如果这是默认音频设备,则为 true。
访问函数
| bool | isDefault() const | 
[只读] mode : const Mode
返回此设备是输入设备还是输出设备。
访问函数
| QAudioDevice::Mode | mode() const | 
成员函数文档
QAudioDevice::QAudioDevice()
构造一个空 QAudioDevice 对象。
QAudioDevice::QAudioDevice(const QAudioDevice &other)
从other复制。
[noexcept] QAudioDevice::QAudioDevice(QAudioDevice &&other)
从other移动构造。
[noexcept] QAudioDevice::~QAudioDevice()
销毁此音频设备信息。
QAudioFormat::ChannelConfig QAudioDevice::channelConfiguration() const
返回设备的通道配置。
bool QAudioDevice::isFormatSupported(const QAudioFormat &settings) const
如果提供的settings由本QAudioDevice描述的音频设备支持,则返回true。
bool QAudioDevice::isNull() const
返回此QAudioDevice对象是否包含有效的设备定义。
int QAudioDevice::maximumChannelCount() const
返回支持的最大通道数。
通常为单声道音频1,立体声音频为2。
int QAudioDevice::maximumSampleRate() const
返回最大支持的采样率(赫兹)。
int QAudioDevice::minimumChannelCount() const
返回支持的最小通道数。
通常为单声道音频1,立体声音频为2。
int QAudioDevice::minimumSampleRate() const
返回最小支持的采样率(赫兹)。
QAudioFormat QAudioDevice::preferredFormat() const
返回此设备的默认音频格式设置。
这些设置由使用的平台/音频插件提供。
它们也取决于使用的QtAudio::Mode。
典型的音频系统会提供类似以下的内容
- 输入设置:48000Hz 单声道 16位。
- 输出设置:48000Hz 立体声 16位。
QList<QAudioFormat::SampleFormat> QAudioDevice::supportedSampleFormats() const
返回支持的样本类型列表。
[noexcept] void QAudioDevice::swap(QAudioDevice &other)
与other交换音频设备。
bool QAudioDevice::operator!=(const QAudioDevice &other) const
如果此QAudioDevice类表示的音频设备与other不同,则返回true。
[noexcept] QAudioDevice &QAudioDevice::operator=(QAudioDevice &&other)
将other移动到本QAudioDevice对象中。
QAudioDevice &QAudioDevice::operator=(const QAudioDevice &other)
将QAudioDevice对象设置为等于other。
bool QAudioDevice::operator==(const QAudioDevice &other) const
如果此QAudioDevice类表示与other相同的音频设备,则返回true。
© 2024 The Qt Company Ltd。本文件中的文档贡献归其各自所有者所有。本文件提供的文档根据由自由软件基金会发布的GNU自由文档许可证版本1.3的条款进行许可。Qt及其相关标志是芬兰The Qt Company Ltd.以及世界各地的商标。所有其他商标均为其各自所有者的财产。