Ejemplo n.º 1
0
        /// <summary>
        /// Contains DFTKey
        /// </summary>
        /// <param name="fftSampleCount">fft运算的点数</param>
        /// <param name="type">fft类型</param>
        /// <returns></returns>
        private bool Contains(uint fftSampleCount, DFTType type)
        {
            var k = new DFTKey()
            {
                FFTSampleCount = fftSampleCount,
                Type           = type
            };
            ulong keyId = k.GetKeyNum();

            return(_dftDescDict.ContainsKey(keyId));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加DFT Desc
        /// </summary>
        /// <param name="fftSampleCount"></param>
        /// <param name="type"></param>
        /// <param name="desc"></param>
        private void AddDFTDesc(uint fftSampleCount, DFTType type, IntPtr desc)
        {
            ulong keyId = 0;

            if (!Contains(fftSampleCount, type, ref keyId))
            {
                lock (_dftDescDict)
                {
                    _dftDescDict.Add(keyId, desc);
                }
            }
            else
            {
                throw new JYDSPInnerException("Descriptor have been exist.");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get DFTKey
        /// </summary>
        /// <param name="fftSampleCount">fft运算的点数</param>
        /// <param name="type">fft类型</param>
        /// <returns></returns>
        public IntPtr GetDFTDesc(int fftSampleCount, DFTType type)
        {
            var k = new DFTKey()
            {
                FFTSampleCount = (uint)fftSampleCount,
                Type           = type
            };

            var keyId = k.GetKeyNum();

            lock (_dftDescDict)
            {
                //存在该Key则直接返回
                if (_dftDescDict.ContainsKey(keyId))
                {
                    return(_dftDescDict[keyId]);
                }

                var desc = IntPtr.Zero;
                int precision, forwardDomain, dimension, length = fftSampleCount, ret;
                //不存在,则创建并配置,保存后返回
                #region ------------根据不同变换类型创建描述符,并分别配置(如果有)-------------
                switch (type)
                {
                case DFTType.Double1DRealInComplexOut:
                    precision     = DFTI.DOUBLE;
                    forwardDomain = DFTI.REAL;
                    dimension     = 1;
                    if (0 != (ret = DFTI.DftiCreateDescriptor(ref desc, precision, forwardDomain,
                                                              dimension, length)))
                    {
                        throw new JYDSPInnerException("DftiCreateDescriptor Failed, error code = " + ret);
                    }

                    if (0 != (ret = DFTI.DftiSetValue(desc, DFTI.PACKED_FORMAT, DFTI.CCS_FORMAT)))
                    {
                        throw new JYDSPInnerException("DftiSetValue PACKED_FORMAT Failed, error code = " + ret);
                    }
                    break;

                case DFTType.Double1DComplexInComplexOut:
                    precision     = DFTI.DOUBLE;
                    forwardDomain = DFTI.COMPLEX;
                    dimension     = 1;
                    if (0 != (ret = DFTI.DftiCreateDescriptor(ref desc, precision, forwardDomain,
                                                              dimension, length)))
                    {
                        throw new JYDSPInnerException("DftiCreateDescriptor Failed, error code = " + ret);
                    }
                    break;

                case DFTType.Single1DRealInComplexOut:
                    precision     = DFTI.SINGLE;
                    forwardDomain = DFTI.REAL;
                    dimension     = 1;
                    if (0 != (ret = DFTI.DftiCreateDescriptor(ref desc, precision, forwardDomain,
                                                              dimension, length)))
                    {
                        throw new JYDSPInnerException("DftiCreateDescriptor Failed, error code = " + ret);
                    }

                    if (0 != (ret = DFTI.DftiSetValue(desc, DFTI.PACKED_FORMAT, DFTI.CCS_FORMAT)))
                    {
                        throw new JYDSPInnerException("DftiSetValue PACKED_FORMAT Failed, error code = " + ret);
                    }
                    break;

                case DFTType.Single1DComplexInComplexOut:
                    precision     = DFTI.SINGLE;
                    forwardDomain = DFTI.COMPLEX;
                    dimension     = 1;
                    if (0 != (ret = DFTI.DftiCreateDescriptor(ref desc, precision, forwardDomain,
                                                              dimension, length)))
                    {
                        throw new JYDSPInnerException("DftiCreateDescriptor Failed, error code = " + ret);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }
                #endregion

                #region ------------------公共设置------------------
                var scaleFactor = 1.0 / length;
                //配置IFFT的ScaleFactor
                if (0 != (ret = DFTI.DftiSetValue(desc, DFTI.BACKWARD_SCALE, scaleFactor)))
                {
                    throw new JYDSPInnerException("DftiSetValue Failed, error code = " + ret);
                }

                //配置DFTI_PLACEMENT为DFTI_NOT_INPLACE,即FFT后的结果不覆盖原输入信号
                if (0 != (ret = DFTI.DftiSetValue(desc, DFTI.PLACEMENT, DFTI.NOT_INPLACE)))
                {
                    throw new JYDSPInnerException("DftiSetValue PLACEMENT Failed, error code = " + ret);
                }

                if (0 != (ret = DFTI.DftiCommitDescriptor(desc)))
                {
                    throw new JYDSPInnerException("DftiCommitDescriptor Failed, error code = " + ret);
                }
                #endregion

                //保存描述符并返回
                _dftDescDict.Add(keyId, desc);
                return(desc);
            }
        }
Ejemplo n.º 4
0
 public DFTKey(uint fftSampleCount, DFTType type)
 {
     FFTSampleCount = fftSampleCount;
     Type           = type;
 }