A sound object in 3D space. 更多...
头: | #include <QSpatialSound> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS SpatialAudio)
target_link_libraries(mytarget PRIVATE Qt6::SpatialAudio) |
qmake: | QT += spatialaudio |
继承: | QObject |
enum class | DistanceModel { Logarithmic, Linear, ManualAttenuation } |
enum | Loops { Infinite, Once } |
|
|
QSpatialSound (QAudioEngine * engine ) | |
virtual | ~QSpatialSound () |
bool | autoPlay () const |
float | directivity () const |
float | directivityOrder () const |
float | distanceCutoff () const |
QSpatialSound::DistanceModel | distanceModel () const |
QAudioEngine * | engine () const |
int | loops () const |
float | manualAttenuation () const |
float | nearFieldGain () const |
float | occlusionIntensity () const |
QVector3D | position () const |
QQuaternion | rotation () const |
void | setAutoPlay (bool autoPlay ) |
void | setDirectivity (float alpha ) |
void | setDirectivityOrder (float alpha ) |
void | setDistanceCutoff (float cutoff ) |
void | setDistanceModel (QSpatialSound::DistanceModel model ) |
void | setLoops (int loops ) |
void | setManualAttenuation (float attenuation ) |
void | setNearFieldGain (float gain ) |
void | setOcclusionIntensity (float occlusion ) |
void | setPosition (QVector3D pos ) |
void | setRotation (const QQuaternion & q ) |
void | setSize (float size ) |
void | setSource (const QUrl & url ) |
void | setVolume (float volume ) |
float | size () const |
QUrl | source () const |
float | volume () const |
void | pause () |
void | play () |
void | stop () |
void | autoPlayChanged () |
void | directivityChanged () |
void | directivityOrderChanged () |
void | distanceCutoffChanged () |
void | distanceModelChanged () |
void | loopsChanged () |
void | manualAttenuationChanged () |
void | nearFieldGainChanged () |
void | occlusionIntensityChanged () |
void | positionChanged () |
void | rotationChanged () |
void | sizeChanged () |
void | sourceChanged () |
void | volumeChanged () |
QSpatialSound represents an audible object in 3D space. You can define its position and orientation in space, set the sound it is playing and define a volume for the object.
The object can have different attenuation behavior, emit sound mainly in one direction or spherically, and behave as if occluded by some other object.
Defines how the volume of the sound scales with distance to the listener.
常量 | 值 | 描述 |
---|---|---|
QSpatialSound::DistanceModel::Logarithmic
|
0
|
Volume decreases logarithmically with distance. |
QSpatialSound::DistanceModel::Linear
|
1
|
Volume decreases linearly with distance. |
QSpatialSound::DistanceModel::ManualAttenuation
|
2
|
Attenuation is defined manually using the manualAttenuation 特性。 |
Lets you control the sound playback loop using the following values:
常量 | 值 | 描述 |
---|---|---|
QSpatialSound::Infinite
|
-1
|
Playback infinitely |
QSpatialSound::Once
|
1
|
Playback once |
Determines whether the sound should automatically start playing when a source gets specified.
默认值为
true
.
访问函数:
bool | autoPlay () const |
void | setAutoPlay (bool autoPlay ) |
通知程序信号:
void | autoPlayChanged () |
Defines the directivity of the sound source. A value of 0 implies that the sound is emitted equally in all directions, while a value of 1 implies that the source mainly emits sound in the forward direction.
Valid values are between 0 and 1, the default is 0.
访问函数:
float | directivity () const |
void | setDirectivity (float alpha ) |
通知程序信号:
void | directivityChanged () |
Defines the order of the directivity of the sound source. A higher order implies a sharper localization of the sound cone.
The minimum value and default for this property is 1.
访问函数:
float | directivityOrder () const |
void | setDirectivityOrder (float alpha ) |
通知程序信号:
void | directivityOrderChanged () |
Defines a distance beyond which sound coming from the source will cutoff. If the listener is further away from the sound object than the cutoff distance it won't be audible anymore.
访问函数:
float | distanceCutoff () const |
void | setDistanceCutoff (float cutoff ) |
通知程序信号:
void | distanceCutoffChanged () |
Defines distance model for this sound source. The volume starts scaling down from size to distanceCutoff . The volume is constant for distances smaller than size and zero for distances larger than the cutoff distance.
访问函数:
QSpatialSound::DistanceModel | distanceModel () const |
void | setDistanceModel (QSpatialSound::DistanceModel model ) |
通知程序信号:
void | distanceModelChanged () |
另请参阅 QSpatialSound::DistanceModel .
Determines how many times the sound is played before the player stops. Set to QSpatialSound::Infinite to play the current sound in a loop forever.
默认值为
1
.
访问函数:
int | loops () const |
void | setLoops (int loops ) |
通知程序信号:
void | loopsChanged () |
Defines a manual attenuation factor if distanceModel 被设为 QSpatialSound::DistanceModel::ManualAttenuation .
访问函数:
float | manualAttenuation () const |
void | setManualAttenuation (float attenuation ) |
通知程序信号:
void | manualAttenuationChanged () |
Defines the near field gain for the sound source. Valid values are between 0 and 1. A near field gain of 1 will raise the volume of the sound signal by approx 20 dB for distances very close to the listener.
访问函数:
float | nearFieldGain () const |
void | setNearFieldGain (float gain ) |
通知程序信号:
void | nearFieldGainChanged () |
Defines how much the object is occluded. 0 implies the object is not occluded at all, 1 implies the sound source is fully occluded by another object.
A fully occluded object will still be audible, but especially higher frequencies will be dampened. In addition, the object will still participate in generating reverb and reflections in the room.
Values larger than 1 are possible to further dampen the direct sound coming from the source.
默认为 0。
访问函数:
float | occlusionIntensity () const |
void | setOcclusionIntensity (float occlusion ) |
通知程序信号:
void | occlusionIntensityChanged () |
Defines the position of the sound source in 3D space. Units are in centimeters by default.
访问函数:
QVector3D | 位置 () const |
void | setPosition (QVector3D pos ) |
通知程序信号:
void | positionChanged () |
另请参阅 QAudioEngine::distanceScale .
Defines the orientation of the sound source in 3D space.
访问函数:
QQuaternion | rotation () const |
void | setRotation (const QQuaternion & q ) |
通知程序信号:
void | rotationChanged () |
Defines the size of the sound source. If the listener is closer to the sound object than the size, volume will stay constant. The size is also used to for occlusion calculations, where large sources can be partially occluded by a wall.
访问函数:
float | size () const |
void | setSize (float size ) |
通知程序信号:
void | sizeChanged () |
The source file for the sound to be played.
访问函数:
QUrl | source () const |
void | setSource (const QUrl & url ) |
通知程序信号:
void | sourceChanged () |
Defines the volume of the sound.
Values between 0 and 1 will attenuate the sound, while values above 1 provide an additional gain boost.
访问函数:
float | volume () const |
void | setVolume (float volume ) |
通知程序信号:
void | volumeChanged () |
[explicit]
QSpatialSound::
QSpatialSound
(
QAudioEngine
*
engine
)
Creates a spatial sound source for engine . The object can be placed in 3D space and will be louder the closer to the listener it is.
[virtual noexcept]
QSpatialSound::
~QSpatialSound
()
Destroys the sound source.
Returns the engine associated with this listener.
[slot]
void
QSpatialSound::
pause
()
Pauses sound playback. Calling play () will continue playback.
[slot]
void
QSpatialSound::
play
()
Starts playing back the sound. Does nothing if the sound is already playing.
[slot]
void
QSpatialSound::
stop
()
Stops sound playback and resets the current position and current loop count to 0. Calling play () will start playback at the beginning of the sound file.