60 pos *= ep->distanceScale;
63 ep->resonanceAudio->api->SetSourcePosition(d->
sourceId,
pos.x(),
pos.y(),
pos.z());
71 return d->
pos/ep->distanceScale;
84 ep->resonanceAudio->api->SetSourceRotation(d->
sourceId,
q.x(),
q.y(),
q.z(),
q.scalar());
153 vraudio::DistanceRolloffModel dm = vraudio::kLogarithmic;
156 dm = vraudio::kLinear;
173 if (!ep->currentRoom)
177 QVector3D roomDim2 = ep->currentRoom->dimensions()/2.;
178 QVector3D roomPos = ep->currentRoom->position();
187 ep->resonanceAudio->api->SetSourceRoomEffectsGain(
sourceId, 1);
196 auto relativeListenerPos = ep->listenerPosition() - roomPos;
197 relativeListenerPos = roomRot.
rotatedVector(relativeListenerPos);
205 const float transitionDistance =
size + 0.4;
210 float factors[3] = { 0., 0., 0. };
211 bool foundWall =
false;
214 float dx =
sign * roomDim2.
x() - relativeListenerPos.x();
216 float dy = roomDim2.
y() -
qAbs(intersection.
y());
217 float dz = roomDim2.
z() -
qAbs(intersection.
z());
218 if (dy > 0 && dz > 0) {
221 factors[
Y] =
qMax(0.f, 1.f/3.f - dy/transitionDistance);
222 factors[Z] =
qMax(0.f, 1.f/3.f - dz/transitionDistance);
223 factors[
X] = 1.f - factors[
Y] - factors[Z];
229 float dy =
sign * roomDim2.
y() - relativeListenerPos.y();
231 float dx = roomDim2.
x() -
qAbs(intersection.
x());
232 float dz = roomDim2.
z() -
qAbs(intersection.
z());
233 if (dx > 0 && dz > 0) {
236 factors[
X] =
qMax(0.f, 1.f/3.f - dx/transitionDistance);
237 factors[Z] =
qMax(0.f, 1.f/3.f - dz/transitionDistance);
238 factors[
Y] = 1.f - factors[
X] - factors[Z];
245 float dz =
sign * roomDim2.
z() - relativeListenerPos.z();
247 float dx = roomDim2.
x() -
qAbs(intersection.
x());
248 float dy = roomDim2.
y() -
qAbs(intersection.
y());
249 if (dx > 0 && dy > 0) {
252 factors[
X] =
qMax(0.f, 1.f/3.f - dx/transitionDistance);
253 factors[
Y] =
qMax(0.f, 1.f/3.f - dy/transitionDistance);
254 factors[Z] = 1.f - factors[
X] - factors[
Y];
260 for (
int i = 0;
i < 3; ++
i) {
266 ep->resonanceAudio->api->SetSourceRoomEffectsGain(
sourceId, 0);
287 size *= ep->distanceScale;
299 return d->
size/ep->distanceScale;
312 cutoff *= ep->distanceScale;
445 gain =
qBound(0., gain, 1.);
507 if (oldLoops !=
loops)
566 ep->removeSpatialSound(
this);
571 ep->addSpatialSound(
this);
591#include "moc_qspatialsound.cpp"
QAtomicInteger< bool > m_autoPlay
static QAudioEnginePrivate * get(QAudioEngine *engine)
static QAudioRoomPrivate * get(const QAudioRoom *r)
Wall
An enum defining the 6 walls of the room.
T fetchAndStoreRelaxed(T newValue) noexcept
T loadRelaxed() const noexcept
The QQuaternion class represents a quaternion consisting of a vector and scalar.
float z() const
Returns the z coordinate of this quaternion's vector.
float scalar() const
Returns the scalar component of this quaternion.
float x() const
Returns the x coordinate of this quaternion's vector.
float y() const
Returns the y coordinate of this quaternion's vector.
QVector3D rotatedVector(const QVector3D &vector) const
Rotates vector with this quaternion to produce a new vector in 3D space.
void updateDistanceModel()
QSpatialSound::DistanceModel distanceModel
void stop()
Stops sound playback and resets the current position and current loop count to 0.
void setVolume(float volume)
void manualAttenuationChanged()
void pause()
Pauses sound playback.
void setPosition(QVector3D pos)
void setNearFieldGain(float gain)
void play()
Starts playing back the sound.
void setDistanceModel(DistanceModel model)
float nearFieldGain
Defines the near field gain for the sound source.
float manualAttenuation
Defines a manual attenuation factor if \l distanceModel is set to QSpatialSound::DistanceModel::Manua...
void occlusionIntensityChanged()
DistanceModel distanceModel
Defines distance model for this sound source.
void setManualAttenuation(float attenuation)
void setSource(const QUrl &url)
~QSpatialSound()
Destroys the sound source.
float directivity
Defines the directivity of the sound source.
void distanceModelChanged()
void setDirectivityOrder(float alpha)
QAudioEngine * engine() const
Returns the engine associated with this listener.
QUrl source
The source file for the sound to be played.
float directivityOrder
Defines the order of the directivity of the sound source.
void setDistanceCutoff(float cutoff)
void setAutoPlay(bool autoPlay)
void setDirectivity(float alpha)
bool autoPlay
Determines whether the sound should automatically start playing when a source gets specified.
void setOcclusionIntensity(float occlusion)
QQuaternion rotation
Defines the orientation of the sound source in 3D space.
void distanceCutoffChanged()
float size
Defines the size of the sound source.
int loops
Determines how many times the sound is played before the player stops.
void nearFieldGainChanged()
void setRotation(const QQuaternion &q)
float volume
Defines the volume of the sound.
float occlusionIntensity
Defines how much the object is occluded.
float distanceCutoff
Defines a distance beyond which sound coming from the source will cutoff.
QSpatialSound(QAudioEngine *engine)
Creates a spatial sound source for engine.
QVector3D position
Defines the position of the sound source in 3D space.
DistanceModel
Defines how the volume of the sound scales with distance to the listener.
void directivityChanged()
The QVector3D class represents a vector or vertex in 3D space.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float x() const noexcept
Returns the x coordinate of this point.
constexpr float z() const noexcept
Returns the z coordinate of this point.
Combined button and popup list for selecting options.
constexpr const T & qBound(const T &min, const T &val, const T &max)
constexpr const T & qMax(const T &a, const T &b)
constexpr T qAbs(const T &t)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble q
GLfloat GLfloat GLfloat alpha
GLfixed GLfixed GLint GLint order
QSqlQueryModel * model
[16]
std::uniform_real_distribution dist(1, 2.5)
[2]
QUrl url("example.com")
[constructor-url-reference]