-
Notifications
You must be signed in to change notification settings - Fork 511
AudioListener
DirectXTK | Audio |
---|
AudioListener is a helper object derived from X3DAUDIO_LISTENER that can be used by the Apply3D method of SoundEffectInstance, SoundStreamInstance, and DynamicSoundEffectInstance.
See AudioEmitter.
Related tutorial: Using positional audio
#include <Audio.h>
The default constructor creates a listener located at 0,0,0 facing -z
and an up vector of +y
.
When using left-handed coordinates, be sure to set
OrientFront
In addition to setting the members of X3DAUDIO_LISTENER
directly, these helper functions are provided:
-
SetPosition (XMVECTOR) or (XMFLOAT3): Sets the Position of the listener.
-
SetVelocity (XMVECTOR) or (XMFLOAT3): Sets the Velocity of the listener.
-
SetOrientation (XMVECTOR forward, XMVECTOR up) or (XMFLOAT3 forward, XMFLOAT3 up)
-
SetOrientationFromQuaternion (XMVECTOR): Sets the OrientFront/OrientTop of the listener.
-
Update (XMVECTOR newPos, XMVECTOR upDir, float dt): Computes a direction and velocity for the listener based on the current Position value, the new position, and the provided delta time (Δt). This updates the OrientFront/OrientTop to match, and then sets the Position to the new position. If dt is 0, the update is skipped.
float dt = static_cast<float>(timer.GetElapsedSeconds());
emitter.Update(soundPosition, Vector3::Up, dt);
listener.Update(playerPosiiton, Vector3::Up, dt);
if (soundSource)
{
soundSource->Apply3D(listener, emitter);
}
GameFest 2010: The (3D) Sound of Success: X3DAudio and Sound Positioning
All content and source code for this package are subject to the terms of the MIT License.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
- Universal Windows Platform apps
- Windows desktop apps
- Windows 11
- Windows 10
- Windows 8.1
- Windows 7 Service Pack 1
- Xbox One
- x86
- x64
- ARM64
- Visual Studio 2022
- Visual Studio 2019 (16.11)
- clang/LLVM v12 - v18
- MinGW 12.2, 13.2
- CMake 3.20