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