Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1271 lines
61 KiB

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