summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2008-06-04 05:41:59 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2008-06-04 05:41:59 +0000
commitcc11e9466a3aa2ffc67779f80b2059a326301660 (patch)
treefe983231163513f062b9c3647cd0fc7e944527f2
parent9ea6bc06da5902aa5e0fff77a1764ca9befd115b (diff)
downloadrockbox-cc11e9466a3aa2ffc67779f80b2059a326301660.tar.gz
rockbox-cc11e9466a3aa2ffc67779f80b2059a326301660.zip
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
-rw-r--r--apps/codecs/libmusepack/decoder.h3
-rw-r--r--apps/codecs/libmusepack/mpc_decoder.c46
2 files changed, 28 insertions, 21 deletions
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 {
110 mpc_uint32_t SeekTableCounter; // used to sum up skip info, if SeekTable_Step != 1 110 mpc_uint32_t SeekTableCounter; // used to sum up skip info, if SeekTable_Step != 1
111 mpc_uint32_t MaxDecodedFrames; // Maximum frames decoded (indicates usable seek table entries) 111 mpc_uint32_t MaxDecodedFrames; // Maximum frames decoded (indicates usable seek table entries)
112 mpc_uint32_t* SeekTable; // seek table itself 112 mpc_uint32_t* SeekTable; // seek table itself
113 mpc_uint8_t SeekTable_Step; // frames per seek table index 113 mpc_uint8_t SeekTable_Step; // 1<<SeekTable_Step = frames per table index
114 mpc_uint32_t SeekTable_Mask; // used to avoid modulo-operation in seek
114 115
115#ifdef MPC_FIXED_POINT 116#ifdef MPC_FIXED_POINT
116 mpc_uint8_t SCF_shift[256]; 117 mpc_uint8_t SCF_shift[256];
diff --git a/apps/codecs/libmusepack/mpc_decoder.c b/apps/codecs/libmusepack/mpc_decoder.c
index 75dd1da918..e63d1efaec 100644
--- a/apps/codecs/libmusepack/mpc_decoder.c
+++ b/apps/codecs/libmusepack/mpc_decoder.c
@@ -96,6 +96,7 @@ mpc_uint8_t LUTDSCF [1<< 6] IBSS_ATTR_MPC_LARGE_IRAM; // 64 Bytes = 2976 B
96//------------------------------------------------------------------------------ 96//------------------------------------------------------------------------------
97enum 97enum
98 { 98 {
99 SEEK_PRE_DECODE = 33, // number of frames to be pre-decoded
99 MEMSIZE = MPC_DECODER_MEMSIZE, // overall buffer size 100 MEMSIZE = MPC_DECODER_MEMSIZE, // overall buffer size
100 MEMSIZE2 = (MEMSIZE/2), // size of one buffer 101 MEMSIZE2 = (MEMSIZE/2), // size of one buffer
101 MEMMASK = (MEMSIZE-1) 102 MEMMASK = (MEMSIZE-1)
@@ -502,9 +503,9 @@ mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer)
502 503
503 /* update seek table */ 504 /* update seek table */
504 d->SeekTableCounter += d->FwdJumpInfo + 20; 505 d->SeekTableCounter += d->FwdJumpInfo + 20;
505 if (0 == (d->DecodedFrames % d->SeekTable_Step)) 506 if (0 == ((d->DecodedFrames) & (d->SeekTable_Mask)))
506 { 507 {
507 d->SeekTable[d->DecodedFrames/d->SeekTable_Step] = d->SeekTableCounter; 508 d->SeekTable[d->DecodedFrames>>d->SeekTable_Step] = d->SeekTableCounter;
508 d->MaxDecodedFrames = d->DecodedFrames; 509 d->MaxDecodedFrames = d->DecodedFrames;
509 d->SeekTableCounter = 0; 510 d->SeekTableCounter = 0;
510 } 511 }
@@ -1435,7 +1436,8 @@ void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r)
1435 d->Ring = 0; 1436 d->Ring = 0;
1436 d->WordsRead = 0; 1437 d->WordsRead = 0;
1437 d->Max_Band = 0; 1438 d->Max_Band = 0;
1438 d->SeekTable_Step = 1; 1439 d->SeekTable_Step = 0;
1440 d->SeekTable_Mask = 0;
1439 d->SeekTableCounter = 0; 1441 d->SeekTableCounter = 0;
1440 1442
1441 mpc_decoder_initialisiere_quantisierungstabellen(d, 1.0f); 1443 mpc_decoder_initialisiere_quantisierungstabellen(d, 1.0f);
@@ -1488,7 +1490,11 @@ static void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si)
1488 // limit used table size to MPC_SEEK_BUFFER_SIZE 1490 // limit used table size to MPC_SEEK_BUFFER_SIZE
1489 seekTableSize = min(si->frames, MPC_SEEK_BUFFER_SIZE); 1491 seekTableSize = min(si->frames, MPC_SEEK_BUFFER_SIZE);
1490 // frames per buffer to not exceed buffer and to be able to seek full file 1492 // frames per buffer to not exceed buffer and to be able to seek full file
1491 d->SeekTable_Step = (si->frames + seekTableSize - 1) / seekTableSize; 1493 while ( seekTableSize < si->frames / (1<<d->SeekTable_Step) )
1494 {
1495 d->SeekTable_Step++;
1496 }
1497 d->SeekTable_Mask = (1 << d->SeekTable_Step) - 1;
1492} 1498}
1493 1499
1494mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si) 1500mpc_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)
1595 // seek direction (note: avoids casting to int64) 1601 // seek direction (note: avoids casting to int64)
1596 delta = (d->DecodedFrames > seekFrame ? -(mpc_int32_t)(d->DecodedFrames - seekFrame) : (mpc_int32_t)(seekFrame - d->DecodedFrames)); 1602 delta = (d->DecodedFrames > seekFrame ? -(mpc_int32_t)(d->DecodedFrames - seekFrame) : (mpc_int32_t)(seekFrame - d->DecodedFrames));
1597 1603
1598 if (seekFrame > 33) 1604 if (seekFrame > SEEK_PRE_DECODE)
1599 lastFrame = seekFrame - 33 + 1 - d->SeekTable_Step; 1605 lastFrame = seekFrame - SEEK_PRE_DECODE + 1 - (1<<d->SeekTable_Step);
1600 1606
1601 if (d->MaxDecodedFrames == 0) // nothing decoded yet, parse stream 1607 if (d->MaxDecodedFrames == 0) // nothing decoded yet, parse stream
1602 { 1608 {
@@ -1614,9 +1620,9 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
1614 for (d->DecodedFrames = 0; d->DecodedFrames < lastFrame; d->DecodedFrames++) 1620 for (d->DecodedFrames = 0; d->DecodedFrames < lastFrame; d->DecodedFrames++)
1615 { 1621 {
1616 d->SeekTableCounter += mpc_decoder_jump_frame(d); 1622 d->SeekTableCounter += mpc_decoder_jump_frame(d);
1617 if (0 == ((d->DecodedFrames+1) % d->SeekTable_Step)) 1623 if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask)))
1618 { 1624 {
1619 d->SeekTable[(d->DecodedFrames+1)/d->SeekTable_Step] = d->SeekTableCounter; 1625 d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step] = d->SeekTableCounter;
1620 d->MaxDecodedFrames = d->DecodedFrames; 1626 d->MaxDecodedFrames = d->DecodedFrames;
1621 d->SeekTableCounter = 0; 1627 d->SeekTableCounter = 0;
1622 } 1628 }
@@ -1630,15 +1636,15 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
1630 fpos = d->SeekTable[0]; 1636 fpos = d->SeekTable[0];
1631 for (d->DecodedFrames = 0; d->DecodedFrames < lastFrame; d->DecodedFrames++) 1637 for (d->DecodedFrames = 0; d->DecodedFrames < lastFrame; d->DecodedFrames++)
1632 { 1638 {
1633 if (0 == (d->DecodedFrames+1) % d->SeekTable_Step) 1639 if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask)))
1634 { 1640 {
1635 fpos += d->SeekTable[(d->DecodedFrames+1)/d->SeekTable_Step]; 1641 fpos += d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step];
1636 d->SeekTableCounter = 0; 1642 d->SeekTableCounter = 0;
1637 } 1643 }
1638 } 1644 }
1639 mpc_decoder_seek_to(d, fpos); 1645 mpc_decoder_seek_to(d, fpos);
1640 } 1646 }
1641 else if (delta > 33) // jump forward, seek table is available 1647 else if (delta > SEEK_PRE_DECODE) // jump forward, seek table is available
1642 { 1648 {
1643 mpc_decoder_reset_state(d); 1649 mpc_decoder_reset_state(d);
1644 1650
@@ -1646,9 +1652,9 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
1646 fpos = mpc_decoder_bits_read(d); 1652 fpos = mpc_decoder_bits_read(d);
1647 for (; d->DecodedFrames < d->MaxDecodedFrames && d->DecodedFrames < lastFrame; d->DecodedFrames++) 1653 for (; d->DecodedFrames < d->MaxDecodedFrames && d->DecodedFrames < lastFrame; d->DecodedFrames++)
1648 { 1654 {
1649 if (0 == (d->DecodedFrames+1) % d->SeekTable_Step) 1655 if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask)))
1650 { 1656 {
1651 fpos += d->SeekTable[(d->DecodedFrames+1)/d->SeekTable_Step]; 1657 fpos += d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step];
1652 d->SeekTableCounter = 0; 1658 d->SeekTableCounter = 0;
1653 } 1659 }
1654 } 1660 }
@@ -1658,18 +1664,18 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
1658 for (;d->DecodedFrames < lastFrame; d->DecodedFrames++) 1664 for (;d->DecodedFrames < lastFrame; d->DecodedFrames++)
1659 { 1665 {
1660 d->SeekTableCounter += mpc_decoder_jump_frame(d); 1666 d->SeekTableCounter += mpc_decoder_jump_frame(d);
1661 if (0 == (d->DecodedFrames+1) % d->SeekTable_Step) 1667 if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask)))
1662 { 1668 {
1663 d->SeekTable[(d->DecodedFrames+1)/d->SeekTable_Step] = d->SeekTableCounter; 1669 d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step] = d->SeekTableCounter;
1664 d->MaxDecodedFrames = d->DecodedFrames; 1670 d->MaxDecodedFrames = d->DecodedFrames;
1665 d->SeekTableCounter = 0; 1671 d->SeekTableCounter = 0;
1666 } 1672 }
1667 } 1673 }
1668 } 1674 }
1669 // until here we jumped to desired position -33 frames 1675 // until here we jumped to desired position -SEEK_PRE_DECODE frames
1670 1676
1671 // now we decode the last 33 frames until we reach the seek position 1677 // now we decode the last SEEK_PRE_DECODE frames until we reach the seek
1672 // this is neccessary as mpc uses entropy coding in time domain 1678 // position. this is neccessary as mpc uses entropy coding in time domain
1673 for (;d->DecodedFrames < seekFrame; d->DecodedFrames++) 1679 for (;d->DecodedFrames < seekFrame; d->DecodedFrames++)
1674 { 1680 {
1675 mpc_uint32_t FrameBitCnt; 1681 mpc_uint32_t FrameBitCnt;
@@ -1701,9 +1707,9 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample)
1701 1707
1702 // update seek table, if there new entries to fill 1708 // update seek table, if there new entries to fill
1703 d->SeekTableCounter += d->FwdJumpInfo + 20; 1709 d->SeekTableCounter += d->FwdJumpInfo + 20;
1704 if (0 == (d->DecodedFrames+1) % d->SeekTable_Step) 1710 if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask)))
1705 { 1711 {
1706 d->SeekTable[(d->DecodedFrames+1)/d->SeekTable_Step] = d->SeekTableCounter; 1712 d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step] = d->SeekTableCounter;
1707 d->MaxDecodedFrames = d->DecodedFrames; 1713 d->MaxDecodedFrames = d->DecodedFrames;
1708 d->SeekTableCounter = 0; 1714 d->SeekTableCounter = 0;
1709 } 1715 }