diff options
author | Lars Knoll <lars.knoll@qt.io> | 2022-05-02 09:51:44 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2022-05-11 08:24:15 +0200 |
commit | 6b4126e3d142ce1c056bc07a394eecbc1d4a2746 (patch) | |
tree | 0018a31369d39953d90b366ce1c07018e5545b3d /src/multimediaquick3d | |
parent | 1ec09ede3d696409ec86ec4f78394d431d4ddd4c (diff) |
Add documentation for the QtQuick3D.SpatialAudio module
Used the C++ docs as a template. Also added a few missing methods
and properties.
Also cleaned up the docs for the C++ API and fixed the qdoc warnings
there.
Change-Id: Ie9ccd14a344b4d22c83f26abd64414fcaccccc9c
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimediaquick3d')
8 files changed, 477 insertions, 69 deletions
diff --git a/src/multimediaquick3d/qquick3dspatialaudio-qml-types.qdoc b/src/multimediaquick3d/qquick3dspatialaudio-qml-types.qdoc new file mode 100644 index 000000000..b09f5fb6b --- /dev/null +++ b/src/multimediaquick3d/qquick3dspatialaudio-qml-types.qdoc @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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 Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! +\qmlmodule QtQuick3D.SpatialAudio +\title QtQuick3D.SpatialAudio QML Types +\ingroup qmlmodules +\brief Provides QML types for spatial audio in Qt Quick 3D. + +The QML types Spatial Audio support the basic use cases such as: +\list + \li have a person listening to sounds in 3D space, + \li place sound sources in 3D space, + \li support room acoustics with direct reflections and reverb, + \li support stereo overlay sources (e.g. for sound tracks). + \li support output to Headphones using binaural (virtual 3D) rendering of the sound field + \li support output to stereo or surround speaker configurations +\endlist + +\section1 QML Types + +Qt Quick3D Spatial Audio QML types can be imported into your application using the +following import statement in your .qml file: + +\qml \QtMinorVersion +import QtQuick3D.SpatialAudio +\endqml + +\generatelist qmltypesbymodule QtQuick3D.SpatialAudio + +\noautolist +*/ diff --git a/src/multimediaquick3d/qquick3dspatialaudioengine.cpp b/src/multimediaquick3d/qquick3dspatialaudioengine.cpp index 80dd222cc..f167d04fd 100644 --- a/src/multimediaquick3d/qquick3dspatialaudioengine.cpp +++ b/src/multimediaquick3d/qquick3dspatialaudioengine.cpp @@ -35,11 +35,40 @@ ** ****************************************************************************/ #include <qquick3dspatialaudioengine_p.h> +#include <qaudiodevice.h> QT_BEGIN_NAMESPACE static QSpatialAudioEngine *globalEngine = nullptr; +/*! + \qmltype SpatialAudioEngine + \inqmlmodule QtQuick3D.SpatialAudio + + \brief SpatialAudioEngine manages sound objects inside a 3D scene. + + SpatialAudioEngine manages sound objects inside a 3D scene. You can add + SpatialAudioSoundSource objects to the scene to define sounds that happen + at a specified location in 3D space. SpatialAudioStereoSource allows you to add + a stereo overlay (for example voice over or a sound track). + + You can use SpatialAudioListener 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. In many cases, the + SpatialAudioListener object can simply be instantiated as a child object of the QtQuick3D.Camera + object. + + Create SpatialAudioRoom objcects to simulate the sound (reflections and reverb) of a room with + certain dimensions and different types of walls. + + SpatialAudioEngine does offer a mode where Qt is using simulating the effects of the ear + using head related impulse reponse functions (see also https://en.wikipedia.org/wiki/Sound_localization) + to localize the sound in 3D space when using headphones and create a spatial audio effect through + headphones. +*/ + + QQuick3DSpatialAudioEngine::QQuick3DSpatialAudioEngine() { auto *e = getEngine(); @@ -52,6 +81,23 @@ QQuick3DSpatialAudioEngine::~QQuick3DSpatialAudioEngine() { } +/*! + \qmlproperty enumeration SpatialAudioEngine::outputMode + + Sets or retrieves the current output mode of the engine. + + \table + \header \li Property value + \li Description + \row \li Normal + \li Map the sounds to the loudspeaker configuration of the output device. + This is normally a stereo or surround speaker setup. + \row \li Headphone + \li Use Headphone spatialization to create a 3D audio effect when listening + to the sound field through headphones. + \endtable + */ + void QQuick3DSpatialAudioEngine::setOutputMode(OutputMode mode) { globalEngine->setOutputMode(QSpatialAudioEngine::OutputMode(mode)); @@ -62,6 +108,11 @@ QQuick3DSpatialAudioEngine::OutputMode QQuick3DSpatialAudioEngine::outputMode() return OutputMode(globalEngine->outputMode()); } +/*! + \qmlproperty QtMultimedia.AudioDevice SpatialAudioEngine::outputDevice + + Sets or returns the device that is being used for outputting the sound field. + */ void QQuick3DSpatialAudioEngine::setOutputDevice(const QAudioDevice &device) { globalEngine->setOutputDevice(device); @@ -72,6 +123,11 @@ QAudioDevice QQuick3DSpatialAudioEngine::outputDevice() const return globalEngine->outputDevice(); } +/*! + \qmlproperty float SpatialAudioEngine::masterVolume + + Sets or returns overall volume being used to render the sound field. + */ void QQuick3DSpatialAudioEngine::setMasterVolume(float volume) { globalEngine->setMasterVolume(volume); diff --git a/src/multimediaquick3d/qquick3dspatialaudiolistener.cpp b/src/multimediaquick3d/qquick3dspatialaudiolistener.cpp index 37dd0f4b4..de58066f2 100644 --- a/src/multimediaquick3d/qquick3dspatialaudiolistener.cpp +++ b/src/multimediaquick3d/qquick3dspatialaudiolistener.cpp @@ -40,6 +40,20 @@ QT_BEGIN_NAMESPACE +/*! + \qmltype SpatialAudioListener + \inqmlmodule QtQuick3D.SpatialAudio + + \brief defines the position and orientation of the person listening to a sound field + defined by a SpatialAudioEngine. + + A SpatialAudioEngine can have exactly one listener, that defines the position and orientation + of the person listening to the sounds defined by the objects placed within the audio engine. + + In most cases, the SpatialAudioListener should simply be a child of the Camera element in QtQuick3D. + This will ensure that the sound experience is aligned with the visual rendering of the scene. + */ + QQuick3DSpatialAudioListener::QQuick3DSpatialAudioListener() { m_listener = new QSpatialAudioListener(QQuick3DSpatialAudioEngine::getEngine()); diff --git a/src/multimediaquick3d/qquick3dspatialaudioroom.cpp b/src/multimediaquick3d/qquick3dspatialaudioroom.cpp index d50b9d0ab..74b1cf1c5 100644 --- a/src/multimediaquick3d/qquick3dspatialaudioroom.cpp +++ b/src/multimediaquick3d/qquick3dspatialaudioroom.cpp @@ -42,6 +42,7 @@ QT_BEGIN_NAMESPACE /*! \qmltype SpatialAudioRoom + \inqmlmodule QtQuick3D.SpatialAudio Defines a room for the spatial audio engine. @@ -57,9 +58,6 @@ QT_BEGIN_NAMESPACE volume. */ -/*! - Constructs a QQuick3DSpatialAudioRoom for \a engine. - */ QQuick3DSpatialAudioRoom::QQuick3DSpatialAudioRoom() { m_room = new QSpatialAudioRoom(QQuick3DSpatialAudioEngine::getEngine()); @@ -75,47 +73,12 @@ QQuick3DSpatialAudioRoom::QQuick3DSpatialAudioRoom() connect(m_room, &QSpatialAudioRoom::reverbBrightnessChanged, this, &QQuick3DSpatialAudioRoom::reverbBrightnessChanged); } -/*! - Destroys the room. - */ QQuick3DSpatialAudioRoom::~QQuick3DSpatialAudioRoom() { delete m_room; } /*! - \enum SpatialAudioRoom::Material - - Defines different materials that can be applied to the different walls of the room. - - \value Transparent The side of the room is open and won't contribute to reflections or reverb. - \value AcousticCeilingTiles Acoustic tiles that suppress most reflections and reverb. - \value BrickBare A bare brick wall. - \value BrickPainted A painted brick wall. - \value ConcreteBlockCoarse A raw concrete wall - \value ConcreteBlockPainted A painted concrete wall - \value CurtainHeavy A heavy curtain. Will mostly reflect low frequencies - \value FiberGlassInsulation Fiber glass insulation. Only reflects very low frequencies - \value GlassThin A thin glass wall - \value GlassThick A thick glass wall - \value Grass Grass - \value LinoleumOnConcrete A Linoleum floor - \value Marble A marble floor - \value Metal Metal - \value ParquetOnConcrete Parquet wooden floor on concrete - \value PlasterRough Rough plaster - \value PlasterSmooth Smooth plaster - \value PlywoodPanel Plywodden panel - \value PolishedConcreteOrTile Polished concrete or tiles - \value Sheetrock Rock - \value WaterOrIceSurface Water or ice - \value WoodCeiling A wooden ceiling - \value WoodPanel Wooden panel - \value Uniform Artificial material giving uniform reflections on all frequencies -*/ - - -/*! \qmlproperty vector3D SpatialAudioRoom::dimensions Defines the dimensions of the room in 3D space. All units are @@ -133,8 +96,58 @@ QVector3D QQuick3DSpatialAudioRoom::dimensions() const /*! \qmlproperty SpatialAudioRoom::Material SpatialAudioRoom::left + \qmlproperty SpatialAudioRoom::Material SpatialAudioRoom::right + \qmlproperty SpatialAudioRoom::Material SpatialAudioRoom::front + \qmlproperty SpatialAudioRoom::Material SpatialAudioRoom::back + \qmlproperty SpatialAudioRoom::Material SpatialAudioRoom::floor + \qmlproperty SpatialAudioRoom::Material SpatialAudioRoom::ceiling - Sets the material to use for the left (negative x) of the room. + Sets the material to use for the different sides of the room. Properties correlate to + coordinates as follows: + + \table + \header + \li Property + \li Coordinate + \row \li left \li Negative x + \row \li right \li Positive x + \row \li back \li Negative x + \row \li front \li Positive z + \row \li floor \li Negative y + \row \li ceiling \li Positive y + \endtable + + Valid values for the material are: + + \table + \header + \li Property value + \li Description + \row \li Transparent \li The side of the room is open and won't contribute to reflections or reverb. + \row \li AcousticCeilingTiles \li Acoustic tiles that suppress most reflections and reverb. + \row \li BrickBare \li A bare brick wall. + \row \li BrickPainted \li A painted brick wall. + \row \li ConcreteBlockCoarse \li A raw concrete wall + \row \li ConcreteBlockPainted \li A painted concrete wall + \row \li CurtainHeavy \li A heavy curtain. Will mostly reflect low frequencies + \row \li FiberGlassInsulation \li Fiber glass insulation. Only reflects very low frequencies + \row \li GlassThin \li A thin glass wall + \row \li GlassThick \li A thick glass wall + \row \li Grass \li Grass + \row \li LinoleumOnConcrete \li A Linoleum floor + \row \li Marble \li A marble floor + \row \li Metal \li Metal + \row \li ParquetOnConcrete \li Parquet wooden floor on concrete + \row \li PlasterRough \li Rough plaster + \row \li PlasterSmooth \li Smooth plaster + \row \li PlywoodPanel \li Plywodden panel + \row \li PolishedConcreteOrTile \li Polished concrete or tiles + \row \li Sheetrock \li Rock + \row \li WaterOrIceSurface \li Water or ice + \row \li WoodCeiling \li A wooden ceiling + \row \li WoodPanel \li Wooden panel + \row \li Uniform \li Artificial material giving uniform reflections on all frequencies + \endtable */ void QQuick3DSpatialAudioRoom::setLeft(Material material) { @@ -146,11 +159,6 @@ QQuick3DSpatialAudioRoom::Material QQuick3DSpatialAudioRoom::left() const return Material(m_room->wall(QSpatialAudioRoom::LeftWall)); } -/*! - \qmlproperty SpatialAudioRoom::Material SpatialAudioRoom::right - - Sets the material to use for the right (positive x) of the room. - */ void QQuick3DSpatialAudioRoom::setRight(Material material) { m_room->setWall(QSpatialAudioRoom::RightWall, QSpatialAudioRoom::Material(material)); @@ -161,11 +169,6 @@ QQuick3DSpatialAudioRoom::Material QQuick3DSpatialAudioRoom::right() const return Material(m_room->wall(QSpatialAudioRoom::RightWall)); } -/*! - \qmlproperty SpatialAudioRoom::Material SpatialAudioRoom::front - - Sets the material to use for the front (positive z) of the room. - */ void QQuick3DSpatialAudioRoom::setFront(Material material) { m_room->setWall(QSpatialAudioRoom::FrontWall, QSpatialAudioRoom::Material(material)); @@ -176,11 +179,6 @@ QQuick3DSpatialAudioRoom::Material QQuick3DSpatialAudioRoom::front() const return Material(m_room->wall(QSpatialAudioRoom::FrontWall)); } -/*! - \qmlproperty SpatialAudioRoom::Material SpatialAudioRoom::back - - Sets the material to use for the back (negative z) of the room. - */ void QQuick3DSpatialAudioRoom::setBack(Material material) { m_room->setWall(QSpatialAudioRoom::BackWall, QSpatialAudioRoom::Material(material)); @@ -191,11 +189,6 @@ QQuick3DSpatialAudioRoom::Material QQuick3DSpatialAudioRoom::back() const return Material(m_room->wall(QSpatialAudioRoom::BackWall)); } -/*! - \qmlproperty SpatialAudioRoom::Material SpatialAudioRoom::floor - - Sets the material to use for the floor of the room. - */ void QQuick3DSpatialAudioRoom::setFloor(Material material) { m_room->setWall(QSpatialAudioRoom::Floor, QSpatialAudioRoom::Material(material)); @@ -206,11 +199,6 @@ QQuick3DSpatialAudioRoom::Material QQuick3DSpatialAudioRoom::floor() const return Material(m_room->wall(QSpatialAudioRoom::Floor)); } -/*! - \qmlproperty SpatialAudioRoom::Material SpatialAudioRoom::ceiling - - Sets the material to use for the ceiling of the room. - */ void QQuick3DSpatialAudioRoom::setCeiling(Material material) { m_room->setWall(QSpatialAudioRoom::Ceiling, QSpatialAudioRoom::Material(material)); @@ -281,7 +269,7 @@ float QQuick3DSpatialAudioRoom::reverbTime() const } /*! - \qmlproperty float SpatialAudioRoom::reverbTime + \qmlproperty float SpatialAudioRoom::reverbBrightness A brightness factor to be applied to the generated reverb. A positive value will increase reverb for higher frequencies and diff --git a/src/multimediaquick3d/qquick3dspatialaudiosoundsource.cpp b/src/multimediaquick3d/qquick3dspatialaudiosoundsource.cpp index d08c9bfd7..1e41f26e8 100644 --- a/src/multimediaquick3d/qquick3dspatialaudiosoundsource.cpp +++ b/src/multimediaquick3d/qquick3dspatialaudiosoundsource.cpp @@ -42,6 +42,20 @@ QT_BEGIN_NAMESPACE +/*! + \qmltype SpatialAudioSoundSource + \inqmlmodule QtQuick3D.SpatialAudio + + \brief A sound object in 3D space. + + A SpatialAudioSoundSource represents an audible object in 3D space. You can define + it's 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. + */ + QQuick3DSpatialAudioSoundSource::QQuick3DSpatialAudioSoundSource() { m_sound = new QSpatialAudioSoundSource(QQuick3DSpatialAudioEngine::getEngine()); @@ -58,6 +72,8 @@ QQuick3DSpatialAudioSoundSource::QQuick3DSpatialAudioSoundSource() connect(m_sound, &QSpatialAudioSoundSource::directivityChanged, this, &QQuick3DSpatialAudioSoundSource::directivityChanged); connect(m_sound, &QSpatialAudioSoundSource::directivityOrderChanged, this, &QQuick3DSpatialAudioSoundSource::directivityOrderChanged); connect(m_sound, &QSpatialAudioSoundSource::nearFieldGainChanged, this, &QQuick3DSpatialAudioSoundSource::nearFieldGainChanged); + connect(m_sound, &QSpatialAudioSoundSource::loopsChanged, this, &QQuick3DSpatialAudioSoundSource::loopsChanged); + connect(m_sound, &QSpatialAudioSoundSource::autoPlayChanged, this, &QQuick3DSpatialAudioSoundSource::autoPlayChanged); } QQuick3DSpatialAudioSoundSource::~QQuick3DSpatialAudioSoundSource() @@ -65,6 +81,11 @@ QQuick3DSpatialAudioSoundSource::~QQuick3DSpatialAudioSoundSource() delete m_sound; } +/*! + \qmlproperty url QSpatialAudioSoundSource::source + + The source file for the sound to be played. + */ QUrl QQuick3DSpatialAudioSoundSource::source() const { return m_sound->source(); @@ -78,6 +99,11 @@ void QQuick3DSpatialAudioSoundSource::setSource(QUrl source) m_sound->setSource(url); } +/*! + \qmlproperty float QSpatialAudioSoundSource::volume + + Defines an overall volume for this sound source. + */ void QQuick3DSpatialAudioSoundSource::setVolume(float volume) { m_sound->setVolume(volume); @@ -88,6 +114,22 @@ float QQuick3DSpatialAudioSoundSource::volume() const return m_sound->volume(); } +/*! + \qmlproperty enumeration SpatialAudioSoundSource::distanceModel + + Defines how the volume of the sound scales with distance to the listener. + + \table + \header \li Property value + \li Description + \row \li Logarithmic + \li Volume decreases logarithmically with distance. + \row \li Linear + \li Volume decreases linearly with distance. + \row \li ManualAttenutation + \li Attenuation is defined manually using the \l manualAttenuation property. + \endtable + */ void QQuick3DSpatialAudioSoundSource::setDistanceModel(DistanceModel model) { m_sound->setDistanceModel(QSpatialAudioSoundSource::DistanceModel(model)); @@ -98,6 +140,13 @@ QQuick3DSpatialAudioSoundSource::DistanceModel QQuick3DSpatialAudioSoundSource:: return DistanceModel(m_sound->distanceModel()); } +/*! + \qmlproperty float SpatialAudioSoundSource::minimumDistance + + Defines a minimum distance for the sound source. If the listener is closer to the sound + object than the minimum distance, volume will stay constant and the sound source won't + be localized in space. + */ void QQuick3DSpatialAudioSoundSource::setMinimumDistance(float min) { m_sound->setMinimumDistance(min); @@ -108,6 +157,12 @@ float QQuick3DSpatialAudioSoundSource::minimumDistance() const return m_sound->minimumDistance(); } +/*! + \qmlproperty float SpatialAudioSoundSource::maximumDistance + + Defines a maximum distance for the sound source. If the listener is further away from + the sound object than the maximum distance it won't be audible anymore. + */ void QQuick3DSpatialAudioSoundSource::setMaximumDistance(float max) { m_sound->setMaximumDistance(max); @@ -118,6 +173,12 @@ float QQuick3DSpatialAudioSoundSource::maximumDistance() const return m_sound->maximumDistance(); } +/*! + \qmlproperty float SpatialAudioSoundSource::manualAttenuation + + Defines a manual attenuation factor if \l distanceModel is set to + SpatialAudioSoundSource.ManualAttenutation. + */ void QQuick3DSpatialAudioSoundSource::setManualAttenuation(float attenuation) { m_sound->setManualAttenuation(attenuation); @@ -128,6 +189,14 @@ float QQuick3DSpatialAudioSoundSource::manualAttenuation() const return m_sound->manualAttenuation(); } +/*! + \qmlproperty float SpatialAudioSoundSource::occlusionIntensity + + Defines how much the object is occluded. 0 implies the object is + not occluded at all, while a large number implies a large occlusion. + + The default is 0. + */ void QQuick3DSpatialAudioSoundSource::setOcclusionIntensity(float occlusion) { m_sound->setOcclusionIntensity(occlusion); @@ -138,6 +207,15 @@ float QQuick3DSpatialAudioSoundSource::occlusionIntensity() const return m_sound->occlusionIntensity(); } +/*! + \qmlproperty float SpatialAudioSoundSource::directivity + + 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. + */ void QQuick3DSpatialAudioSoundSource::setDirectivity(float alpha) { m_sound->setDirectivity(alpha); @@ -148,6 +226,14 @@ float QQuick3DSpatialAudioSoundSource::directivity() const return m_sound->directivity(); } +/*! + \qmlproperty float SpatialAudioSoundSource::directivityOrder + + 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. + */ void QQuick3DSpatialAudioSoundSource::setDirectivityOrder(float alpha) { m_sound->setDirectivityOrder(alpha); @@ -158,6 +244,13 @@ float QQuick3DSpatialAudioSoundSource::directivityOrder() const return m_sound->directivityOrder(); } +/*! + \qmlproperty float SpatialAudioSoundSource::nearFieldGain + + 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. + */ void QQuick3DSpatialAudioSoundSource::setNearFieldGain(float gain) { m_sound->setNearFieldGain(gain); @@ -178,4 +271,71 @@ void QQuick3DSpatialAudioSoundSource::updateRotation() m_sound->setRotation(sceneRotation()); } +/*! + \qmlproperty int QSpatialAudioSoundSource::loops + + Determines how often the sound is played before the player stops. + Set to SpatialAudioSoundSource::Infinite to loop the current sound forever. + + The default value is \c 1. + */ +int QQuick3DSpatialAudioSoundSource::loops() const +{ + return m_sound->loops(); +} + +void QQuick3DSpatialAudioSoundSource::setLoops(int loops) +{ + m_sound->setLoops(loops); +} + +/*! + \qmlproperty bool SpatialAudioSoundSource::autoPlay + + Determines whether the sound should automatically start playing when a source + gets specified. + + The default value is \c true. + */ +bool QQuick3DSpatialAudioSoundSource::autoPlay() const +{ + return m_sound->autoPlay(); +} + +void QQuick3DSpatialAudioSoundSource::setAutoPlay(bool autoPlay) +{ + m_sound->setAutoPlay(autoPlay); +} + +/*! + \qmlmethod SpatialAudioSoundSource::play() + + Starts playing back the sound. Does nothing if the sound is already playing. + */ +void QQuick3DSpatialAudioSoundSource::play() +{ + m_sound->play(); +} + +/*! + \qmlmethod SpatialAudioSoundSource::pause() + + Pauses sound playback at the current position. Calling play() will continue playback. + */ +void QQuick3DSpatialAudioSoundSource::pause() +{ + m_sound->pause(); +} + +/*! + \qmlmethod SpatialAudioSoundSource::stop() + + Stops sound playback and resets the current position and loop count to 0. Calling play() will + begin playback at the beginning of the sound file. + */ +void QQuick3DSpatialAudioSoundSource::stop() +{ + m_sound->stop(); +} + QT_END_NAMESPACE diff --git a/src/multimediaquick3d/qquick3dspatialaudiosoundsource_p.h b/src/multimediaquick3d/qquick3dspatialaudiosoundsource_p.h index c7be4b312..29c74d21e 100644 --- a/src/multimediaquick3d/qquick3dspatialaudiosoundsource_p.h +++ b/src/multimediaquick3d/qquick3dspatialaudiosoundsource_p.h @@ -57,6 +57,8 @@ class QQuick3DSpatialAudioSoundSource : public QQuick3DNode 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) + Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged) + Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged) QML_NAMED_ELEMENT(SpatialAudioSoundSource) public: @@ -70,9 +72,9 @@ public: float volume() const; enum DistanceModel { - DistanceModel_Logarithmic, - DistanceModel_Linear, - DistanceModel_ManualAttenutation + Logarithmic, + Linear, + ManualAttenutation }; Q_ENUM(DistanceModel); @@ -100,6 +102,24 @@ public: void setNearFieldGain(float gain); float nearFieldGain() const; + enum Loops + { + Infinite = -1, + Once = 1 + }; + Q_ENUM(Loops) + + int loops() const; + void setLoops(int loops); + + bool autoPlay() const; + void setAutoPlay(bool autoPlay); + +public Q_SLOTS: + void play(); + void pause(); + void stop(); + Q_SIGNALS: void sourceChanged(); void volumeChanged(); @@ -111,8 +131,10 @@ Q_SIGNALS: void directivityChanged(); void directivityOrderChanged(); void nearFieldGainChanged(); + void loopsChanged(); + void autoPlayChanged(); -protected Q_SLOTS: +private Q_SLOTS: void updatePosition(); void updateRotation(); diff --git a/src/multimediaquick3d/qquick3dspatialaudiostereosource.cpp b/src/multimediaquick3d/qquick3dspatialaudiostereosource.cpp index c2edcbe13..3bfc9b125 100644 --- a/src/multimediaquick3d/qquick3dspatialaudiostereosource.cpp +++ b/src/multimediaquick3d/qquick3dspatialaudiostereosource.cpp @@ -42,12 +42,25 @@ QT_BEGIN_NAMESPACE +/*! + \qmltype SpatialAudioStereoSource + \inqmlmodule QtQuick3D.SpatialAudio + + \brief A stereo overlay sound. + + A SpatialAudioStereoSource represents a position and orientation independent sound. + It's commonly used for background sounds (e.g. music) that is supposed to be independent + of the listeners position and orientation. + */ + QQuick3DSpatialAudioStereoSource::QQuick3DSpatialAudioStereoSource() { m_sound = new QSpatialAudioStereoSource(QQuick3DSpatialAudioEngine::getEngine()); connect(m_sound, &QSpatialAudioStereoSource::sourceChanged, this, &QQuick3DSpatialAudioStereoSource::sourceChanged); connect(m_sound, &QSpatialAudioStereoSource::volumeChanged, this, &QQuick3DSpatialAudioStereoSource::volumeChanged); + connect(m_sound, &QSpatialAudioStereoSource::loopsChanged, this, &QQuick3DSpatialAudioStereoSource::loopsChanged); + connect(m_sound, &QSpatialAudioStereoSource::autoPlayChanged, this, &QQuick3DSpatialAudioStereoSource::autoPlayChanged); } QQuick3DSpatialAudioStereoSource::~QQuick3DSpatialAudioStereoSource() @@ -55,6 +68,11 @@ QQuick3DSpatialAudioStereoSource::~QQuick3DSpatialAudioStereoSource() delete m_sound; } +/*! + \qmlproperty url QSpatialAudioStereoSource::source + + The source file for the sound to be played. + */ QUrl QQuick3DSpatialAudioStereoSource::source() const { return m_sound->source(); @@ -68,6 +86,11 @@ void QQuick3DSpatialAudioStereoSource::setSource(QUrl source) m_sound->setSource(url); } +/*! + \qmlproperty float QSpatialAudioStereoSource::volume + + Defines an overall volume for this sound source. + */ void QQuick3DSpatialAudioStereoSource::setVolume(float volume) { m_sound->setVolume(volume); @@ -78,4 +101,71 @@ float QQuick3DSpatialAudioStereoSource::volume() const return m_sound->volume(); } +/*! + \qmlproperty int QSpatialAudioStereoSource::loops + + Determines how often the sound is played before the player stops. + Set to SpatialAudioSoundSource::Infinite to loop the current sound forever. + + The default value is \c 1. + */ +int QQuick3DSpatialAudioStereoSource::loops() const +{ + return m_sound->loops(); +} + +void QQuick3DSpatialAudioStereoSource::setLoops(int loops) +{ + m_sound->setLoops(loops); +} + +/*! + \qmlproperty bool SpatialAudioStereoSource::autoPlay + + Determines whether the sound should automatically start playing when a source + gets specified. + + The default value is \c true. + */ +bool QQuick3DSpatialAudioStereoSource::autoPlay() const +{ + return m_sound->autoPlay(); +} + +void QQuick3DSpatialAudioStereoSource::setAutoPlay(bool autoPlay) +{ + m_sound->setAutoPlay(autoPlay); +} + +/*! + \qmlmethod SpatialAudioStereoSource::play() + + Starts playing back the sound. Does nothing if the sound is already playing. + */ +void QQuick3DSpatialAudioStereoSource::play() +{ + m_sound->play(); +} + +/*! + \qmlmethod SpatialAudioStereoSource::pause() + + Pauses sound playback at the current position. Calling play() will continue playback. + */ +void QQuick3DSpatialAudioStereoSource::pause() +{ + m_sound->pause(); +} + +/*! + \qmlmethod SpatialAudioStereoSource::stop() + + Stops sound playback and resets the current position and loop count to 0. Calling play() will + begin playback at the beginning of the sound file. + */ +void QQuick3DSpatialAudioStereoSource::stop() +{ + m_sound->stop(); +} + QT_END_NAMESPACE diff --git a/src/multimediaquick3d/qquick3dspatialaudiostereosource_p.h b/src/multimediaquick3d/qquick3dspatialaudiostereosource_p.h index 185abf7a5..25df87732 100644 --- a/src/multimediaquick3d/qquick3dspatialaudiostereosource_p.h +++ b/src/multimediaquick3d/qquick3dspatialaudiostereosource_p.h @@ -50,6 +50,8 @@ 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) + Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged) + Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged) QML_NAMED_ELEMENT(SpatialAudioStereoSource) public: @@ -62,9 +64,29 @@ public: void setVolume(float volume); float volume() const; + enum Loops + { + Infinite = -1, + Once = 1 + }; + Q_ENUM(Loops) + + int loops() const; + void setLoops(int loops); + + bool autoPlay() const; + void setAutoPlay(bool autoPlay); + +public Q_SLOTS: + void play(); + void pause(); + void stop(); + Q_SIGNALS: void sourceChanged(); void volumeChanged(); + void loopsChanged(); + void autoPlayChanged(); private: QSpatialAudioStereoSource *m_sound = nullptr; |