Ignore:
Timestamp:
02/17/07 16:14:53 (18 years ago)
Author:
r2d
Message:
  • speed improvements (mainly inlining)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libmpc/branches/r2d/libmpcdec/mpc_bits_reader.c

    r195 r219  
    11/*
    2   Copyright (c) 2005, The Musepack Development Team
     2  Copyright (c) 2007, The Musepack Development Team
    33  All rights reserved.
    44
     
    3636#include "internal.h"
    3737#include "huffman.h"
     38#include "mpc_bits_reader.h"
    3839
    39 #define MAX_ENUM 32
    40 
    41 static const mpc_uint32_t Cnk[MAX_ENUM / 2][MAX_ENUM] =
     40const mpc_uint32_t Cnk[MAX_ENUM / 2][MAX_ENUM] =
    4241{
    4342        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31},
     
    5958};
    6059
    61 static const mpc_uint8_t Cnk_len[MAX_ENUM / 2][MAX_ENUM] =
     60const mpc_uint8_t Cnk_len[MAX_ENUM / 2][MAX_ENUM] =
    6261{
    6362        {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5},
     
    8079};
    8180
    82 static const mpc_uint32_t Cnk_lost[MAX_ENUM / 2][MAX_ENUM] =
     81const mpc_uint32_t Cnk_lost[MAX_ENUM / 2][MAX_ENUM] =
    8382{
    8483        {0, 0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
     
    105104static const mpc_uint8_t log2_lost[32] =
    106105{ 0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31};
    107 
    108 // FIXME : make it work without 64 bit use for 32 bit output
    109 mpc_uint32_t mpc_bits_read(mpc_bits_reader * r, const unsigned int nb_bits)
    110 {
    111         mpc_uint64_t ret = r->buff[0];
    112 
    113         while(nb_bits > r->count){
    114                 r->buff++;
    115                 ret = (ret << 8) | r->buff[0];
    116                 r->count += 8;
    117         }
    118 
    119         r->count -= nb_bits;
    120 
    121         return (mpc_uint32_t)((ret >> r->count) & (-1u >> (32 - nb_bits)));
    122 }
    123 
    124 // basic huffman decoding routine
    125 // works with maximum lengths up to 16
    126 mpc_int32_t mpc_bits_huff_dec(mpc_bits_reader * r, const mpc_huffman *Table)
    127 {
    128     int tmp; mpc_uint32_t code;
    129     code = ((r->buff[0] << 16) | (r->buff[1] << 8) | r->buff[2])
    130                         << (16 - r->count);
    131 
    132         while (code < Table->Code) Table++;
    133 
    134         tmp = r->count - Table->Length;
    135         r->buff -= tmp >> 3;
    136         r->count = tmp & 0x07;
    137 
    138         return Table->Value;
    139 }
    140106
    141107mpc_int32_t mpc_bits_golomb_dec(mpc_bits_reader * r, const mpc_uint_t k)
     
    166132
    167133        return (l << k) | ((code >> r->count) & ((1 << k) - 1));
    168 }
    169 
    170 mpc_uint32_t mpc_bits_enum_dec(mpc_bits_reader * r, mpc_uint_t k, mpc_uint_t n)
    171 {
    172         mpc_uint32_t bits = 0;
    173         mpc_uint32_t code;
    174         const mpc_uint32_t * C = Cnk[k-1];
    175 
    176         code = mpc_bits_read(r, Cnk_len[k-1][n-1] - 1);
    177 
    178         if (code >= Cnk_lost[k-1][n-1])
    179                 code = ((code << 1) | mpc_bits_read(r, 1)) - Cnk_lost[k-1][n-1];
    180 
    181         do {
    182                 n--;
    183                 if (code >= C[n]) {
    184                         bits |= 1 << n;
    185                         code -= C[n];
    186                         C -= MAX_ENUM;
    187                         k--;
    188                 }
    189         } while(k > 0);
    190 
    191         return bits;
    192134}
    193135
Note: See TracChangeset for help on using the changeset viewer.