- Qt 6.4
- Qt Multimedia
- C++ Classes
- QtMultimedia
- QAudioFormat
- Qt 6.4.3 Reference Documentation

# QAudioFormat Class

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

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

- List of all members, including inherited members

## Public Types

enum | AudioChannelPosition { UnknownPosition, FrontLeft, FrontRight, FrontCenter, LFE, …, BottomFrontRight }
enum | ChannelConfig { ChannelConfigUnknown, ChannelConfigMono, ChannelConfigStereo, ChannelConfig2Dot1, ChannelConfig3Dot0, …, ChannelConfigSurround7Dot1 }
enum | SampleFormat { Unknown, UInt8, Int16, Int32, Float }

## Public Functions

| QAudioFormat(const QAudioFormat &other)
| QAudioFormat()
| ~QAudioFormat()
int | bytesPerFrame() const
int | bytesPerSample() const
ChannelConfig | channelConfig() const
int | channelCount() const
bool | isValid() const
SampleFormat | sampleFormat() const
int | sampleRate() const
void | setChannelCount(int channels)
void | setSampleFormat(SampleFormat format)
void | setSampleRate(int samplerate)

## Static Public Members

ChannelConfig | channelConfig(Args... channels)

## Related Non-Members

bool | operator!=(const QAudioFormat &a, const QAudioFormat &b)
bool | operator==(const QAudioFormat &a, const QAudioFormat &b)

## Detailed Description

An audio format specifies how data in a raw audio stream is arranged. For example, how the stream is to be interpreted.

QAudioFormat contains parameters that specify how the audio sample data is arranged. These are the frequency, the number of channels, and the sample format. The following table describes these in more detail.

Parameter | Description
--- | ---
Sample Rate | Samples per second of audio data in Hertz.
Number of channels | The number of audio channels (typically one for mono or two for stereo). These are the amount of consecutive samples that together form one frame in the stream
Sample format | The format of the audio samples in the stream

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

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::AudioChannelPosition

Describes the possible audio channel positions. These follow the standard definition used in the 22.2 surround sound configuration.

Constant | Value | Description
--- | --- | ---
`QAudioFormat::UnknownPosition` | `0` | Unknown position
`QAudioFormat::FrontLeft` | `1` |
`QAudioFormat::FrontRight` | `2` |
`QAudioFormat::FrontCenter` | `3` |
`QAudioFormat::LFE` | `4` | Low Frequency Effect channel (Subwoofer)
`QAudioFormat::BackLeft` | `5` |
`QAudioFormat::BackRight` | `6` |
`QAudioFormat::FrontLeftOfCenter` | `7` |
`QAudioFormat::FrontRightOfCenter` | `8` |
`QAudioFormat::BackCenter` | `9` |
`QAudioFormat::LFE2` | `19` |
`QAudioFormat::SideLeft` | `10` |
`QAudioFormat::SideRight` | `11` |
`QAudioFormat::TopFrontLeft` | `13` |
`QAudioFormat::TopFrontRight` | `15` |
`QAudioFormat::TopFrontCenter` | `14` |
`QAudioFormat::TopCenter` | `12` |
`QAudioFormat::TopBackLeft` | `16` |
`QAudioFormat::TopBackRight` | `18` |
`QAudioFormat::TopSideLeft` | `20` |
`QAudioFormat::TopSideRight` | `21` |
`QAudioFormat::TopBackCenter` | `17` |
`QAudioFormat::BottomFrontCenter` | `22` |
`QAudioFormat::BottomFrontLeft` | `23` |
`QAudioFormat::BottomFrontRight` | `24` |

### enum QAudioFormat::ChannelConfig

This enum describes a standardized audio channel layout. The most common configurations are Mono, Stereo, 2.1 (stereo plus low frequency), 5.1 surround, and 7.1 surround configurations.

