CommonLibSSE (Parapets fork)
X3DAudio.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "RE/D/D3DTypes.h"
4 
5 namespace RE
6 {
7 #pragma pack(push, 1)
8 
10 
11  // instance handle of precalculated constants
12  using X3DAUDIO_HANDLE = std::byte[20];
13 
14  // Distance curve point:
15  // Defines a DSP setting at a given normalized distance.
17  {
18  float Distance; // 0 - normalized distance, must be within [0.0f, 1.0f]
19  float DSPSetting; // 4 - DSP setting
20  };
21  static_assert(sizeof(X3DAUDIO_DISTANCE_CURVE_POINT) == 0x8);
22 
23  // Distance curve:
24  // A piecewise curve made up of linear segments used to
25  // define DSP behaviour with respect to normalized distance.
26  //
27  // Note that curve point distances are normalized within [0.0f, 1.0f].
28  // X3DAUDIO_EMITTER.CurveDistanceScaler must be used to scale the
29  // normalized distances to user-defined world units.
30  // For distances beyond CurveDistanceScaler * 1.0f,
31  // pPoints[PointCount-1].DSPSetting is used as the DSP setting.
32  //
33  // All distance curve spans must be such that:
34  // pPoints[k-1].DSPSetting + ((pPoints[k].DSPSetting-pPoints[k-1].DSPSetting) / (pPoints[k].Distance-pPoints[k-1].Distance)) * (pPoints[k].Distance-pPoints[k-1].Distance) != NAN or infinite values
35  // For all points in the distance curve where 1 <= k < PointCount.
37  {
38  X3DAUDIO_DISTANCE_CURVE_POINT* pPoints; // 0 - distance curve point array, must have at least PointCount elements with no duplicates and be sorted in ascending order with respect to Distance
39  std::uint32_t PointCount; // 8 - number of distance curve points, must be >= 2 as all distance curves must have at least two endpoints, defining DSP settings at 0.0f and 1.0f normalized distance
40  };
41  static_assert(sizeof(X3DAUDIO_DISTANCE_CURVE) == 0xC);
42  inline static constexpr X3DAUDIO_DISTANCE_CURVE_POINT X3DAudioDefault_LinearCurvePoints[2] = { 0.0f, 1.0f, 1.0f, 0.0f };
44 
45  // Cone:
46  // Specifies directionality for a listener or single-channel emitter by
47  // modifying DSP behaviour with respect to its front orientation.
48  // This is modeled using two sound cones: an inner cone and an outer cone.
49  // On/within the inner cone, DSP settings are scaled by the inner values.
50  // On/beyond the outer cone, DSP settings are scaled by the outer values.
51  // If on both the cones, DSP settings are scaled by the inner values only.
52  // Between the two cones, the scaler is linearly interpolated between the
53  // inner and outer values. Set both cone angles to 0 or X3DAUDIO_2PI for
54  // omnidirectionality using only the outer or inner values respectively.
56  {
57  float InnerAngle; // 00 - inner cone angle in radians, must be within [0.0f, X3DAUDIO_2PI]
58  float OuterAngle; // 04 - outer cone angle in radians, must be within [InnerAngle, X3DAUDIO_2PI]
59  float InnerVolume; // 08 - volume level scaler on/within inner cone, used only for matrix calculations, must be within [0.0f, 2.0f] when used
60  float OuterVolume; // 0C - volume level scaler on/beyond outer cone, used only for matrix calculations, must be within [0.0f, 2.0f] when used
61  float InnerLPF; // 10 - LPF (both direct and reverb paths) coefficient subtrahend on/within inner cone, used only for LPF (both direct and reverb paths) calculations, must be within [0.0f, 1.0f] when used
62  float OuterLPF; // 14 - LPF (both direct and reverb paths) coefficient subtrahend on/beyond outer cone, used only for LPF (both direct and reverb paths) calculations, must be within [0.0f, 1.0f] when used
63  float InnerReverb; // 18 - reverb send level scaler on/within inner cone, used only for reverb calculations, must be within [0.0f, 2.0f] when used
64  float OuterReverb; // 1C - reverb send level scaler on/beyond outer cone, used only for reverb calculations, must be within [0.0f, 2.0f] when used
65  };
66  static_assert(sizeof(X3DAUDIO_CONE) == 0x20);
67 
68  // Listener:
69  // Defines a point of 3D audio reception.
70  //
71  // The cone is directed by the listener's front orientation.
73  {
74  X3DAUDIO_VECTOR OrientFront; // 00 - orientation of front direction, used only for matrix and delay calculations or listeners with cones for matrix, LPF (both direct and reverb paths), and reverb calculations, must be normalized when used
75  X3DAUDIO_VECTOR OrientTop; // 0C - orientation of top direction, used only for matrix and delay calculations, must be orthonormal with OrientFront when used
76  X3DAUDIO_VECTOR Position; // 18 - position in user-defined world units, does not affect Velocity
77  X3DAUDIO_VECTOR Velocity; // 24 - velocity vector in user-defined world units/second, used only for doppler calculations, does not affect Position
78  X3DAUDIO_CONE* pCone; // 30 - sound cone, used only for matrix, LPF (both direct and reverb paths), and reverb calculations, NULL specifies omnidirectionality
79  };
80  static_assert(sizeof(X3DAUDIO_LISTENER) == 0x38);
81 
82  // Emitter:
83  // Defines a 3D audio source, divided into two classifications:
84  //
85  // Single-point -- For use with single-channel sounds.
86  // Positioned at the emitter base, i.e. the channel radius
87  // and azimuth are ignored if the number of channels == 1.
88  //
89  // May be omnidirectional or directional using a cone.
90  // The cone originates from the emitter base position,
91  // and is directed by the emitter's front orientation.
92  //
93  // Multi-point -- For use with multi-channel sounds.
94  // Each non-LFE channel is positioned using an
95  // azimuth along the channel radius with respect to the
96  // front orientation vector in the plane orthogonal to the
97  // top orientation vector. An azimuth of X3DAUDIO_2PI
98  // specifies a channel is an LFE. Such channels are
99  // positioned at the emitter base and are calculated
100  // with respect to pLFECurve only, never pVolumeCurve.
101  //
102  // Multi-point emitters are always omnidirectional,
103  // i.e. the cone is ignored if the number of channels > 1.
104  //
105  // Note that many properties are shared among all channel points,
106  // locking certain behaviour with respect to the emitter base position.
107  // For example, doppler shift is always calculated with respect to the
108  // emitter base position and so is constant for all its channel points.
109  // Distance curve calculations are also with respect to the emitter base
110  // position, with the curves being calculated independently of each other.
111  // For instance, volume and LFE calculations do not affect one another.
113  {
114  X3DAUDIO_CONE* pCone; // 00 - sound cone, used only with single-channel emitters for matrix, LPF (both direct and reverb paths), and reverb calculations, NULL specifies omnidirectionality
115  X3DAUDIO_VECTOR OrientFront; // 08 - orientation of front direction, used only for emitter angle calculations or with multi-channel emitters for matrix calculations or single-channel emitters with cones for matrix, LPF (both direct and reverb paths), and reverb calculations, must be normalized when used
116  X3DAUDIO_VECTOR OrientTop; // 14 - orientation of top direction, used only with multi-channel emitters for matrix calculations, must be orthonormal with OrientFront when used
117  X3DAUDIO_VECTOR Position; // 20 - position in user-defined world units, does not affect Velocity
118  X3DAUDIO_VECTOR Velocity; // 2C - velocity vector in user-defined world units/second, used only for doppler calculations, does not affect Position
119  float InnerRadius; // 38 - inner radius, must be within [0.0f, FLT_MAX]
120  float InnerRadiusAngle; // 3C - inner radius angle, must be within [0.0f, X3DAUDIO_PI/4.0)
121  std::uint32_t ChannelCount; // 40 - number of sound channels, must be > 0
122  float ChannelRadius; // 44 - channel radius, used only with multi-channel emitters for matrix calculations, must be >= 0.0f when used
123  float* pChannelAzimuths; // 48 - channel azimuth array, used only with multi-channel emitters for matrix calculations, contains positions of each channel expressed in radians along the channel radius with respect to the front orientation vector in the plane orthogonal to the top orientation vector, or X3DAUDIO_2PI to specify an LFE channel, must have at least ChannelCount elements, all within [0.0f, X3DAUDIO_2PI] when used
124  X3DAUDIO_DISTANCE_CURVE* pVolumeCurve; // 50 - volume level distance curve, used only for matrix calculations, NULL specifies a default curve that conforms to the inverse square law, calculated in user-defined world units with distances <= CurveDistanceScaler clamped to no attenuation
125  X3DAUDIO_DISTANCE_CURVE* pLFECurve; // 58 - LFE level distance curve, used only for matrix calculations, NULL specifies a default curve that conforms to the inverse square law, calculated in user-defined world units with distances <= CurveDistanceScaler clamped to no attenuation
126  X3DAUDIO_DISTANCE_CURVE* pLPFDirectCurve; // 60 - LPF direct-path coefficient distance curve, used only for LPF direct-path calculations, NULL specifies the default curve: [0.0f,1.0f], [1.0f,0.75f]
127  X3DAUDIO_DISTANCE_CURVE* pLPFReverbCurve; // 68 - LPF reverb-path coefficient distance curve, used only for LPF reverb-path calculations, NULL specifies the default curve: [0.0f,0.75f], [1.0f,0.75f]
128  X3DAUDIO_DISTANCE_CURVE* pReverbCurve; // 70 - reverb send level distance curve, used only for reverb calculations, NULL specifies the default curve: [0.0f,1.0f], [1.0f,0.0f]
129  float CurveDistanceScalar; // 78 - curve distance scaler, used to scale normalized distance curves to user-defined world units and/or exaggerate their effect, used only for matrix, LPF (both direct and reverb paths), and reverb calculations, must be within [FLT_MIN, FLT_MAX] when used
130  float DopplerScalar; // 7C - doppler shift scaler, used to exaggerate doppler shift effect, used only for doppler calculations, must be within [0.0f, FLT_MAX] when used
131  };
132  static_assert(sizeof(X3DAUDIO_EMITTER) == 0x80);
133 
134  // DSP settings:
135  // Receives results from a call to X3DAudioCalculate to be sent
136  // to the low-level audio rendering API for 3D signal processing.
137  //
138  // The user is responsible for allocating the matrix coefficient table,
139  // delay time array, and initializing the channel counts when used.
141  {
142  float* pMatrixCoefficients; // 00 - [inout] matrix coefficient table, receives an array representing the volume level used to send from source channel S to destination channel D, stored as pMatrixCoefficients[SrcChannelCount * D + S], must have at least SrcChannelCount*DstChannelCount elements
143  float* pDelayTimes; // 08 - [inout] delay time array, receives delays for each destination channel in milliseconds, must have at least DstChannelCount elements (stereo final mix only)
144  std::uint32_t SrcChannelCount; // 10 - [in] number of source channels, must equal number of channels in respective emitter
145  std::uint32_t DstChannelCount; // 14 - [in] number of destination channels, must equal number of channels of the final mix
146  float LPFDirectCoefficient; // 18 - [out] LPF direct-path coefficient
147  float LPFReverbCoefficient; // 1C - [out] LPF reverb-path coefficient
148  float ReverbLevel; // 20 - [out] reverb send level
149  float DopplerFactor; // 24 - [out] doppler shift factor, scales resampler ratio for doppler shift effect, where the effective frequency = DopplerFactor * original frequency
150  float EmitterToListenerAngle; // 28 - [out] emitter-to-listener interior angle, expressed in radians with respect to the emitter's front orientation
151  float EmitterToListenerDistance; // 2C - [out] distance in user-defined world units from the emitter base to listener position, always calculated
152  float EmitterVelocityComponent; // 30 - [out] component of emitter velocity vector projected onto emitter->listener vector in user-defined world units/second, calculated only for doppler
153  float ListenerVelocityComponent; // 34 - [out] component of listener velocity vector projected onto emitter->listener vector in user-defined world units/second, calculated only for doppler
154  };
155  static_assert(sizeof(X3DAUDIO_DSP_SETTINGS) == 0x38);
156 
157 #pragma pack(pop)
158 }
Definition: AbsorbEffect.h:6
static constexpr X3DAUDIO_DISTANCE_CURVE_POINT X3DAudioDefault_LinearCurvePoints[2]
Definition: X3DAudio.h:42
static constexpr X3DAUDIO_DISTANCE_CURVE X3DAudioDefault_LinearCurve
Definition: X3DAudio.h:43
std::byte[20] X3DAUDIO_HANDLE
Definition: X3DAudio.h:12
Definition: D3DTypes.h:6
Definition: X3DAudio.h:56
float InnerVolume
Definition: X3DAudio.h:59
float InnerReverb
Definition: X3DAudio.h:63
float InnerLPF
Definition: X3DAudio.h:61
float OuterLPF
Definition: X3DAudio.h:62
float OuterVolume
Definition: X3DAudio.h:60
float InnerAngle
Definition: X3DAudio.h:57
float OuterReverb
Definition: X3DAudio.h:64
float OuterAngle
Definition: X3DAudio.h:58
Definition: X3DAudio.h:17
float Distance
Definition: X3DAudio.h:18
float DSPSetting
Definition: X3DAudio.h:19
Definition: X3DAudio.h:37
std::uint32_t PointCount
Definition: X3DAudio.h:39
X3DAUDIO_DISTANCE_CURVE_POINT * pPoints
Definition: X3DAudio.h:38
Definition: X3DAudio.h:141
float LPFReverbCoefficient
Definition: X3DAudio.h:147
float * pDelayTimes
Definition: X3DAudio.h:143
std::uint32_t DstChannelCount
Definition: X3DAudio.h:145
float ListenerVelocityComponent
Definition: X3DAudio.h:153
float DopplerFactor
Definition: X3DAudio.h:149
float EmitterToListenerDistance
Definition: X3DAudio.h:151
float EmitterToListenerAngle
Definition: X3DAudio.h:150
float ReverbLevel
Definition: X3DAudio.h:148
float EmitterVelocityComponent
Definition: X3DAudio.h:152
float LPFDirectCoefficient
Definition: X3DAudio.h:146
float * pMatrixCoefficients
Definition: X3DAudio.h:142
std::uint32_t SrcChannelCount
Definition: X3DAudio.h:144
Definition: X3DAudio.h:113
X3DAUDIO_VECTOR OrientFront
Definition: X3DAudio.h:115
X3DAUDIO_DISTANCE_CURVE * pReverbCurve
Definition: X3DAudio.h:128
float * pChannelAzimuths
Definition: X3DAudio.h:123
X3DAUDIO_DISTANCE_CURVE * pLFECurve
Definition: X3DAudio.h:125
X3DAUDIO_CONE * pCone
Definition: X3DAudio.h:114
float InnerRadiusAngle
Definition: X3DAudio.h:120
X3DAUDIO_DISTANCE_CURVE * pVolumeCurve
Definition: X3DAudio.h:124
float CurveDistanceScalar
Definition: X3DAudio.h:129
float DopplerScalar
Definition: X3DAudio.h:130
std::uint32_t ChannelCount
Definition: X3DAudio.h:121
float InnerRadius
Definition: X3DAudio.h:119
X3DAUDIO_VECTOR OrientTop
Definition: X3DAudio.h:116
X3DAUDIO_VECTOR Velocity
Definition: X3DAudio.h:118
float ChannelRadius
Definition: X3DAudio.h:122
X3DAUDIO_DISTANCE_CURVE * pLPFReverbCurve
Definition: X3DAudio.h:127
X3DAUDIO_DISTANCE_CURVE * pLPFDirectCurve
Definition: X3DAudio.h:126
X3DAUDIO_VECTOR Position
Definition: X3DAudio.h:117
Definition: X3DAudio.h:73
X3DAUDIO_CONE * pCone
Definition: X3DAudio.h:78
X3DAUDIO_VECTOR Velocity
Definition: X3DAudio.h:77
X3DAUDIO_VECTOR OrientTop
Definition: X3DAudio.h:75
X3DAUDIO_VECTOR OrientFront
Definition: X3DAudio.h:74
X3DAUDIO_VECTOR Position
Definition: X3DAudio.h:76