QAudioFormat 类

The QAudioFormat 类存储音频流参数信息。 更多...

头: #include <QAudioFormat>
qmake: QT += multimedia

公共类型

enum Endian { BigEndian, LittleEndian }
enum SampleType { Unknown, SignedInt, UnSignedInt, Float }

公共函数

QAudioFormat ()
QAudioFormat (const QAudioFormat & other )
~QAudioFormat ()
QAudioFormat::Endian byteOrder () const
qint32 bytesForDuration (qint64 duration ) const
qint32 bytesForFrames (qint32 frameCount ) const
int bytesPerFrame () const
int channelCount () const
QString codec () const
qint64 durationForBytes (qint32 bytes ) const
qint64 durationForFrames (qint32 frameCount ) const
qint32 framesForBytes (qint32 byteCount ) const
qint32 framesForDuration (qint64 duration ) const
bool isValid () const
int sampleRate () const
int sampleSize () const
QAudioFormat::SampleType sampleType () const
void setByteOrder (QAudioFormat::Endian byteOrder )
void setChannelCount (int channels )
void setCodec (const QString & codec )
void setSampleRate (int samplerate )
void setSampleSize (int sampleSize )
void setSampleType (QAudioFormat::SampleType sampleType )
bool operator!= (const QAudioFormat & other ) const
QAudioFormat & operator= (const QAudioFormat & other )
bool operator== (const QAudioFormat & other ) const

详细描述

The QAudioFormat 类存储音频流参数信息。

An audio format specifies how data in an audio stream is arranged, i.e, how the stream is to be interpreted. The encoding itself is specified by the codec () used for the stream.

除编码外, QAudioFormat contains other parameters that further specify how the audio sample data is arranged. These are the frequency, the number of channels, the sample size, the sample type, and the byte order. 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)
采样大小 How much data is stored in each sample (typically 8 or 16 bits)
采样类型 Numerical representation of sample (typically signed integer, unsigned integer or float)
字节序 Byte ordering of sample (typically little endian, big endian)

This class is typically used in conjunction with QAudioInput or QAudioOutput 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 QAudioDeviceInfo . This class also lets you query available parameter values for a device, so that you can set the parameters yourself. See the QAudioDeviceInfo class description for details. You need to know the format of the audio streams you wish to play or record.

In the common case of interleaved linear PCM data, the codec will be "audio/pcm", and the 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:: Endian

常量 描述
QAudioFormat::BigEndian QSysInfo::BigEndian Samples are big endian byte order
QAudioFormat::LittleEndian QSysInfo::LittleEndian Samples are little endian byte order

enum QAudioFormat:: SampleType

常量 描述
QAudioFormat::Unknown 0 不设置
QAudioFormat::SignedInt 1 采样是有符号整数
QAudioFormat::UnSignedInt 2 采样是无符号整数
QAudioFormat::Float 3 采样是浮点数

成员函数文档编制

QAudioFormat:: QAudioFormat ()

构建新的音频格式。

值的初始化如下:

QAudioFormat:: QAudioFormat (const QAudioFormat & other )

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

QAudioFormat:: ~QAudioFormat ()

销毁此音频格式。

QAudioFormat::Endian QAudioFormat:: byteOrder () const

Returns the current byteOrder value.

另请参阅 setByteOrder ().

qint32 QAudioFormat:: bytesForDuration ( qint64 duration ) const

Returns the number of bytes required for this audio format for duration 微秒。

返回 0 若此格式无效。

Note that some rounding may occur if duration 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 ().

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.

int QAudioFormat:: channelCount () const

返回当前通道计数值。

另请参阅 setChannelCount ().

QString QAudioFormat:: codec () const

返回当前编解码器标识符。

另请参阅 setCodec () 和 QAudioDeviceInfo::supportedCodecs ().

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 duration ) const

Returns the number of frames required to represent duration microseconds in this format.

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

bool QAudioFormat:: isValid () const

Returns true if all of the parameters are valid.

int QAudioFormat:: sampleRate () const

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

另请参阅 setSampleRate ().

int QAudioFormat:: sampleSize () const

返回当前采样大小值 (以位为单位)。

另请参阅 setSampleSize () 和 bytesPerFrame ().

QAudioFormat::SampleType QAudioFormat:: sampleType () const

返回当前 SampleType 值。

另请参阅 setSampleType ().

void QAudioFormat:: setByteOrder ( QAudioFormat::Endian byteOrder )

设置 byteOrder to byteOrder .

另请参阅 byteOrder ().

void QAudioFormat:: setChannelCount ( int channels )

将通道计数设为 channels .

另请参阅 channelCount ().

void QAudioFormat:: setCodec (const QString & codec )

将编解码器设为 codec .

The parameter to this function should be one of the types reported by the QAudioDeviceInfo::supportedCodecs () function for the audio device you are working with.

另请参阅 codec () 和 QAudioDeviceInfo::supportedCodecs ().

void QAudioFormat:: setSampleRate ( int samplerate )

Sets the sample rate to samplerate Hertz.

另请参阅 sampleRate ().

void QAudioFormat:: setSampleSize ( int sampleSize )

Sets the sample size to the sampleSize specified, in bits.

This is typically 8 or 16, but some systems may support higher sample sizes.

另请参阅 sampleSize ().

void QAudioFormat:: setSampleType ( QAudioFormat::SampleType sampleType )

设置 sampleType to sampleType .

另请参阅 sampleType ().

bool QAudioFormat:: operator!= (const QAudioFormat & other ) const

返回 true,若此 QAudioFormat is not equal to the other QAudioFormat ;否则返回 false。

All elements of QAudioFormat are used for the comparison.

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

赋值 other 到此 QAudioFormat 实现。

bool QAudioFormat:: operator== (const QAudioFormat & other ) const

返回 true,若此 QAudioFormat is equal to the other QAudioFormat ;否则返回 false。

All elements of QAudioFormat are used for the comparison.