public static ComplexSignal FromArray(float[,] array, int sampleRate)
{
int samples = array.GetLength(0);
int channels = array.GetLength(1);
// check signal size
if (!Accord.Math.Tools.IsPowerOf2(samples))
{
throw new InvalidSignalPropertiesException("Signals length should be a power of 2.");
}
Complex[,] data = new Complex[samples, channels];
for (int i = 0; i < samples; i++)
for (int j = 0; j < channels; j++)
data[i, j] = new Complex(array[i, j], 0);
byte[] buffer = new byte[data.Length * Marshal.SizeOf(typeof(Complex))];
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
Marshal.Copy(handle.AddrOfPinnedObject(), buffer, 0, buffer.Length);
handle.Free();
return new ComplexSignal(buffer, channels, samples, sampleRate);
}