View Single Post
Old 13 May 2010, 09:03 pm   #3
Buschel
The Man
 
Join Date: Mar 2008
Posts: 9
Default

The following code works on simulation and ARM target. It is by factors faster than the unchanged version. I am not fully satisfied with the code, but it is a proof-of-concept. Ayn further ideas/comments from your side?

static void
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;

// 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
{
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);
}
Buschel is offline   Reply With Quote