Constant | Value | Description
--- | --- | ---
`QAudioFormat::ChannelConfigUnknown` | `0` | The channel configuration is not known.
`QAudioFormat::ChannelConfigMono` | `QtPrivate::channelConfig(FrontCenter)` | The audio has one Center channel.
`QAudioFormat::ChannelConfigStereo` | `QtPrivate::channelConfig(FrontLeft, FrontRight)` | The audio has two channels, Left and Right.
`QAudioFormat::ChannelConfig2Dot1` | `QtPrivate::channelConfig(FrontLeft, FrontRight, LFE)` | The audio has three channels, Left, Right and LFE (low frequency effect).
`QAudioFormat::ChannelConfig3Dot0` | `QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter)` | The audio has three channels, Left, Right, and Center.
`QAudioFormat::ChannelConfig3Dot1` | `QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE)` | The audio has four channels, Left, Right, Center, and LFE (low frequency effect).
`QAudioFormat::ChannelConfigSurround5Dot0` | `QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, BackLeft, BackRight)` | The audio has five channels, Left, Right, Center, BackLeft, and BackRight.
`QAudioFormat::ChannelConfigSurround5Dot1` | `QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE, BackLeft, BackRight)` | The audio has 6 channels, Left, Right, Center, LFE, BackLeft, and BackRight.
`QAudioFormat::ChannelConfigSurround7Dot0` | `QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, BackLeft, BackRight, SideLeft, SideRight)` | The audio has 7 channels, Left, Right, Center, BackLeft, BackRight, SideLeft, and SideRight.
`QAudioFormat::ChannelConfigSurround7Dot1` | `QtPrivate::channelConfig(FrontLeft, FrontRight, FrontCenter, LFE, BackLeft, BackRight, SideLeft, SideRight)` | The audio has 8 channels, Left, Right, Center, LFE, BackLeft, BackRight, SideLeft, and SideRight.

### enum QAudioFormat::SampleFormat

Qt will always expect and use samples in the endianness of the host platform. When processing audio data from external sources yourself, ensure you convert them to the correct endianness before writing them to a QAudioSink or QAudioBuffer.

Constant | Value | Description
--- | --- | ---
`QAudioFormat::Unknown` | `0` | Not Set
`QAudioFormat::UInt8` | `1` | Samples are unsigned 8 bit signed integers
`QAudioFormat::Int16` | `2` | Samples are 16 bit signed integers
`QAudioFormat::Int32` | `3` | Samples are 32 bit signed integers
`QAudioFormat::Float` | `4` | Samples are floats

## Member Function Documentation

### `[default]` QAudioFormat::QAudioFormat(const QAudioFormat &other)

Construct a new audio format using other.

### `[default]` QAudioFormat::QAudioFormat()

Constructs a new audio format.

Values are initialized as follows:

- sampleRate() = 0
- channelCount() = 0
- sampleFormat() = QAudioFormat::Unknown

### `[default]` QAudioFormat::~QAudioFormat()

Destroy this audio format.

### 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::bytesPerSample() const

Returns the number of bytes required to represent one sample in this format.

Returns 0 if this format is invalid.

### `[static]` template <typename Args> ChannelConfig QAudioFormat::channelConfig(Args... channels)

Returns the current channel configuration for the given channels.

### ChannelConfig QAudioFormat::channelConfig() const

Returns the current channel configuration.

### int QAudioFormat::channelCount() const

Returns the current channel count value.

See also setChannelCount().

### bool QAudioFormat::isValid() const

Returns `true` if all of the parameters are valid.

### SampleFormat QAudioFormat::sampleFormat() const

Returns the current sample format.

See also setSampleFormat().

### int QAudioFormat::sampleRate() const

Returns the current sample rate in Hertz.

See also setSampleRate().

### void QAudioFormat::setChannelCount(int channels)

Sets the channel count to channels. Setting this also sets the channel config to ChannelConfigUnknown.

See also channelCount().

### void QAudioFormat::setSampleFormat(SampleFormat format)

Sets the sample format to format.

See also sampleFormat() and QAudioFormat::SampleFormat.

### void QAudioFormat::setSampleRate(int samplerate)

Sets the sample rate to samplerate in Hertz.

See also sampleRate().

## Related Non-Members

### bool operator!=(const QAudioFormat &a, const QAudioFormat &b)

Returns `true` if audio format a is not equal to b, otherwise returns `false`.

### bool operator==(const QAudioFormat &a, const QAudioFormat &b)

Returns `true` if audio format a is equal to b, otherwise returns `false`.