Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QAudioDevice Class Reference

The QAudioDevice class provides an information about audio devices and their functionality. More...

#include <qaudiodevice.h>

+ Inheritance diagram for QAudioDevice:
+ Collaboration diagram for QAudioDevice:

Public Types

enum  Mode { Null , Input , Output }
 Describes the mode of this device. More...
 

Public Member Functions

 QAudioDevice ()
 Describes an audio device.
 
 QAudioDevice (const QAudioDevice &other)
 Constructs a copy of other.
 
 ~QAudioDevice ()
 Destroy this audio device info.
 
 QAudioDevice (QAudioDevice &&other) noexcept=default
 Move constructs from other.
 
void swap (QAudioDevice &other) noexcept
 Swaps the audio device with the other.
 
QAudioDeviceoperator= (const QAudioDevice &other)
 Sets the QAudioDevice object to be equal to other.
 
bool operator== (const QAudioDevice &other) const
 Returns true if this QAudioDevice class represents the same audio device as other.
 
bool operator!= (const QAudioDevice &other) const
 Returns true if this QAudioDevice class represents a different audio device than other.
 
bool isNull () const
 Returns whether this QAudioDevice object holds a valid device definition.
 
QByteArray id () const
 
QString description () const
 
bool isDefault () const
 
QAudioDevice::Mode mode () const
 
bool isFormatSupported (const QAudioFormat &format) const
 Returns true if the supplied settings are supported by the audio device described by this QAudioDevice.
 
QAudioFormat preferredFormat () const
 Returns the default audio format settings for this device.
 
int minimumSampleRate () const
 Returns the minimum supported sample rate (in Hertz).
 
int maximumSampleRate () const
 Returns the maximum supported sample rate (in Hertz).
 
int minimumChannelCount () const
 Returns the minimum number of supported channel counts.
 
int maximumChannelCount () const
 Returns the maximum number of supported channel counts.
 
QList< QAudioFormat::SampleFormatsupportedSampleFormats () const
 Returns a list of supported sample types.
 
QAudioFormat::ChannelConfig channelConfiguration () const
 Returns the channel configuration of the device.
 
const QAudioDevicePrivatehandle () const
 

Properties

QByteArray id
 \qmlproperty string QtMultimedia::audioDevice::id
 
QString description
 \qmlproperty string QtMultimedia::audioDevice::description
 
bool isDefault
 \qmlproperty bool QtMultimedia::audioDevice::isDefault
 
Mode mode
 \qmlproperty enumeration QtMultimedia::audioDevice::mode
 

Friends

class QAudioDevicePrivate
 

Detailed Description

The QAudioDevice class provides an information about audio devices and their functionality.

\inmodule QtMultimedia

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, and 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 class.

The values supported by the device for each of these parameters can be fetched with minimumChannelCount(), maximumChannelCount(), minimumSampleRate(), maximumSampleRate() and 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(). For instance:

The set of available devices can be retrieved from the QMediaDevices class.

For instance:

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

See also
QAudioSink, QAudioSource, QAudioFormat

Definition at line 24 of file qaudiodevice.h.

Member Enumeration Documentation

◆ Mode

Describes the mode of this device.

\value Null A null device. \value Input An input device. \value Output An output device.

Enumerator
Null 
Input 
Output 

Definition at line 32 of file qaudiodevice.h.

Constructor & Destructor Documentation

◆ QAudioDevice() [1/3]

QAudioDevice::QAudioDevice ( )
default

Describes an audio device.

\qmlvaluetype audioDevice
\inqmlmodule QtMultimedia
\since 6.2

! \instantiates QAudioDevice

The audioDevice value type describes the properties of an audio device that is connected to the system.

The list of audio input or output devices can be queried from the \l{MediaDevices} type. To select a certain audio device for input or output set it as the device on \l{AudioInput} or \l{AudioOutput}.

\qml MediaPlayer { audioOutput: AudioOutput { device: mediaDevices.defaultAudioOutput } } MediaDevices { id: mediaDevices } \endqml

Constructs a null QAudioDevice object.

◆ QAudioDevice() [2/3]

QAudioDevice::QAudioDevice ( const QAudioDevice & other)
default

Constructs a copy of other.

◆ ~QAudioDevice()

QAudioDevice::~QAudioDevice ( )
default

Destroy this audio device info.

◆ QAudioDevice() [3/3]

QAudioDevice::QAudioDevice ( QAudioDevice && other)
defaultnoexcept

Move constructs from other.

Member Function Documentation

◆ channelConfiguration()

QAudioFormat::ChannelConfig QAudioDevice::channelConfiguration ( ) const

Returns the channel configuration of the device.

Definition at line 300 of file qaudiodevice.cpp.

References QAudioFormat::ChannelConfigUnknown, QAudioDevicePrivate::channelConfiguration, and isNull().

Referenced by QAudioOutputStream::startOutput(), and QFFmpeg::AudioRenderer::updateOutput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ description()

QString QAudioDevice::description ( ) const

Definition at line 195 of file qaudiodevice.cpp.

References QAudioDevicePrivate::description, and isNull().

+ Here is the call graph for this function:

◆ handle()

QAudioDevicePrivate QAudioDevice::handle ( ) const
inline

Definition at line 71 of file qaudiodevice.h.

References d.

Referenced by QWindowsMediaDevices::createAudioSink(), QWindowsMediaDevices::createAudioSource(), QGstreamerAudioInput::setAudioDevice(), and QGstreamerAudioOutput::setAudioDevice().

+ Here is the caller graph for this function:

◆ id()

QByteArray QAudioDevice::id ( ) const

