Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QAudioBuffer Class Reference

\inmodule QtMultimedia More...

#include <qaudiobuffer.h>

+ Collaboration diagram for QAudioBuffer:

Public Types

typedef QAudioFrameMono< QAudioFormat::UInt8U8M
 This is a predefined specialization for an unsigned 8 bit mono sample.
 
typedef QAudioFrameMono< QAudioFormat::Int16S16M
 
typedef QAudioFrameMono< QAudioFormat::Int32S32M
 This is a predefined specialization for a signed 32 bit mono sample.
 
typedef QAudioFrameMono< QAudioFormat::FloatF32M
 This is a predefined specialization for a 32 bit float mono sample.
 
typedef QAudioFrameStereo< QAudioFormat::UInt8U8S
 This is a predifined specialization for an unsiged 8 bit stereo sample.
 
typedef QAudioFrameStereo< QAudioFormat::Int16S16S
 This is a predefined specialization for a signed stereo 16 bit sample.
 
typedef QAudioFrameStereo< QAudioFormat::Int32S32S
 This is a predifined specialization for a siged 32 bit stereo sample.
 
typedef QAudioFrameStereo< QAudioFormat::FloatF32S
 This is a predifined specialization for a 32 bit float stereo sample.
 

Public Member Functions

 QAudioBuffer () noexcept
 Create a new, empty, invalid buffer.
 
 QAudioBuffer (const QAudioBuffer &other) noexcept
 Creates a new audio buffer from other.
 
 QAudioBuffer (const QByteArray &data, const QAudioFormat &format, qint64 startTime=-1)
 Creates a new audio buffer from the supplied data, in the given format.
 
 QAudioBuffer (int numFrames, const QAudioFormat &format, qint64 startTime=-1)
 Creates a new audio buffer with space for numFrames frames of the given format.
 
 ~QAudioBuffer ()
 Destroys this audio buffer.
 
QAudioBufferoperator= (const QAudioBuffer &other)
 Moves other into this QAudioBuffer.
 
 QAudioBuffer (QAudioBuffer &&other) noexcept=default
 Constructs a QAudioBuffer by moving from other.
 
void swap (QAudioBuffer &other) noexcept
 Swaps the audio buffer with other.
 
bool isValid () const noexcept
 Returns true if this is a valid buffer.
 
void detach ()
 Detaches this audio buffers from other copies that might share data with it.
 
QAudioFormat format () const noexcept
 Returns the \l {QAudioFormat}{format} of this buffer.
 
qsizetype frameCount () const noexcept
 Returns the number of complete audio frames in this buffer.
 
qsizetype sampleCount () const noexcept
 Returns the number of samples in this buffer.
 
qsizetype byteCount () const noexcept
 Returns the size of this buffer, in bytes.
 
qint64 duration () const noexcept
 Returns the duration of audio in this buffer, in microseconds.
 
qint64 startTime () const noexcept
 Returns the time in a stream that this buffer starts at (in microseconds).
 
template<typename T >
const T * constData () const
 Returns a pointer to this buffer's data.
 
template<typename T >
const T * data () const
 Returns a pointer to this buffer's data.
 
template<typename T >
T * data ()
 Returns a pointer to this buffer's data.
 

Detailed Description

\inmodule QtMultimedia

The QAudioBuffer class represents a collection of audio samples with a specific format and sample rate.

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() or constData() methods.

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

Definition at line 114 of file qaudiobuffer.h.

Member Typedef Documentation

◆ F32M

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

Definition at line 147 of file qaudiobuffer.h.

◆ F32S

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

Definition at line 152 of file qaudiobuffer.h.

◆ S16M

◆ S16S

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

Each channel is a {signed short}.

Definition at line 150 of file qaudiobuffer.h.

◆ S32M

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

\typedef QAudioBuffer::S16M
This is a predefined specialization for a signed 16 bit mono sample.

i

Definition at line 146 of file qaudiobuffer.h.

◆ S32S

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

Definition at line 151 of file qaudiobuffer.h.

◆ U8M

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

Definition at line 144 of file qaudiobuffer.h.

◆ U8S

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

Definition at line 149 of file qaudiobuffer.h.

Constructor & Destructor Documentation

◆ QAudioBuffer() [1/5]

QAudioBuffer::QAudioBuffer ( )
defaultnoexcept

Create a new, empty, invalid buffer.

◆ QAudioBuffer() [2/5]

QAudioBuffer::QAudioBuffer ( const QAudioBuffer & other)
defaultnoexcept

Creates a new audio buffer from other.

Audio buffers are explicitly shared, you should call detach() on the buffer to make a copy that can then be modified.

◆ QAudioBuffer() [3/5]

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

