public static void EnergyandEntropy(List<float> data, string _filename, OpenFileDialog open)
{
NAudio.Wave.WaveChannel32 wave = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName));
byte[] mainBuffer = new byte[wave.Length];
int sampleRate = wave.WaveFormat.SampleRate;
int window_ms = 200;
int window;
int fs = sampleRate;
window = window_ms * fs / 1000;
float[] fbuffer = new float[mainBuffer.Length / 8];
wave.Read(mainBuffer, 0, mainBuffer.Length);
for (int i = 0; i < fbuffer.Length; i++)
{
fbuffer[i] = (BitConverter.ToSingle(mainBuffer, i * 8));
}
data.AddRange(fbuffer);
int dataRange = data.Count - (data.Count % window);
data.RemoveRange(dataRange, data.Count - dataRange);
var rows = window;
var cols = data.Count / window;
float[,] array2D = new float[window, data.Count / window];
var current = 0;
List<double> abc = new List<double>();
List<double> cba = new List<double>();
List<double> vuv = new List<double>();
List<MWArray> ent = new List<MWArray>();
MWNumericArray arr1;
EntropyCalculation obj = new EntropyCalculation();
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
array2D[i, j] = data[current++];
double a = array2D[i, j] * array2D[i, j];
abc.Add(a);
cba.Add(array2D[i, j]);
arr1 = cba.ToArray();
if (abc.Count % rows == 0 && abc.Count > 0)
{
double energies = Math.Sqrt(abc.Sum());
MWArray result = obj.entropy(arr1);
abc.Clear();
cba.Clear();
arr1 = null;
vuv.Add(energies);
ent.Add(result);
}
}
}
}
我有这段代码并使用了一个名为 entropy.m 的 MatLab 函数(我将其转换为 dll)。我正在计算数据段的能量和熵。为此,我在里面填充数据List
。当我的数据达到行数时,我清除列表和 MWArray。然后它继续处理下一个段。
这是我的问题。在计算小文件的熵时,它工作正常。但是,当我尝试计算大于 10 兆字节的文件的熵时,arr1 = cba.ToArray();
此行会引发异常。SEHException was unhandled
-External component has thrown an exception.
我试图放置一些断点然后观察代码。它在循环开始时起作用,但随后给了我那个例外。我怎么解决这个问题?