QAudioFormat#

The QAudioFormat class stores audio stream parameter information. More

Inheritance diagram of PySide6.QtMultimedia.QAudioFormat

Synopsis#

Functions#

Static functions#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

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).

class PySide6.QtMultimedia.QAudioFormat#
PySide6.QtMultimedia.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

Description

QAudioFormat.Unknown

Not Set

QAudioFormat.UInt8

Samples are unsigned 8 bit signed integers

QAudioFormat.Int16

Samples are 16 bit signed integers

QAudioFormat.Int32

Samples are 32 bit signed integers

QAudioFormat.Float

Samples are floats

New in version 6.1.

PySide6.QtMultimedia.QAudioFormat.AudioChannelPosition#

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

Constant

Description

QAudioFormat.UnknownPosition

Unknown position

QAudioFormat.FrontLeft

QAudioFormat.FrontRight

QAudioFormat.FrontCenter

QAudioFormat.LFE

Low Frequency Effect channel (Subwoofer)

QAudioFormat.BackLeft

QAudioFormat.BackRight

QAudioFormat.FrontLeftOfCenter

QAudioFormat.FrontRightOfCenter

QAudioFormat.BackCenter

QAudioFormat.LFE2

QAudioFormat.SideLeft

QAudioFormat.SideRight

QAudioFormat.TopFrontLeft

QAudioFormat.TopFrontRight

QAudioFormat.TopFrontCenter

QAudioFormat.TopCenter

QAudioFormat.TopBackLeft

QAudioFormat.TopBackRight

QAudioFormat.TopSideLeft

QAudioFormat.TopSideRight

QAudioFormat.TopBackCenter

QAudioFormat.BottomFrontCenter

QAudioFormat.BottomFrontLeft

QAudioFormat.BottomFrontRight

New in version 6.2.

PySide6.QtMultimedia.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

Description

QAudioFormat.ChannelConfigUnknown

The channel configuration is not known.

QAudioFormat.ChannelConfigMono

The audio has one Center channel.

QAudioFormat.ChannelConfigStereo

The audio has two channels, Left and Right.

QAudioFormat.ChannelConfig2Dot1

The audio has three channels, Left, Right and LFE (low frequency effect).

QAudioFormat.ChannelConfig3Dot0

The audio has three channels, Left, Right, and Center.

QAudioFormat.ChannelConfig3Dot1

The audio has four channels, Left, Right, Center, and LFE (low frequency effect).

QAudioFormat.ChannelConfigSurround5Dot0

The audio has five channels, Left, Right, Center, BackLeft , and BackRight .

QAudioFormat.ChannelConfigSurround5Dot1

The audio has 6 channels, Left, Right, Center, LFE, BackLeft , and BackRight .

QAudioFormat.ChannelConfigSurround7Dot0

The audio has 7 channels, Left, Right, Center, BackLeft , BackRight , SideLeft , and SideRight .

QAudioFormat.ChannelConfigSurround7Dot1

The audio has 8 channels, Left, Right, Center, LFE, BackLeft , BackRight , SideLeft , and SideRight .

PySide6.QtMultimedia.QAudioFormat.NChannelPositions#
PySide6.QtMultimedia.QAudioFormat.bytesForDuration(microseconds)#
Parameters:

microseconds – int

Return type:

qint32

Returns the number of bytes required for this audio format for microseconds.

Returns 0 if this format is not valid.

Note that some rounding may occur if microseconds is not an exact fraction of the sampleRate() .

PySide6.QtMultimedia.QAudioFormat.bytesForFrames(frameCount)#
Parameters:

frameCountqint32

Return type:

qint32

Returns the number of bytes required for frameCount frames of this format.

Returns 0 if this format is not valid.

PySide6.QtMultimedia.QAudioFormat.bytesPerFrame()#
Return type:

int

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.

PySide6.QtMultimedia.QAudioFormat.bytesPerSample()#
Return type:

int

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

