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

source code of qtmultimedia/src/spatialaudioquick3d/qquick3daudioroom.cpp