FAudioFX.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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/xaudio2fx/
  28. *
  29. * Note, however, that FAudio's Reverb implementation does NOT support the new
  30. * parameters for XAudio 2.9's 7.1 Reverb effect!
  31. */
  32. #ifndef FAUDIOFX_H
  33. #define FAUDIOFX_H
  34. #include "FAudio.h"
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif /* __cplusplus */
  38. /* GUIDs */
  39. extern const FAudioGUID FAudioFX_CLSID_AudioVolumeMeter;
  40. extern const FAudioGUID FAudioFX_CLSID_AudioReverb;
  41. /* Structures */
  42. #pragma pack(push, 1)
  43. typedef struct FAudioFXVolumeMeterLevels
  44. {
  45. float *pPeakLevels;
  46. float *pRMSLevels;
  47. uint32_t ChannelCount;
  48. } FAudioFXVolumeMeterLevels;
  49. typedef struct FAudioFXReverbParameters
  50. {
  51. float WetDryMix;
  52. uint32_t ReflectionsDelay;
  53. uint8_t ReverbDelay;
  54. uint8_t RearDelay;
  55. uint8_t PositionLeft;
  56. uint8_t PositionRight;
  57. uint8_t PositionMatrixLeft;
  58. uint8_t PositionMatrixRight;
  59. uint8_t EarlyDiffusion;
  60. uint8_t LateDiffusion;
  61. uint8_t LowEQGain;
  62. uint8_t LowEQCutoff;
  63. uint8_t HighEQGain;
  64. uint8_t HighEQCutoff;
  65. float RoomFilterFreq;
  66. float RoomFilterMain;
  67. float RoomFilterHF;
  68. float ReflectionsGain;
  69. float ReverbGain;
  70. float DecayTime;
  71. float Density;
  72. float RoomSize;
  73. } FAudioFXReverbParameters;
  74. typedef struct FAudioFXReverbParameters9
  75. {
  76. float WetDryMix;
  77. uint32_t ReflectionsDelay;
  78. uint8_t ReverbDelay;
  79. uint8_t RearDelay;
  80. uint8_t SideDelay;
  81. uint8_t PositionLeft;
  82. uint8_t PositionRight;
  83. uint8_t PositionMatrixLeft;
  84. uint8_t PositionMatrixRight;
  85. uint8_t EarlyDiffusion;
  86. uint8_t LateDiffusion;
  87. uint8_t LowEQGain;
  88. uint8_t LowEQCutoff;
  89. uint8_t HighEQGain;
  90. uint8_t HighEQCutoff;
  91. float RoomFilterFreq;
  92. float RoomFilterMain;
  93. float RoomFilterHF;
  94. float ReflectionsGain;
  95. float ReverbGain;
  96. float DecayTime;
  97. float Density;
  98. float RoomSize;
  99. } FAudioFXReverbParameters9;
  100. typedef struct FAudioFXReverbI3DL2Parameters
  101. {
  102. float WetDryMix;
  103. int32_t Room;
  104. int32_t RoomHF;
  105. float RoomRolloffFactor;
  106. float DecayTime;
  107. float DecayHFRatio;
  108. int32_t Reflections;
  109. float ReflectionsDelay;
  110. int32_t Reverb;
  111. float ReverbDelay;
  112. float Diffusion;
  113. float Density;
  114. float HFReference;
  115. } FAudioFXReverbI3DL2Parameters;
  116. #pragma pack(pop)
  117. /* Constants */
  118. #define FAUDIOFX_DEBUG 1
  119. #define FAUDIOFX_REVERB_MIN_FRAMERATE 20000
  120. #define FAUDIOFX_REVERB_MAX_FRAMERATE 48000
  121. #define FAUDIOFX_REVERB_MIN_WET_DRY_MIX 0.0f
  122. #define FAUDIOFX_REVERB_MIN_REFLECTIONS_DELAY 0
  123. #define FAUDIOFX_REVERB_MIN_REVERB_DELAY 0
  124. #define FAUDIOFX_REVERB_MIN_REAR_DELAY 0
  125. #define FAUDIOFX_REVERB_MIN_7POINT1_SIDE_DELAY 0
  126. #define FAUDIOFX_REVERB_MIN_7POINT1_REAR_DELAY 0
  127. #define FAUDIOFX_REVERB_MIN_POSITION 0
  128. #define FAUDIOFX_REVERB_MIN_DIFFUSION 0
  129. #define FAUDIOFX_REVERB_MIN_LOW_EQ_GAIN 0
  130. #define FAUDIOFX_REVERB_MIN_LOW_EQ_CUTOFF 0
  131. #define FAUDIOFX_REVERB_MIN_HIGH_EQ_GAIN 0
  132. #define FAUDIOFX_REVERB_MIN_HIGH_EQ_CUTOFF 0
  133. #define FAUDIOFX_REVERB_MIN_ROOM_FILTER_FREQ 20.0f
  134. #define FAUDIOFX_REVERB_MIN_ROOM_FILTER_MAIN -100.0f
  135. #define FAUDIOFX_REVERB_MIN_ROOM_FILTER_HF -100.0f
  136. #define FAUDIOFX_REVERB_MIN_REFLECTIONS_GAIN -100.0f
  137. #define FAUDIOFX_REVERB_MIN_REVERB_GAIN -100.0f
  138. #define FAUDIOFX_REVERB_MIN_DECAY_TIME 0.1f
  139. #define FAUDIOFX_REVERB_MIN_DENSITY 0.0f
  140. #define FAUDIOFX_REVERB_MIN_ROOM_SIZE 0.0f
  141. #define FAUDIOFX_REVERB_MAX_WET_DRY_MIX 100.0f
  142. #define FAUDIOFX_REVERB_MAX_REFLECTIONS_DELAY 300
  143. #define FAUDIOFX_REVERB_MAX_REVERB_DELAY 85
  144. #define FAUDIOFX_REVERB_MAX_REAR_DELAY 5
  145. #define FAUDIOFX_REVERB_MAX_7POINT1_SIDE_DELAY 5
  146. #define FAUDIOFX_REVERB_MAX_7POINT1_REAR_DELAY 20
  147. #define FAUDIOFX_REVERB_MAX_POSITION 30
  148. #define FAUDIOFX_REVERB_MAX_DIFFUSION 15
  149. #define FAUDIOFX_REVERB_MAX_LOW_EQ_GAIN 12
  150. #define FAUDIOFX_REVERB_MAX_LOW_EQ_CUTOFF 9
  151. #define FAUDIOFX_REVERB_MAX_HIGH_EQ_GAIN 8
  152. #define FAUDIOFX_REVERB_MAX_HIGH_EQ_CUTOFF 14
  153. #define FAUDIOFX_REVERB_MAX_ROOM_FILTER_FREQ 20000.0f
  154. #define FAUDIOFX_REVERB_MAX_ROOM_FILTER_MAIN 0.0f
  155. #define FAUDIOFX_REVERB_MAX_ROOM_FILTER_HF 0.0f
  156. #define FAUDIOFX_REVERB_MAX_REFLECTIONS_GAIN 20.0f
  157. #define FAUDIOFX_REVERB_MAX_REVERB_GAIN 20.0f
  158. #define FAUDIOFX_REVERB_MAX_DENSITY 100.0f
  159. #define FAUDIOFX_REVERB_MAX_ROOM_SIZE 100.0f
  160. #define FAUDIOFX_REVERB_DEFAULT_WET_DRY_MIX 100.0f
  161. #define FAUDIOFX_REVERB_DEFAULT_REFLECTIONS_DELAY 5
  162. #define FAUDIOFX_REVERB_DEFAULT_REVERB_DELAY 5
  163. #define FAUDIOFX_REVERB_DEFAULT_REAR_DELAY 5
  164. #define FAUDIOFX_REVERB_DEFAULT_7POINT1_SIDE_DELAY 5
  165. #define FAUDIOFX_REVERB_DEFAULT_7POINT1_REAR_DELAY 20
  166. #define FAUDIOFX_REVERB_DEFAULT_POSITION 6
  167. #define FAUDIOFX_REVERB_DEFAULT_POSITION_MATRIX 27
  168. #define FAUDIOFX_REVERB_DEFAULT_EARLY_DIFFUSION 8
  169. #define FAUDIOFX_REVERB_DEFAULT_LATE_DIFFUSION 8
  170. #define FAUDIOFX_REVERB_DEFAULT_LOW_EQ_GAIN 8
  171. #define FAUDIOFX_REVERB_DEFAULT_LOW_EQ_CUTOFF 4
  172. #define FAUDIOFX_REVERB_DEFAULT_HIGH_EQ_GAIN 8
  173. #define FAUDIOFX_REVERB_DEFAULT_HIGH_EQ_CUTOFF 4
  174. #define FAUDIOFX_REVERB_DEFAULT_ROOM_FILTER_FREQ 5000.0f
  175. #define FAUDIOFX_REVERB_DEFAULT_ROOM_FILTER_MAIN 0.0f
  176. #define FAUDIOFX_REVERB_DEFAULT_ROOM_FILTER_HF 0.0f
  177. #define FAUDIOFX_REVERB_DEFAULT_REFLECTIONS_GAIN 0.0f
  178. #define FAUDIOFX_REVERB_DEFAULT_REVERB_GAIN 0.0f
  179. #define FAUDIOFX_REVERB_DEFAULT_DECAY_TIME 1.0f
  180. #define FAUDIOFX_REVERB_DEFAULT_DENSITY 100.0f
  181. #define FAUDIOFX_REVERB_DEFAULT_ROOM_SIZE 100.0f
  182. #define FAUDIOFX_I3DL2_PRESET_DEFAULT \
  183. {100,-10000, 0,0.0f, 1.00f,0.50f,-10000,0.020f,-10000,0.040f,100.0f,100.0f,5000.0f}
  184. #define FAUDIOFX_I3DL2_PRESET_GENERIC \
  185. {100, -1000, -100,0.0f, 1.49f,0.83f, -2602,0.007f, 200,0.011f,100.0f,100.0f,5000.0f}
  186. #define FAUDIOFX_I3DL2_PRESET_PADDEDCELL \
  187. {100, -1000,-6000,0.0f, 0.17f,0.10f, -1204,0.001f, 207,0.002f,100.0f,100.0f,5000.0f}
  188. #define FAUDIOFX_I3DL2_PRESET_ROOM \
  189. {100, -1000, -454,0.0f, 0.40f,0.83f, -1646,0.002f, 53,0.003f,100.0f,100.0f,5000.0f}
  190. #define FAUDIOFX_I3DL2_PRESET_BATHROOM \
  191. {100, -1000,-1200,0.0f, 1.49f,0.54f, -370,0.007f, 1030,0.011f,100.0f, 60.0f,5000.0f}
  192. #define FAUDIOFX_I3DL2_PRESET_LIVINGROOM \
  193. {100, -1000,-6000,0.0f, 0.50f,0.10f, -1376,0.003f, -1104,0.004f,100.0f,100.0f,5000.0f}
  194. #define FAUDIOFX_I3DL2_PRESET_STONEROOM \
  195. {100, -1000, -300,0.0f, 2.31f,0.64f, -711,0.012f, 83,0.017f,100.0f,100.0f,5000.0f}
  196. #define FAUDIOFX_I3DL2_PRESET_AUDITORIUM \
  197. {100, -1000, -476,0.0f, 4.32f,0.59f, -789,0.020f, -289,0.030f,100.0f,100.0f,5000.0f}
  198. #define FAUDIOFX_I3DL2_PRESET_CONCERTHALL \
  199. {100, -1000, -500,0.0f, 3.92f,0.70f, -1230,0.020f, -2,0.029f,100.0f,100.0f,5000.0f}
  200. #define FAUDIOFX_I3DL2_PRESET_CAVE \
  201. {100, -1000, 0,0.0f, 2.91f,1.30f, -602,0.015f, -302,0.022f,100.0f,100.0f,5000.0f}
  202. #define FAUDIOFX_I3DL2_PRESET_ARENA \
  203. {100, -1000, -698,0.0f, 7.24f,0.33f, -1166,0.020f, 16,0.030f,100.0f,100.0f,5000.0f}
  204. #define FAUDIOFX_I3DL2_PRESET_HANGAR \
  205. {100, -1000,-1000,0.0f,10.05f,0.23f, -602,0.020f, 198,0.030f,100.0f,100.0f,5000.0f}
  206. #define FAUDIOFX_I3DL2_PRESET_CARPETEDHALLWAY \
  207. {100, -1000,-4000,0.0f, 0.30f,0.10f, -1831,0.002f, -1630,0.030f,100.0f,100.0f,5000.0f}
  208. #define FAUDIOFX_I3DL2_PRESET_HALLWAY \
  209. {100, -1000, -300,0.0f, 1.49f,0.59f, -1219,0.007f, 441,0.011f,100.0f,100.0f,5000.0f}
  210. #define FAUDIOFX_I3DL2_PRESET_STONECORRIDOR \
  211. {100, -1000, -237,0.0f, 2.70f,0.79f, -1214,0.013f, 395,0.020f,100.0f,100.0f,5000.0f}
  212. #define FAUDIOFX_I3DL2_PRESET_ALLEY \
  213. {100, -1000, -270,0.0f, 1.49f,0.86f, -1204,0.007f, -4,0.011f,100.0f,100.0f,5000.0f}
  214. #define FAUDIOFX_I3DL2_PRESET_FOREST \
  215. {100, -1000,-3300,0.0f, 1.49f,0.54f, -2560,0.162f, -613,0.088f, 79.0f,100.0f,5000.0f}
  216. #define FAUDIOFX_I3DL2_PRESET_CITY \
  217. {100, -1000, -800,0.0f, 1.49f,0.67f, -2273,0.007f, -2217,0.011f, 50.0f,100.0f,5000.0f}
  218. #define FAUDIOFX_I3DL2_PRESET_MOUNTAINS \
  219. {100, -1000,-2500,0.0f, 1.49f,0.21f, -2780,0.300f, -2014,0.100f, 27.0f,100.0f,5000.0f}
  220. #define FAUDIOFX_I3DL2_PRESET_QUARRY \
  221. {100, -1000,-1000,0.0f, 1.49f,0.83f,-10000,0.061f, 500,0.025f,100.0f,100.0f,5000.0f}
  222. #define FAUDIOFX_I3DL2_PRESET_PLAIN \
  223. {100, -1000,-2000,0.0f, 1.49f,0.50f, -2466,0.179f, -2514,0.100f, 21.0f,100.0f,5000.0f}
  224. #define FAUDIOFX_I3DL2_PRESET_PARKINGLOT \
  225. {100, -1000, 0,0.0f, 1.65f,1.50f, -1363,0.008f, -1153,0.012f,100.0f,100.0f,5000.0f}
  226. #define FAUDIOFX_I3DL2_PRESET_SEWERPIPE \
  227. {100, -1000,-1000,0.0f, 2.81f,0.14f, 429,0.014f, 648,0.021f, 80.0f, 60.0f,5000.0f}
  228. #define FAUDIOFX_I3DL2_PRESET_UNDERWATER \
  229. {100, -1000,-4000,0.0f, 1.49f,0.10f, -449,0.007f, 1700,0.011f,100.0f,100.0f,5000.0f}
  230. #define FAUDIOFX_I3DL2_PRESET_SMALLROOM \
  231. {100, -1000, -600,0.0f, 1.10f,0.83f, -400,0.005f, 500,0.010f,100.0f,100.0f,5000.0f}
  232. #define FAUDIOFX_I3DL2_PRESET_MEDIUMROOM \
  233. {100, -1000, -600,0.0f, 1.30f,0.83f, -1000,0.010f, -200,0.020f,100.0f,100.0f,5000.0f}
  234. #define FAUDIOFX_I3DL2_PRESET_LARGEROOM \
  235. {100, -1000, -600,0.0f, 1.50f,0.83f, -1600,0.020f, -1000,0.040f,100.0f,100.0f,5000.0f}
  236. #define FAUDIOFX_I3DL2_PRESET_MEDIUMHALL \
  237. {100, -1000, -600,0.0f, 1.80f,0.70f, -1300,0.015f, -800,0.030f,100.0f,100.0f,5000.0f}
  238. #define FAUDIOFX_I3DL2_PRESET_LARGEHALL \
  239. {100, -1000, -600,0.0f, 1.80f,0.70f, -2000,0.030f, -1400,0.060f,100.0f,100.0f,5000.0f}
  240. #define FAUDIOFX_I3DL2_PRESET_PLATE \
  241. {100, -1000, -200,0.0f, 1.30f,0.90f, 0,0.002f, 0,0.010f,100.0f, 75.0f,5000.0f}
  242. /* Functions */
  243. FAUDIOAPI uint32_t FAudioCreateVolumeMeter(FAPO** ppApo, uint32_t Flags);
  244. FAUDIOAPI uint32_t FAudioCreateReverb(FAPO** ppApo, uint32_t Flags);
  245. FAUDIOAPI uint32_t FAudioCreateReverb9(FAPO** ppApo, uint32_t Flags);
  246. /* See "extensions/CustomAllocatorEXT.txt" for more information. */
  247. FAUDIOAPI uint32_t FAudioCreateVolumeMeterWithCustomAllocatorEXT(
  248. FAPO** ppApo,
  249. uint32_t Flags,
  250. FAudioMallocFunc customMalloc,
  251. FAudioFreeFunc customFree,
  252. FAudioReallocFunc customRealloc
  253. );
  254. FAUDIOAPI uint32_t FAudioCreateReverbWithCustomAllocatorEXT(
  255. FAPO** ppApo,
  256. uint32_t Flags,
  257. FAudioMallocFunc customMalloc,
  258. FAudioFreeFunc customFree,
  259. FAudioReallocFunc customRealloc
  260. );
  261. FAUDIOAPI uint32_t FAudioCreateReverb9WithCustomAllocatorEXT(
  262. FAPO** ppApo,
  263. uint32_t Flags,
  264. FAudioMallocFunc customMalloc,
  265. FAudioFreeFunc customFree,
  266. FAudioReallocFunc customRealloc
  267. );
  268. FAUDIOAPI void ReverbConvertI3DL2ToNative(
  269. const FAudioFXReverbI3DL2Parameters *pI3DL2,
  270. FAudioFXReverbParameters *pNative
  271. );
  272. FAUDIOAPI void ReverbConvertI3DL2ToNative9(
  273. const FAudioFXReverbI3DL2Parameters *pI3DL2,
  274. FAudioFXReverbParameters9 *pNative,
  275. int32_t sevenDotOneReverb
  276. );
  277. #ifdef __cplusplus
  278. }
  279. #endif /* __cplusplus */
  280. #endif /* FAUDIOFX_H */
  281. /* vim: set noexpandtab shiftwidth=8 tabstop=8: */