Index: apps/codecs/libmusepack/mpc_demux.c =================================================================== --- apps/codecs/libmusepack/mpc_demux.c (revision 25994) +++ apps/codecs/libmusepack/mpc_demux.c (working copy) @@ -122,22 +122,57 @@ mpc_demux_seek(mpc_demux * d, mpc_seek_t fpos, mpc_uint32_t min_bytes) { mpc_seek_t next_pos; mpc_int_t bit_offset; + mpc_seek_t tell_pos = d->r->tell(d->r) - d->bytes_total; +// static int no_flush = 0; +// static int cnt_flush = 0; // FIXME : do not flush the buffer if fpos is in the current buffer - - next_pos = fpos >> 3; - if (d->si.stream_version == 7) - next_pos = ((next_pos - d->si.header_position) & (-1 << 2)) + d->si.header_position; - bit_offset = (int) (fpos - (next_pos << 3)); - - d->r->seek(d->r, (mpc_int32_t) next_pos); - mpc_demux_clear_buff(d); - if (d->si.stream_version == 7) - mpc_demux_fill(d, (min_bytes + ((bit_offset + 7) >> 3) + 3) & (~3), MPC_BUFFER_SWAP); + /* + printf("d->bits_reader.buff = %d\n", d->bits_reader.buff); + printf("d->buffer = %d\n", d->buffer); + printf("d->bytes_total = %d\n", d->bytes_total); + printf("tell_pos = %d\n", tell_pos); + printf("fpos/8 = %d\n", fpos>>3); + printf("min_bytes = %d\n", min_bytes); + printf("if (%d >= %d &&\n", fpos>>3, tell_pos); + printf(" %d <= %d\n", d->bits_reader.buff - d->buffer - tell_pos + (fpos>>3) + min_bytes, DEMUX_BUFFER_SIZE); + printf("--------------------\n"); + */ + //AB + // d->bits_reader.buff - d->buffer = position within buffer + // d->bytes_total = total position in file at buffer start + // fpos = file position in bit (not byte) + // tell_pos = minimum number of bytes to be available from fpos on + if ((fpos>>3) >= tell_pos && + d->bits_reader.buff - d->buffer + (fpos>>3) + min_bytes - tell_pos <= DEMUX_BUFFER_SIZE) + { + int total_pos_bytes = d->bits_reader.buff - d->buffer + tell_pos; + int diff_pos_bytes = (fpos>>3) - total_pos_bytes; + d->bits_reader.buff += diff_pos_bytes; + d->bits_reader.count = 8 - (fpos & 7); + +// ++no_flush; + } else - mpc_demux_fill(d, min_bytes + ((bit_offset + 7) >> 3), 0); - d->bits_reader.buff += bit_offset >> 3; - d->bits_reader.count = 8 - (bit_offset & 7); + { + next_pos = fpos >> 3; + if (d->si.stream_version == 7) + next_pos = ((next_pos - d->si.header_position) & (-1 << 2)) + d->si.header_position; + bit_offset = (int) (fpos - (next_pos << 3)); + + d->r->seek(d->r, (mpc_int32_t) next_pos); + mpc_demux_clear_buff(d); + if (d->si.stream_version == 7) + mpc_demux_fill(d, DEMUX_BUFFER_SIZE, MPC_BUFFER_SWAP); + else + mpc_demux_fill(d, DEMUX_BUFFER_SIZE, 0); + d->bits_reader.buff += bit_offset >> 3; + d->bits_reader.count = 8 - (bit_offset & 7); + +// ++cnt_flush; + } +// printf("buffer ok = %d, flush = %d\n", no_flush, cnt_flush); + //AB } /**