QAudioDevice Class
QAudioDeviceクラスは、オーディオ・デバイスとその機能についての情報を提供します。詳細...
ヘッダー | #include <QAudioDevice> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Multimedia) target_link_libraries(mytarget PRIVATE Qt6::Multimedia) |
qmake: | QT += multimedia |
パブリックタイプ
enum | Mode { Null, Input, Output } |
プロパティ
- description : const QString
- id : const QByteArray
- isDefault : const bool
- mode : const Mode
公共機能
QAudioDevice() | |
QAudioDevice(const QAudioDevice &other) | |
QAudioDevice(QAudioDevice &&other) | |
~QAudioDevice() | |
QAudioFormat::ChannelConfig | channelConfiguration() const |
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 |
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 は、入力または再生のためにシステムで利用可能なオーディオデバイスを記述します。
QAudioDevice は、QAudioSource やQAudioSink のような、デバイスと通信するクラスを構築するために Qt によって使用されます。 また、キャプチャセッションやメディア再生時に使用する入力デバイスや出力デバイスを決定するためにも使用されます。
QAudioDeviceインスタンスは、対応する物理デバイスが切断されたり、その設定が変更されたりしても、その寿命を通じてそのプロパティを保持します。更新されたプロパティを追跡するには、関連するシグナルが発生したときに、QMediaDevices から QAudioDevice の新しいインスタンスをロードする必要があります。
また、各デバイスがサポートしているフォーマットを問い合わせることもできます。ここでいうフォーマットとは、チャンネル数、サンプル・レート、サンプル・タイプからなる集合のことです。フォーマットはQAudioFormat クラスで表されます。
minimumChannelCount(),maximumChannelCount(),minimumSampleRate(),maximumSampleRate(),supportedSampleFormats() で、デバイスがサポートする各パラメータの値を取得できる。サポートされる組み合わせは、オーディオデバイスの機能に依存します。特定のフォーマットが必要な場合は、isFormatSupported() でデバイスがサポートしているかどうかを確認できます。例えば
{ sourceFile.setFileName("/tmp/test.raw"); sourceFile.open(QIODevice::ReadOnly); QAudioFormatformat;// フォーマットを設定する。例えば、format.setSampleRate(8000); format.setChannelCount(1); format.setSampleFormat(QAudioFormat::UInt8); QAudioDeviceinfo(QMediaDevices::defaultAudioOutput());if(!info.isFormatSupported(format)) { {. qWarning() << "Raw audio format not supported by backend, cannot play audio."; return; } audio= newQAudioSink(format, this); connect(audio、 QAudioSink::stateChanged, this, &AudioInputExample::handleStateChanged); audio->start(&sourceFile); }
利用可能なデバイスのセットは、QMediaDevices クラスから取得できます。
例えば
const autodevices=QMediaDevices::audioOutputs();for(constQAudioDeviceデバイス) qDebug() << "Device: " << device.description();
このコードサンプルでは、サウンドを出力できる、つまりサポートされているフォーマットでオーディオストリームを再生できる、すべてのデバイスをループします。見つかった各デバイスについて、単純に deviceName() を表示します。
QAudioSink 、QAudioSource 、QAudioFormatも参照 。
メンバー型ドキュメント
enum QAudioDevice::Mode
このデバイスのモードを記述する。
定数 | 値 | 説明 |
---|---|---|
QAudioDevice::Null | 0 | ヌル・デバイス |
QAudioDevice::Input | 1 | 入力デバイス |
QAudioDevice::Output | 2 | 出力デバイス |
プロパティの説明
[read-only]
description : const QString
オーディオデバイスの可読形式の名前を返します。
この文字列を使用して、ユーザーにデバイスを提示します。
関数にアクセスします:
QString | description() const |
[read-only]
id : const QByteArray
オーディオデバイスの識別子を返します。
デバイス名は、使用するプラットフォーム/オーディオプラグインによって異なります。
オーディオデバイスの一意な識別子です。
アクセス関数
QByteArray | id() const |
[read-only]
isDefault : const bool
このデバイスがデフォルトのオーディオデバイスである場合に true を返します。
関数にアクセスします:
bool | isDefault() const |
[read-only]
mode : const Mode
このデバイスが入力デバイスであるか出力デバイスであるかを返します。
アクセス関数
QAudioDevice::Mode | mode() const |
メンバー関数ドキュメント
QAudioDevice::QAudioDevice()
NULLの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 クラスが、次のクラスとは異なるオーディオ・デバイスを表す場合、true を返します。other
[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 を返す。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.