- class QAudioFormat#
The
QAudioFormat
class stores audio stream parameter information. More…Synopsis#
Methods#
def
bytesForFrames()
def
bytesPerFrame()
def
bytesPerSample()
def
channelConfig()
def
channelCount()
def
channelOffset()
def
framesForBytes()
def
isValid()
def
__ne__()
def
__eq__()
def
sampleFormat()
def
sampleRate()
def
setSampleRate()
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
orQAudioSink
to allow you to specify the parameters of the audio stream being read or written, or withQAudioBuffer
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 theQAudioDevice
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 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
orQAudioBuffer
.Constant
Description
QAudioFormat.Unknown
Not Set
QAudioFormat.UInt8
Samples are 8 bit unsigned 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.
- class 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.
- class 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
, andBackRight
.QAudioFormat.ChannelConfigSurround5Dot1
The audio has 6 channels, Left, Right, Center, LFE,
BackLeft
, andBackRight
.QAudioFormat.ChannelConfigSurround7Dot0
The audio has 7 channels, Left, Right, Center,
BackLeft
,BackRight
,SideLeft
, andSideRight
.QAudioFormat.ChannelConfigSurround7Dot1
The audio has 8 channels, Left, Right, Center, LFE,
BackLeft
,BackRight
,SideLeft
, andSideRight
.
- PySide6.QtMultimedia.QAudioFormat.NChannelPositions#
- bytesForDuration(microseconds)#
- Parameters:
microseconds – int
- Return type:
int
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 thesampleRate()
.See also
- bytesForFrames(frameCount)#
- Parameters:
frameCount – int
- Return type:
int
Returns the number of bytes required for
frameCount
frames of this format.Returns 0 if this format is not valid.
See also
- 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.
- bytesPerSample()#
- Return type:
int
Returns the number of bytes required to represent one sample in this format.
Returns 0 if this format is invalid.
- channelConfig()#
- Return type:
Returns the current channel configuration.
- channelCount()#
- Return type:
int
Returns the current channel count value.
See also
- channelOffset(channel)#
- Parameters:
channel –
AudioChannelPosition
- 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 defaultChannelConfigForChannelCount(channelCount)#
- Parameters:
channelCount – int
- Return type:
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 inAudioChannelPosition
.- durationForBytes(byteCount)#
- Parameters:
byteCount – int
- 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.See also
- durationForFrames(frameCount)#
- Parameters:
frameCount – int
- Return type:
int
Return the number of microseconds represented by
frameCount
frames in this format.- framesForBytes(byteCount)#
- Parameters:
byteCount – int
- Return type:
int
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.
See also
- framesForDuration(microseconds)#
- Parameters:
microseconds – int
- Return type:
int
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 thesampleRate()
.- isValid()#
- Return type:
bool
Returns
true
if all of the parameters are valid.- normalizedSampleValue(sample)#
- Parameters:
sample –
void
- Return type:
float
Normalizes the
sample
value to a number between -1 and 1. The method depends on the QaudioFormat.- __ne__(b)#
- Parameters:
b –
QAudioFormat
- Return type:
bool
Returns
true
if audio formata
is not equal tob
, otherwise returnsfalse
.- __eq__(b)#
- Parameters:
b –
QAudioFormat
- Return type:
bool
Returns
true
if audio formata
is equal tob
, otherwise returnsfalse
.- sampleFormat()#
- Return type:
Returns the current sample format.
See also
- sampleRate()#
- Return type:
int
Returns the current sample rate in Hertz.
See also
- setChannelConfig(config)#
- Parameters:
config –
ChannelConfig
Sets the channel configuration to
config
.Sets the channel configuration of the audio format to one of the standard audio channel configurations.
- setChannelCount(channelCount)#
- Parameters:
channelCount – int
Sets the channel count to
channels
. Setting this also sets the channel config toChannelConfigUnknown
.See also
- setSampleFormat(f)#
- Parameters:
f –
SampleFormat
Sets the sample format to
format
.See also
- setSampleRate(sampleRate)#
- Parameters:
sampleRate – int
Sets the sample rate to
samplerate
in Hertz.See also