예제 #1
0
        internal static int pitch_xcorr(
            int[] _x,
            int[] _y,
            int[] xcorr,
            int len,
            int max_pitch)
        {
            int i;
            int maxcorr = 1;

            Inlines.OpusAssert(max_pitch > 0);
            for (i = 0; i < max_pitch - 3; i += 4)
            {
                int sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0;
                Kernels.xcorr_kernel(_x, _y, i, ref sum0, ref sum1, ref sum2, ref sum3, len);
                xcorr[i]     = sum0;
                xcorr[i + 1] = sum1;
                xcorr[i + 2] = sum2;
                xcorr[i + 3] = sum3;
                sum0         = Inlines.MAX32(sum0, sum1);
                sum2         = Inlines.MAX32(sum2, sum3);
                sum0         = Inlines.MAX32(sum0, sum2);
                maxcorr      = Inlines.MAX32(maxcorr, sum0);
            }
            /* In case max_pitch isn't a multiple of 4, do non-unrolled version. */
            for (; i < max_pitch; i++)
            {
                int inner_sum = Kernels.celt_inner_prod(_x, 0, _y, i, len);
                xcorr[i] = inner_sum;
                maxcorr  = Inlines.MAX32(maxcorr, inner_sum);
            }
            return(maxcorr);
        }
예제 #2
0
        internal static unsafe int pitch_xcorr(
            short[] _x,
            int _x_ptr,
            short[] _y,
            int _y_ptr,
            int[] xcorr,
            int len,
            int max_pitch)
        {
            int i;
            int maxcorr = 1;

            Inlines.OpusAssert(max_pitch > 0);
            fixed(int *pxcorr = xcorr)
            {
                fixed(short *px_base = _x, py_base = _y)
                {
                    short *px = px_base + _x_ptr;

                    for (i = 0; i < max_pitch - 3; i += 4)
                    {
                        int    sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0;
                        short *py = py_base + _y_ptr + i;
                        Kernels.xcorr_kernel(px, py, ref sum0, ref sum1, ref sum2, ref sum3, len);

                        int *pxcorr2 = pxcorr + i;
                        pxcorr2[0] = sum0;
                        pxcorr2[1] = sum1;
                        pxcorr2[2] = sum2;
                        pxcorr2[3] = sum3;
                        sum0       = Inlines.MAX32(sum0, sum1);
                        sum2       = Inlines.MAX32(sum2, sum3);
                        sum0       = Inlines.MAX32(sum0, sum2);
                        maxcorr    = Inlines.MAX32(maxcorr, sum0);
                    }
                    /* In case max_pitch isn't a multiple of 4, do non-unrolled version. */
                    for (; i < max_pitch; i++)
                    {
                        short *py        = py_base + _y_ptr + i;
                        int    inner_sum = Kernels.celt_inner_prod(px, py, len);
                        xcorr[i] = inner_sum;
                        maxcorr  = Inlines.MAX32(maxcorr, inner_sum);
                    }
                }
            }

            return(maxcorr);
        }
예제 #3
0
        internal static void celt_iir(
            int[] _x,
            int _x_ptr,
            int[] den,
            int[] _y,
            int _y_ptr,
            int N,
            int ord,
            int[] mem)
        {
            int i, j;

            int[] rden = new int[ord];
            int[] y    = new int[N + ord];
            Inlines.OpusAssert((ord & 3) == 0);

            for (i = 0; i < ord; i++)
            {
                rden[i] = den[ord - i - 1];
            }
            for (i = 0; i < ord; i++)
            {
                y[i] = (0 - mem[ord - i - 1]);
            }
            for (; i < N + ord; i++)
            {
                y[i] = 0;
            }
            for (i = 0; i < N - 3; i += 4)
            {
                /* Unroll by 4 as if it were an FIR filter */
                int sum0 = _x[_x_ptr + i];
                int sum1 = _x[_x_ptr + i + 1];
                int sum2 = _x[_x_ptr + i + 2];
                int sum3 = _x[_x_ptr + i + 3];
                Kernels.xcorr_kernel(rden, y, i, ref sum0, ref sum1, ref sum2, ref sum3, ord);

                /* Patch up the result to compensate for the fact that this is an IIR */
                y[i + ord]         = (0 - Inlines.ROUND16((sum0), CeltConstants.SIG_SHIFT));
                _y[_y_ptr + i]     = sum0;
                sum1               = Inlines.MAC16_16(sum1, y[i + ord], den[0]);
                y[i + ord + 1]     = (0 - Inlines.ROUND16((sum1), CeltConstants.SIG_SHIFT));
                _y[_y_ptr + i + 1] = sum1;
                sum2               = Inlines.MAC16_16(sum2, y[i + ord + 1], den[0]);
                sum2               = Inlines.MAC16_16(sum2, y[i + ord], den[1]);
                y[i + ord + 2]     = (0 - Inlines.ROUND16((sum2), CeltConstants.SIG_SHIFT));
                _y[_y_ptr + i + 2] = sum2;

                sum3               = Inlines.MAC16_16(sum3, y[i + ord + 2], den[0]);
                sum3               = Inlines.MAC16_16(sum3, y[i + ord + 1], den[1]);
                sum3               = Inlines.MAC16_16(sum3, y[i + ord], den[2]);
                y[i + ord + 3]     = (0 - Inlines.ROUND16((sum3), CeltConstants.SIG_SHIFT));
                _y[_y_ptr + i + 3] = sum3;
            }
            for (; i < N; i++)
            {
                int sum = _x[_x_ptr + i];
                for (j = 0; j < ord; j++)
                {
                    sum -= Inlines.MULT16_16(rden[j], y[i + j]);
                }
                y[i + ord]     = Inlines.ROUND16((sum), CeltConstants.SIG_SHIFT);
                _y[_y_ptr + i] = sum;
            }
            for (i = 0; i < ord; i++)
            {
                mem[i] = (_y[_y_ptr + N - i - 1]);
            }
        }