From cc11e9466a3aa2ffc67779f80b2059a326301660 Mon Sep 17 00:00:00 2001 From: Andree Buschmann Date: Wed, 4 Jun 2008 05:41:59 +0000 Subject: 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 --- apps/codecs/libmusepack/decoder.h | 3 ++- apps/codecs/libmusepack/mpc_decoder.c | 46 ++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 21 deletions(-) (limited to 'apps/codecs/libmusepack') diff --git a/apps/codecs/libmusepack/decoder.h b/apps/codecs/libmusepack/decoder.h index 41ffe1ca9a..499cd53137 100644 --- a/apps/codecs/libmusepack/decoder.h +++ b/apps/codecs/libmusepack/decoder.h @@ -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 MaxDecodedFrames; // Maximum frames decoded (indicates usable seek table entries) mpc_uint32_t* SeekTable; // seek table itself - mpc_uint8_t SeekTable_Step; // frames per seek table index + mpc_uint8_t SeekTable_Step; // 1<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->SeekTableCounter = 0; } @@ -1435,7 +1436,8 @@ void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r) d->Ring = 0; d->WordsRead = 0; d->Max_Band = 0; - d->SeekTable_Step = 1; + d->SeekTable_Step = 0; + d->SeekTable_Mask = 0; d->SeekTableCounter = 0; 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 seekTableSize = min(si->frames, MPC_SEEK_BUFFER_SIZE); // 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<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) @@ -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) delta = (d->DecodedFrames > seekFrame ? -(mpc_int32_t)(d->DecodedFrames - seekFrame) : (mpc_int32_t)(seekFrame - d->DecodedFrames)); - if (seekFrame > 33) - lastFrame = seekFrame - 33 + 1 - d->SeekTable_Step; + if (seekFrame > SEEK_PRE_DECODE) + lastFrame = seekFrame - SEEK_PRE_DECODE + 1 - (1<SeekTable_Step); 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++) { 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->SeekTableCounter = 0; } @@ -1630,15 +1636,15 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample) fpos = d->SeekTable[0]; 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; } } 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); @@ -1646,9 +1652,9 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample) fpos = mpc_decoder_bits_read(d); 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; } } @@ -1658,18 +1664,18 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample) for (;d->DecodedFrames < lastFrame; d->DecodedFrames++) { 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->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 - // this is neccessary as mpc uses entropy coding in time domain + // now we decode the last SEEK_PRE_DECODE frames until we reach the seek + // position. this is neccessary as mpc uses entropy coding in time domain for (;d->DecodedFrames < seekFrame; d->DecodedFrames++) { 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 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->SeekTableCounter = 0; } -- cgit