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 /* This file has no documentation since the MSDN docs are still perfectly fine:
28  * https://docs.microsoft.com/en-us/windows/desktop/api/xapo/
29  *
30  * Of course, the APIs aren't exactly the same since XAPO is super dependent on
31  * C++. Instead, we use a struct full of functions to mimic a vtable.
32  *
33  * The only serious difference is that our FAPO (yes, really) always has the
34  * Get/SetParameters function pointers, for simplicity. You can ignore these if
35  * your effect does not have parameters, as they will never get called unless
36  * it is explicitly requested by the application.
37  */
38 
39 #ifndef FAPO_H
40 #define FAPO_H
41 
42 #include "FAudio.h"
43 
44 #define FAPOAPI FAUDIOAPI
45 #define FAPOCALL FAUDIOCALL
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif /* __cplusplus */
50 
51 /* Enumerations */
52 
53 typedef enum FAPOBufferFlags
54 {
55 	FAPO_BUFFER_SILENT,
56 	FAPO_BUFFER_VALID
57 } FAPOBufferFlags;
58 
59 /* Structures */
60 
61 #pragma pack(push, 1)
62 
63 typedef struct FAPORegistrationProperties
64 {
65 	FAudioGUID clsid;
66 	int16_t FriendlyName[256]; /* Win32 wchar_t */
67 	int16_t CopyrightInfo[256]; /* Win32 wchar_t */
68 	uint32_t MajorVersion;
69 	uint32_t MinorVersion;
70 	uint32_t Flags;
71 	uint32_t MinInputBufferCount;
72 	uint32_t MaxInputBufferCount;
73 	uint32_t MinOutputBufferCount;
74 	uint32_t MaxOutputBufferCount;
75 } FAPORegistrationProperties;
76 
77 typedef struct FAPOLockForProcessBufferParameters
78 {
79 	const FAudioWaveFormatEx *pFormat;
80 	uint32_t MaxFrameCount;
81 } FAPOLockForProcessBufferParameters;
82 
83 typedef struct FAPOProcessBufferParameters
84 {
85 	void* pBuffer;
86 	FAPOBufferFlags BufferFlags;
87 	uint32_t ValidFrameCount;
88 } FAPOProcessBufferParameters;
89 
90 #pragma pack(pop)
91 
92 /* Constants */
93 
94 #define FAPO_MIN_CHANNELS 1
95 #define FAPO_MAX_CHANNELS 64
96 
97 #define FAPO_MIN_FRAMERATE 1000
98 #define FAPO_MAX_FRAMERATE 200000
99 
100 #define FAPO_REGISTRATION_STRING_LENGTH 256
101 
102 #define FAPO_FLAG_CHANNELS_MUST_MATCH		0x00000001
103 #define FAPO_FLAG_FRAMERATE_MUST_MATCH		0x00000002
104 #define FAPO_FLAG_BITSPERSAMPLE_MUST_MATCH	0x00000004
105 #define FAPO_FLAG_BUFFERCOUNT_MUST_MATCH	0x00000008
106 #define FAPO_FLAG_INPLACE_REQUIRED		0x00000020
107 #define FAPO_FLAG_INPLACE_SUPPORTED		0x00000010
108 
109 /* FAPO Interface */
110 
111 #ifndef FAPO_DECL
112 #define FAPO_DECL
113 typedef struct FAPO FAPO;
114 #endif /* FAPO_DECL */
115 
116 typedef int32_t (FAPOCALL * AddRefFunc)(
117 	void *fapo
118 );
119 typedef int32_t (FAPOCALL * ReleaseFunc)(
120 	void *fapo
121 );
122 typedef uint32_t (FAPOCALL * GetRegistrationPropertiesFunc)(
123 	void* fapo,
124 	FAPORegistrationProperties **ppRegistrationProperties
125 );
126 typedef uint32_t (FAPOCALL * IsInputFormatSupportedFunc)(
127 	void* fapo,
128 	const FAudioWaveFormatEx *pOutputFormat,
129 	const FAudioWaveFormatEx *pRequestedInputFormat,
130 	FAudioWaveFormatEx **ppSupportedInputFormat
131 );
132 typedef uint32_t (FAPOCALL * IsOutputFormatSupportedFunc)(
133 	void* fapo,
134 	const FAudioWaveFormatEx *pInputFormat,
135 	const FAudioWaveFormatEx *pRequestedOutputFormat,
136 	FAudioWaveFormatEx **ppSupportedOutputFormat
137 );
138 typedef uint32_t (FAPOCALL * InitializeFunc)(
139 	void* fapo,
140 	const void* pData,
141 	uint32_t DataByteSize
142 );
143 typedef void (FAPOCALL * ResetFunc)(
144 	void* fapo
145 );
146 typedef uint32_t (FAPOCALL * LockForProcessFunc)(
147 	void* fapo,
148 	uint32_t InputLockedParameterCount,
149 	const FAPOLockForProcessBufferParameters *pInputLockedParameters,
150 	uint32_t OutputLockedParameterCount,
151 	const FAPOLockForProcessBufferParameters *pOutputLockedParameters
152 );
153 typedef void (FAPOCALL * UnlockForProcessFunc)(
154 	void* fapo
155 );
156 typedef void (FAPOCALL * ProcessFunc)(
157 	void* fapo,
158 	uint32_t InputProcessParameterCount,
159 	const FAPOProcessBufferParameters* pInputProcessParameters,
160 	uint32_t OutputProcessParameterCount,
161 	FAPOProcessBufferParameters* pOutputProcessParameters,
162 	int32_t IsEnabled
163 );
164 typedef uint32_t (FAPOCALL * CalcInputFramesFunc)(
165 	void* fapo,
166 	uint32_t OutputFrameCount
167 );
168 typedef uint32_t (FAPOCALL * CalcOutputFramesFunc)(
169 	void* fapo,
170 	uint32_t InputFrameCount
171 );
172 typedef void (FAPOCALL * SetParametersFunc)(
173 	void* fapo,
174 	const void* pParameters,
175 	uint32_t ParameterByteSize
176 );
177 typedef void (FAPOCALL * GetParametersFunc)(
178 	void* fapo,
179 	void* pParameters,
180 	uint32_t ParameterByteSize
181 );
182 
183 struct FAPO
184 {
185 	AddRefFunc AddRef;
186 	ReleaseFunc Release;
187 	GetRegistrationPropertiesFunc GetRegistrationProperties;
188 	IsInputFormatSupportedFunc IsInputFormatSupported;
189 	IsOutputFormatSupportedFunc IsOutputFormatSupported;
190 	InitializeFunc Initialize;
191 	ResetFunc Reset;
192 	LockForProcessFunc LockForProcess;
193 	UnlockForProcessFunc UnlockForProcess;
194 	ProcessFunc Process;
195 	CalcInputFramesFunc CalcInputFrames;
196 	CalcOutputFramesFunc CalcOutputFrames;
197 	SetParametersFunc SetParameters;
198 	GetParametersFunc GetParameters;
199 };
200 
201 #ifdef __cplusplus
202 }
203 #endif /* __cplusplus */
204 
205 #endif /* FAPO_H */
206 
207 /* vim: set noexpandtab shiftwidth=8 tabstop=8: */
208