QAudioBuffer 類

QAudioBuffer 類錶示具有特定格式和采樣率的一批音頻樣本。 更多...

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

公共類型

F32M
F32S
S16M
S16S
S32M
S32S
U8M
U8S

公共函數

QAudioBuffer ()
QAudioBuffer (const QByteArray & data , const QAudioFormat & format , qint64 startTime = -1)
QAudioBuffer (int numFrames , const QAudioFormat & format , qint64 startTime = -1)
QAudioBuffer (const QAudioBuffer & other )
QAudioBuffer (QAudioBuffer && other )
~QAudioBuffer ()
qsizetype byteCount () const
const T * constData () const
const T * data () const
T * data ()
void detach ()
qint64 duration () const
QAudioFormat format () const
qsizetype frameCount () const
bool isValid () const
qsizetype sampleCount () const
qint64 startTime () const
void swap (QAudioBuffer & other )
QAudioBuffer & operator= (const QAudioBuffer & other )
QAudioBuffer & operator= (QAudioBuffer && other )

詳細描述

QAudioBuffer is used by the QAudioDecoder class to hand decoded audio data over to the application. An audio buffer contains data in a certain QAudioFormat that can be queried using format (). It is also tagged with timing and duration information.

To access the data stored inside the buffer, use the data () 或 constData () 方法。

Audio buffers are explicitly shared, in most cases, you should call detach () before modifying the data.

成員類型文檔編製

QAudioBuffer:: F32M

This is a predefined specialization for a 32 bit float mono sample.

QAudioBuffer:: F32S

This is a predifined specialization for a 32 bit float stereo sample.

QAudioBuffer:: S16M

This is a predefined specialization for a signed 16 bit mono sample. i

QAudioBuffer:: S16S

This is a predefined specialization for a signed stereo 16 bit sample. Each channel is a signed short .

QAudioBuffer:: S32M

This is a predefined specialization for a signed 32 bit mono sample.

QAudioBuffer:: S32S

This is a predifined specialization for a siged 32 bit stereo sample.

QAudioBuffer:: U8M

This is a predefined specialization for an unsigned 8 bit mono sample.

QAudioBuffer:: U8S

This is a predifined specialization for an unsiged 8 bit stereo sample.

成員函數文檔編製

QAudioBuffer:: QAudioBuffer ()

創建新的、空無效緩衝。

QAudioBuffer:: QAudioBuffer (const QByteArray & data , const QAudioFormat & format , qint64 startTime = -1)

創建新的音頻緩衝從供給 data ,在給定 format . The format will determine how the number and sizes of the samples are interpreted from the data .

If the supplied data is not an integer multiple of the calculated frame size, the excess data will not be used.

This audio buffer will copy the contents of data .

startTime (in microseconds) indicates when this buffer starts in the stream. If this buffer is not part of a stream, set it to -1.

QAudioBuffer:: QAudioBuffer ( int numFrames , const QAudioFormat & format , qint64 startTime = -1)

創建具有空間的新音頻緩衝為 numFrames frames of the given format . The individual samples will be initialized to the default for the format.

startTime (in microseconds) indicates when this buffer starts in the stream. If this buffer is not part of a stream, set it to -1.

QAudioBuffer:: QAudioBuffer (const QAudioBuffer & other )

創建新的音頻緩衝從 other . Audio buffers are explicitly shared, you should call detach () on the buffer to make a copy that can then be modified.

QAudioBuffer:: QAudioBuffer ( QAudioBuffer && other )

Constructs a QAudioBuffer by moving from other .

QAudioBuffer:: ~QAudioBuffer ()

銷毀此音頻緩衝。

qsizetype QAudioBuffer:: byteCount () const

返迴此緩衝的大小 (以字節為單位)。

template <typename T> const T *QAudioBuffer:: constData () const

返迴此緩衝數據的指針。隻可以讀取它。

This method is preferred over the const version of data () to prevent unnecessary copying.

There is also a templatized version of this constData() function that allows you to retrieve a specific type of read-only pointer to the data. Note that there is no checking done on the format of the audio buffer - this is simply a convenience function.

// With a 16bit sample buffer:
const quint16 *data = buffer->constData<quint16>();
					

template <typename T> const T *QAudioBuffer:: data () const

返迴此緩衝數據的指針。隻可以讀取它。

應該使用 constData () function rather than this to prevent accidental deep copying.

There is also a templatized version of this data() function that allows you to retrieve a specific type of read-only pointer to the data. Note that there is no checking done on the format of the audio buffer - this is simply a convenience function.

// With a 16bit sample const buffer:
const quint16 *data = buffer->data<quint16>();
					

template <typename T> T *QAudioBuffer:: data ()

Returns a pointer to this buffer's data. You can modify the data through the returned pointer.

由於 QAudioBuffer objects are explicitly shared, you should usually call detach () before modifying the data through this function.

There is also a templatized version of data() allows you to retrieve a specific type of pointer to the data. Note that there is no checking done on the format of the audio buffer - this is simply a convenience function.

// With a 16bit sample buffer:
quint16 *data = buffer->data<quint16>(); // May cause deep copy
					

void QAudioBuffer:: detach ()

Detaches this audio buffers from other copies that might share data with it.

qint64 QAudioBuffer:: duration () const

Returns the duration of audio in this buffer, in microseconds.

這從屬 format (),和 frameCount ().

QAudioFormat QAudioBuffer:: format () const

返迴 format 對於此緩衝。

Several properties of this format influence how the duration () 或 byteCount () are calculated from the frameCount ().

qsizetype QAudioBuffer:: frameCount () const

Returns the number of complete audio frames in this buffer.

An audio frame is an interleaved set of one sample per channel for the same instant in time.

bool QAudioBuffer:: isValid () const

Returns true if this is a valid buffer. A valid buffer has more than zero frames in it and a valid format.

qsizetype QAudioBuffer:: sampleCount () const

返迴此緩衝中的樣本數。

If the format of this buffer has multiple channels, then this count includes all channels. This means that a stereo buffer with 1000 samples in total will have 500 left samples and 500 right samples (interleaved), and this function will return 1000.

另請參閱 frameCount ().

qint64 QAudioBuffer:: startTime () const

Returns the time in a stream that this buffer starts at (in microseconds).

若此緩衝不屬於流,這將返迴 -1。

void QAudioBuffer:: swap ( QAudioBuffer & other )

Swaps the audio buffer with other .

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

賦值 other 緩衝到此。

QAudioBuffer &QAudioBuffer:: operator= ( QAudioBuffer && other )

移動 other 到此 QAudioBuffer .