1 /************************** BEGIN AudioPluginInterface.h **************************/ 2 /************************************************************************ 3 FAUST Architecture File 4 Copyright (C) 2003-2017 GRAME, Centre National de Creation Musicale 5 --------------------------------------------------------------------- 6 This Architecture section is free software; you can redistribute it 7 and/or modify it under the terms of the GNU General Public License 8 as published by the Free Software Foundation; either version 3 of 9 the License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; If not, see <http://www.gnu.org/licenses/>. 18 19 EXCEPTION : As a special exception, you may create a larger work 20 that contains this FAUST architecture section and distribute 21 that work under terms of your choice, so long as this FAUST 22 architecture section is not modified. 23 ************************************************************************/ 24 25 #ifndef __UNITYAUDIOPLUGININTERFACE__ 26 #define __UNITYAUDIOPLUGININTERFACE__ 27 28 #define UNITY_AUDIO_PLUGIN_API_VERSION 0x010300 29 30 #ifndef UNITY_PREFIX_CONFIGURE_H 31 32 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) 33 # define UNITY_WIN 1 34 #elif defined(__MACH__) || defined(__APPLE__) 35 # define UNITY_OSX 1 36 #elif defined(__ANDROID__) 37 # define UNITY_ANDROID 1 38 #elif defined(__linux__) 39 # define UNITY_LINUX 1 40 #elif defined(__PS3__) 41 # define UNITY_PS3 1 42 #elif defined(__SPU__) 43 # define UNITY_SPU 1 44 #endif 45 46 #if defined(_AMD64_) || defined(__LP64__) 47 # define UNITY_64 1 48 # define UNITY_32 0 49 #else 50 # define UNITY_64 0 51 # define UNITY_32 1 52 #endif 53 54 #ifndef SInt16_defined 55 # define SInt16_defined 56 typedef signed short SInt16; 57 #endif 58 59 #ifndef UInt16_defined 60 # define UInt16_defined 61 typedef unsigned short UInt16; 62 #endif 63 64 #ifndef UInt8_defined 65 # define UInt8_defined 66 typedef unsigned char UInt8; 67 #endif 68 69 #ifndef SInt8_defined 70 # define SInt8_defined 71 typedef signed char SInt8; 72 #endif 73 74 #if UNITY_64 75 # if UNITY_LINUX 76 # ifndef SInt32_defined 77 # define SInt32_defined 78 typedef signed int SInt32; 79 # endif 80 # ifndef UInt32_defined 81 # define UInt32_defined 82 typedef unsigned int UInt32; 83 # endif 84 # ifndef UInt64_defined 85 # define UInt64_defined 86 typedef unsigned long UInt64; 87 # endif 88 # ifndef SInt64_defined 89 # define SInt64_defined 90 typedef signed long SInt64; 91 # endif 92 # elif UNITY_OSX 93 # ifndef SInt32_defined 94 # define SInt32_defined 95 typedef signed int SInt32; 96 # endif 97 # ifndef UInt32_defined 98 # define UInt32_defined 99 typedef unsigned int UInt32; 100 # endif 101 # ifndef UInt64_defined 102 # define UInt64_defined 103 typedef unsigned long long UInt64; 104 # endif 105 # ifndef SInt64_defined 106 # define SInt64_defined 107 typedef signed long long SInt64; 108 # endif 109 # elif UNITY_WIN 110 # ifndef SInt32_defined 111 # define SInt32_defined 112 typedef signed long SInt32; 113 # endif 114 # ifndef UInt32_defined 115 # define UInt32_defined 116 typedef unsigned long UInt32; 117 # endif 118 # ifndef UInt64_defined 119 # define UInt64_defined 120 typedef unsigned long long UInt64; 121 # endif 122 # ifndef SInt64_defined 123 # define SInt64_defined 124 typedef signed long long SInt64; 125 # endif 126 #endif 127 #else 128 # ifndef SInt32_defined 129 # define SInt32_defined 130 typedef signed int SInt32; 131 # endif 132 # ifndef UInt32_defined 133 # define UInt32_defined 134 typedef unsigned int UInt32; 135 # endif 136 # ifndef UInt64_defined 137 # define UInt64_defined 138 typedef unsigned long long UInt64; 139 # endif 140 # ifndef SInt64_defined 141 # define SInt64_defined 142 typedef signed long long SInt64; 143 # endif 144 #endif 145 146 #endif 147 148 #if UNITY_WIN 149 #define UNITY_AUDIODSP_CALLBACK __stdcall 150 #elif UNITY_OSX 151 #define UNITY_AUDIODSP_CALLBACK 152 #else 153 #define UNITY_AUDIODSP_CALLBACK 154 #endif 155 156 // Attribute to make function be exported from a plugin 157 #if UNITY_WIN 158 #define UNITY_AUDIODSP_EXPORT_API __declspec(dllexport) 159 #else 160 #define UNITY_AUDIODSP_EXPORT_API 161 #endif 162 163 #if defined(__CYGWIN32__) 164 #define UNITY_AUDIODSP_CALLBACK __stdcall 165 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) 166 #define UNITY_AUDIODSP_CALLBACK __stdcall 167 #elif defined(__MACH__) || defined(__ANDROID__) || defined(__linux__) || defined(__QNX__) 168 #define UNITY_AUDIODSP_CALLBACK 169 #else 170 #define UNITY_AUDIODSP_CALLBACK 171 #endif 172 173 #define UNITY_AUDIODSP_RESULT int 174 175 #if !UNITY_SPU // asserts require _exit() to be defined 176 #include <assert.h> 177 #endif 178 179 enum 180 { 181 UNITY_AUDIODSP_OK = 0, 182 UNITY_AUDIODSP_ERR_UNSUPPORTED = 1, 183 }; 184 185 struct UnityAudioEffectState; 186 187 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_CreateCallback)(UnityAudioEffectState* state); 188 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_ReleaseCallback)(UnityAudioEffectState* state); 189 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_ResetCallback)(UnityAudioEffectState* state); 190 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_ProcessCallback)(UnityAudioEffectState* state, float* inbuffer, float* outbuffer, unsigned int length, int inchannels, int outchannels); 191 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_SetPositionCallback)(UnityAudioEffectState* state, unsigned int pos); 192 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_SetFloatParameterCallback)(UnityAudioEffectState* state, int index, float value); 193 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_GetFloatParameterCallback)(UnityAudioEffectState* state, int index, float* value, char *valuestr); 194 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_GetFloatBufferCallback)(UnityAudioEffectState* state, const char* name, float* buffer, int numsamples); 195 196 enum UnityAudioEffectDefinitionFlags 197 { 198 UnityAudioEffectDefinitionFlags_IsSideChainTarget = 1 << 0, // Does this effect need a side chain buffer and can it be targeted by a Send? 199 UnityAudioEffectDefinitionFlags_IsSpatializer = 2 << 0, // Should this plugin be inserted at sources and take over panning? 200 }; 201 202 enum UnityAudioEffectStateFlags 203 { 204 UnityAudioEffectStateFlags_IsPlaying = 1 << 0, // Set when engine is in play mode. Also true while paused. 205 UnityAudioEffectStateFlags_IsPaused = 1 << 1, // Set when engine is paused mode. 206 UnityAudioEffectStateFlags_IsMuted = 1 << 2, // Set when effect is being muted (only available in the editor) 207 UnityAudioEffectStateFlags_IsSideChainTarget = 1 << 3, // Does this effect need a side chain buffer and can it be targeted by a Send? 208 }; 209 210 // This callback can be used to override the way distance attenuation is performed on AudioSources. 211 // distanceIn is the distance between the source and the listener and attenuationOut is the output volume. 212 // attenuationIn is the volume-curve based attenuation that would have been applied by Unity if this callback were not set. 213 // A typical attenuation curve may look like this: *attenuationOut = 1.0f / max(1.0f, distanceIn); 214 // The callback may also be used to apply a secondary gain on top of the one through attenuationIn by Unity's AudioSource curve. 215 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_DistanceAttenuationCallback)(UnityAudioEffectState* state, float distanceIn, float attenuationIn, float* attenuationOut); 216 217 struct UnityAudioSpatializerData 218 { 219 float listenermatrix[16]; // Matrix that transforms sourcepos into the local space of the listener 220 float sourcematrix[16]; // Transform matrix of audio source 221 float spatialblend; // Distance-controlled spatial blend 222 float reverbzonemix; // Reverb zone mix level parameter (and curve) on audio source 223 float spread; // Spread parameter of the audio source (0..360 degrees) 224 float stereopan; // Stereo panning parameter of the audio source (-1 = fully left, 1 = fully right) 225 UnityAudioEffect_DistanceAttenuationCallback distanceattenuationcallback; // The spatializer plugin may override the distance attenuation in order to influence the voice prioritization (leave this callback as NULL to use the built-in audio source attenuation curve) 226 }; 227 228 struct UnityAudioEffectState 229 { 230 union 231 { 232 struct 233 { 234 UInt32 structsize; // Size of this struct 235 UInt32 samplerate; // System sample rate 236 UInt64 currdsptick; // Pointer to a sample counter marking the start of the current block being processed 237 UInt64 prevdsptick; // Used for determining when DSPs are bypassed and so sidechain info becomes invalid 238 float* sidechainbuffer; // Side-chain buffers to read from 239 void* effectdata; // Internal data for the effect 240 UInt32 flags; // Various flags through which information can be queried from the host 241 void* internal; // Internal data, do not touch! 242 243 // Version 1.0 of the plugin API only contains data up to here, so perform a state->structsize >= sizeof(UnityAudioEffectState) in your code before you 244 // access any of this data in order to detect whether the host API is older than the plugin. 245 246 UnityAudioSpatializerData* spatializerdata; // Data for spatializers 247 UInt32 dspbuffersize; // Number of frames being processed per process callback. Use this to allocate temporary buffers before processing starts. 248 UInt32 hostapiversion; // Version of plugin API used by host 249 }; 250 unsigned char pad[80]; // This entire structure must be a multiple of 16 bytes (and and instance 16 byte aligned) for PS3 SPU DMA requirements 251 }; 252 #ifdef __cplusplus GetEffectDataUnityAudioEffectState253 template<typename T> inline T* GetEffectData() const 254 { 255 #if !UNITY_SPU // asserts require _exit() to be defined 256 assert(effectdata); 257 assert(internal); 258 #endif 259 return (T*)effectdata; 260 } 261 262 #endif 263 }; 264 265 struct UnityAudioParameterDefinition 266 { 267 char name[16]; // Display name on the GUI 268 char unit[16]; // Scientific unit of parameter to be appended after the value in textboxes 269 const char* description; // Description of parameter (displayed in tool tips, automatically generated documentation, etc.) 270 float min; // Minimum value of the parameter 271 float max; // Maximum value of the parameter 272 float defaultval; // Default and initial value of the parameter 273 float displayscale; // Scale factor used only for the display of parameters (i.e. 100 for a percentage value ranging from 0 to 1) 274 float displayexponent; // Exponent for mapping parameters to sliders 275 }; 276 277 struct UnityAudioEffectDefinition 278 { 279 UInt32 structsize; // Size of this struct 280 UInt32 paramstructsize; // Size of paramdesc fields 281 UInt32 apiversion; // Plugin API version 282 UInt32 pluginversion; // Version of this plugin 283 UInt32 channels; // Number of channels. Effects should set this to 0 and process any number of input/output channels they get in the process callback. Generator elements should specify a >0 value here. 284 UInt32 numparameters; // The number of parameters exposed by this plugin. 285 UInt64 flags; // Various capabilities and requirements of the plugin. 286 char name[32]; // Name used for registration of the effect. This name will also be displayed in the GUI. 287 UnityAudioEffect_CreateCallback create; // The create callback is called when DSP unit is created and can be null. 288 UnityAudioEffect_ReleaseCallback release; // The release callback is called just before the plugin is freed and should free any data associated with this specific instance of the plugin. No further callbacks related to the instance will happen after this function has been called. 289 UnityAudioEffect_ResetCallback reset; // The reset callback is called by the user to bring back the plugin instance into its initial state. Use to avoid clicks or artifacts. 290 UnityAudioEffect_ProcessCallback process; // The processing callback is repeatedly called with a block of input audio to read from and an output block to write to. 291 UnityAudioEffect_SetPositionCallback setposition; // The position callback can be used for implementing seek operations. 292 UnityAudioParameterDefinition* paramdefs; // A pointer to the definitions of the parameters exposed by this plugin. This data pointed to must remain valid for the whole lifetime of the dynamic library (ideally it's static). 293 UnityAudioEffect_SetFloatParameterCallback setfloatparameter; // This is called whenever one of the exposed parameters is changed. 294 UnityAudioEffect_GetFloatParameterCallback getfloatparameter; // This is called to query parameter values. 295 UnityAudioEffect_GetFloatBufferCallback getfloatbuffer; // Get N samples of named buffer. Used for displaying analysis data from the runtime. 296 }; 297 298 // This function fills in N pointers for the N effects contained in the library and returns N. 299 extern "C" UNITY_AUDIODSP_EXPORT_API int UnityGetAudioEffectDefinitions(UnityAudioEffectDefinition*** descptr); 300 #endif 301 /************************** END AudioPluginInterface.h **************************/ 302