Ignore:
Timestamp:
11/13/06 20:13:18 (18 years ago)
Author:
r2d
Message:
  • changed decoder struct and length computations
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.