Changeset 107


Ignore:
Timestamp:
11/09/06 13:44:00 (17 years ago)
Author:
r2d
Message:
  • gapless playback should now be supported (not verified)
Location:
libmpcdec/branches/zorg
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libmpcdec/branches/zorg/include/mpcdec/mpcdec.h

    r104 r107  
    5858typedef struct mpc_frame_info_t {
    5959        mpc_uint32_t samples;   // number of samples in the frame
    60         mpc_uint32_t sample_freq;       // frame sample frequency
    61         mpc_uint8_t channels;   // number of channels
    6260        MPC_SAMPLE_FORMAT * buffer;     // frame samples buffer (size = samples * channels * sizeof(MPC_SAMPLE_FORMAT)
    6361} mpc_frame_info;
  • libmpcdec/branches/zorg/src/decoder.h

    r104 r107  
    6464    /// @name internal state variables
    6565    //@{
    66     mpc_uint32_t  SampleRate;                 // Sample frequency
    67     mpc_uint32_t  StreamVersion;              // version of bitstream
    68     mpc_uint32_t  Max_Band;
    69     mpc_uint32_t  MS_used;                    // MS-coding used ?
    70         mpc_uint32_t  TrueGaplessPresent;
    71         mpc_uint32_t  OverallFrames;              // number of frames in the stream, 0 = unknow
    72         mpc_uint32_t  LastFrameSamples;           // number of samples in the last frame
     66        mpc_uint32_t  stream_version; ///< Streamversion of stream
     67        mpc_uint32_t  max_band; ///< Maximum band-index used in stream (0...31)
     68        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
     72        mpc_uint32_t channels; ///< Number of channels in stream
    7373
    7474        mpc_uint32_t  samples_to_skip;
    75         mpc_uint32_t  DecodedFrames;
     75        mpc_uint32_t  decoded_frames;
    7676
    7777    // randomizer state variables
  • libmpcdec/branches/zorg/src/mpc_decoder.c

    r104 r107  
    8989void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si)
    9090{
    91         d->StreamVersion      = si->stream_version;
    92         d->MS_used            = si->ms;
    93         d->Max_Band           = si->max_band;
    94         d->OverallFrames      = si->frames;
    95         d->TrueGaplessPresent = si->is_true_gapless;
    96         d->SampleRate         = si->sample_freq;
     91        d->stream_version     = si->stream_version;
     92        d->ms                 = si->ms;
     93        d->max_band           = si->max_band;
     94        d->frames             = si->frames;
     95        d->is_true_gapless    = si->is_true_gapless;
     96        d->channels           = si->channels;
     97        d->last_frame_samples = si->last_frame_samples;
    9798}
    9899
     
    118119                                                          mpc_frame_info * i)
    119120{
    120         // FIXME : sauter décodage si d->samples_to_skip > MPC_FRAME_LENGTH pour sv7
    121         switch (d->StreamVersion) {
    122                 case 0x07:
    123                 case 0x17:
    124                 case 0x08:
    125                         i->channels = 2;
    126                         i->sample_freq = d->SampleRate;
    127                         i->samples = MPC_FRAME_LENGTH;
    128                         mpc_decoder_read_bitstream_sv7(d, r);
    129                         break;
     121        d->decoded_frames++;
     122
     123        if (d->decoded_frames > d->frames && !d->is_true_gapless) {
     124                mpc_decoder_reset_y(d);
     125        } else {
     126                mpc_decoder_read_bitstream_sv7(d, r);
     127                mpc_decoder_requantisierung(d);
    130128        }
    131 
    132         // synthesize signal
    133         mpc_decoder_requantisierung(d);
    134129        mpc_decoder_synthese_filter_float(d, i->buffer);
    135130
    136         d->DecodedFrames++;
    137 
    138 //     // cut off first MPC_DECODER_SYNTH_DELAY zero-samples
    139 //      if (d->DecodedFrames == d->OverallFrames  && d->StreamVersion >= 6) {
    140 //         // reconstruct exact filelength
    141 //              mpc_int32_t  mod_block   = mpc_bits_read(r,  11);
    142 //              mpc_int32_t  FilterDecay;
    143 //
    144 //              if (mod_block == 0) {
    145 //             // Encoder bugfix
    146 //                      mod_block = 1152;
    147 //              }
    148 //              FilterDecay = (mod_block + MPC_DECODER_SYNTH_DELAY) % MPC_FRAME_LENGTH;
    149 //
    150 //         // additional FilterDecay samples are needed for decay of synthesis filter
    151 //              if (MPC_DECODER_SYNTH_DELAY + mod_block >= MPC_FRAME_LENGTH) {
    152 //                      if (!d->TrueGaplessPresent) {
    153 //                              mpc_decoder_reset_y(d);
    154 //                      } else {
    155 //                              mpc_bits_read(r, 20);
    156 //                              mpc_decoder_read_bitstream_sv7(d, FALSE);
    157 //                              mpc_decoder_requantisierung(d, d->Max_Band);
    158 //                      }
    159 //
    160 //                      mpc_decoder_synthese_filter_float(d, buffer + 2304);
    161 //
    162 //                      i->samples = MPC_FRAME_LENGTH + FilterDecay;
    163 //              }
    164 //              else {                              // there are only FilterDecay samples needed for this frame
    165 //                      i->samples = FilterDecay;
    166 //              }
    167 //      }
     131    // cut off first MPC_DECODER_SYNTH_DELAY zero-samples
     132    // reconstruct exact filelength
     133        if (d->decoded_frames == d->frames && (d->stream_version & 15) == 7) {
     134                d->last_frame_samples = mpc_bits_read(r, 11);
     135                if (d->last_frame_samples == 0) {
     136            // Encoder bugfix
     137                        d->last_frame_samples = MPC_FRAME_LENGTH;
     138                }
     139        }
     140
     141        mpc_int32_t samples_left = d->last_frame_samples + MPC_DECODER_SYNTH_DELAY
     142                        + (d->frames - d->decoded_frames) * MPC_FRAME_LENGTH;
     143
     144        i->samples = samples_left > MPC_FRAME_LENGTH ? MPC_FRAME_LENGTH : samples_left < 0 ? 0 : samples_left;
    168145
    169146        if (d->samples_to_skip) {
     
    173150                } else {
    174151                        i->samples -= d->samples_to_skip;
    175                         memmove(i->buffer, i->buffer + d->samples_to_skip * i->channels,
    176                                         i->samples * i->channels * sizeof (MPC_SAMPLE_FORMAT));
     152                        memmove(i->buffer, i->buffer + d->samples_to_skip * d->channels,
     153                                        i->samples * d->channels * sizeof (MPC_SAMPLE_FORMAT));
    177154                        d->samples_to_skip = 0;
    178155                }
     
    193170    mpc_int32_t*    L;
    194171    mpc_int32_t*    R;
    195         const mpc_int32_t Last_Band = d->Max_Band;
     172        const mpc_int32_t Last_Band = d->max_band;
    196173
    197174#ifdef MPC_FIXED_POINT
     
    363340    *ResL = mpc_bits_read(r, 4);
    364341    *ResR = mpc_bits_read(r, 4);
    365     if (d->MS_used && !(*ResL==0 && *ResR==0)) {
     342        if (d->ms && !(*ResL==0 && *ResR==0)) {
    366343        d->MS_Flag[0] = mpc_bits_read(r, 1);
    367344    }
     
    369346    // consecutive subbands
    370347    ++ResL; ++ResR; // increase pointers
    371     for (n=1; n <= d->Max_Band; ++n, ++ResL, ++ResR)
     348        for (n=1; n <= d->max_band; ++n, ++ResL, ++ResR)
    372349    {
    373350                idx   = mpc_bits_huff_dec(r, mpc_table_HuffHdr);
     
    377354        *ResR = (idx!=4) ? *(ResR-1) + idx : (int) mpc_bits_read(r, 4);
    378355
    379         if (d->MS_used && !(*ResL==0 && *ResR==0)) {
     356                if (d->ms && !(*ResL==0 && *ResR==0)) {
    380357            d->MS_Flag[n] = mpc_bits_read(r, 1);
    381358        }
  • libmpcdec/branches/zorg/src/mpc_demux.c

    r104 r107  
    172172void mpc_demux_decode(mpc_demux * d, mpc_frame_info * i)
    173173{
    174         i->samples = 0;
    175         if (d->d->OverallFrames != 0 && d->d->DecodedFrames == d->d->OverallFrames)
    176                 return;
    177174        if (d->si.stream_version == 8) {
    178175                mpc_bits_reader r;
    179                 if (d->block_bits < 8){
     176                if (d->block_bits < 8 && (d->d->decoded_frames < d->d->frames || d->d->frames == 0)){
    180177                        mpc_block b;
    181178                        d->bits_reader.count &= -8;
     
    195192                d->block_bits -= (d->bits_reader.buff - r.buff) * 8 + r.count - d->bits_reader.count;
    196193        } else {
    197                 int frame_size;
    198194                mpc_bits_reader r;
    199195                mpc_demux_fill(d, MAX_FRAME_SIZE, MPC_BUFFER_FULL | MPC_BUFFER_SWAP);
    200                 frame_size = mpc_bits_read(&d->bits_reader, 20); // read frame size
     196                mpc_bits_read(&d->bits_reader, 20); // read frame size
    201197                r = d->bits_reader;
    202198                mpc_decoder_decode_frame(d->d, &d->bits_reader, i);
    203                 if ((d->bits_reader.buff - r.buff) * 8 + r.count - d->bits_reader.count != frame_size){
    204                         frame_size--;
    205                         frame_size += 1;
    206                 }
    207199        }
    208200}
     
    215207//      mpc_uint32_t  FrameBitCnt = 0;
    216208//
    217 //      if (d->DecodedFrames >= d->OverallFrames) {
     209//      if (d->decoded_frames >= d->OverallFrames) {
    218210//              return (mpc_uint32_t)(-1);                           // end of file -> abort decoding
    219211//      }
    220212//
    221213//     // add seeking info
    222 //      if (d->seeking_table_frames < d->DecodedFrames &&
    223 //                 (d->DecodedFrames & ((1 << d->seeking_pwr) - 1)) == 0) {
    224 //              d->seeking_table[d->DecodedFrames >> d->seeking_pwr] = mpc_decoder_bits_read(d);
    225 //              d->seeking_table_frames = d->DecodedFrames;
     214//      if (d->seeking_table_frames < d->decoded_frames &&
     215//                 (d->decoded_frames & ((1 << d->seeking_pwr) - 1)) == 0) {
     216//              d->seeking_table[d->decoded_frames >> d->seeking_pwr] = mpc_decoder_bits_read(d);
     217//              d->seeking_table_frames = d->decoded_frames;
    226218//                 }
    227219//
Note: See TracChangeset for help on using the changeset viewer.