diff options
author | Thom Johansen <thomj@rockbox.org> | 2006-08-31 18:18:57 +0000 |
---|---|---|
committer | Thom Johansen <thomj@rockbox.org> | 2006-08-31 18:18:57 +0000 |
commit | 20332bce1d49d7285109564d2e29ee18b0acd54e (patch) | |
tree | 9e423a673c6f7e03816a0f0ca785ef3915405b44 /apps/codecs | |
parent | 6af8603d9a8894e644f0b9508f2142c2b56d09a3 (diff) | |
download | rockbox-20332bce1d49d7285109564d2e29ee18b0acd54e.tar.gz rockbox-20332bce1d49d7285109564d2e29ee18b0acd54e.zip |
FS patch #5172 by Andrew Cupper. Musepack seeking support. Decoder should also be faster.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10827 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs')
-rw-r--r-- | apps/codecs/libmusepack/config_types.h | 2 | ||||
-rw-r--r-- | apps/codecs/libmusepack/decoder.h | 46 | ||||
-rw-r--r-- | apps/codecs/libmusepack/huffman.h | 4 | ||||
-rw-r--r-- | apps/codecs/libmusepack/huffsv7.c | 20 | ||||
-rw-r--r-- | apps/codecs/libmusepack/internal.h | 4 | ||||
-rw-r--r-- | apps/codecs/libmusepack/mpc_decoder.c | 969 | ||||
-rw-r--r-- | apps/codecs/libmusepack/musepack.h | 6 | ||||
-rw-r--r-- | apps/codecs/libmusepack/synth_filter.c | 5 | ||||
-rw-r--r-- | apps/codecs/mpc.c | 32 |
9 files changed, 836 insertions, 252 deletions
diff --git a/apps/codecs/libmusepack/config_types.h b/apps/codecs/libmusepack/config_types.h index 30a609b863..96e8b90430 100644 --- a/apps/codecs/libmusepack/config_types.h +++ b/apps/codecs/libmusepack/config_types.h | |||
@@ -40,6 +40,8 @@ typedef unsigned char mpc_bool_t; | |||
40 | #define FALSE 0 | 40 | #define FALSE 0 |
41 | 41 | ||
42 | /* these are filled in by configure */ | 42 | /* these are filled in by configure */ |
43 | typedef signed char mpc_int8_t; | ||
44 | typedef unsigned char mpc_uint8_t; | ||
43 | typedef short mpc_int16_t; | 45 | typedef short mpc_int16_t; |
44 | typedef unsigned short mpc_uint16_t; | 46 | typedef unsigned short mpc_uint16_t; |
45 | typedef int mpc_int32_t; | 47 | typedef int mpc_int32_t; |
diff --git a/apps/codecs/libmusepack/decoder.h b/apps/codecs/libmusepack/decoder.h index 708533b09e..7ffa572db2 100644 --- a/apps/codecs/libmusepack/decoder.h +++ b/apps/codecs/libmusepack/decoder.h | |||
@@ -44,6 +44,7 @@ | |||
44 | #include "streaminfo.h" | 44 | #include "streaminfo.h" |
45 | 45 | ||
46 | #define MPC_SUPPORT_SV456 | 46 | #define MPC_SUPPORT_SV456 |
47 | #define SCF_HACK | ||
47 | 48 | ||
48 | enum { | 49 | enum { |
49 | MPC_V_MEM = 2304, | 50 | MPC_V_MEM = 2304, |
@@ -51,8 +52,8 @@ enum { | |||
51 | }; | 52 | }; |
52 | 53 | ||
53 | typedef struct { | 54 | typedef struct { |
54 | mpc_int32_t L [36]; | 55 | mpc_int16_t L [36]; |
55 | mpc_int32_t R [36]; | 56 | mpc_int16_t R [36]; |
56 | } QuantTyp; | 57 | } QuantTyp; |
57 | 58 | ||
58 | typedef struct mpc_decoder_t { | 59 | typedef struct mpc_decoder_t { |
@@ -61,10 +62,12 @@ typedef struct mpc_decoder_t { | |||
61 | /// @name internal state variables | 62 | /// @name internal state variables |
62 | //@{ | 63 | //@{ |
63 | 64 | ||
65 | mpc_uint32_t next; | ||
64 | mpc_uint32_t dword; /// currently decoded 32bit-word | 66 | mpc_uint32_t dword; /// currently decoded 32bit-word |
65 | mpc_uint32_t pos; /// bit-position within dword | 67 | mpc_uint32_t pos; /// bit-position within dword |
66 | mpc_uint32_t Speicher[MPC_DECODER_MEMSIZE]; /// read-buffer | 68 | mpc_uint32_t *Speicher; /// read-buffer |
67 | mpc_uint32_t Zaehler; /// actual index within read-buffer | 69 | mpc_uint32_t Zaehler; /// actual index within read-buffer |
70 | mpc_uint32_t Ring; | ||
68 | 71 | ||
69 | mpc_uint32_t samples_to_skip; | 72 | mpc_uint32_t samples_to_skip; |
70 | mpc_uint32_t last_block_samples; | 73 | mpc_uint32_t last_block_samples; |
@@ -74,6 +77,9 @@ typedef struct mpc_decoder_t { | |||
74 | 77 | ||
75 | mpc_uint32_t DecodedFrames; | 78 | mpc_uint32_t DecodedFrames; |
76 | mpc_uint32_t OverallFrames; | 79 | mpc_uint32_t OverallFrames; |
80 | mpc_uint32_t MaxDecodedFrames; // Maximum frames decoded (indicates usable seek table entries) | ||
81 | mpc_uint16_t SeekTableIndex; | ||
82 | mpc_uint32_t SeekTableCounter; | ||
77 | mpc_int32_t SampleRate; // Sample frequency | 83 | mpc_int32_t SampleRate; // Sample frequency |
78 | 84 | ||
79 | mpc_uint32_t StreamVersion; // version of bitstream | 85 | mpc_uint32_t StreamVersion; // version of bitstream |
@@ -90,28 +96,34 @@ typedef struct mpc_decoder_t { | |||
90 | mpc_uint32_t __r1; | 96 | mpc_uint32_t __r1; |
91 | mpc_uint32_t __r2; | 97 | mpc_uint32_t __r2; |
92 | 98 | ||
93 | mpc_int32_t SCF_Index_L [32] [3]; | 99 | mpc_int8_t SCF_Index_L [32] [3]; |
94 | mpc_int32_t SCF_Index_R [32] [3]; // holds scalefactor-indices | 100 | mpc_int8_t SCF_Index_R [32] [3]; // holds scalefactor-indices |
95 | QuantTyp Q [32]; // holds quantized samples | 101 | QuantTyp Q [32]; // holds quantized samples |
96 | mpc_int32_t Res_L [32]; | 102 | mpc_int8_t Res_L [32]; |
97 | mpc_int32_t Res_R [32]; // holds the chosen quantizer for each subband | 103 | mpc_int8_t Res_R [32]; // holds the chosen quantizer for each subband |
104 | #ifdef MPC_SUPPORT_SV456 | ||
98 | mpc_bool_t DSCF_Flag_L [32]; | 105 | mpc_bool_t DSCF_Flag_L [32]; |
99 | mpc_bool_t DSCF_Flag_R [32]; // differential SCF used? | 106 | mpc_bool_t DSCF_Flag_R [32]; // differential SCF used? |
100 | mpc_int32_t SCFI_L [32]; | 107 | #endif |
101 | mpc_int32_t SCFI_R [32]; // describes order of transmitted SCF | 108 | mpc_int8_t SCFI_L [32]; |
102 | mpc_int32_t DSCF_Reference_L [32]; | 109 | mpc_int8_t SCFI_R [32]; // describes order of transmitted SCF |
103 | mpc_int32_t DSCF_Reference_R [32]; // holds last frames SCF | 110 | //mpc_int32_t DSCF_Reference_L [32]; |
111 | //mpc_int32_t DSCF_Reference_R [32]; // holds last frames SCF | ||
104 | mpc_bool_t MS_Flag[32]; // MS used? | 112 | mpc_bool_t MS_Flag[32]; // MS used? |
113 | |||
114 | mpc_uint32_t* SeekTable; | ||
115 | mpc_bool_t Use_SeekTable; | ||
116 | mpc_bool_t Use_FastSeek; | ||
117 | mpc_bool_t Use_StaticSeekTable; | ||
118 | mpc_uint8_t SeekTable_Step; | ||
119 | mpc_uint32_t Max_SeekTable_Size; | ||
120 | |||
105 | #ifdef MPC_FIXED_POINT | 121 | #ifdef MPC_FIXED_POINT |
106 | unsigned char SCF_shift[256]; | 122 | unsigned char SCF_shift[256]; |
107 | #endif | 123 | #endif |
108 | 124 | ||
109 | /* These two see very frequent use in synth_filter.c, so we'll put them | 125 | MPC_SAMPLE_FORMAT V_L[MPC_V_MEM + 960]; |
110 | in IRAM for Rockbox use. Actual arrays are placed in mpc_decoder.c */ | 126 | MPC_SAMPLE_FORMAT V_R[MPC_V_MEM + 960]; |
111 | /* MPC_SAMPLE_FORMAT V_L[MPC_V_MEM + 960]; */ | ||
112 | /* MPC_SAMPLE_FORMAT V_R[MPC_V_MEM + 960]; */ | ||
113 | MPC_SAMPLE_FORMAT *V_L; | ||
114 | MPC_SAMPLE_FORMAT *V_R; | ||
115 | MPC_SAMPLE_FORMAT Y_L[36][32]; | 127 | MPC_SAMPLE_FORMAT Y_L[36][32]; |
116 | MPC_SAMPLE_FORMAT Y_R[36][32]; | 128 | MPC_SAMPLE_FORMAT Y_R[36][32]; |
117 | MPC_SAMPLE_FORMAT SCF[256]; ///< holds adapted scalefactors (for clipping prevention) | 129 | MPC_SAMPLE_FORMAT SCF[256]; ///< holds adapted scalefactors (for clipping prevention) |
diff --git a/apps/codecs/libmusepack/huffman.h b/apps/codecs/libmusepack/huffman.h index 3edbeb7b6e..87fd5c15a4 100644 --- a/apps/codecs/libmusepack/huffman.h +++ b/apps/codecs/libmusepack/huffman.h | |||
@@ -46,8 +46,8 @@ struct mpc_decoder_t; // forward declare to break circular dependencies | |||
46 | /// Huffman table entry. | 46 | /// Huffman table entry. |
47 | typedef struct huffman_type_t { | 47 | typedef struct huffman_type_t { |
48 | mpc_uint32_t Code; | 48 | mpc_uint32_t Code; |
49 | mpc_uint16_t Length; | 49 | mpc_uint8_t Length; |
50 | mpc_int16_t Value; | 50 | mpc_int8_t Value; |
51 | } HuffmanTyp; | 51 | } HuffmanTyp; |
52 | 52 | ||
53 | #endif // _mpcdec_huffman_h_ | 53 | #endif // _mpcdec_huffman_h_ |
diff --git a/apps/codecs/libmusepack/huffsv7.c b/apps/codecs/libmusepack/huffsv7.c index a59674191d..5611595281 100644 --- a/apps/codecs/libmusepack/huffsv7.c +++ b/apps/codecs/libmusepack/huffsv7.c | |||
@@ -39,38 +39,38 @@ | |||
39 | #include <huffman.h> | 39 | #include <huffman.h> |
40 | #include <requant.h> | 40 | #include <requant.h> |
41 | 41 | ||
42 | const HuffmanTyp mpc_table_HuffHdr [10] = | 42 | const HuffmanTyp mpc_table_HuffHdr [10] ICONST_ATTR = |
43 | {{2147483648u,1,0},{1610612736u,3,1},{1577058304u,7,-4},{1568669696u,9,3},{1560281088u,9,4},{1543503872u,8,-5},{1476395008u,6,2},{1342177280u,5,-3},{1073741824u,4,-2},{0u,2,-1},}; | 43 | {{2147483648u,1,0},{1610612736u,3,1},{1577058304u,7,-4},{1568669696u,9,3},{1560281088u,9,4},{1543503872u,8,-5},{1476395008u,6,2},{1342177280u,5,-3},{1073741824u,4,-2},{0u,2,-1},}; |
44 | const HuffmanTyp mpc_table_HuffSCFI [ 4] = | 44 | const HuffmanTyp mpc_table_HuffSCFI [ 4] ICONST_ATTR = |
45 | {{2147483648u,1,1},{1610612736u,3,2},{1073741824u,3,0},{0u,2,3},}; | 45 | {{2147483648u,1,1},{1610612736u,3,2},{1073741824u,3,0},{0u,2,3},}; |
46 | const HuffmanTyp mpc_table_HuffDSCF [16] = | 46 | const HuffmanTyp mpc_table_HuffDSCF [16] ICONST_ATTR = |
47 | {{4160749568u,5,5},{4026531840u,5,-4},{3758096384u,4,3},{3489660928u,4,-3},{3221225472u,4,8},{2684354560u,3,1},{2415919104u,4,0},{2281701376u,5,-5},{2214592512u,6,7},{2147483648u,6,-7},{1610612736u,3,-1},{1073741824u,3,2},{805306368u,4,4},{671088640u,5,6},{536870912u,5,-6},{0u,3,-2},}; | 47 | {{4160749568u,5,5},{4026531840u,5,-4},{3758096384u,4,3},{3489660928u,4,-3},{3221225472u,4,8},{2684354560u,3,1},{2415919104u,4,0},{2281701376u,5,-5},{2214592512u,6,7},{2147483648u,6,-7},{1610612736u,3,-1},{1073741824u,3,2},{805306368u,4,4},{671088640u,5,6},{536870912u,5,-6},{0u,3,-2},}; |
48 | 48 | ||
49 | static const HuffmanTyp mpc_table_HuffQ1 [2] [3*3*3] = { | 49 | static const HuffmanTyp mpc_table_HuffQ1 [2] [3*3*3] ICONST_ATTR = { |
50 | {{3758096384u,3,13},{3690987520u,6,26},{3623878656u,6,0},{3556769792u,6,20},{3489660928u,6,6},{3221225472u,4,14},{2952790016u,4,12},{2684354560u,4,4},{2415919104u,4,22},{2348810240u,6,8},{2281701376u,6,18},{2214592512u,6,24},{2147483648u,6,2},{1879048192u,4,16},{1610612736u,4,10},{1476395008u,5,17},{1342177280u,5,9},{1207959552u,5,1},{1073741824u,5,25},{939524096u,5,5},{805306368u,5,21},{671088640u,5,3},{536870912u,5,11},{402653184u,5,15},{268435456u,5,23},{134217728u,5,19},{0u,5,7},}, | 50 | {{3758096384u,3,13},{3690987520u,6,26},{3623878656u,6,0},{3556769792u,6,20},{3489660928u,6,6},{3221225472u,4,14},{2952790016u,4,12},{2684354560u,4,4},{2415919104u,4,22},{2348810240u,6,8},{2281701376u,6,18},{2214592512u,6,24},{2147483648u,6,2},{1879048192u,4,16},{1610612736u,4,10},{1476395008u,5,17},{1342177280u,5,9},{1207959552u,5,1},{1073741824u,5,25},{939524096u,5,5},{805306368u,5,21},{671088640u,5,3},{536870912u,5,11},{402653184u,5,15},{268435456u,5,23},{134217728u,5,19},{0u,5,7},}, |
51 | {{2147483648u,1,13},{2113929216u,7,15},{2080374784u,7,1},{2046820352u,7,11},{2013265920u,7,7},{1979711488u,7,17},{1946157056u,7,25},{1912602624u,7,19},{1904214016u,9,8},{1895825408u,9,18},{1887436800u,9,2},{1879048192u,9,24},{1845493760u,7,3},{1811939328u,7,23},{1778384896u,7,21},{1744830464u,7,5},{1728053248u,8,0},{1711276032u,8,26},{1694498816u,8,6},{1677721600u,8,20},{1610612736u,6,9},{1342177280u,4,14},{1073741824u,4,12},{805306368u,4,4},{536870912u,4,22},{268435456u,4,16},{0u,4,10},}, | 51 | {{2147483648u,1,13},{2113929216u,7,15},{2080374784u,7,1},{2046820352u,7,11},{2013265920u,7,7},{1979711488u,7,17},{1946157056u,7,25},{1912602624u,7,19},{1904214016u,9,8},{1895825408u,9,18},{1887436800u,9,2},{1879048192u,9,24},{1845493760u,7,3},{1811939328u,7,23},{1778384896u,7,21},{1744830464u,7,5},{1728053248u,8,0},{1711276032u,8,26},{1694498816u,8,6},{1677721600u,8,20},{1610612736u,6,9},{1342177280u,4,14},{1073741824u,4,12},{805306368u,4,4},{536870912u,4,22},{268435456u,4,16},{0u,4,10},}, |
52 | }; | 52 | }; |
53 | static const HuffmanTyp mpc_table_HuffQ2 [2] [5*5] = { | 53 | static const HuffmanTyp mpc_table_HuffQ2 [2] [5*5] ICONST_ATTR = { |
54 | {{4026531840u,4,13},{3758096384u,4,17},{3489660928u,4,7},{3221225472u,4,11},{3154116608u,6,1},{3087007744u,6,23},{3053453312u,7,4},{3019898880u,7,20},{2986344448u,7,0},{2952790016u,7,24},{2818572288u,5,22},{2684354560u,5,10},{2147483648u,3,12},{2013265920u,5,2},{1879048192u,5,14},{1610612736u,4,6},{1342177280u,4,18},{1073741824u,4,8},{805306368u,4,16},{671088640u,5,9},{536870912u,5,5},{402653184u,5,15},{268435456u,5,21},{134217728u,5,19},{0u,5,3},}, | 54 | {{4026531840u,4,13},{3758096384u,4,17},{3489660928u,4,7},{3221225472u,4,11},{3154116608u,6,1},{3087007744u,6,23},{3053453312u,7,4},{3019898880u,7,20},{2986344448u,7,0},{2952790016u,7,24},{2818572288u,5,22},{2684354560u,5,10},{2147483648u,3,12},{2013265920u,5,2},{1879048192u,5,14},{1610612736u,4,6},{1342177280u,4,18},{1073741824u,4,8},{805306368u,4,16},{671088640u,5,9},{536870912u,5,5},{402653184u,5,15},{268435456u,5,21},{134217728u,5,19},{0u,5,3},}, |
55 | {{4160749568u,5,18},{4026531840u,5,6},{3892314112u,5,8},{3875536896u,8,3},{3871342592u,10,24},{3867148288u,10,4},{3862953984u,10,0},{3858759680u,10,20},{3825205248u,7,23},{3791650816u,7,1},{3758096384u,7,19},{3623878656u,5,16},{3590324224u,7,15},{3556769792u,7,21},{3523215360u,7,9},{3489660928u,7,5},{3422552064u,6,2},{3355443200u,6,10},{3288334336u,6,14},{3221225472u,6,22},{2147483648u,2,12},{1610612736u,3,13},{1073741824u,3,17},{536870912u,3,11},{0u,3,7},}, | 55 | {{4160749568u,5,18},{4026531840u,5,6},{3892314112u,5,8},{3875536896u,8,3},{3871342592u,10,24},{3867148288u,10,4},{3862953984u,10,0},{3858759680u,10,20},{3825205248u,7,23},{3791650816u,7,1},{3758096384u,7,19},{3623878656u,5,16},{3590324224u,7,15},{3556769792u,7,21},{3523215360u,7,9},{3489660928u,7,5},{3422552064u,6,2},{3355443200u,6,10},{3288334336u,6,14},{3221225472u,6,22},{2147483648u,2,12},{1610612736u,3,13},{1073741824u,3,17},{536870912u,3,11},{0u,3,7},}, |
56 | }; | 56 | }; |
57 | static const HuffmanTyp mpc_table_HuffQ3 [2] [ 7] = { | 57 | static const HuffmanTyp mpc_table_HuffQ3 [2] [ 7] ICONST_ATTR = { |
58 | {{3758096384u,3,1},{3489660928u,4,3},{3221225472u,4,-3},{2684354560u,3,2},{2147483648u,3,-2},{1073741824u,2,0},{0u,2,-1},}, | 58 | {{3758096384u,3,1},{3489660928u,4,3},{3221225472u,4,-3},{2684354560u,3,2},{2147483648u,3,-2},{1073741824u,2,0},{0u,2,-1},}, |
59 | {{3221225472u,2,0},{2147483648u,2,-1},{1073741824u,2,1},{805306368u,4,-2},{671088640u,5,3},{536870912u,5,-3},{0u,3,2},}, | 59 | {{3221225472u,2,0},{2147483648u,2,-1},{1073741824u,2,1},{805306368u,4,-2},{671088640u,5,3},{536870912u,5,-3},{0u,3,2},}, |
60 | }; | 60 | }; |
61 | static const HuffmanTyp mpc_table_HuffQ4 [2] [ 9] = { | 61 | static const HuffmanTyp mpc_table_HuffQ4 [2] [ 9] ICONST_ATTR = { |
62 | {{3758096384u,3,0},{3221225472u,3,-1},{2684354560u,3,1},{2147483648u,3,-2},{1610612736u,3,2},{1342177280u,4,-4},{1073741824u,4,4},{536870912u,3,3},{0u,3,-3},}, | 62 | {{3758096384u,3,0},{3221225472u,3,-1},{2684354560u,3,1},{2147483648u,3,-2},{1610612736u,3,2},{1342177280u,4,-4},{1073741824u,4,4},{536870912u,3,3},{0u,3,-3},}, |
63 | {{3758096384u,3,1},{3489660928u,4,2},{3221225472u,4,-3},{2147483648u,2,0},{1610612736u,3,-2},{1342177280u,4,3},{1207959552u,5,-4},{1073741824u,5,4},{0u,2,-1},}, | 63 | {{3758096384u,3,1},{3489660928u,4,2},{3221225472u,4,-3},{2147483648u,2,0},{1610612736u,3,-2},{1342177280u,4,3},{1207959552u,5,-4},{1073741824u,5,4},{0u,2,-1},}, |
64 | }; | 64 | }; |
65 | static const HuffmanTyp mpc_table_HuffQ5 [2] [15] = { | 65 | static const HuffmanTyp mpc_table_HuffQ5 [2] [15] ICONST_ATTR = { |
66 | {{4026531840u,4,2},{3892314112u,5,5},{3825205248u,6,-7},{3758096384u,6,7},{3489660928u,4,-3},{3221225472u,4,3},{3087007744u,5,-6},{2952790016u,5,6},{2684354560u,4,-4},{2415919104u,4,4},{2147483648u,4,-5},{1610612736u,3,0},{1073741824u,3,-1},{536870912u,3,1},{0u,3,-2},}, | 66 | {{4026531840u,4,2},{3892314112u,5,5},{3825205248u,6,-7},{3758096384u,6,7},{3489660928u,4,-3},{3221225472u,4,3},{3087007744u,5,-6},{2952790016u,5,6},{2684354560u,4,-4},{2415919104u,4,4},{2147483648u,4,-5},{1610612736u,3,0},{1073741824u,3,-1},{536870912u,3,1},{0u,3,-2},}, |
67 | {{4026531840u,4,3},{3892314112u,5,4},{3858759680u,7,6},{3841982464u,8,-7},{3825205248u,8,7},{3758096384u,6,-6},{3221225472u,3,0},{2684354560u,3,-1},{2147483648u,3,1},{1610612736u,3,-2},{1073741824u,3,2},{939524096u,5,-5},{805306368u,5,5},{536870912u,4,-4},{0u,3,-3},}, | 67 | {{4026531840u,4,3},{3892314112u,5,4},{3858759680u,7,6},{3841982464u,8,-7},{3825205248u,8,7},{3758096384u,6,-6},{3221225472u,3,0},{2684354560u,3,-1},{2147483648u,3,1},{1610612736u,3,-2},{1073741824u,3,2},{939524096u,5,-5},{805306368u,5,5},{536870912u,4,-4},{0u,3,-3},}, |
68 | }; | 68 | }; |
69 | static const HuffmanTyp mpc_table_HuffQ6 [2] [31] = { | 69 | static const HuffmanTyp mpc_table_HuffQ6 [2] [31] ICONST_ATTR = { |
70 | {{4160749568u,5,3},{4026531840u,5,-4},{3959422976u,6,-11},{3892314112u,6,12},{3758096384u,5,4},{3623878656u,5,6},{3489660928u,5,-5},{3355443200u,5,5},{3221225472u,5,7},{3087007744u,5,-7},{3019898880u,6,-12},{2952790016u,6,-13},{2818572288u,5,-6},{2684354560u,5,8},{2550136832u,5,-8},{2415919104u,5,9},{2281701376u,5,-9},{2214592512u,6,13},{2181038080u,7,-15},{2147483648u,7,15},{1879048192u,4,0},{1744830464u,5,-10},{1610612736u,5,10},{1342177280u,4,-1},{1073741824u,4,2},{805306368u,4,1},{536870912u,4,-2},{469762048u,6,14},{402653184u,6,-14},{268435456u,5,11},{0u,4,-3},}, | 70 | {{4160749568u,5,3},{4026531840u,5,-4},{3959422976u,6,-11},{3892314112u,6,12},{3758096384u,5,4},{3623878656u,5,6},{3489660928u,5,-5},{3355443200u,5,5},{3221225472u,5,7},{3087007744u,5,-7},{3019898880u,6,-12},{2952790016u,6,-13},{2818572288u,5,-6},{2684354560u,5,8},{2550136832u,5,-8},{2415919104u,5,9},{2281701376u,5,-9},{2214592512u,6,13},{2181038080u,7,-15},{2147483648u,7,15},{1879048192u,4,0},{1744830464u,5,-10},{1610612736u,5,10},{1342177280u,4,-1},{1073741824u,4,2},{805306368u,4,1},{536870912u,4,-2},{469762048u,6,14},{402653184u,6,-14},{268435456u,5,11},{0u,4,-3},}, |
71 | {{4160749568u,5,-6},{4026531840u,5,6},{3758096384u,4,1},{3489660928u,4,-1},{3456106496u,7,10},{3422552064u,7,-10},{3405774848u,8,-11},{3397386240u,9,-12},{3395289088u,11,13},{3394764800u,13,15},{3394240512u,13,-14},{3393716224u,13,14},{3393191936u,13,-15},{3388997632u,10,-13},{3372220416u,8,11},{3355443200u,8,12},{3288334336u,6,-9},{3221225472u,6,9},{2952790016u,4,-2},{2684354560u,4,2},{2415919104u,4,3},{2147483648u,4,-3},{2013265920u,5,-7},{1879048192u,5,7},{1610612736u,4,-4},{1342177280u,4,4},{1207959552u,5,-8},{1073741824u,5,8},{805306368u,4,5},{536870912u,4,-5},{0u,3,0},}, | 71 | {{4160749568u,5,-6},{4026531840u,5,6},{3758096384u,4,1},{3489660928u,4,-1},{3456106496u,7,10},{3422552064u,7,-10},{3405774848u,8,-11},{3397386240u,9,-12},{3395289088u,11,13},{3394764800u,13,15},{3394240512u,13,-14},{3393716224u,13,14},{3393191936u,13,-15},{3388997632u,10,-13},{3372220416u,8,11},{3355443200u,8,12},{3288334336u,6,-9},{3221225472u,6,9},{2952790016u,4,-2},{2684354560u,4,2},{2415919104u,4,3},{2147483648u,4,-3},{2013265920u,5,-7},{1879048192u,5,7},{1610612736u,4,-4},{1342177280u,4,4},{1207959552u,5,-8},{1073741824u,5,8},{805306368u,4,5},{536870912u,4,-5},{0u,3,0},}, |
72 | }; | 72 | }; |
73 | static const HuffmanTyp mpc_table_HuffQ7 [2] [63] = { | 73 | static const HuffmanTyp mpc_table_HuffQ7 [2] [63] ICONST_ATTR = { |
74 | {{4227858432u,6,7},{4160749568u,6,8},{4093640704u,6,9},{4026531840u,6,-8},{3959422976u,6,11},{3925868544u,7,21},{3909091328u,8,-28},{3892314112u,8,28},{3825205248u,6,-9},{3791650816u,7,-22},{3758096384u,7,-21},{3690987520u,6,-10},{3623878656u,6,-11},{3556769792u,6,10},{3489660928u,6,12},{3422552064u,6,-13},{3388997632u,7,22},{3355443200u,7,23},{3288334336u,6,-12},{3221225472u,6,13},{3154116608u,6,14},{3087007744u,6,-14},{3053453312u,7,-23},{3036676096u,8,-29},{3019898880u,8,29},{2952790016u,6,-15},{2885681152u,6,15},{2818572288u,6,16},{2751463424u,6,-16},{2717908992u,7,-24},{2684354560u,7,24},{2617245696u,6,17},{2583691264u,7,-25},{2566914048u,8,-30},{2550136832u,8,30},{2483027968u,6,-17},{2415919104u,6,18},{2348810240u,6,-18},{2315255808u,7,25},{2281701376u,7,26},{2214592512u,6,19},{2181038080u,7,-26},{2147483648u,7,-27},{2013265920u,5,2},{1946157056u,6,-19},{1879048192u,6,20},{1744830464u,5,-1},{1728053248u,8,-31},{1711276032u,8,31},{1677721600u,7,27},{1610612736u,6,-20},{1476395008u,5,1},{1342177280u,5,-5},{1207959552u,5,-3},{1073741824u,5,3},{939524096u,5,0},{805306368u,5,-2},{671088640u,5,-4},{536870912u,5,4},{402653184u,5,5},{268435456u,5,-6},{134217728u,5,6},{0u,5,-7},}, | 74 | {{4227858432u,6,7},{4160749568u,6,8},{4093640704u,6,9},{4026531840u,6,-8},{3959422976u,6,11},{3925868544u,7,21},{3909091328u,8,-28},{3892314112u,8,28},{3825205248u,6,-9},{3791650816u,7,-22},{3758096384u,7,-21},{3690987520u,6,-10},{3623878656u,6,-11},{3556769792u,6,10},{3489660928u,6,12},{3422552064u,6,-13},{3388997632u,7,22},{3355443200u,7,23},{3288334336u,6,-12},{3221225472u,6,13},{3154116608u,6,14},{3087007744u,6,-14},{3053453312u,7,-23},{3036676096u,8,-29},{3019898880u,8,29},{2952790016u,6,-15},{2885681152u,6,15},{2818572288u,6,16},{2751463424u,6,-16},{2717908992u,7,-24},{2684354560u,7,24},{2617245696u,6,17},{2583691264u,7,-25},{2566914048u,8,-30},{2550136832u,8,30},{2483027968u,6,-17},{2415919104u,6,18},{2348810240u,6,-18},{2315255808u,7,25},{2281701376u,7,26},{2214592512u,6,19},{2181038080u,7,-26},{2147483648u,7,-27},{2013265920u,5,2},{1946157056u,6,-19},{1879048192u,6,20},{1744830464u,5,-1},{1728053248u,8,-31},{1711276032u,8,31},{1677721600u,7,27},{1610612736u,6,-20},{1476395008u,5,1},{1342177280u,5,-5},{1207959552u,5,-3},{1073741824u,5,3},{939524096u,5,0},{805306368u,5,-2},{671088640u,5,-4},{536870912u,5,4},{402653184u,5,5},{268435456u,5,-6},{134217728u,5,6},{0u,5,-7},}, |
75 | {{4160749568u,5,-1},{4026531840u,5,2},{3892314112u,5,-2},{3758096384u,5,3},{3741319168u,8,-20},{3737124864u,10,24},{3736862720u,14,28},{3736600576u,14,-28},{3736338432u,14,-30},{3736076288u,14,30},{3735027712u,12,-27},{3734765568u,14,29},{3734503424u,14,-29},{3734241280u,14,31},{3733979136u,14,-31},{3732930560u,12,27},{3724541952u,9,-22},{3690987520u,7,-17},{3623878656u,6,-11},{3489660928u,5,-3},{3355443200u,5,4},{3221225472u,5,-4},{3187671040u,7,17},{3170893824u,8,20},{3162505216u,9,22},{3158310912u,10,-25},{3154116608u,10,-26},{3087007744u,6,12},{2952790016u,5,5},{2818572288u,5,-5},{2684354560u,5,6},{2550136832u,5,-6},{2483027968u,6,-12},{2449473536u,7,-18},{2415919104u,7,18},{2348810240u,6,13},{2281701376u,6,-13},{2147483648u,5,-7},{2080374784u,6,14},{2063597568u,8,21},{2046820352u,8,-21},{2013265920u,7,-19},{1879048192u,5,7},{1744830464u,5,8},{1677721600u,6,-14},{1610612736u,6,-15},{1476395008u,5,-8},{1409286144u,6,15},{1375731712u,7,19},{1371537408u,10,25},{1367343104u,10,26},{1358954496u,9,-23},{1350565888u,9,23},{1342177280u,9,-24},{1207959552u,5,-9},{1073741824u,5,9},{1006632960u,6,16},{939524096u,6,-16},{805306368u,5,10},{536870912u,4,0},{402653184u,5,-10},{268435456u,5,11},{0u,4,1},}, | 75 | {{4160749568u,5,-1},{4026531840u,5,2},{3892314112u,5,-2},{3758096384u,5,3},{3741319168u,8,-20},{3737124864u,10,24},{3736862720u,14,28},{3736600576u,14,-28},{3736338432u,14,-30},{3736076288u,14,30},{3735027712u,12,-27},{3734765568u,14,29},{3734503424u,14,-29},{3734241280u,14,31},{3733979136u,14,-31},{3732930560u,12,27},{3724541952u,9,-22},{3690987520u,7,-17},{3623878656u,6,-11},{3489660928u,5,-3},{3355443200u,5,4},{3221225472u,5,-4},{3187671040u,7,17},{3170893824u,8,20},{3162505216u,9,22},{3158310912u,10,-25},{3154116608u,10,-26},{3087007744u,6,12},{2952790016u,5,5},{2818572288u,5,-5},{2684354560u,5,6},{2550136832u,5,-6},{2483027968u,6,-12},{2449473536u,7,-18},{2415919104u,7,18},{2348810240u,6,13},{2281701376u,6,-13},{2147483648u,5,-7},{2080374784u,6,14},{2063597568u,8,21},{2046820352u,8,-21},{2013265920u,7,-19},{1879048192u,5,7},{1744830464u,5,8},{1677721600u,6,-14},{1610612736u,6,-15},{1476395008u,5,-8},{1409286144u,6,15},{1375731712u,7,19},{1371537408u,10,25},{1367343104u,10,26},{1358954496u,9,-23},{1350565888u,9,23},{1342177280u,9,-24},{1207959552u,5,-9},{1073741824u,5,9},{1006632960u,6,16},{939524096u,6,-16},{805306368u,5,10},{536870912u,4,0},{402653184u,5,-10},{268435456u,5,11},{0u,4,1},}, |
76 | }; | 76 | }; |
diff --git a/apps/codecs/libmusepack/internal.h b/apps/codecs/libmusepack/internal.h index 44279e2fa5..45f2b41eea 100644 --- a/apps/codecs/libmusepack/internal.h +++ b/apps/codecs/libmusepack/internal.h | |||
@@ -54,6 +54,10 @@ mpc_uint32_t mpc_swap32(mpc_uint32_t val) { | |||
54 | } | 54 | } |
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | #ifndef min | ||
58 | #define min(a, b) (((a) < (b)) ? (a) : (b)) | ||
59 | #endif | ||
60 | |||
57 | /// Searches for a ID3v2-tag and reads the length (in bytes) of it. | 61 | /// Searches for a ID3v2-tag and reads the length (in bytes) of it. |
58 | /// \param reader supplying raw stream data | 62 | /// \param reader supplying raw stream data |
59 | /// \return size of tag, in bytes | 63 | /// \return size of tag, in bytes |
diff --git a/apps/codecs/libmusepack/mpc_decoder.c b/apps/codecs/libmusepack/mpc_decoder.c index fc1755ff60..4bf36bddc6 100644 --- a/apps/codecs/libmusepack/mpc_decoder.c +++ b/apps/codecs/libmusepack/mpc_decoder.c | |||
@@ -58,6 +58,38 @@ extern const HuffmanTyp mpc_table_Region_C [ 4]; | |||
58 | 58 | ||
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | #ifndef MPC_LITTLE_ENDIAN | ||
62 | #define SWAP(X) mpc_swap32(X) | ||
63 | #else | ||
64 | #define SWAP(X) X | ||
65 | #endif | ||
66 | |||
67 | #ifdef SCF_HACK | ||
68 | #define SCF_DIFF(SCF, D) (SCF == -128 ? -128 : SCF + D) | ||
69 | #else | ||
70 | #define SCF_DIFF(SCF, D) SCF + D | ||
71 | #endif | ||
72 | |||
73 | #define LOOKUP(x, e, q) mpc_decoder_make_huffman_lookup ( (q), sizeof(q), (x), (e) ) | ||
74 | #define Decode_DSCF() HUFFMAN_DECODE_FASTEST ( d, mpc_table_HuffDSCF, LUTDSCF, 6 ) | ||
75 | #define HUFFMAN_DECODE_FASTEST(d,a,b,c) mpc_decoder_huffman_decode_fastest ( (d), (a), (b), 32-(c) ) | ||
76 | #define HUFFMAN_DECODE_FASTERER(d,a,b,c) mpc_decoder_huffman_decode_fasterer ( (d), (a), (b), 32-(c) ) | ||
77 | |||
78 | mpc_uint8_t LUT1_0 [1<< 6]; | ||
79 | mpc_uint8_t LUT1_1 [1<< 9]; // 576 Bytes | ||
80 | mpc_uint8_t LUT2_0 [1<< 7]; | ||
81 | mpc_uint8_t LUT2_1 [1<<10]; // 1152 Bytes | ||
82 | mpc_uint8_t LUT3_0 [1<< 4]; | ||
83 | mpc_uint8_t LUT3_1 [1<< 5]; // 48 Bytes | ||
84 | mpc_uint8_t LUT4_0 [1<< 4]; | ||
85 | mpc_uint8_t LUT4_1 [1<< 5]; // 48 Bytes | ||
86 | mpc_uint8_t LUT5_0 [1<< 6]; | ||
87 | mpc_uint8_t LUT5_1 [1<< 8]; // 320 Bytes | ||
88 | mpc_uint8_t LUT6_0 [1<< 7]; | ||
89 | mpc_uint8_t LUT6_1 [1<< 7]; // 256 Bytes | ||
90 | mpc_uint8_t LUT7_0 [1<< 8];mpc_uint8_t LUT7_1 [1<< 8]; // 512 Bytes | ||
91 | mpc_uint8_t LUTDSCF [1<< 6]; // 64 Bytes = 2976 Bytes | ||
92 | |||
61 | //------------------------------------------------------------------------------ | 93 | //------------------------------------------------------------------------------ |
62 | // types | 94 | // types |
63 | //------------------------------------------------------------------------------ | 95 | //------------------------------------------------------------------------------ |
@@ -75,10 +107,20 @@ enum | |||
75 | // forward declarations | 107 | // forward declarations |
76 | //------------------------------------------------------------------------------ | 108 | //------------------------------------------------------------------------------ |
77 | void mpc_decoder_read_bitstream_sv6(mpc_decoder *d); | 109 | void mpc_decoder_read_bitstream_sv6(mpc_decoder *d); |
78 | void mpc_decoder_read_bitstream_sv7(mpc_decoder *d); | 110 | void mpc_decoder_read_bitstream_sv7(mpc_decoder *d, mpc_bool_t fastSeeking); |
79 | void mpc_decoder_update_buffer(mpc_decoder *d, mpc_uint32_t RING); | 111 | void mpc_decoder_update_buffer(mpc_decoder *d); |
80 | mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample); | 112 | mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample); |
81 | void mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band); | 113 | void mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band); |
114 | void mpc_decoder_seek_to(mpc_decoder *d, mpc_uint32_t bitPos); | ||
115 | void mpc_decoder_seek_forward(mpc_decoder *d, mpc_uint32_t bits); | ||
116 | mpc_uint32_t mpc_decoder_jump_frame(mpc_decoder *d); | ||
117 | void mpc_decoder_fill_buffer(mpc_decoder *d); | ||
118 | void mpc_decoder_reset_state(mpc_decoder *d); | ||
119 | static mpc_uint32_t get_initial_fpos(mpc_decoder *d, mpc_uint32_t StreamVersion); | ||
120 | static inline mpc_int32_t mpc_decoder_huffman_decode_fastest(mpc_decoder *d, const HuffmanTyp* Table, const mpc_uint8_t* tab, mpc_uint16_t unused_bits); | ||
121 | static void mpc_move_next(mpc_decoder *d); | ||
122 | |||
123 | mpc_uint32_t Speicher[MPC_DECODER_MEMSIZE]; | ||
82 | 124 | ||
83 | //------------------------------------------------------------------------------ | 125 | //------------------------------------------------------------------------------ |
84 | // utility functions | 126 | // utility functions |
@@ -96,19 +138,13 @@ static mpc_bool_t f_seek(mpc_decoder *d, mpc_int32_t offset) | |||
96 | static mpc_int32_t f_read_dword(mpc_decoder *d, mpc_uint32_t * ptr, mpc_uint32_t count) | 138 | static mpc_int32_t f_read_dword(mpc_decoder *d, mpc_uint32_t * ptr, mpc_uint32_t count) |
97 | { | 139 | { |
98 | count = f_read(d, ptr, count << 2) >> 2; | 140 | count = f_read(d, ptr, count << 2) >> 2; |
99 | #ifndef MPC_LITTLE_ENDIAN | ||
100 | mpc_uint32_t n; | ||
101 | for(n = 0; n< count; n++) { | ||
102 | ptr[n] = mpc_swap32(ptr[n]); | ||
103 | } | ||
104 | #endif | ||
105 | return count; | 141 | return count; |
106 | } | 142 | } |
107 | 143 | ||
108 | //------------------------------------------------------------------------------ | 144 | //------------------------------------------------------------------------------ |
109 | // huffman & bitstream functions | 145 | // huffman & bitstream functions |
110 | //------------------------------------------------------------------------------ | 146 | //------------------------------------------------------------------------------ |
111 | static const mpc_uint32_t mask [33] = { | 147 | static const mpc_uint32_t mask [33] ICONST_ATTR = { |
112 | 0x00000000, 0x00000001, 0x00000003, 0x00000007, | 148 | 0x00000000, 0x00000001, 0x00000003, 0x00000007, |
113 | 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F, | 149 | 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F, |
114 | 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF, | 150 | 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF, |
@@ -127,6 +163,7 @@ static void | |||
127 | mpc_decoder_reset_bitstream_decode(mpc_decoder *d) | 163 | mpc_decoder_reset_bitstream_decode(mpc_decoder *d) |
128 | { | 164 | { |
129 | d->dword = 0; | 165 | d->dword = 0; |
166 | d->next = 0; | ||
130 | d->pos = 0; | 167 | d->pos = 0; |
131 | d->Zaehler = 0; | 168 | d->Zaehler = 0; |
132 | d->WordsRead = 0; | 169 | d->WordsRead = 0; |
@@ -139,8 +176,16 @@ mpc_decoder_bits_read(mpc_decoder *d) | |||
139 | return 32 * d->WordsRead + d->pos; | 176 | return 32 * d->WordsRead + d->pos; |
140 | } | 177 | } |
141 | 178 | ||
179 | static void mpc_move_next(mpc_decoder *d) { | ||
180 | d->Zaehler = (d->Zaehler + 1) & MEMMASK; | ||
181 | d->dword = d->next; | ||
182 | d->next = SWAP(d->Speicher[(d->Zaehler + 1) & MEMMASK]); | ||
183 | d->pos -= 32; | ||
184 | ++(d->WordsRead); | ||
185 | } | ||
186 | |||
142 | // read desired number of bits out of the bitstream | 187 | // read desired number of bits out of the bitstream |
143 | static mpc_uint32_t | 188 | static inline mpc_uint32_t |
144 | mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits) | 189 | mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits) |
145 | { | 190 | { |
146 | mpc_uint32_t out = d->dword; | 191 | mpc_uint32_t out = d->dword; |
@@ -151,28 +196,45 @@ mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits) | |||
151 | out >>= (32 - d->pos); | 196 | out >>= (32 - d->pos); |
152 | } | 197 | } |
153 | else { | 198 | else { |
154 | d->dword = d->Speicher[d->Zaehler = (d->Zaehler + 1) & MEMMASK]; | 199 | mpc_move_next(d); |
155 | d->pos -= 32; | ||
156 | if (d->pos) { | 200 | if (d->pos) { |
157 | out <<= d->pos; | 201 | out <<= d->pos; |
158 | out |= d->dword >> (32 - d->pos); | 202 | out |= d->dword >> (32 - d->pos); |
159 | } | 203 | } |
160 | ++(d->WordsRead); | ||
161 | } | 204 | } |
162 | 205 | ||
163 | return out & mask[bits]; | 206 | return out & mask[bits]; |
164 | } | 207 | } |
165 | 208 | ||
209 | static void | ||
210 | mpc_decoder_make_huffman_lookup( | ||
211 | mpc_uint8_t* lookup, size_t length, const HuffmanTyp* Table, size_t elements ) | ||
212 | { | ||
213 | size_t i; | ||
214 | size_t idx = elements; | ||
215 | mpc_uint32_t dval = (mpc_uint32_t)0x80000000L / length * 2; | ||
216 | mpc_uint32_t val = dval - 1; | ||
217 | |||
218 | for ( i = 0; i < length; i++, val += dval ) { | ||
219 | while ( idx > 0 && val >= Table[idx-1].Code ) | ||
220 | idx--; | ||
221 | *lookup++ = (mpc_uint8_t)idx; | ||
222 | } | ||
223 | |||
224 | return; | ||
225 | } | ||
226 | |||
166 | // decode SCFI-bundle (sv4,5,6) | 227 | // decode SCFI-bundle (sv4,5,6) |
167 | static void | 228 | static void |
168 | mpc_decoder_scfi_bundle_read( | 229 | mpc_decoder_scfi_bundle_read( |
169 | mpc_decoder *d, | 230 | mpc_decoder *d, |
170 | const HuffmanTyp* Table, mpc_int32_t* SCFI, mpc_bool_t* DSCF) | 231 | const HuffmanTyp* Table, mpc_int8_t* SCFI, mpc_bool_t* DSCF) |
171 | { | 232 | { |
172 | // load preview and decode | 233 | // load preview and decode |
173 | mpc_uint32_t code = d->dword << d->pos; | 234 | mpc_uint32_t code = d->dword << d->pos; |
235 | |||
174 | if (d->pos > 26) { | 236 | if (d->pos > 26) { |
175 | code |= d->Speicher[(d->Zaehler + 1) & MEMMASK] >> (32 - d->pos); | 237 | code |= d->next >> (32 - d->pos); |
176 | } | 238 | } |
177 | while (code < Table->Code) { | 239 | while (code < Table->Code) { |
178 | Table++; | 240 | Table++; |
@@ -180,9 +242,7 @@ mpc_decoder_scfi_bundle_read( | |||
180 | 242 | ||
181 | // set the new position within bitstream without performing a dummy-read | 243 | // set the new position within bitstream without performing a dummy-read |
182 | if ((d->pos += Table->Length) >= 32) { | 244 | if ((d->pos += Table->Length) >= 32) { |
183 | d->pos -= 32; | 245 | mpc_move_next(d); |
184 | d->dword = d->Speicher[d->Zaehler = (d->Zaehler+1) & MEMMASK]; | ||
185 | ++(d->WordsRead); | ||
186 | } | 246 | } |
187 | 247 | ||
188 | *SCFI = Table->Value >> 1; | 248 | *SCFI = Table->Value >> 1; |
@@ -196,8 +256,9 @@ mpc_decoder_huffman_decode(mpc_decoder *d, const HuffmanTyp *Table) | |||
196 | { | 256 | { |
197 | // load preview and decode | 257 | // load preview and decode |
198 | mpc_uint32_t code = d->dword << d->pos; | 258 | mpc_uint32_t code = d->dword << d->pos; |
259 | |||
199 | if (d->pos > 18) { | 260 | if (d->pos > 18) { |
200 | code |= d->Speicher[(d->Zaehler + 1) & MEMMASK] >> (32 - d->pos); | 261 | code |= d->next >> (32 - d->pos); |
201 | } | 262 | } |
202 | while (code < Table->Code) { | 263 | while (code < Table->Code) { |
203 | Table++; | 264 | Table++; |
@@ -205,9 +266,7 @@ mpc_decoder_huffman_decode(mpc_decoder *d, const HuffmanTyp *Table) | |||
205 | 266 | ||
206 | // set the new position within bitstream without performing a dummy-read | 267 | // set the new position within bitstream without performing a dummy-read |
207 | if ((d->pos += Table->Length) >= 32) { | 268 | if ((d->pos += Table->Length) >= 32) { |
208 | d->pos -= 32; | 269 | mpc_move_next(d); |
209 | d->dword = d->Speicher[d->Zaehler = (d->Zaehler + 1) & MEMMASK]; | ||
210 | ++(d->WordsRead); | ||
211 | } | 270 | } |
212 | 271 | ||
213 | return Table->Value; | 272 | return Table->Value; |
@@ -220,8 +279,9 @@ mpc_decoder_huffman_decode_fast(mpc_decoder *d, const HuffmanTyp* Table) | |||
220 | { | 279 | { |
221 | // load preview and decode | 280 | // load preview and decode |
222 | mpc_uint32_t code = d->dword << d->pos; | 281 | mpc_uint32_t code = d->dword << d->pos; |
282 | |||
223 | if (d->pos > 22) { | 283 | if (d->pos > 22) { |
224 | code |= d->Speicher[(d->Zaehler + 1) & MEMMASK] >> (32 - d->pos); | 284 | code |= d->next >> (32 - d->pos); |
225 | } | 285 | } |
226 | while (code < Table->Code) { | 286 | while (code < Table->Code) { |
227 | Table++; | 287 | Table++; |
@@ -229,9 +289,7 @@ mpc_decoder_huffman_decode_fast(mpc_decoder *d, const HuffmanTyp* Table) | |||
229 | 289 | ||
230 | // set the new position within bitstream without performing a dummy-read | 290 | // set the new position within bitstream without performing a dummy-read |
231 | if ((d->pos += Table->Length) >= 32) { | 291 | if ((d->pos += Table->Length) >= 32) { |
232 | d->pos -= 32; | 292 | mpc_move_next(d); |
233 | d->dword = d->Speicher[d->Zaehler = (d->Zaehler + 1) & MEMMASK]; | ||
234 | ++(d->WordsRead); | ||
235 | } | 293 | } |
236 | 294 | ||
237 | return Table->Value; | 295 | return Table->Value; |
@@ -244,32 +302,73 @@ mpc_decoder_huffman_decode_faster(mpc_decoder *d, const HuffmanTyp* Table) | |||
244 | { | 302 | { |
245 | // load preview and decode | 303 | // load preview and decode |
246 | mpc_uint32_t code = d->dword << d->pos; | 304 | mpc_uint32_t code = d->dword << d->pos; |
305 | |||
247 | if (d->pos > 27) { | 306 | if (d->pos > 27) { |
248 | code |= d->Speicher[(d->Zaehler + 1) & MEMMASK] >> (32 - d->pos); | 307 | code |= d->next >> (32 - d->pos); |
308 | } | ||
309 | while (code < Table->Code) { | ||
310 | Table++; | ||
311 | } | ||
312 | |||
313 | // set the new position within bitstream without performing a dummy-read | ||
314 | if ((d->pos += Table->Length) >= 32) { | ||
315 | mpc_move_next(d); | ||
249 | } | 316 | } |
317 | |||
318 | return Table->Value; | ||
319 | } | ||
320 | |||
321 | /* partial lookup table decode */ | ||
322 | static mpc_int32_t | ||
323 | mpc_decoder_huffman_decode_fasterer(mpc_decoder *d, const HuffmanTyp* Table, const mpc_uint8_t* tab, mpc_uint16_t unused_bits) | ||
324 | { | ||
325 | // load preview and decode | ||
326 | mpc_uint32_t code = d->dword << d->pos; | ||
327 | |||
328 | if (d->pos > 18) { // preview 14 bits | ||
329 | code |= d->next >> (32 - d->pos); | ||
330 | } | ||
331 | |||
332 | Table += tab [(size_t)(code >> unused_bits) ]; | ||
333 | |||
250 | while (code < Table->Code) { | 334 | while (code < Table->Code) { |
251 | Table++; | 335 | Table++; |
252 | } | 336 | } |
253 | 337 | ||
254 | // set the new position within bitstream without performing a dummy-read | 338 | // set the new position within bitstream without performing a dummy-read |
255 | if ((d->pos += Table->Length) >= 32) { | 339 | if ((d->pos += Table->Length) >= 32) { |
256 | d->pos -= 32; | 340 | mpc_move_next(d); |
257 | d->dword = d->Speicher[d->Zaehler = (d->Zaehler + 1) & MEMMASK]; | ||
258 | ++(d->WordsRead); | ||
259 | } | 341 | } |
260 | 342 | ||
261 | return Table->Value; | 343 | return Table->Value; |
262 | } | 344 | } |
263 | 345 | ||
264 | MPC_SAMPLE_FORMAT V_L[MPC_V_MEM + 960] IBSS_ATTR; | 346 | /* full decode using lookup table */ |
265 | MPC_SAMPLE_FORMAT V_R[MPC_V_MEM + 960] IBSS_ATTR; | 347 | static inline mpc_int32_t |
348 | mpc_decoder_huffman_decode_fastest(mpc_decoder *d, const HuffmanTyp* Table, const mpc_uint8_t* tab, mpc_uint16_t unused_bits) | ||
349 | { | ||
350 | // load preview and decode | ||
351 | mpc_uint32_t code = d->dword << d->pos; | ||
352 | |||
353 | if (d->pos > unused_bits) { | ||
354 | code |= d->next >> (32 - d->pos); | ||
355 | } | ||
356 | |||
357 | Table+=tab [(size_t)(code >> unused_bits) ]; | ||
358 | |||
359 | // set the new position within bitstream without performing a dummy-read | ||
360 | if ((d->pos += Table->Length) >= 32) { | ||
361 | mpc_move_next(d); | ||
362 | } | ||
363 | |||
364 | return Table->Value; | ||
365 | } | ||
266 | 366 | ||
267 | static void | 367 | static void |
268 | mpc_decoder_reset_v(mpc_decoder *d) | 368 | mpc_decoder_reset_v(mpc_decoder *d) |
269 | { | 369 | { |
270 | /* since d->V_L and d->V_R are now pointers, sizeof (d->V_x) will no longer work */ | 370 | memset(d->V_L, 0, sizeof d->V_L); |
271 | memset(d->V_L, 0, sizeof V_L); | 371 | memset(d->V_R, 0, sizeof d->V_R); |
272 | memset(d->V_R, 0, sizeof V_R); | ||
273 | } | 372 | } |
274 | 373 | ||
275 | static void | 374 | static void |
@@ -291,6 +390,8 @@ mpc_decoder_reset_globals(mpc_decoder *d) | |||
291 | mpc_decoder_reset_bitstream_decode(d); | 390 | mpc_decoder_reset_bitstream_decode(d); |
292 | 391 | ||
293 | d->DecodedFrames = 0; | 392 | d->DecodedFrames = 0; |
393 | d->SeekTableIndex = 0; | ||
394 | d->MaxDecodedFrames = 0; | ||
294 | d->StreamVersion = 0; | 395 | d->StreamVersion = 0; |
295 | d->MS_used = 0; | 396 | d->MS_used = 0; |
296 | 397 | ||
@@ -302,10 +403,12 @@ mpc_decoder_reset_globals(mpc_decoder *d) | |||
302 | memset(d->Res_R , 0, sizeof d->Res_R ); | 403 | memset(d->Res_R , 0, sizeof d->Res_R ); |
303 | memset(d->SCFI_L , 0, sizeof d->SCFI_L ); | 404 | memset(d->SCFI_L , 0, sizeof d->SCFI_L ); |
304 | memset(d->SCFI_R , 0, sizeof d->SCFI_R ); | 405 | memset(d->SCFI_R , 0, sizeof d->SCFI_R ); |
406 | #ifdef MPC_SUPPORT_SV456 | ||
305 | memset(d->DSCF_Flag_L , 0, sizeof d->DSCF_Flag_L ); | 407 | memset(d->DSCF_Flag_L , 0, sizeof d->DSCF_Flag_L ); |
306 | memset(d->DSCF_Flag_R , 0, sizeof d->DSCF_Flag_R ); | 408 | memset(d->DSCF_Flag_R , 0, sizeof d->DSCF_Flag_R ); |
307 | memset(d->DSCF_Reference_L, 0, sizeof d->DSCF_Reference_L ); | 409 | #endif |
308 | memset(d->DSCF_Reference_R, 0, sizeof d->DSCF_Reference_R ); | 410 | //memset(d->DSCF_Reference_L, 0, sizeof d->DSCF_Reference_L ); |
411 | //memset(d->DSCF_Reference_R, 0, sizeof d->DSCF_Reference_R ); | ||
309 | memset(d->Q , 0, sizeof d->Q ); | 412 | memset(d->Q , 0, sizeof d->Q ); |
310 | memset(d->MS_Flag , 0, sizeof d->MS_Flag ); | 413 | memset(d->MS_Flag , 0, sizeof d->MS_Flag ); |
311 | } | 414 | } |
@@ -314,16 +417,11 @@ mpc_uint32_t | |||
314 | mpc_decoder_decode_frame(mpc_decoder *d, mpc_uint32_t *in_buffer, | 417 | mpc_decoder_decode_frame(mpc_decoder *d, mpc_uint32_t *in_buffer, |
315 | mpc_uint32_t in_len, MPC_SAMPLE_FORMAT *out_buffer) | 418 | mpc_uint32_t in_len, MPC_SAMPLE_FORMAT *out_buffer) |
316 | { | 419 | { |
317 | unsigned int i; | ||
318 | mpc_decoder_reset_bitstream_decode(d); | 420 | mpc_decoder_reset_bitstream_decode(d); |
319 | if (in_len > sizeof(d->Speicher)) in_len = sizeof(d->Speicher); | 421 | if (in_len > sizeof(Speicher)) in_len = sizeof(Speicher); |
320 | memcpy(d->Speicher, in_buffer, in_len); | 422 | memcpy(d->Speicher, in_buffer, in_len); |
321 | #ifdef MPC_LITTLE_ENDIAN | 423 | d->dword = SWAP(d->Speicher[0]); |
322 | for (i = 0; i < (in_len + 3) / 4; i++) | 424 | d->next = SWAP(d->Speicher[1]); |
323 | d->Speicher[i] = mpc_swap32(d->Speicher[i]); | ||
324 | #endif | ||
325 | (void)i; /* avoid warning */ | ||
326 | d->dword = d->Speicher[0]; | ||
327 | switch (d->StreamVersion) { | 425 | switch (d->StreamVersion) { |
328 | #ifdef MPC_SUPPORT_SV456 | 426 | #ifdef MPC_SUPPORT_SV456 |
329 | case 0x04: | 427 | case 0x04: |
@@ -334,7 +432,7 @@ mpc_decoder_decode_frame(mpc_decoder *d, mpc_uint32_t *in_buffer, | |||
334 | #endif | 432 | #endif |
335 | case 0x07: | 433 | case 0x07: |
336 | case 0x17: | 434 | case 0x17: |
337 | mpc_decoder_read_bitstream_sv7(d); | 435 | mpc_decoder_read_bitstream_sv7(d, FALSE); |
338 | break; | 436 | break; |
339 | default: | 437 | default: |
340 | return (mpc_uint32_t)(-1); | 438 | return (mpc_uint32_t)(-1); |
@@ -359,7 +457,7 @@ mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer) | |||
359 | mpc_decoder_reset_y(d); | 457 | mpc_decoder_reset_y(d); |
360 | } else { | 458 | } else { |
361 | mpc_decoder_bitstream_read(d, 20); | 459 | mpc_decoder_bitstream_read(d, 20); |
362 | mpc_decoder_read_bitstream_sv7(d); | 460 | mpc_decoder_read_bitstream_sv7(d, FALSE); |
363 | mpc_decoder_requantisierung(d, d->Max_Band); | 461 | mpc_decoder_requantisierung(d, d->Max_Band); |
364 | } | 462 | } |
365 | mpc_decoder_synthese_filter_float(d, buffer); | 463 | mpc_decoder_synthese_filter_float(d, buffer); |
@@ -370,6 +468,9 @@ mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer) | |||
370 | return (mpc_uint32_t)(-1); // end of file -> abort decoding | 468 | return (mpc_uint32_t)(-1); // end of file -> abort decoding |
371 | } | 469 | } |
372 | 470 | ||
471 | if (d->DecodedFrames == 0 && d->Use_SeekTable) | ||
472 | d->SeekTable[0] = mpc_decoder_bits_read(d); | ||
473 | |||
373 | // read jump-info for validity check of frame | 474 | // read jump-info for validity check of frame |
374 | d->FwdJumpInfo = mpc_decoder_bitstream_read(d, 20); | 475 | d->FwdJumpInfo = mpc_decoder_bitstream_read(d, 20); |
375 | 476 | ||
@@ -387,13 +488,28 @@ mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer) | |||
387 | #endif | 488 | #endif |
388 | case 0x07: | 489 | case 0x07: |
389 | case 0x17: | 490 | case 0x17: |
390 | mpc_decoder_read_bitstream_sv7(d); | 491 | mpc_decoder_read_bitstream_sv7(d, FALSE); |
391 | break; | 492 | break; |
392 | default: | 493 | default: |
393 | return (mpc_uint32_t)(-1); | 494 | return (mpc_uint32_t)(-1); |
394 | } | 495 | } |
395 | d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == d->FwdJumpInfo; | 496 | d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == d->FwdJumpInfo; |
396 | 497 | ||
498 | d->DecodedFrames++; | ||
499 | |||
500 | if (d->Use_SeekTable) { | ||
501 | if (d->SeekTable_Step == 1) { | ||
502 | d->SeekTable [d->DecodedFrames] = d->FwdJumpInfo + 20; | ||
503 | } else { | ||
504 | if ((d->DecodedFrames-1) % d->SeekTable_Step == 0) { | ||
505 | d->SeekTable[d->SeekTableIndex] = d->SeekTableCounter; | ||
506 | d->SeekTableIndex += 1; | ||
507 | d->SeekTableCounter = 0; | ||
508 | } | ||
509 | d->SeekTableCounter += d->FwdJumpInfo + 20; | ||
510 | } | ||
511 | } | ||
512 | |||
397 | // synthesize signal | 513 | // synthesize signal |
398 | mpc_decoder_requantisierung(d, d->Max_Band); | 514 | mpc_decoder_requantisierung(d, d->Max_Band); |
399 | 515 | ||
@@ -402,8 +518,6 @@ mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer) | |||
402 | 518 | ||
403 | mpc_decoder_synthese_filter_float(d, buffer); | 519 | mpc_decoder_synthese_filter_float(d, buffer); |
404 | 520 | ||
405 | d->DecodedFrames++; | ||
406 | |||
407 | // cut off first MPC_DECODER_SYNTH_DELAY zero-samples | 521 | // cut off first MPC_DECODER_SYNTH_DELAY zero-samples |
408 | if (d->DecodedFrames == d->OverallFrames && d->StreamVersion >= 6) { | 522 | if (d->DecodedFrames == d->OverallFrames && d->StreamVersion >= 6) { |
409 | // reconstruct exact filelength | 523 | // reconstruct exact filelength |
@@ -483,7 +597,7 @@ mpc_uint32_t mpc_decoder_decode( | |||
483 | } | 597 | } |
484 | 598 | ||
485 | } | 599 | } |
486 | mpc_decoder_update_buffer(d, RING); | 600 | mpc_decoder_update_buffer(d); |
487 | 601 | ||
488 | if (valid_samples > 0) { | 602 | if (valid_samples > 0) { |
489 | return valid_samples; | 603 | return valid_samples; |
@@ -502,8 +616,8 @@ mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) | |||
502 | MPC_SAMPLE_FORMAT tempr; | 616 | MPC_SAMPLE_FORMAT tempr; |
503 | MPC_SAMPLE_FORMAT* YL; | 617 | MPC_SAMPLE_FORMAT* YL; |
504 | MPC_SAMPLE_FORMAT* YR; | 618 | MPC_SAMPLE_FORMAT* YR; |
505 | mpc_int32_t* L; | 619 | mpc_int16_t* L; |
506 | mpc_int32_t* R; | 620 | mpc_int16_t* R; |
507 | 621 | ||
508 | #ifdef MPC_FIXED_POINT | 622 | #ifdef MPC_FIXED_POINT |
509 | #if MPC_FIXED_POINT_FRACTPART == 14 | 623 | #if MPC_FIXED_POINT_FRACTPART == 14 |
@@ -694,10 +808,12 @@ mpc_decoder_read_bitstream_sv6(mpc_decoder *d) | |||
694 | const HuffmanTyp *Table; | 808 | const HuffmanTyp *Table; |
695 | const HuffmanTyp *x1; | 809 | const HuffmanTyp *x1; |
696 | const HuffmanTyp *x2; | 810 | const HuffmanTyp *x2; |
697 | mpc_int32_t *L; | 811 | mpc_int8_t *L; |
698 | mpc_int32_t *R; | 812 | mpc_int8_t *R; |
699 | mpc_int32_t *ResL = d->Res_L; | 813 | mpc_int16_t *QL; |
700 | mpc_int32_t *ResR = d->Res_R; | 814 | mpc_int16_t *QR; |
815 | mpc_int8_t *ResL = d->Res_L; | ||
816 | mpc_int8_t *ResR = d->Res_R; | ||
701 | 817 | ||
702 | /************************ HEADER **************************/ | 818 | /************************ HEADER **************************/ |
703 | ResL = d->Res_L; | 819 | ResL = d->Res_L; |
@@ -738,7 +854,7 @@ mpc_decoder_read_bitstream_sv6(mpc_decoder *d) | |||
738 | /*********** DSCF ************/ | 854 | /*********** DSCF ************/ |
739 | if (d->DSCF_Flag_L[n]==1) | 855 | if (d->DSCF_Flag_L[n]==1) |
740 | { | 856 | { |
741 | L[2] = d->DSCF_Reference_L[n]; | 857 | //L[2] = d->DSCF_Reference_L[n]; |
742 | switch (d->SCFI_L[n]) | 858 | switch (d->SCFI_L[n]) |
743 | { | 859 | { |
744 | case 3: | 860 | case 3: |
@@ -797,11 +913,11 @@ mpc_decoder_read_bitstream_sv6(mpc_decoder *d) | |||
797 | } | 913 | } |
798 | } | 914 | } |
799 | // update Reference for DSCF | 915 | // update Reference for DSCF |
800 | d->DSCF_Reference_L[n] = L[2]; | 916 | //d->DSCF_Reference_L[n] = L[2]; |
801 | } | 917 | } |
802 | if (*ResR) | 918 | if (*ResR) |
803 | { | 919 | { |
804 | R[2] = d->DSCF_Reference_R[n]; | 920 | //R[2] = d->DSCF_Reference_R[n]; |
805 | /*********** DSCF ************/ | 921 | /*********** DSCF ************/ |
806 | if (d->DSCF_Flag_R[n]==1) | 922 | if (d->DSCF_Flag_R[n]==1) |
807 | { | 923 | { |
@@ -863,7 +979,7 @@ mpc_decoder_read_bitstream_sv6(mpc_decoder *d) | |||
863 | } | 979 | } |
864 | } | 980 | } |
865 | // update Reference for DSCF | 981 | // update Reference for DSCF |
866 | d->DSCF_Reference_R[n] = R[2]; | 982 | //d->DSCF_Reference_R[n] = R[2]; |
867 | } | 983 | } |
868 | } | 984 | } |
869 | 985 | ||
@@ -875,28 +991,28 @@ mpc_decoder_read_bitstream_sv6(mpc_decoder *d) | |||
875 | // setting pointers | 991 | // setting pointers |
876 | x1 = mpc_table_SampleHuff[*ResL]; | 992 | x1 = mpc_table_SampleHuff[*ResL]; |
877 | x2 = mpc_table_SampleHuff[*ResR]; | 993 | x2 = mpc_table_SampleHuff[*ResR]; |
878 | L = d->Q[n].L; | 994 | QL = d->Q[n].L; |
879 | R = d->Q[n].R; | 995 | QR = d->Q[n].R; |
880 | 996 | ||
881 | if (x1!=NULL || x2!=NULL) | 997 | if (x1!=NULL || x2!=NULL) |
882 | for (k=0; k<36; ++k) | 998 | for (k=0; k<36; ++k) |
883 | { | 999 | { |
884 | if (x1 != NULL) *L++ = mpc_decoder_huffman_decode_fast(d, x1); | 1000 | if (x1 != NULL) *QL++ = mpc_decoder_huffman_decode_fast(d, x1); |
885 | if (x2 != NULL) *R++ = mpc_decoder_huffman_decode_fast(d, x2); | 1001 | if (x2 != NULL) *QR++ = mpc_decoder_huffman_decode_fast(d, x2); |
886 | } | 1002 | } |
887 | 1003 | ||
888 | if (*ResL>7 || *ResR>7) | 1004 | if (*ResL>7 || *ResR>7) |
889 | for (k=0; k<36; ++k) | 1005 | for (k=0; k<36; ++k) |
890 | { | 1006 | { |
891 | if (*ResL>7) *L++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResL]) - Dc[*ResL]; | 1007 | if (*ResL>7) *QL++ = (mpc_int16_t)mpc_decoder_bitstream_read(d, Res_bit[*ResL]) - Dc[*ResL]; |
892 | if (*ResR>7) *R++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResR]) - Dc[*ResR]; | 1008 | if (*ResR>7) *QR++ = (mpc_int16_t)mpc_decoder_bitstream_read(d, Res_bit[*ResR]) - Dc[*ResR]; |
893 | } | 1009 | } |
894 | } | 1010 | } |
895 | } | 1011 | } |
896 | #endif //MPC_SUPPORT_SV456 | 1012 | #endif //MPC_SUPPORT_SV456 |
897 | /****************************************** SV 7 ******************************************/ | 1013 | /****************************************** SV 7 ******************************************/ |
898 | void | 1014 | void |
899 | mpc_decoder_read_bitstream_sv7(mpc_decoder *d) | 1015 | mpc_decoder_read_bitstream_sv7(mpc_decoder *d, mpc_bool_t fastSeeking) |
900 | { | 1016 | { |
901 | // these arrays hold decoding results for bundled quantizers (3- and 5-step) | 1017 | // these arrays hold decoding results for bundled quantizers (3- and 5-step) |
902 | /*static*/ mpc_int32_t idx30[] = { -1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1}; | 1018 | /*static*/ mpc_int32_t idx30[] = { -1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1}; |
@@ -909,9 +1025,12 @@ mpc_decoder_read_bitstream_sv7(mpc_decoder *d) | |||
909 | mpc_int32_t Max_used_Band=0; | 1025 | mpc_int32_t Max_used_Band=0; |
910 | const HuffmanTyp *Table; | 1026 | const HuffmanTyp *Table; |
911 | mpc_int32_t idx; | 1027 | mpc_int32_t idx; |
912 | mpc_int32_t *L ,*R; | 1028 | mpc_int8_t *L ,*R; |
913 | mpc_int32_t *ResL,*ResR; | 1029 | mpc_int16_t *LQ ,*RQ; |
1030 | mpc_int8_t *ResL,*ResR; | ||
914 | mpc_uint32_t tmp; | 1031 | mpc_uint32_t tmp; |
1032 | mpc_uint8_t *LUT; | ||
1033 | mpc_uint8_t max_length; | ||
915 | 1034 | ||
916 | /***************************** Header *****************************/ | 1035 | /***************************** Header *****************************/ |
917 | ResL = d->Res_L; | 1036 | ResL = d->Res_L; |
@@ -922,6 +1041,8 @@ mpc_decoder_read_bitstream_sv7(mpc_decoder *d) | |||
922 | *ResR = mpc_decoder_bitstream_read(d, 4); | 1041 | *ResR = mpc_decoder_bitstream_read(d, 4); |
923 | if (d->MS_used && !(*ResL==0 && *ResR==0)) { | 1042 | if (d->MS_used && !(*ResL==0 && *ResR==0)) { |
924 | d->MS_Flag[0] = mpc_decoder_bitstream_read(d, 1); | 1043 | d->MS_Flag[0] = mpc_decoder_bitstream_read(d, 1); |
1044 | } else { | ||
1045 | d->MS_Flag[0] = 0; | ||
925 | } | 1046 | } |
926 | 1047 | ||
927 | // consecutive subbands | 1048 | // consecutive subbands |
@@ -941,6 +1062,8 @@ mpc_decoder_read_bitstream_sv7(mpc_decoder *d) | |||
941 | // only perform following procedures up to the maximum non-zero subband | 1062 | // only perform following procedures up to the maximum non-zero subband |
942 | if (*ResL!=0 || *ResR!=0) { | 1063 | if (*ResL!=0 || *ResR!=0) { |
943 | Max_used_Band = n; | 1064 | Max_used_Band = n; |
1065 | } else { | ||
1066 | d->MS_Flag[n] = 0; | ||
944 | } | 1067 | } |
945 | } | 1068 | } |
946 | /****************************** SCFI ******************************/ | 1069 | /****************************** SCFI ******************************/ |
@@ -961,148 +1084,215 @@ mpc_decoder_read_bitstream_sv7(mpc_decoder *d) | |||
961 | for (n=0; n<=Max_used_Band; ++n, ++ResL, ++ResR, L+=3, R+=3) { | 1084 | for (n=0; n<=Max_used_Band; ++n, ++ResL, ++ResR, L+=3, R+=3) { |
962 | if (*ResL) | 1085 | if (*ResL) |
963 | { | 1086 | { |
964 | L[2] = d->DSCF_Reference_L[n]; | 1087 | //L[2] = d->DSCF_Reference_L[n]; |
965 | switch (d->SCFI_L[n]) | 1088 | switch (d->SCFI_L[n]) |
966 | { | 1089 | { |
967 | case 1: | 1090 | case 1: |
968 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1091 | idx = Decode_DSCF (); |
969 | L[0] = (idx!=8) ? L[2] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1092 | L[0] = (idx!=8) ? SCF_DIFF(L[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
970 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1093 | idx = Decode_DSCF (); |
971 | L[1] = (idx!=8) ? L[0] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1094 | L[1] = (idx!=8) ? SCF_DIFF(L[0], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
972 | L[2] = L[1]; | 1095 | L[2] = L[1]; |
973 | break; | 1096 | break; |
974 | case 3: | 1097 | case 3: |
975 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1098 | idx = Decode_DSCF (); |
976 | L[0] = (idx!=8) ? L[2] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1099 | L[0] = (idx!=8) ? SCF_DIFF(L[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
977 | L[1] = L[0]; | 1100 | L[1] = L[0]; |
978 | L[2] = L[1]; | 1101 | L[2] = L[1]; |
979 | break; | 1102 | break; |
980 | case 2: | 1103 | case 2: |
981 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1104 | idx = Decode_DSCF (); |
982 | L[0] = (idx!=8) ? L[2] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1105 | L[0] = (idx!=8) ? SCF_DIFF(L[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
983 | L[1] = L[0]; | 1106 | L[1] = L[0]; |
984 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1107 | idx = Decode_DSCF (); |
985 | L[2] = (idx!=8) ? L[1] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1108 | L[2] = (idx!=8) ? SCF_DIFF(L[1], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
986 | break; | 1109 | break; |
987 | case 0: | 1110 | case 0: |
988 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1111 | idx = Decode_DSCF (); |
989 | L[0] = (idx!=8) ? L[2] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1112 | L[0] = (idx!=8) ? SCF_DIFF(L[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
990 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1113 | idx = Decode_DSCF (); |
991 | L[1] = (idx!=8) ? L[0] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1114 | L[1] = (idx!=8) ? SCF_DIFF(L[0], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
992 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1115 | idx = Decode_DSCF (); |
993 | L[2] = (idx!=8) ? L[1] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1116 | L[2] = (idx!=8) ? SCF_DIFF(L[1], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
994 | break; | 1117 | break; |
995 | default: | 1118 | default: |
996 | return; | 1119 | return; |
997 | break; | 1120 | break; |
998 | } | 1121 | } |
999 | // update Reference for DSCF | ||
1000 | d->DSCF_Reference_L[n] = L[2]; | ||
1001 | } | 1122 | } |
1002 | if (*ResR) | 1123 | if (*ResR) |
1003 | { | 1124 | { |
1004 | R[2] = d->DSCF_Reference_R[n]; | ||
1005 | switch (d->SCFI_R[n]) | 1125 | switch (d->SCFI_R[n]) |
1006 | { | 1126 | { |
1007 | case 1: | 1127 | case 1: |
1008 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1128 | idx = Decode_DSCF (); |
1009 | R[0] = (idx!=8) ? R[2] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1129 | R[0] = (idx!=8) ? SCF_DIFF(R[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
1010 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1130 | idx = Decode_DSCF (); |
1011 | R[1] = (idx!=8) ? R[0] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1131 | R[1] = (idx!=8) ? SCF_DIFF(R[0], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
1012 | R[2] = R[1]; | 1132 | R[2] = R[1]; |
1013 | break; | 1133 | break; |
1014 | case 3: | 1134 | case 3: |
1015 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1135 | idx = Decode_DSCF (); |
1016 | R[0] = (idx!=8) ? R[2] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1136 | R[0] = (idx!=8) ? SCF_DIFF(R[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
1017 | R[1] = R[0]; | 1137 | R[1] = R[0]; |
1018 | R[2] = R[1]; | 1138 | R[2] = R[1]; |
1019 | break; | 1139 | break; |
1020 | case 2: | 1140 | case 2: |
1021 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1141 | idx = Decode_DSCF (); |
1022 | R[0] = (idx!=8) ? R[2] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1142 | R[0] = (idx!=8) ? SCF_DIFF(R[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
1023 | R[1] = R[0]; | 1143 | R[1] = R[0]; |
1024 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1144 | idx = Decode_DSCF (); |
1025 | R[2] = (idx!=8) ? R[1] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1145 | R[2] = (idx!=8) ? SCF_DIFF(R[1], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
1026 | break; | 1146 | break; |
1027 | case 0: | 1147 | case 0: |
1028 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1148 | idx = Decode_DSCF (); |
1029 | R[0] = (idx!=8) ? R[2] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1149 | R[0] = (idx!=8) ? SCF_DIFF(R[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
1030 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1150 | idx = Decode_DSCF (); |
1031 | R[1] = (idx!=8) ? R[0] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1151 | R[1] = (idx!=8) ? SCF_DIFF(R[0], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
1032 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffDSCF); | 1152 | idx = Decode_DSCF (); |
1033 | R[2] = (idx!=8) ? R[1] + idx : (int) mpc_decoder_bitstream_read(d, 6); | 1153 | R[2] = (idx!=8) ? SCF_DIFF(R[1], idx) : (int) mpc_decoder_bitstream_read(d, 6); |
1034 | break; | 1154 | break; |
1035 | default: | 1155 | default: |
1036 | return; | 1156 | return; |
1037 | break; | 1157 | break; |
1038 | } | 1158 | } |
1039 | // update Reference for DSCF | ||
1040 | d->DSCF_Reference_R[n] = R[2]; | ||
1041 | } | 1159 | } |
1042 | } | 1160 | } |
1161 | |||
1162 | if (fastSeeking) | ||
1163 | return; | ||
1164 | |||
1043 | /***************************** Samples ****************************/ | 1165 | /***************************** Samples ****************************/ |
1044 | ResL = d->Res_L; | 1166 | ResL = d->Res_L; |
1045 | ResR = d->Res_R; | 1167 | ResR = d->Res_R; |
1046 | L = d->Q[0].L; | 1168 | LQ = d->Q[0].L; |
1047 | R = d->Q[0].R; | 1169 | RQ = d->Q[0].R; |
1048 | for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR, L+=36, R+=36) | 1170 | for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR, LQ+=36, RQ+=36) |
1049 | { | 1171 | { |
1050 | /************** links **************/ | 1172 | /************** links **************/ |
1051 | switch (*ResL) | 1173 | switch (*ResL) |
1052 | { | 1174 | { |
1053 | case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9: | 1175 | case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9: |
1054 | case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17: | 1176 | case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17: |
1055 | L += 36; | 1177 | LQ += 36; |
1056 | break; | 1178 | break; |
1057 | case -1: | 1179 | case -1: |
1058 | for (k=0; k<36; k++ ) { | 1180 | for (k=0; k<36; k++ ) { |
1059 | tmp = mpc_random_int(d); | 1181 | tmp = mpc_random_int(d); |
1060 | *L++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; | 1182 | *LQ++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; |
1061 | } | 1183 | } |
1062 | break; | 1184 | break; |
1063 | case 0: | 1185 | case 0: |
1064 | L += 36;// increase pointer | 1186 | LQ += 36;// increase pointer |
1065 | break; | 1187 | break; |
1066 | case 1: | 1188 | case 1: |
1067 | Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][1]; | 1189 | if (mpc_decoder_bitstream_read(d, 1)) { |
1190 | Table = mpc_table_HuffQ[1][1]; | ||
1191 | LUT = LUT1_1; | ||
1192 | max_length = 9; | ||
1193 | } else { | ||
1194 | Table = mpc_table_HuffQ[0][1]; | ||
1195 | LUT = LUT1_0; | ||
1196 | max_length = 6; | ||
1197 | } | ||
1068 | for (k=0; k<12; ++k) | 1198 | for (k=0; k<12; ++k) |
1069 | { | 1199 | { |
1070 | idx = mpc_decoder_huffman_decode_fast(d, Table); | 1200 | idx = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); |
1071 | *L++ = idx30[idx]; | 1201 | *LQ++ = idx30[idx]; |
1072 | *L++ = idx31[idx]; | 1202 | *LQ++ = idx31[idx]; |
1073 | *L++ = idx32[idx]; | 1203 | *LQ++ = idx32[idx]; |
1074 | } | 1204 | } |
1075 | break; | 1205 | break; |
1076 | case 2: | 1206 | case 2: |
1077 | Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][2]; | 1207 | if (mpc_decoder_bitstream_read(d, 1)) { |
1208 | Table = mpc_table_HuffQ[1][2]; | ||
1209 | LUT = LUT2_1; | ||
1210 | max_length = 10; | ||
1211 | } else { | ||
1212 | Table = mpc_table_HuffQ[0][2]; | ||
1213 | LUT = LUT2_0; | ||
1214 | max_length = 7; | ||
1215 | } | ||
1078 | for (k=0; k<18; ++k) | 1216 | for (k=0; k<18; ++k) |
1079 | { | 1217 | { |
1080 | idx = mpc_decoder_huffman_decode_fast(d, Table); | 1218 | idx = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); |
1081 | *L++ = idx50[idx]; | 1219 | *LQ++ = idx50[idx]; |
1082 | *L++ = idx51[idx]; | 1220 | *LQ++ = idx51[idx]; |
1083 | } | 1221 | } |
1084 | break; | 1222 | break; |
1085 | case 3: | 1223 | case 3: |
1224 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1225 | Table = mpc_table_HuffQ[1][3]; | ||
1226 | LUT = LUT3_1; | ||
1227 | max_length = 5; | ||
1228 | } else { | ||
1229 | Table = mpc_table_HuffQ[0][3]; | ||
1230 | LUT = LUT3_0; | ||
1231 | max_length = 4; | ||
1232 | } | ||
1233 | for (k=0; k<36; ++k) | ||
1234 | *LQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1235 | break; | ||
1086 | case 4: | 1236 | case 4: |
1087 | Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResL]; | 1237 | if (mpc_decoder_bitstream_read(d, 1)) { |
1238 | Table = mpc_table_HuffQ[1][4]; | ||
1239 | LUT = LUT4_1; | ||
1240 | max_length = 5; | ||
1241 | } else { | ||
1242 | Table = mpc_table_HuffQ[0][4]; | ||
1243 | LUT = LUT4_0; | ||
1244 | max_length = 4; | ||
1245 | } | ||
1088 | for (k=0; k<36; ++k) | 1246 | for (k=0; k<36; ++k) |
1089 | *L++ = mpc_decoder_huffman_decode_faster(d, Table); | 1247 | *LQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); |
1090 | break; | 1248 | break; |
1091 | case 5: | 1249 | case 5: |
1092 | Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResL]; | 1250 | if (mpc_decoder_bitstream_read(d, 1)) { |
1251 | Table = mpc_table_HuffQ[1][5]; | ||
1252 | LUT = LUT5_1; | ||
1253 | max_length = 8; | ||
1254 | } else { | ||
1255 | Table = mpc_table_HuffQ[0][5]; | ||
1256 | LUT = LUT5_0; | ||
1257 | max_length = 6; | ||
1258 | } | ||
1093 | for (k=0; k<36; ++k) | 1259 | for (k=0; k<36; ++k) |
1094 | *L++ = mpc_decoder_huffman_decode_fast(d, Table); | 1260 | *LQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); |
1095 | break; | 1261 | break; |
1096 | case 6: | 1262 | case 6: |
1263 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1264 | Table = mpc_table_HuffQ[1][6]; | ||
1265 | LUT = LUT6_1; | ||
1266 | max_length = 7; | ||
1267 | for (k=0; k<36; ++k) | ||
1268 | *LQ++ = HUFFMAN_DECODE_FASTERER ( d, Table, LUT, max_length ); | ||
1269 | } else { | ||
1270 | Table = mpc_table_HuffQ[0][6]; | ||
1271 | LUT = LUT6_0; | ||
1272 | max_length = 7; | ||
1273 | for (k=0; k<36; ++k) | ||
1274 | *LQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1275 | } | ||
1276 | break; | ||
1097 | case 7: | 1277 | case 7: |
1098 | Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResL]; | 1278 | if (mpc_decoder_bitstream_read(d, 1)) { |
1099 | for (k=0; k<36; ++k) | 1279 | Table = mpc_table_HuffQ[1][7]; |
1100 | *L++ = mpc_decoder_huffman_decode(d, Table); | 1280 | LUT = LUT7_1; |
1281 | max_length = 8; | ||
1282 | for (k=0; k<36; ++k) | ||
1283 | *LQ++ = HUFFMAN_DECODE_FASTERER ( d, Table, LUT, max_length ); | ||
1284 | } else { | ||
1285 | Table = mpc_table_HuffQ[0][7]; | ||
1286 | LUT = LUT7_0; | ||
1287 | max_length = 8; | ||
1288 | for (k=0; k<36; ++k) | ||
1289 | *LQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1290 | } | ||
1101 | break; | 1291 | break; |
1102 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: | 1292 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: |
1103 | tmp = Dc[*ResL]; | 1293 | tmp = Dc[*ResL]; |
1104 | for (k=0; k<36; ++k) | 1294 | for (k=0; k<36; ++k) |
1105 | *L++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResL]) - tmp; | 1295 | *LQ++ = (mpc_int16_t)mpc_decoder_bitstream_read(d, Res_bit[*ResL]) - tmp; |
1106 | break; | 1296 | break; |
1107 | default: | 1297 | default: |
1108 | return; | 1298 | return; |
@@ -1112,57 +1302,125 @@ mpc_decoder_read_bitstream_sv7(mpc_decoder *d) | |||
1112 | { | 1302 | { |
1113 | case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9: | 1303 | case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9: |
1114 | case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17: | 1304 | case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17: |
1115 | R += 36; | 1305 | RQ += 36; |
1116 | break; | 1306 | break; |
1117 | case -1: | 1307 | case -1: |
1118 | for (k=0; k<36; k++ ) { | 1308 | for (k=0; k<36; k++ ) { |
1119 | tmp = mpc_random_int(d); | 1309 | tmp = mpc_random_int(d); |
1120 | *R++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; | 1310 | *RQ++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; |
1121 | } | 1311 | } |
1122 | break; | 1312 | break; |
1123 | case 0: | 1313 | case 0: |
1124 | R += 36;// increase pointer | 1314 | RQ += 36;// increase pointer |
1125 | break; | 1315 | break; |
1126 | case 1: | 1316 | case 1: |
1127 | Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][1]; | 1317 | if (mpc_decoder_bitstream_read(d, 1)) { |
1318 | Table = mpc_table_HuffQ[1][1]; | ||
1319 | LUT = LUT1_1; | ||
1320 | max_length = 9; | ||
1321 | } else { | ||
1322 | Table = mpc_table_HuffQ[0][1]; | ||
1323 | LUT = LUT1_0; | ||
1324 | max_length = 6; | ||
1325 | } | ||
1128 | for (k=0; k<12; ++k) | 1326 | for (k=0; k<12; ++k) |
1129 | { | 1327 | { |
1130 | idx = mpc_decoder_huffman_decode_fast(d, Table); | 1328 | idx = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); |
1131 | *R++ = idx30[idx]; | 1329 | *RQ++ = idx30[idx]; |
1132 | *R++ = idx31[idx]; | 1330 | *RQ++ = idx31[idx]; |
1133 | *R++ = idx32[idx]; | 1331 | *RQ++ = idx32[idx]; |
1134 | } | 1332 | } |
1135 | break; | 1333 | break; |
1136 | case 2: | 1334 | case 2: |
1137 | Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][2]; | 1335 | if (mpc_decoder_bitstream_read(d, 1)) { |
1336 | Table = mpc_table_HuffQ[1][2]; | ||
1337 | LUT = LUT2_1; | ||
1338 | max_length = 10; | ||
1339 | } else { | ||
1340 | Table = mpc_table_HuffQ[0][2]; | ||
1341 | LUT = LUT2_0; | ||
1342 | max_length = 7; | ||
1343 | } | ||
1138 | for (k=0; k<18; ++k) | 1344 | for (k=0; k<18; ++k) |
1139 | { | 1345 | { |
1140 | idx = mpc_decoder_huffman_decode_fast(d, Table); | 1346 | idx = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); |
1141 | *R++ = idx50[idx]; | 1347 | *RQ++ = idx50[idx]; |
1142 | *R++ = idx51[idx]; | 1348 | *RQ++ = idx51[idx]; |
1143 | } | 1349 | } |
1144 | break; | 1350 | break; |
1145 | case 3: | 1351 | case 3: |
1352 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1353 | Table = mpc_table_HuffQ[1][3]; | ||
1354 | LUT = LUT3_1; | ||
1355 | max_length = 5; | ||
1356 | } else { | ||
1357 | Table = mpc_table_HuffQ[0][3]; | ||
1358 | LUT = LUT3_0; | ||
1359 | max_length = 4; | ||
1360 | } | ||
1361 | for (k=0; k<36; ++k) | ||
1362 | *RQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1363 | break; | ||
1146 | case 4: | 1364 | case 4: |
1147 | Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResR]; | 1365 | if (mpc_decoder_bitstream_read(d, 1)) { |
1366 | Table = mpc_table_HuffQ[1][4]; | ||
1367 | LUT = LUT4_1; | ||
1368 | max_length = 5; | ||
1369 | } else { | ||
1370 | Table = mpc_table_HuffQ[0][4]; | ||
1371 | LUT = LUT4_0; | ||
1372 | max_length = 4; | ||
1373 | } | ||
1148 | for (k=0; k<36; ++k) | 1374 | for (k=0; k<36; ++k) |
1149 | *R++ = mpc_decoder_huffman_decode_faster(d, Table); | 1375 | *RQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); |
1150 | break; | 1376 | break; |
1151 | case 5: | 1377 | case 5: |
1152 | Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResR]; | 1378 | if (mpc_decoder_bitstream_read(d, 1)) { |
1379 | Table = mpc_table_HuffQ[1][5]; | ||
1380 | LUT = LUT5_1; | ||
1381 | max_length = 8; | ||
1382 | } else { | ||
1383 | Table = mpc_table_HuffQ[0][5]; | ||
1384 | LUT = LUT5_0; | ||
1385 | max_length = 6; | ||
1386 | } | ||
1153 | for (k=0; k<36; ++k) | 1387 | for (k=0; k<36; ++k) |
1154 | *R++ = mpc_decoder_huffman_decode_fast(d, Table); | 1388 | *RQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); |
1155 | break; | 1389 | break; |
1156 | case 6: | 1390 | case 6: |
1157 | case 7: | 1391 | if (mpc_decoder_bitstream_read(d, 1)) { |
1158 | Table = mpc_table_HuffQ[mpc_decoder_bitstream_read(d, 1)][*ResR]; | 1392 | Table = mpc_table_HuffQ[1][6]; |
1393 | LUT = LUT6_1; | ||
1394 | max_length = 7; | ||
1159 | for (k=0; k<36; ++k) | 1395 | for (k=0; k<36; ++k) |
1160 | *R++ = mpc_decoder_huffman_decode(d, Table); | 1396 | *RQ++ = HUFFMAN_DECODE_FASTERER ( d, Table, LUT, max_length ); |
1161 | break; | 1397 | } else { |
1398 | Table = mpc_table_HuffQ[0][6]; | ||
1399 | LUT = LUT6_0; | ||
1400 | max_length = 7; | ||
1401 | for (k=0; k<36; ++k) | ||
1402 | *RQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1403 | } | ||
1404 | break; | ||
1405 | case 7: | ||
1406 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1407 | Table = mpc_table_HuffQ[1][7]; | ||
1408 | LUT = LUT7_1; | ||
1409 | max_length = 8; | ||
1410 | for (k=0; k<36; ++k) | ||
1411 | *RQ++ = HUFFMAN_DECODE_FASTERER ( d, Table, LUT, max_length ); | ||
1412 | } else { | ||
1413 | Table = mpc_table_HuffQ[0][7]; | ||
1414 | LUT = LUT7_0; | ||
1415 | max_length = 8; | ||
1416 | for (k=0; k<36; ++k) | ||
1417 | *RQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1418 | } | ||
1419 | break; | ||
1162 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: | 1420 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: |
1163 | tmp = Dc[*ResR]; | 1421 | tmp = Dc[*ResR]; |
1164 | for (k=0; k<36; ++k) | 1422 | for (k=0; k<36; ++k) |
1165 | *R++ = (mpc_int32_t)mpc_decoder_bitstream_read(d, Res_bit[*ResR]) - tmp; | 1423 | *RQ++ = (mpc_int16_t)mpc_decoder_bitstream_read(d, Res_bit[*ResR]) - tmp; |
1166 | break; | 1424 | break; |
1167 | default: | 1425 | default: |
1168 | return; | 1426 | return; |
@@ -1182,6 +1440,7 @@ void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r) | |||
1182 | d->FrameWasValid = 0; | 1440 | d->FrameWasValid = 0; |
1183 | d->OverallFrames = 0; | 1441 | d->OverallFrames = 0; |
1184 | d->DecodedFrames = 0; | 1442 | d->DecodedFrames = 0; |
1443 | d->MaxDecodedFrames = 0; | ||
1185 | d->TrueGaplessPresent = 0; | 1444 | d->TrueGaplessPresent = 0; |
1186 | d->last_block_samples = 0; | 1445 | d->last_block_samples = 0; |
1187 | d->WordsRead = 0; | 1446 | d->WordsRead = 0; |
@@ -1193,21 +1452,58 @@ void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r) | |||
1193 | d->dword = 0; | 1452 | d->dword = 0; |
1194 | d->pos = 0; | 1453 | d->pos = 0; |
1195 | d->Zaehler = 0; | 1454 | d->Zaehler = 0; |
1455 | d->Ring = 0; | ||
1196 | d->WordsRead = 0; | 1456 | d->WordsRead = 0; |
1197 | d->Max_Band = 0; | 1457 | d->Max_Band = 0; |
1458 | d->SeekTable = NULL; | ||
1459 | d->Use_FastSeek = TRUE; | ||
1460 | d->Use_SeekTable = TRUE; | ||
1461 | d->Use_StaticSeekTable = FALSE; | ||
1462 | d->SeekTable_Step = 1; | ||
1463 | d->SeekTableIndex = 0; | ||
1464 | d->SeekTableCounter = 0; | ||
1465 | d->Max_SeekTable_Size = 0; | ||
1198 | 1466 | ||
1199 | mpc_decoder_initialisiere_quantisierungstabellen(d, 1.0f); | 1467 | mpc_decoder_initialisiere_quantisierungstabellen(d, 1.0f); |
1468 | #if 0 | ||
1469 | mpc_decoder_init_huffman_sv6(d); | ||
1470 | mpc_decoder_init_huffman_sv7(d); | ||
1471 | #endif | ||
1472 | |||
1473 | LOOKUP ( mpc_table_HuffQ[0][1], 27, LUT1_0 ); | ||
1474 | LOOKUP ( mpc_table_HuffQ[1][1], 27, LUT1_1 ); | ||
1475 | LOOKUP ( mpc_table_HuffQ[0][2], 25, LUT2_0 ); | ||
1476 | LOOKUP ( mpc_table_HuffQ[1][2], 25, LUT2_1 ); | ||
1477 | LOOKUP ( mpc_table_HuffQ[0][3], 7, LUT3_0 ); | ||
1478 | LOOKUP ( mpc_table_HuffQ[1][3], 7, LUT3_1 ); | ||
1479 | LOOKUP ( mpc_table_HuffQ[0][4], 9, LUT4_0 ); | ||
1480 | LOOKUP ( mpc_table_HuffQ[1][4], 9, LUT4_1 ); | ||
1481 | LOOKUP ( mpc_table_HuffQ[0][5], 15, LUT5_0 ); | ||
1482 | LOOKUP ( mpc_table_HuffQ[1][5], 15, LUT5_1 ); | ||
1483 | LOOKUP ( mpc_table_HuffQ[0][6], 31, LUT6_0 ); | ||
1484 | LOOKUP ( mpc_table_HuffQ[1][6], 31, LUT6_1 ); | ||
1485 | LOOKUP ( mpc_table_HuffQ[0][7], 63, LUT7_0 ); | ||
1486 | LOOKUP ( mpc_table_HuffQ[1][7], 63, LUT7_1 ); | ||
1487 | LOOKUP ( mpc_table_HuffDSCF, 16, LUTDSCF ); | ||
1488 | |||
1489 | d->Speicher = Speicher; | ||
1200 | 1490 | ||
1201 | /* Link struct entries to actual tables which are placed in IRAM */ | ||
1202 | d->V_L = V_L; | ||
1203 | d->V_R = V_R; | ||
1204 | #if defined(CPU_COLDFIRE)&& !defined(SIMULATOR) | 1491 | #if defined(CPU_COLDFIRE)&& !defined(SIMULATOR) |
1205 | coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE); | 1492 | coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE); |
1206 | #endif | 1493 | #endif |
1207 | } | 1494 | } |
1208 | 1495 | ||
1496 | void mpc_decoder_destroy(mpc_decoder *d) { | ||
1497 | |||
1498 | if (d->SeekTable != NULL && d->Use_StaticSeekTable == FALSE) | ||
1499 | free(d->SeekTable); | ||
1500 | |||
1501 | } | ||
1502 | |||
1209 | void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si) | 1503 | void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si) |
1210 | { | 1504 | { |
1505 | mpc_uint16_t seekTableSize; | ||
1506 | |||
1211 | mpc_decoder_reset_synthesis(d); | 1507 | mpc_decoder_reset_synthesis(d); |
1212 | mpc_decoder_reset_globals(d); | 1508 | mpc_decoder_reset_globals(d); |
1213 | 1509 | ||
@@ -1220,26 +1516,53 @@ void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si) | |||
1220 | d->SampleRate = (mpc_int32_t)si->sample_freq; | 1516 | d->SampleRate = (mpc_int32_t)si->sample_freq; |
1221 | 1517 | ||
1222 | d->samples_to_skip = MPC_DECODER_SYNTH_DELAY; | 1518 | d->samples_to_skip = MPC_DECODER_SYNTH_DELAY; |
1519 | |||
1520 | if (d->SeekTable != NULL && d->Use_StaticSeekTable == FALSE) | ||
1521 | free(d->SeekTable); | ||
1522 | |||
1523 | if (d->Use_SeekTable) { | ||
1524 | if (d->Use_StaticSeekTable == FALSE) { | ||
1525 | if (d->Max_SeekTable_Size == 0) { | ||
1526 | seekTableSize = si->frames; | ||
1527 | } else { | ||
1528 | seekTableSize = min(si->frames, d->Max_SeekTable_Size / sizeof(mpc_uint32_t)); | ||
1529 | } | ||
1530 | d->SeekTable = (mpc_uint32_t*) calloc( sizeof(mpc_uint32_t), seekTableSize); | ||
1531 | d->SeekTable_Step = si->frames / seekTableSize; | ||
1532 | if (si->frames % seekTableSize) | ||
1533 | d->SeekTable_Step+=1; | ||
1534 | } else { | ||
1535 | seekTableSize = d->Max_SeekTable_Size / sizeof(mpc_uint32_t); | ||
1536 | d->SeekTable_Step = si->frames / seekTableSize; | ||
1537 | if (si->frames % seekTableSize) | ||
1538 | d->SeekTable_Step+=1; | ||
1539 | } | ||
1540 | } | ||
1541 | |||
1223 | } | 1542 | } |
1224 | 1543 | ||
1225 | mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si) | 1544 | mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si) |
1226 | { | 1545 | { |
1227 | mpc_decoder_set_streaminfo(d, si); | 1546 | mpc_uint32_t bitPos; |
1547 | mpc_uint32_t fpos; | ||
1228 | 1548 | ||
1229 | // AB: setting position to the beginning of the data-bitstream | 1549 | mpc_decoder_set_streaminfo(d, si); |
1230 | switch (d->StreamVersion) { | ||
1231 | case 0x04: f_seek(d, 4 + d->MPCHeaderPos); d->pos = 16; break; // Geht auch über eine der Helperfunktionen | ||
1232 | case 0x05: | ||
1233 | case 0x06: f_seek(d, 8 + d->MPCHeaderPos); d->pos = 0; break; | ||
1234 | case 0x07: | ||
1235 | case 0x17: /*f_seek ( 24 + d->MPCHeaderPos );*/ d->pos = 8; break; | ||
1236 | default: return FALSE; | ||
1237 | } | ||
1238 | 1550 | ||
1239 | // AB: fill buffer and initialize decoder | 1551 | // setting position to the beginning of the data-bitstream |
1240 | f_read_dword(d, d->Speicher, MEMSIZE ); | 1552 | bitPos = get_initial_fpos(d, d->StreamVersion); |
1241 | d->dword = d->Speicher[d->Zaehler = 0]; | 1553 | fpos = bitPos >> 5; |
1242 | 1554 | ||
1555 | // fill buffer and initialize decoder | ||
1556 | f_seek(d, fpos*4 + d->MPCHeaderPos); | ||
1557 | f_read_dword(d, d->Speicher, MEMSIZE); | ||
1558 | d->Ring = 0; | ||
1559 | d->Zaehler = 0; | ||
1560 | d->pos = bitPos & 31; | ||
1561 | d->WordsRead = fpos; | ||
1562 | d->dword = SWAP(d->Speicher[0]); | ||
1563 | d->next = SWAP(d->Speicher[1]); | ||
1564 | d->SeekTable_Step = 1; | ||
1565 | |||
1243 | return TRUE; | 1566 | return TRUE; |
1244 | } | 1567 | } |
1245 | 1568 | ||
@@ -1253,21 +1576,19 @@ helper1(mpc_decoder *d, mpc_uint32_t bitpos) | |||
1253 | { | 1576 | { |
1254 | f_seek(d, (bitpos >> 5) * 4 + d->MPCHeaderPos); | 1577 | f_seek(d, (bitpos >> 5) * 4 + d->MPCHeaderPos); |
1255 | f_read_dword(d, d->Speicher, 2); | 1578 | f_read_dword(d, d->Speicher, 2); |
1256 | d->dword = d->Speicher[d->Zaehler = 0]; | 1579 | d->dword = SWAP(d->Speicher[d->Zaehler = 0]); |
1257 | d->pos = bitpos & 31; | 1580 | d->pos = bitpos & 31; |
1258 | } | 1581 | } |
1259 | #endif | ||
1260 | 1582 | ||
1261 | static void | 1583 | static void |
1262 | helper2(mpc_decoder *d, mpc_uint32_t bitpos) | 1584 | helper2(mpc_decoder *d, mpc_uint32_t bitpos) |
1263 | { | 1585 | { |
1264 | f_seek(d, (bitpos>>5) * 4 + d->MPCHeaderPos); | 1586 | f_seek(d, (bitpos>>5) * 4 + d->MPCHeaderPos); |
1265 | f_read_dword(d, d->Speicher, MEMSIZE); | 1587 | f_read_dword(d, d->Speicher, MEMSIZE); |
1266 | d->dword = d->Speicher[d->Zaehler = 0]; | 1588 | d->dword = SWAP(d->Speicher[d->Zaehler = 0]); |
1267 | d->pos = bitpos & 31; | 1589 | d->pos = bitpos & 31; |
1268 | } | 1590 | } |
1269 | 1591 | ||
1270 | #if 0 | ||
1271 | static void | 1592 | static void |
1272 | helper3(mpc_decoder *d, mpc_uint32_t bitpos, mpc_uint32_t* buffoffs) | 1593 | helper3(mpc_decoder *d, mpc_uint32_t bitpos, mpc_uint32_t* buffoffs) |
1273 | { | 1594 | { |
@@ -1278,10 +1599,28 @@ helper3(mpc_decoder *d, mpc_uint32_t bitpos, mpc_uint32_t* buffoffs) | |||
1278 | f_seek(d, bitpos * 4L + d->MPCHeaderPos); | 1599 | f_seek(d, bitpos * 4L + d->MPCHeaderPos); |
1279 | f_read_dword(d, d->Speicher, MEMSIZE ); | 1600 | f_read_dword(d, d->Speicher, MEMSIZE ); |
1280 | } | 1601 | } |
1281 | d->dword = d->Speicher[d->Zaehler = bitpos - *buffoffs ]; | 1602 | d->dword = SWAP(d->Speicher[d->Zaehler = bitpos - *buffoffs ]); |
1282 | } | 1603 | } |
1283 | #endif | 1604 | #endif |
1284 | 1605 | ||
1606 | // jumps over the current frame | ||
1607 | mpc_uint32_t mpc_decoder_jump_frame(mpc_decoder *d) { | ||
1608 | |||
1609 | mpc_uint32_t frameSize; | ||
1610 | |||
1611 | // ensure the buffer is full | ||
1612 | mpc_decoder_update_buffer(d); | ||
1613 | |||
1614 | // bits in frame | ||
1615 | frameSize = mpc_decoder_bitstream_read(d, 20); | ||
1616 | |||
1617 | // jump forward | ||
1618 | mpc_decoder_seek_forward(d, frameSize); | ||
1619 | |||
1620 | return frameSize + 20; | ||
1621 | |||
1622 | } | ||
1623 | |||
1285 | static mpc_uint32_t get_initial_fpos(mpc_decoder *d, mpc_uint32_t StreamVersion) | 1624 | static mpc_uint32_t get_initial_fpos(mpc_decoder *d, mpc_uint32_t StreamVersion) |
1286 | { | 1625 | { |
1287 | mpc_uint32_t fpos = 0; | 1626 | mpc_uint32_t fpos = 0; |
@@ -1301,55 +1640,170 @@ mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds) | |||
1301 | return mpc_decoder_seek_sample(d, (mpc_int64_t)(seconds * (double)d->SampleRate + 0.5)); | 1640 | return mpc_decoder_seek_sample(d, (mpc_int64_t)(seconds * (double)d->SampleRate + 0.5)); |
1302 | } | 1641 | } |
1303 | 1642 | ||
1304 | mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample) | 1643 | void mpc_decoder_reset_state(mpc_decoder *d) { |
1305 | { | ||
1306 | mpc_uint32_t fpos; | ||
1307 | mpc_uint32_t fwd; | ||
1308 | |||
1309 | fwd = (mpc_uint32_t) (destsample / MPC_FRAME_LENGTH); | ||
1310 | d->samples_to_skip = MPC_DECODER_SYNTH_DELAY + (mpc_uint32_t)(destsample % MPC_FRAME_LENGTH); | ||
1311 | 1644 | ||
1312 | memset(d->Y_L , 0, sizeof d->Y_L ); | 1645 | memset(d->Y_L , 0, sizeof d->Y_L ); |
1313 | memset(d->Y_R , 0, sizeof d->Y_R ); | 1646 | memset(d->Y_R , 0, sizeof d->Y_R ); |
1647 | #ifdef SCF_HACK | ||
1648 | memset(d->SCF_Index_L , -128, sizeof d->SCF_Index_L ); | ||
1649 | memset(d->SCF_Index_R , -128, sizeof d->SCF_Index_R ); | ||
1650 | #else | ||
1314 | memset(d->SCF_Index_L , 0, sizeof d->SCF_Index_L ); | 1651 | memset(d->SCF_Index_L , 0, sizeof d->SCF_Index_L ); |
1315 | memset(d->SCF_Index_R , 0, sizeof d->SCF_Index_R ); | 1652 | memset(d->SCF_Index_R , 0, sizeof d->SCF_Index_R ); |
1653 | #endif | ||
1316 | memset(d->Res_L , 0, sizeof d->Res_L ); | 1654 | memset(d->Res_L , 0, sizeof d->Res_L ); |
1317 | memset(d->Res_R , 0, sizeof d->Res_R ); | 1655 | memset(d->Res_R , 0, sizeof d->Res_R ); |
1318 | memset(d->SCFI_L , 0, sizeof d->SCFI_L ); | 1656 | memset(d->SCFI_L , 0, sizeof d->SCFI_L ); |
1319 | memset(d->SCFI_R , 0, sizeof d->SCFI_R ); | 1657 | memset(d->SCFI_R , 0, sizeof d->SCFI_R ); |
1658 | #ifdef MPC_SUPPORT_SV456 | ||
1320 | memset(d->DSCF_Flag_L , 0, sizeof d->DSCF_Flag_L ); | 1659 | memset(d->DSCF_Flag_L , 0, sizeof d->DSCF_Flag_L ); |
1321 | memset(d->DSCF_Flag_R , 0, sizeof d->DSCF_Flag_R ); | 1660 | memset(d->DSCF_Flag_R , 0, sizeof d->DSCF_Flag_R ); |
1322 | memset(d->DSCF_Reference_L, 0, sizeof d->DSCF_Reference_L ); | 1661 | #endif |
1323 | memset(d->DSCF_Reference_R, 0, sizeof d->DSCF_Reference_R ); | 1662 | //memset(d->DSCF_Reference_L, 0, sizeof d->DSCF_Reference_L ); |
1663 | //memset(d->DSCF_Reference_R, 0, sizeof d->DSCF_Reference_R ); | ||
1324 | memset(d->Q , 0, sizeof d->Q ); | 1664 | memset(d->Q , 0, sizeof d->Q ); |
1325 | memset(d->MS_Flag , 0, sizeof d->MS_Flag ); | 1665 | memset(d->MS_Flag , 0, sizeof d->MS_Flag ); |
1326 | 1666 | ||
1327 | // resetting synthesis filter to avoid "clicks" | 1667 | } |
1328 | mpc_decoder_reset_synthesis(d); | 1668 | |
1669 | mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample) | ||
1670 | { | ||
1671 | mpc_uint32_t fpos = 0; // the bit to seek to | ||
1672 | mpc_uint32_t seekFrame = 0; // the frame to seek to | ||
1673 | mpc_uint32_t lastFrame = 0; // last frame to seek to before scanning scale factors | ||
1674 | mpc_int32_t delta = 0; // direction of seek | ||
1675 | |||
1676 | destsample += MPC_DECODER_SYNTH_DELAY; | ||
1677 | seekFrame = (mpc_uint32_t) ((destsample) / MPC_FRAME_LENGTH); | ||
1678 | d->samples_to_skip = (mpc_uint32_t)((destsample) % MPC_FRAME_LENGTH); | ||
1329 | 1679 | ||
1330 | // prevent from desired position out of allowed range | 1680 | // prevent from desired position out of allowed range |
1331 | fwd = fwd < d->OverallFrames ? fwd : d->OverallFrames; | 1681 | seekFrame = seekFrame < d->OverallFrames ? seekFrame : d->OverallFrames; |
1332 | 1682 | ||
1333 | // reset number of decoded frames | 1683 | // seek direction (note: avoids casting to int64) |
1334 | d->DecodedFrames = 0; | 1684 | delta = (d->DecodedFrames > seekFrame ? -(mpc_int32_t)(d->DecodedFrames - seekFrame) : (mpc_int32_t)(seekFrame - d->DecodedFrames)); |
1335 | 1685 | ||
1336 | fpos = get_initial_fpos(d, d->StreamVersion); | 1686 | // update max decoded frames |
1337 | if (fpos == 0) { | 1687 | if (d->DecodedFrames > d->MaxDecodedFrames) |
1338 | return FALSE; | 1688 | d->MaxDecodedFrames = d->DecodedFrames; |
1339 | } | 1689 | |
1690 | if (seekFrame > 33) | ||
1691 | lastFrame = seekFrame - 33 + 1 - d->SeekTable_Step; | ||
1692 | |||
1693 | if ((!d->Use_SeekTable && delta < 0) || d->MaxDecodedFrames == 0) { | ||
1340 | 1694 | ||
1341 | helper2(d, fpos); | 1695 | mpc_decoder_reset_state(d); |
1696 | |||
1697 | // starts from the beginning since no frames have been decoded yet, or not using seek table | ||
1698 | fpos = get_initial_fpos(d, d->StreamVersion); | ||
1699 | |||
1700 | // seek to the first frame | ||
1701 | mpc_decoder_seek_to(d, fpos); | ||
1702 | |||
1703 | // reset number of decoded frames | ||
1704 | d->DecodedFrames = 0; | ||
1705 | |||
1706 | if (d->Use_SeekTable) { | ||
1707 | // jump to the last frame, updating seek table | ||
1708 | if (d->SeekTable_Step == 1) { | ||
1709 | d->SeekTable[0] = (mpc_uint32_t)fpos; | ||
1710 | for (;d->DecodedFrames < lastFrame; d->DecodedFrames++) | ||
1711 | d->SeekTable[d->DecodedFrames+1] = mpc_decoder_jump_frame(d); | ||
1712 | } else { | ||
1713 | d->SeekTableIndex = 0; | ||
1714 | d->SeekTableCounter = (mpc_uint32_t)fpos; | ||
1715 | for (;d->DecodedFrames < lastFrame; d->DecodedFrames++) { | ||
1716 | if (d->DecodedFrames % d->SeekTable_Step == 0) { | ||
1717 | d->SeekTable[d->SeekTableIndex] = d->SeekTableCounter; | ||
1718 | d->SeekTableIndex += 1; | ||
1719 | d->SeekTableCounter = 0; | ||
1720 | } | ||
1721 | d->SeekTableCounter += mpc_decoder_jump_frame(d); | ||
1722 | } | ||
1723 | } | ||
1724 | } else { | ||
1725 | // just jump to the last frame | ||
1726 | for (;d->DecodedFrames < lastFrame; d->DecodedFrames++) | ||
1727 | mpc_decoder_jump_frame(d); | ||
1728 | } | ||
1729 | |||
1730 | } else if (delta < 0) { | ||
1731 | |||
1732 | mpc_decoder_reset_state(d); | ||
1733 | |||
1734 | // jumps backwards using the seek table | ||
1735 | fpos = d->SeekTable[0]; | ||
1736 | if (d->SeekTable_Step == 1) { | ||
1737 | for (d->DecodedFrames = 0;d->DecodedFrames < lastFrame; d->DecodedFrames++) | ||
1738 | fpos += d->SeekTable[d->DecodedFrames+1]; | ||
1739 | } else { | ||
1740 | d->SeekTableIndex = 0; | ||
1741 | //d->SeekTableCounter = 0; | ||
1742 | for (d->DecodedFrames = 0;d->DecodedFrames < lastFrame; d->DecodedFrames+=d->SeekTable_Step, d->SeekTableIndex++) | ||
1743 | fpos += d->SeekTable[d->SeekTableIndex+1]; | ||
1744 | d->SeekTableCounter = d->SeekTable[d->SeekTableIndex]; | ||
1745 | } | ||
1746 | mpc_decoder_seek_to(d, fpos); | ||
1747 | |||
1748 | } else if (delta > 33) { | ||
1749 | |||
1750 | mpc_decoder_reset_state(d); | ||
1751 | |||
1752 | // jumps forward from the current position | ||
1753 | if (d->Use_SeekTable) { | ||
1754 | |||
1755 | if (d->MaxDecodedFrames > lastFrame) { // REVIEW: Correct?? or (d->MaxDecodedFrames > d->DecodedFrames) | ||
1756 | // jump to the last usable position in the seek table | ||
1757 | if (d->SeekTable_Step == 1) { | ||
1758 | fpos = mpc_decoder_bits_read(d); | ||
1759 | for (; d->DecodedFrames < d->MaxDecodedFrames && d->DecodedFrames < lastFrame; d->DecodedFrames++) | ||
1760 | fpos += d->SeekTable[d->DecodedFrames+1]; | ||
1761 | } else { | ||
1762 | // could test SeekTable offset and jump to next entry but this is easier for now... | ||
1763 | //d->SeekTableIndex = 0; | ||
1764 | //d->SeekTableCounter = 0; | ||
1765 | fpos = d->SeekTable[0]; | ||
1766 | d->SeekTableIndex = 0; | ||
1767 | for (d->DecodedFrames = 0;d->DecodedFrames < d->MaxDecodedFrames && d->DecodedFrames < lastFrame; d->DecodedFrames+=d->SeekTable_Step, d->SeekTableIndex++) | ||
1768 | fpos += d->SeekTable[d->SeekTableIndex+1]; | ||
1769 | d->SeekTableCounter = d->SeekTable[d->SeekTableIndex]; | ||
1770 | } | ||
1771 | |||
1772 | mpc_decoder_seek_to(d, fpos); | ||
1773 | } | ||
1774 | if (d->SeekTable_Step == 1) { | ||
1775 | for (;d->DecodedFrames < lastFrame; d->DecodedFrames++) | ||
1776 | d->SeekTable[d->DecodedFrames+1] = mpc_decoder_jump_frame(d); | ||
1777 | } else { | ||
1778 | for (;d->DecodedFrames < lastFrame; d->DecodedFrames++) { | ||
1779 | if (d->DecodedFrames % d->SeekTable_Step == 0) { | ||
1780 | d->SeekTable[d->SeekTableIndex] = d->SeekTableCounter; | ||
1781 | d->SeekTableIndex += 1; | ||
1782 | d->SeekTableCounter = 0; | ||
1783 | } | ||
1784 | d->SeekTableCounter += mpc_decoder_jump_frame(d); | ||
1785 | } | ||
1786 | } | ||
1787 | } else { | ||
1788 | for (;d->DecodedFrames < lastFrame; d->DecodedFrames++) | ||
1789 | mpc_decoder_jump_frame(d); | ||
1790 | } | ||
1791 | |||
1792 | } | ||
1793 | |||
1794 | // REVIEW: Needed? | ||
1795 | mpc_decoder_update_buffer(d); | ||
1796 | |||
1797 | for (;d->DecodedFrames < seekFrame; d->DecodedFrames++) { | ||
1342 | 1798 | ||
1343 | // read the last 32 frames before the desired position to scan the scalefactors (artifactless jumping) | ||
1344 | for ( ; d->DecodedFrames < fwd; d->DecodedFrames++ ) { | ||
1345 | mpc_uint32_t FrameBitCnt; | 1799 | mpc_uint32_t FrameBitCnt; |
1346 | mpc_uint32_t RING; | 1800 | |
1347 | RING = d->Zaehler; | ||
1348 | d->FwdJumpInfo = mpc_decoder_bitstream_read(d, 20); // read jump-info | 1801 | d->FwdJumpInfo = mpc_decoder_bitstream_read(d, 20); // read jump-info |
1349 | d->ActDecodePos = (d->Zaehler << 5) + d->pos; | 1802 | d->ActDecodePos = (d->Zaehler << 5) + d->pos; |
1350 | FrameBitCnt = mpc_decoder_bits_read(d); // scanning the scalefactors and check for validity of frame | 1803 | FrameBitCnt = mpc_decoder_bits_read(d); |
1804 | // scanning the scalefactors (and check for validity of frame) | ||
1351 | if (d->StreamVersion >= 7) { | 1805 | if (d->StreamVersion >= 7) { |
1352 | mpc_decoder_read_bitstream_sv7(d); | 1806 | mpc_decoder_read_bitstream_sv7(d, d->Use_FastSeek && (d->DecodedFrames < seekFrame - 1)); |
1353 | } | 1807 | } |
1354 | else { | 1808 | else { |
1355 | #ifdef MPC_SUPPORT_SV456 | 1809 | #ifdef MPC_SUPPORT_SV456 |
@@ -1358,28 +1812,123 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample) | |||
1358 | return FALSE; | 1812 | return FALSE; |
1359 | #endif | 1813 | #endif |
1360 | } | 1814 | } |
1361 | if (mpc_decoder_bits_read(d) - FrameBitCnt != d->FwdJumpInfo ) { | 1815 | |
1362 | // Box ("Bug in perform_jump"); | 1816 | FrameBitCnt = mpc_decoder_bits_read(d) - FrameBitCnt; |
1817 | |||
1818 | if (d->Use_FastSeek && d->FwdJumpInfo > FrameBitCnt) | ||
1819 | mpc_decoder_seek_forward(d, d->FwdJumpInfo - FrameBitCnt); | ||
1820 | else if (FrameBitCnt != d->FwdJumpInfo ) | ||
1821 | // Bug in perform_jump; | ||
1363 | return FALSE; | 1822 | return FALSE; |
1823 | |||
1824 | // REVIEW: Only if decodedFrames < maxDecodedFrames?? | ||
1825 | if (d->Use_SeekTable) { | ||
1826 | if (d->SeekTable_Step == 1) { | ||
1827 | // check that the frame length corresponds with any data already in the seek table | ||
1828 | if (d->SeekTable[d->DecodedFrames+1] != 0 && d->SeekTable[d->DecodedFrames+1] != d->FwdJumpInfo + 20) | ||
1829 | return FALSE; | ||
1830 | d->SeekTable [d->DecodedFrames+1] = d->FwdJumpInfo + 20; | ||
1831 | } else { | ||
1832 | if (d->DecodedFrames % d->SeekTable_Step == 0) { | ||
1833 | if (d->SeekTable[d->SeekTableIndex] != 0 && d->SeekTable[d->SeekTableIndex] != d->SeekTableCounter) | ||
1834 | return FALSE; | ||
1835 | d->SeekTable[d->SeekTableIndex] = d->SeekTableCounter; | ||
1836 | d->SeekTableIndex += 1; | ||
1837 | d->SeekTableCounter = 0; | ||
1838 | } | ||
1839 | d->SeekTableCounter += d->FwdJumpInfo + 20; | ||
1840 | } | ||
1364 | } | 1841 | } |
1842 | |||
1365 | // update buffer | 1843 | // update buffer |
1366 | if ((RING ^ d->Zaehler) & MEMSIZE2) { | 1844 | mpc_decoder_update_buffer(d); |
1367 | f_read_dword(d, d->Speicher + (RING & MEMSIZE2), MEMSIZE2); | 1845 | |
1846 | if (d->DecodedFrames == seekFrame - 1) { | ||
1847 | |||
1848 | // initialize the synth correctly for perfect decoding | ||
1849 | mpc_decoder_requantisierung(d, d->Max_Band); | ||
1850 | mpc_decoder_synthese_filter_float(d, NULL); | ||
1851 | |||
1368 | } | 1852 | } |
1853 | |||
1369 | } | 1854 | } |
1370 | 1855 | ||
1371 | // LastBitsRead = BitsRead (); | ||
1372 | // LastFrame = d->DecodedFrames; | ||
1373 | |||
1374 | return TRUE; | 1856 | return TRUE; |
1375 | } | 1857 | } |
1376 | 1858 | ||
1377 | void mpc_decoder_update_buffer(mpc_decoder *d, mpc_uint32_t RING) | 1859 | |
1860 | void mpc_decoder_fill_buffer(mpc_decoder *d) { | ||
1861 | |||
1862 | f_read_dword(d, d->Speicher, MEMSIZE); | ||
1863 | d->dword = SWAP(d->Speicher[d->Zaehler = 0]); | ||
1864 | d->next = SWAP(d->Speicher[1]); | ||
1865 | d->Ring = 0; | ||
1866 | |||
1867 | } | ||
1868 | |||
1869 | |||
1870 | void mpc_decoder_update_buffer(mpc_decoder *d) | ||
1378 | { | 1871 | { |
1379 | if ((RING ^ d->Zaehler) & MEMSIZE2 ) { | 1872 | if ((d->Ring ^ d->Zaehler) & MEMSIZE2) { |
1380 | // update buffer | 1873 | // update buffer |
1381 | f_read_dword(d, d->Speicher + (RING & MEMSIZE2), MEMSIZE2); | 1874 | f_read_dword(d, d->Speicher + (d->Ring & MEMSIZE2), MEMSIZE2); |
1875 | d->Ring = d->Zaehler; | ||
1876 | } | ||
1877 | } | ||
1878 | |||
1879 | |||
1880 | void mpc_decoder_seek_to(mpc_decoder *d, mpc_uint32_t bitPos) { | ||
1881 | |||
1882 | // required dword | ||
1883 | mpc_uint32_t fpos = (bitPos >> 5); | ||
1884 | mpc_uint32_t bufferStart = d->WordsRead - d->Zaehler; | ||
1885 | if ((d->Zaehler & MEMSIZE2) != FALSE) | ||
1886 | bufferStart += MEMSIZE2; | ||
1887 | |||
1888 | if (fpos >= bufferStart && fpos < bufferStart + MEMSIZE) { | ||
1889 | |||
1890 | // required position is within the buffer, no need to seek | ||
1891 | d->Zaehler = (fpos - bufferStart + ((d->Zaehler & MEMSIZE2) != FALSE ? MEMSIZE2 : 0)) & MEMMASK; | ||
1892 | d->pos = bitPos & 31; | ||
1893 | d->WordsRead = fpos; | ||
1894 | d->dword = SWAP(d->Speicher[d->Zaehler]); | ||
1895 | d->next = SWAP(d->Speicher[(d->Zaehler + 1) & MEMMASK]); | ||
1896 | |||
1897 | mpc_decoder_update_buffer(d); | ||
1898 | |||
1899 | |||
1900 | } else { | ||
1901 | |||
1902 | // DWORD aligned | ||
1903 | f_seek(d, fpos*4 + d->MPCHeaderPos); | ||
1904 | d->Zaehler = 0; | ||
1905 | d->pos = bitPos & 31; | ||
1906 | d->WordsRead = fpos; | ||
1907 | |||
1908 | mpc_decoder_fill_buffer(d); | ||
1909 | |||
1382 | } | 1910 | } |
1911 | |||
1912 | } | ||
1913 | |||
1914 | |||
1915 | void mpc_decoder_seek_forward(mpc_decoder *d, mpc_uint32_t bits) { | ||
1916 | |||
1917 | bits += d->pos; | ||
1918 | d->pos = bits & 31; | ||
1919 | bits = bits >> 5; // to DWORDs | ||
1920 | d->Zaehler = (d->Zaehler + bits) & MEMMASK; | ||
1921 | d->dword = SWAP(d->Speicher[d->Zaehler]); | ||
1922 | d->next = SWAP(d->Speicher[(d->Zaehler + 1) & MEMMASK]); | ||
1923 | d->WordsRead += bits; | ||
1924 | |||
1383 | } | 1925 | } |
1384 | 1926 | ||
1385 | 1927 | ||
1928 | void mpc_decoder_set_seek_table(mpc_decoder *d, mpc_uint32_t *seek_table, mpc_uint32_t max_table_size) { | ||
1929 | |||
1930 | d->Use_StaticSeekTable = TRUE; | ||
1931 | d->SeekTable = seek_table; | ||
1932 | d->Max_SeekTable_Size = max_table_size; | ||
1933 | |||
1934 | } | ||
diff --git a/apps/codecs/libmusepack/musepack.h b/apps/codecs/libmusepack/musepack.h index 9155f3f74d..549ea798a9 100644 --- a/apps/codecs/libmusepack/musepack.h +++ b/apps/codecs/libmusepack/musepack.h | |||
@@ -132,6 +132,12 @@ mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample); | |||
132 | /// Seeks to specified position in seconds in the source stream. | 132 | /// Seeks to specified position in seconds in the source stream. |
133 | mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds); | 133 | mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds); |
134 | 134 | ||
135 | /// Sets the static seek table pointer. | ||
136 | void mpc_decoder_set_seek_table(mpc_decoder *d, mpc_uint32_t *seek_table, mpc_uint32_t max_table_size); | ||
137 | |||
138 | /// Cleans up the decoder | ||
139 | void mpc_decoder_destroy(mpc_decoder *d); | ||
140 | |||
135 | #ifdef __cplusplus | 141 | #ifdef __cplusplus |
136 | } | 142 | } |
137 | #endif // __cplusplus | 143 | #endif // __cplusplus |
diff --git a/apps/codecs/libmusepack/synth_filter.c b/apps/codecs/libmusepack/synth_filter.c index c03355b01b..2b14c26c92 100644 --- a/apps/codecs/libmusepack/synth_filter.c +++ b/apps/codecs/libmusepack/synth_filter.c | |||
@@ -334,6 +334,7 @@ static void Synthese_Filter_float_internal(MPC_SAMPLE_FORMAT * OutData,MPC_SAMPL | |||
334 | for ( n = 0; n < 36; n++, Y += 32 ) { | 334 | for ( n = 0; n < 36; n++, Y += 32 ) { |
335 | V -= 64; | 335 | V -= 64; |
336 | Calculate_New_V ( Y, V ); | 336 | Calculate_New_V ( Y, V ); |
337 | if (OutData != NULL) | ||
337 | { | 338 | { |
338 | MPC_SAMPLE_FORMAT * Data = OutData; | 339 | MPC_SAMPLE_FORMAT * Data = OutData; |
339 | const MPC_SAMPLE_FORMAT * D = (const MPC_SAMPLE_FORMAT *) &Di_opt; | 340 | const MPC_SAMPLE_FORMAT * D = (const MPC_SAMPLE_FORMAT *) &Di_opt; |
@@ -429,7 +430,7 @@ static void Synthese_Filter_float_internal(MPC_SAMPLE_FORMAT * OutData,MPC_SAMPL | |||
429 | , 1); | 430 | , 1); |
430 | 431 | ||
431 | Data += 1; | 432 | Data += 1; |
432 | #endif | 433 | #endif |
433 | } | 434 | } |
434 | V -= 32;//bleh | 435 | V -= 32;//bleh |
435 | OutData+=32; | 436 | OutData+=32; |
@@ -452,7 +453,7 @@ mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData) | |||
452 | memmove(d->V_R + MPC_V_MEM, d->V_R, 960 * sizeof(MPC_SAMPLE_FORMAT) ); | 453 | memmove(d->V_R + MPC_V_MEM, d->V_R, 960 * sizeof(MPC_SAMPLE_FORMAT) ); |
453 | 454 | ||
454 | Synthese_Filter_float_internal( | 455 | Synthese_Filter_float_internal( |
455 | OutData + MPC_FRAME_LENGTH, | 456 | (OutData == NULL ? NULL : OutData + MPC_FRAME_LENGTH), |
456 | (MPC_SAMPLE_FORMAT *)(d->V_R + MPC_V_MEM), | 457 | (MPC_SAMPLE_FORMAT *)(d->V_R + MPC_V_MEM), |
457 | (MPC_SAMPLE_FORMAT *)(d->Y_R [0])); | 458 | (MPC_SAMPLE_FORMAT *)(d->Y_R [0])); |
458 | } | 459 | } |
diff --git a/apps/codecs/mpc.c b/apps/codecs/mpc.c index 6629801a56..c1fa0d7a99 100644 --- a/apps/codecs/mpc.c +++ b/apps/codecs/mpc.c | |||
@@ -22,7 +22,7 @@ | |||
22 | 22 | ||
23 | CODEC_HEADER | 23 | CODEC_HEADER |
24 | 24 | ||
25 | mpc_decoder decoder; | 25 | mpc_decoder decoder IBSS_ATTR; |
26 | 26 | ||
27 | /* Our implementations of the mpc_reader callback functions. */ | 27 | /* Our implementations of the mpc_reader callback functions. */ |
28 | mpc_int32_t read_impl(void *data, void *ptr, mpc_int32_t size) | 28 | mpc_int32_t read_impl(void *data, void *ptr, mpc_int32_t size) |
@@ -63,7 +63,8 @@ mpc_bool_t canseek_impl(void *data) | |||
63 | return true; | 63 | return true; |
64 | } | 64 | } |
65 | 65 | ||
66 | MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH] IBSS_ATTR; | 66 | MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH]; |
67 | mpc_uint32_t seek_table[10000]; | ||
67 | 68 | ||
68 | #ifdef USE_IRAM | 69 | #ifdef USE_IRAM |
69 | extern char iramcopy[]; | 70 | extern char iramcopy[]; |
@@ -92,6 +93,7 @@ enum codec_status codec_start(struct codec_api *api) | |||
92 | ci->configure(DSP_DITHER, (bool *)false); | 93 | ci->configure(DSP_DITHER, (bool *)false); |
93 | ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)(28)); | 94 | ci->configure(DSP_SET_SAMPLE_DEPTH, (long *)(28)); |
94 | ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*16)); | 95 | ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*16)); |
96 | ci->configure(CODEC_SET_FILEBUF_PRESEEK, (long *)(0)); | ||
95 | 97 | ||
96 | /* Create a decoder instance */ | 98 | /* Create a decoder instance */ |
97 | reader.read = read_impl; | 99 | reader.read = read_impl; |
@@ -101,6 +103,11 @@ enum codec_status codec_start(struct codec_api *api) | |||
101 | reader.canseek = canseek_impl; | 103 | reader.canseek = canseek_impl; |
102 | reader.data = ci; | 104 | reader.data = ci; |
103 | 105 | ||
106 | /* Ensure that SeekTable is clear since decoder is reused */ | ||
107 | decoder.SeekTable = NULL; | ||
108 | |||
109 | mpc_decoder_set_seek_table(&decoder, seek_table, sizeof(seek_table)); | ||
110 | |||
104 | next_track: | 111 | next_track: |
105 | if (codec_init(api)) { | 112 | if (codec_init(api)) { |
106 | retval = CODEC_ERROR; | 113 | retval = CODEC_ERROR; |
@@ -113,7 +120,7 @@ next_track: | |||
113 | retval = CODEC_ERROR; | 120 | retval = CODEC_ERROR; |
114 | goto done; | 121 | goto done; |
115 | } | 122 | } |
116 | frequency = info.sample_freq; | 123 | frequency = info.sample_freq / 1000; |
117 | ci->configure(DSP_SET_FREQUENCY, (long *)(long)info.sample_freq); | 124 | ci->configure(DSP_SET_FREQUENCY, (long *)(long)info.sample_freq); |
118 | 125 | ||
119 | /* set playback engine up for correct number of channels */ | 126 | /* set playback engine up for correct number of channels */ |
@@ -139,21 +146,23 @@ next_track: | |||
139 | /* This is the decoding loop. */ | 146 | /* This is the decoding loop. */ |
140 | samplesdone = 0; | 147 | samplesdone = 0; |
141 | do { | 148 | do { |
142 | #if 0 | 149 | #if 1 |
143 | /* Complete seek handler. This will be extremely slow and unresponsive | 150 | /* Complete seek handler. */ |
144 | on target, so has been disabledt. */ | ||
145 | if (ci->seek_time) { | 151 | if (ci->seek_time) { |
146 | mpc_int64_t new_offset = (ci->seek_time - 1)*info.sample_freq/1000; | 152 | /* hack to improve seek time if filebuf goes empty */ |
153 | ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*512)); | ||
154 | mpc_int64_t new_offset = (ci->seek_time - 1)*frequency; | ||
147 | if (mpc_decoder_seek_sample(&decoder, new_offset)) { | 155 | if (mpc_decoder_seek_sample(&decoder, new_offset)) { |
148 | samplesdone = new_offset; | 156 | samplesdone = new_offset; |
149 | ci->set_elapsed(ci->seek_time); | 157 | ci->set_elapsed(ci->seek_time); |
150 | } | 158 | } |
151 | ci->seek_complete(); | 159 | ci->seek_complete(); |
160 | /* reset chunksize */ | ||
161 | ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*16)); | ||
162 | |||
152 | } | 163 | } |
153 | #else | 164 | #else |
154 | /* Seek to start of track handler. This is the only case that isn't slow | 165 | /* Seek to start of track handler. */ |
155 | as hell, and needs to be supported for the back button to function as | ||
156 | wanted. */ | ||
157 | if (ci->seek_time) { | 166 | if (ci->seek_time) { |
158 | if (ci->seek_time == 1 && mpc_decoder_seek_sample(&decoder, 0)) { | 167 | if (ci->seek_time == 1 && mpc_decoder_seek_sample(&decoder, 0)) { |
159 | samplesdone = 0; | 168 | samplesdone = 0; |
@@ -178,7 +187,7 @@ next_track: | |||
178 | status*sizeof(MPC_SAMPLE_FORMAT))) | 187 | status*sizeof(MPC_SAMPLE_FORMAT))) |
179 | ci->yield(); | 188 | ci->yield(); |
180 | samplesdone += status; | 189 | samplesdone += status; |
181 | ci->set_elapsed(samplesdone/(frequency/1000)); | 190 | ci->set_elapsed(samplesdone/frequency); |
182 | } | 191 | } |
183 | } while (status != 0); | 192 | } while (status != 0); |
184 | retval = CODEC_OK; | 193 | retval = CODEC_OK; |
@@ -188,6 +197,7 @@ done: | |||
188 | goto next_track; | 197 | goto next_track; |
189 | 198 | ||
190 | exit: | 199 | exit: |
200 | mpc_decoder_destroy(&decoder); | ||
191 | return retval; | 201 | return retval; |
192 | } | 202 | } |
193 | 203 | ||