forked from len0rd/rockbox
Further changes in mpc buffered seek. Remove magical number and replace it with a better commented #define. Use shift and bit mask instead of division and modulo operations when using the seek buffer. Saves some binary size for the codec.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17686 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
9ea6bc06da
commit
cc11e9466a
2 changed files with 28 additions and 21 deletions
|
|
@ -110,7 +110,8 @@ typedef struct mpc_decoder_t {
|
||||||
mpc_uint32_t SeekTableCounter; // used to sum up skip info, if SeekTable_Step != 1
|
mpc_uint32_t SeekTableCounter; // used to sum up skip info, if SeekTable_Step != 1
|
||||||
mpc_uint32_t MaxDecodedFrames; // Maximum frames decoded (indicates usable seek table entries)
|
mpc_uint32_t MaxDecodedFrames; // Maximum frames decoded (indicates usable seek table entries)
|
||||||
mpc_uint32_t* SeekTable; // seek table itself
|
mpc_uint32_t* SeekTable; // seek table itself
|
||||||
mpc_uint8_t SeekTable_Step; // frames per seek table index
|
mpc_uint8_t SeekTable_Step; // 1<<SeekTable_Step = frames per table index
|
||||||
|
mpc_uint32_t SeekTable_Mask; // used to avoid modulo-operation in seek
|
||||||
|
|
||||||
#ifdef MPC_FIXED_POINT
|
#ifdef MPC_FIXED_POINT
|
||||||
mpc_uint8_t SCF_shift[256];
|
mpc_uint8_t SCF_shift[256];
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ mpc_uint8_t LUTDSCF [1<< 6] IBSS_ATTR_MPC_LARGE_IRAM; // 64 Bytes = 2976 B
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
SEEK_PRE_DECODE = 33, // number of frames to be pre-decoded
|
||||||
MEMSIZE = MPC_DECODER_MEMSIZE, // overall buffer size
|
MEMSIZE = MPC_DECODER_MEMSIZE, // overall buffer size
|
||||||
MEMSIZE2 = (MEMSIZE/2), // size of one buffer
|
MEMSIZE2 = (MEMSIZE/2), // size of one buffer
|
||||||
MEMMASK = (MEMSIZE-1)
|
MEMMASK = (MEMSIZE-1)
|
||||||
|
|
@ -502,9 +503,9 @@ mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer)
|
||||||
|
|
||||||
/* update seek table */
|
/* update seek table */
|
||||||
d->SeekTableCounter += d->FwdJumpInfo + 20;
|
d->SeekTableCounter += d->FwdJumpInfo + 20;
|
||||||
if (0 == (d->DecodedFrames % d->SeekTable_Step))
|
if (0 == ((d->DecodedFrames) & (d->SeekTable_Mask)))
|
||||||
{
|
{
|
||||||
d->SeekTable[d->DecodedFrames/d->SeekTable_Step] = d->SeekTableCounter;
|
d->SeekTable[d->DecodedFrames>>d->SeekTable_Step] = d->SeekTableCounter;
|
||||||
d->MaxDecodedFrames = d->DecodedFrames;
|
d->MaxDecodedFrames = d->DecodedFrames;
|
||||||
d->SeekTableCounter = 0;
|
d->SeekTableCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1435,7 +1436,8 @@ void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r)
|
||||||
d->Ring = 0;
|
d->Ring = 0;
|
||||||
d->WordsRead = 0;
|
d->WordsRead = 0;
|
||||||
d->Max_Band = 0;
|
d->Max_Band = 0;
|
||||||
d->SeekTable_Step = 1;
|
d->SeekTable_Step = 0;
|
||||||
|
d->SeekTable_Mask = 0;
|
||||||
d->SeekTableCounter = 0;
|
d->SeekTableCounter = 0;
|
||||||
|
|
||||||
mpc_decoder_initialisiere_quantisierungstabellen(d, 1.0f);
|
mpc_decoder_initialisiere_quantisierungstabellen(d, 1.0f);
|
||||||
|
|
@ -1488,7 +1490,11 @@ static void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si)
|
||||||
// limit used table size to MPC_SEEK_BUFFER_SIZE
|
// limit used table size to MPC_SEEK_BUFFER_SIZE
|
||||||
seekTableSize = min(si->frames, MPC_SEEK_BUFFER_SIZE);
|
seekTableSize = min(si->frames, MPC_SEEK_BUFFER_SIZE);
|
||||||
// frames per buffer to not exceed buffer and to be able to seek full file
|
// frames per buffer to not exceed buffer and to be able to seek full file
|
||||||
d->SeekTable_Step = (si->frames + seekTableSize - 1) / seekTableSize;
|
while ( seekTableSize < si->frames / (1<<d->SeekTable_Step) )
|
||||||
|
{
|
||||||
|
d->SeekTable_Step++;
|
||||||
|
}
|
||||||
|
d->SeekTable_Mask = (1 << d->SeekTable_Step) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si)
|
mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si)
|
||||||
|
|
@ -1595,8 +1601,8 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
|
||||||
// seek direction (note: avoids casting to int64)
|
// seek direction (note: avoids casting to int64)
|
||||||
delta = (d->DecodedFrames > seekFrame ? -(mpc_int32_t)(d->DecodedFrames - seekFrame) : (mpc_int32_t)(seekFrame - d->DecodedFrames));
|
delta = (d->DecodedFrames > seekFrame ? -(mpc_int32_t)(d->DecodedFrames - seekFrame) : (mpc_int32_t)(seekFrame - d->DecodedFrames));
|
||||||
|
|
||||||
if (seekFrame > 33)
|
if (seekFrame > SEEK_PRE_DECODE)
|
||||||
lastFrame = seekFrame - 33 + 1 - d->SeekTable_Step;
|
lastFrame = seekFrame - SEEK_PRE_DECODE + 1 - (1<<d->SeekTable_Step);
|
||||||
|
|
||||||
if (d->MaxDecodedFrames == 0) // nothing decoded yet, parse stream
|
if (d->MaxDecodedFrames == 0) // nothing decoded yet, parse stream
|
||||||
{
|
{
|
||||||
|
|
@ -1614,9 +1620,9 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
|
||||||
for (d->DecodedFrames = 0; d->DecodedFrames < lastFrame; d->DecodedFrames++)
|
for (d->DecodedFrames = 0; d->DecodedFrames < lastFrame; d->DecodedFrames++)
|
||||||
{
|
{
|
||||||
d->SeekTableCounter += mpc_decoder_jump_frame(d);
|
d->SeekTableCounter += mpc_decoder_jump_frame(d);
|
||||||
if (0 == ((d->DecodedFrames+1) % d->SeekTable_Step))
|
if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask)))
|
||||||
{
|
{
|
||||||
d->SeekTable[(d->DecodedFrames+1)/d->SeekTable_Step] = d->SeekTableCounter;
|
d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step] = d->SeekTableCounter;
|
||||||
d->MaxDecodedFrames = d->DecodedFrames;
|
d->MaxDecodedFrames = d->DecodedFrames;
|
||||||
d->SeekTableCounter = 0;
|
d->SeekTableCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1630,15 +1636,15 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
|
||||||
fpos = d->SeekTable[0];
|
fpos = d->SeekTable[0];
|
||||||
for (d->DecodedFrames = 0; d->DecodedFrames < lastFrame; d->DecodedFrames++)
|
for (d->DecodedFrames = 0; d->DecodedFrames < lastFrame; d->DecodedFrames++)
|
||||||
{
|
{
|
||||||
if (0 == (d->DecodedFrames+1) % d->SeekTable_Step)
|
if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask)))
|
||||||
{
|
{
|
||||||
fpos += d->SeekTable[(d->DecodedFrames+1)/d->SeekTable_Step];
|
fpos += d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step];
|
||||||
d->SeekTableCounter = 0;
|
d->SeekTableCounter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mpc_decoder_seek_to(d, fpos);
|
mpc_decoder_seek_to(d, fpos);
|
||||||
}
|
}
|
||||||
else if (delta > 33) // jump forward, seek table is available
|
else if (delta > SEEK_PRE_DECODE) // jump forward, seek table is available
|
||||||
{
|
{
|
||||||
mpc_decoder_reset_state(d);
|
mpc_decoder_reset_state(d);
|
||||||
|
|
||||||
|
|
@ -1646,9 +1652,9 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
|
||||||
fpos = mpc_decoder_bits_read(d);
|
fpos = mpc_decoder_bits_read(d);
|
||||||
for (; d->DecodedFrames < d->MaxDecodedFrames && d->DecodedFrames < lastFrame; d->DecodedFrames++)
|
for (; d->DecodedFrames < d->MaxDecodedFrames && d->DecodedFrames < lastFrame; d->DecodedFrames++)
|
||||||
{
|
{
|
||||||
if (0 == (d->DecodedFrames+1) % d->SeekTable_Step)
|
if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask)))
|
||||||
{
|
{
|
||||||
fpos += d->SeekTable[(d->DecodedFrames+1)/d->SeekTable_Step];
|
fpos += d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step];
|
||||||
d->SeekTableCounter = 0;
|
d->SeekTableCounter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1658,18 +1664,18 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
|
||||||
for (;d->DecodedFrames < lastFrame; d->DecodedFrames++)
|
for (;d->DecodedFrames < lastFrame; d->DecodedFrames++)
|
||||||
{
|
{
|
||||||
d->SeekTableCounter += mpc_decoder_jump_frame(d);
|
d->SeekTableCounter += mpc_decoder_jump_frame(d);
|
||||||
if (0 == (d->DecodedFrames+1) % d->SeekTable_Step)
|
if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask)))
|
||||||
{
|
{
|
||||||
d->SeekTable[(d->DecodedFrames+1)/d->SeekTable_Step] = d->SeekTableCounter;
|
d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step] = d->SeekTableCounter;
|
||||||
d->MaxDecodedFrames = d->DecodedFrames;
|
d->MaxDecodedFrames = d->DecodedFrames;
|
||||||
d->SeekTableCounter = 0;
|
d->SeekTableCounter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// until here we jumped to desired position -33 frames
|
// until here we jumped to desired position -SEEK_PRE_DECODE frames
|
||||||
|
|
||||||
// now we decode the last 33 frames until we reach the seek position
|
// now we decode the last SEEK_PRE_DECODE frames until we reach the seek
|
||||||
// this is neccessary as mpc uses entropy coding in time domain
|
// position. this is neccessary as mpc uses entropy coding in time domain
|
||||||
for (;d->DecodedFrames < seekFrame; d->DecodedFrames++)
|
for (;d->DecodedFrames < seekFrame; d->DecodedFrames++)
|
||||||
{
|
{
|
||||||
mpc_uint32_t FrameBitCnt;
|
mpc_uint32_t FrameBitCnt;
|
||||||
|
|
@ -1701,9 +1707,9 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
|
||||||
|
|
||||||
// update seek table, if there new entries to fill
|
// update seek table, if there new entries to fill
|
||||||
d->SeekTableCounter += d->FwdJumpInfo + 20;
|
d->SeekTableCounter += d->FwdJumpInfo + 20;
|
||||||
if (0 == (d->DecodedFrames+1) % d->SeekTable_Step)
|
if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask)))
|
||||||
{
|
{
|
||||||
d->SeekTable[(d->DecodedFrames+1)/d->SeekTable_Step] = d->SeekTableCounter;
|
d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step] = d->SeekTableCounter;
|
||||||
d->MaxDecodedFrames = d->DecodedFrames;
|
d->MaxDecodedFrames = d->DecodedFrames;
|
||||||
d->SeekTableCounter = 0;
|
d->SeekTableCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue