QAudioFormat Class

The QAudioFormat class stores audio stream parameter information. More...

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

Public Types

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

Detailed Description

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.

In addition to the encoding, 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.

ParameterDescription
Sample RateSamples per second of audio data in Hertz.
Number of channelsThe number of audio channels (typically one for mono or two for stereo)
Sample sizeHow much data is stored in each sample (typically 8 or 16 bits)
Sample typeNumerical representation of sample (typically signed integer, unsigned integer or float)
Byte orderByte 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).

Member Type Documentation

enum QAudioFormat::Endian

ConstantValueDescription
QAudioFormat::BigEndianQSysInfo::BigEndianSamples are big endian byte order
QAudioFormat::LittleEndianQSysInfo::LittleEndianSamples are little endian byte order

enum QAudioFormat::SampleType

ConstantValueDescription
QAudioFormat::Unknown0Not Set
QAudioFormat::SignedInt1Samples are signed integers
QAudioFormat::UnSignedInt2Samples are unsigned intergers
QAudioFormat::Float3Samples are floats