XAudio2.h 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  1. /**************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation. All rights reserved.
  4. *
  5. * File: xaudio2.h
  6. * Content: Declarations for the XAudio2 game audio API.
  7. *
  8. **************************************************************************/
  9. #ifndef __XAUDIO2_INCLUDED__
  10. #define __XAUDIO2_INCLUDED__
  11. /**************************************************************************
  12. *
  13. * XAudio2 COM object class and interface IDs.
  14. *
  15. **************************************************************************/
  16. #include <comdecl.h> // For DEFINE_CLSID and DEFINE_IID
  17. // XAudio 2.0 (March 2008 SDK)
  18. //DEFINE_CLSID(XAudio2, fac23f48, 31f5, 45a8, b4, 9b, 52, 25, d6, 14, 01, aa);
  19. //DEFINE_CLSID(XAudio2_Debug, fac23f48, 31f5, 45a8, b4, 9b, 52, 25, d6, 14, 01, db);
  20. // XAudio 2.1 (June 2008 SDK)
  21. //DEFINE_CLSID(XAudio2, e21a7345, eb21, 468e, be, 50, 80, 4d, b9, 7c, f7, 08);
  22. //DEFINE_CLSID(XAudio2_Debug, f7a76c21, 53d4, 46bb, ac, 53, 8b, 45, 9c, ae, 46, bd);
  23. // XAudio 2.2 (August 2008 SDK)
  24. //DEFINE_CLSID(XAudio2, b802058a, 464a, 42db, bc, 10, b6, 50, d6, f2, 58, 6a);
  25. //DEFINE_CLSID(XAudio2_Debug, 97dfb7e7, 5161, 4015, 87, a9, c7, 9e, 6a, 19, 52, cc);
  26. // XAudio 2.3 (November 2008 SDK)
  27. //DEFINE_CLSID(XAudio2, 4c5e637a, 16c7, 4de3, 9c, 46, 5e, d2, 21, 81, 96, 2d);
  28. //DEFINE_CLSID(XAudio2_Debug, ef0aa05d, 8075, 4e5d, be, ad, 45, be, 0c, 3c, cb, b3);
  29. // XAudio 2.4 (March 2009 SDK)
  30. //DEFINE_CLSID(XAudio2, 03219e78, 5bc3, 44d1, b9, 2e, f6, 3d, 89, cc, 65, 26);
  31. //DEFINE_CLSID(XAudio2_Debug, 4256535c, 1ea4, 4d4b, 8a, d5, f9, db, 76, 2e, ca, 9e);
  32. // XAudio 2.5 (August 2009 SDK)
  33. //DEFINE_CLSID(XAudio2, 4c9b6dde, 6809, 46e6, a2, 78, 9b, 6a, 97, 58, 86, 70);
  34. //DEFINE_CLSID(XAudio2_Debug, 715bdd1a, aa82, 436b, b0, fa, 6a, ce, a3, 9b, d0, a1);
  35. // XAudio 2.6 (February 2010 SDK)
  36. //DEFINE_CLSID(XAudio2, 3eda9b49, 2085, 498b, 9b, b2, 39, a6, 77, 84, 93, de);
  37. //DEFINE_CLSID(XAudio2_Debug, 47199894, 7cc2, 444d, 98, 73, ce, d2, 56, 2c, c6, 0e);
  38. // XAudio 2.7 (June 2010 SDK)
  39. DEFINE_CLSID(XAudio2, 5a508685, a254, 4fba, 9b, 82, 9a, 24, b0, 03, 06, af);
  40. DEFINE_CLSID(XAudio2_Debug, db05ea35, 0329, 4d4b, a5, 3a, 6d, ea, d0, 3d, 38, 52);
  41. DEFINE_IID(IXAudio2, 8bcf1f58, 9fe7, 4583, 8a, c6, e2, ad, c4, 65, c8, bb);
  42. // Ignore the rest of this header if only the GUID definitions were requested
  43. #ifndef GUID_DEFS_ONLY
  44. #ifdef _XBOX
  45. #include <xobjbase.h> // Xbox COM declarations (IUnknown, etc)
  46. #else
  47. #include <objbase.h> // Windows COM declarations
  48. #endif
  49. #include <sal.h> // Markers for documenting API semantics
  50. #include <audiodefs.h> // Basic audio data types and constants
  51. #include <xma2defs.h> // Data types and constants for XMA2 audio
  52. // All structures defined in this file use tight field packing
  53. #pragma pack(push, 1)
  54. /**************************************************************************
  55. *
  56. * XAudio2 constants, flags and error codes.
  57. *
  58. **************************************************************************/
  59. // Numeric boundary values
  60. #define XAUDIO2_MAX_BUFFER_BYTES 0x80000000 // Maximum bytes allowed in a source buffer
  61. #define XAUDIO2_MAX_QUEUED_BUFFERS 64 // Maximum buffers allowed in a voice queue
  62. #define XAUDIO2_MAX_BUFFERS_SYSTEM 2 // Maximum buffers allowed for system threads (Xbox 360 only)
  63. #define XAUDIO2_MAX_AUDIO_CHANNELS 64 // Maximum channels in an audio stream
  64. #define XAUDIO2_MIN_SAMPLE_RATE 1000 // Minimum audio sample rate supported
  65. #define XAUDIO2_MAX_SAMPLE_RATE 200000 // Maximum audio sample rate supported
  66. #define XAUDIO2_MAX_VOLUME_LEVEL 16777216.0f // Maximum acceptable volume level (2^24)
  67. #define XAUDIO2_MIN_FREQ_RATIO (1/1024.0f) // Minimum SetFrequencyRatio argument
  68. #define XAUDIO2_MAX_FREQ_RATIO 1024.0f // Maximum MaxFrequencyRatio argument
  69. #define XAUDIO2_DEFAULT_FREQ_RATIO 2.0f // Default MaxFrequencyRatio argument
  70. #define XAUDIO2_MAX_FILTER_ONEOVERQ 1.5f // Maximum XAUDIO2_FILTER_PARAMETERS.OneOverQ
  71. #define XAUDIO2_MAX_FILTER_FREQUENCY 1.0f // Maximum XAUDIO2_FILTER_PARAMETERS.Frequency
  72. #define XAUDIO2_MAX_LOOP_COUNT 254 // Maximum non-infinite XAUDIO2_BUFFER.LoopCount
  73. #define XAUDIO2_MAX_INSTANCES 8 // Maximum simultaneous XAudio2 objects on Xbox 360
  74. // For XMA voices on Xbox 360 there is an additional restriction on the MaxFrequencyRatio
  75. // argument and the voice's sample rate: the product of these numbers cannot exceed 600000
  76. // for one-channel voices or 300000 for voices with more than one channel.
  77. #define XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MONO 600000
  78. #define XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MULTICHANNEL 300000
  79. // Numeric values with special meanings
  80. #define XAUDIO2_COMMIT_NOW 0 // Used as an OperationSet argument
  81. #define XAUDIO2_COMMIT_ALL 0 // Used in IXAudio2::CommitChanges
  82. #define XAUDIO2_INVALID_OPSET (UINT32)(-1) // Not allowed for OperationSet arguments
  83. #define XAUDIO2_NO_LOOP_REGION 0 // Used in XAUDIO2_BUFFER.LoopCount
  84. #define XAUDIO2_LOOP_INFINITE 255 // Used in XAUDIO2_BUFFER.LoopCount
  85. #define XAUDIO2_DEFAULT_CHANNELS 0 // Used in CreateMasteringVoice
  86. #define XAUDIO2_DEFAULT_SAMPLERATE 0 // Used in CreateMasteringVoice
  87. // Flags
  88. #define XAUDIO2_DEBUG_ENGINE 0x0001 // Used in XAudio2Create on Windows only
  89. #define XAUDIO2_VOICE_NOPITCH 0x0002 // Used in IXAudio2::CreateSourceVoice
  90. #define XAUDIO2_VOICE_NOSRC 0x0004 // Used in IXAudio2::CreateSourceVoice
  91. #define XAUDIO2_VOICE_USEFILTER 0x0008 // Used in IXAudio2::CreateSource/SubmixVoice
  92. #define XAUDIO2_VOICE_MUSIC 0x0010 // Used in IXAudio2::CreateSourceVoice
  93. #define XAUDIO2_PLAY_TAILS 0x0020 // Used in IXAudio2SourceVoice::Stop
  94. #define XAUDIO2_END_OF_STREAM 0x0040 // Used in XAUDIO2_BUFFER.Flags
  95. #define XAUDIO2_SEND_USEFILTER 0x0080 // Used in XAUDIO2_SEND_DESCRIPTOR.Flags
  96. // Default parameters for the built-in filter
  97. #define XAUDIO2_DEFAULT_FILTER_TYPE LowPassFilter
  98. #define XAUDIO2_DEFAULT_FILTER_FREQUENCY XAUDIO2_MAX_FILTER_FREQUENCY
  99. #define XAUDIO2_DEFAULT_FILTER_ONEOVERQ 1.0f
  100. // Internal XAudio2 constants
  101. #ifdef _XBOX
  102. #define XAUDIO2_QUANTUM_NUMERATOR 2 // On Xbox 360, XAudio2 processes audio
  103. #define XAUDIO2_QUANTUM_DENOMINATOR 375 // in 5.333ms chunks (= 2/375 seconds)
  104. #else
  105. #define XAUDIO2_QUANTUM_NUMERATOR 1 // On Windows, XAudio2 processes audio
  106. #define XAUDIO2_QUANTUM_DENOMINATOR 100 // in 10ms chunks (= 1/100 seconds)
  107. #endif
  108. #define XAUDIO2_QUANTUM_MS (1000.0f * XAUDIO2_QUANTUM_NUMERATOR / XAUDIO2_QUANTUM_DENOMINATOR)
  109. // XAudio2 error codes
  110. #define FACILITY_XAUDIO2 0x896
  111. #define XAUDIO2_E_INVALID_CALL 0x88960001 // An API call or one of its arguments was illegal
  112. #define XAUDIO2_E_XMA_DECODER_ERROR 0x88960002 // The XMA hardware suffered an unrecoverable error
  113. #define XAUDIO2_E_XAPO_CREATION_FAILED 0x88960003 // XAudio2 failed to initialize an XAPO effect
  114. #define XAUDIO2_E_DEVICE_INVALIDATED 0x88960004 // An audio device became unusable (unplugged, etc)
  115. /**************************************************************************
  116. *
  117. * Forward declarations for the XAudio2 interfaces.
  118. *
  119. **************************************************************************/
  120. #ifdef __cplusplus
  121. #define FWD_DECLARE(x) interface x
  122. #else
  123. #define FWD_DECLARE(x) typedef interface x x
  124. #endif
  125. FWD_DECLARE(IXAudio2);
  126. FWD_DECLARE(IXAudio2Voice);
  127. FWD_DECLARE(IXAudio2SourceVoice);
  128. FWD_DECLARE(IXAudio2SubmixVoice);
  129. FWD_DECLARE(IXAudio2MasteringVoice);
  130. FWD_DECLARE(IXAudio2EngineCallback);
  131. FWD_DECLARE(IXAudio2VoiceCallback);
  132. /**************************************************************************
  133. *
  134. * XAudio2 structures and enumerations.
  135. *
  136. **************************************************************************/
  137. // Used in IXAudio2::Initialize
  138. #ifdef _XBOX
  139. typedef enum XAUDIO2_XBOX_HWTHREAD_SPECIFIER
  140. {
  141. XboxThread0 = 0x01,
  142. XboxThread1 = 0x02,
  143. XboxThread2 = 0x04,
  144. XboxThread3 = 0x08,
  145. XboxThread4 = 0x10,
  146. XboxThread5 = 0x20,
  147. XAUDIO2_ANY_PROCESSOR = XboxThread4,
  148. XAUDIO2_DEFAULT_PROCESSOR = XAUDIO2_ANY_PROCESSOR
  149. } XAUDIO2_XBOX_HWTHREAD_SPECIFIER, XAUDIO2_PROCESSOR;
  150. #else
  151. typedef enum XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER
  152. {
  153. Processor1 = 0x00000001,
  154. Processor2 = 0x00000002,
  155. Processor3 = 0x00000004,
  156. Processor4 = 0x00000008,
  157. Processor5 = 0x00000010,
  158. Processor6 = 0x00000020,
  159. Processor7 = 0x00000040,
  160. Processor8 = 0x00000080,
  161. Processor9 = 0x00000100,
  162. Processor10 = 0x00000200,
  163. Processor11 = 0x00000400,
  164. Processor12 = 0x00000800,
  165. Processor13 = 0x00001000,
  166. Processor14 = 0x00002000,
  167. Processor15 = 0x00004000,
  168. Processor16 = 0x00008000,
  169. Processor17 = 0x00010000,
  170. Processor18 = 0x00020000,
  171. Processor19 = 0x00040000,
  172. Processor20 = 0x00080000,
  173. Processor21 = 0x00100000,
  174. Processor22 = 0x00200000,
  175. Processor23 = 0x00400000,
  176. Processor24 = 0x00800000,
  177. Processor25 = 0x01000000,
  178. Processor26 = 0x02000000,
  179. Processor27 = 0x04000000,
  180. Processor28 = 0x08000000,
  181. Processor29 = 0x10000000,
  182. Processor30 = 0x20000000,
  183. Processor31 = 0x40000000,
  184. Processor32 = 0x80000000,
  185. XAUDIO2_ANY_PROCESSOR = 0xffffffff,
  186. XAUDIO2_DEFAULT_PROCESSOR = XAUDIO2_ANY_PROCESSOR
  187. } XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER, XAUDIO2_PROCESSOR;
  188. #endif
  189. // Used in XAUDIO2_DEVICE_DETAILS below to describe the types of applications
  190. // that the user has specified each device as a default for. 0 means that the
  191. // device isn't the default for any role.
  192. typedef enum XAUDIO2_DEVICE_ROLE
  193. {
  194. NotDefaultDevice = 0x0,
  195. DefaultConsoleDevice = 0x1,
  196. DefaultMultimediaDevice = 0x2,
  197. DefaultCommunicationsDevice = 0x4,
  198. DefaultGameDevice = 0x8,
  199. GlobalDefaultDevice = 0xf,
  200. InvalidDeviceRole = ~GlobalDefaultDevice
  201. } XAUDIO2_DEVICE_ROLE;
  202. // Returned by IXAudio2::GetDeviceDetails
  203. typedef struct XAUDIO2_DEVICE_DETAILS
  204. {
  205. WCHAR DeviceID[256]; // String identifier for the audio device.
  206. WCHAR DisplayName[256]; // Friendly name suitable for display to a human.
  207. XAUDIO2_DEVICE_ROLE Role; // Roles that the device should be used for.
  208. WAVEFORMATEXTENSIBLE OutputFormat; // The device's native PCM audio output format.
  209. } XAUDIO2_DEVICE_DETAILS;
  210. // Returned by IXAudio2Voice::GetVoiceDetails
  211. typedef struct XAUDIO2_VOICE_DETAILS
  212. {
  213. UINT32 CreationFlags; // Flags the voice was created with.
  214. UINT32 InputChannels; // Channels in the voice's input audio.
  215. UINT32 InputSampleRate; // Sample rate of the voice's input audio.
  216. } XAUDIO2_VOICE_DETAILS;
  217. // Used in XAUDIO2_VOICE_SENDS below
  218. typedef struct XAUDIO2_SEND_DESCRIPTOR
  219. {
  220. UINT32 Flags; // Either 0 or XAUDIO2_SEND_USEFILTER.
  221. IXAudio2Voice* pOutputVoice; // This send's destination voice.
  222. } XAUDIO2_SEND_DESCRIPTOR;
  223. // Used in the voice creation functions and in IXAudio2Voice::SetOutputVoices
  224. typedef struct XAUDIO2_VOICE_SENDS
  225. {
  226. UINT32 SendCount; // Number of sends from this voice.
  227. XAUDIO2_SEND_DESCRIPTOR* pSends; // Array of SendCount send descriptors.
  228. } XAUDIO2_VOICE_SENDS;
  229. // Used in XAUDIO2_EFFECT_CHAIN below
  230. typedef struct XAUDIO2_EFFECT_DESCRIPTOR
  231. {
  232. IUnknown* pEffect; // Pointer to the effect object's IUnknown interface.
  233. BOOL InitialState; // TRUE if the effect should begin in the enabled state.
  234. UINT32 OutputChannels; // How many output channels the effect should produce.
  235. } XAUDIO2_EFFECT_DESCRIPTOR;
  236. // Used in the voice creation functions and in IXAudio2Voice::SetEffectChain
  237. typedef struct XAUDIO2_EFFECT_CHAIN
  238. {
  239. UINT32 EffectCount; // Number of effects in this voice's effect chain.
  240. XAUDIO2_EFFECT_DESCRIPTOR* pEffectDescriptors; // Array of effect descriptors.
  241. } XAUDIO2_EFFECT_CHAIN;
  242. // Used in XAUDIO2_FILTER_PARAMETERS below
  243. typedef enum XAUDIO2_FILTER_TYPE
  244. {
  245. LowPassFilter, // Attenuates frequencies above the cutoff frequency.
  246. BandPassFilter, // Attenuates frequencies outside a given range.
  247. HighPassFilter, // Attenuates frequencies below the cutoff frequency.
  248. NotchFilter // Attenuates frequencies inside a given range.
  249. } XAUDIO2_FILTER_TYPE;
  250. // Used in IXAudio2Voice::Set/GetFilterParameters and Set/GetOutputFilterParameters
  251. typedef struct XAUDIO2_FILTER_PARAMETERS
  252. {
  253. XAUDIO2_FILTER_TYPE Type; // Low-pass, band-pass or high-pass.
  254. float Frequency; // Radian frequency (2 * sin(pi*CutoffFrequency/SampleRate));
  255. // must be >= 0 and <= XAUDIO2_MAX_FILTER_FREQUENCY
  256. // (giving a maximum CutoffFrequency of SampleRate/6).
  257. float OneOverQ; // Reciprocal of the filter's quality factor Q;
  258. // must be > 0 and <= XAUDIO2_MAX_FILTER_ONEOVERQ.
  259. } XAUDIO2_FILTER_PARAMETERS;
  260. // Used in IXAudio2SourceVoice::SubmitSourceBuffer
  261. typedef struct XAUDIO2_BUFFER
  262. {
  263. UINT32 Flags; // Either 0 or XAUDIO2_END_OF_STREAM.
  264. UINT32 AudioBytes; // Size of the audio data buffer in bytes.
  265. const BYTE* pAudioData; // Pointer to the audio data buffer.
  266. UINT32 PlayBegin; // First sample in this buffer to be played.
  267. UINT32 PlayLength; // Length of the region to be played in samples,
  268. // or 0 to play the whole buffer.
  269. UINT32 LoopBegin; // First sample of the region to be looped.
  270. UINT32 LoopLength; // Length of the desired loop region in samples,
  271. // or 0 to loop the entire buffer.
  272. UINT32 LoopCount; // Number of times to repeat the loop region,
  273. // or XAUDIO2_LOOP_INFINITE to loop forever.
  274. void* pContext; // Context value to be passed back in callbacks.
  275. } XAUDIO2_BUFFER;
  276. // Used in IXAudio2SourceVoice::SubmitSourceBuffer when submitting XWMA data.
  277. // NOTE: If an XWMA sound is submitted in more than one buffer, each buffer's
  278. // pDecodedPacketCumulativeBytes[PacketCount-1] value must be subtracted from
  279. // all the entries in the next buffer's pDecodedPacketCumulativeBytes array.
  280. // And whether a sound is submitted in more than one buffer or not, the final
  281. // buffer of the sound should use the XAUDIO2_END_OF_STREAM flag, or else the
  282. // client must call IXAudio2SourceVoice::Discontinuity after submitting it.
  283. typedef struct XAUDIO2_BUFFER_WMA
  284. {
  285. const UINT32* pDecodedPacketCumulativeBytes; // Decoded packet's cumulative size array.
  286. // Each element is the number of bytes accumulated
  287. // when the corresponding XWMA packet is decoded in
  288. // order. The array must have PacketCount elements.
  289. UINT32 PacketCount; // Number of XWMA packets submitted. Must be >= 1 and
  290. // divide evenly into XAUDIO2_BUFFER.AudioBytes.
  291. } XAUDIO2_BUFFER_WMA;
  292. // Returned by IXAudio2SourceVoice::GetState
  293. typedef struct XAUDIO2_VOICE_STATE
  294. {
  295. void* pCurrentBufferContext; // The pContext value provided in the XAUDIO2_BUFFER
  296. // that is currently being processed, or NULL if
  297. // there are no buffers in the queue.
  298. UINT32 BuffersQueued; // Number of buffers currently queued on the voice
  299. // (including the one that is being processed).
  300. UINT64 SamplesPlayed; // Total number of samples produced by the voice since
  301. // it began processing the current audio stream.
  302. } XAUDIO2_VOICE_STATE;
  303. // Returned by IXAudio2::GetPerformanceData
  304. typedef struct XAUDIO2_PERFORMANCE_DATA
  305. {
  306. // CPU usage information
  307. UINT64 AudioCyclesSinceLastQuery; // CPU cycles spent on audio processing since the
  308. // last call to StartEngine or GetPerformanceData.
  309. UINT64 TotalCyclesSinceLastQuery; // Total CPU cycles elapsed since the last call
  310. // (only counts the CPU XAudio2 is running on).
  311. UINT32 MinimumCyclesPerQuantum; // Fewest CPU cycles spent processing any one
  312. // audio quantum since the last call.
  313. UINT32 MaximumCyclesPerQuantum; // Most CPU cycles spent processing any one
  314. // audio quantum since the last call.
  315. // Memory usage information
  316. UINT32 MemoryUsageInBytes; // Total heap space currently in use.
  317. // Audio latency and glitching information
  318. UINT32 CurrentLatencyInSamples; // Minimum delay from when a sample is read from a
  319. // source buffer to when it reaches the speakers.
  320. UINT32 GlitchesSinceEngineStarted; // Audio dropouts since the engine was started.
  321. // Data about XAudio2's current workload
  322. UINT32 ActiveSourceVoiceCount; // Source voices currently playing.
  323. UINT32 TotalSourceVoiceCount; // Source voices currently existing.
  324. UINT32 ActiveSubmixVoiceCount; // Submix voices currently playing/existing.
  325. UINT32 ActiveResamplerCount; // Resample xAPOs currently active.
  326. UINT32 ActiveMatrixMixCount; // MatrixMix xAPOs currently active.
  327. // Usage of the hardware XMA decoder (Xbox 360 only)
  328. UINT32 ActiveXmaSourceVoices; // Number of source voices decoding XMA data.
  329. UINT32 ActiveXmaStreams; // A voice can use more than one XMA stream.
  330. } XAUDIO2_PERFORMANCE_DATA;
  331. // Used in IXAudio2::SetDebugConfiguration
  332. typedef struct XAUDIO2_DEBUG_CONFIGURATION
  333. {
  334. UINT32 TraceMask; // Bitmap of enabled debug message types.
  335. UINT32 BreakMask; // Message types that will break into the debugger.
  336. BOOL LogThreadID; // Whether to log the thread ID with each message.
  337. BOOL LogFileline; // Whether to log the source file and line number.
  338. BOOL LogFunctionName; // Whether to log the function name.
  339. BOOL LogTiming; // Whether to log message timestamps.
  340. } XAUDIO2_DEBUG_CONFIGURATION;
  341. // Values for the TraceMask and BreakMask bitmaps. Only ERRORS and WARNINGS
  342. // are valid in BreakMask. WARNINGS implies ERRORS, DETAIL implies INFO, and
  343. // FUNC_CALLS implies API_CALLS. By default, TraceMask is ERRORS and WARNINGS
  344. // and all the other settings are zero.
  345. #define XAUDIO2_LOG_ERRORS 0x0001 // For handled errors with serious effects.
  346. #define XAUDIO2_LOG_WARNINGS 0x0002 // For handled errors that may be recoverable.
  347. #define XAUDIO2_LOG_INFO 0x0004 // Informational chit-chat (e.g. state changes).
  348. #define XAUDIO2_LOG_DETAIL 0x0008 // More detailed chit-chat.
  349. #define XAUDIO2_LOG_API_CALLS 0x0010 // Public API function entries and exits.
  350. #define XAUDIO2_LOG_FUNC_CALLS 0x0020 // Internal function entries and exits.
  351. #define XAUDIO2_LOG_TIMING 0x0040 // Delays detected and other timing data.
  352. #define XAUDIO2_LOG_LOCKS 0x0080 // Usage of critical sections and mutexes.
  353. #define XAUDIO2_LOG_MEMORY 0x0100 // Memory heap usage information.
  354. #define XAUDIO2_LOG_STREAMING 0x1000 // Audio streaming information.
  355. /**************************************************************************
  356. *
  357. * IXAudio2: Top-level XAudio2 COM interface.
  358. *
  359. **************************************************************************/
  360. // Use default arguments if compiling as C++
  361. #ifdef __cplusplus
  362. #define X2DEFAULT(x) =x
  363. #else
  364. #define X2DEFAULT(x)
  365. #endif
  366. #undef INTERFACE
  367. #define INTERFACE IXAudio2
  368. DECLARE_INTERFACE_(IXAudio2, IUnknown)
  369. {
  370. // NAME: IXAudio2::QueryInterface
  371. // DESCRIPTION: Queries for a given COM interface on the XAudio2 object.
  372. // Only IID_IUnknown and IID_IXAudio2 are supported.
  373. //
  374. // ARGUMENTS:
  375. // riid - IID of the interface to be obtained.
  376. // ppvInterface - Returns a pointer to the requested interface.
  377. //
  378. STDMETHOD(QueryInterface) (THIS_ REFIID riid, __deref_out void** ppvInterface) PURE;
  379. // NAME: IXAudio2::AddRef
  380. // DESCRIPTION: Adds a reference to the XAudio2 object.
  381. //
  382. STDMETHOD_(ULONG, AddRef) (THIS) PURE;
  383. // NAME: IXAudio2::Release
  384. // DESCRIPTION: Releases a reference to the XAudio2 object.
  385. //
  386. STDMETHOD_(ULONG, Release) (THIS) PURE;
  387. // NAME: IXAudio2::GetDeviceCount
  388. // DESCRIPTION: Returns the number of audio output devices available.
  389. //
  390. // ARGUMENTS:
  391. // pCount - Returns the device count.
  392. //
  393. STDMETHOD(GetDeviceCount) (THIS_ __out UINT32* pCount) PURE;
  394. // NAME: IXAudio2::GetDeviceDetails
  395. // DESCRIPTION: Returns information about the device with the given index.
  396. //
  397. // ARGUMENTS:
  398. // Index - Index of the device to be queried.
  399. // pDeviceDetails - Returns the device details.
  400. //
  401. STDMETHOD(GetDeviceDetails) (THIS_ UINT32 Index, __out XAUDIO2_DEVICE_DETAILS* pDeviceDetails) PURE;
  402. // NAME: IXAudio2::Initialize
  403. // DESCRIPTION: Sets global XAudio2 parameters and prepares it for use.
  404. //
  405. // ARGUMENTS:
  406. // Flags - Flags specifying the XAudio2 object's behavior. Currently unused.
  407. // XAudio2Processor - An XAUDIO2_PROCESSOR enumeration value that specifies
  408. // the hardware thread (Xbox) or processor (Windows) that XAudio2 will use.
  409. // The enumeration values are platform-specific; platform-independent code
  410. // can use XAUDIO2_DEFAULT_PROCESSOR to use the default on each platform.
  411. //
  412. STDMETHOD(Initialize) (THIS_ UINT32 Flags X2DEFAULT(0),
  413. XAUDIO2_PROCESSOR XAudio2Processor X2DEFAULT(XAUDIO2_DEFAULT_PROCESSOR)) PURE;
  414. // NAME: IXAudio2::RegisterForCallbacks
  415. // DESCRIPTION: Adds a new client to receive XAudio2's engine callbacks.
  416. //
  417. // ARGUMENTS:
  418. // pCallback - Callback interface to be called during each processing pass.
  419. //
  420. STDMETHOD(RegisterForCallbacks) (__in IXAudio2EngineCallback* pCallback) PURE;
  421. // NAME: IXAudio2::UnregisterForCallbacks
  422. // DESCRIPTION: Removes an existing receiver of XAudio2 engine callbacks.
  423. //
  424. // ARGUMENTS:
  425. // pCallback - Previously registered callback interface to be removed.
  426. //
  427. STDMETHOD_(void, UnregisterForCallbacks) (__in IXAudio2EngineCallback* pCallback) PURE;
  428. // NAME: IXAudio2::CreateSourceVoice
  429. // DESCRIPTION: Creates and configures a source voice.
  430. //
  431. // ARGUMENTS:
  432. // ppSourceVoice - Returns the new object's IXAudio2SourceVoice interface.
  433. // pSourceFormat - Format of the audio that will be fed to the voice.
  434. // Flags - XAUDIO2_VOICE flags specifying the source voice's behavior.
  435. // MaxFrequencyRatio - Maximum SetFrequencyRatio argument to be allowed.
  436. // pCallback - Optional pointer to a client-provided callback interface.
  437. // pSendList - Optional list of voices this voice should send audio to.
  438. // pEffectChain - Optional list of effects to apply to the audio data.
  439. //
  440. STDMETHOD(CreateSourceVoice) (THIS_ __deref_out IXAudio2SourceVoice** ppSourceVoice,
  441. __in const WAVEFORMATEX* pSourceFormat,
  442. UINT32 Flags X2DEFAULT(0),
  443. float MaxFrequencyRatio X2DEFAULT(XAUDIO2_DEFAULT_FREQ_RATIO),
  444. __in_opt IXAudio2VoiceCallback* pCallback X2DEFAULT(NULL),
  445. __in_opt const XAUDIO2_VOICE_SENDS* pSendList X2DEFAULT(NULL),
  446. __in_opt const XAUDIO2_EFFECT_CHAIN* pEffectChain X2DEFAULT(NULL)) PURE;
  447. // NAME: IXAudio2::CreateSubmixVoice
  448. // DESCRIPTION: Creates and configures a submix voice.
  449. //
  450. // ARGUMENTS:
  451. // ppSubmixVoice - Returns the new object's IXAudio2SubmixVoice interface.
  452. // InputChannels - Number of channels in this voice's input audio data.
  453. // InputSampleRate - Sample rate of this voice's input audio data.
  454. // Flags - XAUDIO2_VOICE flags specifying the submix voice's behavior.
  455. // ProcessingStage - Arbitrary number that determines the processing order.
  456. // pSendList - Optional list of voices this voice should send audio to.
  457. // pEffectChain - Optional list of effects to apply to the audio data.
  458. //
  459. STDMETHOD(CreateSubmixVoice) (THIS_ __deref_out IXAudio2SubmixVoice** ppSubmixVoice,
  460. UINT32 InputChannels, UINT32 InputSampleRate,
  461. UINT32 Flags X2DEFAULT(0), UINT32 ProcessingStage X2DEFAULT(0),
  462. __in_opt const XAUDIO2_VOICE_SENDS* pSendList X2DEFAULT(NULL),
  463. __in_opt const XAUDIO2_EFFECT_CHAIN* pEffectChain X2DEFAULT(NULL)) PURE;
  464. // NAME: IXAudio2::CreateMasteringVoice
  465. // DESCRIPTION: Creates and configures a mastering voice.
  466. //
  467. // ARGUMENTS:
  468. // ppMasteringVoice - Returns the new object's IXAudio2MasteringVoice interface.
  469. // InputChannels - Number of channels in this voice's input audio data.
  470. // InputSampleRate - Sample rate of this voice's input audio data.
  471. // Flags - XAUDIO2_VOICE flags specifying the mastering voice's behavior.
  472. // DeviceIndex - Identifier of the device to receive the output audio.
  473. // pEffectChain - Optional list of effects to apply to the audio data.
  474. //
  475. STDMETHOD(CreateMasteringVoice) (THIS_ __deref_out IXAudio2MasteringVoice** ppMasteringVoice,
  476. UINT32 InputChannels X2DEFAULT(XAUDIO2_DEFAULT_CHANNELS),
  477. UINT32 InputSampleRate X2DEFAULT(XAUDIO2_DEFAULT_SAMPLERATE),
  478. UINT32 Flags X2DEFAULT(0), UINT32 DeviceIndex X2DEFAULT(0),
  479. __in_opt const XAUDIO2_EFFECT_CHAIN* pEffectChain X2DEFAULT(NULL)) PURE;
  480. // NAME: IXAudio2::StartEngine
  481. // DESCRIPTION: Creates and starts the audio processing thread.
  482. //
  483. STDMETHOD(StartEngine) (THIS) PURE;
  484. // NAME: IXAudio2::StopEngine
  485. // DESCRIPTION: Stops and destroys the audio processing thread.
  486. //
  487. STDMETHOD_(void, StopEngine) (THIS) PURE;
  488. // NAME: IXAudio2::CommitChanges
  489. // DESCRIPTION: Atomically applies a set of operations previously tagged
  490. // with a given identifier.
  491. //
  492. // ARGUMENTS:
  493. // OperationSet - Identifier of the set of operations to be applied.
  494. //
  495. STDMETHOD(CommitChanges) (THIS_ UINT32 OperationSet) PURE;
  496. // NAME: IXAudio2::GetPerformanceData
  497. // DESCRIPTION: Returns current resource usage details: memory, CPU, etc.
  498. //
  499. // ARGUMENTS:
  500. // pPerfData - Returns the performance data structure.
  501. //
  502. STDMETHOD_(void, GetPerformanceData) (THIS_ __out XAUDIO2_PERFORMANCE_DATA* pPerfData) PURE;
  503. // NAME: IXAudio2::SetDebugConfiguration
  504. // DESCRIPTION: Configures XAudio2's debug output (in debug builds only).
  505. //
  506. // ARGUMENTS:
  507. // pDebugConfiguration - Structure describing the debug output behavior.
  508. // pReserved - Optional parameter; must be NULL.
  509. //
  510. STDMETHOD_(void, SetDebugConfiguration) (THIS_ __in_opt const XAUDIO2_DEBUG_CONFIGURATION* pDebugConfiguration,
  511. __in_opt __reserved void* pReserved X2DEFAULT(NULL)) PURE;
  512. };
  513. /**************************************************************************
  514. *
  515. * IXAudio2Voice: Base voice management interface.
  516. *
  517. **************************************************************************/
  518. #undef INTERFACE
  519. #define INTERFACE IXAudio2Voice
  520. DECLARE_INTERFACE(IXAudio2Voice)
  521. {
  522. // These methods are declared in a macro so that the same declarations
  523. // can be used in the derived voice types (IXAudio2SourceVoice, etc).
  524. #define Declare_IXAudio2Voice_Methods() \
  525. \
  526. /* NAME: IXAudio2Voice::GetVoiceDetails
  527. // DESCRIPTION: Returns the basic characteristics of this voice.
  528. //
  529. // ARGUMENTS:
  530. // pVoiceDetails - Returns the voice's details.
  531. */\
  532. STDMETHOD_(void, GetVoiceDetails) (THIS_ __out XAUDIO2_VOICE_DETAILS* pVoiceDetails) PURE; \
  533. \
  534. /* NAME: IXAudio2Voice::SetOutputVoices
  535. // DESCRIPTION: Replaces the set of submix/mastering voices that receive
  536. // this voice's output.
  537. //
  538. // ARGUMENTS:
  539. // pSendList - Optional list of voices this voice should send audio to.
  540. */\
  541. STDMETHOD(SetOutputVoices) (THIS_ __in_opt const XAUDIO2_VOICE_SENDS* pSendList) PURE; \
  542. \
  543. /* NAME: IXAudio2Voice::SetEffectChain
  544. // DESCRIPTION: Replaces this voice's current effect chain with a new one.
  545. //
  546. // ARGUMENTS:
  547. // pEffectChain - Structure describing the new effect chain to be used.
  548. */\
  549. STDMETHOD(SetEffectChain) (THIS_ __in_opt const XAUDIO2_EFFECT_CHAIN* pEffectChain) PURE; \
  550. \
  551. /* NAME: IXAudio2Voice::EnableEffect
  552. // DESCRIPTION: Enables an effect in this voice's effect chain.
  553. //
  554. // ARGUMENTS:
  555. // EffectIndex - Index of an effect within this voice's effect chain.
  556. // OperationSet - Used to identify this call as part of a deferred batch.
  557. */\
  558. STDMETHOD(EnableEffect) (THIS_ UINT32 EffectIndex, \
  559. UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
  560. \
  561. /* NAME: IXAudio2Voice::DisableEffect
  562. // DESCRIPTION: Disables an effect in this voice's effect chain.
  563. //
  564. // ARGUMENTS:
  565. // EffectIndex - Index of an effect within this voice's effect chain.
  566. // OperationSet - Used to identify this call as part of a deferred batch.
  567. */\
  568. STDMETHOD(DisableEffect) (THIS_ UINT32 EffectIndex, \
  569. UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
  570. \
  571. /* NAME: IXAudio2Voice::GetEffectState
  572. // DESCRIPTION: Returns the running state of an effect.
  573. //
  574. // ARGUMENTS:
  575. // EffectIndex - Index of an effect within this voice's effect chain.
  576. // pEnabled - Returns the enabled/disabled state of the given effect.
  577. */\
  578. STDMETHOD_(void, GetEffectState) (THIS_ UINT32 EffectIndex, __out BOOL* pEnabled) PURE; \
  579. \
  580. /* NAME: IXAudio2Voice::SetEffectParameters
  581. // DESCRIPTION: Sets effect-specific parameters.
  582. //
  583. // REMARKS: Unlike IXAPOParameters::SetParameters, this method may
  584. // be called from any thread. XAudio2 implements
  585. // appropriate synchronization to copy the parameters to the
  586. // realtime audio processing thread.
  587. //
  588. // ARGUMENTS:
  589. // EffectIndex - Index of an effect within this voice's effect chain.
  590. // pParameters - Pointer to an effect-specific parameters block.
  591. // ParametersByteSize - Size of the pParameters array in bytes.
  592. // OperationSet - Used to identify this call as part of a deferred batch.
  593. */\
  594. STDMETHOD(SetEffectParameters) (THIS_ UINT32 EffectIndex, \
  595. __in_bcount(ParametersByteSize) const void* pParameters, \
  596. UINT32 ParametersByteSize, \
  597. UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
  598. \
  599. /* NAME: IXAudio2Voice::GetEffectParameters
  600. // DESCRIPTION: Obtains the current effect-specific parameters.
  601. //
  602. // ARGUMENTS:
  603. // EffectIndex - Index of an effect within this voice's effect chain.
  604. // pParameters - Returns the current values of the effect-specific parameters.
  605. // ParametersByteSize - Size of the pParameters array in bytes.
  606. */\
  607. STDMETHOD(GetEffectParameters) (THIS_ UINT32 EffectIndex, \
  608. __out_bcount(ParametersByteSize) void* pParameters, \
  609. UINT32 ParametersByteSize) PURE; \
  610. \
  611. /* NAME: IXAudio2Voice::SetFilterParameters
  612. // DESCRIPTION: Sets this voice's filter parameters.
  613. //
  614. // ARGUMENTS:
  615. // pParameters - Pointer to the filter's parameter structure.
  616. // OperationSet - Used to identify this call as part of a deferred batch.
  617. */\
  618. STDMETHOD(SetFilterParameters) (THIS_ __in const XAUDIO2_FILTER_PARAMETERS* pParameters, \
  619. UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
  620. \
  621. /* NAME: IXAudio2Voice::GetFilterParameters
  622. // DESCRIPTION: Returns this voice's current filter parameters.
  623. //
  624. // ARGUMENTS:
  625. // pParameters - Returns the filter parameters.
  626. */\
  627. STDMETHOD_(void, GetFilterParameters) (THIS_ __out XAUDIO2_FILTER_PARAMETERS* pParameters) PURE; \
  628. \
  629. /* NAME: IXAudio2Voice::SetOutputFilterParameters
  630. // DESCRIPTION: Sets the filter parameters on one of this voice's sends.
  631. //
  632. // ARGUMENTS:
  633. // pDestinationVoice - Destination voice of the send whose filter parameters will be set.
  634. // pParameters - Pointer to the filter's parameter structure.
  635. // OperationSet - Used to identify this call as part of a deferred batch.
  636. */\
  637. STDMETHOD(SetOutputFilterParameters) (THIS_ __in_opt IXAudio2Voice* pDestinationVoice, \
  638. __in const XAUDIO2_FILTER_PARAMETERS* pParameters, \
  639. UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
  640. \
  641. /* NAME: IXAudio2Voice::GetOutputFilterParameters
  642. // DESCRIPTION: Returns the filter parameters from one of this voice's sends.
  643. //
  644. // ARGUMENTS:
  645. // pDestinationVoice - Destination voice of the send whose filter parameters will be read.
  646. // pParameters - Returns the filter parameters.
  647. */\
  648. STDMETHOD_(void, GetOutputFilterParameters) (THIS_ __in_opt IXAudio2Voice* pDestinationVoice, \
  649. __out XAUDIO2_FILTER_PARAMETERS* pParameters) PURE; \
  650. \
  651. /* NAME: IXAudio2Voice::SetVolume
  652. // DESCRIPTION: Sets this voice's overall volume level.
  653. //
  654. // ARGUMENTS:
  655. // Volume - New overall volume level to be used, as an amplitude factor.
  656. // OperationSet - Used to identify this call as part of a deferred batch.
  657. */\
  658. STDMETHOD(SetVolume) (THIS_ float Volume, \
  659. UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
  660. \
  661. /* NAME: IXAudio2Voice::GetVolume
  662. // DESCRIPTION: Obtains this voice's current overall volume level.
  663. //
  664. // ARGUMENTS:
  665. // pVolume: Returns the voice's current overall volume level.
  666. */\
  667. STDMETHOD_(void, GetVolume) (THIS_ __out float* pVolume) PURE; \
  668. \
  669. /* NAME: IXAudio2Voice::SetChannelVolumes
  670. // DESCRIPTION: Sets this voice's per-channel volume levels.
  671. //
  672. // ARGUMENTS:
  673. // Channels - Used to confirm the voice's channel count.
  674. // pVolumes - Array of per-channel volume levels to be used.
  675. // OperationSet - Used to identify this call as part of a deferred batch.
  676. */\
  677. STDMETHOD(SetChannelVolumes) (THIS_ UINT32 Channels, __in_ecount(Channels) const float* pVolumes, \
  678. UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
  679. \
  680. /* NAME: IXAudio2Voice::GetChannelVolumes
  681. // DESCRIPTION: Returns this voice's current per-channel volume levels.
  682. //
  683. // ARGUMENTS:
  684. // Channels - Used to confirm the voice's channel count.
  685. // pVolumes - Returns an array of the current per-channel volume levels.
  686. */\
  687. STDMETHOD_(void, GetChannelVolumes) (THIS_ UINT32 Channels, __out_ecount(Channels) float* pVolumes) PURE; \
  688. \
  689. /* NAME: IXAudio2Voice::SetOutputMatrix
  690. // DESCRIPTION: Sets the volume levels used to mix from each channel of this
  691. // voice's output audio to each channel of a given destination
  692. // voice's input audio.
  693. //
  694. // ARGUMENTS:
  695. // pDestinationVoice - The destination voice whose mix matrix to change.
  696. // SourceChannels - Used to confirm this voice's output channel count
  697. // (the number of channels produced by the last effect in the chain).
  698. // DestinationChannels - Confirms the destination voice's input channels.
  699. // pLevelMatrix - Array of [SourceChannels * DestinationChannels] send
  700. // levels. The level used to send from source channel S to destination
  701. // channel D should be in pLevelMatrix[S + SourceChannels * D].
  702. // OperationSet - Used to identify this call as part of a deferred batch.
  703. */\
  704. STDMETHOD(SetOutputMatrix) (THIS_ __in_opt IXAudio2Voice* pDestinationVoice, \
  705. UINT32 SourceChannels, UINT32 DestinationChannels, \
  706. __in_ecount(SourceChannels * DestinationChannels) const float* pLevelMatrix, \
  707. UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
  708. \
  709. /* NAME: IXAudio2Voice::GetOutputMatrix
  710. // DESCRIPTION: Obtains the volume levels used to send each channel of this
  711. // voice's output audio to each channel of a given destination
  712. // voice's input audio.
  713. //
  714. // ARGUMENTS:
  715. // pDestinationVoice - The destination voice whose mix matrix to obtain.
  716. // SourceChannels - Used to confirm this voice's output channel count
  717. // (the number of channels produced by the last effect in the chain).
  718. // DestinationChannels - Confirms the destination voice's input channels.
  719. // pLevelMatrix - Array of send levels, as above.
  720. */\
  721. STDMETHOD_(void, GetOutputMatrix) (THIS_ __in_opt IXAudio2Voice* pDestinationVoice, \
  722. UINT32 SourceChannels, UINT32 DestinationChannels, \
  723. __out_ecount(SourceChannels * DestinationChannels) float* pLevelMatrix) PURE; \
  724. \
  725. /* NAME: IXAudio2Voice::DestroyVoice
  726. // DESCRIPTION: Destroys this voice, stopping it if necessary and removing
  727. // it from the XAudio2 graph.
  728. */\
  729. STDMETHOD_(void, DestroyVoice) (THIS) PURE
  730. Declare_IXAudio2Voice_Methods();
  731. };
  732. /**************************************************************************
  733. *
  734. * IXAudio2SourceVoice: Source voice management interface.
  735. *
  736. **************************************************************************/
  737. #undef INTERFACE
  738. #define INTERFACE IXAudio2SourceVoice
  739. DECLARE_INTERFACE_(IXAudio2SourceVoice, IXAudio2Voice)
  740. {
  741. // Methods from IXAudio2Voice base interface
  742. Declare_IXAudio2Voice_Methods();
  743. // NAME: IXAudio2SourceVoice::Start
  744. // DESCRIPTION: Makes this voice start consuming and processing audio.
  745. //
  746. // ARGUMENTS:
  747. // Flags - Flags controlling how the voice should be started.
  748. // OperationSet - Used to identify this call as part of a deferred batch.
  749. //
  750. STDMETHOD(Start) (THIS_ UINT32 Flags X2DEFAULT(0), UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
  751. // NAME: IXAudio2SourceVoice::Stop
  752. // DESCRIPTION: Makes this voice stop consuming audio.
  753. //
  754. // ARGUMENTS:
  755. // Flags - Flags controlling how the voice should be stopped.
  756. // OperationSet - Used to identify this call as part of a deferred batch.
  757. //
  758. STDMETHOD(Stop) (THIS_ UINT32 Flags X2DEFAULT(0), UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
  759. // NAME: IXAudio2SourceVoice::SubmitSourceBuffer
  760. // DESCRIPTION: Adds a new audio buffer to this voice's input queue.
  761. //
  762. // ARGUMENTS:
  763. // pBuffer - Pointer to the buffer structure to be queued.
  764. // pBufferWMA - Additional structure used only when submitting XWMA data.
  765. //
  766. STDMETHOD(SubmitSourceBuffer) (THIS_ __in const XAUDIO2_BUFFER* pBuffer, __in_opt const XAUDIO2_BUFFER_WMA* pBufferWMA X2DEFAULT(NULL)) PURE;
  767. // NAME: IXAudio2SourceVoice::FlushSourceBuffers
  768. // DESCRIPTION: Removes all pending audio buffers from this voice's queue.
  769. //
  770. STDMETHOD(FlushSourceBuffers) (THIS) PURE;
  771. // NAME: IXAudio2SourceVoice::Discontinuity
  772. // DESCRIPTION: Notifies the voice of an intentional break in the stream of
  773. // audio buffers (e.g. the end of a sound), to prevent XAudio2
  774. // from interpreting an empty buffer queue as a glitch.
  775. //
  776. STDMETHOD(Discontinuity) (THIS) PURE;
  777. // NAME: IXAudio2SourceVoice::ExitLoop
  778. // DESCRIPTION: Breaks out of the current loop when its end is reached.
  779. //
  780. // ARGUMENTS:
  781. // OperationSet - Used to identify this call as part of a deferred batch.
  782. //
  783. STDMETHOD(ExitLoop) (THIS_ UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
  784. // NAME: IXAudio2SourceVoice::GetState
  785. // DESCRIPTION: Returns the number of buffers currently queued on this voice,
  786. // the pContext value associated with the currently processing
  787. // buffer (if any), and other voice state information.
  788. //
  789. // ARGUMENTS:
  790. // pVoiceState - Returns the state information.
  791. //
  792. STDMETHOD_(void, GetState) (THIS_ __out XAUDIO2_VOICE_STATE* pVoiceState) PURE;
  793. // NAME: IXAudio2SourceVoice::SetFrequencyRatio
  794. // DESCRIPTION: Sets this voice's frequency adjustment, i.e. its pitch.
  795. //
  796. // ARGUMENTS:
  797. // Ratio - Frequency change, expressed as source frequency / target frequency.
  798. // OperationSet - Used to identify this call as part of a deferred batch.
  799. //
  800. STDMETHOD(SetFrequencyRatio) (THIS_ float Ratio,
  801. UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
  802. // NAME: IXAudio2SourceVoice::GetFrequencyRatio
  803. // DESCRIPTION: Returns this voice's current frequency adjustment ratio.
  804. //
  805. // ARGUMENTS:
  806. // pRatio - Returns the frequency adjustment.
  807. //
  808. STDMETHOD_(void, GetFrequencyRatio) (THIS_ __out float* pRatio) PURE;
  809. // NAME: IXAudio2SourceVoice::SetSourceSampleRate
  810. // DESCRIPTION: Reconfigures this voice to treat its source data as being
  811. // at a different sample rate than the original one specified
  812. // in CreateSourceVoice's pSourceFormat argument.
  813. //
  814. // ARGUMENTS:
  815. // UINT32 - The intended sample rate of further submitted source data.
  816. //
  817. STDMETHOD(SetSourceSampleRate) (THIS_ UINT32 NewSourceSampleRate) PURE;
  818. };
  819. /**************************************************************************
  820. *
  821. * IXAudio2SubmixVoice: Submixing voice management interface.
  822. *
  823. **************************************************************************/
  824. #undef INTERFACE
  825. #define INTERFACE IXAudio2SubmixVoice
  826. DECLARE_INTERFACE_(IXAudio2SubmixVoice, IXAudio2Voice)
  827. {
  828. // Methods from IXAudio2Voice base interface
  829. Declare_IXAudio2Voice_Methods();
  830. // There are currently no methods specific to submix voices.
  831. };
  832. /**************************************************************************
  833. *
  834. * IXAudio2MasteringVoice: Mastering voice management interface.
  835. *
  836. **************************************************************************/
  837. #undef INTERFACE
  838. #define INTERFACE IXAudio2MasteringVoice
  839. DECLARE_INTERFACE_(IXAudio2MasteringVoice, IXAudio2Voice)
  840. {
  841. // Methods from IXAudio2Voice base interface
  842. Declare_IXAudio2Voice_Methods();
  843. // There are currently no methods specific to mastering voices.
  844. };
  845. /**************************************************************************
  846. *
  847. * IXAudio2EngineCallback: Client notification interface for engine events.
  848. *
  849. * REMARKS: Contains methods to notify the client when certain events happen
  850. * in the XAudio2 engine. This interface should be implemented by
  851. * the client. XAudio2 will call these methods via the interface
  852. * pointer provided by the client when it calls XAudio2Create or
  853. * IXAudio2::Initialize.
  854. *
  855. **************************************************************************/
  856. #undef INTERFACE
  857. #define INTERFACE IXAudio2EngineCallback
  858. DECLARE_INTERFACE(IXAudio2EngineCallback)
  859. {
  860. // Called by XAudio2 just before an audio processing pass begins.
  861. STDMETHOD_(void, OnProcessingPassStart) (THIS) PURE;
  862. // Called just after an audio processing pass ends.
  863. STDMETHOD_(void, OnProcessingPassEnd) (THIS) PURE;
  864. // Called in the event of a critical system error which requires XAudio2
  865. // to be closed down and restarted. The error code is given in Error.
  866. STDMETHOD_(void, OnCriticalError) (THIS_ HRESULT Error) PURE;
  867. };
  868. /**************************************************************************
  869. *
  870. * IXAudio2VoiceCallback: Client notification interface for voice events.
  871. *
  872. * REMARKS: Contains methods to notify the client when certain events happen
  873. * in an XAudio2 voice. This interface should be implemented by the
  874. * client. XAudio2 will call these methods via an interface pointer
  875. * provided by the client in the IXAudio2::CreateSourceVoice call.
  876. *
  877. **************************************************************************/
  878. #undef INTERFACE
  879. #define INTERFACE IXAudio2VoiceCallback
  880. DECLARE_INTERFACE(IXAudio2VoiceCallback)
  881. {
  882. // Called just before this voice's processing pass begins.
  883. STDMETHOD_(void, OnVoiceProcessingPassStart) (THIS_ UINT32 BytesRequired) PURE;
  884. // Called just after this voice's processing pass ends.
  885. STDMETHOD_(void, OnVoiceProcessingPassEnd) (THIS) PURE;
  886. // Called when this voice has just finished playing a buffer stream
  887. // (as marked with the XAUDIO2_END_OF_STREAM flag on the last buffer).
  888. STDMETHOD_(void, OnStreamEnd) (THIS) PURE;
  889. // Called when this voice is about to start processing a new buffer.
  890. STDMETHOD_(void, OnBufferStart) (THIS_ void* pBufferContext) PURE;
  891. // Called when this voice has just finished processing a buffer.
  892. // The buffer can now be reused or destroyed.
  893. STDMETHOD_(void, OnBufferEnd) (THIS_ void* pBufferContext) PURE;
  894. // Called when this voice has just reached the end position of a loop.
  895. STDMETHOD_(void, OnLoopEnd) (THIS_ void* pBufferContext) PURE;
  896. // Called in the event of a critical error during voice processing,
  897. // such as a failing xAPO or an error from the hardware XMA decoder.
  898. // The voice may have to be destroyed and re-created to recover from
  899. // the error. The callback arguments report which buffer was being
  900. // processed when the error occurred, and its HRESULT code.
  901. STDMETHOD_(void, OnVoiceError) (THIS_ void* pBufferContext, HRESULT Error) PURE;
  902. };
  903. /**************************************************************************
  904. *
  905. * Macros to make it easier to use the XAudio2 COM interfaces in C code.
  906. *
  907. **************************************************************************/
  908. #ifndef __cplusplus
  909. // IXAudio2
  910. #define IXAudio2_QueryInterface(This,riid,ppvInterface) ((This)->lpVtbl->QueryInterface(This,riid,ppvInterface))
  911. #define IXAudio2_AddRef(This) ((This)->lpVtbl->AddRef(This))
  912. #define IXAudio2_Release(This) ((This)->lpVtbl->Release(This))
  913. #define IXAudio2_GetDeviceCount(This,puCount) ((This)->lpVtbl->GetDeviceCount(This,puCount))
  914. #define IXAudio2_GetDeviceDetails(This,Index,pDeviceDetails) ((This)->lpVtbl->GetDeviceDetails(This,Index,pDeviceDetails))
  915. #define IXAudio2_Initialize(This,Flags,XAudio2Processor) ((This)->lpVtbl->Initialize(This,Flags,XAudio2Processor))
  916. #define IXAudio2_CreateSourceVoice(This,ppSourceVoice,pSourceFormat,Flags,MaxFrequencyRatio,pCallback,pSendList,pEffectChain) ((This)->lpVtbl->CreateSourceVoice(This,ppSourceVoice,pSourceFormat,Flags,MaxFrequencyRatio,pCallback,pSendList,pEffectChain))
  917. #define IXAudio2_CreateSubmixVoice(This,ppSubmixVoice,InputChannels,InputSampleRate,Flags,ProcessingStage,pSendList,pEffectChain) ((This)->lpVtbl->CreateSubmixVoice(This,ppSubmixVoice,InputChannels,InputSampleRate,Flags,ProcessingStage,pSendList,pEffectChain))
  918. #define IXAudio2_CreateMasteringVoice(This,ppMasteringVoice,InputChannels,InputSampleRate,Flags,DeviceIndex,pEffectChain) ((This)->lpVtbl->CreateMasteringVoice(This,ppMasteringVoice,InputChannels,InputSampleRate,Flags,DeviceIndex,pEffectChain))
  919. #define IXAudio2_StartEngine(This) ((This)->lpVtbl->StartEngine(This))
  920. #define IXAudio2_StopEngine(This) ((This)->lpVtbl->StopEngine(This))
  921. #define IXAudio2_CommitChanges(This,OperationSet) ((This)->lpVtbl->CommitChanges(This,OperationSet))
  922. #define IXAudio2_GetPerformanceData(This,pPerfData) ((This)->lpVtbl->GetPerformanceData(This,pPerfData))
  923. #define IXAudio2_SetDebugConfiguration(This,pDebugConfiguration,pReserved) ((This)->lpVtbl->SetDebugConfiguration(This,pDebugConfiguration,pReserved))
  924. // IXAudio2Voice
  925. #define IXAudio2Voice_GetVoiceDetails(This,pVoiceDetails) ((This)->lpVtbl->GetVoiceDetails(This,pVoiceDetails))
  926. #define IXAudio2Voice_SetOutputVoices(This,pSendList) ((This)->lpVtbl->SetOutputVoices(This,pSendList))
  927. #define IXAudio2Voice_SetEffectChain(This,pEffectChain) ((This)->lpVtbl->SetEffectChain(This,pEffectChain))
  928. #define IXAudio2Voice_EnableEffect(This,EffectIndex,OperationSet) ((This)->lpVtbl->EnableEffect(This,EffectIndex,OperationSet))
  929. #define IXAudio2Voice_DisableEffect(This,EffectIndex,OperationSet) ((This)->lpVtbl->DisableEffect(This,EffectIndex,OperationSet))
  930. #define IXAudio2Voice_GetEffectState(This,EffectIndex,pEnabled) ((This)->lpVtbl->GetEffectState(This,EffectIndex,pEnabled))
  931. #define IXAudio2Voice_SetEffectParameters(This,EffectIndex,pParameters,ParametersByteSize, OperationSet) ((This)->lpVtbl->SetEffectParameters(This,EffectIndex,pParameters,ParametersByteSize,OperationSet))
  932. #define IXAudio2Voice_GetEffectParameters(This,EffectIndex,pParameters,ParametersByteSize) ((This)->lpVtbl->GetEffectParameters(This,EffectIndex,pParameters,ParametersByteSize))
  933. #define IXAudio2Voice_SetFilterParameters(This,pParameters,OperationSet) ((This)->lpVtbl->SetFilterParameters(This,pParameters,OperationSet))
  934. #define IXAudio2Voice_GetFilterParameters(This,pParameters) ((This)->lpVtbl->GetFilterParameters(This,pParameters))
  935. #define IXAudio2Voice_SetOutputFilterParameters(This,pDestinationVoice,pParameters,OperationSet) ((This)->lpVtbl->SetOutputFilterParameters(This,pDestinationVoice,pParameters,OperationSet))
  936. #define IXAudio2Voice_GetOutputFilterParameters(This,pDestinationVoice,pParameters) ((This)->lpVtbl->GetOutputFilterParameters(This,pDestinationVoice,pParameters))
  937. #define IXAudio2Voice_SetVolume(This,Volume,OperationSet) ((This)->lpVtbl->SetVolume(This,Volume,OperationSet))
  938. #define IXAudio2Voice_GetVolume(This,pVolume) ((This)->lpVtbl->GetVolume(This,pVolume))
  939. #define IXAudio2Voice_SetChannelVolumes(This,Channels,pVolumes,OperationSet) ((This)->lpVtbl->SetChannelVolumes(This,Channels,pVolumes,OperationSet))
  940. #define IXAudio2Voice_GetChannelVolumes(This,Channels,pVolumes) ((This)->lpVtbl->GetChannelVolumes(This,Channels,pVolumes))
  941. #define IXAudio2Voice_SetOutputMatrix(This,pDestinationVoice,SourceChannels,DestinationChannels,pLevelMatrix,OperationSet) ((This)->lpVtbl->SetOutputMatrix(This,pDestinationVoice,SourceChannels,DestinationChannels,pLevelMatrix,OperationSet))
  942. #define IXAudio2Voice_GetOutputMatrix(This,pDestinationVoice,SourceChannels,DestinationChannels,pLevelMatrix) ((This)->lpVtbl->GetOutputMatrix(This,pDestinationVoice,SourceChannels,DestinationChannels,pLevelMatrix))
  943. #define IXAudio2Voice_DestroyVoice(This) ((This)->lpVtbl->DestroyVoice(This))
  944. // IXAudio2SourceVoice
  945. #define IXAudio2SourceVoice_GetVoiceDetails IXAudio2Voice_GetVoiceDetails
  946. #define IXAudio2SourceVoice_SetOutputVoices IXAudio2Voice_SetOutputVoices
  947. #define IXAudio2SourceVoice_SetEffectChain IXAudio2Voice_SetEffectChain
  948. #define IXAudio2SourceVoice_EnableEffect IXAudio2Voice_EnableEffect
  949. #define IXAudio2SourceVoice_DisableEffect IXAudio2Voice_DisableEffect
  950. #define IXAudio2SourceVoice_GetEffectState IXAudio2Voice_GetEffectState
  951. #define IXAudio2SourceVoice_SetEffectParameters IXAudio2Voice_SetEffectParameters
  952. #define IXAudio2SourceVoice_GetEffectParameters IXAudio2Voice_GetEffectParameters
  953. #define IXAudio2SourceVoice_SetFilterParameters IXAudio2Voice_SetFilterParameters
  954. #define IXAudio2SourceVoice_GetFilterParameters IXAudio2Voice_GetFilterParameters
  955. #define IXAudio2SourceVoice_SetOutputFilterParameters IXAudio2Voice_SetOutputFilterParameters
  956. #define IXAudio2SourceVoice_GetOutputFilterParameters IXAudio2Voice_GetOutputFilterParameters
  957. #define IXAudio2SourceVoice_SetVolume IXAudio2Voice_SetVolume
  958. #define IXAudio2SourceVoice_GetVolume IXAudio2Voice_GetVolume
  959. #define IXAudio2SourceVoice_SetChannelVolumes IXAudio2Voice_SetChannelVolumes
  960. #define IXAudio2SourceVoice_GetChannelVolumes IXAudio2Voice_GetChannelVolumes
  961. #define IXAudio2SourceVoice_SetOutputMatrix IXAudio2Voice_SetOutputMatrix
  962. #define IXAudio2SourceVoice_GetOutputMatrix IXAudio2Voice_GetOutputMatrix
  963. #define IXAudio2SourceVoice_DestroyVoice IXAudio2Voice_DestroyVoice
  964. #define IXAudio2SourceVoice_Start(This,Flags,OperationSet) ((This)->lpVtbl->Start(This,Flags,OperationSet))
  965. #define IXAudio2SourceVoice_Stop(This,Flags,OperationSet) ((This)->lpVtbl->Stop(This,Flags,OperationSet))
  966. #define IXAudio2SourceVoice_SubmitSourceBuffer(This,pBuffer,pBufferWMA) ((This)->lpVtbl->SubmitSourceBuffer(This,pBuffer,pBufferWMA))
  967. #define IXAudio2SourceVoice_FlushSourceBuffers(This) ((This)->lpVtbl->FlushSourceBuffers(This))
  968. #define IXAudio2SourceVoice_Discontinuity(This) ((This)->lpVtbl->Discontinuity(This))
  969. #define IXAudio2SourceVoice_ExitLoop(This,OperationSet) ((This)->lpVtbl->ExitLoop(This,OperationSet))
  970. #define IXAudio2SourceVoice_GetState(This,pVoiceState) ((This)->lpVtbl->GetState(This,pVoiceState))
  971. #define IXAudio2SourceVoice_SetFrequencyRatio(This,Ratio,OperationSet) ((This)->lpVtbl->SetFrequencyRatio(This,Ratio,OperationSet))
  972. #define IXAudio2SourceVoice_GetFrequencyRatio(This,pRatio) ((This)->lpVtbl->GetFrequencyRatio(This,pRatio))
  973. #define IXAudio2SourceVoice_SetSourceSampleRate(This,NewSourceSampleRate) ((This)->lpVtbl->SetSourceSampleRate(This,NewSourceSampleRate))
  974. // IXAudio2SubmixVoice
  975. #define IXAudio2SubmixVoice_GetVoiceDetails IXAudio2Voice_GetVoiceDetails
  976. #define IXAudio2SubmixVoice_SetOutputVoices IXAudio2Voice_SetOutputVoices
  977. #define IXAudio2SubmixVoice_SetEffectChain IXAudio2Voice_SetEffectChain
  978. #define IXAudio2SubmixVoice_EnableEffect IXAudio2Voice_EnableEffect
  979. #define IXAudio2SubmixVoice_DisableEffect IXAudio2Voice_DisableEffect
  980. #define IXAudio2SubmixVoice_GetEffectState IXAudio2Voice_GetEffectState
  981. #define IXAudio2SubmixVoice_SetEffectParameters IXAudio2Voice_SetEffectParameters
  982. #define IXAudio2SubmixVoice_GetEffectParameters IXAudio2Voice_GetEffectParameters
  983. #define IXAudio2SubmixVoice_SetFilterParameters IXAudio2Voice_SetFilterParameters
  984. #define IXAudio2SubmixVoice_GetFilterParameters IXAudio2Voice_GetFilterParameters
  985. #define IXAudio2SubmixVoice_SetOutputFilterParameters IXAudio2Voice_SetOutputFilterParameters
  986. #define IXAudio2SubmixVoice_GetOutputFilterParameters IXAudio2Voice_GetOutputFilterParameters
  987. #define IXAudio2SubmixVoice_SetVolume IXAudio2Voice_SetVolume
  988. #define IXAudio2SubmixVoice_GetVolume IXAudio2Voice_GetVolume
  989. #define IXAudio2SubmixVoice_SetChannelVolumes IXAudio2Voice_SetChannelVolumes
  990. #define IXAudio2SubmixVoice_GetChannelVolumes IXAudio2Voice_GetChannelVolumes
  991. #define IXAudio2SubmixVoice_SetOutputMatrix IXAudio2Voice_SetOutputMatrix
  992. #define IXAudio2SubmixVoice_GetOutputMatrix IXAudio2Voice_GetOutputMatrix
  993. #define IXAudio2SubmixVoice_DestroyVoice IXAudio2Voice_DestroyVoice
  994. // IXAudio2MasteringVoice
  995. #define IXAudio2MasteringVoice_GetVoiceDetails IXAudio2Voice_GetVoiceDetails
  996. #define IXAudio2MasteringVoice_SetOutputVoices IXAudio2Voice_SetOutputVoices
  997. #define IXAudio2MasteringVoice_SetEffectChain IXAudio2Voice_SetEffectChain
  998. #define IXAudio2MasteringVoice_EnableEffect IXAudio2Voice_EnableEffect
  999. #define IXAudio2MasteringVoice_DisableEffect IXAudio2Voice_DisableEffect
  1000. #define IXAudio2MasteringVoice_GetEffectState IXAudio2Voice_GetEffectState
  1001. #define IXAudio2MasteringVoice_SetEffectParameters IXAudio2Voice_SetEffectParameters
  1002. #define IXAudio2MasteringVoice_GetEffectParameters IXAudio2Voice_GetEffectParameters
  1003. #define IXAudio2MasteringVoice_SetFilterParameters IXAudio2Voice_SetFilterParameters
  1004. #define IXAudio2MasteringVoice_GetFilterParameters IXAudio2Voice_GetFilterParameters
  1005. #define IXAudio2MasteringVoice_SetOutputFilterParameters IXAudio2Voice_SetOutputFilterParameters
  1006. #define IXAudio2MasteringVoice_GetOutputFilterParameters IXAudio2Voice_GetOutputFilterParameters
  1007. #define IXAudio2MasteringVoice_SetVolume IXAudio2Voice_SetVolume
  1008. #define IXAudio2MasteringVoice_GetVolume IXAudio2Voice_GetVolume
  1009. #define IXAudio2MasteringVoice_SetChannelVolumes IXAudio2Voice_SetChannelVolumes
  1010. #define IXAudio2MasteringVoice_GetChannelVolumes IXAudio2Voice_GetChannelVolumes
  1011. #define IXAudio2MasteringVoice_SetOutputMatrix IXAudio2Voice_SetOutputMatrix
  1012. #define IXAudio2MasteringVoice_GetOutputMatrix IXAudio2Voice_GetOutputMatrix
  1013. #define IXAudio2MasteringVoice_DestroyVoice IXAudio2Voice_DestroyVoice
  1014. #endif // #ifndef __cplusplus
  1015. /**************************************************************************
  1016. *
  1017. * Utility functions used to convert from pitch in semitones and volume
  1018. * in decibels to the frequency and amplitude ratio units used by XAudio2.
  1019. * These are only defined if the client #defines XAUDIO2_HELPER_FUNCTIONS
  1020. * prior to #including xaudio2.h.
  1021. *
  1022. **************************************************************************/
  1023. #ifdef XAUDIO2_HELPER_FUNCTIONS
  1024. #define _USE_MATH_DEFINES // Make math.h define M_PI
  1025. #include <math.h> // For powf, log10f, sinf and asinf
  1026. // Calculate the argument to SetVolume from a decibel value
  1027. __inline float XAudio2DecibelsToAmplitudeRatio(float Decibels)
  1028. {
  1029. return powf(10.0f, Decibels / 20.0f);
  1030. }
  1031. // Recover a volume in decibels from an amplitude factor
  1032. __inline float XAudio2AmplitudeRatioToDecibels(float Volume)
  1033. {
  1034. if (Volume == 0)
  1035. {
  1036. return -3.402823466e+38f; // Smallest float value (-FLT_MAX)
  1037. }
  1038. return 20.0f * log10f(Volume);
  1039. }
  1040. // Calculate the argument to SetFrequencyRatio from a semitone value
  1041. __inline float XAudio2SemitonesToFrequencyRatio(float Semitones)
  1042. {
  1043. // FrequencyRatio = 2 ^ Octaves
  1044. // = 2 ^ (Semitones / 12)
  1045. return powf(2.0f, Semitones / 12.0f);
  1046. }
  1047. // Recover a pitch in semitones from a frequency ratio
  1048. __inline float XAudio2FrequencyRatioToSemitones(float FrequencyRatio)
  1049. {
  1050. // Semitones = 12 * log2(FrequencyRatio)
  1051. // = 12 * log2(10) * log10(FrequencyRatio)
  1052. return 39.86313713864835f * log10f(FrequencyRatio);
  1053. }
  1054. // Convert from filter cutoff frequencies expressed in Hertz to the radian
  1055. // frequency values used in XAUDIO2_FILTER_PARAMETERS.Frequency. Note that
  1056. // the highest CutoffFrequency supported is SampleRate/6. Higher values of
  1057. // CutoffFrequency will return XAUDIO2_MAX_FILTER_FREQUENCY.
  1058. __inline float XAudio2CutoffFrequencyToRadians(float CutoffFrequency, UINT32 SampleRate)
  1059. {
  1060. if ((UINT32)(CutoffFrequency * 6.0f) >= SampleRate)
  1061. {
  1062. return XAUDIO2_MAX_FILTER_FREQUENCY;
  1063. }
  1064. return 2.0f * sinf((float)M_PI * CutoffFrequency / SampleRate);
  1065. }
  1066. // Convert from radian frequencies back to absolute frequencies in Hertz
  1067. __inline float XAudio2RadiansToCutoffFrequency(float Radians, float SampleRate)
  1068. {
  1069. return SampleRate * asinf(Radians / 2.0f) / (float)M_PI;
  1070. }
  1071. #endif // #ifdef XAUDIO2_HELPER_FUNCTIONS
  1072. /**************************************************************************
  1073. *
  1074. * XAudio2Create: Top-level function that creates an XAudio2 instance.
  1075. *
  1076. * On Windows this is just an inline function that calls CoCreateInstance
  1077. * and Initialize. The arguments are described above, under Initialize,
  1078. * except that the XAUDIO2_DEBUG_ENGINE flag can be used here to select
  1079. * the debug version of XAudio2.
  1080. *
  1081. * On Xbox, this function is implemented in the XAudio2 library, and the
  1082. * XAUDIO2_DEBUG_ENGINE flag has no effect; the client must explicitly
  1083. * link with the debug version of the library to obtain debug behavior.
  1084. *
  1085. **************************************************************************/
  1086. #ifdef _XBOX
  1087. STDAPI XAudio2Create(__deref_out IXAudio2** ppXAudio2, UINT32 Flags X2DEFAULT(0),
  1088. XAUDIO2_PROCESSOR XAudio2Processor X2DEFAULT(XAUDIO2_DEFAULT_PROCESSOR));
  1089. #else // Windows
  1090. __inline HRESULT XAudio2Create(__deref_out IXAudio2** ppXAudio2, UINT32 Flags X2DEFAULT(0),
  1091. XAUDIO2_PROCESSOR XAudio2Processor X2DEFAULT(XAUDIO2_DEFAULT_PROCESSOR))
  1092. {
  1093. // Instantiate the appropriate XAudio2 engine
  1094. IXAudio2* pXAudio2;
  1095. #ifdef __cplusplus
  1096. HRESULT hr = CoCreateInstance((Flags & XAUDIO2_DEBUG_ENGINE) ? __uuidof(XAudio2_Debug) : __uuidof(XAudio2),
  1097. NULL, CLSCTX_INPROC_SERVER, __uuidof(IXAudio2), (void**)&pXAudio2);
  1098. if (SUCCEEDED(hr))
  1099. {
  1100. hr = pXAudio2->Initialize(Flags, XAudio2Processor);
  1101. if (SUCCEEDED(hr))
  1102. {
  1103. *ppXAudio2 = pXAudio2;
  1104. }
  1105. else
  1106. {
  1107. pXAudio2->Release();
  1108. }
  1109. }
  1110. #else
  1111. HRESULT hr = CoCreateInstance((Flags & XAUDIO2_DEBUG_ENGINE) ? &CLSID_XAudio2_Debug : &CLSID_XAudio2,
  1112. NULL, CLSCTX_INPROC_SERVER, &IID_IXAudio2, (void**)&pXAudio2);
  1113. if (SUCCEEDED(hr))
  1114. {
  1115. hr = pXAudio2->lpVtbl->Initialize(pXAudio2, Flags, XAudio2Processor);
  1116. if (SUCCEEDED(hr))
  1117. {
  1118. *ppXAudio2 = pXAudio2;
  1119. }
  1120. else
  1121. {
  1122. pXAudio2->lpVtbl->Release(pXAudio2);
  1123. }
  1124. }
  1125. #endif // #ifdef __cplusplus
  1126. return hr;
  1127. }
  1128. #endif // #ifdef _XBOX
  1129. // Undo the #pragma pack(push, 1) directive at the top of this file
  1130. #pragma pack(pop)
  1131. #endif // #ifndef GUID_DEFS_ONLY
  1132. #endif // #ifndef __XAUDIO2_INCLUDED__