1 /* FAudio - XAudio Reimplementation for FNA
2  *
3  * Copyright (c) 2011-2021 Ethan Lee, Luigi Auriemma, and the MonoGame Team
4  *
5  * This software is provided 'as-is', without any express or implied warranty.
6  * In no event will the authors be held liable for any damages arising from
7  * the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software in a
15  * product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  *
18  * 2. Altered source versions must be plainly marked as such, and must not be
19  * misrepresented as being the original software.
20  *
21  * 3. This notice may not be removed or altered from any source distribution.
22  *
23  * Ethan "flibitijibibo" Lee <flibitijibibo@flibitijibibo.com>
24  *
25  */
26 
27 #ifndef FAUDIO_H
28 #define FAUDIO_H
29 
30 #ifdef _WIN32
31 #define FAUDIOAPI __declspec(dllexport)
32 #define FAUDIOCALL __cdecl
33 #else
34 #define FAUDIOAPI
35 #define FAUDIOCALL
36 #endif
37 
38 #ifdef _MSC_VER
39 #define FAUDIODEPRECATED(msg) __declspec(deprecated(msg))
40 #else
41 #define FAUDIODEPRECATED(msg) __attribute__((deprecated(msg)))
42 #endif
43 
44 /* -Wpedantic nameless union/struct silencing */
45 #ifndef FAUDIONAMELESS
46 #ifdef __GNUC__
47 #define FAUDIONAMELESS __extension__
48 #else
49 #define FAUDIONAMELESS
50 #endif /* __GNUC__ */
51 #endif /* FAUDIONAMELESS */
52 
53 #include <stdint.h>
54 #include <stddef.h>
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif /* __cplusplus */
59 
60 /* Type Declarations */
61 
62 typedef struct FAudio FAudio;
63 typedef struct FAudioVoice FAudioVoice;
64 typedef FAudioVoice FAudioSourceVoice;
65 typedef FAudioVoice FAudioSubmixVoice;
66 typedef FAudioVoice FAudioMasteringVoice;
67 typedef struct FAudioEngineCallback FAudioEngineCallback;
68 typedef struct FAudioVoiceCallback FAudioVoiceCallback;
69 
70 /* Enumerations */
71 
72 typedef enum FAudioDeviceRole
73 {
74 	FAudioNotDefaultDevice =		0x0,
75 	FAudioDefaultConsoleDevice =		0x1,
76 	FAudioDefaultMultimediaDevice =		0x2,
77 	FAudioDefaultCommunicationsDevice =	0x4,
78 	FAudioDefaultGameDevice =		0x8,
79 	FAudioGlobalDefaultDevice =		0xF,
80 	FAudioInvalidDeviceRole = ~FAudioGlobalDefaultDevice
81 } FAudioDeviceRole;
82 
83 typedef enum FAudioFilterType
84 {
85 	FAudioLowPassFilter,
86 	FAudioBandPassFilter,
87 	FAudioHighPassFilter,
88 	FAudioNotchFilter
89 } FAudioFilterType;
90 
91 typedef enum FAudioStreamCategory
92 {
93 	FAudioStreamCategory_Other,
94 	FAudioStreamCategory_ForegroundOnlyMedia,
95 	FAudioStreamCategory_BackgroundCapableMedia,
96 	FAudioStreamCategory_Communications,
97 	FAudioStreamCategory_Alerts,
98 	FAudioStreamCategory_SoundEffects,
99 	FAudioStreamCategory_GameEffects,
100 	FAudioStreamCategory_GameMedia,
101 	FAudioStreamCategory_GameChat,
102 	FAudioStreamCategory_Speech,
103 	FAudioStreamCategory_Movie,
104 	FAudioStreamCategory_Media
105 } FAudioStreamCategory;
106 
107 /* FIXME: The original enum violates ISO C and is platform specific anyway... */
108 typedef uint32_t FAudioProcessor;
109 #define FAUDIO_DEFAULT_PROCESSOR 0xFFFFFFFF
110 
111 /* Structures */
112 
113 #pragma pack(push, 1)
114 
115 typedef struct FAudioGUID
116 {
117 	uint32_t Data1;
118 	uint16_t Data2;
119 	uint16_t Data3;
120 	uint8_t Data4[8];
121 } FAudioGUID;
122 
123 /* See MSDN:
124  * https://msdn.microsoft.com/en-us/library/windows/desktop/dd390970%28v=vs.85%29.aspx
125  */
126 typedef struct FAudioWaveFormatEx
127 {
128 	uint16_t wFormatTag;
129 	uint16_t nChannels;
130 	uint32_t nSamplesPerSec;
131 	uint32_t nAvgBytesPerSec;
132 	uint16_t nBlockAlign;
133 	uint16_t wBitsPerSample;
134 	uint16_t cbSize;
135 } FAudioWaveFormatEx;
136 
137 /* See MSDN:
138  * https://msdn.microsoft.com/en-us/library/windows/desktop/dd390971(v=vs.85).aspx
139  */
140 typedef struct FAudioWaveFormatExtensible
141 {
142 	FAudioWaveFormatEx Format;
143 	union
144 	{
145 		uint16_t wValidBitsPerSample;
146 		uint16_t wSamplesPerBlock;
147 		uint16_t wReserved;
148 	} Samples;
149 	uint32_t dwChannelMask;
150 	FAudioGUID SubFormat;
151 } FAudioWaveFormatExtensible;
152 
153 typedef struct FAudioADPCMCoefSet
154 {
155 	int16_t iCoef1;
156 	int16_t iCoef2;
157 } FAudioADPCMCoefSet;
158 
159 typedef struct FAudioADPCMWaveFormat
160 {
161 	FAudioWaveFormatEx wfx;
162 	uint16_t wSamplesPerBlock;
163 	uint16_t wNumCoef;
164 
165 	/* MSVC warns on empty arrays in structs */
166 	#ifdef _MSC_VER
167 	#pragma warning(push)
168 	#pragma warning(disable: 4200)
169 	#endif
170 
171 	FAudioADPCMCoefSet aCoef[];
172 	/* MSADPCM has 7 coefficient pairs:
173 	 * {
174 	 *	{ 256,    0 },
175 	 *	{ 512, -256 },
176 	 *	{   0,    0 },
177 	 *	{ 192,   64 },
178 	 *	{ 240,    0 },
179 	 *	{ 460, -208 },
180 	 *	{ 392, -232 }
181 	 * }
182 	 */
183 
184 	#ifdef _MSC_VER
185 	#pragma warning(pop)
186 	#endif
187 } FAudioADPCMWaveFormat;
188 
189 typedef struct FAudioDeviceDetails
190 {
191 	int16_t DeviceID[256]; /* Win32 wchar_t */
192 	int16_t DisplayName[256]; /* Win32 wchar_t */
193 	FAudioDeviceRole Role;
194 	FAudioWaveFormatExtensible OutputFormat;
195 } FAudioDeviceDetails;
196 
197 typedef struct FAudioVoiceDetails
198 {
199 	uint32_t CreationFlags;
200 	uint32_t ActiveFlags;
201 	uint32_t InputChannels;
202 	uint32_t InputSampleRate;
203 } FAudioVoiceDetails;
204 
205 typedef struct FAudioSendDescriptor
206 {
207 	uint32_t Flags; /* 0 or FAUDIO_SEND_USEFILTER */
208 	FAudioVoice *pOutputVoice;
209 } FAudioSendDescriptor;
210 
211 typedef struct FAudioVoiceSends
212 {
213 	uint32_t SendCount;
214 	FAudioSendDescriptor *pSends;
215 } FAudioVoiceSends;
216 
217 #ifndef FAPO_DECL
218 #define FAPO_DECL
219 typedef struct FAPO FAPO;
220 #endif /* FAPO_DECL */
221 
222 typedef struct FAudioEffectDescriptor
223 {
224 	FAPO *pEffect;
225 	int32_t InitialState; /* 1 - Enabled, 0 - Disabled */
226 	uint32_t OutputChannels;
227 } FAudioEffectDescriptor;
228 
229 typedef struct FAudioEffectChain
230 {
231 	uint32_t EffectCount;
232 	FAudioEffectDescriptor *pEffectDescriptors;
233 } FAudioEffectChain;
234 
235 typedef struct FAudioFilterParameters
236 {
237 	FAudioFilterType Type;
238 	float Frequency;	/* [0, FAUDIO_MAX_FILTER_FREQUENCY] */
239 	float OneOverQ;		/* [0, FAUDIO_MAX_FILTER_ONEOVERQ] */
240 } FAudioFilterParameters;
241 
242 typedef struct FAudioBuffer
243 {
244 	/* Either 0 or FAUDIO_END_OF_STREAM */
245 	uint32_t Flags;
246 	/* Pointer to wave data, memory block size.
247 	 * Note that pAudioData is not copied; FAudio reads directly from your
248 	 * pointer! This pointer must be valid until FAudio has finished using
249 	 * it, at which point an OnBufferEnd callback will be generated.
250 	 */
251 	uint32_t AudioBytes;
252 	const uint8_t *pAudioData;
253 	/* Play region, in sample frames. */
254 	uint32_t PlayBegin;
255 	uint32_t PlayLength;
256 	/* Loop region, in sample frames.
257 	 * This can be used to loop a subregion of the wave instead of looping
258 	 * the whole thing, i.e. if you have an intro/outro you can set these
259 	 * to loop the middle sections instead. If you don't need this, set both
260 	 * values to 0.
261 	 */
262 	uint32_t LoopBegin;
263 	uint32_t LoopLength;
264 	/* [0, FAUDIO_LOOP_INFINITE] */
265 	uint32_t LoopCount;
266 	/* This is sent to callbacks as pBufferContext */
267 	void *pContext;
268 } FAudioBuffer;
269 
270 typedef struct FAudioBufferWMA
271 {
272 	const uint32_t *pDecodedPacketCumulativeBytes;
273 	uint32_t PacketCount;
274 } FAudioBufferWMA;
275 
276 typedef struct FAudioVoiceState
277 {
278 	void *pCurrentBufferContext;
279 	uint32_t BuffersQueued;
280 	uint64_t SamplesPlayed;
281 } FAudioVoiceState;
282 
283 typedef struct FAudioPerformanceData
284 {
285 	uint64_t AudioCyclesSinceLastQuery;
286 	uint64_t TotalCyclesSinceLastQuery;
287 	uint32_t MinimumCyclesPerQuantum;
288 	uint32_t MaximumCyclesPerQuantum;
289 	uint32_t MemoryUsageInBytes;
290 	uint32_t CurrentLatencyInSamples;
291 	uint32_t GlitchesSinceEngineStarted;
292 	uint32_t ActiveSourceVoiceCount;
293 	uint32_t TotalSourceVoiceCount;
294 	uint32_t ActiveSubmixVoiceCount;
295 	uint32_t ActiveResamplerCount;
296 	uint32_t ActiveMatrixMixCount;
297 	uint32_t ActiveXmaSourceVoices;
298 	uint32_t ActiveXmaStreams;
299 } FAudioPerformanceData;
300 
301 typedef struct FAudioDebugConfiguration
302 {
303 	/* See FAUDIO_LOG_* */
304 	uint32_t TraceMask;
305 	uint32_t BreakMask;
306 	/* 0 or 1 */
307 	int32_t LogThreadID;
308 	int32_t LogFileline;
309 	int32_t LogFunctionName;
310 	int32_t LogTiming;
311 } FAudioDebugConfiguration;
312 
313 #pragma pack(pop)
314 
315 /* Constants */
316 
317 #define FAUDIO_E_OUT_OF_MEMORY		0x8007000e
318 #define FAUDIO_E_INVALID_ARG		0x80070057
319 #define FAUDIO_E_UNSUPPORTED_FORMAT	0x88890008
320 #define FAUDIO_E_INVALID_CALL		0x88960001
321 #define FAUDIO_E_DEVICE_INVALIDATED	0x88960004
322 #define FAPO_E_FORMAT_UNSUPPORTED	0x88970001
323 
324 #define FAUDIO_MAX_BUFFER_BYTES		0x80000000
325 #define FAUDIO_MAX_QUEUED_BUFFERS	64
326 #define FAUDIO_MAX_AUDIO_CHANNELS	64
327 #define FAUDIO_MIN_SAMPLE_RATE		1000
328 #define FAUDIO_MAX_SAMPLE_RATE		200000
329 #define FAUDIO_MAX_VOLUME_LEVEL		16777216.0f
330 #define FAUDIO_MIN_FREQ_RATIO		(1.0f / 1024.0f)
331 #define FAUDIO_MAX_FREQ_RATIO		1024.0f
332 #define FAUDIO_DEFAULT_FREQ_RATIO	2.0f
333 #define FAUDIO_MAX_FILTER_ONEOVERQ	1.5f
334 #define FAUDIO_MAX_FILTER_FREQUENCY	1.0f
335 #define FAUDIO_MAX_LOOP_COUNT		254
336 
337 #define FAUDIO_COMMIT_NOW		0
338 #define FAUDIO_COMMIT_ALL		0
339 #define FAUDIO_INVALID_OPSET		(uint32_t) (-1)
340 #define FAUDIO_NO_LOOP_REGION		0
341 #define FAUDIO_LOOP_INFINITE		255
342 #define FAUDIO_DEFAULT_CHANNELS		0
343 #define FAUDIO_DEFAULT_SAMPLERATE	0
344 
345 #define FAUDIO_DEBUG_ENGINE		0x0001
346 #define FAUDIO_VOICE_NOPITCH		0x0002
347 #define FAUDIO_VOICE_NOSRC		0x0004
348 #define FAUDIO_VOICE_USEFILTER		0x0008
349 #define FAUDIO_VOICE_MUSIC		0x0010
350 #define FAUDIO_PLAY_TAILS		0x0020
351 #define FAUDIO_END_OF_STREAM		0x0040
352 #define FAUDIO_SEND_USEFILTER		0x0080
353 #define FAUDIO_VOICE_NOSAMPLESPLAYED	0x0100
354 #define FAUDIO_1024_QUANTUM		0x8000
355 
356 #define FAUDIO_DEFAULT_FILTER_TYPE	FAudioLowPassFilter
357 #define FAUDIO_DEFAULT_FILTER_FREQUENCY	FAUDIO_MAX_FILTER_FREQUENCY
358 #define FAUDIO_DEFAULT_FILTER_ONEOVERQ	1.0f
359 
360 #define FAUDIO_LOG_ERRORS		0x0001
361 #define FAUDIO_LOG_WARNINGS		0x0002
362 #define FAUDIO_LOG_INFO			0x0004
363 #define FAUDIO_LOG_DETAIL		0x0008
364 #define FAUDIO_LOG_API_CALLS		0x0010
365 #define FAUDIO_LOG_FUNC_CALLS		0x0020
366 #define FAUDIO_LOG_TIMING		0x0040
367 #define FAUDIO_LOG_LOCKS		0x0080
368 #define FAUDIO_LOG_MEMORY		0x0100
369 #define FAUDIO_LOG_STREAMING		0x1000
370 
371 #ifndef _SPEAKER_POSITIONS_
372 #define SPEAKER_FRONT_LEFT		0x00000001
373 #define SPEAKER_FRONT_RIGHT		0x00000002
374 #define SPEAKER_FRONT_CENTER		0x00000004
375 #define SPEAKER_LOW_FREQUENCY		0x00000008
376 #define SPEAKER_BACK_LEFT		0x00000010
377 #define SPEAKER_BACK_RIGHT		0x00000020
378 #define SPEAKER_FRONT_LEFT_OF_CENTER	0x00000040
379 #define SPEAKER_FRONT_RIGHT_OF_CENTER	0x00000080
380 #define SPEAKER_BACK_CENTER		0x00000100
381 #define SPEAKER_SIDE_LEFT		0x00000200
382 #define SPEAKER_SIDE_RIGHT		0x00000400
383 #define SPEAKER_TOP_CENTER		0x00000800
384 #define SPEAKER_TOP_FRONT_LEFT		0x00001000
385 #define SPEAKER_TOP_FRONT_CENTER	0x00002000
386 #define SPEAKER_TOP_FRONT_RIGHT		0x00004000
387 #define SPEAKER_TOP_BACK_LEFT		0x00008000
388 #define SPEAKER_TOP_BACK_CENTER		0x00010000
389 #define SPEAKER_TOP_BACK_RIGHT		0x00020000
390 #define _SPEAKER_POSITIONS_
391 #endif
392 
393 #ifndef SPEAKER_MONO
394 #define SPEAKER_MONO	SPEAKER_FRONT_CENTER
395 #define SPEAKER_STEREO	(SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT)
396 #define SPEAKER_2POINT1 \
397 	(	SPEAKER_FRONT_LEFT	| \
398 		SPEAKER_FRONT_RIGHT	| \
399 		SPEAKER_LOW_FREQUENCY	)
400 #define SPEAKER_SURROUND \
401 	(	SPEAKER_FRONT_LEFT	| \
402 		SPEAKER_FRONT_RIGHT	| \
403 		SPEAKER_FRONT_CENTER	| \
404 		SPEAKER_BACK_CENTER	)
405 #define SPEAKER_QUAD \
406 	(	SPEAKER_FRONT_LEFT	| \
407 		SPEAKER_FRONT_RIGHT	| \
408 		SPEAKER_BACK_LEFT	| \
409 		SPEAKER_BACK_RIGHT	)
410 #define SPEAKER_4POINT1 \
411 	(	SPEAKER_FRONT_LEFT	| \
412 		SPEAKER_FRONT_RIGHT	| \
413 		SPEAKER_LOW_FREQUENCY	| \
414 		SPEAKER_BACK_LEFT	| \
415 		SPEAKER_BACK_RIGHT	)
416 #define SPEAKER_5POINT1 \
417 	(	SPEAKER_FRONT_LEFT	| \
418 		SPEAKER_FRONT_RIGHT	| \
419 		SPEAKER_FRONT_CENTER	| \
420 		SPEAKER_LOW_FREQUENCY	| \
421 		SPEAKER_BACK_LEFT	| \
422 		SPEAKER_BACK_RIGHT	)
423 #define SPEAKER_7POINT1 \
424 	(	SPEAKER_FRONT_LEFT		| \
425 		SPEAKER_FRONT_RIGHT		| \
426 		SPEAKER_FRONT_CENTER		| \
427 		SPEAKER_LOW_FREQUENCY		| \
428 		SPEAKER_BACK_LEFT		| \
429 		SPEAKER_BACK_RIGHT		| \
430 		SPEAKER_FRONT_LEFT_OF_CENTER	| \
431 		SPEAKER_FRONT_RIGHT_OF_CENTER	)
432 #define SPEAKER_5POINT1_SURROUND \
433 	(	SPEAKER_FRONT_LEFT	| \
434 		SPEAKER_FRONT_RIGHT	| \
435 		SPEAKER_FRONT_CENTER	| \
436 		SPEAKER_LOW_FREQUENCY	| \
437 		SPEAKER_SIDE_LEFT	| \
438 		SPEAKER_SIDE_RIGHT	)
439 #define SPEAKER_7POINT1_SURROUND \
440 	(	SPEAKER_FRONT_LEFT	| \
441 		SPEAKER_FRONT_RIGHT	| \
442 		SPEAKER_FRONT_CENTER	| \
443 		SPEAKER_LOW_FREQUENCY	| \
444 		SPEAKER_BACK_LEFT	| \
445 		SPEAKER_BACK_RIGHT	| \
446 		SPEAKER_SIDE_LEFT	| \
447 		SPEAKER_SIDE_RIGHT	)
448 #define SPEAKER_XBOX SPEAKER_5POINT1
449 #endif
450 
451 #define FAUDIO_FORMAT_PCM		1
452 #define FAUDIO_FORMAT_MSADPCM		2
453 #define FAUDIO_FORMAT_IEEE_FLOAT	3
454 #define FAUDIO_FORMAT_WMAUDIO2		0x0161
455 #define FAUDIO_FORMAT_WMAUDIO3		0x0162
456 #define FAUDIO_FORMAT_WMAUDIO_LOSSLESS	0x0163
457 #define FAUDIO_FORMAT_XMAUDIO2		0x0166
458 #define FAUDIO_FORMAT_EXTENSIBLE	0xFFFE
459 
460 extern FAudioGUID DATAFORMAT_SUBTYPE_PCM;
461 extern FAudioGUID DATAFORMAT_SUBTYPE_IEEE_FLOAT;
462 
463 /* FAudio Version API */
464 
465 #define FAUDIO_TARGET_VERSION 8 /* Targeting compatibility with XAudio 2.8 */
466 
467 #define FAUDIO_ABI_VERSION	 0
468 #define FAUDIO_MAJOR_VERSION	21
469 #define FAUDIO_MINOR_VERSION	 1
470 #define FAUDIO_PATCH_VERSION	 0
471 
472 #define FAUDIO_COMPILED_VERSION ( \
473 	(FAUDIO_ABI_VERSION * 100 * 100 * 100) + \
474 	(FAUDIO_MAJOR_VERSION * 100 * 100) + \
475 	(FAUDIO_MINOR_VERSION * 100) + \
476 	(FAUDIO_PATCH_VERSION) \
477 )
478 
479 FAUDIOAPI uint32_t FAudioLinkedVersion(void);
480 
481 /* FAudio Interface */
482 
483 /* This should be your first FAudio call.
484  *
485  * ppFAudio:		Filled with the FAudio core context.
486  * Flags:		Can be 0 or FAUDIO_DEBUG_ENGINE.
487  * XAudio2Processor:	Set this to FAUDIO_DEFAULT_PROCESSOR.
488  *
489  * Returns 0 on success.
490  */
491 FAUDIOAPI uint32_t FAudioCreate(
492 	FAudio **ppFAudio,
493 	uint32_t Flags,
494 	FAudioProcessor XAudio2Processor
495 );
496 
497 /* See "extensions/COMConstructEXT.txt" for more details */
498 FAUDIOAPI uint32_t FAudioCOMConstructEXT(FAudio **ppFAudio, uint8_t version);
499 
500 /* Increments a reference counter. When counter is 0, audio is freed.
501  * Returns the reference count after incrementing.
502  */
503 FAUDIOAPI uint32_t FAudio_AddRef(FAudio *audio);
504 
505 /* Decrements a reference counter. When counter is 0, audio is freed.
506  * Returns the reference count after decrementing.
507  */
508 FAUDIOAPI uint32_t FAudio_Release(FAudio *audio);
509 
510 /* Queries the number of sound devices available for use.
511  *
512  * pCount: Filled with the number of available sound devices.
513  *
514  * Returns 0 on success.
515  */
516 FAUDIOAPI uint32_t FAudio_GetDeviceCount(FAudio *audio, uint32_t *pCount);
517 
518 /* Gets basic information about a sound device.
519  *
520  * Index:		Can be between 0 and the result of GetDeviceCount.
521  * pDeviceDetails:	Filled with the device information.
522  *
523  * Returns 0 on success.
524  */
525 FAUDIOAPI uint32_t FAudio_GetDeviceDetails(
526 	FAudio *audio,
527 	uint32_t Index,
528 	FAudioDeviceDetails *pDeviceDetails
529 );
530 
531 /* You don't actually have to call this, unless you're using the COM APIs.
532  * See the FAudioCreate API for parameter information.
533  */
534 FAUDIOAPI uint32_t FAudio_Initialize(
535 	FAudio *audio,
536 	uint32_t Flags,
537 	FAudioProcessor XAudio2Processor
538 );
539 
540 /* Register a new set of engine callbacks.
541  * There is no limit to the number of sets, but expect performance to degrade
542  * if you have a whole bunch of these. You most likely only need one.
543  *
544  * pCallback: The completely-initialized FAudioEngineCallback structure.
545  *
546  * Returns 0 on success.
547  */
548 FAUDIOAPI uint32_t FAudio_RegisterForCallbacks(
549 	FAudio *audio,
550 	FAudioEngineCallback *pCallback
551 );
552 
553 /* Remove an active set of engine callbacks.
554  * This checks the pointer value, NOT the callback values!
555  *
556  * pCallback: An FAudioEngineCallback structure previously sent to Register.
557  *
558  * Returns 0 on success.
559  */
560 FAUDIOAPI void FAudio_UnregisterForCallbacks(
561 	FAudio *audio,
562 	FAudioEngineCallback *pCallback
563 );
564 
565 /* Creates a "source" voice, used to play back wavedata.
566  *
567  * ppSourceVoice:	Filled with the source voice pointer.
568  * pSourceFormat:	The input wavedata format, see the documentation for
569  *			FAudioWaveFormatEx.
570  * Flags:		Can be 0 or a mix of the following FAUDIO_VOICE_* flags:
571  *			NOPITCH/NOSRC:	Resampling is disabled. If you set this,
572  *					the source format sample rate MUST match
573  *					the output voices' input sample rates.
574  *					Also, SetFrequencyRatio will fail.
575  *			USEFILTER:	Enables the use of SetFilterParameters.
576  *			MUSIC:		Unsupported.
577  * MaxFrequencyRatio:	AKA your max pitch. This allows us to optimize the size
578  *			of the decode/resample cache sizes. For example, if you
579  *			only expect to raise pitch by a single octave, you can
580  *			set this value to 2.0f. 2.0f is the default value.
581  *			Bounds: [FAUDIO_MIN_FREQ_RATIO, FAUDIO_MAX_FREQ_RATIO].
582  * pCallback:		Voice callbacks, see FAudioVoiceCallback documentation.
583  * pSendList:		List of output voices. If NULL, defaults to master.
584  *			All output voices must have the same sample rate!
585  * pEffectChain:	List of FAPO effects. This value can be NULL.
586  *
587  * Returns 0 on success.
588  */
589 FAUDIOAPI uint32_t FAudio_CreateSourceVoice(
590 	FAudio *audio,
591 	FAudioSourceVoice **ppSourceVoice,
592 	const FAudioWaveFormatEx *pSourceFormat,
593 	uint32_t Flags,
594 	float MaxFrequencyRatio,
595 	FAudioVoiceCallback *pCallback,
596 	const FAudioVoiceSends *pSendList,
597 	const FAudioEffectChain *pEffectChain
598 );
599 
600 /* Creates a "submix" voice, used to mix/process input voices.
601  * The typical use case for this is to perform CPU-intensive tasks on large
602  * groups of voices all at once. Examples include resampling and FAPO effects.
603  *
604  * ppSubmixVoice:	Filled with the submix voice pointer.
605  * InputChannels:	Input voices will convert to this channel count.
606  * InputSampleRate:	Input voices will convert to this sample rate.
607  * Flags:		Can be 0 or FAUDIO_VOICE_USEFILTER.
608  * ProcessingStage:	If you have multiple submixes that depend on a specific
609  *			order of processing, you can sort them by setting this
610  *			value to prioritize them. For example, submixes with
611  *			stage 0 will process first, then stage 1, 2, and so on.
612  * pSendList:		List of output voices. If NULL, defaults to master.
613  *			All output voices must have the same sample rate!
614  * pEffectChain:	List of FAPO effects. This value can be NULL.
615  *
616  * Returns 0 on success.
617  */
618 FAUDIOAPI uint32_t FAudio_CreateSubmixVoice(
619 	FAudio *audio,
620 	FAudioSubmixVoice **ppSubmixVoice,
621 	uint32_t InputChannels,
622 	uint32_t InputSampleRate,
623 	uint32_t Flags,
624 	uint32_t ProcessingStage,
625 	const FAudioVoiceSends *pSendList,
626 	const FAudioEffectChain *pEffectChain
627 );
628 
629 /* This should be your second FAudio call, unless you care about which device
630  * you want to use. In that case, see GetDeviceDetails.
631  *
632  * ppMasteringVoice:	Filled with the mastering voice pointer.
633  * InputChannels:	Device channel count. Can be FAUDIO_DEFAULT_CHANNELS.
634  * InputSampleRate:	Device sample rate. Can be FAUDIO_DEFAULT_SAMPLERATE.
635  * Flags:		This value must be 0.
636  * DeviceIndex:		0 for the default device. See GetDeviceCount.
637  * pEffectChain:	List of FAPO effects. This value can be NULL.
638  *
639  * Returns 0 on success.
640  */
641 FAUDIOAPI uint32_t FAudio_CreateMasteringVoice(
642 	FAudio *audio,
643 	FAudioMasteringVoice **ppMasteringVoice,
644 	uint32_t InputChannels,
645 	uint32_t InputSampleRate,
646 	uint32_t Flags,
647 	uint32_t DeviceIndex,
648 	const FAudioEffectChain *pEffectChain
649 );
650 
651 /* This is the XAudio 2.8+ version of CreateMasteringVoice.
652  * Right now this doesn't do anything. Don't use this function.
653  */
654 FAUDIOAPI uint32_t FAudio_CreateMasteringVoice8(
655 	FAudio *audio,
656 	FAudioMasteringVoice **ppMasteringVoice,
657 	uint32_t InputChannels,
658 	uint32_t InputSampleRate,
659 	uint32_t Flags,
660 	uint16_t *szDeviceId,
661 	const FAudioEffectChain *pEffectChain,
662 	FAudioStreamCategory StreamCategory
663 );
664 
665 /* Starts the engine, begins processing the audio graph.
666  * Returns 0 on success.
667  */
668 FAUDIOAPI uint32_t FAudio_StartEngine(FAudio *audio);
669 
670 /* Stops the engine and halts all processing.
671  * The audio device will continue to run, but will produce silence.
672  * The graph will be frozen until you call StartEngine, where it will then
673  * resume all processing exactly as it would have had this never been called.
674  */
675 FAUDIOAPI void FAudio_StopEngine(FAudio *audio);
676 
677 /* Flushes a batch of FAudio calls compiled with a given "OperationSet" tag.
678  * This function is based on IXAudio2::CommitChanges from the XAudio2 spec.
679  * This is useful for pushing calls that need to be done perfectly in sync. For
680  * example, if you want to play two separate sources at the exact same time, you
681  * can call FAudioSourceVoice_Start with an OperationSet value of your choice,
682  * then call CommitChanges with that same value to start the sources together.
683  *
684  * OperationSet: Either a value known by you or FAUDIO_COMMIT_ALL
685  *
686  * Returns 0 on success.
687  */
688 FAUDIOAPI uint32_t FAudio_CommitOperationSet(
689 	FAudio *audio,
690 	uint32_t OperationSet
691 );
692 
693 /* DO NOT USE THIS FUNCTION OR I SWEAR TO GOD */
694 FAUDIODEPRECATED("This function will break your program! Use FAudio_CommitOperationSet instead!")
695 FAUDIOAPI uint32_t FAudio_CommitChanges(FAudio *audio);
696 
697 /* Requests various bits of performance information from the engine.
698  *
699  * pPerfData: Filled with the data. See FAudioPerformanceData for details.
700  */
701 FAUDIOAPI void FAudio_GetPerformanceData(
702 	FAudio *audio,
703 	FAudioPerformanceData *pPerfData
704 );
705 
706 /* When using a Debug binary, this lets you configure what information gets
707  * logged to output. Be careful, this can spit out a LOT of text.
708  *
709  * pDebugConfiguration:	See FAudioDebugConfiguration for details.
710  * pReserved:		Set this to NULL.
711  */
712 FAUDIOAPI void FAudio_SetDebugConfiguration(
713 	FAudio *audio,
714 	FAudioDebugConfiguration *pDebugConfiguration,
715 	void* pReserved
716 );
717 
718 /* Requests the values that determine's the engine's update size.
719  * For example, a 48KHz engine with a 1024-sample update period would return
720  * 1024 for the numerator and 48000 for the denominator. With this information,
721  * you can determine the precise update size in milliseconds.
722  *
723  * quantumNumerator - The engine's update size, in sample frames.
724  * quantumDenominator - The engine's sample rate, in Hz
725  */
726 FAUDIOAPI void FAudio_GetProcessingQuantum(
727 	FAudio *audio,
728 	uint32_t *quantumNumerator,
729 	uint32_t *quantumDenominator
730 );
731 
732 /* FAudioVoice Interface */
733 
734 /* Requests basic information about a voice.
735  *
736  * pVoiceDetails: See FAudioVoiceDetails for details.
737  */
738 FAUDIOAPI void FAudioVoice_GetVoiceDetails(
739 	FAudioVoice *voice,
740 	FAudioVoiceDetails *pVoiceDetails
741 );
742 
743 /* Change the output voices for this voice.
744  * This function is invalid for mastering voices.
745  *
746  * pSendList:	List of output voices. If NULL, defaults to master.
747  *		All output voices must have the same sample rate!
748  *
749  * Returns 0 on success.
750  */
751 FAUDIOAPI uint32_t FAudioVoice_SetOutputVoices(
752 	FAudioVoice *voice,
753 	const FAudioVoiceSends *pSendList
754 );
755 
756 /* Change/Remove the effect chain for this voice.
757  *
758  * pEffectChain:	List of FAPO effects. This value can be NULL.
759  *			Note that the final channel counts for this chain MUST
760  *			match the input/output channel count that was
761  *			determined at voice creation time!
762  *
763  * Returns 0 on success.
764  */
765 FAUDIOAPI uint32_t FAudioVoice_SetEffectChain(
766 	FAudioVoice *voice,
767 	const FAudioEffectChain *pEffectChain
768 );
769 
770 /* Enables an effect in the effect chain.
771  *
772  * EffectIndex:		The index of the effect (based on the chain order).
773  * OperationSet:	See CommitChanges. Default is FAUDIO_COMMIT_NOW.
774  *
775  * Returns 0 on success.
776  */
777 FAUDIOAPI uint32_t FAudioVoice_EnableEffect(
778 	FAudioVoice *voice,
779 	uint32_t EffectIndex,
780 	uint32_t OperationSet
781 );
782 
783 /* Disables an effect in the effect chain.
784  *
785  * EffectIndex:		The index of the effect (based on the chain order).
786  * OperationSet:	See CommitChanges. Default is FAUDIO_COMMIT_NOW.
787  *
788  * Returns 0 on success.
789  */
790 FAUDIOAPI uint32_t FAudioVoice_DisableEffect(
791 	FAudioVoice *voice,
792 	uint32_t EffectIndex,
793 	uint32_t OperationSet
794 );
795 
796 /* Queries the enabled/disabled state of an effect in the effect chain.
797  *
798  * EffectIndex:	The index of the effect (based on the chain order).
799  * pEnabled:	Filled with either 1 (Enabled) or 0 (Disabled).
800  *
801  * Returns 0 on success.
802  */
803 FAUDIOAPI void FAudioVoice_GetEffectState(
804 	FAudioVoice *voice,
805 	uint32_t EffectIndex,
806 	int32_t *pEnabled
807 );
808 
809 /* Submits a block of memory to be sent to FAPO::SetParameters.
810  *
811  * EffectIndex:		The index of the effect (based on the chain order).
812  * pParameters:		The values to be copied and submitted to the FAPO.
813  * ParametersByteSize:	This should match what the FAPO expects!
814  * OperationSet:	See CommitChanges. Default is FAUDIO_COMMIT_NOW.
815  *
816  * Returns 0 on success.
817  */
818 FAUDIOAPI uint32_t FAudioVoice_SetEffectParameters(
819 	FAudioVoice *voice,
820 	uint32_t EffectIndex,
821 	const void *pParameters,
822 	uint32_t ParametersByteSize,
823 	uint32_t OperationSet
824 );
825 
826 /* Requests the latest parameters from FAPO::GetParameters.
827  *
828  * EffectIndex:		The index of the effect (based on the chain order).
829  * pParameters:		Filled with the latest parameter values from the FAPO.
830  * ParametersByteSize:	This should match what the FAPO expects!
831  *
832  * Returns 0 on success.
833  */
834 FAUDIOAPI uint32_t FAudioVoice_GetEffectParameters(
835 	FAudioVoice *voice,
836 	uint32_t EffectIndex,
837 	void *pParameters,
838 	uint32_t ParametersByteSize
839 );
840 
841 /* Sets the filter variables for a voice.
842  * This is only valid on voices with the USEFILTER flag.
843  *
844  * pParameters:		See FAudioFilterParameters for details.
845  * OperationSet:	See CommitChanges. Default is FAUDIO_COMMIT_NOW.
846  *
847  * Returns 0 on success.
848  */
849 FAUDIOAPI uint32_t FAudioVoice_SetFilterParameters(
850 	FAudioVoice *voice,
851 	const FAudioFilterParameters *pParameters,
852 	uint32_t OperationSet
853 );
854 
855 /* Requests the filter variables for a voice.
856  * This is only valid on voices with the USEFILTER flag.
857  *
858  * pParameters: See FAudioFilterParameters for details.
859  */
860 FAUDIOAPI void FAudioVoice_GetFilterParameters(
861 	FAudioVoice *voice,
862 	FAudioFilterParameters *pParameters
863 );
864 
865 /* Sets the filter variables for a voice's output voice.
866  * This is only valid on sends with the USEFILTER flag.
867  *
868  * pDestinationVoice:	An output voice from the voice's send list.
869  * pParameters:		See FAudioFilterParameters for details.
870  * OperationSet:	See CommitChanges. Default is FAUDIO_COMMIT_NOW.
871  *
872  * Returns 0 on success.
873  */
874 FAUDIOAPI uint32_t FAudioVoice_SetOutputFilterParameters(
875 	FAudioVoice *voice,
876 	FAudioVoice *pDestinationVoice,
877 	const FAudioFilterParameters *pParameters,
878 	uint32_t OperationSet
879 );
880 
881 /* Requests the filter variables for a voice's output voice.
882  * This is only valid on sends with the USEFILTER flag.
883  *
884  * pDestinationVoice:	An output voice from the voice's send list.
885  * pParameters:		See FAudioFilterParameters for details.
886  */
887 FAUDIOAPI void FAudioVoice_GetOutputFilterParameters(
888 	FAudioVoice *voice,
889 	FAudioVoice *pDestinationVoice,
890 	FAudioFilterParameters *pParameters
891 );
892 
893 /* Sets the global volume of a voice.
894  *
895  * Volume:		Amplitude ratio. 1.0f is default, 0.0f is silence.
896  *			Note that you can actually set volume < 0.0f!
897  *			Bounds: [-FAUDIO_MAX_VOLUME_LEVEL, FAUDIO_MAX_VOLUME_LEVEL]
898  * OperationSet:	See CommitChanges. Default is FAUDIO_COMMIT_NOW.
899  *
900  * Returns 0 on success.
901  */
902 FAUDIOAPI uint32_t FAudioVoice_SetVolume(
903 	FAudioVoice *voice,
904 	float Volume,
905 	uint32_t OperationSet
906 );
907 
908 /* Requests the global volume of a voice.
909  *
910  * pVolume: Filled with the current voice amplitude ratio.
911  */
912 FAUDIOAPI void FAudioVoice_GetVolume(
913 	FAudioVoice *voice,
914 	float *pVolume
915 );
916 
917 /* Sets the per-channel volumes of a voice.
918  *
919  * Channels:		Must match the channel count of this voice!
920  * pVolumes:		Amplitude ratios for each channel. Same as SetVolume.
921  * OperationSet:	See CommitChanges. Default is FAUDIO_COMMIT_NOW.
922  *
923  * Returns 0 on success.
924  */
925 FAUDIOAPI uint32_t FAudioVoice_SetChannelVolumes(
926 	FAudioVoice *voice,
927 	uint32_t Channels,
928 	const float *pVolumes,
929 	uint32_t OperationSet
930 );
931 
932 /* Requests the per-channel volumes of a voice.
933  *
934  * Channels:	Must match the channel count of this voice!
935  * pVolumes:	Filled with the current channel amplitude ratios.
936  */
937 FAUDIOAPI void FAudioVoice_GetChannelVolumes(
938 	FAudioVoice *voice,
939 	uint32_t Channels,
940 	float *pVolumes
941 );
942 
943 /* Sets the volumes of a send's output channels. The matrix is based on the
944  * voice's input channels. For example, the default matrix for a 2-channel
945  * source and a 2-channel output voice is as follows:
946  * [0] = 1.0f; <- Left input, left output
947  * [1] = 0.0f; <- Right input, left output
948  * [2] = 0.0f; <- Left input, right output
949  * [3] = 1.0f; <- Right input, right output
950  * This is typically only used for panning or 3D sound (via F3DAudio).
951  *
952  * pDestinationVoice:	An output voice from the voice's send list.
953  * SourceChannels:	Must match the voice's input channel count!
954  * DestinationChannels:	Must match the destination's input channel count!
955  * pLevelMatrix:	A float[SourceChannels * DestinationChannels].
956  * OperationSet:	See CommitChanges. Default is FAUDIO_COMMIT_NOW.
957  *
958  * Returns 0 on success.
959  */
960 FAUDIOAPI uint32_t FAudioVoice_SetOutputMatrix(
961 	FAudioVoice *voice,
962 	FAudioVoice *pDestinationVoice,
963 	uint32_t SourceChannels,
964 	uint32_t DestinationChannels,
965 	const float *pLevelMatrix,
966 	uint32_t OperationSet
967 );
968 
969 /* Gets the volumes of a send's output channels. See SetOutputMatrix.
970  *
971  * pDestinationVoice:	An output voice from the voice's send list.
972  * SourceChannels:	Must match the voice's input channel count!
973  * DestinationChannels:	Must match the voice's output channel count!
974  * pLevelMatrix:	A float[SourceChannels * DestinationChannels].
975  */
976 FAUDIOAPI void FAudioVoice_GetOutputMatrix(
977 	FAudioVoice *voice,
978 	FAudioVoice *pDestinationVoice,
979 	uint32_t SourceChannels,
980 	uint32_t DestinationChannels,
981 	float *pLevelMatrix
982 );
983 
984 /* Removes this voice from the audio graph and frees memory. */
985 FAUDIOAPI void FAudioVoice_DestroyVoice(FAudioVoice *voice);
986 
987 /* FAudioSourceVoice Interface */
988 
989 /* Starts processing for a source voice.
990  *
991  * Flags:		Must be 0.
992  * OperationSet:	See CommitChanges. Default is FAUDIO_COMMIT_NOW.
993  *
994  * Returns 0 on success.
995  */
996 FAUDIOAPI uint32_t FAudioSourceVoice_Start(
997 	FAudioSourceVoice *voice,
998 	uint32_t Flags,
999 	uint32_t OperationSet
1000 );
1001 
1002 /* Pauses processing for a source voice. Yes, I said pausing.
1003  * If you want to _actually_ stop, call FlushSourceBuffers next.
1004  *
1005  * Flags:		Can be 0 or FAUDIO_PLAY_TAILS, which allows effects to
1006  *			keep emitting output even after processing has stopped.
1007  * OperationSet:	See CommitChanges. Default is FAUDIO_COMMIT_NOW.
1008  *
1009  * Returns 0 on success.
1010  */
1011 FAUDIOAPI uint32_t FAudioSourceVoice_Stop(
1012 	FAudioSourceVoice *voice,
1013 	uint32_t Flags,
1014 	uint32_t OperationSet
1015 );
1016 
1017 /* Submits a block of wavedata for the source to process.
1018  *
1019  * pBuffer:	See FAudioBuffer for details.
1020  * pBufferWMA:	See FAudioBufferWMA for details. (Also, don't use WMA.)
1021  *
1022  * Returns 0 on success.
1023  */
1024 FAUDIOAPI uint32_t FAudioSourceVoice_SubmitSourceBuffer(
1025 	FAudioSourceVoice *voice,
1026 	const FAudioBuffer *pBuffer,
1027 	const FAudioBufferWMA *pBufferWMA
1028 );
1029 
1030 /* Removes all buffers from a source, with a minor exception.
1031  * If the voice is still playing, the active buffer is left alone.
1032  * All buffers that are removed will spawn an OnBufferEnd callback.
1033  *
1034  * Returns 0 on success.
1035  */
1036 FAUDIOAPI uint32_t FAudioSourceVoice_FlushSourceBuffers(
1037 	FAudioSourceVoice *voice
1038 );
1039 
1040 /* Takes the last buffer currently queued and sets the END_OF_STREAM flag.
1041  *
1042  * Returns 0 on success.
1043  */
1044 FAUDIOAPI uint32_t FAudioSourceVoice_Discontinuity(
1045 	FAudioSourceVoice *voice
1046 );
1047 
1048 /* Sets the loop count of the active buffer to 0.
1049  *
1050  * OperationSet: See CommitChanges. Default is FAUDIO_COMMIT_NOW.
1051  *
1052  * Returns 0 on success.
1053  */
1054 FAUDIOAPI uint32_t FAudioSourceVoice_ExitLoop(
1055 	FAudioSourceVoice *voice,
1056 	uint32_t OperationSet
1057 );
1058 
1059 /* Requests the state and some basic statistics for this source.
1060  *
1061  * pVoiceState:	See FAudioVoiceState for details.
1062  * Flags:	Can be 0 or FAUDIO_VOICE_NOSAMPLESPLAYED.
1063  */
1064 FAUDIOAPI void FAudioSourceVoice_GetState(
1065 	FAudioSourceVoice *voice,
1066 	FAudioVoiceState *pVoiceState,
1067 	uint32_t Flags
1068 );
1069 
1070 /* Sets the frequency ratio (fancy phrase for pitch) of this source.
1071  *
1072  * Ratio:		The frequency ratio, must be <= MaxFrequencyRatio.
1073  * OperationSet:	See CommitChanges. Default is FAUDIO_COMMIT_NOW.
1074  *
1075  * Returns 0 on success.
1076  */
1077 FAUDIOAPI uint32_t FAudioSourceVoice_SetFrequencyRatio(
1078 	FAudioSourceVoice *voice,
1079 	float Ratio,
1080 	uint32_t OperationSet
1081 );
1082 
1083 /* Requests the frequency ratio (fancy phrase for pitch) of this source.
1084  *
1085  * pRatio: Filled with the frequency ratio.
1086  */
1087 FAUDIOAPI void FAudioSourceVoice_GetFrequencyRatio(
1088 	FAudioSourceVoice *voice,
1089 	float *pRatio
1090 );
1091 
1092 /* Resets the core sample rate of this source.
1093  * You probably don't want this, it's more likely you want SetFrequencyRatio.
1094  * This is used to recycle voices without having to constantly reallocate them.
1095  * For example, if you have wavedata that's all float32 mono, but the sample
1096  * rates are different, you can take a source that was being used for a 48KHz
1097  * wave and call this so it can be used for a 44.1KHz wave.
1098  *
1099  * NewSourceSampleRate: The new sample rate for this source.
1100  *
1101  * Returns 0 on success.
1102  */
1103 FAUDIOAPI uint32_t FAudioSourceVoice_SetSourceSampleRate(
1104 	FAudioSourceVoice *voice,
1105 	uint32_t NewSourceSampleRate
1106 );
1107 
1108 /* FAudioMasteringVoice Interface */
1109 
1110 /* Requests the channel mask for the mastering voice.
1111  * This is typically used with F3DAudioInitialize, but you may find it
1112  * interesting if you want to see the user's basic speaker layout.
1113  *
1114  * pChannelMask: Filled with the channel mask.
1115  *
1116  * Returns 0 on success.
1117  */
1118 FAUDIOAPI uint32_t FAudioMasteringVoice_GetChannelMask(
1119 	FAudioMasteringVoice *voice,
1120 	uint32_t *pChannelMask
1121 );
1122 
1123 /* FAudioEngineCallback Interface */
1124 
1125 /* If something horrible happens, this will be called.
1126  *
1127  * Error: The error code that spawned this callback.
1128  */
1129 typedef void (FAUDIOCALL * OnCriticalErrorFunc)(
1130 	FAudioEngineCallback *callback,
1131 	uint32_t Error
1132 );
1133 
1134 /* This is called at the end of a processing update. */
1135 typedef void (FAUDIOCALL * OnProcessingPassEndFunc)(
1136 	FAudioEngineCallback *callback
1137 );
1138 
1139 /* This is called at the beginning of a processing update. */
1140 typedef void (FAUDIOCALL * OnProcessingPassStartFunc)(
1141 	FAudioEngineCallback *callback
1142 );
1143 
1144 struct FAudioEngineCallback
1145 {
1146 	OnCriticalErrorFunc OnCriticalError;
1147 	OnProcessingPassEndFunc OnProcessingPassEnd;
1148 	OnProcessingPassStartFunc OnProcessingPassStart;
1149 };
1150 
1151 /* FAudioVoiceCallback Interface */
1152 
1153 /* When a buffer is no longer in use, this is called.
1154  *
1155  * pBufferContext: The pContext for the FAudioBuffer in question.
1156  */
1157 typedef void (FAUDIOCALL * OnBufferEndFunc)(
1158 	FAudioVoiceCallback *callback,
1159 	void *pBufferContext
1160 );
1161 
1162 /* When a buffer is now being used, this is called.
1163  *
1164  * pBufferContext: The pContext for the FAudioBuffer in question.
1165  */
1166 typedef void (FAUDIOCALL * OnBufferStartFunc)(
1167 	FAudioVoiceCallback *callback,
1168 	void *pBufferContext
1169 );
1170 
1171 /* When a buffer completes a loop, this is called.
1172  *
1173  * pBufferContext: The pContext for the FAudioBuffer in question.
1174  */
1175 typedef void (FAUDIOCALL * OnLoopEndFunc)(
1176 	FAudioVoiceCallback *callback,
1177 	void *pBufferContext
1178 );
1179 
1180 /* When a buffer that has the END_OF_STREAM flag is finished, this is called. */
1181 typedef void (FAUDIOCALL * OnStreamEndFunc)(
1182 	FAudioVoiceCallback *callback
1183 );
1184 
1185 /* If something horrible happens to a voice, this is called.
1186  *
1187  * pBufferContext:	The pContext for the FAudioBuffer in question.
1188  * Error:		The error code that spawned this callback.
1189  */
1190 typedef void (FAUDIOCALL * OnVoiceErrorFunc)(
1191 	FAudioVoiceCallback *callback,
1192 	void *pBufferContext,
1193 	uint32_t Error
1194 );
1195 
1196 /* When this voice is done being processed, this is called. */
1197 typedef void (FAUDIOCALL * OnVoiceProcessingPassEndFunc)(
1198 	FAudioVoiceCallback *callback
1199 );
1200 
1201 /* When a voice is about to start being processed, this is called.
1202  *
1203  * BytesRequested:	The number of bytes needed from the application to
1204  *			complete a full update. For example, if we need 512
1205  *			frames for a whole update, and the voice is a float32
1206  *			stereo source, BytesRequired will be 4096.
1207  */
1208 typedef void (FAUDIOCALL * OnVoiceProcessingPassStartFunc)(
1209 	FAudioVoiceCallback *callback,
1210 	uint32_t BytesRequired
1211 );
1212 
1213 struct FAudioVoiceCallback
1214 {
1215 	OnBufferEndFunc OnBufferEnd;
1216 	OnBufferStartFunc OnBufferStart;
1217 	OnLoopEndFunc OnLoopEnd;
1218 	OnStreamEndFunc OnStreamEnd;
1219 	OnVoiceErrorFunc OnVoiceError;
1220 	OnVoiceProcessingPassEndFunc OnVoiceProcessingPassEnd;
1221 	OnVoiceProcessingPassStartFunc OnVoiceProcessingPassStart;
1222 };
1223 
1224 /* FAudio Custom Allocator API
1225  * See "extensions/CustomAllocatorEXT.txt" for more information.
1226  */
1227 
1228 typedef void* (FAUDIOCALL * FAudioMallocFunc)(size_t size);
1229 typedef void (FAUDIOCALL * FAudioFreeFunc)(void* ptr);
1230 typedef void* (FAUDIOCALL * FAudioReallocFunc)(void* ptr, size_t size);
1231 
1232 FAUDIOAPI uint32_t FAudioCreateWithCustomAllocatorEXT(
1233 	FAudio **ppFAudio,
1234 	uint32_t Flags,
1235 	FAudioProcessor XAudio2Processor,
1236 	FAudioMallocFunc customMalloc,
1237 	FAudioFreeFunc customFree,
1238 	FAudioReallocFunc customRealloc
1239 );
1240 FAUDIOAPI uint32_t FAudioCOMConstructWithCustomAllocatorEXT(
1241 	FAudio **ppFAudio,
1242 	uint8_t version,
1243 	FAudioMallocFunc customMalloc,
1244 	FAudioFreeFunc customFree,
1245 	FAudioReallocFunc customRealloc
1246 );
1247 
1248 /* FAudio Engine Procedure API
1249  * See "extensions/EngineProcedureEXT.txt" for more information.
1250  */
1251 typedef void (FAUDIOCALL *FAudioEngineCallEXT)(FAudio *audio, float *output);
1252 typedef void (FAUDIOCALL *FAudioEngineProcedureEXT)(FAudioEngineCallEXT defaultEngineProc, FAudio *audio, float *output, void *user);
1253 
1254 FAUDIOAPI void FAudio_SetEngineProcedureEXT(
1255 	FAudio *audio,
1256 	FAudioEngineProcedureEXT clientEngineProc,
1257 	void *user
1258 );
1259 
1260 
1261 /* FAudio I/O API */
1262 
1263 #define FAUDIO_SEEK_SET 0
1264 #define FAUDIO_SEEK_CUR 1
1265 #define FAUDIO_SEEK_END 2
1266 #define FAUDIO_EOF -1
1267 
1268 typedef size_t (FAUDIOCALL * FAudio_readfunc)(
1269 	void *data,
1270 	void *dst,
1271 	size_t size,
1272 	size_t count
1273 );
1274 typedef int64_t (FAUDIOCALL * FAudio_seekfunc)(
1275 	void *data,
1276 	int64_t offset,
1277 	int whence
1278 );
1279 typedef int (FAUDIOCALL * FAudio_closefunc)(
1280 	void *data
1281 );
1282 
1283 typedef struct FAudioIOStream
1284 {
1285 	void *data;
1286 	FAudio_readfunc read;
1287 	FAudio_seekfunc seek;
1288 	FAudio_closefunc close;
1289 	void *lock;
1290 } FAudioIOStream;
1291 
1292 FAUDIOAPI FAudioIOStream* FAudio_fopen(const char *path);
1293 FAUDIOAPI FAudioIOStream* FAudio_memopen(void *mem, int len);
1294 FAUDIOAPI uint8_t* FAudio_memptr(FAudioIOStream *io, size_t offset);
1295 FAUDIOAPI void FAudio_close(FAudioIOStream *io);
1296 
1297 #ifdef __cplusplus
1298 }
1299 #endif /* __cplusplus */
1300 
1301 #endif /* FAUDIO_H */
1302 
1303 /* vim: set noexpandtab shiftwidth=8 tabstop=8: */
1304