FAudio.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  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 21
  436. #define FAUDIO_MINOR_VERSION 11
  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: */