static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
    uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
    bc->bits >>= n;
#else
    uint64_t ret = bc->bits >> (64 - n);
    bc->bits <<= n;
#endif
    bc->bits_left -= n;
    return ret;
}
['static int mpc7_decode_frame(AVCodecContext * avctx, void *data,\n                             int *got_frame_ptr, AVPacket *avpkt)\n{\n    AVFrame *frame     = data;\n    const uint8_t *buf = avpkt->data;\n    int buf_size;\n    MPCContext *c = avctx->priv_data;\n    BitstreamContext bc;\n    int i, ch;\n    int mb = -1;\n    Band *bands = c->bands;\n    int off, ret, last_frame, skip;\n    int bits_used, bits_avail;\n    memset(bands, 0, sizeof(*bands) * (c->maxbands + 1));\n    buf_size = avpkt->size & ~3;\n    if (buf_size <= 0) {\n        av_log(avctx, AV_LOG_ERROR, "packet size is too small (%i bytes)\\n",\n               avpkt->size);\n        return AVERROR_INVALIDDATA;\n    }\n    if (buf_size != avpkt->size) {\n        av_log(avctx, AV_LOG_WARNING, "packet size is not a multiple of 4. "\n               "extra bytes at the end will be skipped.\\n");\n    }\n    skip       = buf[0];\n    last_frame = buf[1];\n    buf       += 4;\n    buf_size  -= 4;\n    frame->nb_samples = last_frame ? c->lastframelen : MPC_FRAME_SIZE;\n    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {\n        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n        return ret;\n    }\n    av_fast_padded_malloc(&c->bits, &c->buf_size, buf_size);\n    if (!c->bits)\n        return AVERROR(ENOMEM);\n    c->bdsp.bswap_buf((uint32_t *) c->bits, (const uint32_t *) buf,\n                      buf_size >> 2);\n    bitstream_init(&bc, c->bits, buf_size * 8);\n    bitstream_skip(&bc, skip);\n    for(i = 0; i <= c->maxbands; i++){\n        for(ch = 0; ch < 2; ch++){\n            int t = 4;\n            if (i)\n                t = bitstream_read_vlc(&bc, hdr_vlc.table, MPC7_HDR_BITS, 1) - 5;\n            if (t == 4)\n                bands[i].res[ch] = bitstream_read(&bc, 4);\n            else bands[i].res[ch] = av_clip(bands[i-1].res[ch] + t, 0, 17);\n        }\n        if(bands[i].res[0] || bands[i].res[1]){\n            mb = i;\n            if (c->MSS)\n                bands[i].msf = bitstream_read_bit(&bc);\n        }\n    }\n    for(i = 0; i <= mb; i++)\n        for(ch = 0; ch < 2; ch++)\n            if (bands[i].res[ch])\n                bands[i].scfi[ch] = bitstream_read_vlc(&bc, scfi_vlc.table, MPC7_SCFI_BITS, 1);\n    for(i = 0; i <= mb; i++){\n        for(ch = 0; ch < 2; ch++){\n            if(bands[i].res[ch]){\n                bands[i].scf_idx[ch][2] = c->oldDSCF[ch][i];\n                bands[i].scf_idx[ch][0] = get_scale_idx(&bc, bands[i].scf_idx[ch][2]);\n                switch(bands[i].scfi[ch]){\n                case 0:\n                    bands[i].scf_idx[ch][1] = get_scale_idx(&bc, bands[i].scf_idx[ch][0]);\n                    bands[i].scf_idx[ch][2] = get_scale_idx(&bc, bands[i].scf_idx[ch][1]);\n                    break;\n                case 1:\n                    bands[i].scf_idx[ch][1] = get_scale_idx(&bc, bands[i].scf_idx[ch][0]);\n                    bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1];\n                    break;\n                case 2:\n                    bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0];\n                    bands[i].scf_idx[ch][2] = get_scale_idx(&bc, bands[i].scf_idx[ch][1]);\n                    break;\n                case 3:\n                    bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0];\n                    break;\n                }\n                c->oldDSCF[ch][i] = bands[i].scf_idx[ch][2];\n            }\n        }\n    }\n    memset(c->Q, 0, sizeof(c->Q));\n    off = 0;\n    for(i = 0; i < BANDS; i++, off += SAMPLES_PER_BAND)\n        for(ch = 0; ch < 2; ch++)\n            idx_to_quant(c, &bc, bands[i].res[ch], c->Q[ch] + off);\n    ff_mpc_dequantize_and_synth(c, mb, (int16_t **)frame->extended_data, 2);\n    bits_used = bitstream_tell(&bc);\n    bits_avail = buf_size * 8;\n    if (!last_frame && ((bits_avail < bits_used) || (bits_used + 32 <= bits_avail))) {\n        av_log(avctx, AV_LOG_ERROR, "Error decoding frame: used %i of %i bits\\n", bits_used, bits_avail);\n        return -1;\n    }\n    if(c->frames_to_skip){\n        c->frames_to_skip--;\n        *got_frame_ptr = 0;\n        return avpkt->size;\n    }\n    *got_frame_ptr = 1;\n    return avpkt->size;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n    if (!n)\n        return 0;\n    if (n > bc->bits_left) {\n        refill_32(bc);\n        if (bc->bits_left < 32)\n            bc->bits_left = n;\n    }\n    return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n    uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n    bc->bits >>= n;\n#else\n    uint64_t ret = bc->bits >> (64 - n);\n    bc->bits <<= n;\n#endif\n    bc->bits_left -= n;\n    return ret;\n}']