1 #pragma once
2 
3 #define UNITY_AUDIO_PLUGIN_API_VERSION 0x010300
4 
5 #ifndef UNITY_PREFIX_CONFIGURE_H
6 
7 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64)
8 #   define UNITY_WIN 1
9 #elif defined(__MACH__) || defined(__APPLE__)
10 #   define UNITY_OSX 1
11 #elif defined(__ANDROID__)
12 #   define UNITY_ANDROID 1
13 #elif defined(__linux__)
14 #   define UNITY_LINUX 1
15 #elif defined(__PS3__)
16 #   define UNITY_PS3 1
17 #elif defined(__SPU__)
18 #   define UNITY_SPU 1
19 #endif
20 
21 #if defined(_AMD64_) || defined(__LP64__)
22 #   define UNITY_64 1
23 #   define UNITY_32 0
24 #else
25 #   define UNITY_64 0
26 #   define UNITY_32 1
27 #endif
28 
29 #ifndef SInt16_defined
30 #   define SInt16_defined
31 typedef signed short SInt16;
32 #endif
33 
34 #ifndef UInt16_defined
35 #   define UInt16_defined
36 typedef unsigned short UInt16;
37 #endif
38 
39 #ifndef UInt8_defined
40 #   define UInt8_defined
41 typedef unsigned char UInt8;
42 #endif
43 
44 #ifndef SInt8_defined
45 #   define SInt8_defined
46 typedef signed char SInt8;
47 #endif
48 
49 #if UNITY_64
50 #   if UNITY_LINUX
51 #       ifndef SInt32_defined
52 #           define SInt32_defined
53 typedef signed int SInt32;
54 #       endif
55 #       ifndef UInt32_defined
56 #           define UInt32_defined
57 typedef unsigned int UInt32;
58 #       endif
59 #       ifndef UInt64_defined
60 #           define UInt64_defined
61 typedef unsigned long UInt64;
62 #       endif
63 #       ifndef SInt64_defined
64 #           define SInt64_defined
65 typedef signed long SInt64;
66 #       endif
67 #   elif UNITY_OSX
68 #       ifndef SInt32_defined
69 #           define SInt32_defined
70 typedef signed int SInt32;
71 #       endif
72 #       ifndef UInt32_defined
73 #           define UInt32_defined
74 typedef unsigned int UInt32;
75 #       endif
76 #       ifndef UInt64_defined
77 #           define UInt64_defined
78 typedef unsigned long long UInt64;
79 #       endif
80 #       ifndef SInt64_defined
81 #           define SInt64_defined
82 typedef signed long long SInt64;
83 #       endif
84 #   elif UNITY_WIN
85 #       ifndef SInt32_defined
86 #           define SInt32_defined
87 typedef signed long SInt32;
88 #       endif
89 #       ifndef UInt32_defined
90 #           define UInt32_defined
91 typedef unsigned long UInt32;
92 #       endif
93 #       ifndef UInt64_defined
94 #           define UInt64_defined
95 typedef unsigned long long UInt64;
96 #       endif
97 #       ifndef SInt64_defined
98 #           define SInt64_defined
99 typedef signed long long SInt64;
100 #       endif
101     #endif
102 #else
103 #       ifndef SInt32_defined
104 #           define SInt32_defined
105 typedef signed int SInt32;
106 #       endif
107 #       ifndef UInt32_defined
108 #           define UInt32_defined
109 typedef unsigned int UInt32;
110 #       endif
111 #       ifndef UInt64_defined
112 #           define UInt64_defined
113 typedef unsigned long long UInt64;
114 #       endif
115 #       ifndef SInt64_defined
116 #           define SInt64_defined
117 typedef signed long long SInt64;
118 #       endif
119 #endif
120 
121 #endif
122 
123 #if UNITY_WIN
124     #define UNITY_AUDIODSP_CALLBACK __stdcall
125 #elif UNITY_OSX
126     #define UNITY_AUDIODSP_CALLBACK
127 #else
128     #define UNITY_AUDIODSP_CALLBACK
129 #endif
130 
131 // Attribute to make function be exported from a plugin
132 #if UNITY_WIN
133     #define UNITY_AUDIODSP_EXPORT_API __declspec(dllexport)
134 #else
135     #define UNITY_AUDIODSP_EXPORT_API
136 #endif
137 
138 #if defined(__CYGWIN32__)
139     #define UNITY_AUDIODSP_CALLBACK __stdcall
140 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64)
141     #define UNITY_AUDIODSP_CALLBACK __stdcall
142 #elif defined(__MACH__) || defined(__ANDROID__) || defined(__linux__) || defined(__QNX__)
143     #define UNITY_AUDIODSP_CALLBACK
144 #else
145     #define UNITY_AUDIODSP_CALLBACK
146 #endif
147 
148 #define UNITY_AUDIODSP_RESULT int
149 
150 #if !UNITY_SPU // asserts require _exit() to be defined
151 #include <assert.h>
152 #endif
153 
154 enum
155 {
156     UNITY_AUDIODSP_OK = 0,
157     UNITY_AUDIODSP_ERR_UNSUPPORTED = 1
158 };
159 
160 struct UnityAudioEffectState;
161 
162 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_CreateCallback)(UnityAudioEffectState* state);
163 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_ReleaseCallback)(UnityAudioEffectState* state);
164 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_ResetCallback)(UnityAudioEffectState* state);
165 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_ProcessCallback)(UnityAudioEffectState* state, float* inbuffer, float* outbuffer, unsigned int length, int inchannels, int outchannels);
166 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_SetPositionCallback)(UnityAudioEffectState* state, unsigned int pos);
167 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_SetFloatParameterCallback)(UnityAudioEffectState* state, int index, float value);
168 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_GetFloatParameterCallback)(UnityAudioEffectState* state, int index, float* value, char *valuestr);
169 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_GetFloatBufferCallback)(UnityAudioEffectState* state, const char* name, float* buffer, int numsamples);
170 
171 enum UnityAudioEffectDefinitionFlags
172 {
173     UnityAudioEffectDefinitionFlags_IsSideChainTarget  = 1 << 0,   // Does this effect need a side chain buffer and can it be targeted by a Send?
174     UnityAudioEffectDefinitionFlags_IsSpatializer      = 2 << 0    // Should this plugin be inserted at sources and take over panning?
175 };
176 
177 enum UnityAudioEffectStateFlags
178 {
179     UnityAudioEffectStateFlags_IsPlaying               = 1 << 0,   // Set when engine is in play mode. Also true while paused.
180     UnityAudioEffectStateFlags_IsPaused                = 1 << 1,   // Set when engine is paused mode.
181     UnityAudioEffectStateFlags_IsMuted                 = 1 << 2,   // Set when effect is being muted (only available in the editor)
182     UnityAudioEffectStateFlags_IsSideChainTarget       = 1 << 3    // Does this effect need a side chain buffer and can it be targeted by a Send?
183 };
184 
185 // This callback can be used to override the way distance attenuation is performed on AudioSources.
186 // distanceIn is the distance between the source and the listener and attenuationOut is the output volume.
187 // attenuationIn is the volume-curve based attenuation that would have been applied by Unity if this callback were not set.
188 // A typical attenuation curve may look like this: *attenuationOut = 1.0f / max(1.0f, distanceIn);
189 // The callback may also be used to apply a secondary gain on top of the one through attenuationIn by Unity's AudioSource curve.
190 typedef UNITY_AUDIODSP_RESULT (UNITY_AUDIODSP_CALLBACK * UnityAudioEffect_DistanceAttenuationCallback)(UnityAudioEffectState* state, float distanceIn, float attenuationIn, float* attenuationOut);
191 
192 struct UnityAudioSpatializerData
193 {
194     float listenermatrix[16];                                                 // Matrix that transforms sourcepos into the local space of the listener
195     float sourcematrix[16];                                                   // Transform matrix of audio source
196     float spatialblend;                                                       // Distance-controlled spatial blend
197     float reverbzonemix;                                                      // Reverb zone mix level parameter (and curve) on audio source
198     float spread;                                                             // Spread parameter of the audio source (0..360 degrees)
199     float stereopan;                                                          // Stereo panning parameter of the audio source (-1 = fully left, 1 = fully right)
200     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)
201 };
202 
203 struct UnityAudioEffectState
204 {
205     union
206     {
207         struct
208         {
209             UInt32                             structsize;         // Size of this struct
210             UInt32                             samplerate;         // System sample rate
211             UInt64                             currdsptick;        // Pointer to a sample counter marking the start of the current block being processed
212             UInt64                             prevdsptick;        // Used for determining when DSPs are bypassed and so sidechain info becomes invalid
213             float*                             sidechainbuffer;    // Side-chain buffers to read from
214             void*                              effectdata;         // Internal data for the effect
215             UInt32                             flags;              // Various flags through which information can be queried from the host
216             void*                              internal;           // Internal data, do not touch!
217 
218             // 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
219             // access any of this data in order to detect whether the host API is older than the plugin.
220 
221             UnityAudioSpatializerData*         spatializerdata;    // Data for spatializers
222             UInt32                             dspbuffersize;      // Number of frames being processed per process callback. Use this to allocate temporary buffers before processing starts.
223             UInt32                             hostapiversion;     // Version of plugin API used by host
224         };
225         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
226     };
227 #ifdef __cplusplus
GetEffectDataUnityAudioEffectState228     template<typename T> inline T* GetEffectData() const
229     {
230 #if !UNITY_SPU // asserts require _exit() to be defined
231         assert(effectdata);
232         assert(internal);
233 #endif
234         return (T*)effectdata;
235     }
236 
237 #endif
238 };
239 
240 struct UnityAudioParameterDefinition
241 {
242     char                                       name[16];           // Display name on the GUI
243     char                                       unit[16];           // Scientific unit of parameter to be appended after the value in textboxes
244     const char*                                description;        // Description of parameter (displayed in tool tips, automatically generated documentation, etc.)
245     float                                      min;                // Minimum value of the parameter
246     float                                      max;                // Maximum value of the parameter
247     float                                      defaultval;         // Default and initial value of the parameter
248     float                                      displayscale;       // Scale factor used only for the display of parameters (i.e. 100 for a percentage value ranging from 0 to 1)
249     float                                      displayexponent;    // Exponent for mapping parameters to sliders
250 };
251 
252 struct UnityAudioEffectDefinition
253 {
254     UInt32                                     structsize;         // Size of this struct
255     UInt32                                     paramstructsize;    // Size of paramdesc fields
256     UInt32                                     apiversion;         // Plugin API version
257     UInt32                                     pluginversion;      // Version of this plugin
258     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.
259     UInt32                                     numparameters;      // The number of parameters exposed by this plugin.
260     UInt64                                     flags;              // Various capabilities and requirements of the plugin.
261     char                                       name[32];           // Name used for registration of the effect. This name will also be displayed in the GUI.
262     UnityAudioEffect_CreateCallback            create;             // The create callback is called when DSP unit is created and can be null.
263     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.
264     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.
265     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.
266     UnityAudioEffect_SetPositionCallback       setposition;        // The position callback can be used for implementing seek operations.
267     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).
268     UnityAudioEffect_SetFloatParameterCallback setfloatparameter;  // This is called whenever one of the exposed parameters is changed.
269     UnityAudioEffect_GetFloatParameterCallback getfloatparameter;  // This is called to query parameter values.
270     UnityAudioEffect_GetFloatBufferCallback    getfloatbuffer;     // Get N samples of named buffer. Used for displaying analysis data from the runtime.
271 };
272 
273 // This function fills in N pointers for the N effects contained in the library and returns N.
274 extern "C" UNITY_AUDIODSP_EXPORT_API int UnityGetAudioEffectDefinitions(UnityAudioEffectDefinition*** descptr);
275