Changeset 126 for libmpcdec/branches/zorg
- Timestamp:
- 11/13/06 20:13:18 (18 years ago)
- Location:
- libmpcdec/branches/zorg/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpcdec/branches/zorg/src/decoder.h
r108 r126 67 67 mpc_uint32_t max_band; ///< Maximum band-index used in stream (0...31) 68 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 stream71 mpc_uint32_t last_frame_samples; ///< Number of valid samples within last frame72 69 mpc_uint32_t channels; ///< Number of channels in stream 73 70 71 mpc_uint64_t samples; ///< Number of samples in stream 72 73 mpc_uint64_t decoded_samples; ///< Number of samples decoded from file begining 74 74 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 begining76 75 77 76 // randomizer state variables -
libmpcdec/branches/zorg/src/mpc_decoder.c
r108 r126 70 70 static void mpc_decoder_requantisierung(mpc_decoder *d); 71 71 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 // } 77 77 78 78 void mpc_decoder_setup(mpc_decoder *d) … … 92 92 d->ms = si->ms; 93 93 d->max_band = si->max_band; 94 d->frames = si->frames;95 d->is_true_gapless = si->is_true_gapless;96 94 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; 98 100 } 99 101 … … 119 121 mpc_frame_info * i) 120 122 { 123 mpc_bits_reader r_sav = *r; 121 124 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; 127 129 } 130 131 mpc_decoder_read_bitstream_sv7(d, r); 132 mpc_decoder_requantisierung(d); 128 133 mpc_decoder_synthese_filter_float(d, i->buffer); 129 134 130 d->decoded_frames++; 131 132 // cut off first MPC_DECODER_SYNTH_DELAY zero-samples 135 d->decoded_samples += MPC_FRAME_LENGTH; 136 133 137 // 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; 142 145 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; 145 147 146 148 if (d->samples_to_skip) { -
libmpcdec/branches/zorg/src/mpc_demux.c
r117 r126 119 119 120 120 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) { 123 124 mpc_demux_fill(d, 6 * 4, MPC_BUFFER_SWAP); // header block size + endian convertion 124 125 streaminfo_read_header_sv7(&d->si, &d->bits_reader); … … 183 184 if (d->si.stream_version == 8) { 184 185 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)){ 186 187 mpc_block b; 187 188 d->bits_reader.count &= -8; … … 199 200 r = d->bits_reader; 200 201 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; 202 203 } else { 203 204 mpc_bits_reader r; -
libmpcdec/branches/zorg/src/streaminfo.c
r117 r126 99 99 { 100 100 mpc_uint16_t Estimatedpeak_title = 0; 101 mpc_uint32_t frames, last_frame_samples; 101 102 102 103 si->bitrate = 0; 103 si->frames= mpc_bits_read(r, 32);104 frames = mpc_bits_read(r, 32); 104 105 mpc_bits_read(r, 1); // intensity stereo : should be 0 105 106 si->ms = mpc_bits_read(r, 1); … … 115 116 si->peak_album = (mpc_uint16_t) mpc_bits_read(r, 16); 116 117 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 frame118 last_frame_samples = mpc_bits_read(r, 11); // true gapless: valid samples for last frame 118 119 si->fast_seek = mpc_bits_read(r, 1); // fast seeking 119 120 mpc_bits_read(r, 19); // unused … … 123 124 mpc_get_encoder_string(si); 124 125 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; 131 135 132 136 return MPC_STATUS_OK; … … 138 142 { 139 143 mpc_uint32_t CRC; 140 mpc_uint64_t sampleCount = 0;141 144 mpc_bits_reader r = *r_in; 142 145 … … 144 147 CRC = mpc_bits_read(&r, 32); 145 148 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); 148 150 si->is_true_gapless = 1; 149 si->last_frame_samples = sampleCount - (si->frames - 1) * MPC_FRAME_LENGTH;150 151 si->sample_freq = samplefreqs[mpc_bits_read(&r, 4)]; 151 152 si->channels = mpc_bits_read(&r, 4) + 1; … … 156 157 si->bitrate = 0; 157 158 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; 163 161 164 162 return MPC_STATUS_OK; … … 198 196 mpc_streaminfo_get_length(mpc_streaminfo * si) 199 197 { 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 201 mpc_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.