Returns 0 if this format is invalid.

PySide6.QtMultimedia.QAudioFormat.channelConfig()#
Return type:

ChannelConfig

Returns the current channel configuration.

PySide6.QtMultimedia.QAudioFormat.channelCount()#
Return type:

int

Returns the current channel count value.

PySide6.QtMultimedia.QAudioFormat.channelOffset(channel)#
Parameters:

channelAudioChannelPosition

Return type:

int

Returns the position of a certain audio channel inside an audio frame for the given format. Returns -1 if the channel does not exist for this format or the channel configuration is unknown.

static PySide6.QtMultimedia.QAudioFormat.defaultChannelConfigForChannelCount(channelCount)#
Parameters:

channelCount – int

Return type:

ChannelConfig

Returns a default channel configuration for channelCount.

Default configurations are defined for up to 8 channels, and correspond to standard Mono, Stereo and Surround configurations. For higher channel counts, this simply uses the first channelCount audio channels defined in AudioChannelPosition .

PySide6.QtMultimedia.QAudioFormat.durationForBytes(byteCount)#
Parameters:

byteCountqint32

Return type:

int

Returns the number of microseconds represented by bytes in this format.

Returns 0 if this format is not valid.

Note that some rounding may occur if bytes is not an exact multiple of the number of bytes per frame.

PySide6.QtMultimedia.QAudioFormat.durationForFrames(frameCount)#
Parameters:

frameCountqint32

Return type:

int

Return the number of microseconds represented by frameCount frames in this format.

PySide6.QtMultimedia.QAudioFormat.framesForBytes(byteCount)#
Parameters:

byteCountqint32

Return type:

qint32

Returns the number of frames represented by byteCount in this format.

Note that some rounding may occur if byteCount is not an exact multiple of the number of bytes per frame.

Each frame has one sample per channel.

PySide6.QtMultimedia.QAudioFormat.framesForDuration(microseconds)#
Parameters:

microseconds – int

Return type:

qint32

Returns the number of frames required to represent microseconds in this format.

Note that some rounding may occur if microseconds is not an exact fraction of the sampleRate() .

PySide6.QtMultimedia.QAudioFormat.isValid()#
Return type:

bool

Returns true if all of the parameters are valid.

PySide6.QtMultimedia.QAudioFormat.normalizedSampleValue(sample)#
Parameters:

samplevoid

Return type:

float

Normalizes the sample value to a number between -1 and 1. The method depends on the QaudioFormat.

PySide6.QtMultimedia.QAudioFormat.__ne__(b)#
Parameters:

bPySide6.QtMultimedia.QAudioFormat

Return type:

bool

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

PySide6.QtMultimedia.QAudioFormat.__eq__(b)#
Parameters:

bPySide6.QtMultimedia.QAudioFormat

Return type:

bool

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

PySide6.QtMultimedia.QAudioFormat.sampleFormat()#
Return type:

SampleFormat

Returns the current sample format.

PySide6.QtMultimedia.QAudioFormat.sampleRate()#
Return type:

int

Returns the current sample rate in Hertz.

See also

setSampleRate()

PySide6.QtMultimedia.QAudioFormat.setChannelConfig(config)#
Parameters:

configChannelConfig

Sets the channel configuration to config.

Sets the channel configuration of the audio format to one of the standard audio channel configurations.

Note

that this will also modify the channel count.

See also

channelConfig()

PySide6.QtMultimedia.QAudioFormat.setChannelCount(channelCount)#
Parameters:

channelCount – int

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

See also

channelCount()

PySide6.QtMultimedia.QAudioFormat.setSampleFormat(f)#
Parameters:

fSampleFormat

Sets the sample format to format.

See also

sampleFormat() SampleFormat

PySide6.QtMultimedia.QAudioFormat.setSampleRate(sampleRate)#
Parameters:

sampleRate – int

Sets the sample rate to samplerate in Hertz.

See also

sampleRate()