Creates a new audio buffer from the supplied data, in the given 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.

Definition at line 74 of file qaudiobuffer.cpp.

References d, and startTime.

◆ QAudioBuffer() [4/5]

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

Creates a new audio buffer with space for 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.

Definition at line 90 of file qaudiobuffer.cpp.

References data(), and startTime().

+ Here is the call graph for this function:

◆ ~QAudioBuffer()

QAudioBuffer::~QAudioBuffer ( )
default

Destroys this audio buffer.

◆ QAudioBuffer() [5/5]

QAudioBuffer::QAudioBuffer ( QAudioBuffer && other)
defaultnoexcept

Constructs a QAudioBuffer by moving from other.

Member Function Documentation

◆ byteCount()

qsizetype QAudioBuffer::byteCount ( ) const
noexcept

Returns the size of this buffer, in bytes.

Definition at line 189 of file qaudiobuffer.cpp.

References QAudioBufferPrivate::data, and QByteArray::size().

Referenced by QSoundEffectPrivate::bytesAvailable(), QSoundEffectPrivate::readData(), and QSoundEffectPrivate::size().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ constData()

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

Returns a pointer to this buffer's data.

You can only read it.

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

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>();
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint buffer
unsigned short quint16
Definition qtypes.h:48

Definition at line 154 of file qaudiobuffer.h.

Referenced by QAmbientSoundPrivate::getBuffer(), and QSoundEffectPrivate::readData().

+ Here is the caller graph for this function:

◆ data() [1/2]

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

Returns a pointer to this buffer's data.

You can modify the data through the returned pointer.

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

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

Definition at line 160 of file qaudiobuffer.h.

◆ data() [2/2]

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

Returns a pointer to this buffer's data.

You can only read it.

You should use the \l constData() function rather than this to prevent accidental deep copying.

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>();

Definition at line 157 of file qaudiobuffer.h.

Referenced by QAudioBuffer().

+ Here is the caller graph for this function:

◆ detach()

void QAudioBuffer::detach ( )

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

Definition at line 136 of file qaudiobuffer.cpp.

◆ duration()

qint64 QAudioBuffer::duration ( ) const
noexcept

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

This depends on the \l format(), and the \l frameCount().

Definition at line 199 of file qaudiobuffer.cpp.

References QAudioFormat::durationForFrames(), format(), and frameCount().

+ Here is the call graph for this function:

◆ format()

QAudioFormat QAudioBuffer::format ( ) const
noexcept

Returns the \l {QAudioFormat}{format} of this buffer.

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

Definition at line 150 of file qaudiobuffer.cpp.

References QAudioBufferPrivate::format.

Referenced by duration(), sampleCount(), and QSoundEffectPrivate::sampleReady().

+ Here is the caller graph for this function:

◆ frameCount()

qsizetype QAudioBuffer::frameCount ( ) const
noexcept

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.

Definition at line 163 of file qaudiobuffer.cpp.

References QAudioBufferPrivate::data, QAudioBufferPrivate::format, QAudioFormat::framesForBytes(), and QByteArray::size().

Referenced by duration(), and sampleCount().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValid()

bool QAudioBuffer::isValid ( ) const
inlinenoexcept

Returns true if this is a valid buffer.

A valid buffer has more than zero frames in it and a valid format.

Definition at line 130 of file qaudiobuffer.h.

References d.

Referenced by QFFmpegAudioDecoder::newAudioBuffer(), and QSoundEffectPrivate::sampleReady().

+ Here is the caller graph for this function:

◆ operator=()

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

Moves other into this QAudioBuffer.

Assigns the other buffer to this.

◆ sampleCount()

qsizetype QAudioBuffer::sampleCount ( ) const
noexcept

Returns the number of samples in this buffer.

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.

See also
frameCount()

Definition at line 181 of file qaudiobuffer.cpp.

References QAudioFormat::channelCount(), format(), and frameCount().

Referenced by MFAudioDecoderControl::bufferAvailable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ startTime()

qint64 QAudioBuffer::startTime ( ) const
noexcept

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

If this buffer is not part of a stream, this will return -1.

Definition at line 209 of file qaudiobuffer.cpp.

References QAudioBufferPrivate::startTime.

Referenced by QAudioBuffer(), and QFFmpegAudioDecoder::newAudioBuffer().

+ Here is the caller graph for this function:

◆ swap()

void QAudioBuffer::swap ( QAudioBuffer & other)
inlinenoexcept

Swaps the audio buffer with other.

Definition at line 127 of file qaudiobuffer.h.

References d, other(), and swap().

Referenced by MFAudioDecoderControl::read(), MFAudioDecoderControl::stop(), and swap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: