Search Unity

Not able to register FMOD Plugin on iOS (using Unity3d)

Discussion in 'Scripting' started by cchacon, Oct 3, 2015.

  1. cchacon

    cchacon

    Joined:
    Sep 20, 2015
    Posts:
    18
    I created a FMOD Plugin on C++ and generated both dynamic library (.dylib) and static library (.a).

    I am able to successfully use the dynamic library with FMOD Studio GUI and also I’m able to use it in Unity3d Mac simulator (which picks the dynamic library from Assets/Plugins. But I’m having problems getting things working on the iPhone.

    For iOS, I need to use the static library (*.a), which means I have to manually load the plugin in Unity3d (C#), generate the Xcode project and installed it on the iPhone. I tried implementing a basic function in C and load it on C# and it works fine. That means that static library is generated properly and that I can load it successfully on the iPhone and use it. But I can’t get working the FMOD Description Function.

    Here is my code, when I run it in the iPhone, i’m getting this error:

    Thanks in advanced for your help! I’ve been struggling with this for 5 days and haven’t been able to solve it.

    C++ side:

    Code (CSharp):
    1. F_DECLSPEC F_DLLEXPORT int F_STDCALL AigooGetDSPDescription2(FMOD_DSP_DESCRIPTION *FmodDesc)
    2. {
    3.  
    4. // defines the user interface, maximum distance knob
    5. static float distance_mapping_values[] = { 0, 1, 5, 20, 100, 500, 10000 };
    6. static float distance_mapping_scale[] = { 0, 1, 2, 3, 4, 4.5, 5 };
    7.  
    8. // defines the 3D location attributes
    9. FMOD_DSP_INIT_PARAMDESC_DATA(p_3d_attributes, "3D Attributes", "",  "",  FMOD_DSP_PARAMETER_DATA_TYPE_3DATTRIBUTES);
    10.  
    11.  
    12. FMOD_DSP_DESCRIPTION Aigoo_Simple_Plugin_Desc =
    13. {
    14.     FMOD_PLUGIN_SDK_VERSION,
    15.     "AigooSimplePlugin6",    // name
    16.     0x00010000,     // plug-in version
    17.     1,              // number of input buffers to process
    18.     1,              // number of output buffers to process
    19.     Aigoo_Simple_Plugin_dspcreate,
    20.     Aigoo_Simple_Plugin_dsprelease,
    21.     Aigoo_Simple_Plugin_dspreset,
    22.     Aigoo_Simple_Plugin_dspread,
    23.     0,
    24.     0,
    25.     AIGOO_SIMPLE_PLUGIN_NUM_PARAMETERS,
    26.     Aigoo_Simple_Plugin_dspparam,
    27.     Aigoo_Simple_Plugin_dspsetparamfloat,
    28.     0, // Aigoo_Simple_Plugin_dspsetparamint,
    29.     0, // Aigoo_Simple_Plugin_dspsetparambool,
    30.     Aigoo_Simple_Plugin_dspsetparamdata,
    31.     Aigoo_Simple_Plugin_dspgetparamfloat,
    32.     0, // Aigoo_Simple_Plugin_dspgetparamint,
    33.     0, // Aigoo_Simple_Plugin_dspgetparambool,
    34.     Aigoo_Simple_Plugin_dspgetparamdata,
    35.     Aigoo_Simple_Plugin_shouldiprocess,
    36.     0,                                      // userdata
    37.     Aigoo_Simple_Plugin_sys_register,
    38.     Aigoo_Simple_Plugin_sys_deregister,
    39.     Aigoo_Simple_Plugin_sys_mix
    40. };
    41.  
    42.  
    43. FmodDesc = &Aigoo_Simple_Plugin_Desc;
    44.  
    45. return 9291983;  //this is to test that I'm able to get this value on C# and iOS side
    46. }

    C# side:

    Code (CSharp):
    1. public class AigooPlugInHandler {
    2.     [DllImport ("__Internal")]
    3.     public static extern int AigooGetDSPDescription2(out IntPtr FmodDesc);
    4. }
    5.  
    6. public class MyAigooClass : MonoBehaviour
    7. {
    8.     if (Application.platform == RuntimePlatform.IPhonePlayer) {
    9.         IntPtr FmodDescPtr;
    10.         plugin_result = AigooPlugInHandler.AigooGetDSPDescription2(out FmodDescPtr);
    11.         //printing plugin_result returns 9291983 which is the value returned from C
    12.         if (FmodDescPtr != IntPtr.Zero)
    13.         {
    14.             DSP_DESCRIPTION FmodDesc = (DSP_DESCRIPTION)Marshal.PtrToStructure(FmodDescPtr, typeof(DSP_DESCRIPTION));
    15.             FmodDesc.numinputbuffers = 1;
    16.             ERRCHECK(sys.registerDSP(ref FmodDesc, out mmdsp_handle));
    17.         }
    18.         else
    19.             Console.WriteLine("FmodDescPtr is IntPtr.Zero");  
    20.     }
    21. }
    Thanks,
    Carlos
     
    Last edited: Oct 5, 2015
  2. cchacon

    cchacon

    Joined:
    Sep 20, 2015
    Posts:
    18
    I got a reply in another forum with this suggestion:

    Looks like Aigoo_Simple_Plugin_Desc is being allocated on the stack rather than the heap.

    Instead of:

    Code (CSharp):
    1. FMOD_DSP_DESCRIPTION Aigoo_Simple_Plugin_Desc = ...
    ...try the following. Note how the FMOD_DSP_DESCRIPTION parameter has been changed to a pointer to a pointer:

    Code (CSharp):
    1. F_DECLSPEC F_DLLEXPORT int F_STDCALL
    2. AigooGetDSPDescription2(FMOD_DSP_DESCRIPTION **ppFmodDesc)
    3. {
    4.     FMOD_DSP_DESCRIPTION* Aigoo_Simple_Plugin_DescPtr = new FMOD_DSP_DESCRIPTION ();
    5.     // initialise Aigoo_Simple_Plugin_DescPtr
    6.     .
    7.     .
    8.     .
    9.     *ppFmodDesc = Aigoo_Simple_Plugin_DescPtr;
    10.     .
    11.     .
    12.     .

    But after implementing that change I'm getting a new error:
    After debug narrowed down the error to this call:
    Code (CSharp):
    1. DSP_DESCRIPTION FmodDesc = (DSP_DESCRIPTION)Marshal.PtrToStructure(FmodDescPtr, typeof(DSP_DESCRIPTION));

     
    Last edited: Oct 5, 2015