Changeset 126


Ignore:
Timestamp:
11/13/06 20:13:18 (15 years ago)
Author:
r2d
Message:
  • changed decoder struct and length computations
Location:
libmpcdec/branches/zorg/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libmpcdec/branches/zorg/src/decoder.h

    r108 r126  
    6767        mpc_uint32_t max_band;           ///< Maximum band-index used in stream (0...31)
    6868        mpc_uint32_t ms;                 ///< Mid/side stereo (0: off, 1: on)
    69         mpc_uint32_t is_true_gapless;    ///< True gapless? (0: no, 1: yes)
    70         mpc_uint32_t frames;             ///< Number of frames in stream
    71         mpc_uint32_t last_frame_samples; ///< Number of valid samples within last frame
    7269        mpc_uint32_t channels;           ///< Number of channels in stream
    7370
     71        mpc_uint64_t samples;            ///< Number of samples in stream
     72
     73        mpc_uint64_t decoded_samples;    ///< Number of samples decoded from file begining
    7474        mpc_uint32_t samples_to_skip;    ///< Number samples to skip (used for seeking)
    75         mpc_uint32_t decoded_frames;     ///< Number of frames decoded from file begining
    7675
    7776    // randomizer state variables
  • libmpcdec/branches/zorg/src/mpc_decoder.c

    r108 r126  
    7070static void mpc_decoder_requantisierung(mpc_decoder *d);
    7171
    72 static void mpc_decoder_reset_y(mpc_decoder *d)
    73 {
    74         memset(d->Y_L, 0, sizeof d->Y_L);
    75         memset(d->Y_R, 0, sizeof d->Y_R);
    76 }
     72// static void mpc_decoder_reset_y(mpc_decoder *d)
     73// {
     74//      memset(d->Y_L, 0, sizeof d->Y_L);
     75//      memset(d->Y_R, 0, sizeof d->Y_R);
     76// }
    7777
    7878void mpc_decoder_setup(mpc_decoder *d)
     
    9292        d->ms                 = si->ms;
    9393        d->max_band           = si->max_band;
    94         d->frames             = si->frames;
    95         d->is_true_gapless    = si->is_true_gapless;
    9694        d->channels           = si->channels;
    97         d->last_frame_samples = si->last_frame_samples;
     95
     96        if (si->stream_version == 7 && si->is_true_gapless)
     97                d->samples = ((si->samples + MPC_FRAME_LENGTH - 1) / MPC_FRAME_LENGTH) * MPC_FRAME_LENGTH;
     98        else
     99                d->samples = si->samples;
    98100}
    99101
     
    119121                                                          mpc_frame_info * i)
    120122{
     123        mpc_bits_reader r_sav = *r;
    121124        mpc_int64_t samples_left;
    122         if (d->decoded_frames >= d->frames && !d->is_true_gapless) {
    123                 mpc_decoder_reset_y(d);
    124         } else {
    125                 mpc_decoder_read_bitstream_sv7(d, r);
    126                 mpc_decoder_requantisierung(d);
     125
     126        if (d->decoded_samples >= d->samples && d->samples != 0) {
     127                i->samples = 0;
     128                return;
    127129        }
     130
     131        mpc_decoder_read_bitstream_sv7(d, r);
     132        mpc_decoder_requantisierung(d);
    128133        mpc_decoder_synthese_filter_float(d, i->buffer);
    129134
    130         d->decoded_frames++;
    131 
    132     // cut off first MPC_DECODER_SYNTH_DELAY zero-samples
     135        d->decoded_samples += MPC_FRAME_LENGTH;
     136
    133137    // reconstruct exact filelength
    134         if (d->decoded_frames == d->frames && (d->stream_version & 15) == 7 &&
    135                 (d->last_frame_samples = mpc_bits_read(r, 11)) == 0)
    136                 // Encoder bugfix
    137                 d->last_frame_samples = MPC_FRAME_LENGTH;
    138 
    139         samples_left = d->last_frame_samples + MPC_DECODER_SYNTH_DELAY
    140                         + ((mpc_int64_t)d->frames - d->decoded_frames) * MPC_FRAME_LENGTH;
    141 
     138        if (d->decoded_samples == d->samples && d->stream_version == 7) {
     139                int last_frame_samples = mpc_bits_read(r, 11);
     140                if (last_frame_samples == 0) last_frame_samples = MPC_FRAME_LENGTH;
     141                d->samples += last_frame_samples - MPC_FRAME_LENGTH;
     142        }
     143
     144        samples_left = d->samples - d->decoded_samples + MPC_DECODER_SYNTH_DELAY;
    142145        i->samples = samples_left > MPC_FRAME_LENGTH ? MPC_FRAME_LENGTH : samples_left < 0 ? 0 : samples_left;
    143 
    144         if (samples_left <= MPC_FRAME_LENGTH) d->is_true_gapless = 0;
     146        i->bits = ((r->buff - r_sav.buff) << 3) + r_sav.count - r->count;
    145147
    146148        if (d->samples_to_skip) {
  • libmpcdec/branches/zorg/src/mpc_demux.c

    r117 r126  
    119119
    120120        if (memcmp(magic, "MP+", 3) == 0) {
    121                 d->si.stream_version = magic[3];
    122                 if ((d->si.stream_version & 15) == 7) {
     121                d->si.stream_version = magic[3] & 15;
     122                d->si.pns = magic[3] >> 4;
     123                if (d->si.stream_version == 7) {
    123124                        mpc_demux_fill(d, 6 * 4, MPC_BUFFER_SWAP); // header block size + endian convertion
    124125                        streaminfo_read_header_sv7(&d->si, &d->bits_reader);
     
    183184        if (d->si.stream_version == 8) {
    184185                mpc_bits_reader r;
    185                 if (d->block_bits < 8 && (d->d->decoded_frames < d->d->frames || d->d->frames == 0)){
     186                if (d->block_bits < 8 && (d->d->decoded_samples < d->d->samples || d->d->samples == 0)){
    186187                        mpc_block b;
    187188                        d->bits_reader.count &= -8;
     
    199200                r = d->bits_reader;
    200201                mpc_decoder_decode_frame(d->d, &d->bits_reader, i);
    201                 d->block_bits -= (d->bits_reader.buff - r.buff) * 8 + r.count - d->bits_reader.count;
     202                d->block_bits -= ((d->bits_reader.buff - r.buff) << 3) + r.count - d->bits_reader.count;
    202203        } else {
    203204                mpc_bits_reader r;
  • libmpcdec/branches/zorg/src/streaminfo.c

    r117 r126  
    9999{
    100100    mpc_uint16_t Estimatedpeak_title = 0;
     101        mpc_uint32_t frames, last_frame_samples;
    101102
    102103        si->bitrate            = 0;
    103         si->frames             = mpc_bits_read(r, 32);
     104        frames                 = mpc_bits_read(r, 32);
    104105        mpc_bits_read(r, 1); // intensity stereo : should be 0
    105106        si->ms                 = mpc_bits_read(r, 1);
     
    115116        si->peak_album         = (mpc_uint16_t) mpc_bits_read(r, 16);
    116117        si->is_true_gapless    = mpc_bits_read(r, 1); // true gapless: used?
    117         si->last_frame_samples = mpc_bits_read(r, 11); // true gapless: valid samples for last frame
     118        last_frame_samples    = mpc_bits_read(r, 11); // true gapless: valid samples for last frame
    118119        si->fast_seek          = mpc_bits_read(r, 1); // fast seeking
    119120        mpc_bits_read(r, 19); // unused
     
    123124        mpc_get_encoder_string(si);
    124125
    125         // estimation, exact value needs too much time
    126         si->pcm_samples     = 1152 * si->frames - 576;
    127         si->average_bitrate = 0;
    128         if (si->pcm_samples > 0)
    129                 si->average_bitrate = (si->tag_offset  - si->header_position) * 8.0
    130                                 *  si->sample_freq / si->pcm_samples;
     126        if (last_frame_samples == 0) last_frame_samples = MPC_FRAME_LENGTH;
     127        si->samples = (mpc_int64_t) frames * MPC_FRAME_LENGTH;
     128        if (si->is_true_gapless)
     129                si->samples -= (MPC_FRAME_LENGTH - last_frame_samples);
     130        else
     131                si->samples -= MPC_DECODER_SYNTH_DELAY;
     132
     133        si->average_bitrate = (si->tag_offset  - si->header_position) * 8.0
     134                        *  si->sample_freq / si->samples;
    131135
    132136    return MPC_STATUS_OK;
     
    138142{
    139143        mpc_uint32_t CRC;
    140         mpc_uint64_t sampleCount = 0;
    141144        mpc_bits_reader r = *r_in;
    142145
     
    144147        CRC = mpc_bits_read(&r, 32);
    145148        si->stream_version = mpc_bits_read(&r, 8);
    146         mpc_bits_get_size(&r, &sampleCount);
    147         si->frames = (sampleCount + MPC_FRAME_LENGTH - 1) / MPC_FRAME_LENGTH;
     149        mpc_bits_get_size(&r, &si->samples);
    148150        si->is_true_gapless = 1;
    149         si->last_frame_samples = sampleCount - (si->frames - 1) * MPC_FRAME_LENGTH;
    150151        si->sample_freq = samplefreqs[mpc_bits_read(&r, 4)];
    151152        si->channels = mpc_bits_read(&r, 4) + 1;
     
    156157        si->bitrate = 0;
    157158
    158         si->pcm_samples     = sampleCount;
    159         si->average_bitrate = 0;
    160         if (si->pcm_samples > 0)
    161                 si->average_bitrate = (si->tag_offset - si->header_position) * 8.0
    162                                 *  si->sample_freq / si->pcm_samples;
     159        si->average_bitrate = (si->tag_offset - si->header_position) * 8.0
     160                        *  si->sample_freq / si->samples;
    163161
    164162        return MPC_STATUS_OK;
     
    198196mpc_streaminfo_get_length(mpc_streaminfo * si)
    199197{
    200     return (double) mpc_streaminfo_get_length_samples(si) / si->sample_freq;
    201 }
    202 
    203 mpc_int64_t
    204 mpc_streaminfo_get_length_samples(mpc_streaminfo * si)
    205 {
    206     mpc_int64_t samples = (mpc_int64_t) si->frames * MPC_FRAME_LENGTH;
    207     if (si->is_true_gapless)
    208         samples -= (MPC_FRAME_LENGTH - si->last_frame_samples);
    209     else
    210         samples -= MPC_DECODER_SYNTH_DELAY;
    211     return samples;
    212 }
     198    return (double) si->samples / si->sample_freq;
     199}
     200
     201mpc_int64_t mpc_streaminfo_get_length_samples(mpc_streaminfo *si)
     202{
     203        return si->samples;
     204}
Note: See TracChangeset for help on using the changeset viewer.