Need help using external dll - Want to import whole class

Hello guys,

so I made a script using Visual Studio that I want to use in my project. My project should be able to take two audio signals and convolute them against each other.

What have I done so far?

  • can use the files
  • extracted float[ ] from mono audio tracks
  • convolution algorithm manually typed, works (but takes ages)

Since my algorithm takes ages I wanted to get a faster one from the internet. Found one at CenterSpace. Downloaded their packages and wanted to use them. Then I used Assembly References in the project in Visual Studio to reference the NMath.dll to my project. In Visual Studio everything is fine. In Unity it says: “are you missing assembly reference?”

Since I googled two whole days to resolve this issue and tried out the world, I finally stranded here.

Usefull information: the NMath.dll is compiled against NET Framework 4.0. Unity says that the editor uses only 3.5. In the dll import settings I turned off using the dll for the editor (exclude editor). Still this doesn’t seem to solve my problem.

I also came across importing the DLL via dllImport[ ]… but I seem to be doing it wrong.
Is there a way, maybe even other than “using CenterSpace.NMath.Core;” in my code, that I can get this running?

using CenterSpace.NMath.Core;
using System.Linq;
using UnityEngine;

public class LastTry : MonoBehaviour
{
...
void Convolute(float[] audio, float[] impRsp)
    {
...
var convolution = new Float1DConvolution(impRsp, impRsp.Length);
FloatVector result = convolution.Convolve(audio);
...
}
...
}

I need the type “FloatVector” and the methods of “Float1DConvolution”, which is a class in the NMath.dll

Thanks for any help.

If the NMath.dll targets .net 4.0, then you’ll have to use Unity 2017 and have it target .net 4.6. Edit->Project Settings->Player-> Other Settings, look for “Scripting Runtime Version”

1 Like

Thanks for the quick reply, gonna try that one out!

@kru this did not resolve my issue. The “problem” still exists.

Threat can be closed. Issue not solved but the programming project is closed.

Don’t add a reference via “Add Reference” in Visual Studio. Unity constantly re-creates the project file whenever there are changes. Instead, create a folder in your project and drop the DLL into that folder. Unity will reference it automatically.

Tried it, Dustin, but it did not work. Unity doesn’t creat any reference to the DLL, neither when I drop it into the Assets folder, not when I create a new one.

You also have to solve this problem. Either using Unity 2017 with the framework version set to 4.6, or you have to get a .NET 3.5 version of the DLL. Also, if you turn the DLL off for the editor it’s not going to work.