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_decoder.c

    r70 r81  
    7070// forward declarations
    7171//------------------------------------------------------------------------------
    72 static void mpc_decoder_read_bitstream_sv6(mpc_decoder *d, mpc_bool_t seeking);
    7372static void mpc_decoder_read_bitstream_sv7(mpc_decoder *d, mpc_bool_t seeking);
    7473static void mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band);
     
    7776// utility functions
    7877//------------------------------------------------------------------------------
    79 static mpc_int32_t f_read(mpc_decoder *d, void *ptr, mpc_int32_t size) 
    80 { 
    81     return d->r->read(d->r, ptr, size); 
    82 }
    83 
    84 static mpc_bool_t f_seek(mpc_decoder *d, mpc_int32_t offset) 
    85 { 
    86     return d->r->seek(d->r, offset); 
    87 }
    88 
    89 static mpc_int32_t f_read_dword(mpc_decoder *d, mpc_uint32_t * ptr, mpc_uint32_t count) 
     78static mpc_int32_t f_read(mpc_decoder *d, void *ptr, mpc_int32_t size)
     79{
     80    return d->r->read(d->r, ptr, size);
     81}
     82
     83static mpc_bool_t f_seek(mpc_decoder *d, mpc_int32_t offset)
     84{
     85    return d->r->seek(d->r, offset);
     86}
     87
     88static mpc_int32_t f_read_dword(mpc_decoder *d, mpc_uint32_t * ptr, mpc_uint32_t count)
    9089{
    9190    return f_read(d, ptr, count << 2) >> 2;
     
    130129// resets bitstream decoding
    131130static void
    132 mpc_decoder_reset_bitstream_decode(mpc_decoder *d) 
     131mpc_decoder_reset_bitstream_decode(mpc_decoder *d)
    133132{
    134133    d->dword = 0;
     
    140139// reports the number of read bits
    141140static mpc_uint32_t
    142 mpc_decoder_bits_read(mpc_decoder *d) 
     141mpc_decoder_bits_read(mpc_decoder *d)
    143142{
    144143    return 32 * d->WordsRead + d->pos;
     
    147146// read desired number of bits out of the bitstream (max 31)
    148147static mpc_uint32_t
    149 mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits) 
     148mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits)
    150149{
    151150    mpc_uint32_t out = d->dword;
     
    191190}
    192191
    193 // decode SCFI-bundle (sv4,5,6)
     192void mpc_decoder_get_block(mpc_decoder *d, mpc_block_t * p_block)
     193{
     194        unsigned char tmp;
     195        unsigned int size = 2;
     196
     197        p_block->size = 0;
     198        p_block->key[0] = mpc_decoder_bitstream_read(d, 8);
     199        p_block->key[1] = mpc_decoder_bitstream_read(d, 8);
     200        do {
     201                tmp = mpc_decoder_bitstream_read(d, 8);
     202                p_block->size = (p_block->size << 7) | (tmp & 0x7F);
     203                size++;
     204        } while((tmp & 0x80));
     205
     206        p_block->size -= size;
     207}
     208
    194209static void
    195 mpc_decoder_scfi_bundle_read(mpc_decoder *d, const mpc_huffman* Table,
    196                              mpc_int32_t* SCFI, mpc_bool_t* DSCF)
    197 {
    198     mpc_uint32_t value = mpc_decoder_huffman_decode(d, Table, 6);
    199 
    200     *SCFI = value >> 1;
    201     *DSCF = value &  1;
    202 }
    203 
    204 static void
    205 mpc_decoder_reset_v(mpc_decoder *d)
     210mpc_decoder_reset_v(mpc_decoder *d)
    206211{
    207212    memset(d->V_L, 0, sizeof d->V_L);
     
    210215
    211216static void
    212 mpc_decoder_reset_synthesis(mpc_decoder *d) 
     217mpc_decoder_reset_synthesis(mpc_decoder *d)
    213218{
    214219    mpc_decoder_reset_v(d);
     
    216221
    217222static void
    218 mpc_decoder_reset_y(mpc_decoder *d) 
     223mpc_decoder_reset_y(mpc_decoder *d)
    219224{
    220225    memset(d->Y_L, 0, sizeof d->Y_L);
     
    223228
    224229static void
    225 mpc_decoder_reset_globals(mpc_decoder *d) 
     230mpc_decoder_reset_globals(mpc_decoder *d)
    226231{
    227232    mpc_decoder_reset_bitstream_decode(d);
     
    268273
    269274static mpc_uint32_t
    270 mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer) 
     275mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer)
    271276{
    272277    mpc_uint32_t output_frame_length = MPC_FRAME_LENGTH;
     
    285290    }
    286291
    287     // read jump-info for validity check of frame
    288     FwdJumpInfo  = mpc_decoder_bitstream_read(d, 20);
    289 
    290     // decode data and check for validity of frame
    291     FrameBitCnt = mpc_decoder_bits_read(d);
    292292    switch (d->StreamVersion) {
    293293    case 0x07:
    294294    case 0x17:
     295                // read jump-info for validity check of frame
     296                FwdJumpInfo  = mpc_decoder_bitstream_read(d, 20);
     297        // decode data and check for validity of frame
     298                FrameBitCnt = mpc_decoder_bits_read(d);
    295299        mpc_decoder_read_bitstream_sv7(d, FALSE);
     300                d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == FwdJumpInfo;
    296301        break;
     302        case 0x08:
     303                if (d->BlockBits < 8){
     304                        mpc_block_t block;
     305                        // trouver le block
     306                        mpc_decoder_bitstream_read(d, d->BlockBits);
     307                        while (1) {
     308                                mpc_decoder_get_block(d, &block);
     309                                if (memcmp(block.key, "AD", 2) != 0)
     310                                        mpc_decoder_seek(d, mpc_decoder_bits_read(d) + block.size * 8);
     311                                else
     312                                        break;
     313                        }
     314                        d->BlockBits = block.size * 8;
     315                }
     316                FrameBitCnt = mpc_decoder_bits_read(d);
     317                mpc_decoder_read_bitstream_sv7(d, FALSE);
     318                d->BlockBits -= mpc_decoder_bits_read(d) - FrameBitCnt;
     319                d->FrameWasValid = 1;
     320                break;
    297321    default:
    298322        return (mpc_uint32_t)(-1);
    299323    }
    300     d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == FwdJumpInfo;
    301324
    302325    // synthesize signal
     
    307330
    308331    // cut off first MPC_DECODER_SYNTH_DELAY zero-samples
    309     if (d->DecodedFrames == d->OverallFrames  && d->StreamVersion >= 6) {       
     332    if (d->DecodedFrames == d->OverallFrames  && d->StreamVersion >= 6) {
    310333        // reconstruct exact filelength
    311334        mpc_int32_t  mod_block   = mpc_decoder_bitstream_read(d,  11);
     
    314337        if (mod_block == 0) {
    315338            // Encoder bugfix
    316             mod_block = 1152;                   
     339            mod_block = 1152;
    317340        }
    318341        FilterDecay = (mod_block + MPC_DECODER_SYNTH_DELAY) % MPC_FRAME_LENGTH;
     
    345368            output_frame_length -= d->samples_to_skip;
    346369            memmove(
    347                 buffer, 
    348                 buffer + d->samples_to_skip * 2, 
     370                buffer,
     371                buffer + d->samples_to_skip * 2,
    349372                output_frame_length * 2 * sizeof (MPC_SAMPLE_FORMAT));
    350373            d->samples_to_skip = 0;
     
    357380mpc_uint32_t mpc_decoder_decode(
    358381    mpc_decoder *d,
    359     MPC_SAMPLE_FORMAT *buffer, 
    360     mpc_uint32_t *vbr_update_acc, 
     382    MPC_SAMPLE_FORMAT *buffer,
     383    mpc_uint32_t *vbr_update_acc,
    361384    mpc_uint32_t *vbr_update_bits)
    362385{
     
    378401            // error occurred in bitstream
    379402            return (mpc_uint32_t)(-1);
    380         } 
     403        }
    381404        else {
    382405            if (vbr_update_acc && vbr_update_bits) {
     
    399422
    400423void
    401 mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) 
     424mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band)
    402425{
    403426    mpc_int32_t     Band;
     
    855878  d->__r1 = 1;
    856879  d->__r2 = 1;
     880  d->BlockBits = 0;
    857881
    858882  d->Max_Band = 0;
     
    872896    case  0x07:
    873897    case  0x17: fpos = 200; break;
     898        case  0x08: fpos = 32; break;
    874899    }
    875900    return fpos;
     
    892917}
    893918
    894 mpc_status mpc_decoder_init(mpc_decoder **d, mpc_reader *r, mpc_streaminfo *si) 
     919mpc_status mpc_decoder_init(mpc_decoder **d, mpc_reader *r, mpc_streaminfo *si)
    895920{
    896921    mpc_decoder* p_tmp;
    897    
     922
    898923    p_tmp = malloc(sizeof *p_tmp);
    899924    memset(p_tmp, 0, sizeof *p_tmp);
     
    927952}
    928953
    929 mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds) 
     954mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds)
    930955{
    931956    return mpc_decoder_seek_sample(d, (mpc_int64_t)(seconds * (double)d->SampleRate + 0.5));
    932957}
    933958
    934 mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample) 
     959mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
    935960{
    936961    mpc_uint32_t fpos;
Note: See TracChangeset for help on using the changeset viewer.