Qt 4.8
Public Functions | Static Public Functions | Private Functions | Properties | Friends | List of all members
QAudioDeviceInfo Class Reference

The QAudioDeviceInfo class provides an interface to query audio devices and their functionality. More...

#include <qaudiodeviceinfo.h>

Public Functions

QString deviceName () const
 Returns human readable name of audio device. More...
 
bool isFormatSupported (const QAudioFormat &format) const
 Returns true if settings are supported by the audio device of this QAudioDeviceInfo. More...
 
bool isNull () const
 Returns whether this QAudioDeviceInfo object holds a device definition. More...
 
QAudioFormat nearestFormat (const QAudioFormat &format) const
 Returns closest QAudioFormat to settings that system audio supports. More...
 
QAudioDeviceInfooperator= (const QAudioDeviceInfo &other)
 Sets the QAudioDeviceInfo object to be equal to other. More...
 
QAudioFormat preferredFormat () const
 Returns QAudioFormat of default settings. More...
 
 QAudioDeviceInfo ()
 Constructs an empty QAudioDeviceInfo object. More...
 
 QAudioDeviceInfo (const QAudioDeviceInfo &other)
 Constructs a copy of other. More...
 
QList< QAudioFormat::EndiansupportedByteOrders () const
 Returns a list of supported byte orders. More...
 
QList< int > supportedChannelCounts () const
 Returns a list of supported channel counts. More...
 
QList< int > supportedChannels () const
 Use supportedChannelCount() instead. More...
 
QStringList supportedCodecs () const
 Returns a list of supported codecs. More...
 
QList< int > supportedFrequencies () const
 Use supportedSampleRates() instead. More...
 
QList< int > supportedSampleRates () const
 Returns a list of supported sample rates. More...
 
QList< int > supportedSampleSizes () const
 Returns a list of supported sample sizes. More...
 
QList< QAudioFormat::SampleTypesupportedSampleTypes () const
 Returns a list of supported sample types. More...
 
 ~QAudioDeviceInfo ()
 Destroy this audio device info. More...
 

Static Public Functions

static QList< QAudioDeviceInfoavailableDevices (QAudio::Mode mode)
 Returns a list of audio devices that support mode. More...
 
static QAudioDeviceInfo defaultInputDevice ()
 Returns the name of the default input audio device. More...
 
static QAudioDeviceInfo defaultOutputDevice ()
 Returns the name of the default output audio device. More...
 

Private Functions

QByteArray handle () const
 
QAudio::Mode mode () const
 
 QAudioDeviceInfo (const QString &realm, const QByteArray &handle, QAudio::Mode mode)
 
QString realm () const
 

Properties

QSharedDataPointer< QAudioDeviceInfoPrivated
 

Friends

class QAudioDeviceFactory
 

Detailed Description

The QAudioDeviceInfo class provides an interface to query audio devices and their functionality.

Attention
Module: QtMultimedia
Since
4.6

QAudioDeviceInfo lets you query for audio devices–such as sound cards and USB headsets–that are currently available on the system. The audio devices available are dependent on the platform or audio plugins installed.

You can also query each device for the formats it supports. A format in this context is a set consisting of a specific byte order, channel, codec, frequency, sample rate, and sample type. A format is represented by the QAudioFormat class.

The values supported by the the device for each of these parameters can be fetched with supportedByteOrders(), supportedChannelCounts(), supportedCodecs(), supportedSampleRates(), supportedSampleSizes(), and supportedSampleTypes(). The combinations supported are dependent on the platform, audio plugins installed and 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:

... 8

if (!info.isFormatSupported(format))
format = info.nearestFormat(format);

A QAudioDeviceInfo is used by Qt to construct classes that communicate with the device–such as QAudioInput, and QAudioOutput. The static functions defaultInputDevice(), defaultOutputDevice(), and availableDevices() let you get a list of all available devices. Devices are fetch according to the value of mode this is specified by the QAudio::Mode enum. The QAudioDeviceInfo returned are only valid for the QAudio::Mode.

