![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QAudioFormat class stores audio stream parameter information. More...
#include <qaudioformat.h>
Public Types | |
enum | SampleFormat : quint16 { Unknown , UInt8 , Int16 , Int32 , Float , NSampleFormats } |
Qt will always expect and use samples in the endianness of the host platform. More... | |
enum | AudioChannelPosition { UnknownPosition , FrontLeft , FrontRight , FrontCenter , LFE , BackLeft , BackRight , FrontLeftOfCenter , FrontRightOfCenter , BackCenter , SideLeft , SideRight , TopCenter , TopFrontLeft , TopFrontCenter , TopFrontRight , TopBackLeft , TopBackCenter , TopBackRight , LFE2 , TopSideLeft , TopSideRight , BottomFrontCenter , BottomFrontLeft , BottomFrontRight } |
Describes the possible audio channel positions. More... | |
enum | ChannelConfig : quint32 { ChannelConfigUnknown = 0 , ChannelConfigMono = QtPrivate::channelConfig(FrontCenter) , ChannelConfigStereo = QtPrivate::channelConfig(FrontLeft, FrontRight) , ChannelConfig2Dot1 = QtPrivate::channelConfig(FrontLeft, FrontRight, LFE) , ChannelConfig3Dot0 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter) , ChannelConfig3Dot1 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE) , ChannelConfigSurround5Dot0 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, BackLeft, BackRight) , ChannelConfigSurround5Dot1 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE, BackLeft, BackRight) , ChannelConfigSurround7Dot0 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, BackLeft, BackRight, SideLeft, SideRight) , ChannelConfigSurround7Dot1 = QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE, BackLeft, BackRight, SideLeft, SideRight) } |
\variable QAudioFormat::NChannelPositions More... | |
Public Member Functions | |
constexpr bool | isValid () const noexcept |
Returns true if all of the parameters are valid. | |
constexpr void | setSampleRate (int sampleRate) noexcept |
Sets the sample rate to samplerate in Hertz. | |
constexpr int | sampleRate () const noexcept |
Returns the current sample rate in Hertz. | |
Q_MULTIMEDIA_EXPORT void | setChannelConfig (ChannelConfig config) noexcept |
Sets the channel configuration to config. | |
constexpr ChannelConfig | channelConfig () const noexcept |
Returns the current channel configuration. | |
constexpr void | setChannelCount (int channelCount) noexcept |
Sets the channel count to channels. | |
constexpr int | channelCount () const noexcept |
Returns the current channel count value. | |
Q_MULTIMEDIA_EXPORT int | channelOffset (AudioChannelPosition channel) const noexcept |
Returns the position of a certain audio channel inside an audio frame for the given format. | |
constexpr void | setSampleFormat (SampleFormat f) noexcept |
Sets the sample format to format. | |
constexpr SampleFormat | sampleFormat () const noexcept |
Returns the current sample format. | |
Q_MULTIMEDIA_EXPORT qint32 | bytesForDuration (qint64 microseconds) const |
Returns the number of bytes required for this audio format for microseconds. | |
Q_MULTIMEDIA_EXPORT qint64 | durationForBytes (qint32 byteCount) const |
Returns the number of microseconds represented by bytes in this format. | |
Q_MULTIMEDIA_EXPORT qint32 | bytesForFrames (qint32 frameCount) const |
Returns the number of bytes required for frameCount frames of this format. | |
Q_MULTIMEDIA_EXPORT qint32 | framesForBytes (qint32 byteCount) const |
Returns the number of frames represented by byteCount in this format. | |
Q_MULTIMEDIA_EXPORT qint32 | framesForDuration (qint64 microseconds) const |
Returns the number of frames required to represent microseconds in this format. | |
Q_MULTIMEDIA_EXPORT qint64 | durationForFrames (qint32 frameCount) const |
Return the number of microseconds represented by frameCount frames in this format. | |
constexpr int | bytesPerFrame () const |
Returns the number of bytes required to represent one frame (a sample in each channel) in this format. | |
constexpr int | bytesPerSample () const noexcept |
Returns the number of bytes required to represent one sample in this format. | |
Q_MULTIMEDIA_EXPORT float | normalizedSampleValue (const void *sample) const |
Normalizes the sample value to a number between -1 and 1. | |
Static Public Member Functions | |
template<typename... Args> | |
static constexpr ChannelConfig | channelConfig (Args... channels) |
Returns the current channel configuration for the given channels. | |
static Q_MULTIMEDIA_EXPORT ChannelConfig | defaultChannelConfigForChannelCount (int channelCount) |
Returns a default channel configuration for channelCount. | |
Static Public Attributes | |
static constexpr int | NChannelPositions = BottomFrontRight + 1 |
Friends | |
bool | operator== (const QAudioFormat &a, const QAudioFormat &b) |
Returns true if audio format a is equal to b, otherwise returns false . | |
bool | operator!= (const QAudioFormat &a, const QAudioFormat &b) |
Returns true if audio format a is not equal to b, otherwise returns false . | |
The QAudioFormat class stores audio stream parameter information.
\inmodule QtMultimedia
An audio format specifies how data in a raw audio stream is arranged. For example, how the stream is to be interpreted.
QAudioFormat contains parameters that specify how the audio sample data is arranged. These are the frequency, the number of channels, and the sample format. The following table describes these in more detail.
\table \header
This class is used in conjunction with QAudioSource or QAudioSink to allow you to specify the parameters of the audio stream being read or written, or with QAudioBuffer when dealing with samples in memory.
You can obtain audio formats compatible with the audio device used through functions in QAudioDevice. This class also lets you query available parameter values for a device, so that you can set the parameters yourself. See the \l QAudioDevice class description for details. You need to know the format of the audio streams you wish to play or record.
Samples for all channels will be interleaved. One sample for each channel for the same instant in time is referred to as a frame in Qt Multimedia (and other places).
Definition at line 22 of file qaudioformat.h.
Describes the possible audio channel positions.
These follow the standard definition used in the 22.2 surround sound configuration.
\value UnknownPosition Unknown position \value FrontLeft \value FrontRight \value FrontCenter \value LFE Low Frequency Effect channel (Subwoofer) \value BackLeft \value BackRight \value FrontLeftOfCenter \value FrontRightOfCenter \value BackCenter \value LFE2 \value SideLeft \value SideRight \value TopFrontLeft \value TopFrontRight \value TopFrontCenter \value TopCenter \value TopBackLeft \value TopBackRight \value TopSideLeft \value TopSideRight \value TopBackCenter \value BottomFrontCenter \value BottomFrontLeft \value BottomFrontRight
Definition at line 35 of file qaudioformat.h.
\variable QAudioFormat::NChannelPositions
This enum describes a standardized audio channel layout. The most common configurations are Mono, Stereo, 2.1 (stereo plus low frequency), 5.1 surround, and 7.1 surround configurations.
\value ChannelConfigUnknown The channel configuration is not known. \value ChannelConfigMono The audio has one Center channel. \value ChannelConfigStereo The audio has two channels, Left and Right. \value ChannelConfig2Dot1 The audio has three channels, Left, Right and LFE (low frequency effect). \value ChannelConfig3Dot0 The audio has three channels, Left, Right, and Center. \value ChannelConfig3Dot1 The audio has four channels, Left, Right, Center, and LFE (low frequency effect). \value ChannelConfigSurround5Dot0 The audio has five channels, Left, Right, Center, BackLeft, and BackRight. \value ChannelConfigSurround5Dot1 The audio has 6 channels, Left, Right, Center, LFE, BackLeft, and BackRight. \value ChannelConfigSurround7Dot0 The audio has 7 channels, Left, Right, Center, BackLeft, BackRight, SideLeft, and SideRight. \value ChannelConfigSurround7Dot1 The audio has 8 channels, Left, Right, Center, LFE, BackLeft, BackRight, SideLeft, and SideRight.
Definition at line 64 of file qaudioformat.h.
Qt will always expect and use samples in the endianness of the host platform.
When processing audio data from external sources yourself, ensure you convert them to the correct endianness before writing them to a QAudioSink or QAudioBuffer.
\value Unknown Not Set \value UInt8 Samples are 8 bit unsigned integers \value Int16 Samples are 16 bit signed integers \value Int32 Samples are 32 bit signed integers \value Float Samples are floats \omitvalue NSampleFormats
Enumerator | |
---|---|
Unknown | |
UInt8 | |
Int16 | |
Int32 | |
Float | |
NSampleFormats |
Definition at line 25 of file qaudioformat.h.
Returns the number of bytes required for this audio format for microseconds.
Returns 0 if this format is not valid.
Note that some rounding may occur if microseconds is not an exact fraction of the sampleRate().
Definition at line 256 of file qaudioformat.cpp.
References bytesPerFrame().
Returns the number of bytes required for frameCount frames of this format.
Returns 0 if this format is not valid.
Definition at line 291 of file qaudioformat.cpp.
References bytesPerFrame().
|
inlineconstexpr |
Returns the number of bytes required to represent one frame (a sample in each channel) in this format.
Returns 0 if this format is invalid.
Definition at line 112 of file qaudioformat.h.
References bytesPerSample(), and channelCount().
Referenced by bytesForDuration(), bytesForFrames(), QWindowsAudioUtils::formatToMediaType(), and framesForBytes().
|
inlineconstexprnoexcept |
Returns the number of bytes required to represent one sample in this format.
Returns 0 if this format is invalid.
Definition at line 113 of file qaudioformat.h.
References Float, Int16, Int32, NSampleFormats, UInt8, and Unknown.
Referenced by QOpenSLESEngine::audioFormatToSLFormatPCM(), bytesPerFrame(), and QWindowsAudioUtils::formatToWaveFormatExtensible().
|
inlineconstexprnoexcept |
Returns the current channel configuration.
Definition at line 92 of file qaudioformat.h.
Referenced by QAmbisonicDecoder::QAmbisonicDecoder(), and QPulseAudioInternal::channelMapForAudioFormat().
|
inlinestaticconstexpr |
Returns the current channel configuration for the given channels.
Definition at line 78 of file qaudioformat.h.
|
inlineconstexprnoexcept |
Returns the current channel count value.
Definition at line 95 of file qaudioformat.h.
Referenced by QAmbisonicDecoder::QAmbisonicDecoder(), QPulseAudioInternal::audioFormatToSampleSpec(), QOpenSLESEngine::audioFormatToSLFormatPCM(), bytesPerFrame(), QWindowsAudioUtils::formatToWaveFormatExtensible(), QOpenSLESEngine::getDefaultBufferSize(), and operator<<().
|
noexcept |
Returns the position of a certain audio channel inside an audio frame for the given format.
Returns -1 if the channel does not exist for this format or the channel configuration is unknown.
Definition at line 197 of file qaudioformat.cpp.
|
static |
Returns a default channel configuration for channelCount.
Default configurations are defined for up to 8 channels, and correspond to standard Mono, Stereo and Surround configurations. For higher channel counts, this simply uses the first channelCount audio channels defined in \l QAudioFormat::AudioChannelPosition.
Definition at line 390 of file qaudioformat.cpp.
References BackLeft, BackRight, ChannelConfig2Dot1, ChannelConfigMono, ChannelConfigStereo, ChannelConfigSurround5Dot0, ChannelConfigSurround5Dot1, ChannelConfigSurround7Dot0, ChannelConfigSurround7Dot1, ChannelConfigUnknown, FrontLeft, and FrontRight.
Returns the number of microseconds represented by bytes in this format.
Returns 0 if this format is not valid.
Note that some rounding may occur if bytes is not an exact multiple of the number of bytes per frame.
Definition at line 271 of file qaudioformat.cpp.
References isValid().
Return the number of microseconds represented by frameCount frames in this format.
Definition at line 331 of file qaudioformat.cpp.
References isValid(), and sampleRate().
Returns the number of frames represented by byteCount in this format.
Note that some rounding may occur if byteCount is not an exact multiple of the number of bytes per frame.
Each frame has one sample per channel.
Definition at line 306 of file qaudioformat.cpp.
References bytesPerFrame().
Returns the number of frames required to represent microseconds in this format.
Note that some rounding may occur if microseconds is not an exact fraction of the \l sampleRate().
Definition at line 320 of file qaudioformat.cpp.
References isValid().
|
inlineconstexprnoexcept |
Returns true
if all of the parameters are valid.
Definition at line 83 of file qaudioformat.h.
References Unknown.
Referenced by QFFmpegResampler::QFFmpegResampler(), durationForBytes(), durationForFrames(), QWindowsAudioUtils::formatToMediaType(), QWindowsAudioUtils::formatToWaveFormatExtensible(), framesForDuration(), QOpenSLESEngine::getDefaultBufferSize(), and makeQAudioDevicePrivate().
float QAudioFormat::normalizedSampleValue | ( | const void * | sample | ) | const |
Normalizes the sample value to a number between -1 and 1.
The method depends on the QaudioFormat.
Definition at line 359 of file qaudioformat.cpp.
References Float, NSampleFormats, and Unknown.
|
inlineconstexprnoexcept |
Returns the current sample format.
Definition at line 100 of file qaudioformat.h.
Referenced by QPulseAudioInternal::audioFormatToSampleSpec(), QOpenSLESEngine::audioFormatToSLFormatPCM(), QWindowsAudioUtils::formatToMediaType(), QWindowsAudioUtils::formatToWaveFormatExtensible(), QOpenSLESEngine::getDefaultBufferSize(), makeQAudioDevicePrivate(), and operator<<().
|
inlineconstexprnoexcept |
Returns the current sample rate in Hertz.
Definition at line 89 of file qaudioformat.h.
Referenced by QFFmpeg::AVAudioFormat::AVAudioFormat(), QAmbisonicDecoder::QAmbisonicDecoder(), QPulseAudioInternal::audioFormatToSampleSpec(), QOpenSLESEngine::audioFormatToSLFormatPCM(), durationForFrames(), QWindowsAudioUtils::formatToMediaType(), QWindowsAudioUtils::formatToWaveFormatExtensible(), QOpenSLESEngine::getDefaultBufferSize(), and operator<<().
|
noexcept |
Sets the channel configuration to config.
Sets the channel configuration of the audio format to one of the standard audio channel configurations.
Definition at line 184 of file qaudioformat.cpp.
References ChannelConfigUnknown.
Referenced by QAudioOutputStream::startOutput().
|
inlineconstexprnoexcept |
Sets the channel count to channels.
Setting this also sets the channel config to ChannelConfigUnknown.
Definition at line 94 of file qaudioformat.h.
References ChannelConfigUnknown.
Referenced by makeQAudioDevicePrivate(), QWindowsAudioUtils::mediaTypeToFormat(), QPulseAudioInternal::sampleSpecToAudioFormat(), QAudioOutputStream::startOutput(), and QWindowsAudioUtils::waveFormatExToFormat().
|
inlineconstexprnoexcept |
Sets the sample format to format.
Definition at line 99 of file qaudioformat.h.
Referenced by makeQAudioDevicePrivate(), QWindowsAudioUtils::mediaTypeToFormat(), QPulseAudioInternal::sampleSpecToAudioFormat(), QAudioOutputStream::startOutput(), and QWindowsAudioUtils::waveFormatExToFormat().
|
inlineconstexprnoexcept |
Sets the sample rate to samplerate in Hertz.
Definition at line 88 of file qaudioformat.h.
Referenced by makeQAudioDevicePrivate(), QWindowsAudioUtils::mediaTypeToFormat(), QPulseAudioInternal::sampleSpecToAudioFormat(), QAudioOutputStream::startOutput(), and QWindowsAudioUtils::waveFormatExToFormat().
|
friend |
Returns true
if audio format a is not equal to b, otherwise returns false
.
Definition at line 134 of file qaudioformat.h.
References operator==.
|
friend |
Returns true
if audio format a is equal to b, otherwise returns false
.
Definition at line 128 of file qaudioformat.h.
Referenced by operator!=.
|
staticconstexpr |
Definition at line 62 of file qaudioformat.h.