Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3daudioroom.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
4
5#include <QtQuick3DSpatialAudio/private/qquick3daudioengine_p.h>
6#include <QtSpatialAudio/qaudioroom.h>
7
9
10/*!
11 \qmltype AudioRoom
12 \inqmlmodule QtQuick3D.SpatialAudio
13 \ingroup quick3d_spatialaudio
14 \ingroup multimedia_audio_qml
15
16 Defines a room for the spatial audio engine.
17
18 If the listener is inside a room, first order sound reflections and reverb
19 matching the rooms properties will get applied to the sound field.
20
21 A room is always square and defined by its center position, its orientation and dimensions.
22 Each of the 6 walls of the room can be made of different materials that will contribute
23 to the computed reflections and reverb that the listener will experience while being inside
24 the room.
25
26 If multiple rooms cover the same position, the engine will use the room with the smallest
27 volume.
28 */
29
30QQuick3DAudioRoom::QQuick3DAudioRoom()
31{
32 m_room = new QAudioRoom(QQuick3DAudioEngine::getEngine());
33
34 connect(this, &QQuick3DNode::scenePositionChanged, this, &QQuick3DAudioRoom::updatePosition);
35 connect(this, &QQuick3DNode::sceneRotationChanged, this, &QQuick3DAudioRoom::updateRotation);
36 connect(m_room, &QAudioRoom::dimensionsChanged, this, &QQuick3DAudioRoom::dimensionsChanged);
37 connect(m_room, &QAudioRoom::rotationChanged, this, &QQuick3DAudioRoom::rotationChanged);
38 connect(m_room, &QAudioRoom::wallsChanged, this, &QQuick3DAudioRoom::wallsChanged);
39 connect(m_room, &QAudioRoom::reflectionGainChanged, this, &QQuick3DAudioRoom::reflectionGainChanged);
40 connect(m_room, &QAudioRoom::reverbGainChanged, this, &QQuick3DAudioRoom::reverbGainChanged);
41 connect(m_room, &QAudioRoom::reverbTimeChanged, this, &QQuick3DAudioRoom::reverbTimeChanged);
42 connect(m_room, &QAudioRoom::reverbBrightnessChanged, this, &QQuick3DAudioRoom::reverbBrightnessChanged);
43}
44
46{
47 delete m_room;
48}
49
50/*!
51 \qmlproperty vector3D AudioRoom::dimensions
52
53 Defines the dimensions of the room in 3D space. Units are in centimeters
54 by default.
55
56 \sa QtQuick3D::Node::position
57 */
58void QQuick3DAudioRoom::setDimensions(QVector3D dim)
59{
60 m_room->setDimensions(dim);
61}
62
64{
65 return m_room->dimensions();
66}
67
68/*!
69 \qmlproperty AudioRoom::Material AudioRoom::leftMaterial
70 \qmlproperty AudioRoom::Material AudioRoom::rightMaterial
71 \qmlproperty AudioRoom::Material AudioRoom::frontMaterial
72 \qmlproperty AudioRoom::Material AudioRoom::backMaterial
73 \qmlproperty AudioRoom::Material AudioRoom::floorMaterial
74 \qmlproperty AudioRoom::Material AudioRoom::ceilingMaterial
75
76 Sets the material to use for the different sides of the room. Properties correlate to
77 coordinates as follows:
78
79 \table
80 \header
81 \li Property
82 \li Coordinate
83 \row \li left \li Negative x
84 \row \li right \li Positive x
85 \row \li back \li Negative z
86 \row \li front \li Positive z
87 \row \li floor \li Negative y
88 \row \li ceiling \li Positive y
89 \endtable
90
91 Valid values for the material are:
92
93 \table
94 \header
95 \li Property value
96 \li Description
97 \row \li Transparent \li The side of the room is open and won't contribute to reflections or reverb.
98 \row \li AcousticCeilingTiles \li Acoustic tiles that suppress most reflections and reverb.
99 \row \li BrickBare \li A bare brick wall.
100 \row \li BrickPainted \li A painted brick wall.
101 \row \li ConcreteBlockCoarse \li A raw concrete wall
102 \row \li ConcreteBlockPainted \li A painted concrete wall
103 \row \li CurtainHeavy \li A heavy curtain. Will mostly reflect low frequencies
104 \row \li FiberGlassInsulation \li Fiber glass insulation. Only reflects very low frequencies
105 \row \li GlassThin \li A thin glass wall
106 \row \li GlassThick \li A thick glass wall
107 \row \li Grass \li Grass
108 \row \li LinoleumOnConcrete \li A Linoleum floor
109 \row \li Marble \li A marble floor
110 \row \li Metal \li Metal
111 \row \li ParquetOnConcrete \li Parquet wooden floor on concrete
112 \row \li PlasterRough \li Rough plaster
113 \row \li PlasterSmooth \li Smooth plaster
114 \row \li PlywoodPanel \li Plywodden panel
115 \row \li PolishedConcreteOrTile \li Polished concrete or tiles
116 \row \li Sheetrock \li Rock
117 \row \li WaterOrIceSurface \li Water or ice
118 \row \li WoodCeiling \li A wooden ceiling
119 \row \li WoodPanel \li Wooden panel
120 \row \li Uniform \li Artificial material giving uniform reflections on all frequencies
121 \endtable
122 */
124{
125 m_room->setWallMaterial(QAudioRoom::LeftWall, QAudioRoom::Material(material));
126}
127
129{
130 return Material(m_room->wallMaterial(QAudioRoom::LeftWall));
131}
132
134{
135 m_room->setWallMaterial(QAudioRoom::RightWall, QAudioRoom::Material(material));
136}
137
139{
140 return Material(m_room->wallMaterial(QAudioRoom::RightWall));
141}
142
144{
145 m_room->setWallMaterial(QAudioRoom::FrontWall, QAudioRoom::Material(material));
146}
147
149{
150 return Material(m_room->wallMaterial(QAudioRoom::FrontWall));
151}
152
154{
155 m_room->setWallMaterial(QAudioRoom::BackWall, QAudioRoom::Material(material));
156}
157
159{
160 return Material(m_room->wallMaterial(QAudioRoom::BackWall));
161}
162
164{
165 m_room->setWallMaterial(QAudioRoom::Floor, QAudioRoom::Material(material));
166}
167
169{
170 return Material(m_room->wallMaterial(QAudioRoom::Floor));
171}
172
174{
175 m_room->setWallMaterial(QAudioRoom::Ceiling, QAudioRoom::Material(material));
176}
177
179{
180 return Material(m_room->wallMaterial(QAudioRoom::Ceiling));
181}
182
183/*!
184 \qmlproperty real AudioRoom::reflectionGain
185
186 A gain factor for reflections generated in this room. A value
187 from 0 to 1 will dampen reflections, while a value larger than 1
188 will apply a gain to reflections, making them louder.
189
190 The default is 1, a factor of 0 disables reflections. Negative
191 values are mapped to 0.
192 */
194{
195 m_room->setReflectionGain(factor);
196}
197
199{
200 return m_room->reflectionGain();
201}
202
203/*!
204 \qmlproperty real AudioRoom::reverbGain
205
206 A gain factor for reverb generated in this room. A value
207 from 0 to 1 will dampen reverb, while a value larger than 1
208 will apply a gain to the reverb, making it louder.
209
210 The default is 1, a factor of 0 disables reverb. Negative
211 values are mapped to 0.
212 */
214{
215 m_room->setReverbGain(factor);
216}
217
219{
220 return m_room->reverbGain();
221}
222
223/*!
224 \qmlproperty real AudioRoom::reverbTime
225
226 A factor to be applies to all reverb timings generated for this room.
227 Larger values will lead to longer reverb timings, making the room sound
228 larger.
229
230 The default is 1. Negative values are mapped to 0.
231 */
233{
234 m_room->setReverbTime(factor);
235}
236
238{
239 return m_room->reverbTime();
240}
241
242/*!
243 \qmlproperty real AudioRoom::reverbBrightness
244
245 A brightness factor to be applied to the generated reverb.
246 A positive value will increase reverb for higher frequencies and
247 dampen lower frequencies, a negative value does the reverse.
248
249 The default is 0.
250 */
252{
253 m_room->setReverbBrightness(factor);
254}
255
257{
258 return m_room->reverbBrightness();
259}
260
261void QQuick3DAudioRoom::updatePosition()
262{
263 m_room->setPosition(scenePosition());
264}
265
267{
268 m_room->setRotation(sceneRotation());
269}
270
271QT_END_NAMESPACE
void setReflectionGain(float factor)
\qmlproperty real AudioRoom::reflectionGain
Material leftMaterial() const
void setReverbGain(float factor)
\qmlproperty real AudioRoom::reverbGain
Material frontMaterial() const
void setReverbTime(float factor)
\qmlproperty real AudioRoom::reverbTime
Material rightMaterial() const
Material backMaterial() const
void setFloorMaterial(Material material)
void setRightMaterial(Material material)
QVector3D dimensions() const
void setFrontMaterial(Material material)
Material ceilingMaterial() const
void setCeilingMaterial(Material material)
float reflectionGain() const
void setReverbBrightness(float factor)
\qmlproperty real AudioRoom::reverbBrightness
void setBackMaterial(Material material)
void setLeftMaterial(Material material)
\qmlproperty AudioRoom::Material AudioRoom::leftMaterial \qmlproperty AudioRoom::Material AudioRoom::...
Material floorMaterial() const
float reverbBrightness() const
Combined button and popup list for selecting options.