Subversion Repositories Games.Chess Giants

Rev

Blame | Last modification | View Log | Download | RSS feed

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