Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QAudio Namespace Reference

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

Enumerations

enum  Error {
  NoError , OpenError , IOError , UnderrunError ,
  FatalError
}
 \value NoError No errors have occurred \value OpenError An error occurred opening the audio device \value IOError An error occurred during read/write of audio device \value UnderrunError Audio data is not being fed to the audio device at a fast enough rate \value FatalError A non-recoverable error has occurred, the audio device is not usable at this time. More...
 
enum  State { ActiveState , SuspendedState , StoppedState , IdleState }
 \value ActiveState Audio data is being processed, this state is set after start() is called and while audio data is available to be processed. More...
 
enum  VolumeScale { LinearVolumeScale , CubicVolumeScale , LogarithmicVolumeScale , DecibelVolumeScale }
 This enum defines the different audio volume scales. More...
 

Functions

float convertVolume (float volume, VolumeScale from, VolumeScale to)
 Converts an audio volume from a volume scale to another, and returns the result.
 

Detailed Description

The QAudio namespace contains enums used by the audio classes.

\inmodule QtMultimedia

Enumeration Type Documentation

◆ Error

\value NoError No errors have occurred \value OpenError An error occurred opening the audio device \value IOError An error occurred during read/write of audio device \value UnderrunError Audio data is not being fed to the audio device at a fast enough rate \value FatalError A non-recoverable error has occurred, the audio device is not usable at this time.

Enumerator
NoError 
OpenError 
IOError 
UnderrunError 
FatalError 

Definition at line 24 of file qaudio.h.

◆ State

\value ActiveState Audio data is being processed, this state is set after start() is called and while audio data is available to be processed.

\value SuspendedState The 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. \value StoppedState The audio device is closed, and is not processing any audio data \value IdleState The 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.

Enumerator
ActiveState 
SuspendedState 
StoppedState 
IdleState 

Definition at line 25 of file qaudio.h.

◆ VolumeScale

This enum defines the different audio volume scales.

\value LinearVolumeScale Linear 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. \value CubicVolumeScale Cubic scale. 0.0 (0%) is silence and 1.0 (100%) is full volume. \value LogarithmicVolumeScale Logarithmic Scale. 0.0 (0%) is silence and 1.0 (100%) is full volume. UI volume controls should usually use a logarithmic scale. \value DecibelVolumeScale Decibel (dB, amplitude) logarithmic scale. -200 is silence and 0 is full volume.

Since
5.8
See also
QAudio::convertVolume()
Enumerator
LinearVolumeScale 
CubicVolumeScale 
LogarithmicVolumeScale 
DecibelVolumeScale 

Definition at line 27 of file qaudio.h.

Function Documentation

◆ convertVolume()

Q_MULTIMEDIA_EXPORT float QAudio::convertVolume ( float  volume,
VolumeScale  from,
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:

Since
5.8
See also
VolumeScale, QAudioSink::setVolume(), QAudioSource::setVolume(), QSoundEffect::setVolume()

Definition at line 91 of file qaudio.cpp.

References CubicVolumeScale, DecibelVolumeScale, LinearVolumeScale, LOG100, LogarithmicVolumeScale, qFuzzyIsNull(), qMax(), and qPow().

Referenced by applyVolume().

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