For instance:

qDebug() << "Device name: " << deviceInfo.deviceName();

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
QAudioOutput, QAudioInput

Definition at line 66 of file qaudiodeviceinfo.h.

Constructors and Destructors

◆ QAudioDeviceInfo() [1/3]

QAudioDeviceInfo::QAudioDeviceInfo ( )

Constructs an empty QAudioDeviceInfo object.

Definition at line 151 of file qaudiodeviceinfo.cpp.

151  :
153 {
154 }
QSharedDataPointer< QAudioDeviceInfoPrivate > d

◆ QAudioDeviceInfo() [2/3]

QAudioDeviceInfo::QAudioDeviceInfo ( const QAudioDeviceInfo other)

Constructs a copy of other.

Definition at line 160 of file qaudiodeviceinfo.cpp.

160  :
161  d(other.d)
162 {
163 }
QSharedDataPointer< QAudioDeviceInfoPrivate > d

◆ ~QAudioDeviceInfo()

QAudioDeviceInfo::~QAudioDeviceInfo ( )

Destroy this audio device info.

Definition at line 169 of file qaudiodeviceinfo.cpp.

170 {
171 }

◆ QAudioDeviceInfo() [3/3]

QAudioDeviceInfo::QAudioDeviceInfo ( const QString realm,
const QByteArray handle,
QAudio::Mode  mode 
)
private
Warning
This function is not part of the public interface.

Definition at line 435 of file qaudiodeviceinfo.cpp.

435  :
436  d(new QAudioDeviceInfoPrivate(realm, handle, mode))
437 {
438 }
QSharedDataPointer< QAudioDeviceInfoPrivate > d
QAudio::Mode mode() const

Functions

◆ availableDevices()

QList< QAudioDeviceInfo > QAudioDeviceInfo::availableDevices ( QAudio::Mode  mode)
static

Returns a list of audio devices that support mode.

Definition at line 425 of file qaudiodeviceinfo.cpp.

426 {
428 }
static QList< QAudioDeviceInfo > availableDevices(QAudio::Mode mode)
QAudio::Mode mode() const

◆ defaultInputDevice()

QAudioDeviceInfo QAudioDeviceInfo::defaultInputDevice ( )
static

Returns the name of the default input audio device.

All platform and audio plugin implementations provide a default audio device to use.

Definition at line 406 of file qaudiodeviceinfo.cpp.

407 {
409 }
static QAudioDeviceInfo defaultInputDevice()

◆ defaultOutputDevice()

QAudioDeviceInfo QAudioDeviceInfo::defaultOutputDevice ( )
static

Returns the name of the default output audio device.

All platform and audio plugin implementations provide a default audio device to use.

Definition at line 416 of file qaudiodeviceinfo.cpp.

417 {
419 }
static QAudioDeviceInfo defaultOutputDevice()

◆ deviceName()

QString QAudioDeviceInfo::deviceName ( ) const

Returns human readable name of audio device.

Device names vary depending on platform/audio plugin being used.

They are a unique string identifiers for the audio device.

eg. default, Intel, U0x46d0x9a4

Definition at line 202 of file qaudiodeviceinfo.cpp.

203 {
204  return isNull() ? QString() : d->info->deviceName();
205 }
static mach_timebase_info_data_t info
The QString class provides a Unicode character string.
Definition: qstring.h:83
QSharedDataPointer< QAudioDeviceInfoPrivate > d
QString deviceName() const
Returns human readable name of audio device.
bool isNull() const
Returns whether this QAudioDeviceInfo object holds a device definition.

◆ handle()

QByteArray QAudioDeviceInfo::handle ( ) const
private
Warning
This function is not part of the public interface.

Definition at line 453 of file qaudiodeviceinfo.cpp.

Referenced by QAudioDeviceFactory::createInputDevice(), and QAudioDeviceFactory::createOutputDevice().

454 {
455  return d->handle;
456 }
QSharedDataPointer< QAudioDeviceInfoPrivate > d

