1 /*
2  * Copyright (c) 2017 Derelict Developers
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the names 'Derelict', 'DerelictFmod', nor the names of its contributors
17  *   may be used to endorse or promote products derived from this software
18  *   without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 module derelict.fmod.dsp;
33 
34 import derelict.util.system;
35 
36 import derelict.fmod.common;
37 import derelict.fmod.dsp_effects;
38 
39 align(1):
40 
41 struct FMOD_DSP_BUFFER_ARRAY
42 {
43 	int                numbuffers;              /* [r/w] number of buffers */
44 	int               *buffernumchannels;       /* [r/w] array of number of channels for each buffer */
45 	FMOD_CHANNELMASK  *bufferchannelmask;       /* [r/w] array of channel masks for each buffer */
46 	float            **buffers;                 /* [r/w] array of buffers */
47 	FMOD_SPEAKERMODE   speakermode;             /* [r/w] speaker mode for all buffers in the array */
48 }
49 
50 alias FMOD_DSP_PROCESS_OPERATION = int;
51 enum
52 {
53 	FMOD_DSP_PROCESS_PERFORM,                   /* Process the incoming audio in 'inbufferarray' and output to 'outbufferarray'. */
54 	FMOD_DSP_PROCESS_QUERY                      /* The DSP is being queried for the expected output format and whether it needs to process audio or should be bypassed.  The function should return FMOD_OK, or FMOD_ERR_DSP_DONTPROCESS or FMOD_ERR_DSP_SILENCE if audio can pass through unprocessed. See remarks for more.  If audio is to be processed, 'outbufferarray' must be filled with the expected output format, channel count and mask. */
55 }
56 
57 struct FMOD_COMPLEX
58 {
59 	float real_; /* Real component */
60 	float imag; /* Imaginary component */
61 }
62 
63 alias FMOD_DSP_PAN_SURROUND_FLAGS = int;
64 enum
65 {
66 	FMOD_DSP_PAN_SURROUND_DEFAULT = 0,
67 	FMOD_DSP_PAN_SURROUND_ROTATION_NOT_BIASED = 1,
68 	
69 	FMOD_DSP_PAN_SURROUND_FLAGS_FORCEINT = 65536     /* Makes sure this enum is signed 32bit. */
70 } 
71 
72 alias FMOD_DSP_CREATE_CALLBACK = FMOD_RESULT               function(FMOD_DSP_STATE *dsp_state);
73 alias FMOD_DSP_RELEASE_CALLBACK = FMOD_RESULT              function(FMOD_DSP_STATE *dsp_state);
74 alias FMOD_DSP_RESET_CALLBACK = FMOD_RESULT                function(FMOD_DSP_STATE *dsp_state);
75 alias FMOD_DSP_SETPOSITION_CALLBACK = FMOD_RESULT          function(FMOD_DSP_STATE *dsp_state, uint pos);
76 alias FMOD_DSP_READ_CALLBACK = FMOD_RESULT                 function(FMOD_DSP_STATE *dsp_state, float *inbuffer, float *outbuffer, uint length, int inchannels, int *outchannels);
77 alias FMOD_DSP_SHOULDIPROCESS_CALLBACK = FMOD_RESULT       function(FMOD_DSP_STATE *dsp_state, FMOD_BOOL inputsidle, uint length, FMOD_CHANNELMASK inmask, int inchannels, FMOD_SPEAKERMODE speakermode);
78 alias FMOD_DSP_PROCESS_CALLBACK = FMOD_RESULT              function(FMOD_DSP_STATE *dsp_state, uint length, const FMOD_DSP_BUFFER_ARRAY *inbufferarray, FMOD_DSP_BUFFER_ARRAY *outbufferarray, FMOD_BOOL inputsidle, FMOD_DSP_PROCESS_OPERATION op);
79 alias FMOD_DSP_SETPARAM_FLOAT_CALLBACK = FMOD_RESULT       function(FMOD_DSP_STATE *dsp_state, int index, float value);
80 alias FMOD_DSP_SETPARAM_INT_CALLBACK = FMOD_RESULT         function(FMOD_DSP_STATE *dsp_state, int index, int value);
81 alias FMOD_DSP_SETPARAM_BOOL_CALLBACK = FMOD_RESULT        function(FMOD_DSP_STATE *dsp_state, int index, FMOD_BOOL value);
82 alias FMOD_DSP_SETPARAM_DATA_CALLBACK = FMOD_RESULT        function(FMOD_DSP_STATE *dsp_state, int index, void *data, uint length);
83 alias FMOD_DSP_GETPARAM_FLOAT_CALLBACK = FMOD_RESULT       function(FMOD_DSP_STATE *dsp_state, int index, float *value, char *valuestr);
84 alias FMOD_DSP_GETPARAM_INT_CALLBACK = FMOD_RESULT         function(FMOD_DSP_STATE *dsp_state, int index, int *value, char *valuestr);
85 alias FMOD_DSP_GETPARAM_BOOL_CALLBACK = FMOD_RESULT        function(FMOD_DSP_STATE *dsp_state, int index, FMOD_BOOL *value, char *valuestr);
86 alias FMOD_DSP_GETPARAM_DATA_CALLBACK = FMOD_RESULT        function(FMOD_DSP_STATE *dsp_state, int index, void **data, uint *length, char *valuestr);
87 
88 alias FMOD_DSP_SYSTEM_REGISTER_CALLBACK = FMOD_RESULT		function(FMOD_DSP_STATE *dsp_state);
89 alias FMOD_DSP_SYSTEM_DEREGISTER_CALLBACK = FMOD_RESULT		function(FMOD_DSP_STATE *dsp_state);
90 alias FMOD_DSP_SYSTEM_MIX_CALLBACK = FMOD_RESULT			function(FMOD_DSP_STATE *dsp_state, int stage);
91 
92 alias FMOD_DSP_SYSTEM_GETSAMPLERATE = FMOD_RESULT          function(FMOD_DSP_STATE *dsp_state, int *rate);
93 alias FMOD_DSP_SYSTEM_GETBLOCKSIZE = FMOD_RESULT           function(FMOD_DSP_STATE *dsp_state, uint *blocksize);
94 alias FMOD_DSP_SYSTEM_GETSPEAKERMODE = FMOD_RESULT         function(FMOD_DSP_STATE *dsp_state, FMOD_SPEAKERMODE* speakermode_mixer, FMOD_SPEAKERMODE* speakermode_output);
95 
96 alias FMOD_DSP_ALLOC_FUNC = FMOD_RESULT                    function(uint size, FMOD_MEMORY_TYPE type, const(char) *sourcestr);
97 alias FMOD_DSP_REALLOC_FUNC = FMOD_RESULT                  function(void *ptr, uint size, FMOD_MEMORY_TYPE type, const(char) *sourcestr);
98 alias FMOD_DSP_FREE_FUNC = FMOD_RESULT                     function(void *ptr, FMOD_MEMORY_TYPE type, const(char) *sourcestr);
99 alias FMOD_DSP_LOG_FUNC = FMOD_RESULT                      function(FMOD_DEBUG_FLAGS level, const(char) *file, int line, const(char) *function_, const(char) *string, ...);
100 alias FMOD_DSP_GETSAMPLERATE_FUNC = FMOD_RESULT            function(FMOD_DSP_STATE *dsp_state, int *rate);
101 alias FMOD_DSP_GETBLOCKSIZE_FUNC = FMOD_RESULT             function(FMOD_DSP_STATE *dsp_state, uint *blocksize);
102 alias FMOD_DSP_GETSPEAKERMODE_FUNC = FMOD_RESULT           function(FMOD_DSP_STATE *dsp_state, FMOD_SPEAKERMODE *speakermode_mixer, FMOD_SPEAKERMODE *speakermode_output);
103 alias FMOD_DSP_GETCLOCK_FUNC = FMOD_RESULT                 function(FMOD_DSP_STATE *dsp_state, ulong *clock, uint *offset, uint *length);
104 alias FMOD_DSP_GETLISTENERATTRIBUTES_FUNC = FMOD_RESULT    function(FMOD_DSP_STATE *dsp_state, int *numlisteners, FMOD_3D_ATTRIBUTES *attributes);
105 alias FMOD_DSP_GETUSERDATA_FUNC = FMOD_RESULT              function(FMOD_DSP_STATE *dsp_state, void **userdata);
106 
107 alias FMOD_DSP_DFT_FFTREAL_FUNC = FMOD_RESULT                   function(FMOD_DSP_STATE* thisdsp, int size, const float *signal, FMOD_COMPLEX* dft, const float *window, int signalhop);
108 alias FMOD_DSP_DFT_IFFTREAL_FUNC = FMOD_RESULT                  function(FMOD_DSP_STATE* thisdsp, int size, const FMOD_COMPLEX *dft, float* signal, const float *window, int signalhop);
109 
110 alias FMOD_DSP_PAN_SUMMONOMATRIX_FUNC = FMOD_RESULT               function(FMOD_DSP_STATE *dsp_state, int sourceSpeakerMode, float lowFrequencyGain, float overallGain, float *matrix);
111 alias FMOD_DSP_PAN_SUMSTEREOMATRIX_FUNC = FMOD_RESULT             function(FMOD_DSP_STATE *dsp_state, int sourceSpeakerMode, float pan, float lowFrequencyGain, float overallGain, int matrixHop, float *matrix);
112 alias FMOD_DSP_PAN_SUMSURROUNDMATRIX_FUNC = FMOD_RESULT           function(FMOD_DSP_STATE *dsp_state, int sourceSpeakerMode, int targetSpeakerMode, float direction, float extent, float rotation, float lowFrequencyGain, float overallGain, int matrixHop, float *matrix, FMOD_DSP_PAN_SURROUND_FLAGS flags);
113 alias FMOD_DSP_PAN_SUMMONOTOSURROUNDMATRIX_FUNC = FMOD_RESULT   function(FMOD_DSP_STATE *dsp_state, int targetSpeakerMode, float direction, float extent, float lowFrequencyGain, float overallGain, int matrixHop, float *matrix);
114 alias FMOD_DSP_PAN_SUMSTEREOTOSURROUNDMATRIX_FUNC = FMOD_RESULT  function(FMOD_DSP_STATE *dsp_state, int targetSpeakerMode, float direction, float extent, float rotation, float lowFrequencyGain, float overallGain, int matrixHop, float *matrix);
115 alias FMOD_DSP_PAN_GETROLLOFFGAIN_FUNC = FMOD_RESULT           function(FMOD_DSP_STATE *dsp_state, FMOD_DSP_PAN_3D_ROLLOFF_TYPE rolloff, float distance, float mindistance, float maxdistance, float *gain);
116 alias FMOD_DSP_STATE_GETCLOCK_FUNC = FMOD_RESULT                    function(FMOD_DSP_STATE *dsp_state, ulong *clock, uint *offset, uint *length);
117 alias FMOD_DSP_STATE_GETLISTENERATTRIBUTES_FUNC = FMOD_RESULT function(FMOD_DSP_STATE *dsp_state, int *numlisteners, FMOD_3D_ATTRIBUTES *attributes);
118 
119 static immutable FMOD_DSP_GETPARAM_VALUESTR_LENGTH = 32;
120 
121 alias FMOD_DSP_PARAMETER_TYPE = int;
122 enum
123 {
124 	FMOD_DSP_PARAMETER_TYPE_FLOAT,
125 	FMOD_DSP_PARAMETER_TYPE_INT,
126 	FMOD_DSP_PARAMETER_TYPE_BOOL,
127 	FMOD_DSP_PARAMETER_TYPE_DATA,
128 	
129 	FMOD_DSP_PARAMETER_TYPE_MAX,                /* Maximum number of DSP parameter types. */
130 	FMOD_DSP_PARAMETER_TYPE_FORCEINT = 65536    /* Makes sure this enum is signed 32bit. */
131 }
132 
133 alias FMOD_DSP_PARAMETER_FLOAT_MAPPING_TYPE = int;
134 enum
135 {
136 	FMOD_DSP_PARAMETER_FLOAT_MAPPING_TYPE_LINEAR,               /* Values mapped linearly across range. */
137 	FMOD_DSP_PARAMETER_FLOAT_MAPPING_TYPE_AUTO,                 /* A mapping is automatically chosen based on range and units.  See remarks. */
138 	FMOD_DSP_PARAMETER_FLOAT_MAPPING_TYPE_PIECEWISE_LINEAR,     /* Values mapped in a piecewise linear fashion defined by FMOD_DSP_PARAMETER_FLOAT_MAPPING_PIECEWISE_LINEAR. */
139 	
140 	FMOD_DSP_PARAMETER_FLOAT_MAPPING_TYPE_FORCEINT = 65536      /* Makes sure this enum is signed 32bit. */
141 }
142 
143 struct FMOD_DSP_PARAMETER_FLOAT_MAPPING_PIECEWISE_LINEAR
144 {
145 	int numpoints;                              /* [w] The number of <position, value> pairs in the piecewise mapping (at least 2). */
146 	float *pointparamvalues;                    /* [w] The values in the parameter's units for each point */
147 	float *pointpositions;                      /* [w] The positions along the control's scale (e.g. dial angle) corresponding to each parameter value.  The range of this scale is arbitrary and all positions will be relative to the minimum and maximum values (e.g. [0,1,3] is equivalent to [1,2,4] and [2,4,8]).  If this array is zero, pointparamvalues will be distributed with equal spacing. */
148 }
149 
150 struct FMOD_DSP_PARAMETER_FLOAT_MAPPING
151 {
152 	FMOD_DSP_PARAMETER_FLOAT_MAPPING_TYPE type;
153 	FMOD_DSP_PARAMETER_FLOAT_MAPPING_PIECEWISE_LINEAR piecewiselinearmapping; /* [w] Only required for FMOD_DSP_PARAMETER_FLOAT_MAPPING_TYPE_PIECEWISE_LINEAR type mapping. */
154 }
155 
156 struct FMOD_DSP_PARAMETER_DESC_FLOAT
157 {
158 	float                     min;                      /* [w] Minimum parameter value. */
159 	float                     max;                      /* [w] Maximum parameter value. */
160 	float                     defaultval;               /* [w] Default parameter value. */
161 	FMOD_DSP_PARAMETER_FLOAT_MAPPING mapping;           /* [w] How the values are distributed across dials and automation curves (e.g. linearly, exponentially etc). */
162 }
163 
164 struct FMOD_DSP_PARAMETER_DESC_INT
165 {
166 	int                       min;                      /* [w] Minimum parameter value. */
167 	int                       max;                      /* [w] Maximum parameter value. */
168 	int                       defaultval;               /* [w] Default parameter value. */
169 	FMOD_BOOL                 goestoinf;                /* [w] Whether the last value represents infiniy. */
170 	const char**        valuenames;               /* [w] Names for each value.  There should be as many strings as there are possible values (max - min + 1).  Optional. */
171 }
172 
173 struct FMOD_DSP_PARAMETER_DESC_BOOL
174 {
175 	FMOD_BOOL                 defaultval;               /* [w] Default parameter value. */
176 	const char**        valuenames;               /* [w] Names for false and true, respectively.  There should be two strings.  Optional. */
177 }
178 
179 struct FMOD_DSP_PARAMETER_DESC_DATA
180 {
181 	int                       datatype;                 /* [w] The type of data for this parameter.  Use 0 or above for custom types or set to one of the FMOD_DSP_PARAMETER_DATA_TYPE values. */
182 }
183 
184 struct FMOD_DSP_PARAMETER_DESC
185 {
186 	FMOD_DSP_PARAMETER_TYPE   type;                 /* [w] Type of this parameter. */
187 	char[16]                      name;             /* [w] Name of the parameter to be displayed (ie "Cutoff frequency"). */
188 	char[16]                      label;            /* [w] Short string to be put next to value to denote the unit type (ie "hz"). */
189 	const char               *description;          /* [w] Description of the parameter to be displayed as a help item / tooltip for this parameter. */
190 	
191 	union
192 	{
193 		FMOD_DSP_PARAMETER_DESC_FLOAT   floatdesc;  /* [w] Struct containing information about the parameter in floating point format.  Use when type is FMOD_DSP_PARAMETER_TYPE_FLOAT. */
194 		FMOD_DSP_PARAMETER_DESC_INT     intdesc;    /* [w] Struct containing information about the parameter in integer format.  Use when type is FMOD_DSP_PARAMETER_TYPE_INT. */
195 		FMOD_DSP_PARAMETER_DESC_BOOL    booldesc;   /* [w] Struct containing information about the parameter in boolean format.  Use when type is FMOD_DSP_PARAMETER_TYPE_BOOL. */
196 		FMOD_DSP_PARAMETER_DESC_DATA    datadesc;   /* [w] Struct containing information about the parameter in data format.  Use when type is FMOD_DSP_PARAMETER_TYPE_DATA. */
197 	}
198 }
199 
200 alias FMOD_DSP_PARAMETER_DATA_TYPE = int;
201 enum
202 {
203 	FMOD_DSP_PARAMETER_DATA_TYPE_USER = 0,                  /* The default data type.  All user data types should be 0 or above. */
204 	FMOD_DSP_PARAMETER_DATA_TYPE_OVERALLGAIN = -1,          /* The data type for FMOD_DSP_PARAMETER_OVERALLGAIN parameters.  There should a maximum of one per DSP. */
205 	FMOD_DSP_PARAMETER_DATA_TYPE_3DATTRIBUTES = -2,         /* The data type for FMOD_DSP_PARAMETER_3DATTRIBUTES parameters.  There should a maximum of one per DSP. */
206 	FMOD_DSP_PARAMETER_DATA_TYPE_SIDECHAIN = -3,            /* The data type for FMOD_DSP_PARAMETER_SIDECHAIN parameters.  There should a maximum of one per DSP. */
207 	FMOD_DSP_PARAMETER_DATA_TYPE_FFT = -4,                  /* The data type for FMOD_DSP_PARAMETER_FFT parameters.  There should a maximum of one per DSP. */
208 	FMOD_DSP_PARAMETER_DATA_TYPE_3DATTRIBUTES_MULTI = -5,   /* The data type for FMOD_DSP_PARAMETER_3DATTRIBUTES_MULTI parameters.  There should a maximum of one per DSP. */
209 }
210 
211 struct FMOD_DSP_PARAMETER_OVERALLGAIN
212 {
213 	float linear_gain;                                  /* [r] The overall linear gain of the effect on the direct signal path */
214 	float linear_gain_additive;                         /* [r] Additive gain, for parallel signal paths */
215 }
216 
217 struct FMOD_DSP_PARAMETER_3DATTRIBUTES
218 {
219 	FMOD_3D_ATTRIBUTES relative;                        /* [w] The position of the sound relative to the listener. */
220 	FMOD_3D_ATTRIBUTES absolute;                        /* [w] The position of the sound in world coordinates. */
221 }
222 
223 struct FMOD_DSP_PARAMETER_3DATTRIBUTES_MULTI
224 {
225 	int                numlisteners;                    /* [w] The number of listeners. */
226 	FMOD_3D_ATTRIBUTES[FMOD_MAX_LISTENERS] relative;    /* [w] The position of the sound relative to the listeners. */
227 	float[FMOD_MAX_LISTENERS]              weight;      /* [w] The weighting of the listeners where 0 means listener has no contribution and 1 means full contribution. */
228 	FMOD_3D_ATTRIBUTES absolute;                        /* [w] The position of the sound in world coordinates. */
229 }
230 
231 struct FMOD_DSP_PARAMETER_SIDECHAIN
232 {
233 	FMOD_BOOL sidechainenable;                               /* [r/w] Whether sidechains are enabled. */
234 }
235 
236 struct FMOD_DSP_PARAMETER_FFT
237 {
238 	int     length;                                    /* [r] Number of entries in this spectrum window.   Divide this by the output rate to get the hz per entry. */
239 	int     numchannels;                               /* [r] Number of channels in spectrum. */
240 	float[32]  *spectrum;                              /* [r] Per channel spectrum arrays.  See remarks for more. */
241 }
242 
243 static immutable FMOD_PLUGIN_SDK_VERSION = 110;
244 
245 struct FMOD_DSP_DESCRIPTION
246 {
247 	uint                     pluginsdkversion;   /* [w] The plugin SDK version this plugin is built for.  set to this to FMOD_PLUGIN_SDK_VERSION defined above. */
248 	char[32]                             name;           /* [w] The identifier of the DSP. This will also be used as the name of DSP and shouldn't change between versions. */
249 	uint                     version_;            /* [w] Plugin writer's version number. */
250 	int                              numinputbuffers;    /* [w] Number of input buffers to process.  Use 0 for DSPs that only generate sound and 1 for effects that process incoming sound. */
251 	int                              numoutputbuffers;   /* [w] Number of audio output buffers.  Only one output buffer is currently supported. */
252 	FMOD_DSP_CREATE_CALLBACK         create;             /* [w] Create callback.  This is called when DSP unit is created.  Can be null. */
253 	FMOD_DSP_RELEASE_CALLBACK        release;            /* [w] Release callback.  This is called just before the unit is freed so the user can do any cleanup needed for the unit.  Can be null. */
254 	FMOD_DSP_RESET_CALLBACK          reset;              /* [w] Reset callback.  This is called by the user to reset any history buffers that may need resetting for a filter, when it is to be used or re-used for the first time to its initial clean state.  Use to avoid clicks or artifacts. */
255 	FMOD_DSP_READ_CALLBACK           read;               /* [w] Read callback.  Processing is done here.  Can be null. */
256 	FMOD_DSP_PROCESS_CALLBACK        process;            /* [w] Process callback.  Can be specified instead of the read callback if any channel format changes occur between input and output.  This also replaces shouldiprocess and should return an error if the effect is to be bypassed.  Can be null. */
257 	FMOD_DSP_SETPOSITION_CALLBACK    setposition;        /* [w] Set position callback.  This is called if the unit wants to update its position info but not process data, or reset a cursor position internally if it is reading data from a certain source.  Can be null. */
258 	
259 	int                              numparameters;      /* [w] Number of parameters used in this filter.  The user finds this with DSP::getNumParameters */
260 	FMOD_DSP_PARAMETER_DESC        **paramdesc;          /* [w] Variable number of parameter structures. */
261 	FMOD_DSP_SETPARAM_FLOAT_CALLBACK setparameterfloat;  /* [w] This is called when the user calls DSP::setParameterFloat. Can be null. */
262 	FMOD_DSP_SETPARAM_INT_CALLBACK   setparameterint;    /* [w] This is called when the user calls DSP::setParameterInt.   Can be null. */
263 	FMOD_DSP_SETPARAM_BOOL_CALLBACK  setparameterbool;   /* [w] This is called when the user calls DSP::setParameterBool.  Can be null. */
264 	FMOD_DSP_SETPARAM_DATA_CALLBACK  setparameterdata;   /* [w] This is called when the user calls DSP::setParameterData.  Can be null. */
265 	FMOD_DSP_GETPARAM_FLOAT_CALLBACK getparameterfloat;  /* [w] This is called when the user calls DSP::getParameterFloat. Can be null. */
266 	FMOD_DSP_GETPARAM_INT_CALLBACK   getparameterint;    /* [w] This is called when the user calls DSP::getParameterInt.   Can be null. */
267 	FMOD_DSP_GETPARAM_BOOL_CALLBACK  getparameterbool;   /* [w] This is called when the user calls DSP::getParameterBool.  Can be null. */
268 	FMOD_DSP_GETPARAM_DATA_CALLBACK  getparameterdata;   /* [w] This is called when the user calls DSP::getParameterData.  Can be null. */
269 	FMOD_DSP_SHOULDIPROCESS_CALLBACK shouldiprocess;     /* [w] This is called before processing.  You can detect if inputs are idle and return FMOD_OK to process, or any other error code to avoid processing the effect.  Use a count down timer to allow effect tails to process before idling! */
270 	void                            *userdata;           /* [w] Optional. Specify 0 to ignore. This is user data to be attached to the DSP unit during creation.  Access via DSP::getUserData. */
271 
272 	FMOD_DSP_SYSTEM_REGISTER_CALLBACK   sys_register;       /* [w] Register callback.  This is called when DSP unit is loaded/registered.  Useful for 'global'/per system object init for plugin.  Can be null. */
273 	FMOD_DSP_SYSTEM_DEREGISTER_CALLBACK sys_deregister;     /* [w] Deregister callback.  This is called when DSP unit is unloaded/deregistered.  Useful as 'global'/per system object shutdown for plugin.  Can be null. */
274 	FMOD_DSP_SYSTEM_MIX_CALLBACK        sys_mix;            /* [w] System mix stage callback.  This is called when the mixer starts to execute or is just finishing executing.  Useful for 'global'/per system object once a mix update calls for a plugin.  Can be null. */
275 }
276 
277 struct FMOD_DSP_STATE_DFT_FUNCTIONS
278 {
279 	FMOD_DSP_DFT_FFTREAL_FUNC  fftreal;        /* [r] Function for performing an FFT on a real signal. */
280 	FMOD_DSP_DFT_IFFTREAL_FUNC inversefftreal; /* [r] Function for performing an inverse FFT to get a real signal. */
281 }
282 
283 struct FMOD_DSP_STATE_PAN_FUNCTIONS
284 {
285 	FMOD_DSP_PAN_SUMMONOMATRIX_FUNC             summonomatrix;             /* [r] TBD. */
286 	FMOD_DSP_PAN_SUMSTEREOMATRIX_FUNC           sumstereomatrix;           /* [r] TBD. */
287 	FMOD_DSP_PAN_SUMSURROUNDMATRIX_FUNC         sumsurroundmatrix;         /* [r] TBD. */
288 	FMOD_DSP_PAN_SUMMONOTOSURROUNDMATRIX_FUNC   summonotosurroundmatrix;   /* [r] TBD. */
289 	FMOD_DSP_PAN_SUMSTEREOTOSURROUNDMATRIX_FUNC sumstereotosurroundmatrix; /* [r] TBD. */
290 	FMOD_DSP_PAN_GETROLLOFFGAIN_FUNC            getrolloffgain;            /* [r] TBD. */
291 }
292 
293 struct FMOD_DSP_STATE_FUNCTIONS
294 {
295 	FMOD_DSP_ALLOC_FUNC                 alloc;                  /* [r] Function to allocate memory using the FMOD memory system. */
296 	FMOD_DSP_REALLOC_FUNC               realloc;                /* [r] Function to reallocate memory using the FMOD memory system. */
297 	FMOD_DSP_FREE_FUNC                  free;                   /* [r] Function to free memory allocated with FMOD_DSP_ALLOC_FUNC. */
298 	FMOD_DSP_GETSAMPLERATE_FUNC         getsamplerate;          /* [r] Function to query the system sample rate. */
299 	FMOD_DSP_GETBLOCKSIZE_FUNC          getblocksize;           /* [r] Function to query the system block size, DSPs will be requested to process blocks of varying length up to this size. */
300 	FMOD_DSP_STATE_DFT_FUNCTIONS       *dft;                    /* [r] Struct containing DFT functions to enable a plugin to perform optimized time-frequency domain conversion. */
301 	FMOD_DSP_STATE_PAN_FUNCTIONS       *pan;                    /* [r] Struct containing panning helper functions for spatialization plugins. */
302 	FMOD_DSP_GETSPEAKERMODE_FUNC        getspeakermode;         /* [r] Function to query the system speaker modes.  One is the mixer's default speaker mode, the other is the output mode the system is downmixing or upmixing to.*/
303 	FMOD_DSP_GETCLOCK_FUNC              getclock;               /* [r] Function to get the clock of the current DSP, as well as the subset of the input buffer that contains the signal. */
304 	FMOD_DSP_GETLISTENERATTRIBUTES_FUNC getlistenerattributes;  /* [r] Callback for getting the absolute listener attributes set via the API (returned as left-handed co-ordinates). */
305 	FMOD_DSP_LOG_FUNC                   log;                    /* [r] Function to write to the FMOD logging system. */
306 	FMOD_DSP_GETUSERDATA_FUNC           getuserdata;            /* [r] Function to get the user data attached to this DSP. See FMOD_DSP_DESCRIPTION::userdata. */
307 }
308 
309 struct FMOD_DSP_STATE
310 {
311 	FMOD_DSP                       *instance;            /* [r] Handle to the FMOD_DSP object the callback is associated with.  Not to be modified.  C++ users cast to FMOD::DSP to use.  */
312 	void                           *plugindata;          /* [r/w] Plugin writer created data the output author wants to attach to this object. */
313 	FMOD_CHANNELMASK                channelmask;         /* [r] Specifies which speakers the DSP effect is active on */
314 	FMOD_SPEAKERMODE                source_speakermode;  /* [r] Specifies which speaker mode the signal originated for information purposes, ie in case panning needs to be done differently. */
315 	float                          *sidechaindata;       /* [r] The mixed result of all incoming sidechains is stored at this pointer address. */
316 	int                             sidechainchannels;   /* [r] The number of channels of pcm data stored within the sidechain buffer. */
317 	FMOD_DSP_STATE_FUNCTIONS        *functions;           /* [r] Struct containing callbacks for system level functionality. */
318 	int                             systemobject;        /* [r] FMOD::System object index, relating to the System object that created this DSP. */
319 }
320 
321 /+
322 static immutable FMOD_DSP_STATE_MEMALLOC(_state, _size, _type, _str)                        (_state)->callbacks->alloc         (_size, _type, _str);                                     /* Pass in the FMOD_DSP_STATE handle, size in bytes to alloc, FMOD_MEMORY_TYPE type and optional char * string to identify where the alloc came from. */
323 static immutable FMOD_DSP_STATE_MEMREALLOC(_state, _ptr, _size, _type, _str)                (_state)->callbacks->realloc       (_ptr, _size, _type, _str);                               /* Pass in the FMOD_DSP_STATE handle, optional existing memory pointer, size in bytes to alloc, FMOD_MEMORY_TYPE type and optional char * string to identify where the alloc came from. */
324 static immutable FMOD_DSP_STATE_MEMFREE(_state, _ptr, _type, _str)                          (_state)->callbacks->free          (_ptr, _type, _str);                                      /* Pass in the FMOD_DSP_STATE handle, existing memory pointer, FMOD_MEMORY_TYPE type and optional char * string to identify where the free came from. */
325 static immutable FMOD_DSP_STATE_GETSAMPLERATE(_state, _rate)                                (_state)->callbacks->getsamplerate (_state, _rate);                                          /* Pass in the FMOD_DSP_STATE handle, and the address of an int to receive the system DSP sample rate. */
326 static immutable FMOD_DSP_STATE_GETBLOCKSIZE(_state, _blocksize)                            (_state)->callbacks->getblocksize  (_state, _blocksize);                                     /* Pass in the FMOD_DSP_STATE handle, and the address of an unsigned int to receive the system DSP block size. */
327 static immutable FMOD_DSP_STATE_FFTREAL(_state, _size, _signal, _dft, _window, _signalhop)  (_state)->callbacks->dft->fftreal  (_state, _size, _signal, _dft, _window, _signalhop);      /* Pass in the FMOD_DSP_STATE handle, size of the signal and its DFT, a float buffer containing the signal and an FMOD_COMPLEX buffer to store the calculated DFT. */
328 static immutable FMOD_DSP_STATE_IFFTREAL(_state, _size, _dft, _signal, _window, _signalhop) (_state)->callbacks->dft->inversefftreal(_state, _size, _dft, _signal, _window, _signalhop); /* Pass in the FMOD_DSP_STATE handle, size of the DFT and its signal, an FMOD_COMPLEX buffer containing the DFT and a float buffer to store the calculated signal. */
329 +/
330 
331 struct FMOD_DSP_METERING_INFO
332 {
333 	int   numsamples;       /* [r] The number of samples considered for this metering info. */
334 	float[32] peaklevel;    /* [r] The peak level per channel. */
335 	float[32] rmslevel;     /* [r] The rms level per channel. */
336 	short numchannels;      /* [r] Number of channels. */
337 }