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は、QtがQAudioSource やQAudioSink といった、デバイスと通信するクラスを構築するために使用されます。また、キャプチャセッションやメディア再生中に使用する入力デバイスまたは出力デバイスを決定するためにも使用されます。
QAudioDeviceのインスタンスは、対応する物理デバイスが切断されたり、その設定が変更されたりした場合でも、そのライフタイムを通じてプロパティを維持します。更新されたプロパティを追跡するには、関連するシグナルが発火した際に、QMediaDevices からQAudioDeviceの新しいインスタンスを読み込む必要があります。
また、各デバイスがサポートするフォーマットを照会することもできます。この文脈におけるフォーマットとは、チャンネル数、サンプルレート、およびサンプルタイプからなるセットのことです。フォーマットはQAudioFormat クラスによって表されます。
これらの各パラメータについて、デバイスがサポートする値は、minimumChannelCount()、maximumChannelCount()、minimumSampleRate()、maximumSampleRate()、およびsupportedSampleFormats() を使用して取得できます。サポートされる組み合わせは、オーディオデバイスの機能によって異なります。特定のフォーマットが必要な場合は、isFormatSupported() を使用して、デバイスがそれをサポートしているかどうかを確認できます。例えば:
{
sourceFile.setFileName("/tmp/test.raw");
sourceFile.open(QIODevice::ReadOnly);
QAudioFormat format;
// フォーマットを設定します(例):
format.setSampleRate(44100);
format.setChannelCount(1);
format.setSampleFormat(QAudioFormat::Int16);
QAudioDevice info(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&device: devices)
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 のコピーを作成します。
[constexpr noexcept default] QAudioDevice::QAudioDevice(QAudioDevice &&other)
other からコンストラクトを移動しました。
[noexcept] QAudioDevice::~QAudioDevice()
このオーディオデバイスの情報を削除してください。
QAudioFormat::ChannelConfig QAudioDevice::channelConfiguration() const
デバイスのチャンネル設定を取得します。
bool QAudioDevice::isFormatSupported(const QAudioFormat &settings) const
このQAudioDevice で指定されたオーディオデバイスによって、指定されたsettings がサポートされている場合、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を返します。
© 2026 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.