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