Exemplo n.º 1
0
        //filterCutoff is 0..1 (-6 dB point)

        /// <summary>Initializes a new instance of the <see cref="IppResampler" /> class.</summary>
        /// <param name="inRate">The input sampling rate.</param>
        /// <param name="outRate">The output sampling rate.</param>
        /// <param name="requestedFilterOrder">The requested filter order.</param>
        /// <param name="filterCutoff">The 6-dB cutoff frequency of the anti-aliasing filter
        /// as a fraction of the Nyquist frequency. Must be in the range of 0...1.</param>
        /// <param name="kaiserAlpha">The alpha parameter of the Kaiser filter.</param>
        public IppResampler(int inRate, int outRate, int requestedFilterOrder, float filterCutoff, float kaiserAlpha)
        {
            this.inRate  = inRate;
            this.outRate = outRate;

            //allocate memory for the resampler structure
            int       specSize, filterOrder, filterHeight;
            IppStatus rc;

            rc = Ipp.ippsResamplePolyphaseFixedGetSize_32f(inRate, outRate, requestedFilterOrder, &specSize,
                                                           &filterOrder, &filterHeight, IppHintAlgorithm.ippAlgHintFast);
            IppException.Check(rc);

            //{!} docs suggest to use ippsMalloc_8u(specSize), but that results in memory corruption
            pSpec = (IppsResamplingPolyphaseFixed_32f *)Ipp.ippsMalloc_8u(specSize * filterHeight);

            //initialize IPP resampler
            rc = Ipp.ippsResamplePolyphaseFixedInit_32f(inRate, outRate, filterOrder, filterCutoff,
                                                        kaiserAlpha, pSpec, IppHintAlgorithm.ippAlgHintFast);
            IppException.Check(rc);

            //set up input buffer
            inData     = new float[filterOrder];
            readIndex  = readIndex0 = filterOrder / 2;
            writeIndex = writeIndex0 = filterOrder;
        }
Exemplo n.º 2
0
        /// <summary>Initializes a new instance of the <see cref="ComplexFft" /> class.</summary>
        /// <param name="size">The size of the FFT transform.</param>
        public ComplexFft(int size) : base(size)
        {
            //allocate input buffer
            TimeData = new Complex32[size];
            FreqData = new Complex32[size];

            //calculate FFT buffer sizes
            int       specBufSize, initBufSize, workBufSize;
            IppStatus rc = sp.ippsFFTGetSize_C_32fc(order, IPP_FFT_NODIV_BY_ANY,
                                                    IppHintAlgorithm.ippAlgHintNone, &specBufSize, &initBufSize, &workBufSize);

            IppException.Check(rc);

            //allocate FFT buffers
            Dispose();
            specBuffer = Ipp.ippsMalloc_8u(specBufSize);
            byte[] initBuf = new byte[initBufSize];
            workBuf = new byte[workBufSize];

            //initialize FFT
            fixed(byte *pInitBuf = initBuf)
            fixed(IppsFFTSpec_C_32fc **ppFftSpec = &pFftSpec)
            {
                rc = sp.ippsFFTInit_C_32fc(ppFftSpec, order, IPP_FFT_NODIV_BY_ANY,
                                           IppHintAlgorithm.ippAlgHintNone, specBuffer, pInitBuf);
            }
            IppException.Check(rc);
        }
Exemplo n.º 3
0
        /// <summary>Initializes a new instance of the <see cref="RealFft" /> class.</summary>
        /// <param name="size">The size of the FFT transform.</param>
        public RealFft(int size) : base(size)
        {
            TimeData = new float[size];
            FreqData = new Complex32[size / 2 + 1];

            int       specBufSize, initBufSize, workBufSize;
            IppStatus rc = sp.ippsFFTGetSize_R_32f(order, IPP_FFT_NODIV_BY_ANY,
                                                   IppHintAlgorithm.ippAlgHintNone, &specBufSize, &initBufSize, &workBufSize);

            IppException.Check(rc);

            specBuffer = Ipp.ippsMalloc_8u(specBufSize);
            byte[] initBuf = new byte[initBufSize];
            workBuf = new byte[workBufSize];

            fixed(byte *pInitBuf = initBuf)
            fixed(IppsFFTSpec_R_32f **ppFftSpec = &pFftSpec)
            {
                rc = sp.ippsFFTInit_R_32f(ppFftSpec, order, IPP_FFT_NODIV_BY_ANY,
                                          IppHintAlgorithm.ippAlgHintNone, specBuffer, pInitBuf);
            }
            IppException.Check(rc);
        }