FAudio.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  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. #ifndef FAUDIO_H
  27. #define FAUDIO_H
  28. #ifdef _WIN32
  29. #define FAUDIOAPI
  30. #define FAUDIOCALL
  31. #else
  32. #define FAUDIOAPI
  33. #define FAUDIOCALL
  34. #endif
  35. #ifdef _MSC_VER
  36. #define FAUDIODEPRECATED(msg) __declspec(deprecated(msg))
  37. #else
  38. #define FAUDIODEPRECATED(msg) __attribute__((deprecated(msg)))
  39. #endif
  40. /* -Wpedantic nameless union/struct silencing */
  41. #ifndef FAUDIONAMELESS
  42. #ifdef __GNUC__
  43. #define FAUDIONAMELESS __extension__
  44. #else
  45. #define FAUDIONAMELESS
  46. #endif /* __GNUC__ */
  47. #endif /* FAUDIONAMELESS */
  48. #include <stdint.h>
  49. #include <stddef.h>
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif /* __cplusplus */
  53. /* Type Declarations */
  54. typedef struct FAudio FAudio;
  55. typedef struct FAudioVoice FAudioVoice;
  56. typedef FAudioVoice FAudioSourceVoice;
  57. typedef FAudioVoice FAudioSubmixVoice;
  58. typedef FAudioVoice FAudioMasteringVoice;
  59. typedef struct FAudioEngineCallback FAudioEngineCallback;
  60. typedef struct FAudioVoiceCallback FAudioVoiceCallback;
  61. /* Enumerations */
  62. typedef enum FAudioDeviceRole
  63. {
  64. FAudioNotDefaultDevice = 0x0,
  65. FAudioDefaultConsoleDevice = 0x1,
  66. FAudioDefaultMultimediaDevice = 0x2,
  67. FAudioDefaultCommunicationsDevice = 0x4,
  68. FAudioDefaultGameDevice = 0x8,
  69. FAudioGlobalDefaultDevice = 0xF,
  70. FAudioInvalidDeviceRole = ~FAudioGlobalDefaultDevice
  71. } FAudioDeviceRole;
  72. typedef enum FAudioFilterType
  73. {
  74. FAudioLowPassFilter,
  75. FAudioBandPassFilter,
  76. FAudioHighPassFilter,
  77. FAudioNotchFilter
  78. } FAudioFilterType;
  79. typedef enum FAudioStreamCategory
  80. {
  81. FAudioStreamCategory_Other,
  82. FAudioStreamCategory_ForegroundOnlyMedia,
  83. FAudioStreamCategory_BackgroundCapableMedia,
  84. FAudioStreamCategory_Communications,
  85. FAudioStreamCategory_Alerts,
  86. FAudioStreamCategory_SoundEffects,
  87. FAudioStreamCategory_GameEffects,
  88. FAudioStreamCategory_GameMedia,
  89. FAudioStreamCategory_GameChat,
  90. FAudioStreamCategory_Speech,
  91. FAudioStreamCategory_Movie,
  92. FAudioStreamCategory_Media
  93. } FAudioStreamCategory;
  94. /* FIXME: The original enum violates ISO C and is platform specific anyway... */
  95. typedef uint32_t FAudioProcessor;
  96. #define FAUDIO_DEFAULT_PROCESSOR 0xFFFFFFFF
  97. /* Structures */
  98. #pragma pack(push, 1)
  99. typedef struct FAudioGUID
  100. {
  101. uint32_t Data1;
  102. uint16_t Data2;
  103. uint16_t Data3;
  104. uint8_t Data4[8];
  105. } FAudioGUID;
  106. /* See MSDN:
  107. * https://msdn.microsoft.com/en-us/library/windows/desktop/dd390970%28v=vs.85%29.aspx
  108. */
  109. typedef struct FAudioWaveFormatEx
  110. {
  111. uint16_t wFormatTag;
  112. uint16_t nChannels;
  113. uint32_t nSamplesPerSec;
  114. uint32_t nAvgBytesPerSec;
  115. uint16_t nBlockAlign;
  116. uint16_t wBitsPerSample;
  117. uint16_t cbSize;
  118. } FAudioWaveFormatEx;
  119. /* See MSDN:
  120. * https://msdn.microsoft.com/en-us/library/windows/desktop/dd390971(v=vs.85).aspx
  121. */
  122. typedef struct FAudioWaveFormatExtensible
  123. {
  124. FAudioWaveFormatEx Format;
  125. union
  126. {
  127. uint16_t wValidBitsPerSample;
  128. uint16_t wSamplesPerBlock;
  129. uint16_t wReserved;
  130. } Samples;
  131. uint32_t dwChannelMask;
  132. FAudioGUID SubFormat;
  133. } FAudioWaveFormatExtensible;
  134. typedef struct FAudioADPCMCoefSet
  135. {
  136. int16_t iCoef1;
  137. int16_t iCoef2;
  138. } FAudioADPCMCoefSet;
  139. typedef struct FAudioADPCMWaveFormat
  140. {
  141. FAudioWaveFormatEx wfx;
  142. uint16_t wSamplesPerBlock;
  143. uint16_t wNumCoef;
  144. /* MSVC warns on empty arrays in structs */
  145. #ifdef _MSC_VER
  146. #pragma warning(push)
  147. #pragma warning(disable: 4200)
  148. #endif
  149. FAudioADPCMCoefSet aCoef[];
  150. /* MSADPCM has 7 coefficient pairs:
  151. * {
  152. * { 256, 0 },
  153. * { 512, -256 },
  154. * { 0, 0 },
  155. * { 192, 64 },
  156. * { 240, 0 },
  157. * { 460, -208 },
  158. * { 392, -232 }
  159. * }
  160. */
  161. #ifdef _MSC_VER
  162. #pragma warning(pop)
  163. #endif
  164. } FAudioADPCMWaveFormat;
  165. typedef struct FAudioDeviceDetails
  166. {
  167. int16_t DeviceID[256]; /* Win32 wchar_t */
  168. int16_t DisplayName[256]; /* Win32 wchar_t */
  169. FAudioDeviceRole Role;
  170. FAudioWaveFormatExtensible OutputFormat;
  171. } FAudioDeviceDetails;
  172. typedef struct FAudioVoiceDetails
  173. {
  174. uint32_t CreationFlags;
  175. uint32_t ActiveFlags;
  176. uint32_t InputChannels;
  177. uint32_t InputSampleRate;
  178. } FAudioVoiceDetails;
  179. typedef struct FAudioSendDescriptor
  180. {
  181. uint32_t Flags; /* 0 or FAUDIO_SEND_USEFILTER */
  182. FAudioVoice *pOutputVoice;
  183. } FAudioSendDescriptor;
  184. typedef struct FAudioVoiceSends
  185. {
  186. uint32_t SendCount;
  187. FAudioSendDescriptor *pSends;
  188. } FAudioVoiceSends;
  189. #ifndef FAPO_DECL
  190. #define FAPO_DECL
  191. typedef struct FAPO FAPO;
  192. #endif /* FAPO_DECL */
  193. typedef struct FAudioEffectDescriptor
  194. {
  195. FAPO *pEffect;
  196. int32_t InitialState; /* 1 - Enabled, 0 - Disabled */
  197. uint32_t OutputChannels;
  198. } FAudioEffectDescriptor;
  199. typedef struct FAudioEffectChain
  200. {
  201. uint32_t EffectCount;
  202. FAudioEffectDescriptor *pEffectDescriptors;
  203. } FAudioEffectChain;
  204. typedef struct FAudioFilterParameters
  205. {
  206. FAudioFilterType Type;
  207. float Frequency; /* [0, FAUDIO_MAX_FILTER_FREQUENCY] */
  208. float OneOverQ; /* [0, FAUDIO_MAX_FILTER_ONEOVERQ] */
  209. } FAudioFilterParameters;
  210. typedef struct FAudioBuffer
  211. {
  212. /* Either 0 or FAUDIO_END_OF_STREAM */
  213. uint32_t Flags;
  214. /* Pointer to wave data, memory block size.
  215. * Note that pAudioData is not copied; FAudio reads directly from your
  216. * pointer! This pointer must be valid until FAudio has finished using
  217. * it, at which point an OnBufferEnd callback will be generated.
  218. */
  219. uint32_t AudioBytes;
  220. const uint8_t *pAudioData;
  221. /* Play region, in sample frames. */
  222. uint32_t PlayBegin;
  223. uint32_t PlayLength;
  224. /* Loop region, in sample frames.
  225. * This can be used to loop a subregion of the wave instead of looping
  226. * the whole thing, i.e. if you have an intro/outro you can set these
  227. * to loop the middle sections instead. If you don't need this, set both
  228. * values to 0.
  229. */
  230. uint32_t LoopBegin;
  231. uint32_t LoopLength;
  232. /* [0, FAUDIO_LOOP_INFINITE] */
  233. uint32_t LoopCount;
  234. /* This is sent to callbacks as pBufferContext */
  235. void *pContext;
  236. } FAudioBuffer;
  237. typedef struct FAudioBufferWMA
  238. {
  239. const uint32_t *pDecodedPacketCumulativeBytes;
  240. uint32_t PacketCount;
  241. } FAudioBufferWMA;
  242. typedef struct FAudioVoiceState
  243. {
  244. void *pCurrentBufferContext;
  245. uint32_t BuffersQueued;
  246. uint64_t SamplesPlayed;
  247. } FAudioVoiceState;
  248. typedef struct FAudioPerformanceData
  249. {
  250. uint64_t AudioCyclesSinceLastQuery;
  251. uint64_t TotalCyclesSinceLastQuery;
  252. uint32_t MinimumCyclesPerQuantum;
  253. uint32_t MaximumCyclesPerQuantum;
  254. uint32_t MemoryUsageInBytes;
  255. uint32_t CurrentLatencyInSamples;
  256. uint32_t GlitchesSinceEngineStarted;
  257. uint32_t ActiveSourceVoiceCount;
  258. uint32_t TotalSourceVoiceCount;
  259. uint32_t ActiveSubmixVoiceCount;
  260. uint32_t ActiveResamplerCount;
  261. uint32_t ActiveMatrixMixCount;
  262. uint32_t ActiveXmaSourceVoices;
  263. uint32_t ActiveXmaStreams;
  264. } FAudioPerformanceData;
  265. typedef struct FAudioDebugConfiguration
  266. {
  267. /* See FAUDIO_LOG_* */
  268. uint32_t TraceMask;
  269. uint32_t BreakMask;
  270. /* 0 or 1 */
  271. int32_t LogThreadID;
  272. int32_t LogFileline;
  273. int32_t LogFunctionName;
  274. int32_t LogTiming;
  275. } FAudioDebugConfiguration;
  276. #pragma pack(pop)
  277. /* This ISN'T packed. Strictly speaking it wouldn't have mattered anyway but eh.
  278. * See https://github.com/microsoft/DirectXTK/issues/256
  279. */
  280. typedef struct FAudioXMA2WaveFormatEx
  281. {
  282. FAudioWaveFormatEx wfx;
  283. uint16_t wNumStreams;
  284. uint32_t dwChannelMask;
  285. uint32_t dwSamplesEncoded;
  286. uint32_t dwBytesPerBlock;
  287. uint32_t dwPlayBegin;
  288. uint32_t dwPlayLength;
  289. uint32_t dwLoopBegin;
  290. uint32_t dwLoopLength;
  291. uint8_t bLoopCount;
  292. uint8_t bEncoderVersion;
  293. uint16_t wBlockCount;
  294. } FAudioXMA2WaveFormat;
  295. /* Constants */
  296. #define FAUDIO_E_OUT_OF_MEMORY 0x8007000e
  297. #define FAUDIO_E_INVALID_ARG 0x80070057
  298. #define FAUDIO_E_UNSUPPORTED_FORMAT 0x88890008
  299. #define FAUDIO_E_INVALID_CALL 0x88960001
  300. #define FAUDIO_E_DEVICE_INVALIDATED 0x88960004
  301. #define FAPO_E_FORMAT_UNSUPPORTED 0x88970001
  302. #define FAUDIO_MAX_BUFFER_BYTES 0x80000000
  303. #define FAUDIO_MAX_QUEUED_BUFFERS 64
  304. #define FAUDIO_MAX_AUDIO_CHANNELS 64
  305. #define FAUDIO_MIN_SAMPLE_RATE 1000
  306. #define FAUDIO_MAX_SAMPLE_RATE 200000
  307. #define FAUDIO_MAX_VOLUME_LEVEL 16777216.0f
  308. #define FAUDIO_MIN_FREQ_RATIO (1.0f / 1024.0f)
  309. #define FAUDIO_MAX_FREQ_RATIO 1024.0f
  310. #define FAUDIO_DEFAULT_FREQ_RATIO 2.0f
  311. #define FAUDIO_MAX_FILTER_ONEOVERQ 1.5f
  312. #define FAUDIO_MAX_FILTER_FREQUENCY 1.0f
  313. #define FAUDIO_MAX_LOOP_COUNT 254
  314. #define FAUDIO_COMMIT_NOW 0
  315. #define FAUDIO_COMMIT_ALL 0
  316. #define FAUDIO_INVALID_OPSET (uint32_t) (-1)
  317. #define FAUDIO_NO_LOOP_REGION 0
  318. #define FAUDIO_LOOP_INFINITE 255
  319. #define FAUDIO_DEFAULT_CHANNELS 0
  320. #define FAUDIO_DEFAULT_SAMPLERATE 0
  321. #define FAUDIO_DEBUG_ENGINE 0x0001
  322. #define FAUDIO_VOICE_NOPITCH 0x0002
  323. #define FAUDIO_VOICE_NOSRC 0x0004
  324. #define FAUDIO_VOICE_USEFILTER 0x0008
  325. #define FAUDIO_VOICE_MUSIC 0x0010
  326. #define FAUDIO_PLAY_TAILS 0x0020
  327. #define FAUDIO_END_OF_STREAM 0x0040
  328. #define FAUDIO_SEND_USEFILTER 0x0080
  329. #define FAUDIO_VOICE_NOSAMPLESPLAYED 0x0100
  330. #define FAUDIO_1024_QUANTUM 0x8000
  331. #define FAUDIO_DEFAULT_FILTER_TYPE FAudioLowPassFilter
  332. #define FAUDIO_DEFAULT_FILTER_FREQUENCY FAUDIO_MAX_FILTER_FREQUENCY
  333. #define FAUDIO_DEFAULT_FILTER_ONEOVERQ 1.0f
  334. #define FAUDIO_LOG_ERRORS 0x0001
  335. #define FAUDIO_LOG_WARNINGS 0x0002
  336. #define FAUDIO_LOG_INFO 0x0004
  337. #define FAUDIO_LOG_DETAIL 0x0008
  338. #define FAUDIO_LOG_API_CALLS 0x0010
  339. #define FAUDIO_LOG_FUNC_CALLS 0x0020
  340. #define FAUDIO_LOG_TIMING 0x0040
  341. #define FAUDIO_LOG_LOCKS 0x0080
  342. #define FAUDIO_LOG_MEMORY 0x0100
  343. #define FAUDIO_LOG_STREAMING 0x1000
  344. #ifndef _SPEAKER_POSITIONS_
  345. #define SPEAKER_FRONT_LEFT 0x00000001
  346. #define SPEAKER_FRONT_RIGHT 0x00000002
  347. #define SPEAKER_FRONT_CENTER 0x00000004
  348. #define SPEAKER_LOW_FREQUENCY 0x00000008
  349. #define SPEAKER_BACK_LEFT 0x00000010
  350. #define SPEAKER_BACK_RIGHT 0x00000020
  351. #define SPEAKER_FRONT_LEFT_OF_CENTER 0x00000040
  352. #define SPEAKER_FRONT_RIGHT_OF_CENTER 0x00000080
  353. #define SPEAKER_BACK_CENTER 0x00000100
  354. #define SPEAKER_SIDE_LEFT 0x00000200
  355. #define SPEAKER_SIDE_RIGHT 0x00000400
  356. #define SPEAKER_TOP_CENTER 0x00000800
  357. #define SPEAKER_TOP_FRONT_LEFT 0x00001000
  358. #define SPEAKER_TOP_FRONT_CENTER 0x00002000
  359. #define SPEAKER_TOP_FRONT_RIGHT 0x00004000
  360. #define SPEAKER_TOP_BACK_LEFT 0x00008000
  361. #define SPEAKER_TOP_BACK_CENTER 0x00010000
  362. #define SPEAKER_TOP_BACK_RIGHT 0x00020000
  363. #define _SPEAKER_POSITIONS_
  364. #endif
  365. #ifndef SPEAKER_MONO
  366. #define SPEAKER_MONO SPEAKER_FRONT_CENTER
  367. #define SPEAKER_STEREO (SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT)
  368. #define SPEAKER_2POINT1 \
  369. ( SPEAKER_FRONT_LEFT | \
  370. SPEAKER_FRONT_RIGHT | \
  371. SPEAKER_LOW_FREQUENCY )
  372. #define SPEAKER_SURROUND \
  373. ( SPEAKER_FRONT_LEFT | \
  374. SPEAKER_FRONT_RIGHT | \
  375. SPEAKER_FRONT_CENTER | \
  376. SPEAKER_BACK_CENTER )
  377. #define SPEAKER_QUAD \
  378. ( SPEAKER_FRONT_LEFT | \
  379. SPEAKER_FRONT_RIGHT | \
  380. SPEAKER_BACK_LEFT | \
  381. SPEAKER_BACK_RIGHT )
  382. #define SPEAKER_4POINT1 \
  383. ( SPEAKER_FRONT_LEFT | \
  384. SPEAKER_FRONT_RIGHT | \
  385. SPEAKER_LOW_FREQUENCY | \
  386. SPEAKER_BACK_LEFT | \
  387. SPEAKER_BACK_RIGHT )
  388. #define SPEAKER_5POINT1 \
  389. ( SPEAKER_FRONT_LEFT | \
  390. SPEAKER_FRONT_RIGHT | \
  391. SPEAKER_FRONT_CENTER | \
  392. SPEAKER_LOW_FREQUENCY | \
  393. SPEAKER_BACK_LEFT | \
  394. SPEAKER_BACK_RIGHT )
  395. #define SPEAKER_7POINT1 \
  396. ( SPEAKER_FRONT_LEFT | \
  397. SPEAKER_FRONT_RIGHT | \
  398. SPEAKER_FRONT_CENTER | \
  399. SPEAKER_LOW_FREQUENCY | \
  400. SPEAKER_BACK_LEFT | \
  401. SPEAKER_BACK_RIGHT | \
  402. SPEAKER_FRONT_LEFT_OF_CENTER | \
  403. SPEAKER_FRONT_RIGHT_OF_CENTER )
  404. #define SPEAKER_5POINT1_SURROUND \
  405. ( SPEAKER_FRONT_LEFT | \
  406. SPEAKER_FRONT_RIGHT | \
  407. SPEAKER_FRONT_CENTER | \
  408. SPEAKER_LOW_FREQUENCY | \
  409. SPEAKER_SIDE_LEFT | \
  410. SPEAKER_SIDE_RIGHT )
  411. #define SPEAKER_7POINT1_SURROUND \
  412. ( SPEAKER_FRONT_LEFT | \
  413. SPEAKER_FRONT_RIGHT | \
  414. SPEAKER_FRONT_CENTER | \
  415. SPEAKER_LOW_FREQUENCY | \
  416. SPEAKER_BACK_LEFT | \
  417. SPEAKER_BACK_RIGHT | \
  418. SPEAKER_SIDE_LEFT | \
  419. SPEAKER_SIDE_RIGHT )
  420. #define SPEAKER_XBOX SPEAKER_5POINT1
  421. #endif
  422. #define FAUDIO_FORMAT_PCM 1
  423. #define FAUDIO_FORMAT_MSADPCM 2
  424. #define FAUDIO_FORMAT_IEEE_FLOAT 3
  425. #define FAUDIO_FORMAT_WMAUDIO2 0x0161
  426. #define FAUDIO_FORMAT_WMAUDIO3 0x0162
  427. #define FAUDIO_FORMAT_WMAUDIO_LOSSLESS 0x0163
  428. #define FAUDIO_FORMAT_XMAUDIO2 0x0166
  429. #define FAUDIO_FORMAT_EXTENSIBLE 0xFFFE
  430. extern FAudioGUID DATAFORMAT_SUBTYPE_PCM;
  431. extern FAudioGUID DATAFORMAT_SUBTYPE_IEEE_FLOAT;
  432. /* FAudio Version API */
  433. #define FAUDIO_TARGET_VERSION 8 /* Targeting compatibility with XAudio 2.8 */
  434. #define FAUDIO_ABI_VERSION 0
  435. #define FAUDIO_MAJOR_VERSION 22
  436. #define FAUDIO_MINOR_VERSION 2
  437. #define FAUDIO_PATCH_VERSION 0
  438. #define FAUDIO_COMPILED_VERSION ( \
  439. (FAUDIO_ABI_VERSION * 100 * 100 * 100) + \
  440. (FAUDIO_MAJOR_VERSION * 100 * 100) + \
  441. (FAUDIO_MINOR_VERSION * 100) + \
  442. (FAUDIO_PATCH_VERSION) \
  443. )
  444. FAUDIOAPI uint32_t FAudioLinkedVersion(void);
  445. /* FAudio Interface */
  446. /* This should be your first FAudio call.
  447. *
  448. * ppFAudio: Filled with the FAudio core context.
  449. * Flags: Can be 0 or FAUDIO_DEBUG_ENGINE.
  450. * XAudio2Processor: Set this to FAUDIO_DEFAULT_PROCESSOR.
  451. *
  452. * Returns 0 on success.
  453. */
  454. FAUDIOAPI uint32_t FAudioCreate(
  455. FAudio **ppFAudio,
  456. uint32_t Flags,
  457. FAudioProcessor XAudio2Processor
  458. );
  459. /* See "extensions/COMConstructEXT.txt" for more details */
  460. FAUDIOAPI uint32_t FAudioCOMConstructEXT(FAudio **ppFAudio, uint8_t version);
  461. /* Increments a reference counter. When counter is 0, audio is freed.
  462. * Returns the reference count after incrementing.
  463. */
  464. FAUDIOAPI uint32_t FAudio_AddRef(FAudio *audio);
  465. /* Decrements a reference counter. When counter is 0, audio is freed.
  466. * Returns the reference count after decrementing.
  467. */
  468. FAUDIOAPI uint32_t FAudio_Release(FAudio *audio);
  469. /* Queries the number of sound devices available for use.
  470. *
  471. * pCount: Filled with the number of available sound devices.
  472. *
  473. * Returns 0 on success.
  474. */
  475. FAUDIOAPI uint32_t FAudio_GetDeviceCount(FAudio *audio, uint32_t *pCount);
  476. /* Gets basic information about a sound device.
  477. *
  478. * Index: Can be between 0 and the result of GetDeviceCount.
  479. * pDeviceDetails: Filled with the device information.
  480. *
  481. * Returns 0 on success.
  482. */
  483. FAUDIOAPI uint32_t FAudio_GetDeviceDetails(
  484. FAudio *audio,
  485. uint32_t Index,
  486. FAudioDeviceDetails *pDeviceDetails
  487. );
  488. /* You don't actually have to call this, unless you're using the COM APIs.
  489. * See the FAudioCreate API for parameter information.
  490. */
  491. FAUDIOAPI uint32_t FAudio_Initialize(
  492. FAudio *audio,
  493. uint32_t Flags,
  494. FAudioProcessor XAudio2Processor
  495. );
  496. /* Register a new set of engine callbacks.
  497. * There is no limit to the number of sets, but expect performance to degrade
  498. * if you have a whole bunch of these. You most likely only need one.
  499. *
  500. * pCallback: The completely-initialized FAudioEngineCallback structure.
  501. *
  502. * Returns 0 on success.
  503. */
  504. FAUDIOAPI uint32_t FAudio_RegisterForCallbacks(
  505. FAudio *audio,
  506. FAudioEngineCallback *pCallback
  507. );
  508. /* Remove an active set of engine callbacks.
  509. * This checks the pointer value, NOT the callback values!
  510. *
  511. * pCallback: An FAudioEngineCallback structure previously sent to Register.
  512. *
  513. * Returns 0 on success.
  514. */
  515. FAUDIOAPI void FAudio_UnregisterForCallbacks(
  516. FAudio *audio,
  517. FAudioEngineCallback *pCallback
  518. );
  519. /* Creates a "source" voice, used to play back wavedata.
  520. *
  521. * ppSourceVoice: Filled with the source voice pointer.
  522. * pSourceFormat: The input wavedata format, see the documentation for
  523. * FAudioWaveFormatEx.
  524. * Flags: Can be 0 or a mix of the following FAUDIO_VOICE_* flags:
  525. * NOPITCH/NOSRC: Resampling is disabled. If you set this,
  526. * the source format sample rate MUST match
  527. * the output voices' input sample rates.
  528. * Also, SetFrequencyRatio will fail.
  529. * USEFILTER: Enables the use of SetFilterParameters.
  530. * MUSIC: Unsupported.
  531. * MaxFrequencyRatio: AKA your max pitch. This allows us to optimize the size
  532. * of the decode/resample cache sizes. For example, if you
  533. * only expect to raise pitch by a single octave, you can
  534. * set this value to 2.0f. 2.0f is the default value.
  535. * Bounds: [FAUDIO_MIN_FREQ_RATIO, FAUDIO_MAX_FREQ_RATIO].
  536. * pCallback: Voice callbacks, see FAudioVoiceCallback documentation.
  537. * pSendList: List of output voices. If NULL, defaults to master.
  538. * All output voices must have the same sample rate!
  539. * pEffectChain: List of FAPO effects. This value can be NULL.
  540. *
  541. * Returns 0 on success.
  542. */
  543. FAUDIOAPI uint32_t FAudio_CreateSourceVoice(
  544. FAudio *audio,
  545. FAudioSourceVoice **ppSourceVoice,
  546. const FAudioWaveFormatEx *pSourceFormat,
  547. uint32_t Flags,
  548. float MaxFrequencyRatio,
  549. FAudioVoiceCallback *pCallback,
  550. const FAudioVoiceSends *pSendList,
  551. const FAudioEffectChain *pEffectChain
  552. );
  553. /* Creates a "submix" voice, used to mix/process input voices.
  554. * The typical use case for this is to perform CPU-intensive tasks on large
  555. * groups of voices all at once. Examples include resampling and FAPO effects.
  556. *
  557. * ppSubmixVoice: Filled with the submix voice pointer.
  558. * InputChannels: Input voices will convert to this channel count.
  559. * InputSampleRate: Input voices will convert to this sample rate.
  560. * Flags: Can be 0 or FAUDIO_VOICE_USEFILTER.
  561. * ProcessingStage: If you have multiple submixes that depend on a specific
  562. * order of processing, you can sort them by setting this
  563. * value to prioritize them. For example, submixes with
  564. * stage 0 will process first, then stage 1, 2, and so on.
  565. * pSendList: List of output voices. If NULL, defaults to master.
  566. * All output voices must have the same sample rate!
  567. * pEffectChain: List of FAPO effects. This value can be NULL.
  568. *
  569. * Returns 0 on success.
  570. */
  571. FAUDIOAPI uint32_t FAudio_CreateSubmixVoice(
  572. FAudio *audio,
  573. FAudioSubmixVoice **ppSubmixVoice,
  574. uint32_t InputChannels,
  575. uint32_t InputSampleRate,
  576. uint32_t Flags,
  577. uint32_t ProcessingStage,
  578. const FAudioVoiceSends *pSendList,
  579. const FAudioEffectChain *pEffectChain
  580. );
  581. /* This should be your second FAudio call, unless you care about which device
  582. * you want to use. In that case, see GetDeviceDetails.
  583. *
  584. * ppMasteringVoice: Filled with the mastering voice pointer.
  585. * InputChannels: Device channel count. Can be FAUDIO_DEFAULT_CHANNELS.
  586. * InputSampleRate: Device sample rate. Can be FAUDIO_DEFAULT_SAMPLERATE.
  587. * Flags: This value must be 0.
  588. * DeviceIndex: 0 for the default device. See GetDeviceCount.
  589. * pEffectChain: List of FAPO effects. This value can be NULL.
  590. *
  591. * Returns 0 on success.
  592. */
  593. FAUDIOAPI uint32_t FAudio_CreateMasteringVoice(
  594. FAudio *audio,
  595. FAudioMasteringVoice **ppMasteringVoice,
  596. uint32_t InputChannels,
  597. uint32_t InputSampleRate,
  598. uint32_t Flags,
  599. uint32_t DeviceIndex,
  600. const FAudioEffectChain *pEffectChain
  601. );
  602. /* This is the XAudio 2.8+ version of CreateMasteringVoice.
  603. * Right now this doesn't do anything. Don't use this function.
  604. */
  605. FAUDIOAPI uint32_t FAudio_CreateMasteringVoice8(
  606. FAudio *audio,
  607. FAudioMasteringVoice **ppMasteringVoice,
  608. uint32_t InputChannels,
  609. uint32_t InputSampleRate,
  610. uint32_t Flags,
  611. uint16_t *szDeviceId,
  612. const FAudioEffectChain *pEffectChain,
  613. FAudioStreamCategory StreamCategory
  614. );
  615. /* Starts the engine, begins processing the audio graph.
  616. * Returns 0 on success.
  617. */
  618. FAUDIOAPI uint32_t FAudio_StartEngine(FAudio *audio);
  619. /* Stops the engine and halts all processing.
  620. * The audio device will continue to run, but will produce silence.
  621. * The graph will be frozen until you call StartEngine, where it will then
  622. * resume all processing exactly as it would have had this never been called.
  623. */
  624. FAUDIOAPI void FAudio_StopEngine(FAudio *audio);
  625. /* Flushes a batch of FAudio calls compiled with a given "OperationSet" tag.
  626. * This function is based on IXAudio2::CommitChanges from the XAudio2 spec.
  627. * This is useful for pushing calls that need to be done perfectly in sync. For
  628. * example, if you want to play two separate sources at the exact same time, you
  629. * can call FAudioSourceVoice_Start with an OperationSet value of your choice,
  630. * then call CommitChanges with that same value to start the sources together.
  631. *
  632. * OperationSet: Either a value known by you or FAUDIO_COMMIT_ALL
  633. *
  634. * Returns 0 on success.
  635. */
  636. FAUDIOAPI uint32_t FAudio_CommitOperationSet(
  637. FAudio *audio,
  638. uint32_t OperationSet
  639. );
  640. /* DO NOT USE THIS FUNCTION OR I SWEAR TO GOD */
  641. FAUDIODEPRECATED("This function will break your program! Use FAudio_CommitOperationSet instead!")
  642. FAUDIOAPI uint32_t FAudio_CommitChanges(FAudio *audio);
  643. /* Requests various bits of performance information from the engine.
  644. *
  645. * pPerfData: Filled with the data. See FAudioPerformanceData for details.
  646. */
  647. FAUDIOAPI void FAudio_GetPerformanceData(
  648. FAudio *audio,
  649. FAudioPerformanceData *pPerfData
  650. );
  651. /* When using a Debug binary, this lets you configure what information gets
  652. * logged to output. Be careful, this can spit out a LOT of text.
  653. *
  654. * pDebugConfiguration: See FAudioDebugConfiguration for details.
  655. * pReserved: Set this to NULL.
  656. */
  657. FAUDIOAPI void FAudio_SetDebugConfiguration(
  658. FAudio *audio,
  659. FAudioDebugConfiguration *pDebugConfiguration,
  660. void* pReserved
  661. );
  662. /* Requests the values that determine's the engine's update size.
  663. * For example, a 48KHz engine with a 1024-sample update period would return
  664. * 1024 for the numerator and 48000 for the denominator. With this information,
  665. * you can determine the precise update size in milliseconds.
  666. *
  667. * quantumNumerator - The engine's update size, in sample frames.
  668. * quantumDenominator - The engine's sample rate, in Hz
  669. */
  670. FAUDIOAPI void FAudio_GetProcessingQuantum(
  671. FAudio *audio,
  672. uint32_t *quantumNumerator,
  673. uint32_t *quantumDenominator
  674. );
  675. /* FAudioVoice Interface */
  676. /* Requests basic information about a voice.
  677. *
  678. * pVoiceDetails: See FAudioVoiceDetails for details.
  679. */
  680. FAUDIOAPI void FAudioVoice_GetVoiceDetails(
  681. FAudioVoice *voice,
  682. FAudioVoiceDetails *pVoiceDetails
  683. );
  684. /* Change the output voices for this voice.
  685. * This function is invalid for mastering voices.
  686. *
  687. * pSendList: List of output voices. If NULL, defaults to master.
  688. * All output voices must have the same sample rate!
  689. *
  690. * Returns 0 on success.
  691. */
  692. FAUDIOAPI uint32_t FAudioVoice_SetOutputVoices(
  693. FAudioVoice *voice,
  694. const FAudioVoiceSends *pSendList
  695. );
  696. /* Change/Remove the effect chain for this voice.
  697. *
  698. * pEffectChain: List of FAPO effects. This value can be NULL.
  699. * Note that the final channel counts for this chain MUST
  700. * match the input/output channel count that was
  701. * determined at voice creation time!
  702. *
  703. * Returns 0 on success.
  704. */
  705. FAUDIOAPI uint32_t FAudioVoice_SetEffectChain(
  706. FAudioVoice *voice,
  707. const FAudioEffectChain *pEffectChain
  708. );
  709. /* Enables an effect in the effect chain.
  710. *
  711. * EffectIndex: The index of the effect (based on the chain order).
  712. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  713. *
  714. * Returns 0 on success.
  715. */
  716. FAUDIOAPI uint32_t FAudioVoice_EnableEffect(
  717. FAudioVoice *voice,
  718. uint32_t EffectIndex,
  719. uint32_t OperationSet
  720. );
  721. /* Disables an effect in the effect chain.
  722. *
  723. * EffectIndex: The index of the effect (based on the chain order).
  724. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  725. *
  726. * Returns 0 on success.
  727. */
  728. FAUDIOAPI uint32_t FAudioVoice_DisableEffect(
  729. FAudioVoice *voice,
  730. uint32_t EffectIndex,
  731. uint32_t OperationSet
  732. );
  733. /* Queries the enabled/disabled state of an effect in the effect chain.
  734. *
  735. * EffectIndex: The index of the effect (based on the chain order).
  736. * pEnabled: Filled with either 1 (Enabled) or 0 (Disabled).
  737. *
  738. * Returns 0 on success.
  739. */
  740. FAUDIOAPI void FAudioVoice_GetEffectState(
  741. FAudioVoice *voice,
  742. uint32_t EffectIndex,
  743. int32_t *pEnabled
  744. );
  745. /* Submits a block of memory to be sent to FAPO::SetParameters.
  746. *
  747. * EffectIndex: The index of the effect (based on the chain order).
  748. * pParameters: The values to be copied and submitted to the FAPO.
  749. * ParametersByteSize: This should match what the FAPO expects!
  750. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  751. *
  752. * Returns 0 on success.
  753. */
  754. FAUDIOAPI uint32_t FAudioVoice_SetEffectParameters(
  755. FAudioVoice *voice,
  756. uint32_t EffectIndex,
  757. const void *pParameters,
  758. uint32_t ParametersByteSize,
  759. uint32_t OperationSet
  760. );
  761. /* Requests the latest parameters from FAPO::GetParameters.
  762. *
  763. * EffectIndex: The index of the effect (based on the chain order).
  764. * pParameters: Filled with the latest parameter values from the FAPO.
  765. * ParametersByteSize: This should match what the FAPO expects!
  766. *
  767. * Returns 0 on success.
  768. */
  769. FAUDIOAPI uint32_t FAudioVoice_GetEffectParameters(
  770. FAudioVoice *voice,
  771. uint32_t EffectIndex,
  772. void *pParameters,
  773. uint32_t ParametersByteSize
  774. );
  775. /* Sets the filter variables for a voice.
  776. * This is only valid on voices with the USEFILTER flag.
  777. *
  778. * pParameters: See FAudioFilterParameters for details.
  779. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  780. *
  781. * Returns 0 on success.
  782. */
  783. FAUDIOAPI uint32_t FAudioVoice_SetFilterParameters(
  784. FAudioVoice *voice,
  785. const FAudioFilterParameters *pParameters,
  786. uint32_t OperationSet
  787. );
  788. /* Requests the filter variables for a voice.
  789. * This is only valid on voices with the USEFILTER flag.
  790. *
  791. * pParameters: See FAudioFilterParameters for details.
  792. */
  793. FAUDIOAPI void FAudioVoice_GetFilterParameters(
  794. FAudioVoice *voice,
  795. FAudioFilterParameters *pParameters
  796. );
  797. /* Sets the filter variables for a voice's output voice.
  798. * This is only valid on sends with the USEFILTER flag.
  799. *
  800. * pDestinationVoice: An output voice from the voice's send list.
  801. * pParameters: See FAudioFilterParameters for details.
  802. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  803. *
  804. * Returns 0 on success.
  805. */
  806. FAUDIOAPI uint32_t FAudioVoice_SetOutputFilterParameters(
  807. FAudioVoice *voice,
  808. FAudioVoice *pDestinationVoice,
  809. const FAudioFilterParameters *pParameters,
  810. uint32_t OperationSet
  811. );
  812. /* Requests the filter variables for a voice's output voice.
  813. * This is only valid on sends with the USEFILTER flag.
  814. *
  815. * pDestinationVoice: An output voice from the voice's send list.
  816. * pParameters: See FAudioFilterParameters for details.
  817. */
  818. FAUDIOAPI void FAudioVoice_GetOutputFilterParameters(
  819. FAudioVoice *voice,
  820. FAudioVoice *pDestinationVoice,
  821. FAudioFilterParameters *pParameters
  822. );
  823. /* Sets the global volume of a voice.
  824. *
  825. * Volume: Amplitude ratio. 1.0f is default, 0.0f is silence.
  826. * Note that you can actually set volume < 0.0f!
  827. * Bounds: [-FAUDIO_MAX_VOLUME_LEVEL, FAUDIO_MAX_VOLUME_LEVEL]
  828. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  829. *
  830. * Returns 0 on success.
  831. */
  832. FAUDIOAPI uint32_t FAudioVoice_SetVolume(
  833. FAudioVoice *voice,
  834. float Volume,
  835. uint32_t OperationSet
  836. );
  837. /* Requests the global volume of a voice.
  838. *
  839. * pVolume: Filled with the current voice amplitude ratio.
  840. */
  841. FAUDIOAPI void FAudioVoice_GetVolume(
  842. FAudioVoice *voice,
  843. float *pVolume
  844. );
  845. /* Sets the per-channel volumes of a voice.
  846. *
  847. * Channels: Must match the channel count of this voice!
  848. * pVolumes: Amplitude ratios for each channel. Same as SetVolume.
  849. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  850. *
  851. * Returns 0 on success.
  852. */
  853. FAUDIOAPI uint32_t FAudioVoice_SetChannelVolumes(
  854. FAudioVoice *voice,
  855. uint32_t Channels,
  856. const float *pVolumes,
  857. uint32_t OperationSet
  858. );
  859. /* Requests the per-channel volumes of a voice.
  860. *
  861. * Channels: Must match the channel count of this voice!
  862. * pVolumes: Filled with the current channel amplitude ratios.
  863. */
  864. FAUDIOAPI void FAudioVoice_GetChannelVolumes(
  865. FAudioVoice *voice,
  866. uint32_t Channels,
  867. float *pVolumes
  868. );
  869. /* Sets the volumes of a send's output channels. The matrix is based on the
  870. * voice's input channels. For example, the default matrix for a 2-channel
  871. * source and a 2-channel output voice is as follows:
  872. * [0] = 1.0f; <- Left input, left output
  873. * [1] = 0.0f; <- Right input, left output
  874. * [2] = 0.0f; <- Left input, right output
  875. * [3] = 1.0f; <- Right input, right output
  876. * This is typically only used for panning or 3D sound (via F3DAudio).
  877. *
  878. * pDestinationVoice: An output voice from the voice's send list.
  879. * SourceChannels: Must match the voice's input channel count!
  880. * DestinationChannels: Must match the destination's input channel count!
  881. * pLevelMatrix: A float[SourceChannels * DestinationChannels].
  882. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  883. *
  884. * Returns 0 on success.
  885. */
  886. FAUDIOAPI uint32_t FAudioVoice_SetOutputMatrix(
  887. FAudioVoice *voice,
  888. FAudioVoice *pDestinationVoice,
  889. uint32_t SourceChannels,
  890. uint32_t DestinationChannels,
  891. const float *pLevelMatrix,
  892. uint32_t OperationSet
  893. );
  894. /* Gets the volumes of a send's output channels. See SetOutputMatrix.
  895. *
  896. * pDestinationVoice: An output voice from the voice's send list.
  897. * SourceChannels: Must match the voice's input channel count!
  898. * DestinationChannels: Must match the voice's output channel count!
  899. * pLevelMatrix: A float[SourceChannels * DestinationChannels].
  900. */
  901. FAUDIOAPI void FAudioVoice_GetOutputMatrix(
  902. FAudioVoice *voice,
  903. FAudioVoice *pDestinationVoice,
  904. uint32_t SourceChannels,
  905. uint32_t DestinationChannels,
  906. float *pLevelMatrix
  907. );
  908. /* Removes this voice from the audio graph and frees memory. */
  909. FAUDIOAPI void FAudioVoice_DestroyVoice(FAudioVoice *voice);
  910. /* FAudioSourceVoice Interface */
  911. /* Starts processing for a source voice.
  912. *
  913. * Flags: Must be 0.
  914. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  915. *
  916. * Returns 0 on success.
  917. */
  918. FAUDIOAPI uint32_t FAudioSourceVoice_Start(
  919. FAudioSourceVoice *voice,
  920. uint32_t Flags,
  921. uint32_t OperationSet
  922. );
  923. /* Pauses processing for a source voice. Yes, I said pausing.
  924. * If you want to _actually_ stop, call FlushSourceBuffers next.
  925. *
  926. * Flags: Can be 0 or FAUDIO_PLAY_TAILS, which allows effects to
  927. * keep emitting output even after processing has stopped.
  928. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  929. *
  930. * Returns 0 on success.
  931. */
  932. FAUDIOAPI uint32_t FAudioSourceVoice_Stop(
  933. FAudioSourceVoice *voice,
  934. uint32_t Flags,
  935. uint32_t OperationSet
  936. );
  937. /* Submits a block of wavedata for the source to process.
  938. *
  939. * pBuffer: See FAudioBuffer for details.
  940. * pBufferWMA: See FAudioBufferWMA for details. (Also, don't use WMA.)
  941. *
  942. * Returns 0 on success.
  943. */
  944. FAUDIOAPI uint32_t FAudioSourceVoice_SubmitSourceBuffer(
  945. FAudioSourceVoice *voice,
  946. const FAudioBuffer *pBuffer,
  947. const FAudioBufferWMA *pBufferWMA
  948. );
  949. /* Removes all buffers from a source, with a minor exception.
  950. * If the voice is still playing, the active buffer is left alone.
  951. * All buffers that are removed will spawn an OnBufferEnd callback.
  952. *
  953. * Returns 0 on success.
  954. */
  955. FAUDIOAPI uint32_t FAudioSourceVoice_FlushSourceBuffers(
  956. FAudioSourceVoice *voice
  957. );
  958. /* Takes the last buffer currently queued and sets the END_OF_STREAM flag.
  959. *
  960. * Returns 0 on success.
  961. */
  962. FAUDIOAPI uint32_t FAudioSourceVoice_Discontinuity(
  963. FAudioSourceVoice *voice
  964. );
  965. /* Sets the loop count of the active buffer to 0.
  966. *
  967. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  968. *
  969. * Returns 0 on success.
  970. */
  971. FAUDIOAPI uint32_t FAudioSourceVoice_ExitLoop(
  972. FAudioSourceVoice *voice,
  973. uint32_t OperationSet
  974. );
  975. /* Requests the state and some basic statistics for this source.
  976. *
  977. * pVoiceState: See FAudioVoiceState for details.
  978. * Flags: Can be 0 or FAUDIO_VOICE_NOSAMPLESPLAYED.
  979. */
  980. FAUDIOAPI void FAudioSourceVoice_GetState(
  981. FAudioSourceVoice *voice,
  982. FAudioVoiceState *pVoiceState,
  983. uint32_t Flags
  984. );
  985. /* Sets the frequency ratio (fancy phrase for pitch) of this source.
  986. *
  987. * Ratio: The frequency ratio, must be <= MaxFrequencyRatio.
  988. * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
  989. *
  990. * Returns 0 on success.
  991. */
  992. FAUDIOAPI uint32_t FAudioSourceVoice_SetFrequencyRatio(
  993. FAudioSourceVoice *voice,
  994. float Ratio,
  995. uint32_t OperationSet
  996. );
  997. /* Requests the frequency ratio (fancy phrase for pitch) of this source.
  998. *
  999. * pRatio: Filled with the frequency ratio.
  1000. */
  1001. FAUDIOAPI void FAudioSourceVoice_GetFrequencyRatio(
  1002. FAudioSourceVoice *voice,
  1003. float *pRatio
  1004. );
  1005. /* Resets the core sample rate of this source.
  1006. * You probably don't want this, it's more likely you want SetFrequencyRatio.
  1007. * This is used to recycle voices without having to constantly reallocate them.
  1008. * For example, if you have wavedata that's all float32 mono, but the sample
  1009. * rates are different, you can take a source that was being used for a 48KHz
  1010. * wave and call this so it can be used for a 44.1KHz wave.
  1011. *
  1012. * NewSourceSampleRate: The new sample rate for this source.
  1013. *
  1014. * Returns 0 on success.
  1015. */
  1016. FAUDIOAPI uint32_t FAudioSourceVoice_SetSourceSampleRate(
  1017. FAudioSourceVoice *voice,
  1018. uint32_t NewSourceSampleRate
  1019. );
  1020. /* FAudioMasteringVoice Interface */
  1021. /* Requests the channel mask for the mastering voice.
  1022. * This is typically used with F3DAudioInitialize, but you may find it
  1023. * interesting if you want to see the user's basic speaker layout.
  1024. *
  1025. * pChannelMask: Filled with the channel mask.
  1026. *
  1027. * Returns 0 on success.
  1028. */
  1029. FAUDIOAPI uint32_t FAudioMasteringVoice_GetChannelMask(
  1030. FAudioMasteringVoice *voice,
  1031. uint32_t *pChannelMask
  1032. );
  1033. /* FAudioEngineCallback Interface */
  1034. /* If something horrible happens, this will be called.
  1035. *
  1036. * Error: The error code that spawned this callback.
  1037. */
  1038. typedef void (FAUDIOCALL * OnCriticalErrorFunc)(
  1039. FAudioEngineCallback *callback,
  1040. uint32_t Error
  1041. );
  1042. /* This is called at the end of a processing update. */
  1043. typedef void (FAUDIOCALL * OnProcessingPassEndFunc)(
  1044. FAudioEngineCallback *callback
  1045. );
  1046. /* This is called at the beginning of a processing update. */
  1047. typedef void (FAUDIOCALL * OnProcessingPassStartFunc)(
  1048. FAudioEngineCallback *callback
  1049. );
  1050. struct FAudioEngineCallback
  1051. {
  1052. OnCriticalErrorFunc OnCriticalError;
  1053. OnProcessingPassEndFunc OnProcessingPassEnd;
  1054. OnProcessingPassStartFunc OnProcessingPassStart;
  1055. };
  1056. /* FAudioVoiceCallback Interface */
  1057. /* When a buffer is no longer in use, this is called.
  1058. *
  1059. * pBufferContext: The pContext for the FAudioBuffer in question.
  1060. */
  1061. typedef void (FAUDIOCALL * OnBufferEndFunc)(
  1062. FAudioVoiceCallback *callback,
  1063. void *pBufferContext
  1064. );
  1065. /* When a buffer is now being used, this is called.
  1066. *
  1067. * pBufferContext: The pContext for the FAudioBuffer in question.
  1068. */
  1069. typedef void (FAUDIOCALL * OnBufferStartFunc)(
  1070. FAudioVoiceCallback *callback,
  1071. void *pBufferContext
  1072. );
  1073. /* When a buffer completes a loop, this is called.
  1074. *
  1075. * pBufferContext: The pContext for the FAudioBuffer in question.
  1076. */
  1077. typedef void (FAUDIOCALL * OnLoopEndFunc)(
  1078. FAudioVoiceCallback *callback,
  1079. void *pBufferContext
  1080. );
  1081. /* When a buffer that has the END_OF_STREAM flag is finished, this is called. */
  1082. typedef void (FAUDIOCALL * OnStreamEndFunc)(
  1083. FAudioVoiceCallback *callback
  1084. );
  1085. /* If something horrible happens to a voice, this is called.
  1086. *
  1087. * pBufferContext: The pContext for the FAudioBuffer in question.
  1088. * Error: The error code that spawned this callback.
  1089. */
  1090. typedef void (FAUDIOCALL * OnVoiceErrorFunc)(
  1091. FAudioVoiceCallback *callback,
  1092. void *pBufferContext,
  1093. uint32_t Error
  1094. );
  1095. /* When this voice is done being processed, this is called. */
  1096. typedef void (FAUDIOCALL * OnVoiceProcessingPassEndFunc)(
  1097. FAudioVoiceCallback *callback
  1098. );
  1099. /* When a voice is about to start being processed, this is called.
  1100. *
  1101. * BytesRequested: The number of bytes needed from the application to
  1102. * complete a full update. For example, if we need 512
  1103. * frames for a whole update, and the voice is a float32
  1104. * stereo source, BytesRequired will be 4096.
  1105. */
  1106. typedef void (FAUDIOCALL * OnVoiceProcessingPassStartFunc)(
  1107. FAudioVoiceCallback *callback,
  1108. uint32_t BytesRequired
  1109. );
  1110. struct FAudioVoiceCallback
  1111. {
  1112. OnBufferEndFunc OnBufferEnd;
  1113. OnBufferStartFunc OnBufferStart;
  1114. OnLoopEndFunc OnLoopEnd;
  1115. OnStreamEndFunc OnStreamEnd;
  1116. OnVoiceErrorFunc OnVoiceError;
  1117. OnVoiceProcessingPassEndFunc OnVoiceProcessingPassEnd;
  1118. OnVoiceProcessingPassStartFunc OnVoiceProcessingPassStart;
  1119. };
  1120. /* FAudio Custom Allocator API
  1121. * See "extensions/CustomAllocatorEXT.txt" for more information.
  1122. */
  1123. typedef void* (FAUDIOCALL * FAudioMallocFunc)(size_t size);
  1124. typedef void (FAUDIOCALL * FAudioFreeFunc)(void* ptr);
  1125. typedef void* (FAUDIOCALL * FAudioReallocFunc)(void* ptr, size_t size);
  1126. FAUDIOAPI uint32_t FAudioCreateWithCustomAllocatorEXT(
  1127. FAudio **ppFAudio,
  1128. uint32_t Flags,
  1129. FAudioProcessor XAudio2Processor,
  1130. FAudioMallocFunc customMalloc,
  1131. FAudioFreeFunc customFree,
  1132. FAudioReallocFunc customRealloc
  1133. );
  1134. FAUDIOAPI uint32_t FAudioCOMConstructWithCustomAllocatorEXT(
  1135. FAudio **ppFAudio,
  1136. uint8_t version,
  1137. FAudioMallocFunc customMalloc,
  1138. FAudioFreeFunc customFree,
  1139. FAudioReallocFunc customRealloc
  1140. );
  1141. /* FAudio Engine Procedure API
  1142. * See "extensions/EngineProcedureEXT.txt" for more information.
  1143. */
  1144. typedef void (FAUDIOCALL *FAudioEngineCallEXT)(FAudio *audio, float *output);
  1145. typedef void (FAUDIOCALL *FAudioEngineProcedureEXT)(FAudioEngineCallEXT defaultEngineProc, FAudio *audio, float *output, void *user);
  1146. FAUDIOAPI void FAudio_SetEngineProcedureEXT(
  1147. FAudio *audio,
  1148. FAudioEngineProcedureEXT clientEngineProc,
  1149. void *user
  1150. );
  1151. /* FAudio I/O API */
  1152. #define FAUDIO_SEEK_SET 0
  1153. #define FAUDIO_SEEK_CUR 1
  1154. #define FAUDIO_SEEK_END 2
  1155. #define FAUDIO_EOF -1
  1156. typedef size_t (FAUDIOCALL * FAudio_readfunc)(
  1157. void *data,
  1158. void *dst,
  1159. size_t size,
  1160. size_t count
  1161. );
  1162. typedef int64_t (FAUDIOCALL * FAudio_seekfunc)(
  1163. void *data,
  1164. int64_t offset,
  1165. int whence
  1166. );
  1167. typedef int (FAUDIOCALL * FAudio_closefunc)(
  1168. void *data
  1169. );
  1170. typedef struct FAudioIOStream
  1171. {
  1172. void *data;
  1173. FAudio_readfunc read;
  1174. FAudio_seekfunc seek;
  1175. FAudio_closefunc close;
  1176. void *lock;
  1177. } FAudioIOStream;
  1178. FAUDIOAPI FAudioIOStream* FAudio_fopen(const char *path);
  1179. FAUDIOAPI FAudioIOStream* FAudio_memopen(void *mem, int len);
  1180. FAUDIOAPI uint8_t* FAudio_memptr(FAudioIOStream *io, size_t offset);
  1181. FAUDIOAPI void FAudio_close(FAudioIOStream *io);
  1182. #ifdef __cplusplus
  1183. }
  1184. #endif /* __cplusplus */
  1185. #endif /* FAUDIO_H */
  1186. /* vim: set noexpandtab shiftwidth=8 tabstop=8: */