QAudioBuffer Class

QAudioBuffer 类表示具有特定格式和采样率的音频样本集合。更多

头文件: #include <QAudioBuffer>
CMake.QAudioBuffer 类 find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia

公共类型

公共函数

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
T *data()
const T *data() const
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=(QAudioBuffer &&other)
QAudioBuffer &operator=(const QAudioBuffer &other)

详细说明

QAudioDecoder 类使用 QAudioBuffer 将解码后的音频数据交给应用程序。音频缓冲区包含特定QAudioFormat 中的数据,可使用format() 进行查询。音频缓冲区还标记有定时和持续时间信息。

要访问缓冲区内存储的数据,可使用data() 或constData() 方法。

音频缓冲区是显式共享的,因此在大多数情况下,应在修改数据前调用detach() 方法。

成员类型文档

QAudioBuffer::F32M

这是 32 位浮点单声道采样的预定义特殊化。

QAudioBuffer::F32S

这是对 32 位浮点立体声采样的预先专门化。

QAudioBuffer::S16M

这是一个带符号的 16 位单声道采样的预定义特殊化 i

QAudioBuffer::S16S

这是一个带符号的 16 位立体声采样的预定义特殊化。每个通道都是带符号的短路

QAudioBuffer::S32M

这是对有符号的 32 位单声道采样的预定义特殊化。

QAudioBuffer::S32S

这是对已加密的 32 位立体声采样的预先专门化。

QAudioBuffer::U8M

这是针对无符号 8 位单声道采样的预定义特殊化。

QAudioBuffer::U8S

这是未加密 8 位立体声采样的预定义特殊化。

成员函数文档

[noexcept] QAudioBuffer::QAudioBuffer()

创建一个新的、空的、无效的缓冲区。

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

从提供的data 中创建一个新的音频缓冲区,格式为给定的format 。格式将决定如何从data 解释样本的数量和大小。

如果提供的data 不是计算出的帧大小的整数倍,多余的数据将不会被使用。

该音频缓冲区将复制data 中的内容。

startTime (以微秒为单位)表示该缓冲区在流中的开始时间。如果此缓冲区不是流的一部分,则将其设置为-1。

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

创建一个新的音频缓冲区,为numFrames 给定的format 帧提供空间。单个样本将被初始化为格式的默认值。

startTime (以微秒为单位)表示该缓冲区在流中的开始时间。如果此缓冲区不是流的一部分,则将其设置为-1。

[noexcept] QAudioBuffer::QAudioBuffer(const QAudioBuffer &other)

other 创建一个新的音频缓冲区。音频缓冲区是显式共享的,应在缓冲区上调用detach() 来创建一个可修改的副本。

[noexcept] QAudioBuffer::QAudioBuffer(QAudioBuffer &&other)

other 移动,构建 QAudioBuffer。

[noexcept] QAudioBuffer::~QAudioBuffer()

销毁此音频缓冲区。

[noexcept] qsizetype QAudioBuffer::byteCount() const

返回缓冲区的大小(以字节为单位)。

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

返回指向该缓冲区数据的指针。您只能读取它。

与常量版本的data() 相比,该方法更受青睐,可避免不必要的复制。

请注意,我们不会检查音频缓冲区的格式,这只是一个方便的函数。

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

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

返回指向该缓冲区数据的指针。您可以通过返回的指针修改数据。

由于QAudioBuffer 对象是显式共享的,因此在通过此函数修改数据之前,通常应调用detach() 。

请注意,我们不会对音频缓冲区的格式进行检查,这只是一个方便使用的函数。

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

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

返回指向该缓冲区数据的指针。您只能读取它。

为防止意外的深度复制,应使用constData() 函数而不是此函数。

请注意,我们不会检查音频缓冲区的格式,这只是一个方便的函数。

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

void QAudioBuffer::detach()

将此音频缓冲区与可能与其共享数据的其他副本分离。

[noexcept] qint64 QAudioBuffer::duration() const

返回缓冲区中音频的持续时间(以微秒为单位)。

这取决于format() 和frameCount() 。

[noexcept] QAudioFormat QAudioBuffer::format() const

返回该缓冲区的format

该格式的几个属性会影响从frameCount() 计算duration() 或byteCount() 的方式。

[noexcept] qsizetype QAudioBuffer::frameCount() const

返回此缓冲区中完整音频帧的数量。

音频帧是同一时刻每个通道一个样本的交错集合。

[noexcept] bool QAudioBuffer::isValid() const

如果该缓冲区有效,则返回 true。有效缓冲区中的帧数大于零,格式有效。

[noexcept] qsizetype QAudioBuffer::sampleCount() const

返回此缓冲区中的采样数目。

如果此缓冲区的格式有多个通道,则此计数包括所有通道。也就是说,一个总共有 1000 个采样点的立体声缓冲区将有 500 个左声道采样点和 500 个右声道采样点(交错),此函数将返回 1000。

另请参见 frameCount().

[noexcept] qint64 QAudioBuffer::startTime() const

返回该缓冲区在数据流中的起始时间(以微秒为单位)。

如果该缓冲区不是数据流的一部分,则返回-1。

[noexcept] void QAudioBuffer::swap(QAudioBuffer &other)

other 交换音频缓冲区。

[noexcept] QAudioBuffer &QAudioBuffer::operator=(QAudioBuffer &&other)

other 移至QAudioBuffer

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

other 指定缓冲区。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.