Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquick3dspatialsound.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
5#include "qspatialsound.h"
6#include <QAudioFormat>
7#include <qdir.h>
8#include <QQmlContext>
9#include <QQmlFile>
10
12
30{
32
33 connect(this, &QQuick3DNode::scenePositionChanged, this, &QQuick3DSpatialSound::updatePosition);
34 connect(this, &QQuick3DNode::sceneRotationChanged, this, &QQuick3DSpatialSound::updateRotation);
47}
48
53
60{
61 return m_sound->source();
62}
63
65{
66 const QQmlContext *context = qmlContext(this);
67 QUrl url;
68 if (context) {
69 url = context->resolvedUrl(source);
70 } else {
73 }
74 m_sound->setSource(url);
75}
76
86{
87 m_sound->setVolume(volume);
88}
89
91{
92 return m_sound->volume();
93}
94
118
123
132{
133 m_sound->setSize(min);
134}
135
137{
138 return m_sound->size();
139}
140
149{
150 m_sound->setDistanceCutoff(max);
151}
152
154{
155 return m_sound->distanceCutoff();
156}
157
165{
166 m_sound->setManualAttenuation(attenuation);
167}
168
170{
171 return m_sound->manualAttenuation();
172}
173
183{
184 m_sound->setOcclusionIntensity(occlusion);
185}
186
188{
189 return m_sound->occlusionIntensity();
190}
191
205
207{
208 return m_sound->directivity();
209}
210
223
225{
226 return m_sound->directivityOrder();
227}
228
237{
238 m_sound->setNearFieldGain(gain);
239}
240
242{
243 return m_sound->nearFieldGain();
244}
245
246void QQuick3DSpatialSound::updatePosition()
247{
248 m_sound->setPosition(scenePosition());
249}
250
251void QQuick3DSpatialSound::updateRotation()
252{
253 m_sound->setRotation(sceneRotation());
254}
255
265{
266 return m_sound->loops();
267}
268
270{
271 m_sound->setLoops(loops);
272}
273
283{
284 return m_sound->autoPlay();
285}
286
288{
289 m_sound->setAutoPlay(autoPlay);
290}
291
298{
299 m_sound->play();
300}
301
308{
309 m_sound->pause();
310}
311
319{
320 m_sound->stop();
321}
322
static QString currentPath()
Returns the absolute path of the application's current directory.
Definition qdir.cpp:2054
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
static QAudioEngine * getEngine()
QVector3D scenePosition
void sceneRotationChanged()
void scenePositionChanged()
QQuaternion sceneRotation
void setDirectivity(float alpha)
\qmlproperty float SpatialSound::directivity
QQuick3DSpatialSound()
\qmltype SpatialSound \inqmlmodule QtQuick3D.SpatialAudio
void setAutoPlay(bool autoPlay)
void manualAttenuationChanged()
void setManualAttenuation(float attenuation)
\qmlproperty float SpatialSound::manualAttenuation
void pause()
\qmlmethod SpatialSound::pause()
void play()
\qmlmethod SpatialSound::play()
void occlusionIntensityChanged()
void setDistanceCutoff(float max)
\qmlproperty float SpatialSound::distanceCutoff
void setDirectivityOrder(float alpha)
\qmlproperty float SpatialSound::directivityOrder
void setSize(float min)
\qmlproperty float SpatialSound::size
void stop()
\qmlmethod SpatialSound::stop()
void setDistanceModel(DistanceModel model)
\qmlproperty enumeration SpatialSound::distanceModel
void setVolume(float volume)
\qmlproperty float SpatialSound::volume
void directivityOrderChanged()
void setOcclusionIntensity(float occlusion)
\qmlproperty float SpatialSound::occlusionIntensity
void setNearFieldGain(float gain)
\qmlproperty float SpatialSound::nearFieldGain
\inmodule QtSpatialAudio
void stop()
Stops sound playback and resets the current position and current loop count to 0.
void setVolume(float volume)
void setSize(float size)
void directivityOrderChanged()
void manualAttenuationChanged()
void pause()
Pauses sound playback.
void setPosition(QVector3D pos)
void setNearFieldGain(float gain)
void play()
Starts playing back the sound.
void setDistanceModel(DistanceModel model)
float nearFieldGain
Defines the near field gain for the sound source.
void autoPlayChanged()
float manualAttenuation
Defines a manual attenuation factor if \l distanceModel is set to QSpatialSound::DistanceModel::Manua...
void occlusionIntensityChanged()
DistanceModel distanceModel
Defines distance model for this sound source.
void setManualAttenuation(float attenuation)
void setSource(const QUrl &url)
float directivity
Defines the directivity of the sound source.
void setLoops(int loops)
void distanceModelChanged()
void setDirectivityOrder(float alpha)
void volumeChanged()
QUrl source
The source file for the sound to be played.
float directivityOrder
Defines the order of the directivity of the sound source.
void setDistanceCutoff(float cutoff)
void setAutoPlay(bool autoPlay)
void setDirectivity(float alpha)
void sourceChanged()
bool autoPlay
Determines whether the sound should automatically start playing when a source gets specified.
void setOcclusionIntensity(float occlusion)
void distanceCutoffChanged()
float size
Defines the size of the sound source.
int loops
Determines how many times the sound is played before the player stops.
void nearFieldGainChanged()
void setRotation(const QQuaternion &q)
float volume
Defines the volume of the sound.
float occlusionIntensity
Defines how much the object is occluded.
float distanceCutoff
Defines a distance beyond which sound coming from the source will cutoff.
void loopsChanged()
DistanceModel
Defines how the volume of the sound scales with distance to the listener.
void sizeChanged()
void directivityChanged()
\inmodule QtCore
Definition qurl.h:94
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition qurl.cpp:3368
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition qurl.cpp:2725
Combined button and popup list for selecting options.
static void * context
GLsizei GLsizei GLchar * source
GLfloat GLfloat GLfloat alpha
Definition qopenglext.h:418
QQmlContext * qmlContext(const QObject *obj)
Definition qqml.cpp:75
QSqlQueryModel * model
[16]
QUrl url("example.com")
[constructor-url-reference]