2 * Copyright (c) 2015 Mark Harmstone
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 import
"mmdeviceapi.idl";
23 uuid(5a508685
-a254
-4fba
-9b82
-9a24b00306af
)
30 uuid(db05ea35
-0329-4d4b
-a53a
-6dead03d3852
)
32 coclass XAudio2Debug
{
37 typedef struct WAVEFORMATEX
42 DWORD nAvgBytesPerSec
;
51 WORD wValidBitsPerSample
;
52 WORD wSamplesPerBlock
;
57 } WAVEFORMATEXTENSIBLE
, *PWAVEFORMATEXTENSIBLE
;
59 cpp_quote
("#include <mmreg.h>")
62 interface IXAudio2Voice
;
64 typedef enum XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER
66 Processor1
= 0x00000001,
67 Processor2
= 0x00000002,
68 Processor3
= 0x00000004,
69 Processor4
= 0x00000008,
70 Processor5
= 0x00000010,
71 Processor6
= 0x00000020,
72 Processor7
= 0x00000040,
73 Processor8
= 0x00000080,
74 Processor9
= 0x00000100,
75 Processor10
= 0x00000200,
76 Processor11
= 0x00000400,
77 Processor12
= 0x00000800,
78 Processor13
= 0x00001000,
79 Processor14
= 0x00002000,
80 Processor15
= 0x00004000,
81 Processor16
= 0x00008000,
82 Processor17
= 0x00010000,
83 Processor18
= 0x00020000,
84 Processor19
= 0x00040000,
85 Processor20
= 0x00080000,
86 Processor21
= 0x00100000,
87 Processor22
= 0x00200000,
88 Processor23
= 0x00400000,
89 Processor24
= 0x00800000,
90 Processor25
= 0x01000000,
91 Processor26
= 0x02000000,
92 Processor27
= 0x04000000,
93 Processor28
= 0x08000000,
94 Processor29
= 0x10000000,
95 Processor30
= 0x20000000,
96 Processor31
= 0x40000000,
97 Processor32
= 0x80000000,
98 XAUDIO2_ANY_PROCESSOR
= 0xffffffff,
99 XAUDIO2_DEFAULT_PROCESSOR
= XAUDIO2_ANY_PROCESSOR
100 } XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER
, XAUDIO2_PROCESSOR
;
102 typedef struct XAUDIO2_PERFORMANCE_DATA
104 UINT64 AudioCyclesSinceLastQuery
;
105 UINT64 TotalCyclesSinceLastQuery
;
106 UINT32 MinimumCyclesPerQuantum
;
107 UINT32 MaximumCyclesPerQuantum
;
108 UINT32 MemoryUsageInBytes
;
109 UINT32 CurrentLatencyInSamples
;
110 UINT32 GlitchesSinceEngineStarted
;
111 UINT32 ActiveSourceVoiceCount
;
112 UINT32 TotalSourceVoiceCount
;
113 UINT32 ActiveSubmixVoiceCount
;
114 UINT32 ActiveResamplerCount
;
115 UINT32 ActiveMatrixMixCount
;
116 UINT32 ActiveXmaSourceVoices
;
117 UINT32 ActiveXmaStreams
;
118 } XAUDIO2_PERFORMANCE_DATA
;
120 typedef enum XAUDIO2_DEVICE_ROLE
122 NotDefaultDevice
= 0x0,
123 DefaultConsoleDevice
= 0x1,
124 DefaultMultimediaDevice
= 0x2,
125 DefaultCommunicationsDevice
= 0x4,
126 DefaultGameDevice
= 0x8,
127 GlobalDefaultDevice
= 0xf,
128 InvalidDeviceRole
= ~GlobalDefaultDevice
129 } XAUDIO2_DEVICE_ROLE
;
131 typedef struct XAUDIO2_DEVICE_DETAILS
134 WCHAR DisplayName
[256];
135 XAUDIO2_DEVICE_ROLE Role
;
136 WAVEFORMATEXTENSIBLE OutputFormat
;
137 } XAUDIO2_DEVICE_DETAILS
;
139 typedef struct XAUDIO2_VOICE_DETAILS
141 UINT32 CreationFlags
;
142 UINT32 InputChannels
;
143 UINT32 InputSampleRate
;
144 } XAUDIO2_VOICE_DETAILS
;
146 typedef struct XAUDIO2_SEND_DESCRIPTOR
149 IXAudio2Voice
* pOutputVoice
;
150 } XAUDIO2_SEND_DESCRIPTOR
;
152 typedef struct XAUDIO2_VOICE_SENDS
155 XAUDIO2_SEND_DESCRIPTOR
* pSends
;
156 } XAUDIO2_VOICE_SENDS
;
158 typedef struct XAUDIO2_EFFECT_DESCRIPTOR
162 UINT32 OutputChannels
;
163 } XAUDIO2_EFFECT_DESCRIPTOR
;
165 typedef struct XAUDIO2_EFFECT_CHAIN
168 XAUDIO2_EFFECT_DESCRIPTOR
* pEffectDescriptors
;
169 } XAUDIO2_EFFECT_CHAIN
;
171 const UINT32 XAUDIO2_MAX_BUFFER_BYTES
= 0x80000000;
172 const UINT32 XAUDIO2_MAX_QUEUED_BUFFERS
= 64;
173 const UINT32 XAUDIO2_MAX_BUFFERS_SYSTEM
= 2;
174 const UINT32 XAUDIO2_MAX_AUDIO_CHANNELS
= 64;
175 const UINT32 XAUDIO2_MIN_SAMPLE_RATE
= 1000;
176 const UINT32 XAUDIO2_MAX_SAMPLE_RATE
= 200000;
177 const float XAUDIO2_MAX_VOLUME_LEVEL
= 16777216.0;
178 const float XAUDIO2_MIN_FREQ_RATIO
= (1/1024.0);
179 const float XAUDIO2_MAX_FREQ_RATIO
= 1024.0;
180 const float XAUDIO2_DEFAULT_FREQ_RATIO
= 2.0;
181 const float XAUDIO2_MAX_FILTER_ONEOVERQ
= 1.5;
182 const float XAUDIO2_MAX_FILTER_FREQUENCY
= 1.0;
183 const UINT32 XAUDIO2_MAX_LOOP_COUNT
= 254;
185 const UINT32 XAUDIO2_COMMIT_NOW
= 0;
186 const UINT32 XAUDIO2_COMMIT_ALL
= 0;
187 const UINT32 XAUDIO2_INVALID_OPSET
= 0xffffffff;
188 const UINT32 XAUDIO2_NO_LOOP_REGION
= 0;
189 const UINT32 XAUDIO2_LOOP_INFINITE
= 255;
190 const UINT32 XAUDIO2_DEFAULT_CHANNELS
= 0;
191 const UINT32 XAUDIO2_DEFAULT_SAMPLERATE
= 0;
197 interface IXAudio2EngineCallback
199 void OnProcessingPassStart
();
201 void OnProcessingPassEnd
();
203 void OnCriticalError
([in] HRESULT Error
);
206 typedef enum XAUDIO2_FILTER_TYPE
212 } XAUDIO2_FILTER_TYPE
;
214 typedef struct XAUDIO2_FILTER_PARAMETERS
216 XAUDIO2_FILTER_TYPE Type
;
219 } XAUDIO2_FILTER_PARAMETERS
;
225 interface IXAudio2Voice
227 void GetVoiceDetails
([out] XAUDIO2_VOICE_DETAILS
* pVoiceDetails
);
229 HRESULT SetOutputVoices
([in] const XAUDIO2_VOICE_SENDS
* pSendList
);
231 HRESULT SetEffectChain
([in] const XAUDIO2_EFFECT_CHAIN
* pEffectChain
);
233 HRESULT EnableEffect
(
234 [in] UINT32 EffectIndex
,
235 [in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
237 HRESULT DisableEffect
(
238 [in] UINT32 EffectIndex
,
239 [in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
242 [in] UINT32 EffectIndex
,
243 [out] BOOL
* pEnabled
);
245 HRESULT SetEffectParameters
(
246 [in] UINT32 EffectIndex
,
247 [in] const void* pParameters
,
248 [in] UINT32 ParametersByteSize
,
249 [in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
251 HRESULT GetEffectParameters
(
252 [in] UINT32 EffectIndex
,
253 [out] void* pParameters
,
254 [in] UINT32 ParametersByteSize
);
256 HRESULT SetFilterParameters
(
257 [in] const XAUDIO2_FILTER_PARAMETERS
* pParameters
,
258 [in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
260 void GetFilterParameters
([out] XAUDIO2_FILTER_PARAMETERS
* pParameters
);
262 HRESULT SetOutputFilterParameters
(
263 [in] IXAudio2Voice
* pDestinationVoice
,
264 [in] const XAUDIO2_FILTER_PARAMETERS
* pParameters
,
265 [in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
267 void GetOutputFilterParameters
(
268 [in] IXAudio2Voice
* pDestinationVoice
,
269 [out] XAUDIO2_FILTER_PARAMETERS
* pParameters
);
273 [in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
275 void GetVolume
([out] float* pVolume
);
277 HRESULT SetChannelVolumes
(
278 [in] UINT32 Channels
,
279 [in, size_is(Channels
)] const float* pVolumes
,
280 [in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
282 void GetChannelVolumes
(
283 [in] UINT32 Channels
,
284 [out, size_is(Channels
)] float* pVolumes
);
286 HRESULT SetOutputMatrix
(
287 [in] IXAudio2Voice
* pDestinationVoice
,
288 [in] UINT32 SourceChannels
,
289 [in] UINT32 DestinationChannels
,
290 [in, size_is(SourceChannels
* DestinationChannels
)] const float* pLevelMatrix
,
291 [in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
293 void GetOutputMatrix
(
294 [in] IXAudio2Voice
* pDestinationVoice
,
295 [in] UINT32 SourceChannels
,
296 [in] UINT32 DestinationChannels
,
297 [out, size_is(SourceChannels
* DestinationChannels
)] float* pLevelMatrix
);
302 typedef struct XAUDIO2_BUFFER
306 const BYTE* pAudioData
;
315 typedef struct XAUDIO2_BUFFER_WMA
317 const UINT32
* pDecodedPacketCumulativeBytes
;
319 } XAUDIO2_BUFFER_WMA
;
321 typedef struct XAUDIO2_VOICE_STATE
323 void* pCurrentBufferContext
;
324 UINT32 BuffersQueued
;
325 UINT64 SamplesPlayed
;
326 } XAUDIO2_VOICE_STATE
;
331 interface IXAudio2SourceVoice
: IXAudio2Voice
334 [in, defaultvalue(0)] UINT32 Flags
,
335 [in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
338 [in, defaultvalue(0)] UINT32 Flags
,
339 [in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
341 HRESULT SubmitSourceBuffer
(
342 [in] const XAUDIO2_BUFFER
* pBuffer
,
343 [in, defaultvalue(NULL
)] const XAUDIO2_BUFFER_WMA
* pBufferWMA
);
345 HRESULT FlushSourceBuffers
();
347 HRESULT Discontinuity
();
349 HRESULT ExitLoop
([in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
351 void GetState
([out] XAUDIO2_VOICE_STATE
* pVoiceState
);
353 HRESULT SetFrequencyRatio
(
355 [in, defaultvalue(XAUDIO2_COMMIT_NOW
)] UINT32 OperationSet
);
357 void GetFrequencyRatio
([out] float* pRatio
);
359 HRESULT SetSourceSampleRate
([in] UINT32 NewSourceSampleRate
);
365 interface IXAudio2SubmixVoice
: IXAudio2Voice
372 interface IXAudio2MasteringVoice
: IXAudio2Voice
380 interface IXAudio2VoiceCallback
382 void OnVoiceProcessingPassStart
([in] UINT32 BytesRequired
);
384 void OnVoiceProcessingPassEnd
();
388 void OnBufferStart
([in] void* pBufferContext
);
390 void OnBufferEnd
([in] void* pBufferContext
);
392 void OnLoopEnd
([in] void* pBufferContext
);
395 [in] void* pBuffercontext
,
399 typedef struct XAUDIO2_DEBUG_CONFIGURATION
405 BOOL LogFunctionName
;
407 } XAUDIO2_DEBUG_CONFIGURATION
;
411 uuid(8bcf1f58
-9fe7
-4583-8ac6
-e2adc465c8bb
),
413 interface IXAudio2
: IUnknown
415 HRESULT GetDeviceCount
([out] UINT32
* pCount
);
417 HRESULT GetDeviceDetails
(
419 [out] XAUDIO2_DEVICE_DETAILS
* pDeviceDetails
);
422 [in, defaultvalue(0)] UINT32 Flags
,
423 [in, defaultvalue(XAUDIO2_DEFAULT_PROCESSOR
)] XAUDIO2_PROCESSOR XAudio2Processor
);
425 HRESULT RegisterForCallbacks
([in] IXAudio2EngineCallback
* pCallback
);
427 void UnregisterForCallbacks
([in] IXAudio2EngineCallback
* pCallback
);
429 HRESULT CreateSourceVoice
(
430 [out] IXAudio2SourceVoice
** ppSourceVoice
,
431 [in] const WAVEFORMATEX
* pSourceFormat
,
432 [in, defaultvalue(0)] UINT32 Flags
,
433 [in, defaultvalue(XAUDIO2_DEFAULT_FREQ_RATIO
)] float MaxFrequencyRatio
,
434 [in, defaultvalue(NULL
)] IXAudio2VoiceCallback
* pCallback
,
435 [in, defaultvalue(NULL
)] const XAUDIO2_VOICE_SENDS
* pSendList
,
436 [in, defaultvalue(NULL
)] const XAUDIO2_EFFECT_CHAIN
* pEffectChain
);
438 HRESULT CreateSubmixVoice
(
439 [out] IXAudio2SubmixVoice
** ppSubmixVoice
,
440 [in] UINT32 InputChannels
,
441 [in] UINT32 InputSampleRate
,
442 [in, defaultvalue(0)] UINT32 Flags
,
443 [in, defaultvalue(0)] UINT32 ProcessingStage
,
444 [in, defaultvalue(NULL
)] const XAUDIO2_VOICE_SENDS
* pSendList
,
445 [in, defaultvalue(NULL
)] const XAUDIO2_EFFECT_CHAIN
* pEffectChain
);
447 HRESULT CreateMasteringVoice
(
448 [out] IXAudio2MasteringVoice
** ppMasteringVoice
,
449 [in, defaultvalue(XAUDIO2_DEFAULT_CHANNELS
)] UINT32 InputChannels
,
450 [in, defaultvalue(XAUDIO2_DEFAULT_SAMPLERATE
)] UINT32 InputSampleRate
,
451 [in, defaultvalue(0)] UINT32 Flags
,
452 [in, defaultvalue(0)] UINT32 DeviceIndex
,
453 [in, defaultvalue(NULL
)] const XAUDIO2_EFFECT_CHAIN
* pEffectChain
);
455 HRESULT StartEngine
();
459 HRESULT CommitChanges
([in] UINT32 OperationSet
);
461 void GetPerformanceData
([out] XAUDIO2_PERFORMANCE_DATA
* pPerfData
);
463 [local] void SetDebugConfiguration
(
464 [in] const XAUDIO2_DEBUG_CONFIGURATION
* pDebugConfiguration
,
465 [in, defaultvalue(NULL
)] void* pReserved
);
468 const UINT32 XAUDIO2_DEBUG_ENGINE
= 1;
469 const UINT32 XAUDIO2_VOICE_NOPITCH
= 2;
470 const UINT32 XAUDIO2_VOICE_NOSRC
= 4;
471 const UINT32 XAUDIO2_VOICE_USEFILTER
= 8;
472 const UINT32 XAUDIO2_VOICE_MUSIC
= 16;
473 const UINT32 XAUDIO2_PLAY_TAILS
= 32;
474 const UINT32 XAUDIO2_END_OF_STREAM
= 64;
475 const UINT32 XAUDIO2_SEND_USEFILTER
= 128;
477 const XAUDIO2_FILTER_TYPE XAUDIO2_DEFAULT_FILTER_TYPE
= LowPassFilter
;
478 const float XAUDIO2_DEFAULT_FILTER_FREQUENCY
= XAUDIO2_MAX_FILTER_FREQUENCY
;
479 const float XAUDIO2_DEFAULT_FILTER_ONEOVERQ
= 1.0;
480 const UINT32 XAUDIO2_QUANTUM_NUMERATOR
= 1;
481 const UINT32 XAUDIO2_QUANTUM_DENOMINATOR
= 100;
482 const float XAUDIO2_QUANTUM_MS
= (1000.0 * XAUDIO2_QUANTUM_NUMERATOR
/ XAUDIO2_QUANTUM_DENOMINATOR
);
484 const HRESULT XAUDIO2_E_INVALID_CALL
= 0x88960001;
485 const HRESULT XAUDIO2_E_XMA_DECODER_ERROR
= 0x88960002;
486 const HRESULT XAUDIO2_E_XAPO_CREATION_FAILED
= 0x88960003;
487 const HRESULT XAUDIO2_E_DEVICE_INVALIDATED
= 0x88960004;
489 cpp_quote
("#ifdef XAUDIO2_HELPER_FUNCTIONS")
490 cpp_quote
("#define _USE_MATH_DEFINES")
491 cpp_quote
("#include <math.h>")
492 cpp_quote
("inline static float XAudio2DecibelsToAmplitudeRatio(float decibels) { return powf(10.0f, decibels/20.0f); }")
493 cpp_quote
("inline static float XAudio2AmplitudeRatioToDecibels(float volume) { if (volume == 0) { return -3.402823466e+38f; } return 20.0f * log10f(volume); }")
494 cpp_quote
("inline static float XAudio2SemitonesToFrequencyRatio(float semitones) { return powf(2.0f, semitones/12.0f); }")
495 cpp_quote
("inline static float XAudio2FrequencyRatioToSemitones(float freqratio) { return 39.86313713864835f * log10f(freqratio); }")
496 cpp_quote
("inline static float XAudio2CutoffFrequencyToRadians(float cutofffreq, UINT32 samplerate) { if ((UINT32)(cutofffreq * 6.0f) >= samplerate) { return XAUDIO2_MAX_FILTER_FREQUENCY; } return 2.0f * sinf((float)M_PI * cutofffreq / samplerate); }")
497 cpp_quote
("inline static float XAudio2RadiansToCutoffFrequency(float radians, float samplerate) { return samplerate * asinf(radians/2.0f) / (float)M_PI; }")
500 cpp_quote
("#ifdef __cplusplus")
501 cpp_quote
("inline static HRESULT XAudio2Create(IXAudio2** pxaudio2, UINT32 flags = 0, XAUDIO2_PROCESSOR processor = XAUDIO2_DEFAULT_PROCESSOR) {")
502 cpp_quote
(" IXAudio2* xaudio2;")
503 cpp_quote
(" HRESULT hr = CoCreateInstance(__uuidof(XAudio2), NULL, CLSCTX_INPROC_SERVER, __uuidof(IXAudio2), (void**)&xaudio2);")
504 cpp_quote
(" if (SUCCEEDED(hr)) {")
505 cpp_quote
(" hr = xaudio2->Initialize(flags, processor);")
506 cpp_quote
(" if (SUCCEEDED(hr))")
507 cpp_quote
(" *pxaudio2 = xaudio2;")
509 cpp_quote
(" xaudio2->Release();")
511 cpp_quote
(" return hr;")
514 cpp_quote
("inline static HRESULT XAudio2Create(IXAudio2** pxaudio2, UINT32 flags, XAUDIO2_PROCESSOR processor) {")
515 cpp_quote
(" IXAudio2* xaudio2;")
516 cpp_quote
(" HRESULT hr = CoCreateInstance(&CLSID_XAudio2, NULL, CLSCTX_INPROC_SERVER, &IID_IXAudio2, (void**)&xaudio2);")
517 cpp_quote
(" if (SUCCEEDED(hr)) {")
518 cpp_quote
(" hr = xaudio2->lpVtbl->Initialize(xaudio2, flags, processor);")
519 cpp_quote
(" if (SUCCEEDED(hr))")
520 cpp_quote
(" *pxaudio2 = xaudio2;")
522 cpp_quote
(" xaudio2->lpVtbl->Release(xaudio2);")
524 cpp_quote
(" return hr;")