summaryrefslogtreecommitdiffstats
path: root/src/multimediaquick3d
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2022-04-21 09:24:33 +0200
committerLars Knoll <lars.knoll@qt.io>2022-05-11 08:23:46 +0200
commit82943943820848b437fbc99c405bbb5169e880e1 (patch)
tree65936ec950b526a2865365959a4111c70bb836ea /src/multimediaquick3d
parent5f5b32f5b03c2c8a9dfc59cbc1fa82713eb6d259 (diff)
Add the Quick3D.SpatialAudio QML module
Also this has been developed outside of Qt Multimedia so far, but it makes sense to add it here. This does however introduce an optional dependency of this module to qt quick3d. Change-Id: I357505a5832976917414acc07ca0480a635af176 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimediaquick3d')
-rw-r--r--src/multimediaquick3d/CMakeLists.txt29
-rw-r--r--src/multimediaquick3d/qquick3dspatialaudioengine.cpp96
-rw-r--r--src/multimediaquick3d/qquick3dspatialaudioengine_p.h86
-rw-r--r--src/multimediaquick3d/qquick3dspatialaudiolistener.cpp67
-rw-r--r--src/multimediaquick3d/qquick3dspatialaudiolistener_p.h72
-rw-r--r--src/multimediaquick3d/qquick3dspatialaudiosoundsource.cpp181
-rw-r--r--src/multimediaquick3d/qquick3dspatialaudiosoundsource_p.h128
-rw-r--r--src/multimediaquick3d/qquick3dspatialaudiostereosource.cpp81
-rw-r--r--src/multimediaquick3d/qquick3dspatialaudiostereosource_p.h75
-rw-r--r--src/multimediaquick3d/qtquick3dsoundglobal_p.h62
-rw-r--r--src/multimediaquick3d/qtquick3dsoundtypes_p.h61
-rw-r--r--src/multimediaquick3d/quick3dspatialaudio_plugin.cpp71
12 files changed, 1009 insertions, 0 deletions
diff --git a/src/multimediaquick3d/CMakeLists.txt b/src/multimediaquick3d/CMakeLists.txt
new file mode 100644
index 000000000..d03192f77
--- /dev/null
+++ b/src/multimediaquick3d/CMakeLists.txt
@@ -0,0 +1,29 @@
+#####################################################################
+## Quick3D.Sound Module:
+#####################################################################
+
+qt_internal_add_qml_module(Quick3DSpatialAudioPrivate
+ URI "QtQuick3D.SpatialAudio"
+ VERSION "${PROJECT_VERSION}"
+ CLASS_NAME QQuick3DSpatialAudioModule
+ PLUGIN_TARGET quick3dspatialaudio
+ NO_GENERATE_PLUGIN_SOURCE
+ NO_PLUGIN_OPTIONAL
+ DEPENDENCIES QtQuick QtQuick3DPrivate QtMultimedia
+ CONFIG_MODULE_NAME quick3dspatialaudio
+ INTERNAL_MODULE
+ SOURCES
+ qquick3dspatialaudiolistener.cpp qquick3dspatialaudiolistener_p.h
+ qquick3dspatialaudiosoundsource.cpp qquick3dspatialaudiosoundsource_p.h
+ qquick3dspatialaudiostereosource.cpp qquick3dspatialaudiostereosource_p.h
+ qquick3dspatialaudioengine.cpp qquick3dspatialaudioengine_p.h
+ qtquick3dsoundglobal_p.h
+ qtquick3dsoundtypes_p.h
+ QML_FILES
+ PUBLIC_LIBRARIES
+ Qt::Quick3DPrivate
+ Qt::Multimedia
+ GENERATE_CPP_EXPORTS
+)
+
+target_sources(quick3dspatialaudio PRIVATE quick3dspatialaudio_plugin.cpp)
diff --git a/src/multimediaquick3d/qquick3dspatialaudioengine.cpp b/src/multimediaquick3d/qquick3dspatialaudioengine.cpp
new file mode 100644
index 000000000..80dd222cc
--- /dev/null
+++ b/src/multimediaquick3d/qquick3dspatialaudioengine.cpp
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Spatial Audio module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-NOGPL2$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qquick3dspatialaudioengine_p.h>
+
+QT_BEGIN_NAMESPACE
+
+static QSpatialAudioEngine *globalEngine = nullptr;
+
+QQuick3DSpatialAudioEngine::QQuick3DSpatialAudioEngine()
+{
+ auto *e = getEngine();
+ connect(e, &QSpatialAudioEngine::outputModeChanged, this, &QQuick3DSpatialAudioEngine::outputModeChanged);
+ connect(e, &QSpatialAudioEngine::outputDeviceChanged, this, &QQuick3DSpatialAudioEngine::outputDeviceChanged);
+ connect(e, &QSpatialAudioEngine::masterVolumeChanged, this, &QQuick3DSpatialAudioEngine::masterVolumeChanged);
+}
+
+QQuick3DSpatialAudioEngine::~QQuick3DSpatialAudioEngine()
+{
+}
+
+void QQuick3DSpatialAudioEngine::setOutputMode(OutputMode mode)
+{
+ globalEngine->setOutputMode(QSpatialAudioEngine::OutputMode(mode));
+}
+
+QQuick3DSpatialAudioEngine::OutputMode QQuick3DSpatialAudioEngine::outputMode() const
+{
+ return OutputMode(globalEngine->outputMode());
+}
+
+void QQuick3DSpatialAudioEngine::setOutputDevice(const QAudioDevice &device)
+{
+ globalEngine->setOutputDevice(device);
+}
+
+QAudioDevice QQuick3DSpatialAudioEngine::outputDevice() const
+{
+ return globalEngine->outputDevice();
+}
+
+void QQuick3DSpatialAudioEngine::setMasterVolume(float volume)
+{
+ globalEngine->setMasterVolume(volume);
+}
+
+float QQuick3DSpatialAudioEngine::masterVolume() const
+{
+ return globalEngine->masterVolume();
+}
+
+QSpatialAudioEngine *QQuick3DSpatialAudioEngine::getEngine()
+{
+ if (!globalEngine) {
+ globalEngine = new QSpatialAudioEngine;
+ globalEngine->start();
+ }
+ return globalEngine;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qquick3dspatialaudioengine_p.cpp"
diff --git a/src/multimediaquick3d/qquick3dspatialaudioengine_p.h b/src/multimediaquick3d/qquick3dspatialaudioengine_p.h
new file mode 100644
index 000000000..a2a856d0a
--- /dev/null
+++ b/src/multimediaquick3d/qquick3dspatialaudioengine_p.h
@@ -0,0 +1,86 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Spatial Audio module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-NOGPL2$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QQUICK3DENGINE_H
+#define QQUICK3DENGINE_H
+
+#include <private/qquick3dnode_p.h>
+#include <QtGui/qvector3d.h>
+#include <qspatialaudioengine.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuick3DSpatialAudioSoundSource;
+
+class QQuick3DSpatialAudioEngine : public QObject
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(SpatialAudioEngine)
+ Q_PROPERTY(OutputMode outputMode READ outputMode WRITE setOutputMode NOTIFY outputModeChanged)
+ Q_PROPERTY(QAudioDevice outputDevice READ outputDevice WRITE setOutputDevice NOTIFY outputDeviceChanged)
+ Q_PROPERTY(float masterVolume READ masterVolume WRITE setMasterVolume NOTIFY masterVolumeChanged)
+
+public:
+ // Keep in sync with QSpatialAudioEngine::OutputMode
+ enum OutputMode {
+ Stereo,
+ Headphone
+ };
+ Q_ENUM(OutputMode)
+
+ QQuick3DSpatialAudioEngine();
+ ~QQuick3DSpatialAudioEngine();
+
+ void setOutputMode(OutputMode mode);
+ OutputMode outputMode() const;
+
+ void setOutputDevice(const QAudioDevice &device);
+ QAudioDevice outputDevice() const;
+
+ void setMasterVolume(float volume);
+ float masterVolume() const;
+
+ static QSpatialAudioEngine *getEngine();
+
+Q_SIGNALS:
+ void outputModeChanged();
+ void outputDeviceChanged();
+ void masterVolumeChanged();
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediaquick3d/qquick3dspatialaudiolistener.cpp b/src/multimediaquick3d/qquick3dspatialaudiolistener.cpp
new file mode 100644
index 000000000..37dd0f4b4
--- /dev/null
+++ b/src/multimediaquick3d/qquick3dspatialaudiolistener.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Spatial Audio module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-NOGPL2$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qquick3dspatialaudiolistener_p.h>
+#include <qquick3dspatialaudiosoundsource_p.h>
+#include <qquick3dspatialaudioengine_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuick3DSpatialAudioListener::QQuick3DSpatialAudioListener()
+{
+ m_listener = new QSpatialAudioListener(QQuick3DSpatialAudioEngine::getEngine());
+ connect(this, &QQuick3DNode::scenePositionChanged, this, &QQuick3DSpatialAudioListener::updatePosition);
+ connect(this, &QQuick3DNode::sceneRotationChanged, this, &QQuick3DSpatialAudioListener::updateRotation);
+ updatePosition();
+ updateRotation();
+}
+
+QQuick3DSpatialAudioListener::~QQuick3DSpatialAudioListener()
+{
+ delete m_listener;
+}
+
+void QQuick3DSpatialAudioListener::updatePosition()
+{
+ m_listener->setPosition(scenePosition());
+}
+
+void QQuick3DSpatialAudioListener::updateRotation()
+{
+ m_listener->setRotation(sceneRotation());
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimediaquick3d/qquick3dspatialaudiolistener_p.h b/src/multimediaquick3d/qquick3dspatialaudiolistener_p.h
new file mode 100644
index 000000000..a6575a0bd
--- /dev/null
+++ b/src/multimediaquick3d/qquick3dspatialaudiolistener_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Spatial Audio module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-NOGPL2$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QQUICK3DLISTENER_H
+#define QQUICK3DLISTENER_H
+
+#include <private/qquick3dnode_p.h>
+#include <QtGui/qvector3d.h>
+
+#include <qspatialaudiolistener.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuick3DSpatialAudioSoundSource;
+
+class QQuick3DSpatialAudioListener : public QQuick3DNode
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(SpatialAudioListener)
+
+public:
+ QQuick3DSpatialAudioListener();
+ ~QQuick3DSpatialAudioListener();
+
+ QSpatialAudioListener *listener() { return m_listener; }
+protected:
+ QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *) override { return nullptr; }
+
+protected Q_SLOTS:
+ void updatePosition();
+ void updateRotation();
+
+private:
+ QSpatialAudioListener *m_listener;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediaquick3d/qquick3dspatialaudiosoundsource.cpp b/src/multimediaquick3d/qquick3dspatialaudiosoundsource.cpp
new file mode 100644
index 000000000..d08c9bfd7
--- /dev/null
+++ b/src/multimediaquick3d/qquick3dspatialaudiosoundsource.cpp
@@ -0,0 +1,181 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Spatial Audio module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-NOGPL2$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "qquick3dspatialaudiosoundsource_p.h"
+#include "qquick3dspatialaudioengine_p.h"
+#include "qspatialaudiosoundsource.h"
+#include <QAudioFormat>
+#include <qdir.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuick3DSpatialAudioSoundSource::QQuick3DSpatialAudioSoundSource()
+{
+ m_sound = new QSpatialAudioSoundSource(QQuick3DSpatialAudioEngine::getEngine());
+
+ connect(this, &QQuick3DNode::scenePositionChanged, this, &QQuick3DSpatialAudioSoundSource::updatePosition);
+ connect(this, &QQuick3DNode::sceneRotationChanged, this, &QQuick3DSpatialAudioSoundSource::updateRotation);
+ connect(m_sound, &QSpatialAudioSoundSource::sourceChanged, this, &QQuick3DSpatialAudioSoundSource::sourceChanged);
+ connect(m_sound, &QSpatialAudioSoundSource::volumeChanged, this, &QQuick3DSpatialAudioSoundSource::volumeChanged);
+ connect(m_sound, &QSpatialAudioSoundSource::distanceModelChanged, this, &QQuick3DSpatialAudioSoundSource::distanceModelChanged);
+ connect(m_sound, &QSpatialAudioSoundSource::minimumDistanceChanged, this, &QQuick3DSpatialAudioSoundSource::minimumDistanceChanged);
+ connect(m_sound, &QSpatialAudioSoundSource::maximumDistanceChanged, this, &QQuick3DSpatialAudioSoundSource::maximumDistanceChanged);
+ connect(m_sound, &QSpatialAudioSoundSource::manualAttenuationChanged, this, &QQuick3DSpatialAudioSoundSource::manualAttenuationChanged);
+ connect(m_sound, &QSpatialAudioSoundSource::occlusionIntensityChanged, this, &QQuick3DSpatialAudioSoundSource::occlusionIntensityChanged);
+ connect(m_sound, &QSpatialAudioSoundSource::directivityChanged, this, &QQuick3DSpatialAudioSoundSource::directivityChanged);
+ connect(m_sound, &QSpatialAudioSoundSource::directivityOrderChanged, this, &QQuick3DSpatialAudioSoundSource::directivityOrderChanged);
+ connect(m_sound, &QSpatialAudioSoundSource::nearFieldGainChanged, this, &QQuick3DSpatialAudioSoundSource::nearFieldGainChanged);
+}
+
+QQuick3DSpatialAudioSoundSource::~QQuick3DSpatialAudioSoundSource()
+{
+ delete m_sound;
+}
+
+QUrl QQuick3DSpatialAudioSoundSource::source() const
+{
+ return m_sound->source();
+}
+
+void QQuick3DSpatialAudioSoundSource::setSource(QUrl source)
+{
+ QUrl url = QUrl::fromLocalFile(QDir::currentPath() + u"/");
+ url = url.resolved(source);
+
+ m_sound->setSource(url);
+}
+
+void QQuick3DSpatialAudioSoundSource::setVolume(float volume)
+{
+ m_sound->setVolume(volume);
+}
+
+float QQuick3DSpatialAudioSoundSource::volume() const
+{
+ return m_sound->volume();
+}
+
+void QQuick3DSpatialAudioSoundSource::setDistanceModel(DistanceModel model)
+{
+ m_sound->setDistanceModel(QSpatialAudioSoundSource::DistanceModel(model));
+}
+
+QQuick3DSpatialAudioSoundSource::DistanceModel QQuick3DSpatialAudioSoundSource::distanceModel() const
+{
+ return DistanceModel(m_sound->distanceModel());
+}
+
+void QQuick3DSpatialAudioSoundSource::setMinimumDistance(float min)
+{
+ m_sound->setMinimumDistance(min);
+}
+
+float QQuick3DSpatialAudioSoundSource::minimumDistance() const
+{
+ return m_sound->minimumDistance();
+}
+
+void QQuick3DSpatialAudioSoundSource::setMaximumDistance(float max)
+{
+ m_sound->setMaximumDistance(max);
+}
+
+float QQuick3DSpatialAudioSoundSource::maximumDistance() const
+{
+ return m_sound->maximumDistance();
+}
+
+void QQuick3DSpatialAudioSoundSource::setManualAttenuation(float attenuation)
+{
+ m_sound->setManualAttenuation(attenuation);
+}
+
+float QQuick3DSpatialAudioSoundSource::manualAttenuation() const
+{
+ return m_sound->manualAttenuation();
+}
+
+void QQuick3DSpatialAudioSoundSource::setOcclusionIntensity(float occlusion)
+{
+ m_sound->setOcclusionIntensity(occlusion);
+}
+
+float QQuick3DSpatialAudioSoundSource::occlusionIntensity() const
+{
+ return m_sound->occlusionIntensity();
+}
+
+void QQuick3DSpatialAudioSoundSource::setDirectivity(float alpha)
+{
+ m_sound->setDirectivity(alpha);
+}
+
+float QQuick3DSpatialAudioSoundSource::directivity() const
+{
+ return m_sound->directivity();
+}
+
+void QQuick3DSpatialAudioSoundSource::setDirectivityOrder(float alpha)
+{
+ m_sound->setDirectivityOrder(alpha);
+}
+
+float QQuick3DSpatialAudioSoundSource::directivityOrder() const
+{
+ return m_sound->directivityOrder();
+}
+
+void QQuick3DSpatialAudioSoundSource::setNearFieldGain(float gain)
+{
+ m_sound->setNearFieldGain(gain);
+}
+
+float QQuick3DSpatialAudioSoundSource::nearFieldGain() const
+{
+ return m_sound->nearFieldGain();
+}
+
+void QQuick3DSpatialAudioSoundSource::updatePosition()
+{
+ m_sound->setPosition(scenePosition());
+}
+
+void QQuick3DSpatialAudioSoundSource::updateRotation()
+{
+ m_sound->setRotation(sceneRotation());
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimediaquick3d/qquick3dspatialaudiosoundsource_p.h b/src/multimediaquick3d/qquick3dspatialaudiosoundsource_p.h
new file mode 100644
index 000000000..c7be4b312
--- /dev/null
+++ b/src/multimediaquick3d/qquick3dspatialaudiosoundsource_p.h
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Spatial Audio module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-NOGPL2$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QQUICK3DSOUND_H
+#define QQUICK3DSOUND_H
+
+#include <private/qquick3dnode_p.h>
+#include <QUrl>
+#include <qvector3d.h>
+#include <qspatialaudiosoundsource.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuick3DSpatialAudioSoundSource : public QQuick3DNode
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
+ Q_PROPERTY(DistanceModel distanceModel READ distanceModel WRITE setDistanceModel NOTIFY distanceModelChanged)
+ Q_PROPERTY(float minimumDistance READ minimumDistance WRITE setMinimumDistance NOTIFY minimumDistanceChanged)
+ Q_PROPERTY(float maximumDistance READ maximumDistance WRITE setMaximumDistance NOTIFY maximumDistanceChanged)
+ Q_PROPERTY(float manualAttenuation READ manualAttenuation WRITE setManualAttenuation NOTIFY manualAttenuationChanged)
+ Q_PROPERTY(float occlusionIntensity READ occlusionIntensity WRITE setOcclusionIntensity NOTIFY occlusionIntensityChanged)
+ Q_PROPERTY(float directivity READ directivity WRITE setDirectivity NOTIFY directivityChanged)
+ Q_PROPERTY(float directivityOrder READ directivityOrder WRITE setDirectivityOrder NOTIFY directivityOrderChanged)
+ Q_PROPERTY(float nearFieldGain READ nearFieldGain WRITE setNearFieldGain NOTIFY nearFieldGainChanged)
+ QML_NAMED_ELEMENT(SpatialAudioSoundSource)
+
+public:
+ QQuick3DSpatialAudioSoundSource();
+ ~QQuick3DSpatialAudioSoundSource();
+
+ void setSource(QUrl source);
+ QUrl source() const;
+
+ void setVolume(float volume);
+ float volume() const;
+
+ enum DistanceModel {
+ DistanceModel_Logarithmic,
+ DistanceModel_Linear,
+ DistanceModel_ManualAttenutation
+ };
+ Q_ENUM(DistanceModel);
+
+ void setDistanceModel(DistanceModel model);
+ DistanceModel distanceModel() const;
+
+ void setMinimumDistance(float min);
+ float minimumDistance() const;
+
+ void setMaximumDistance(float max);
+ float maximumDistance() const;
+
+ void setManualAttenuation(float attenuation);
+ float manualAttenuation() const;
+
+ void setOcclusionIntensity(float occlusion);
+ float occlusionIntensity() const;
+
+ void setDirectivity(float alpha);
+ float directivity() const;
+
+ void setDirectivityOrder(float alpha);
+ float directivityOrder() const;
+
+ void setNearFieldGain(float gain);
+ float nearFieldGain() const;
+
+Q_SIGNALS:
+ void sourceChanged();
+ void volumeChanged();
+ void distanceModelChanged();
+ void minimumDistanceChanged();
+ void maximumDistanceChanged();
+ void manualAttenuationChanged();
+ void occlusionIntensityChanged();
+ void directivityChanged();
+ void directivityOrderChanged();
+ void nearFieldGainChanged();
+
+protected Q_SLOTS:
+ void updatePosition();
+ void updateRotation();
+
+protected:
+ QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *) override { return nullptr; }
+
+private:
+ QSpatialAudioSoundSource *m_sound = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediaquick3d/qquick3dspatialaudiostereosource.cpp b/src/multimediaquick3d/qquick3dspatialaudiostereosource.cpp
new file mode 100644
index 000000000..c2edcbe13
--- /dev/null
+++ b/src/multimediaquick3d/qquick3dspatialaudiostereosource.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Spatial Audio module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-NOGPL2$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "qquick3dspatialaudiostereosource_p.h"
+#include "qquick3dspatialaudioengine_p.h"
+#include "qspatialaudiostereosource.h"
+#include <QAudioFormat>
+#include <qdir.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuick3DSpatialAudioStereoSource::QQuick3DSpatialAudioStereoSource()
+{
+ m_sound = new QSpatialAudioStereoSource(QQuick3DSpatialAudioEngine::getEngine());
+
+ connect(m_sound, &QSpatialAudioStereoSource::sourceChanged, this, &QQuick3DSpatialAudioStereoSource::sourceChanged);
+ connect(m_sound, &QSpatialAudioStereoSource::volumeChanged, this, &QQuick3DSpatialAudioStereoSource::volumeChanged);
+}
+
+QQuick3DSpatialAudioStereoSource::~QQuick3DSpatialAudioStereoSource()
+{
+ delete m_sound;
+}
+
+QUrl QQuick3DSpatialAudioStereoSource::source() const
+{
+ return m_sound->source();
+}
+
+void QQuick3DSpatialAudioStereoSource::setSource(QUrl source)
+{
+ QUrl url = QUrl::fromLocalFile(QDir::currentPath() + u"/");
+ url = url.resolved(source);
+
+ m_sound->setSource(url);
+}
+
+void QQuick3DSpatialAudioStereoSource::setVolume(float volume)
+{
+ m_sound->setVolume(volume);
+}
+
+float QQuick3DSpatialAudioStereoSource::volume() const
+{
+ return m_sound->volume();
+}
+
+QT_END_NAMESPACE
diff --git a/src/multimediaquick3d/qquick3dspatialaudiostereosource_p.h b/src/multimediaquick3d/qquick3dspatialaudiostereosource_p.h
new file mode 100644
index 000000000..185abf7a5
--- /dev/null
+++ b/src/multimediaquick3d/qquick3dspatialaudiostereosource_p.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Spatial Audio module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-NOGPL2$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QQUICK3DSPATIALAUDIOSTEREOSOUND_H
+#define QQUICK3DSPATIALAUDIOSTEREOSOUND_H
+
+#include <private/qquick3dnode_p.h>
+#include <QUrl>
+#include <qvector3d.h>
+
+QT_BEGIN_NAMESPACE
+
+class QSpatialAudioStereoSource;
+
+class QQuick3DSpatialAudioStereoSource : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
+ Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
+ QML_NAMED_ELEMENT(SpatialAudioStereoSource)
+
+public:
+ QQuick3DSpatialAudioStereoSource();
+ ~QQuick3DSpatialAudioStereoSource();
+
+ void setSource(QUrl source);
+ QUrl source() const;
+
+ void setVolume(float volume);
+ float volume() const;
+
+Q_SIGNALS:
+ void sourceChanged();
+ void volumeChanged();
+
+private:
+ QSpatialAudioStereoSource *m_sound = nullptr;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediaquick3d/qtquick3dsoundglobal_p.h b/src/multimediaquick3d/qtquick3dsoundglobal_p.h
new file mode 100644
index 000000000..de017039b
--- /dev/null
+++ b/src/multimediaquick3d/qtquick3dsoundglobal_p.h
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Spatial Audio module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-NOGPL2$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QMULTIMEDIAQUICKDEFS_P_H
+#define QMULTIMEDIAQUICKDEFS_P_H
+
+#include <QtCore/qglobal.h>
+#include <QtMultimediaQuick/qtmultimediaquickexports.h>
+
+QT_BEGIN_NAMESPACE
+
+void Q_MULTIMEDIAQUICK_EXPORT qml_register_types_QtQuick3D_SpatialAudio();
+
+QT_END_NAMESPACE
+
+#endif // QMULTIMEDIAQUICKDEFS_P_H
+
diff --git a/src/multimediaquick3d/qtquick3dsoundtypes_p.h b/src/multimediaquick3d/qtquick3dsoundtypes_p.h
new file mode 100644
index 000000000..7d5a75109
--- /dev/null
+++ b/src/multimediaquick3d/qtquick3dsoundtypes_p.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Spatial Audio module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-NOGPL2$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTMULTIMEDIAQUICKTYPES_H
+#define QTMULTIMEDIAQUICKTYPES_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQml/qqml.h>
+#include <private/qtquick3dsoundglobal_p.h>
+
+QT_BEGIN_NAMESPACE
+
+// Nothing for now
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/multimediaquick3d/quick3dspatialaudio_plugin.cpp b/src/multimediaquick3d/quick3dspatialaudio_plugin.cpp
new file mode 100644
index 000000000..0a04f78bf
--- /dev/null
+++ b/src/multimediaquick3d/quick3dspatialaudio_plugin.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Spatial Audio module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL-NOGPL2$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtQml/qqmlextensionplugin.h>
+#include <QtQml/qqml.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcomponent.h>
+#include "qtquick3dsoundglobal_p.h"
+#include "qquick3dspatialaudiolistener_p.h"
+#include "qquick3dspatialaudiosoundsource_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QSpatialAudioQuickModule : public QQmlEngineExtensionPlugin
+{
+ Q_OBJECT
+ Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
+
+public:
+ QSpatialAudioQuickModule(QObject *parent = nullptr)
+ : QQmlEngineExtensionPlugin(parent)
+ {
+ volatile auto registration = qml_register_types_QtQuick3D_SpatialAudio;
+ Q_UNUSED(registration);
+ }
+
+ void initializeEngine(QQmlEngine *engine, const char *uri) override
+ {
+ Q_UNUSED(engine);
+ Q_UNUSED(uri);
+ }
+};
+
+QT_END_NAMESPACE
+
+#include "quick3dspatialaudio_plugin.moc"
+