Exemplo n.º 1
0
        unsafe void decode_subframe_lpc(BitReader bitreader, FlacFrame frame, int ch)
        {
            // warm-up samples
            int obits = frame.subframes[ch].obits;

            for (int i = 0; i < frame.subframes[ch].best.order; i++)
            {
                frame.subframes[ch].best.residual[i] = bitreader.readbits_signed(obits);
            }

            // LPC coefficients
            frame.subframes[ch].best.cbits = (int)bitreader.readbits(4) + 1;             // lpc_precision
            if (frame.subframes[ch].best.cbits >= 16)
            {
                throw new Exception("cbits >= 16");
            }
            frame.subframes[ch].best.shift = bitreader.readbits_signed(5);
            if (frame.subframes[ch].best.shift < 0)
            {
                throw new Exception("negative shift");
            }
            for (int i = 0; i < frame.subframes[ch].best.order; i++)
            {
                frame.subframes[ch].best.coefs[i] = bitreader.readbits_signed(frame.subframes[ch].best.cbits);
            }

            // residual
            decode_residual(bitreader, frame, ch);
        }
Exemplo n.º 2
0
        unsafe void decode_subframe_verbatim(BitReader bitreader, FlacFrame frame, int ch)
        {
            int obits = frame.subframes[ch].obits;

            for (int i = 0; i < frame.blocksize; i++)
            {
                frame.subframes[ch].best.residual[i] = bitreader.readbits_signed(obits);
            }
        }
Exemplo n.º 3
0
        unsafe void decode_subframe_fixed(BitReader bitreader, FlacFrame frame, int ch)
        {
            // warm-up samples
            int obits = frame.subframes[ch].obits;

            for (int i = 0; i < frame.subframes[ch].best.order; i++)
            {
                frame.subframes[ch].best.residual[i] = bitreader.readbits_signed(obits);
            }

            // residual
            decode_residual(bitreader, frame, ch);
        }
Exemplo n.º 4
0
        unsafe void decode_residual(BitReader bitreader, FlacFrame frame, int ch)
        {
            // rice-encoded block
            // coding method
            frame.subframes[ch].best.rc.coding_method = (int)bitreader.readbits(2);             // ????? == 0
            if (frame.subframes[ch].best.rc.coding_method != 0 && frame.subframes[ch].best.rc.coding_method != 1)
            {
                throw new Exception("unsupported residual coding");
            }
            // partition order
            frame.subframes[ch].best.rc.porder = (int)bitreader.readbits(4);
            if (frame.subframes[ch].best.rc.porder > 8)
            {
                throw new Exception("invalid partition order");
            }
            int psize   = frame.blocksize >> frame.subframes[ch].best.rc.porder;
            int res_cnt = psize - frame.subframes[ch].best.order;

            int rice_len = 4 + frame.subframes[ch].best.rc.coding_method;
            // residual
            int  j = frame.subframes[ch].best.order;
            int *r = frame.subframes[ch].best.residual + j;

            for (int p = 0; p < (1 << frame.subframes[ch].best.rc.porder); p++)
            {
                if (p == 1)
                {
                    res_cnt = psize;
                }
                int n = Math.Min(res_cnt, frame.blocksize - j);

                int k = frame.subframes[ch].best.rc.rparams[p] = (int)bitreader.readbits(rice_len);
                if (k == (1 << rice_len) - 1)
                {
                    k = frame.subframes[ch].best.rc.esc_bps[p] = (int)bitreader.readbits(5);
                    for (int i = n; i > 0; i--)
                    {
                        *(r++) = bitreader.readbits_signed((int)k);
                    }
                }
                else
                {
                    bitreader.read_rice_block(n, (int)k, r);
                    r += n;
                }
                j += n;
            }
        }
Exemplo n.º 5
0
        unsafe void decode_subframe_constant(BitReader bitreader, FlacFrame frame, int ch)
        {
            int obits = frame.subframes[ch].obits;

            frame.subframes[ch].best.residual[0] = bitreader.readbits_signed(obits);
        }