QAudioFormat 类

The QAudioFormat class stores audio stream parameter information. 更多...

头: #include <QAudioFormat>
CMake: find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia

公共类型

enum AudioChannelPosition { UnknownPosition, FrontLeft, FrontRight, FrontCenter, LFE, …, BottomFrontRight }
enum ChannelConfig { ChannelConfigUnknown, ChannelConfigMono, ChannelConfigStereo, ChannelConfig2Dot1, ChannelConfig3Dot0, …, ChannelConfigSurround7Dot1 }
enum SampleFormat { Unknown, UInt8, Int16, Int32, Float }

公共函数

QAudioFormat ()
QAudioFormat (const QAudioFormat & other )
~QAudioFormat ()
qint32 bytesForDuration (qint64 microseconds ) const
qint32 bytesForFrames (qint32 frameCount ) const
int bytesPerFrame () const
int bytesPerSample () const
QAudioFormat::ChannelConfig channelConfig () const
int channelCount () const
int channelOffset (QAudioFormat::AudioChannelPosition channel ) const
qint64 durationForBytes (qint32 bytes ) const
qint64 durationForFrames (qint32 frameCount ) const
qint32 framesForBytes (qint32 byteCount ) const
qint32 framesForDuration (qint64 microseconds ) const
bool isValid () const
float normalizedSampleValue (const void * sample ) const
QAudioFormat::SampleFormat sampleFormat () const
int sampleRate () const
void setChannelConfig (QAudioFormat::ChannelConfig config )
void setChannelCount (int channels )
void setSampleFormat (QAudioFormat::SampleFormat format )
void setSampleRate (int samplerate )

静态公共成员

QAudioFormat::ChannelConfig channelConfig (Args... channels )
QAudioFormat::ChannelConfig defaultChannelConfigForChannelCount (int channelCount )
bool operator!= (const QAudioFormat & a , const QAudioFormat & b )
bool operator== (const QAudioFormat & a , const QAudioFormat & b )

详细描述

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.

参数 描述
采样率 Samples per second of audio data in Hertz.
通道数 The number of audio channels (typically one for mono or two for stereo). These are the amount of consecutive samples that together form one frame in the stream
Sample format The format of the audio samples in the stream

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

成员类型文档编制

enum QAudioFormat:: AudioChannelPosition

Describes the possible audio channel positions. These follow the standard definition used in the 22.2 surround sound configuration.

常量 描述
QAudioFormat::UnknownPosition 0 Unknown position
QAudioFormat::FrontLeft 1
QAudioFormat::FrontRight 2
QAudioFormat::FrontCenter 3
QAudioFormat::LFE 4 Low Frequency Effect channel (Subwoofer)
QAudioFormat::BackLeft 5
QAudioFormat::BackRight 6
QAudioFormat::FrontLeftOfCenter 7
QAudioFormat::FrontRightOfCenter 8
QAudioFormat::BackCenter 9
QAudioFormat::LFE2 19
QAudioFormat::SideLeft 10
QAudioFormat::SideRight 11
QAudioFormat::TopFrontLeft 13
QAudioFormat::TopFrontRight 15
QAudioFormat::TopFrontCenter 14
QAudioFormat::TopCenter 12
QAudioFormat::TopBackLeft 16
QAudioFormat::TopBackRight 18
QAudioFormat::TopSideLeft 20
QAudioFormat::TopSideRight 21
QAudioFormat::TopBackCenter 17
QAudioFormat::BottomFrontCenter 22
QAudioFormat::BottomFrontLeft 23
QAudioFormat::BottomFrontRight 24

enum QAudioFormat:: ChannelConfig

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.

常量 描述
QAudioFormat::ChannelConfigUnknown 0 The channel configuration is not known.
QAudioFormat::ChannelConfigMono QtPrivate::channelConfig(FrontCenter) The audio has one Center channel.
QAudioFormat::ChannelConfigStereo QtPrivate::channelConfig(FrontLeft, FrontRight) The audio has two channels, Left and Right.
QAudioFormat::ChannelConfig2Dot1 QtPrivate::channelConfig(FrontLeft, FrontRight, LFE) The audio has three channels, Left, Right and LFE (low frequency effect).
QAudioFormat::ChannelConfig3Dot0 QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter) The audio has three channels, Left, Right, and Center.
QAudioFormat::ChannelConfig3Dot1 QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE) The audio has four channels, Left, Right, Center, and LFE (low frequency effect).
QAudioFormat::ChannelConfigSurround5Dot0 QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, BackLeft, BackRight) The audio has five channels, Left, Right, Center, BackLeft ,和 BackRight .
QAudioFormat::ChannelConfigSurround5Dot1 QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE, BackLeft, BackRight) The audio has 6 channels, Left, Right, Center, LFE, BackLeft ,和 BackRight .
QAudioFormat::ChannelConfigSurround7Dot0 QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, BackLeft, BackRight, SideLeft, SideRight) The audio has 7 channels, Left, Right, Center, BackLeft , BackRight , SideLeft ,和 SideRight .
QAudioFormat::ChannelConfigSurround7Dot1 QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE, BackLeft, BackRight, SideLeft, SideRight) The audio has 8 channels, Left, Right, Center, LFE, BackLeft , BackRight , SideLeft ,和 SideRight .