◆ isFormatSupported()

bool QAudioDeviceInfo::isFormatSupported ( const QAudioFormat format) const

Returns true if settings are supported by the audio device of this QAudioDeviceInfo.

Definition at line 211 of file qaudiodeviceinfo.cpp.

Referenced by nearestFormat().

212 {
213  return isNull() ? false : d->info->isFormatSupported(settings);
214 }
QAbstractAudioDeviceInfo * info
virtual bool isFormatSupported(const QAudioFormat &format) const =0
Returns true if format is available from audio device.
QSharedDataPointer< QAudioDeviceInfoPrivate > d
bool isNull() const
Returns whether this QAudioDeviceInfo object holds a device definition.

◆ isNull()

bool QAudioDeviceInfo::isNull ( ) const

Returns whether this QAudioDeviceInfo object holds a device definition.

Definition at line 187 of file qaudiodeviceinfo.cpp.

Referenced by QAudioDeviceFactory::createInputDevice(), QAudioDeviceFactory::createOutputDevice(), deviceName(), isFormatSupported(), preferredFormat(), supportedByteOrders(), supportedChannels(), supportedCodecs(), supportedFrequencies(), supportedSampleSizes(), and supportedSampleTypes().

188 {
189  return d->info == 0;
190 }
QAbstractAudioDeviceInfo * info
QSharedDataPointer< QAudioDeviceInfoPrivate > d

◆ mode()

QAudio::Mode QAudioDeviceInfo::mode ( ) const
private
Warning
This function is not part of the public interface.

Definition at line 463 of file qaudiodeviceinfo.cpp.

464 {
465  return d->mode;
466 }
QSharedDataPointer< QAudioDeviceInfoPrivate > d

◆ nearestFormat()

QAudioFormat QAudioDeviceInfo::nearestFormat ( const QAudioFormat settings) const

Returns closest QAudioFormat to settings that system audio supports.

These settings are provided by the platform/audio plugin being used.

They also are dependent on the QAudio::Mode being used.

Definition at line 243 of file qaudiodeviceinfo.cpp.

244 {
245  if (isFormatSupported(settings))
246  return settings;
247 
248  QAudioFormat nearest = settings;
249 
250  nearest.setCodec(QLatin1String("audio/pcm"));
251 
252  if (nearest.sampleType() == QAudioFormat::Unknown) {
253  QAudioFormat preferred = preferredFormat();
254  nearest.setSampleType(preferred.sampleType());
255  }
256 
257  QMap<int,int> testFrequencies;
258  QList<int> frequenciesAvailable = supportedFrequencies();
259  QMap<int,int> testSampleSizes;
260  QList<int> sampleSizesAvailable = supportedSampleSizes();
261 
262  // Get sorted sampleSizes (equal to and ascending values only)
263  if (sampleSizesAvailable.contains(settings.sampleSize()))
264  testSampleSizes.insert(0,settings.sampleSize());
265  sampleSizesAvailable.removeAll(settings.sampleSize());
266  foreach (int size, sampleSizesAvailable) {
267  int larger = (size > settings.sampleSize()) ? size : settings.sampleSize();
268  int smaller = (size > settings.sampleSize()) ? settings.sampleSize() : size;
269  if (size >= settings.sampleSize()) {
270  int diff = larger - smaller;
271  testSampleSizes.insert(diff, size);
272  }
273  }
274 
275  // Get sorted frequencies (equal to and ascending values only)
276  if (frequenciesAvailable.contains(settings.frequency()))
277  testFrequencies.insert(0,settings.frequency());
278  frequenciesAvailable.removeAll(settings.frequency());
279  foreach (int frequency, frequenciesAvailable) {
280  int larger = (frequency > settings.frequency()) ? frequency : settings.frequency();
281  int smaller = (frequency > settings.frequency()) ? settings.frequency() : frequency;
282  if (frequency >= settings.frequency()) {
283  int diff = larger - smaller;
284  testFrequencies.insert(diff, frequency);
285  }
286  }
287 
288  // Try to find nearest
289  // Check ascending frequencies, ascending sampleSizes
290  QMapIterator<int, int> sz(testSampleSizes);
291  while (sz.hasNext()) {
292  sz.next();
293  nearest.setSampleSize(sz.value());
294  QMapIterator<int, int> i(testFrequencies);
295  while (i.hasNext()) {
296  i.next();
297  nearest.setFrequency(i.value());
298  if (isFormatSupported(nearest))
299  return nearest;
300  }
301  }
302 
303  //Fallback
304  return preferredFormat();
305 }
int frequency() const
Use sampleRate() instead.
QList< int > supportedSampleSizes() const
Returns a list of supported sample sizes.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setSampleType(QAudioFormat::SampleType sampleType)
Sets the sampleType to sampleType.
int sampleSize() const
Returns the current sample size value.
QAudioFormat::SampleType sampleType() const
Returns the current SampleType value.
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
bool isFormatSupported(const QAudioFormat &format) const
Returns true if settings are supported by the audio device of this QAudioDeviceInfo.
static Bigint * diff(Bigint *a, Bigint *b)
QList< int > supportedFrequencies() const
Use supportedSampleRates() instead.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
void setFrequency(int frequency)
Use setSampleRate() instead.
The QAudioFormat class stores audio parameter information.
Definition: qaudioformat.h:60
QAudioFormat preferredFormat() const
Returns QAudioFormat of default settings.
void setSampleSize(int sampleSize)
Sets the sample size to the sampleSize specified.
void setCodec(const QString &codec)
Sets the codec to codec.
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

