Ignore:
Timestamp:
10/31/06 11:47:09 (18 years ago)
Author:
r2d
Message:
  • first SV8 decoding, it's VERY BADLY implemented. To enable decoding, MPC_LITTLE_ENDIAN must NOT be defined on 386 (so sv7 doesn't work in the same time). Was just to verify that there is no bug in encoding (found 1 !)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libmpcdec/branches/zorg/src/mpc_reader.c

    r70 r81  
    8888
    8989mpc_status
    90 mpc_reader_init_stdio(mpc_reader *p_reader, char *filename)
     90mpc_reader_init_stdio(mpc_reader *p_reader, const char *filename)
    9191{
    9292    mpc_reader tmp_reader; mpc_reader_stdio *p_stdio; int err;
     
    149149    ret = p_reader->seek(p_reader, 0);
    150150    if(!ret) return 0;
    151    
     151
    152152    p_reader->read(p_reader, tmp, sizeof tmp);
    153153
     
    178178    return ret;
    179179}
     180
     181mpc_status mpc_get_block(mpc_reader * p_reader, mpc_block_t * p_block)
     182{
     183        unsigned char tmp;
     184        unsigned int size = 2;
     185
     186        p_block->size = 0;
     187        p_reader->read(p_reader, p_block->key, 2);
     188        do {
     189                p_reader->read(p_reader, &tmp, 1);
     190                p_block->size = (p_block->size << 7) | (tmp & 0x7F);
     191                size++;
     192        } while((tmp & 0x80));
     193
     194        if (size > p_block->size)
     195                return MPC_STATUS_FILE;
     196
     197        p_block->size -= size;
     198
     199        return MPC_STATUS_OK;
     200}
     201
     202mpc_status mpc_find_block(mpc_reader * p_reader, mpc_block_t * p_block,
     203                                                  char * find_key, char * stop_key)
     204{
     205        while (1) {
     206                mpc_get_block(p_reader, p_block);
     207                if (memcmp(p_block->key, find_key, 2) != 0 &&
     208                                  memcmp(p_block->key, stop_key, 2) != 0)
     209                        p_reader->seek(p_reader, p_block->size);
     210                else
     211                        break;
     212        }
     213
     214        if (memcmp(p_block->key, find_key, 2) != 0)
     215                return MPC_STATUS_FILE;
     216
     217        return MPC_STATUS_OK;
     218}
     219
     220mpc_uint32_t mpc_read_bits(mpc_reader * p_reader, mpc_bits_reader * p_bits,
     221                                                   int nb_bits)
     222{
     223        mpc_uint32_t ret = p_bits->buff;
     224        unsigned char tmp = 0;
     225
     226        while(nb_bits > p_bits->bitsCount){
     227                p_reader->read(p_reader, &tmp, 1);
     228                ret = (ret << 8) | tmp;
     229                p_bits->bitsCount += 8;
     230        }
     231
     232        p_bits->buff = (unsigned int) ret;
     233        p_bits->bitsCount -= nb_bits;
     234        ret >>= p_bits->bitsCount;
     235
     236        if (nb_bits == 32)
     237                return ret;
     238        else
     239                return ret & ((1 << nb_bits) - 1);
     240}
     241
Note: See TracChangeset for help on using the changeset viewer.