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
3#include <qquick3daudioroom_p.h>
4#include <qquick3daudioengine_p.h>
5#include <qaudioroom.h>
6
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(this, &QQuick3DNode::scenePositionChanged, this, &QQuick3DAudioRoom::updatePosition);
34 connect(this, &QQuick3DNode::sceneRotationChanged, this, &QQuick3DAudioRoom::updateRotation);
35 connect(m_room, &QAudioRoom::dimensionsChanged, this, &QQuick3DAudioRoom::dimensionsChanged);
36 connect(m_room, &QAudioRoom::rotationChanged, this, &QQuick3DAudioRoom::rotationChanged);
37 connect(m_room, &QAudioRoom::wallsChanged, this, &QQuick3DAudioRoom::wallsChanged);
38 connect(m_room, &QAudioRoom::reflectionGainChanged, this, &QQuick3DAudioRoom::reflectionGainChanged);
39 connect(m_room, &QAudioRoom::reverbGainChanged, this, &QQuick3DAudioRoom::reverbGainChanged);
40 connect(m_room, &QAudioRoom::reverbTimeChanged, this, &QQuick3DAudioRoom::reverbTimeChanged);
41 connect(m_room, &QAudioRoom::reverbBrightnessChanged, this, &QQuick3DAudioRoom::reverbBrightnessChanged);
42}
43
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
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 */
123{
124 m_room->setWallMaterial(QAudioRoom::LeftWall, QAudioRoom::Material(material));
125}
126
128{
129 return Material(m_room->wallMaterial(QAudioRoom::LeftWall));
130}
131
133{
134 m_room->setWallMaterial(QAudioRoom::RightWall, QAudioRoom::Material(material));
135}
136
138{
139 return Material(m_room->wallMaterial(QAudioRoom::RightWall));
140}
141
143{
144 m_room->setWallMaterial(QAudioRoom::FrontWall, QAudioRoom::Material(material));
145}
146
148{
149 return Material(m_room->wallMaterial(QAudioRoom::FrontWall));
150}
151
153{
154 m_room->setWallMaterial(QAudioRoom::BackWall, QAudioRoom::Material(material));
155}
156
158{
159 return Material(m_room->wallMaterial(QAudioRoom::BackWall));
160}
161
163{
164 m_room->setWallMaterial(QAudioRoom::Floor, QAudioRoom::Material(material));
165}
166
168{
169 return Material(m_room->wallMaterial(QAudioRoom::Floor));
170}
171
173{
174 m_room->setWallMaterial(QAudioRoom::Ceiling, QAudioRoom::Material(material));
175}
176
178{
179 return Material(m_room->wallMaterial(QAudioRoom::Ceiling));
180}
181
182/*!
183 \qmlproperty real 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 */
193{
194 m_room->setReflectionGain(factor);
195}
196
198{
199 return m_room->reflectionGain();
200}
201
202/*!
203 \qmlproperty real 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 */
213{
214 m_room->setReverbGain(factor);
215}
216
218{
219 return m_room->reverbGain();
220}
221
222/*!
223 \qmlproperty real 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 */
232{
233 m_room->setReverbTime(factor);
234}
235
237{
238 return m_room->reverbTime();
239}
240
241/*!
242 \qmlproperty real 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 */
251{
252 m_room->setReverbBrightness(factor);
253}
254
256{
257 return m_room->reverbBrightness();
258}
259
260void QQuick3DAudioRoom::updatePosition()
261{
262 m_room->setPosition(scenePosition());
263}
264
266{
267 m_room->setRotation(sceneRotation());
268}
269
270QT_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