◆ operator=()

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

Sets the QAudioDeviceInfo object to be equal to other.

Definition at line 177 of file qaudiodeviceinfo.cpp.

178 {
179  d = other.d;
180  return *this;
181 }
QSharedDataPointer< QAudioDeviceInfoPrivate > d

◆ preferredFormat()

QAudioFormat QAudioDeviceInfo::preferredFormat ( ) const

Returns QAudioFormat of default settings.

These settings are provided by the platform/audio plugin being used.

They also are dependent on the QAudio::Mode being used.

A typical audio system would provide something like:

  • Input settings: 8000Hz mono 8 bit.
  • Output settings: 44100Hz stereo 16 bit little endian.

Definition at line 230 of file qaudiodeviceinfo.cpp.

Referenced by nearestFormat().

231 {
232  return isNull() ? QAudioFormat() : d->info->preferredFormat();
233 }
static mach_timebase_info_data_t info
QSharedDataPointer< QAudioDeviceInfoPrivate > d
bool isNull() const
Returns whether this QAudioDeviceInfo object holds a device definition.
The QAudioFormat class stores audio parameter information.
Definition: qaudioformat.h:60
QAudioFormat preferredFormat() const
Returns QAudioFormat of default settings.

◆ realm()

QString QAudioDeviceInfo::realm ( ) const
private
Warning
This function is not part of the public interface.

Definition at line 444 of file qaudiodeviceinfo.cpp.

Referenced by QAudioDeviceFactory::createInputDevice(), and QAudioDeviceFactory::createOutputDevice().

445 {
446  return d->realm;
447 }
QSharedDataPointer< QAudioDeviceInfoPrivate > d

◆ supportedByteOrders()

QList< QAudioFormat::Endian > QAudioDeviceInfo::supportedByteOrders ( ) const

Returns a list of supported byte orders.

Definition at line 387 of file qaudiodeviceinfo.cpp.

388 {
390 }
QAbstractAudioDeviceInfo * info
QSharedDataPointer< QAudioDeviceInfoPrivate > d
bool isNull() const
Returns whether this QAudioDeviceInfo object holds a device definition.
virtual QList< QAudioFormat::Endian > byteOrderList()=0
Returns the list of currently available byte orders.

◆ supportedChannelCounts()

QList< int > QAudioDeviceInfo::supportedChannelCounts ( ) const

Returns a list of supported channel counts.

Since
4.7