enum QAudioFormat:: SampleFormat

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 .

常量 描述
QAudioFormat::Unknown 0 不设置
QAudioFormat::UInt8 1 Samples are unsigned 8 bit signed integers
QAudioFormat::Int16 2 Samples are 16 bit signed integers
QAudioFormat::Int32 3 Samples are 32 bit signed integers
QAudioFormat::Float 4 采样是浮点数

成员函数文档编制

[default] QAudioFormat:: QAudioFormat ()

Constructs a new audio format.

值的初始化如下:

[default] QAudioFormat:: QAudioFormat (const QAudioFormat & other )

构造新的音频格式使用 other .

[default] QAudioFormat:: ~QAudioFormat ()

销毁此音频格式。

qint32 QAudioFormat:: bytesForDuration ( qint64 microseconds ) const

Returns the number of bytes required for this audio format for microseconds .

返回 0 若此格式无效。

Note that some rounding may occur if microseconds is not an exact fraction of the sampleRate ().

另请参阅 durationForBytes ().

qint32 QAudioFormat:: bytesForFrames ( qint32 frameCount ) const

Returns the number of bytes required for frameCount frames of this format.

返回 0 若此格式无效。

另请参阅 bytesForDuration ().

[constexpr] int QAudioFormat:: bytesPerFrame () const

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.

[constexpr] int QAudioFormat:: bytesPerSample () const

Returns the number of bytes required to represent one sample in this format.

Returns 0 if this format is invalid.

[static constexpr] template <typename Args> QAudioFormat::ChannelConfig QAudioFormat:: channelConfig ( Args ... channels )

Returns the current channel configuration for the given channels .

另请参阅 setChannelConfig ().

[constexpr] QAudioFormat::ChannelConfig QAudioFormat:: channelConfig () const

Returns the current channel configuration.

[constexpr] int QAudioFormat:: channelCount () const

返回当前通道计数值。

另请参阅 setChannelCount ().

int QAudioFormat:: channelOffset ( QAudioFormat::AudioChannelPosition channel ) const

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.

[static] QAudioFormat::ChannelConfig QAudioFormat:: defaultChannelConfigForChannelCount ( int channelCount )

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 QAudioFormat::AudioChannelPosition .

qint64 QAudioFormat:: durationForBytes ( qint32 bytes ) const

Returns the number of microseconds represented by bytes in this format.

返回 0 若此格式无效。

Note that some rounding may occur if bytes is not an exact multiple of the number of bytes per frame.

另请参阅 bytesForDuration ().

qint64 QAudioFormat:: durationForFrames ( qint32 frameCount ) const

Return the number of microseconds represented by frameCount frames in this format.

qint32 QAudioFormat:: framesForBytes ( qint32 byteCount ) const

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.

另请参阅 framesForDuration ().

qint32 QAudioFormat:: framesForDuration ( qint64 microseconds ) const

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

[constexpr] bool QAudioFormat:: isValid () const

返回 true if all of the parameters are valid.

float QAudioFormat:: normalizedSampleValue (const void * sample ) const

Normalizes the sample value to a number between -1 and 1. The method depends on the QaudioFormat.

[constexpr] QAudioFormat::SampleFormat QAudioFormat:: sampleFormat () const

Returns the current sample format.

另请参阅 setSampleFormat ().

[constexpr] int QAudioFormat:: sampleRate () const

返回当前采样率 (以赫兹为单位)。

另请参阅 setSampleRate ().

void QAudioFormat:: setChannelConfig ( QAudioFormat::ChannelConfig config )

Sets the channel configuration to config .

Sets the channel configuration of the audio format to one of the standard audio channel configurations.

注意: that this will also modify the channel count.

另请参阅 channelConfig ().

[constexpr] void QAudioFormat:: setChannelCount ( int channels )

将通道计数设为 channels . Setting this also sets the channel config to ChannelConfigUnknown .

另请参阅 channelCount ().

[constexpr] void QAudioFormat:: setSampleFormat ( QAudioFormat::SampleFormat format )

Sets the sample format to format .

另请参阅 sampleFormat () 和 QAudioFormat::SampleFormat .

[constexpr] void QAudioFormat:: setSampleRate ( int samplerate )

Sets the sample rate to samplerate in Hertz.

另请参阅 sampleRate ().

相关非成员

bool operator!= (const QAudioFormat & a , const QAudioFormat & b )

返回 true if audio format a 不等于 b ,否则返回 false .

bool operator== (const QAudioFormat & a , const QAudioFormat & b )

返回 true if audio format a 等于 b ,否则返回 false .