F3DAudio.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* FAudio - XAudio Reimplementation for FNA
  2. *
  3. * Copyright (c) 2011-2021 Ethan Lee, Luigi Auriemma, and the MonoGame Team
  4. *
  5. * This software is provided 'as-is', without any express or implied warranty.
  6. * In no event will the authors be held liable for any damages arising from
  7. * the use of this software.
  8. *
  9. * Permission is granted to anyone to use this software for any purpose,
  10. * including commercial applications, and to alter it and redistribute it
  11. * freely, subject to the following restrictions:
  12. *
  13. * 1. The origin of this software must not be misrepresented; you must not
  14. * claim that you wrote the original software. If you use this software in a
  15. * product, an acknowledgment in the product documentation would be
  16. * appreciated but is not required.
  17. *
  18. * 2. Altered source versions must be plainly marked as such, and must not be
  19. * misrepresented as being the original software.
  20. *
  21. * 3. This notice may not be removed or altered from any source distribution.
  22. *
  23. * Ethan "flibitijibibo" Lee <flibitijibibo@flibitijibibo.com>
  24. *
  25. */
  26. /* This file has no documentation since the MSDN docs are still perfectly fine:
  27. * https://docs.microsoft.com/en-us/windows/desktop/api/x3daudio/
  28. */
  29. #ifndef F3DAUDIO_H
  30. #define F3DAUDIO_H
  31. #ifdef _WIN32
  32. #define F3DAUDIOAPI
  33. #else
  34. #define F3DAUDIOAPI
  35. #endif
  36. #include <stdint.h>
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif /* __cplusplus */
  40. /* Constants */
  41. #ifndef _SPEAKER_POSITIONS_
  42. #define SPEAKER_FRONT_LEFT 0x00000001
  43. #define SPEAKER_FRONT_RIGHT 0x00000002
  44. #define SPEAKER_FRONT_CENTER 0x00000004
  45. #define SPEAKER_LOW_FREQUENCY 0x00000008
  46. #define SPEAKER_BACK_LEFT 0x00000010
  47. #define SPEAKER_BACK_RIGHT 0x00000020
  48. #define SPEAKER_FRONT_LEFT_OF_CENTER 0x00000040
  49. #define SPEAKER_FRONT_RIGHT_OF_CENTER 0x00000080
  50. #define SPEAKER_BACK_CENTER 0x00000100
  51. #define SPEAKER_SIDE_LEFT 0x00000200
  52. #define SPEAKER_SIDE_RIGHT 0x00000400
  53. #define SPEAKER_TOP_CENTER 0x00000800
  54. #define SPEAKER_TOP_FRONT_LEFT 0x00001000
  55. #define SPEAKER_TOP_FRONT_CENTER 0x00002000
  56. #define SPEAKER_TOP_FRONT_RIGHT 0x00004000
  57. #define SPEAKER_TOP_BACK_LEFT 0x00008000
  58. #define SPEAKER_TOP_BACK_CENTER 0x00010000
  59. #define SPEAKER_TOP_BACK_RIGHT 0x00020000
  60. #define _SPEAKER_POSITIONS_
  61. #endif
  62. #ifndef SPEAKER_MONO
  63. #define SPEAKER_MONO SPEAKER_FRONT_CENTER
  64. #define SPEAKER_STEREO (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT)
  65. #define SPEAKER_2POINT1 \
  66. ( SPEAKER_FRONT_LEFT | \
  67. SPEAKER_FRONT_RIGHT | \
  68. SPEAKER_LOW_FREQUENCY )
  69. #define SPEAKER_SURROUND \
  70. ( SPEAKER_FRONT_LEFT | \
  71. SPEAKER_FRONT_RIGHT | \
  72. SPEAKER_FRONT_CENTER | \
  73. SPEAKER_BACK_CENTER )
  74. #define SPEAKER_QUAD \
  75. ( SPEAKER_FRONT_LEFT | \
  76. SPEAKER_FRONT_RIGHT | \
  77. SPEAKER_BACK_LEFT | \
  78. SPEAKER_BACK_RIGHT )
  79. #define SPEAKER_4POINT1 \
  80. ( SPEAKER_FRONT_LEFT | \
  81. SPEAKER_FRONT_RIGHT | \
  82. SPEAKER_LOW_FREQUENCY | \
  83. SPEAKER_BACK_LEFT | \
  84. SPEAKER_BACK_RIGHT )
  85. #define SPEAKER_5POINT1 \
  86. ( SPEAKER_FRONT_LEFT | \
  87. SPEAKER_FRONT_RIGHT | \
  88. SPEAKER_FRONT_CENTER | \
  89. SPEAKER_LOW_FREQUENCY | \
  90. SPEAKER_BACK_LEFT | \
  91. SPEAKER_BACK_RIGHT )
  92. #define SPEAKER_7POINT1 \
  93. ( SPEAKER_FRONT_LEFT | \
  94. SPEAKER_FRONT_RIGHT | \
  95. SPEAKER_FRONT_CENTER | \
  96. SPEAKER_LOW_FREQUENCY | \
  97. SPEAKER_BACK_LEFT | \
  98. SPEAKER_BACK_RIGHT | \
  99. SPEAKER_FRONT_LEFT_OF_CENTER | \
  100. SPEAKER_FRONT_RIGHT_OF_CENTER )
  101. #define SPEAKER_5POINT1_SURROUND \
  102. ( SPEAKER_FRONT_LEFT | \
  103. SPEAKER_FRONT_RIGHT | \
  104. SPEAKER_FRONT_CENTER | \
  105. SPEAKER_LOW_FREQUENCY | \
  106. SPEAKER_SIDE_LEFT | \
  107. SPEAKER_SIDE_RIGHT )
  108. #define SPEAKER_7POINT1_SURROUND \
  109. ( SPEAKER_FRONT_LEFT | \
  110. SPEAKER_FRONT_RIGHT | \
  111. SPEAKER_FRONT_CENTER | \
  112. SPEAKER_LOW_FREQUENCY | \
  113. SPEAKER_BACK_LEFT | \
  114. SPEAKER_BACK_RIGHT | \
  115. SPEAKER_SIDE_LEFT | \
  116. SPEAKER_SIDE_RIGHT )
  117. #define SPEAKER_XBOX SPEAKER_5POINT1
  118. #endif
  119. #define F3DAUDIO_PI 3.141592654f
  120. #define F3DAUDIO_2PI 6.283185307f
  121. #define F3DAUDIO_CALCULATE_MATRIX 0x00000001
  122. #define F3DAUDIO_CALCULATE_DELAY 0x00000002
  123. #define F3DAUDIO_CALCULATE_LPF_DIRECT 0x00000004
  124. #define F3DAUDIO_CALCULATE_LPF_REVERB 0x00000008
  125. #define F3DAUDIO_CALCULATE_REVERB 0x00000010
  126. #define F3DAUDIO_CALCULATE_DOPPLER 0x00000020
  127. #define F3DAUDIO_CALCULATE_EMITTER_ANGLE 0x00000040
  128. #define F3DAUDIO_CALCULATE_ZEROCENTER 0x00010000
  129. #define F3DAUDIO_CALCULATE_REDIRECT_TO_LFE 0x00020000
  130. /* Type Declarations */
  131. #define F3DAUDIO_HANDLE_BYTESIZE 20
  132. typedef uint8_t F3DAUDIO_HANDLE[F3DAUDIO_HANDLE_BYTESIZE];
  133. /* Structures */
  134. #pragma pack(push, 1)
  135. typedef struct F3DAUDIO_VECTOR
  136. {
  137. float x;
  138. float y;
  139. float z;
  140. } F3DAUDIO_VECTOR;
  141. typedef struct F3DAUDIO_DISTANCE_CURVE_POINT
  142. {
  143. float Distance;
  144. float DSPSetting;
  145. } F3DAUDIO_DISTANCE_CURVE_POINT;
  146. typedef struct F3DAUDIO_DISTANCE_CURVE
  147. {
  148. F3DAUDIO_DISTANCE_CURVE_POINT *pPoints;
  149. uint32_t PointCount;
  150. } F3DAUDIO_DISTANCE_CURVE;
  151. typedef struct F3DAUDIO_CONE
  152. {
  153. float InnerAngle;
  154. float OuterAngle;
  155. float InnerVolume;
  156. float OuterVolume;
  157. float InnerLPF;
  158. float OuterLPF;
  159. float InnerReverb;
  160. float OuterReverb;
  161. } F3DAUDIO_CONE;
  162. typedef struct F3DAUDIO_LISTENER
  163. {
  164. F3DAUDIO_VECTOR OrientFront;
  165. F3DAUDIO_VECTOR OrientTop;
  166. F3DAUDIO_VECTOR Position;
  167. F3DAUDIO_VECTOR Velocity;
  168. F3DAUDIO_CONE *pCone;
  169. } F3DAUDIO_LISTENER;
  170. typedef struct F3DAUDIO_EMITTER
  171. {
  172. F3DAUDIO_CONE *pCone;
  173. F3DAUDIO_VECTOR OrientFront;
  174. F3DAUDIO_VECTOR OrientTop;
  175. F3DAUDIO_VECTOR Position;
  176. F3DAUDIO_VECTOR Velocity;
  177. float InnerRadius;
  178. float InnerRadiusAngle;
  179. uint32_t ChannelCount;
  180. float ChannelRadius;
  181. float *pChannelAzimuths;
  182. F3DAUDIO_DISTANCE_CURVE *pVolumeCurve;
  183. F3DAUDIO_DISTANCE_CURVE *pLFECurve;
  184. F3DAUDIO_DISTANCE_CURVE *pLPFDirectCurve;
  185. F3DAUDIO_DISTANCE_CURVE *pLPFReverbCurve;
  186. F3DAUDIO_DISTANCE_CURVE *pReverbCurve;
  187. float CurveDistanceScaler;
  188. float DopplerScaler;
  189. } F3DAUDIO_EMITTER;
  190. #ifndef F3DAUDIO_DSP_SETTINGS_DECL
  191. #define F3DAUDIO_DSP_SETTINGS_DECL
  192. typedef struct F3DAUDIO_DSP_SETTINGS F3DAUDIO_DSP_SETTINGS;
  193. #endif /* F3DAUDIO_DSP_SETTINGS_DECL */
  194. struct F3DAUDIO_DSP_SETTINGS
  195. {
  196. float *pMatrixCoefficients;
  197. float *pDelayTimes;
  198. uint32_t SrcChannelCount;
  199. uint32_t DstChannelCount;
  200. float LPFDirectCoefficient;
  201. float LPFReverbCoefficient;
  202. float ReverbLevel;
  203. float DopplerFactor;
  204. float EmitterToListenerAngle;
  205. float EmitterToListenerDistance;
  206. float EmitterVelocityComponent;
  207. float ListenerVelocityComponent;
  208. };
  209. #pragma pack(pop)
  210. /* Functions */
  211. F3DAUDIOAPI void F3DAudioInitialize(
  212. uint32_t SpeakerChannelMask,
  213. float SpeedOfSound,
  214. F3DAUDIO_HANDLE Instance
  215. );
  216. F3DAUDIOAPI uint32_t F3DAudioInitialize8(
  217. uint32_t SpeakerChannelMask,
  218. float SpeedOfSound,
  219. F3DAUDIO_HANDLE Instance
  220. );
  221. F3DAUDIOAPI void F3DAudioCalculate(
  222. const F3DAUDIO_HANDLE Instance,
  223. const F3DAUDIO_LISTENER *pListener,
  224. const F3DAUDIO_EMITTER *pEmitter,
  225. uint32_t Flags,
  226. F3DAUDIO_DSP_SETTINGS *pDSPSettings
  227. );
  228. #ifdef __cplusplus
  229. }
  230. #endif /* __cplusplus */
  231. #endif /* F3DAUDIO_H */
  232. /* vim: set noexpandtab shiftwidth=8 tabstop=8: */