Esempio n. 1
0
        unsafe void restore_samples_fixed(FlacFrame frame, int ch)
        {
            FlacSubframeInfo sub = frame.subframes[ch];

            AudioSamples.MemCpy(sub.samples, sub.best.residual, sub.best.order);
            int *data = sub.samples + sub.best.order;
            int *residual = sub.best.residual + sub.best.order;
            int  data_len = frame.blocksize - sub.best.order;
            int  s0, s1, s2;

            switch (sub.best.order)
            {
            case 0:
                AudioSamples.MemCpy(data, residual, data_len);
                break;

            case 1:
                s1 = data[-1];
                for (int i = data_len; i > 0; i--)
                {
                    s1       += *(residual++);
                    *(data++) = s1;
                }
                //data[i] = residual[i] + data[i - 1];
                break;

            case 2:
                s2 = data[-2];
                s1 = data[-1];
                for (int i = data_len; i > 0; i--)
                {
                    s0        = *(residual++) + (s1 << 1) - s2;
                    *(data++) = s0;
                    s2        = s1;
                    s1        = s0;
                }
                //data[i] = residual[i] + data[i - 1] * 2  - data[i - 2];
                break;

            case 3:
                for (int i = 0; i < data_len; i++)
                {
                    data[i] = residual[i] + (((data[i - 1] - data[i - 2]) << 1) + (data[i - 1] - data[i - 2])) + data[i - 3];
                }
                break;

            case 4:
                for (int i = 0; i < data_len; i++)
                {
                    data[i] = residual[i] + ((data[i - 1] + data[i - 3]) << 2) - ((data[i - 2] << 2) + (data[i - 2] << 1)) - data[i - 4];
                }
                break;
            }
        }
Esempio n. 2
0
        unsafe void restore_samples_lpc(FlacFrame frame, int ch)
        {
            FlacSubframeInfo sub  = frame.subframes[ch];
            ulong            csum = 0;

            fixed(int *coefs = sub.best.coefs)
            {
                for (int i = sub.best.order; i > 0; i--)
                {
                    csum += (ulong)Math.Abs(coefs[i - 1]);
                }
                if ((csum << sub.obits) >= 1UL << 32)
                {
                    lpc.decode_residual_long(sub.best.residual, sub.samples, frame.blocksize, sub.best.order, coefs, sub.best.shift);
                }
                else
                {
                    lpc.decode_residual(sub.best.residual, sub.samples, frame.blocksize, sub.best.order, coefs, sub.best.shift);
                }
            }
        }