public void TestDll3(string fn) { string ifiles = "ABC1#1.sts"; string outfile = "ABC1#2.sts"; //float[,] PFrf = new float[8][]; //PFrf[0] = new float[4096]; // IntPtr PFrf = Marshal.AllocHGlobal(8 * 4 * 1024); PFrf pFef = new PFrf(); ////Marshal. pFef.p0 = Marshal.AllocHGlobal(4 * 1024); pFef.p1 = Marshal.AllocHGlobal(4 * 1024); pFef.p2 = Marshal.AllocHGlobal(4 * 1024); pFef.p3 = Marshal.AllocHGlobal(4 * 1024); pFef.p4 = Marshal.AllocHGlobal(4 * 1024); pFef.p5 = Marshal.AllocHGlobal(4 * 1024); pFef.p6 = Marshal.AllocHGlobal(4 * 1024); pFef.p7 = Marshal.AllocHGlobal(4 * 1024); // float[] pSpecData = new float[8*1024]; // IntPtr pFrf = Marshal.AllocHGlobal(8*4 * 1024); ; // Marshal.StructureToPtr(pSpecData, pFrf, true); int nWavePtNum = 3 * 1024; int nProgress = 0; int nFftPtNum = 1024; float fWaveSfOut = 6400f; int nVtbScale = 4; float fGainCvOut = 10.02f; float fGainCvInec = 0.425f; int[] para = new int[4]; para[0] = -1; para[1] = 1; para[2] = 24; para[3] = 85; float[] pFrfd0 = new float[1024]; float[] pFrfd1 = new float[1024]; float[] pFrfd2 = new float[1024]; float[] pFrfd3 = new float[1024]; float[] pFrfd4 = new float[1024]; float[] pFrfd5 = new float[1024]; float[] pFrfd6 = new float[1024]; float[] pFrfd7 = new float[1024]; WindowPara nWindowPara = new WindowPara(); nWindowPara.p1 = -1; nWindowPara.p2 = 1; nWindowPara.p3 = 24; nWindowPara.p4 = 85; IntPtr tmp = Marshal.AllocHGlobal(16); Marshal.StructureToPtr(nWindowPara, tmp, true); int a = Marshal.ReadInt32(tmp); //Marshal.StructureToPtr(person, intPtr, true); //IntPtr nWindowPara = Marshal.AllocHGlobal(4*4); ////nWindowPara.s ////nWindowPara[0] = -1; ////nWindowPara[1] = 1; ////nWindowPara[2] = 24; ////nWindowPara[3] = 85; int nClearDc = 1; int nRC = 0; try { nRC = DaspFrfAverageInFileFloat(ifiles, outfile, out pFef, nWavePtNum, nFftPtNum, fWaveSfOut, nVtbScale, fGainCvInec, fGainCvOut, tmp /* nWindowPara*/, nClearDc, 0, 0, 0, out nProgress); } catch (Exception ex) { } if (nRC > 0) { for (int i = 0; i < 8; i++) { switch (i) { case 0: Marshal.Copy(pFef.p0, pFrfd0, 0, 1024); break; case 1: Marshal.Copy(pFef.p1, pFrfd1, 0, 1024); break; case 2: Marshal.Copy(pFef.p2, pFrfd2, 0, 1024); break; case 3: Marshal.Copy(pFef.p3, pFrfd3, 0, 1024); break; case 4: Marshal.Copy(pFef.p4, pFrfd4, 0, 1024); break; case 5: Marshal.Copy(pFef.p5, pFrfd5, 0, 1024); break; case 6: Marshal.Copy(pFef.p6, pFrfd6, 0, 1024); break; case 7: Marshal.Copy(pFef.p7, pFrfd7, 0, 1024); break; } } } MessageBox.Show(nRC.ToString()); }
/// <summary> /// /// </summary> /// <param name="indata">观测输入数据</param> /// <param name="outdata">观测输出数据</param> /// <param name="lstFrf">计算结果数据</param> /// <param name="nWavePtNum">时域波形的点数</param> /// <param name="nFftPtNum">计算点数</param> /// <param name="fWaveSfOut">输出信号的采样频率</param> /// <param name="fWaveSfIn">输入信号的采样频率</param> /// <param name="nWindowType">输入加窗形式</param> /// <param name="nExpPara">指数窗的系数</param> /// <param name="nWindowLL">力窗左边界位置</param> /// <param name="nWindowLR">力窗右边界位置</param> /// <param name="nClearDc">是否做去直流处理</param> /// <param name="nSpectrumType">输出信号进行微积分转换的方式</param> /// <param name="nCorePar">谱修正系数</param> /// <param name="nCascadePercent">重叠比例</param> /// <returns></returns> public static bool CalFRF(List <float> indata, List <float> outdata, out List <float>[] lstFrf, int nWavePtNum, int nFftPtNum, float fWaveSfOut, float fWaveSfIn, int nWindowType, int nExpPara, int nWindowLL, int nWindowLR, int nClearDc, int nSpectrumType, int nCorePar, int nCascadePercent) { bool br = false; PFrf pFef = new PFrf(); lstFrf = new List <float> [8]; int outnFftPtNum = nFftPtNum / 2 + 1; pFef.p0 = Marshal.AllocHGlobal(4 * outnFftPtNum); pFef.p1 = Marshal.AllocHGlobal(4 * outnFftPtNum); pFef.p2 = Marshal.AllocHGlobal(4 * outnFftPtNum); pFef.p3 = Marshal.AllocHGlobal(4 * outnFftPtNum); pFef.p4 = Marshal.AllocHGlobal(4 * outnFftPtNum); pFef.p5 = Marshal.AllocHGlobal(4 * outnFftPtNum); pFef.p6 = Marshal.AllocHGlobal(4 * outnFftPtNum); pFef.p7 = Marshal.AllocHGlobal(4 * outnFftPtNum); int nProgress = 0; int nVtbScale = Convert.ToInt32(fWaveSfIn / fWaveSfOut); float[] pFrfd0 = new float[nFftPtNum]; float[] pFrfd1 = new float[nFftPtNum]; float[] pFrfd2 = new float[nFftPtNum]; float[] pFrfd3 = new float[nFftPtNum]; float[] pFrfd4 = new float[nFftPtNum]; float[] pFrfd5 = new float[nFftPtNum]; float[] pFrfd6 = new float[nFftPtNum]; float[] pFrfd7 = new float[nFftPtNum]; WindowPara nWindowPara = new WindowPara(); nWindowPara.p1 = nWindowType; // -1; nWindowPara.p2 = nExpPara; // 1; nWindowPara.p3 = nWindowLL; // 24; nWindowPara.p4 = nWindowLR; // 85; IntPtr tmp = Marshal.AllocHGlobal(16); Marshal.StructureToPtr(nWindowPara, tmp, true); //int nClearDc = 1; int nRC = 0; try { nRC = DaspFrfAverageInMemoryFloat(/*pWaveIn, pWaveOut,*/ indata.ToArray(), outdata.ToArray(), out pFef, nWavePtNum, nFftPtNum, fWaveSfOut, nVtbScale, /* fGainCvInec, fGainCvOut,*/ tmp /* nWindowPara*/, nClearDc, nSpectrumType, nCorePar, nCascadePercent, out nProgress); } catch (Exception ex) { } lstFrf[0] = new List <float>(outnFftPtNum); lstFrf[1] = new List <float>(outnFftPtNum); lstFrf[2] = new List <float>(outnFftPtNum); lstFrf[3] = new List <float>(outnFftPtNum); lstFrf[4] = new List <float>(outnFftPtNum); lstFrf[5] = new List <float>(outnFftPtNum); lstFrf[6] = new List <float>(outnFftPtNum); lstFrf[7] = new List <float>(outnFftPtNum); if (nRC > 0) { br = true; for (int i = 0; i < 8; i++) { switch (i) { case 0: Marshal.Copy(pFef.p0, pFrfd0, 0, outnFftPtNum); lstFrf[0] = new List <float>(pFrfd0); break; case 1: Marshal.Copy(pFef.p1, pFrfd1, 0, outnFftPtNum); lstFrf[1] = new List <float>(pFrfd1); break; case 2: Marshal.Copy(pFef.p2, pFrfd2, 0, outnFftPtNum); lstFrf[2] = new List <float>(pFrfd2); break; case 3: Marshal.Copy(pFef.p3, pFrfd3, 0, outnFftPtNum); lstFrf[3] = new List <float>(pFrfd3); break; case 4: Marshal.Copy(pFef.p4, pFrfd4, 0, outnFftPtNum); lstFrf[4] = new List <float>(pFrfd4); break; case 5: Marshal.Copy(pFef.p5, pFrfd5, 0, outnFftPtNum); lstFrf[5] = new List <float>(pFrfd5); break; case 6: Marshal.Copy(pFef.p6, pFrfd6, 0, outnFftPtNum); lstFrf[6] = new List <float>(pFrfd6); break; case 7: Marshal.Copy(pFef.p7, pFrfd7, 0, outnFftPtNum); lstFrf[7] = new List <float>(pFrfd7); break; } } } return(br); }
public static extern int DaspFrfAverageInMemoryFloat(float[] pWaveIn, float[] pWaveOut, out PFrf /*IntPtr*/ pFrf, int nWavePtNum, int nFftPtNum, float fWaveSfOut, int nVtbScale, /*, float fGainCvInec, float fGainCvOut,*/ /*WindowPara*/ IntPtr nWindowPara, int nClearDc, int nCalculousType, int nCorePar, int nCascadePercent, out int nProgress);
//public static extern int DaspFrfAverageInMemoryFloat(IntPtr pWaveIn, IntPtr pWaveOut, out PFrf/*IntPtr*/ pFrf, int nWavePtNum, int nFftPtNum, float fWaveSfOut, int nVtbScale,/*, float fGainCvInec, float fGainCvOut,*/ /*WindowPara*/IntPtr nWindowPara, int nClearDc, int nCalculousType, int nCorePar, int nCascadePercent, out int nProgress); // DaspFrfAverageInFileFloat(string inFileName, string outFileName,out PFrf/*IntPtr*/ pFrf, int nWavePtNum, int nFftPtNum, float fWaveSfOut, int nVtbScale, float fGainCvInec, float fGainCvOut, /*WindowPara*/IntPtr nWindowPara, int nClearDc, int nCalculousType, int nCorePar, int nCascadePercent, out int nProgress); // char * szStsFileNameIn, char * szStsFileNameOut, float **pFrf, int nWavePtNum, int nFftPtNum, float fWaveSfOut, int nVtbScale, float fGainCvIn, float fGainCvOut, int *nWindowPara , int nClearDc, int nCalculousType, int nCorePar, int nCascadePercent, int * nProgress); public void CalFRF(List <float> indata, List <float> outdata) { PFrf pFef = new PFrf(); ////Marshal. pFef.p0 = Marshal.AllocHGlobal(4 * 1024); pFef.p1 = Marshal.AllocHGlobal(4 * 1024); pFef.p2 = Marshal.AllocHGlobal(4 * 1024); pFef.p3 = Marshal.AllocHGlobal(4 * 1024); pFef.p4 = Marshal.AllocHGlobal(4 * 1024); pFef.p5 = Marshal.AllocHGlobal(4 * 1024); pFef.p6 = Marshal.AllocHGlobal(4 * 1024); pFef.p7 = Marshal.AllocHGlobal(4 * 1024); int nWavePtNum = 3 * 1024; int nProgress = 0; int nFftPtNum = 1024; float fWaveSfOut = 6400f; int nVtbScale = 4; int[] para = new int[4]; para[0] = 0; para[1] = 1; para[2] = 24; para[3] = 85; float[] pFrfd0 = new float[1024]; float[] pFrfd1 = new float[1024]; float[] pFrfd2 = new float[1024]; float[] pFrfd3 = new float[1024]; float[] pFrfd4 = new float[1024]; float[] pFrfd5 = new float[1024]; float[] pFrfd6 = new float[1024]; float[] pFrfd7 = new float[1024]; WindowPara nWindowPara = new WindowPara(); nWindowPara.p1 = -1; nWindowPara.p2 = 1; nWindowPara.p3 = 24; nWindowPara.p4 = 85; IntPtr tmp = Marshal.AllocHGlobal(16); Marshal.StructureToPtr(nWindowPara, tmp, true); int nClearDc = 1; int nRC = 0; try { nRC = DaspFrfAverageInMemoryFloat(/*pWaveIn, pWaveOut,*/ indata.ToArray(), outdata.ToArray(), out pFef, nWavePtNum, nFftPtNum, fWaveSfOut, nVtbScale, /* fGainCvInec, fGainCvOut,*/ tmp /* nWindowPara*/, nClearDc, 0, 0, 0, out nProgress); } catch (Exception ex) { } if (nRC > 0) { for (int i = 0; i < 8; i++) { switch (i) { case 0: Marshal.Copy(pFef.p0, pFrfd0, 0, 1024); break; case 1: Marshal.Copy(pFef.p1, pFrfd1, 0, 1024); break; case 2: Marshal.Copy(pFef.p2, pFrfd2, 0, 1024); break; case 3: Marshal.Copy(pFef.p3, pFrfd3, 0, 1024); break; case 4: Marshal.Copy(pFef.p4, pFrfd4, 0, 1024); break; case 5: Marshal.Copy(pFef.p5, pFrfd5, 0, 1024); break; case 6: Marshal.Copy(pFef.p6, pFrfd6, 0, 1024); break; case 7: Marshal.Copy(pFef.p7, pFrfd7, 0, 1024); break; } } } }
public static extern int DaspFrfAverageInFileFloat(string inFileName, string outFileName, out PFrf /*IntPtr*/ pFrf, int nWavePtNum, int nFftPtNum, float fWaveSfOut, int nVtbScale, float fGainCvInec, float fGainCvOut, /*WindowPara*/ IntPtr nWindowPara, int nClearDc, int nCalculousType, int nCorePar, int nCascadePercent, out int nProgress);