Hello
I am trying to use FFTW dll for C# but i get the error:
DllNotFoundException: libfftw3-3.dll
The dll is in Assets > Plugins
I used this repository: GitHub - tszalay/FFTWSharp: C# wrapper for FFTW
And followed this tutorial:
I made this script trying to use it, but i get the error so it won’t run:
using System;
using System.Runtime.InteropServices;
using FFTWSharp;
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField,Range(0,10)] private int _size;
[SerializeField] private float[] data;
[SerializeField] private float[] result;
void Awake()
{
result = Ifft(data);
}
private static float[] Ifft(float[] data)
{
// Get the length of the array
int n = data.Length;
/* Allocate an unmanaged memory block for the input and output data.
* (The input and output are of the same length in this case,
* so we can use just one memory block.) */
IntPtr ptr = fftw.malloc(n * sizeof(double));
// Pass the managed input data to the unmanaged memory block
Marshal.Copy(data, 0, ptr, n);
// Plan the IFFT and execute it (n/2 because
// complex numbers are stored as pairs of doubles)
IntPtr plan = fftw.dft_1d(n / 2, ptr, ptr, fftw_direction.Backward, fftw_flags.Estimate);
fftw.execute(plan);
// Create an array to store the output values
float[] ifft = new float[n];
// Pass the unmanaged output data to the managed array
Marshal.Copy(ptr, ifft, 0, n);
// Do some cleaning
fftw.destroy_plan(plan);
fftw.free(ptr);
fftw.cleanup();
// Scale the output values
for (int i = 0, nh = n / 2; i < n; i++) ifft[i] /= nh;
// Return the IFFT output
return ifft;
}
}
What have i done wrong here?