QAudio Namespace

The QAudio namespace contains enums used by the audio classes. More...

Header: #include <QAudio>
qmake: QT += multimedia

Types

enum Error { NoError, OpenError, IOError, UnderrunError, FatalError }
enum Mode { AudioOutput, AudioInput }
enum Role { UnknownRole, MusicRole, VideoRole, VoiceCommunicationRole, ..., CustomRole }
enum State { ActiveState, SuspendedState, StoppedState, IdleState, InterruptedState }
enum VolumeScale { LinearVolumeScale, CubicVolumeScale, LogarithmicVolumeScale, DecibelVolumeScale }

Functions

qreal convertVolume(qreal volume, QAudio::VolumeScale from, QAudio::VolumeScale to)

Detailed Description

The QAudio namespace contains enums used by the audio classes.

Type Documentation

enum QAudio::Error

ConstantValueDescription
QAudio::NoError0No errors have occurred
QAudio::OpenError1An error occurred opening the audio device
QAudio::IOError2An error occurred during read/write of audio device
QAudio::UnderrunError3Audio data is not being fed to the audio device at a fast enough rate
QAudio::FatalError4A non-recoverable error has occurred, the audio device is not usable at this time.

enum QAudio::Mode

ConstantValueDescription
QAudio::AudioOutput1audio output device
QAudio::AudioInput0audio input device

enum QAudio::Role

This enum describes the role of an audio stream.

ConstantValueDescription
QAudio::UnknownRole0The role is unknown or undefined
QAudio::MusicRole1Music
QAudio::VideoRole2Soundtrack from a movie or a video
QAudio::VoiceCommunicationRole3Voice communications, such as telephony
QAudio::AlarmRole4Alarm
QAudio::NotificationRole5Notification, such as an incoming e-mail or a chat request
QAudio::RingtoneRole6Ringtone
QAudio::AccessibilityRole7For accessibility, such as with a screen reader
QAudio::SonificationRole8Sonification, such as with user interface sounds
QAudio::GameRole9Game audio
QAudio::CustomRole10The role is specified by QMediaPlayer::customAudioRole()

This enum was introduced or modified in Qt 5.6.

See also QMediaPlayer::setAudioRole().

enum QAudio::State

ConstantValueDescription
QAudio::ActiveState0Audio data is being processed, this state is set after start() is called and while audio data is available to be processed.
QAudio::SuspendedState1The audio stream is in a suspended state. Entered after suspend() is called or when another stream takes control of the audio device. In the later case, a call to resume will return control of the audio device to this stream. This should usually only be done upon user request.
QAudio::StoppedState2The audio device is closed, and is not processing any audio data
QAudio::IdleState3The QIODevice passed in has no data and audio system's buffer is empty, this state is set after start() is called and while no audio data is available to be processed.
QAudio::InterruptedState4This stream is in a suspended state because another higher priority stream currently has control of the audio device. Playback cannot resume until the higher priority stream relinquishes control of the audio device.

enum QAudio::VolumeScale

This enum defines the different audio volume scales.

ConstantValueDescription
QAudio::LinearVolumeScale0Linear scale. 0.0 (0%) is silence and 1.0 (100%) is full volume. All Qt Multimedia classes that have an audio volume use a linear scale.
QAudio::CubicVolumeScale1Cubic scale. 0.0 (0%) is silence and 1.0 (100%) is full volume.
QAudio::LogarithmicVolumeScale2Logarithmic Scale. 0.0 (0%) is silence and 1.0 (100%) is full volume. UI volume controls should usually use a logarithmic scale.
QAudio::DecibelVolumeScale3Decibel (dB, amplitude) logarithmic scale. -200 is silence and 0 is full volume.

This enum was introduced or modified in Qt 5.8.

See also QAudio::convertVolume().

Function Documentation

qreal QAudio::convertVolume(qreal volume, QAudio::VolumeScale from, QAudio::VolumeScale to)

Converts an audio volume from a volume scale to another, and returns the result.

Depending on the context, different scales are used to represent audio volume. All Qt Multimedia classes that have an audio volume use a linear scale, the reason is that the loudness of a speaker is controlled by modulating its voltage on a linear scale. The human ear on the other hand, perceives loudness in a logarithmic way. Using a logarithmic scale for volume controls is therefore appropriate in most applications. The decibel scale is logarithmic by nature and is commonly used to define sound levels, it is usually used for UI volume controls in professional audio applications. The cubic scale is a computationally cheap approximation of a logarithmic scale, it provides more control over lower volume levels.

The following example shows how to convert the volume value from a slider control before passing it to a QMediaPlayer. As a result, the perceived increase in volume is the same when increasing the volume slider from 20 to 30 as it is from 50 to 60:

void applyVolume(int volumeSliderValue)
{
    // volumeSliderValue is in the range [0..100]

    qreal linearVolume = QAudio::convertVolume(volumeSliderValue / qreal(100.0),
                                               QAudio::LogarithmicVolumeScale,
                                               QAudio::LinearVolumeScale);

    player.setVolume(qRound(linearVolume * 100));
}

This function was introduced in Qt 5.8.

See also VolumeScale, QMediaPlayer::setVolume(), QAudioOutput::setVolume(), QAudioInput::setVolume(), QSoundEffect::setVolume(), and QMediaRecorder::setVolume().

© 2019 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.