Exemplo n.º 1
0
        /// <summary>Processes the specified input data.</summary>
        /// <param name="inputData">The input data.</param>
        /// <param name="inputOffset">The offset of the first value to process.</param>
        /// <param name="inputStride">The stride in the input data.</param>
        /// <param name="count">The number of values to process.</param>
        /// <returns>The number of resampled values.</returns>
        public int Process(float[] inputData, int inputOffset, int inputStride, int count)
        {
            //resize input buffer, *preserve data*
            int requiredBufferSize = writeIndex + count;

            if (inData.Length < requiredBufferSize)
            {
                Array.Resize(ref inData, requiredBufferSize);
            }

            //de-interleave input data and write to the buffer
            Dsp.StridedToFloat(inputData, inputOffset, inputStride, inData, writeIndex, count);
            writeIndex += count;
            int unusedCount = writeIndex - writeIndex0;

            //estimate output count
            int maxOutCount = (int)(((long)unusedCount * outRate) / inRate) + 2; //+2 is from the example

            if (OutData == null || OutData.Length < maxOutCount)
            {
                OutData = new float[maxOutCount];
            }
            int outCount = 0;

            fixed(float *pSrc = inData, pDst = OutData)
            fixed(double *pTime = &readIndex)
            {
                //resample
                IppStatus rc = Ipp.ippsResamplePolyphaseFixed_32f(pSrc, unusedCount, pDst, 1f, pTime, &outCount, pSpec);

                IppException.Check(rc);
                int usedCount = (int)readIndex - readIndex0;

                //shift unused data back in the buffer
                rc = sp.ippsMove_32f(pSrc + usedCount, pSrc, writeIndex - usedCount);
                IppException.Check(rc);
                readIndex  -= usedCount;
                writeIndex -= usedCount;
            }

            return(outCount);
        }
Exemplo n.º 2
0
        /// <summary>Writes one of the channels of the strided data to the ring buffer.</summary>
        /// <param name="data">The data.</param>
        /// <param name="offset">The offset to the first value.</param>
        /// <param name="inFloatCount">The number of the input floating point values.</param>
        /// <param name="format">The format of the data.</param>
        public void WriteStrided(float[] data, int offset, int inFloatCount, SignalFormat format)
        {
            //single channel, just copy
            if (format.Channels == 1)
            {
                Write(data, offset, inFloatCount);
            }

            //multiple complex channels
            else if (format.IsComplex)
            {
                int stride       = format.Channels * Dsp.COMPONENTS_IN_COMPLEX;
                int floatCount   = inFloatCount / format.Channels;
                int complexCount = inFloatCount / stride;

                if (buffer == null || this.buffer.Length < floatCount)
                {
                    buffer = new float[floatCount];
                }

                Dsp.StridedToComplex(data, offset, stride, buffer, 0, complexCount);
                Write(buffer, 0, floatCount);
            }

            //multiple real channels
            else
            {
                int floatCount = inFloatCount / format.Channels;

                if (buffer == null || this.buffer.Length < floatCount)
                {
                    buffer = new float[floatCount];
                }

                Dsp.StridedToFloat(data, offset, format.Channels, buffer, 0, floatCount);
                Write(buffer, 0, floatCount);
            }
        }