QAudioEngine#
QAudioEngine
manages a three dimensional sound field. More…
Synopsis#
Functions#
def
distanceScale
()def
masterVolume
()def
outputDevice
()def
outputMode
()def
paused
()def
roomEffectsEnabled
()def
sampleRate
()def
setDistanceScale
(scale)def
setMasterVolume
(volume)def
setOutputDevice
(device)def
setOutputMode
(mode)def
setPaused
(paused)def
setRoomEffectsEnabled
(enabled)
Slots#
Signals#
def
distanceScaleChanged
()def
masterVolumeChanged
()def
outputDeviceChanged
()def
outputModeChanged
()def
pausedChanged
()
Detailed Description#
You can use an instance of QAudioEngine
to manage a sound field in three dimensions. A sound field is defined by several QSpatialSound
objects that define a sound at a specified location in 3D space. You can also add stereo overlays using QAmbientSound
.
You can use QAudioListener
to define the position of the person listening to the sound field relative to the sound sources. Sound sources will be less audible if the listener is further away from source. They will also get mapped to the corresponding loudspeakers depending on the direction between listener and source.
QAudioEngine
offers two output modes. The first mode renders the sound field to a set of speakers, either a stereo speaker pair or a surround configuration. The second mode provides an immersive 3D sound experience when using headphones.
Perception of sound localization is driven mainly by two factors. The first factor is timing differences of the sound waves between left and right ear. The second factor comes from various ways how sounds coming from different direcations create different types of reflections from our ears and heads. See https://en.wikipedia.org/wiki/Sound_localization for more details.
The spatial audio engine emulates those timing differences and reflections through Head related transfer functions (HRTF, see https://en.wikipedia.org/wiki/Head-related_transfer_function). The functions used emulates those effects for an average persons ears and head. It provides a good and immersive 3D sound localization experience for most persons when using headphones.
The engine is rather versatile allowing you to define room properties and reverb settings to emulate different types of rooms.
Sound sources can also be occluded dampening the sound coming from those sources.
The audio engine uses a coordinate system that is in centimeters by default. The axes are aligned with the typical coordinate system used in 3D. Positive x points to the right, positive y points up and positive z points backwards.
- class PySide6.QtSpatialAudio.QAudioEngine#
PySide6.QtSpatialAudio.QAudioEngine(parent)
PySide6.QtSpatialAudio.QAudioEngine(sampleRate[, parent=None])
- Parameters
sampleRate – int
parent –
PySide6.QtCore.QObject
- PySide6.QtSpatialAudio.QAudioEngine.OutputMode#
Constant
Description
QAudioEngine.Surround
Map the sounds to the loudspeaker configuration of the output device. This is normally a stereo or surround speaker setup.
QAudioEngine.Stereo
Map the sounds to the stereo loudspeaker configuration of the output device. This will ignore any additional speakers and only use the left and right channels to create a stero rendering of the sound field.
QAudioEngine.Headphone
Use Headphone spatialization to create a 3D audio effect when listening to the sound field through headphones
- PySide6.QtSpatialAudio.QAudioEngine.DistanceScaleCentimeter#
- PySide6.QtSpatialAudio.QAudioEngine.DistanceScaleMeter#
- PySide6.QtSpatialAudio.QAudioEngine.distanceScale()#
- Return type
float
Defines the scale of the coordinate system being used by the spatial audio engine. By default, all units are in centimeters, in line with the default units being used by Qt Quick 3D.
Set the distance scale to QAudioEngine::DistanceScaleMeter to get units in meters.
- PySide6.QtSpatialAudio.QAudioEngine.distanceScaleChanged()#
- PySide6.QtSpatialAudio.QAudioEngine.masterVolume()#
- Return type
float
Sets or returns volume being used to render the sound field.
- PySide6.QtSpatialAudio.QAudioEngine.masterVolumeChanged()#
- PySide6.QtSpatialAudio.QAudioEngine.outputDevice()#
- Return type
Sets or returns the device that is being used for playing the sound field.
- PySide6.QtSpatialAudio.QAudioEngine.outputDeviceChanged()#
- PySide6.QtSpatialAudio.QAudioEngine.outputMode()#
- Return type
Sets or retrieves the current output mode of the engine.
See also
OutputMode
- PySide6.QtSpatialAudio.QAudioEngine.outputModeChanged()#
- PySide6.QtSpatialAudio.QAudioEngine.pause()#
- PySide6.QtSpatialAudio.QAudioEngine.paused()#
- Return type
bool
Pauses the spatial audio engine.
- PySide6.QtSpatialAudio.QAudioEngine.pausedChanged()#
- PySide6.QtSpatialAudio.QAudioEngine.resume()#
- PySide6.QtSpatialAudio.QAudioEngine.roomEffectsEnabled()#
- Return type
bool
Returns true if room effects are enabled.
See also
- PySide6.QtSpatialAudio.QAudioEngine.sampleRate()#
- Return type
int
Returns the sample rate the engine has been configured with.
- PySide6.QtSpatialAudio.QAudioEngine.setDistanceScale(scale)#
- Parameters
scale – float
Defines the scale of the coordinate system being used by the spatial audio engine. By default, all units are in centimeters, in line with the default units being used by Qt Quick 3D.
Set the distance scale to QAudioEngine::DistanceScaleMeter to get units in meters.
- PySide6.QtSpatialAudio.QAudioEngine.setMasterVolume(volume)#
- Parameters
volume – float
Sets or returns volume being used to render the sound field.
- PySide6.QtSpatialAudio.QAudioEngine.setOutputDevice(device)#
- Parameters
device –
PySide6.QtMultimedia.QAudioDevice
Sets or returns the device that is being used for playing the sound field.
- PySide6.QtSpatialAudio.QAudioEngine.setOutputMode(mode)#
- Parameters
mode –
OutputMode
Sets or retrieves the current output mode of the engine.
See also
OutputMode
- PySide6.QtSpatialAudio.QAudioEngine.setPaused(paused)#
- Parameters
paused – bool
Pauses the spatial audio engine.
- PySide6.QtSpatialAudio.QAudioEngine.setRoomEffectsEnabled(enabled)#
- Parameters
enabled – bool
Enables room effects such as echos and reverb.
Enables room effects if enabled
is true. Room effects will only apply if you create one or more QAudioRoom
objects and the listener is inside at least one of the rooms. If the listener is inside multiple rooms, the room with the smallest volume will be used.
See also
- PySide6.QtSpatialAudio.QAudioEngine.start()#
Starts the engine.
- PySide6.QtSpatialAudio.QAudioEngine.stop()#
Stops the engine.