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