Definition at line 355 of file qaudiodeviceinfo.cpp.

356 {
357  return supportedChannels();
358 }
QList< int > supportedChannels() const
Use supportedChannelCount() instead.

◆ supportedChannels()

QList< int > QAudioDeviceInfo::supportedChannels ( ) const

Use supportedChannelCount() instead.

Definition at line 369 of file qaudiodeviceinfo.cpp.

Referenced by supportedChannelCounts().

370 {
371  return isNull() ? QList<int>() : d->info->channelsList();
372 }
QAbstractAudioDeviceInfo * info
QSharedDataPointer< QAudioDeviceInfoPrivate > d
virtual QList< int > channelsList()=0
Returns the list of currently available channels.
bool isNull() const
Returns whether this QAudioDeviceInfo object holds a device definition.

◆ supportedCodecs()

QStringList QAudioDeviceInfo::supportedCodecs ( ) const

Returns a list of supported codecs.

All platform and plugin implementations should provide support for:

"audio/pcm" - Linear PCM

For writing plugins to support additional codecs refer to:

http://www.iana.org/assignments/media-types/audio/

Definition at line 319 of file qaudiodeviceinfo.cpp.

320 {
321  return isNull() ? QStringList() : d->info->codecList();
322 }
static mach_timebase_info_data_t info
QSharedDataPointer< QAudioDeviceInfoPrivate > d
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
bool isNull() const
Returns whether this QAudioDeviceInfo object holds a device definition.

◆ supportedFrequencies()

QList< int > QAudioDeviceInfo::supportedFrequencies ( ) const

Use supportedSampleRates() instead.

Definition at line 344 of file qaudiodeviceinfo.cpp.

Referenced by nearestFormat(), and supportedSampleRates().

345 {
346  return isNull() ? QList<int>() : d->info->frequencyList();
347 }
QAbstractAudioDeviceInfo * info
QSharedDataPointer< QAudioDeviceInfoPrivate > d
bool isNull() const
Returns whether this QAudioDeviceInfo object holds a device definition.
virtual QList< int > frequencyList()=0
Returns the list of currently available frequencies.

◆ supportedSampleRates()

QList< int > QAudioDeviceInfo::supportedSampleRates ( ) const

Returns a list of supported sample rates.

Since
4.7

Definition at line 330 of file qaudiodeviceinfo.cpp.

331 {
332  return supportedFrequencies();
333 }
QList< int > supportedFrequencies() const
Use supportedSampleRates() instead.

◆ supportedSampleSizes()

QList< int > QAudioDeviceInfo::supportedSampleSizes ( ) const

Returns a list of supported sample sizes.

Definition at line 378 of file qaudiodeviceinfo.cpp.

Referenced by nearestFormat().

379 {
380  return isNull() ? QList<int>() : d->info->sampleSizeList();
381 }
QAbstractAudioDeviceInfo * info
virtual QList< int > sampleSizeList()=0
Returns the list of currently available sample sizes.
QSharedDataPointer< QAudioDeviceInfoPrivate > d
bool isNull() const
Returns whether this QAudioDeviceInfo object holds a device definition.

◆ supportedSampleTypes()

QList< QAudioFormat::SampleType > QAudioDeviceInfo::supportedSampleTypes ( ) const

Returns a list of supported sample types.

Definition at line 396 of file qaudiodeviceinfo.cpp.

397 {
399 }
QAbstractAudioDeviceInfo * info
QSharedDataPointer< QAudioDeviceInfoPrivate > d
bool isNull() const
Returns whether this QAudioDeviceInfo object holds a device definition.
virtual QList< QAudioFormat::SampleType > sampleTypeList()=0
Returns the list of currently available sample types.

Friends and Related Functions

◆ QAudioDeviceFactory

friend class QAudioDeviceFactory
friend

Definition at line 68 of file qaudiodeviceinfo.h.

Properties

◆ d

QSharedDataPointer<QAudioDeviceInfoPrivate> QAudioDeviceInfo::d
private

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