Definition at line 175 of file qaudiodevice.cpp.

References QAudioDevicePrivate::id, isNull(), and QByteArray().

+ Here is the call graph for this function:

◆ isDefault()

bool QAudioDevice::isDefault ( ) const

Definition at line 211 of file qaudiodevice.cpp.

References QAudioDevicePrivate::isDefault.

◆ isFormatSupported()

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

Returns true if the supplied settings are supported by the audio device described by this QAudioDevice.

Definition at line 220 of file qaudiodevice.cpp.

References QListSpecialMethodsBase< T >::contains(), isNull(), QAudioDevicePrivate::maximumChannelCount, QAudioDevicePrivate::maximumSampleRate, QAudioDevicePrivate::minimumChannelCount, QAudioDevicePrivate::minimumSampleRate, settings, and QAudioDevicePrivate::supportedSampleFormats.

Referenced by QDarwinAudioSink::start(), QDarwinAudioSource::start(), QDarwinAudioSink::start(), and QDarwinAudioSource::start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isNull()

bool QAudioDevice::isNull ( ) const

Returns whether this QAudioDevice object holds a valid device definition.

Definition at line 151 of file qaudiodevice.cpp.

Referenced by channelConfiguration(), description(), id(), isFormatSupported(), maximumChannelCount(), maximumSampleRate(), minimumChannelCount(), minimumSampleRate(), preferredFormat(), QSoundEffectPrivate::sampleReady(), QGstreamerAudioInput::setAudioDevice(), and supportedSampleFormats().

+ Here is the caller graph for this function:

◆ maximumChannelCount()

int QAudioDevice::maximumChannelCount ( ) const

Returns the maximum number of supported channel counts.

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

Definition at line 284 of file qaudiodevice.cpp.

References isNull(), and QAudioDevicePrivate::maximumChannelCount.

+ Here is the call graph for this function:

◆ maximumSampleRate()

int QAudioDevice::maximumSampleRate ( ) const

Returns the maximum supported sample rate (in Hertz).

Definition at line 264 of file qaudiodevice.cpp.

References isNull(), and QAudioDevicePrivate::maximumSampleRate.

+ Here is the call graph for this function:

◆ minimumChannelCount()

int QAudioDevice::minimumChannelCount ( ) const

Returns the minimum number of supported channel counts.

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

Definition at line 274 of file qaudiodevice.cpp.

References isNull(), and QAudioDevicePrivate::minimumChannelCount.

+ Here is the call graph for this function:

◆ minimumSampleRate()

int QAudioDevice::minimumSampleRate ( ) const

Returns the minimum supported sample rate (in Hertz).

Definition at line 256 of file qaudiodevice.cpp.

References isNull(), and QAudioDevicePrivate::minimumSampleRate.

+ Here is the call graph for this function:

◆ mode()

QAudioDevice::Mode QAudioDevice::mode ( ) const

Definition at line 346 of file qaudiodevice.cpp.

References QAudioDevicePrivate::mode, and Null.

◆ operator!=()

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

Returns true if this QAudioDevice class represents a different audio device than other.

Definition at line 143 of file qaudiodevice.cpp.

References operator==(), and other().

+ Here is the call graph for this function:

◆ operator=()

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

Sets the QAudioDevice object to be equal to other.

Moves other into this QAudioDevice object.

◆ operator==()

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

Returns true if this QAudioDevice class represents the same audio device as other.

Definition at line 128 of file qaudiodevice.cpp.

References QAudioDevicePrivate::id, QAudioDevicePrivate::isDefault, QAudioDevicePrivate::mode, and other().

Referenced by operator!=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ preferredFormat()

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 \l {QtAudio}Mode being used.

A typical audio system would provide something like: \list

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

Definition at line 248 of file qaudiodevice.cpp.

References isNull(), and QAudioDevicePrivate::preferredFormat.

Referenced by openSlDebugInfo(), and QAudioOutputStream::startOutput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ supportedSampleFormats()

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

Returns a list of supported sample types.

Definition at line 292 of file qaudiodevice.cpp.

References isNull(), and QAudioDevicePrivate::supportedSampleFormats.

+ Here is the call graph for this function:

◆ swap()

void QAudioDevice::swap ( QAudioDevice & other)
inlinenoexcept

Swaps the audio device with the other.

Definition at line 45 of file qaudiodevice.h.

References d, other(), and swap().

Referenced by swap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QAudioDevicePrivate

friend class QAudioDevicePrivate
friend

Definition at line 73 of file qaudiodevice.h.

Property Documentation

◆ description

QAudioDevice::description
read

\qmlproperty string QtMultimedia::audioDevice::description

Holds a human readable name of the audio device.

Use this string to present the device to the user.

Returns a human readable name of the audio device.

Use this string to present the device to the user.

Definition at line 28 of file qaudiodevice.h.

Referenced by QGstreamerAudioInput::setAudioDevice().

◆ id

◆ isDefault

QAudioDevice::isDefault
read

\qmlproperty bool QtMultimedia::audioDevice::isDefault

Is true if this is the default audio device.

Returns true if this is the default audio device.

Definition at line 29 of file qaudiodevice.h.

◆ mode

QAudioDevice::mode
read

\qmlproperty enumeration QtMultimedia::audioDevice::mode

Holds whether this device is an input or output device.

The returned value can be one of the following:

\value audioDevice.Null A null device. \value audioDevice.Input input device. \value audioDevice.Output An output device.

Returns whether this device is an input or output device.

Definition at line 30 of file qaudiodevice.h.

Referenced by QAudioInput::QAudioInput(), and QAudioOutput::QAudioOutput().


The documentation for this class was generated from the following files: