diff options
Diffstat (limited to 'lib/rbcodec/codecs/libmusepack')
26 files changed, 5600 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libmusepack/AUTHORS b/lib/rbcodec/codecs/libmusepack/AUTHORS new file mode 100644 index 0000000000..1bcac63765 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/AUTHORS | |||
@@ -0,0 +1,10 @@ | |||
1 | libmpcdec is the result of the work of many people: | ||
2 | |||
3 | * Andree Buschmann and Frank Klemm | ||
4 | Original implementation and core development. | ||
5 | |||
6 | * Peter Pawlowski and Benoit Amiaux | ||
7 | Portability and further optimizations. | ||
8 | |||
9 | * Miles Egan | ||
10 | Port to pure C, documentation, and api refinements. | ||
diff --git a/lib/rbcodec/codecs/libmusepack/COPYING b/lib/rbcodec/codecs/libmusepack/COPYING new file mode 100644 index 0000000000..10190c014a --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/COPYING | |||
@@ -0,0 +1,31 @@ | |||
1 | Copyright (c) 2005, The Musepack Development Team | ||
2 | All rights reserved. | ||
3 | |||
4 | Redistribution and use in source and binary forms, with or without | ||
5 | modification, are permitted provided that the following conditions are | ||
6 | met: | ||
7 | |||
8 | * Redistributions of source code must retain the above copyright | ||
9 | notice, this list of conditions and the following disclaimer. | ||
10 | |||
11 | * Redistributions in binary form must reproduce the above | ||
12 | copyright notice, this list of conditions and the following | ||
13 | disclaimer in the documentation and/or other materials provided | ||
14 | with the distribution. | ||
15 | |||
16 | * Neither the name of the The Musepack Development Team nor the | ||
17 | names of its contributors may be used to endorse or promote | ||
18 | products derived from this software without specific prior | ||
19 | written permission. | ||
20 | |||
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
25 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
27 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
31 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
diff --git a/lib/rbcodec/codecs/libmusepack/ChangeLog b/lib/rbcodec/codecs/libmusepack/ChangeLog new file mode 100644 index 0000000000..6c998480bd --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/ChangeLog | |||
@@ -0,0 +1,40 @@ | |||
1 | 1.3.0 | ||
2 | * first sv8 release | ||
3 | * major changes in the API (decoder and demuxer are split) | ||
4 | |||
5 | 1.2.3 | ||
6 | * Reduced memory usage and code size. Patch by Peter Pawlowski | ||
7 | |||
8 | 1.2.2 | ||
9 | * Fixed compilation under OpenBSD | ||
10 | * Unix EOF again | ||
11 | |||
12 | 1.2.1 | ||
13 | * Warnings cleanup, patch by Tomas Salfischberger, Thom Johansen and | ||
14 | Daniel Stenberg (Rockbox) | ||
15 | * Mplayer interface, patch by Reimar Doffinger | ||
16 | * Unix EOF everywhere | ||
17 | |||
18 | 1.2 | ||
19 | * 1.1.1 broke the API (BOOL type changed to mpc_bool_t). Version bumped to 1.2 to reflect the major change. Sorry to those who were caught by this error | ||
20 | * Fixed relative/absolute includes (#include "stuff.h" in /include/mpcdec, #include <mpcdec/stuff> in src/) | ||
21 | * Added msvc project files | ||
22 | * Changed mpc_reader_t structure, any specific data of the reader's | ||
23 | implementations should be hidden behind the (void*) data pointer. (example | ||
24 | in default implementation mpc_reader_file) | ||
25 | * Renamed to libmpcdec (to make room for libmpcenc) | ||
26 | |||
27 | 1.1.1 | ||
28 | * fix for fixed-point mode bug | ||
29 | |||
30 | 1.1 | ||
31 | * add compliance & cleanup patches from Michael Roitzsch of xine project | ||
32 | * switch to BSD license | ||
33 | * port to pure C | ||
34 | * add doxygen documentation | ||
35 | * revise API somewhat | ||
36 | |||
37 | 1.0.3 | ||
38 | * autotools build process | ||
39 | * sample binary added | ||
40 | * floating-point mode by default | ||
diff --git a/lib/rbcodec/codecs/libmusepack/SOURCES b/lib/rbcodec/codecs/libmusepack/SOURCES new file mode 100644 index 0000000000..60d762afd2 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/SOURCES | |||
@@ -0,0 +1,14 @@ | |||
1 | crc32.c | ||
2 | huffman.c | ||
3 | mpc_bits_reader.c | ||
4 | mpc_decoder.c | ||
5 | mpc_demux.c | ||
6 | requant.c | ||
7 | streaminfo.c | ||
8 | synth_filter.c | ||
9 | #if defined(CPU_ARM) | ||
10 | synth_filter_arm.S | ||
11 | #endif | ||
12 | #if defined(CPU_COLDFIRE) | ||
13 | synth_filter_coldfire.S | ||
14 | #endif | ||
diff --git a/lib/rbcodec/codecs/libmusepack/crc32.c b/lib/rbcodec/codecs/libmusepack/crc32.c new file mode 100644 index 0000000000..7613f1c2c8 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/crc32.c | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * C Implementation: crc32 | ||
3 | * | ||
4 | * code from http://www.w3.org/TR/PNG/#D-CRCAppendix | ||
5 | * | ||
6 | */ | ||
7 | #include "internal.h" | ||
8 | |||
9 | /* Table of CRCs of all 8-bit messages. */ | ||
10 | static unsigned long crc_table[256]; | ||
11 | |||
12 | /* Flag: has the table been computed? Initially false. */ | ||
13 | static int crc_table_computed = 0; | ||
14 | |||
15 | /* Make the table for a fast CRC. */ | ||
16 | static void make_crc_table(void) | ||
17 | { | ||
18 | unsigned long c; | ||
19 | int n, k; | ||
20 | |||
21 | for (n = 0; n < 256; n++) { | ||
22 | c = (unsigned long) n; | ||
23 | for (k = 0; k < 8; k++) { | ||
24 | if (c & 1) | ||
25 | c = 0xedb88320L ^ (c >> 1); | ||
26 | else | ||
27 | c = c >> 1; | ||
28 | } | ||
29 | crc_table[n] = c; | ||
30 | } | ||
31 | crc_table_computed = 1; | ||
32 | } | ||
33 | |||
34 | |||
35 | /* Update a running CRC with the bytes buf[0..len-1]--the CRC | ||
36 | should be initialized to all 1's, and the transmitted value | ||
37 | is the 1's complement of the final running CRC (see the | ||
38 | crc() routine below). */ | ||
39 | |||
40 | static unsigned long update_crc(unsigned long crc, unsigned char *buf, int len) | ||
41 | { | ||
42 | unsigned long c = crc; | ||
43 | int n; | ||
44 | |||
45 | if (!crc_table_computed) | ||
46 | make_crc_table(); | ||
47 | for (n = 0; n < len; n++) { | ||
48 | c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); | ||
49 | } | ||
50 | return c; | ||
51 | } | ||
52 | |||
53 | /* Return the CRC of the bytes buf[0..len-1]. */ | ||
54 | unsigned long mpc_crc32(unsigned char *buf, int len) | ||
55 | { | ||
56 | return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL; | ||
57 | } | ||
diff --git a/lib/rbcodec/codecs/libmusepack/decoder.h b/lib/rbcodec/codecs/libmusepack/decoder.h new file mode 100644 index 0000000000..1acacae8d9 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/decoder.h | |||
@@ -0,0 +1,101 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | /// \file decoder.h | ||
35 | #ifndef _MPCDEC_DECODER_H_ | ||
36 | #define _MPCDEC_DECODER_H_ | ||
37 | #ifdef WIN32 | ||
38 | #pragma once | ||
39 | #endif | ||
40 | |||
41 | #include "reader.h" | ||
42 | |||
43 | #ifdef __cplusplus | ||
44 | extern "C" { | ||
45 | #endif | ||
46 | |||
47 | #define SEEKING_TABLE_SIZE 256u | ||
48 | // set it to SLOW_SEEKING_WINDOW to not use fast seeking | ||
49 | #define FAST_SEEKING_WINDOW 32 | ||
50 | // set it to FAST_SEEKING_WINDOW to only use fast seeking | ||
51 | #define SLOW_SEEKING_WINDOW 0x80000000 | ||
52 | |||
53 | enum { | ||
54 | MPC_V_MEM = 2304, | ||
55 | MPC_DECODER_MEMSIZE = 16384, // overall buffer size | ||
56 | }; | ||
57 | |||
58 | struct mpc_decoder_t { | ||
59 | /// @name internal state variables | ||
60 | //@{ | ||
61 | mpc_uint32_t stream_version; ///< Streamversion of stream | ||
62 | mpc_int32_t max_band; ///< Maximum band-index used in stream (0...31) | ||
63 | mpc_uint32_t ms; ///< Mid/side stereo (0: off, 1: on) | ||
64 | mpc_uint32_t channels; ///< Number of channels in stream | ||
65 | |||
66 | mpc_uint64_t samples; ///< Number of samples in stream | ||
67 | |||
68 | mpc_uint64_t decoded_samples; ///< Number of samples decoded from file begining | ||
69 | mpc_uint32_t samples_to_skip; ///< Number samples to skip (used for seeking) | ||
70 | mpc_int32_t last_max_band; ///< number of bands used in the last frame | ||
71 | |||
72 | // randomizer state variables | ||
73 | mpc_uint32_t __r1; | ||
74 | mpc_uint32_t __r2; | ||
75 | |||
76 | mpc_int32_t SCF_Index_L [32] [3]; | ||
77 | mpc_int32_t SCF_Index_R [32] [3]; // holds scalefactor-indices | ||
78 | mpc_quantizer Q [32]; // holds quantized samples | ||
79 | mpc_int32_t Res_L [32]; | ||
80 | mpc_int32_t Res_R [32]; // holds the chosen quantizer for each subband | ||
81 | mpc_bool_t DSCF_Flag_L [32]; | ||
82 | mpc_bool_t DSCF_Flag_R [32]; // differential SCF used? | ||
83 | mpc_int32_t SCFI_L [32]; | ||
84 | mpc_int32_t SCFI_R [32]; // describes order of transmitted SCF | ||
85 | mpc_bool_t MS_Flag[32]; // MS used? | ||
86 | #ifdef MPC_FIXED_POINT | ||
87 | mpc_uint8_t SCF_shift[256]; | ||
88 | #endif | ||
89 | |||
90 | MPC_SAMPLE_FORMAT *V_L; | ||
91 | MPC_SAMPLE_FORMAT *V_R; | ||
92 | MPC_SAMPLE_FORMAT *Y_L; | ||
93 | MPC_SAMPLE_FORMAT *Y_R; | ||
94 | mpc_uint32_t SCF[256]; ///< holds adapted scalefactors (for clipping prevention) | ||
95 | //@} | ||
96 | }; | ||
97 | |||
98 | #ifdef __cplusplus | ||
99 | } | ||
100 | #endif | ||
101 | #endif | ||
diff --git a/lib/rbcodec/codecs/libmusepack/huffman.c b/lib/rbcodec/codecs/libmusepack/huffman.c new file mode 100644 index 0000000000..c304775623 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/huffman.c | |||
@@ -0,0 +1,530 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | /// \file huffman.c | ||
35 | /// Implementations of sv7/sv8 huffman decoding functions. | ||
36 | #include "mpcdec.h" | ||
37 | #include "huffman.h" | ||
38 | |||
39 | |||
40 | // sv7 huffman tables | ||
41 | static const mpc_huffman mpc_table_HuffHdr [10] ICONST_ATTR = { | ||
42 | {0x8000, 1, 0}, {0x6000, 3, 1}, {0x5e00, 7,-4}, {0x5d80, 9, 3}, {0x5d00, 9, 4}, | ||
43 | {0x5c00, 8,-5}, {0x5800, 6, 2}, {0x5000, 5,-3}, {0x4000, 4,-2}, {0x0000, 2,-1} | ||
44 | }; | ||
45 | |||
46 | const mpc_huffman mpc_table_HuffSCFI [4] ICONST_ATTR = { | ||
47 | {0x8000, 1, 1}, {0x6000, 3, 2}, {0x4000, 3, 0}, {0x0000, 2, 3} | ||
48 | }; | ||
49 | |||
50 | static const mpc_huffman mpc_table_HuffDSCF [16] ICONST_ATTR = { | ||
51 | {0xf800, 5, 5}, {0xf000, 5,-4}, {0xe000, 4, 3}, {0xd000, 4,-3}, | ||
52 | {0xc000, 4, 8}, {0xa000, 3, 1}, {0x9000, 4, 0}, {0x8800, 5,-5}, | ||
53 | {0x8400, 6, 7}, {0x8000, 6,-7}, {0x6000, 3,-1}, {0x4000, 3, 2}, | ||
54 | {0x3000, 4, 4}, {0x2800, 5, 6}, {0x2000, 5,-6}, {0x0000, 3,-2} | ||
55 | }; | ||
56 | |||
57 | static const mpc_huffman mpc_table_HuffQ1 [2] [27] ICONST_ATTR = { | ||
58 | { | ||
59 | {0xe000, 3, 13}, {0xdc00, 6, 26}, {0xd800, 6, 0}, | ||
60 | {0xd400, 6, 20}, {0xd000, 6, 6}, {0xc000, 4, 14}, | ||
61 | {0xb000, 4, 12}, {0xa000, 4, 4}, {0x9000, 4, 22}, | ||
62 | {0x8c00, 6, 8}, {0x8800, 6, 18}, {0x8400, 6, 24}, | ||
63 | {0x8000, 6, 2}, {0x7000, 4, 16}, {0x6000, 4, 10}, | ||
64 | {0x5800, 5, 17}, {0x5000, 5, 9}, {0x4800, 5, 1}, | ||
65 | {0x4000, 5, 25}, {0x3800, 5, 5}, {0x3000, 5, 21}, | ||
66 | {0x2800, 5, 3}, {0x2000, 5, 11}, {0x1800, 5, 15}, | ||
67 | {0x1000, 5, 23}, {0x0800, 5, 19}, {0x0000, 5, 7} | ||
68 | }, { | ||
69 | {0x8000, 1, 13}, {0x7e00, 7, 15}, {0x7c00, 7, 1}, | ||
70 | {0x7a00, 7, 11}, {0x7800, 7, 7}, {0x7600, 7, 17}, | ||
71 | {0x7400, 7, 25}, {0x7200, 7, 19}, {0x7180, 9, 8}, | ||
72 | {0x7100, 9, 18}, {0x7080, 9, 2}, {0x7000, 9, 24}, | ||
73 | {0x6e00, 7, 3}, {0x6c00, 7, 23}, {0x6a00, 7, 21}, | ||
74 | {0x6800, 7, 5}, {0x6700, 8, 0}, {0x6600, 8, 26}, | ||
75 | {0x6500, 8, 6}, {0x6400, 8, 20}, {0x6000, 6, 9}, | ||
76 | {0x5000, 4, 14}, {0x4000, 4, 12}, {0x3000, 4, 4}, | ||
77 | {0x2000, 4, 22}, {0x1000, 4, 16}, {0x0000, 4, 10} | ||
78 | } | ||
79 | }; | ||
80 | |||
81 | static const mpc_huffman mpc_table_HuffQ2 [2] [25] ICONST_ATTR = { | ||
82 | { | ||
83 | {0xf000, 4, 13}, {0xe000, 4, 17}, {0xd000, 4, 7}, {0xc000, 4, 11}, {0xbc00, 6, 1}, | ||
84 | {0xb800, 6, 23}, {0xb600, 7, 4}, {0xb400, 7, 20}, {0xb200, 7, 0}, {0xb000, 7, 24}, | ||
85 | {0xa800, 5, 22}, {0xa000, 5, 10}, {0x8000, 3, 12}, {0x7800, 5, 2}, {0x7000, 5, 14}, | ||
86 | {0x6000, 4, 6}, {0x5000, 4, 18}, {0x4000, 4, 8}, {0x3000, 4, 16}, {0x2800, 5, 9}, | ||
87 | {0x2000, 5, 5}, {0x1800, 5, 15}, {0x1000, 5, 21}, {0x0800, 5, 19}, {0x0000, 5, 3} | ||
88 | }, { | ||
89 | {0xf800, 5, 18}, {0xf000, 5, 6}, {0xe800, 5, 8}, {0xe700, 8, 3}, {0xe6c0,10, 24}, | ||
90 | {0xe680,10, 4}, {0xe640,10, 0}, {0xe600,10, 20}, {0xe400, 7, 23}, {0xe200, 7, 1}, | ||
91 | {0xe000, 7, 19}, {0xd800, 5, 16}, {0xd600, 7, 15}, {0xd400, 7, 21}, {0xd200, 7, 9}, | ||
92 | {0xd000, 7, 5}, {0xcc00, 6, 2}, {0xc800, 6, 10}, {0xc400, 6, 14}, {0xc000, 6, 22}, | ||
93 | {0x8000, 2, 12}, {0x6000, 3, 13}, {0x4000, 3, 17}, {0x2000, 3, 11}, {0x0000, 3, 7} | ||
94 | } | ||
95 | }; | ||
96 | |||
97 | static const mpc_huffman mpc_table_HuffQ3 [2] [7] ICONST_ATTR = { | ||
98 | { | ||
99 | {0xe000, 3, 1}, {0xd000, 4, 3}, {0xc000, 4,-3}, {0xa000, 3, 2}, | ||
100 | {0x8000, 3,-2}, {0x4000, 2, 0}, {0x0000, 2,-1} | ||
101 | }, { | ||
102 | {0xc000, 2, 0}, {0x8000, 2,-1}, {0x4000, 2, 1}, {0x3000, 4,-2}, | ||
103 | {0x2800, 5, 3}, {0x2000, 5,-3}, {0x0000, 3, 2} | ||
104 | } | ||
105 | }; | ||
106 | |||
107 | static const mpc_huffman mpc_table_HuffQ4 [2] [9] ICONST_ATTR = { | ||
108 | { | ||
109 | {0xe000, 3, 0}, {0xc000, 3,-1}, {0xa000, 3, 1}, | ||
110 | {0x8000, 3,-2}, {0x6000, 3, 2}, {0x5000, 4,-4}, | ||
111 | {0x4000, 4, 4}, {0x2000, 3, 3}, {0x0000, 3,-3} | ||
112 | }, { | ||
113 | {0xe000, 3, 1}, {0xd000, 4, 2}, {0xc000, 4,-3}, | ||
114 | {0x8000, 2, 0}, {0x6000, 3,-2}, {0x5000, 4, 3}, | ||
115 | {0x4800, 5,-4}, {0x4000, 5, 4}, {0x0000, 2,-1} | ||
116 | } | ||
117 | }; | ||
118 | |||
119 | static const mpc_huffman mpc_table_HuffQ5 [2] [15] ICONST_ATTR = { | ||
120 | { | ||
121 | {0xf000, 4, 2}, {0xe800, 5, 5}, {0xe400, 6,-7}, {0xe000, 6, 7}, {0xd000, 4,-3}, | ||
122 | {0xc000, 4, 3}, {0xb800, 5,-6}, {0xb000, 5, 6}, {0xa000, 4,-4}, {0x9000, 4, 4}, | ||
123 | {0x8000, 4,-5}, {0x6000, 3, 0}, {0x4000, 3,-1}, {0x2000, 3, 1}, {0x0000, 3,-2} | ||
124 | }, { | ||
125 | {0xf000, 4, 3}, {0xe800, 5, 4}, {0xe600, 7, 6}, {0xe500, 8,-7}, {0xe400, 8, 7}, | ||
126 | {0xe000, 6,-6}, {0xc000, 3, 0}, {0xa000, 3,-1}, {0x8000, 3, 1}, {0x6000, 3,-2}, | ||
127 | {0x4000, 3, 2}, {0x3800, 5,-5}, {0x3000, 5, 5}, {0x2000, 4,-4}, {0x0000, 3,-3} | ||
128 | } | ||
129 | }; | ||
130 | |||
131 | static const mpc_huffman mpc_table_HuffQ6 [2] [31] ICONST_ATTR = { | ||
132 | { | ||
133 | {0xf800, 5, 3}, {0xf000, 5, -4}, {0xec00, 6,-11}, {0xe800, 6, 12}, {0xe000, 5, 4}, | ||
134 | {0xd800, 5, 6}, {0xd000, 5, -5}, {0xc800, 5, 5}, {0xc000, 5, 7}, {0xb800, 5, -7}, | ||
135 | {0xb400, 6,-12}, {0xb000, 6,-13}, {0xa800, 5, -6}, {0xa000, 5, 8}, {0x9800, 5, -8}, | ||
136 | {0x9000, 5, 9}, {0x8800, 5, -9}, {0x8400, 6, 13}, {0x8200, 7,-15}, {0x8000, 7, 15}, | ||
137 | {0x7000, 4, 0}, {0x6800, 5,-10}, {0x6000, 5, 10}, {0x5000, 4, -1}, {0x4000, 4, 2}, | ||
138 | {0x3000, 4, 1}, {0x2000, 4, -2}, {0x1c00, 6, 14}, {0x1800, 6,-14}, {0x1000, 5, 11}, | ||
139 | {0x0000, 4, -3} | ||
140 | }, { | ||
141 | {0xf800, 5, -6}, {0xf000, 5, 6}, {0xe000, 4, 1}, {0xd000, 4, -1}, {0xce00, 7, 10}, | ||
142 | {0xcc00, 7,-10}, {0xcb00, 8,-11}, {0xca80, 9,-12}, {0xca60,11, 13}, {0xca58,13, 15}, | ||
143 | {0xca50,13,-14}, {0xca48,13, 14}, {0xca40,13,-15}, {0xca00,10,-13}, {0xc900, 8, 11}, | ||
144 | {0xc800, 8, 12}, {0xc400, 6, -9}, {0xc000, 6, 9}, {0xb000, 4, -2}, {0xa000, 4, 2}, | ||
145 | {0x9000, 4, 3}, {0x8000, 4, -3}, {0x7800, 5, -7}, {0x7000, 5, 7}, {0x6000, 4, -4}, | ||
146 | {0x5000, 4, 4}, {0x4800, 5, -8}, {0x4000, 5, 8}, {0x3000, 4, 5}, {0x2000, 4, -5}, | ||
147 | {0x0000, 3, 0} | ||
148 | } | ||
149 | }; | ||
150 | |||
151 | static const mpc_huffman mpc_table_HuffQ7 [2] [63] ICONST_ATTR = { | ||
152 | { | ||
153 | {0xfc00, 6, 7}, {0xf800, 6, 8}, {0xf400, 6, 9}, {0xf000, 6, -8}, {0xec00, 6, 11}, | ||
154 | {0xea00, 7, 21}, {0xe900, 8,-28}, {0xe800, 8, 28}, {0xe400, 6, -9}, {0xe200, 7,-22}, | ||
155 | {0xe000, 7,-21}, {0xdc00, 6,-10}, {0xd800, 6,-11}, {0xd400, 6, 10}, {0xd000, 6, 12}, | ||
156 | {0xcc00, 6,-13}, {0xca00, 7, 22}, {0xc800, 7, 23}, {0xc400, 6,-12}, {0xc000, 6, 13}, | ||
157 | {0xbc00, 6, 14}, {0xb800, 6,-14}, {0xb600, 7,-23}, {0xb500, 8,-29}, {0xb400, 8, 29}, | ||
158 | {0xb000, 6,-15}, {0xac00, 6, 15}, {0xa800, 6, 16}, {0xa400, 6,-16}, {0xa200, 7,-24}, | ||
159 | {0xa000, 7, 24}, {0x9c00, 6, 17}, {0x9a00, 7,-25}, {0x9900, 8,-30}, {0x9800, 8, 30}, | ||
160 | {0x9400, 6,-17}, {0x9000, 6, 18}, {0x8c00, 6,-18}, {0x8a00, 7, 25}, {0x8800, 7, 26}, | ||
161 | {0x8400, 6, 19}, {0x8200, 7,-26}, {0x8000, 7,-27}, {0x7800, 5, 2}, {0x7400, 6,-19}, | ||
162 | {0x7000, 6, 20}, {0x6800, 5, -1}, {0x6700, 8,-31}, {0x6600, 8, 31}, {0x6400, 7, 27}, | ||
163 | {0x6000, 6,-20}, {0x5800, 5, 1}, {0x5000, 5, -5}, {0x4800, 5, -3}, {0x4000, 5, 3}, | ||
164 | {0x3800, 5, 0}, {0x3000, 5, -2}, {0x2800, 5, -4}, {0x2000, 5, 4}, {0x1800, 5, 5}, | ||
165 | {0x1000, 5, -6}, {0x0800, 5, 6}, {0x0000, 5, -7} | ||
166 | }, { | ||
167 | {0xf800, 5, -1}, {0xf000, 5, 2}, {0xe800, 5, -2}, {0xe000, 5, 3}, {0xdf00, 8,-20}, | ||
168 | {0xdec0,10, 24}, {0xdebc,14, 28}, {0xdeb8,14,-28}, {0xdeb4,14,-30}, {0xdeb0,14, 30}, | ||
169 | {0xdea0,12,-27}, {0xde9c,14, 29}, {0xde98,14,-29}, {0xde94,14, 31}, {0xde90,14,-31}, | ||
170 | {0xde80,12, 27}, {0xde00, 9,-22}, {0xdc00, 7,-17}, {0xd800, 6,-11}, {0xd000, 5, -3}, | ||
171 | {0xc800, 5, 4}, {0xc000, 5, -4}, {0xbe00, 7, 17}, {0xbd00, 8, 20}, {0xbc80, 9, 22}, | ||
172 | {0xbc40,10,-25}, {0xbc00,10,-26}, {0xb800, 6, 12}, {0xb000, 5, 5}, {0xa800, 5, -5}, | ||
173 | {0xa000, 5, 6}, {0x9800, 5, -6}, {0x9400, 6,-12}, {0x9200, 7,-18}, {0x9000, 7, 18}, | ||
174 | {0x8c00, 6, 13}, {0x8800, 6,-13}, {0x8000, 5, -7}, {0x7c00, 6, 14}, {0x7b00, 8, 21}, | ||
175 | {0x7a00, 8,-21}, {0x7800, 7,-19}, {0x7000, 5, 7}, {0x6800, 5, 8}, {0x6400, 6,-14}, | ||
176 | {0x6000, 6,-15}, {0x5800, 5, -8}, {0x5400, 6, 15}, {0x5200, 7, 19}, {0x51c0,10, 25}, | ||
177 | {0x5180,10, 26}, {0x5100, 9,-23}, {0x5080, 9, 23}, {0x5000, 9,-24}, {0x4800, 5,-9}, | ||
178 | {0x4000, 5, 9}, {0x3c00, 6, 16}, {0x3800, 6,-16}, {0x3000, 5, 10}, {0x2000, 4, 0}, | ||
179 | {0x1800, 5,-10}, {0x1000, 5, 11}, {0x0000, 4, 1} | ||
180 | } | ||
181 | }; | ||
182 | |||
183 | // sv8 huffman tables | ||
184 | static const mpc_huffman mpc_huff_SCFI_1 [3] ICONST_ATTR = { | ||
185 | {0x8000, 1, 1}, {0x4000, 2, 2}, {0x0, 3, 3} | ||
186 | }; // 3 | ||
187 | static const mpc_int8_t mpc_sym_SCFI_1 [4] ICONST_ATTR = { | ||
188 | 2, 3, 1, 0 | ||
189 | }; | ||
190 | static const mpc_huffman mpc_huff_SCFI_2 [5] ICONST_ATTR = { | ||
191 | {0x8000, 2, 3}, {0x4000, 3, 5}, {0x1800, 5, 11}, {0x400, 6, 14}, {0x0, 7, 15} | ||
192 | }; // 5 | ||
193 | static const mpc_int8_t mpc_sym_SCFI_2 [16] ICONST_ATTR = { | ||
194 | 15, 10, 14, 11, 13, 9, 7, 6, 5, 12, 8, 3, 2, 0, 4, 1 | ||
195 | }; | ||
196 | |||
197 | static const mpc_huffman mpc_huff_DSCF_1 [12] ICONST_ATTR = { | ||
198 | {0xa000, 3, 7}, {0x4000, 4, 12}, {0x2800, 5, 16}, {0x1800, 6, 21}, | ||
199 | {0x0e00, 7, 27}, {0x0700, 8, 34}, {0x0380, 9, 41}, {0x0140, 10, 48}, | ||
200 | {0x0080, 11, 53}, {0x0030, 12, 57}, {0x0018, 13, 60}, {0x0000, 14, 63} | ||
201 | }; // 12 | ||
202 | static const mpc_int8_t mpc_sym_DSCF_1 [64] ICONST_ATTR = { | ||
203 | 35, 34, 33, 36, 32, 30, 29, 27, 26, 37, 28, 25, 39, 38, 24, 23, | ||
204 | 40, 22, 21, 20, 19, 43, 42, 41, 18, 17, 16, 15, 46, 45, 44, 14, | ||
205 | 13, 12, 11, 49, 48, 47, 31, 10, 9, 8, 7, 6, 52, 51, 50, 5, | ||
206 | 4, 3, 54, 53, 2, 1, 0, 57, 56, 55, 63, 62, 61, 60, 59, 58 | ||
207 | }; | ||
208 | static const mpc_huffman mpc_huff_DSCF_2 [13] ICONST_ATTR = { | ||
209 | {0x6000, 3, 7}, {0x3000, 4, 10}, {0x1800, 5, 13}, {0x1000, 6, 16}, | ||
210 | {0x0a00, 7, 20}, {0x0600, 8, 25}, {0x0380, 9, 31}, {0x01c0, 10, 38}, | ||
211 | {0x00e0, 11, 45}, {0x0050, 12, 52}, {0x0020, 13, 57}, {0x000c, 14, 61}, | ||
212 | {0x0000, 15, 64} | ||
213 | }; // 13 | ||
214 | static const mpc_int8_t mpc_sym_DSCF_2 [65] ICONST_ATTR = { | ||
215 | 33, 32, 31, 30, 29, 34, 28, 27, 36, 35, 26, 37, 25, 38, 24, 23, | ||
216 | 40, 39, 22, 21, 42, 41, 20, 19, 18, 45, 44, 43, 17, 16, 15, 14, | ||
217 | 48, 47, 46, 13, 12, 11, 10, 64, 52, 51, 50, 49, 9, 8, 7, 6, | ||
218 | 55, 54, 53, 5, 4, 3, 58, 57, 56, 2, 1, 63, 62, 61, 60, 59, | ||
219 | 0 | ||
220 | }; | ||
221 | |||
222 | static const mpc_huffman mpc_huff_Bands [12] ICONST_ATTR = { | ||
223 | {0x8000, 1, 1}, {0x4000, 2, 2}, {0x2000, 3, 3}, {0x1000, 5, 6}, | ||
224 | {0x0800, 6, 8}, {0x0600, 7, 10}, {0x0300, 8, 13}, {0x0200, 9, 16}, | ||
225 | {0x0140, 10, 20}, {0x00c0, 11, 25}, {0x0010, 12, 31}, {0x0000, 13, 32} | ||
226 | }; // 12 | ||
227 | static const mpc_int8_t mpc_sym_Bands [33] ICONST_ATTR = { | ||
228 | 0, 32, 1, 31, 2, 30, 3, 4, 29, 6, 5, 28, 7, 27, 26, 8, | ||
229 | 25, 24, 23, 9, 22, 21, 20, 18, 17, 16, 15, 14, 12, 11, 10, 19, | ||
230 | 13 | ||
231 | }; | ||
232 | |||
233 | static const mpc_huffman mpc_huff_Res_1 [16] ICONST_ATTR = { | ||
234 | {0x8000, 1, 1}, {0x4000, 2, 2}, {0x2000, 3, 3}, {0x1000, 4, 4}, | ||
235 | {0x0800, 5, 5}, {0x0400, 6, 6}, {0x0200, 7, 7}, {0x0100, 8, 8}, | ||
236 | {0x0080, 9, 9}, {0x0040, 10, 10}, {0x0020, 11, 11}, {0x0010, 12, 12}, | ||
237 | {0x0008, 13, 13}, {0x0004, 14, 14}, {0x0002, 15, 15}, {0x0000, 16, 16} | ||
238 | }; // 16 | ||
239 | static const mpc_int8_t mpc_sym_Res_1 [17] ICONST_ATTR = { | ||
240 | 0, 1, 16, 2, 3, 4, 5, 15, 6, 7, 8, 9, 10, 11, 12, 14, 13 | ||
241 | }; | ||
242 | static const mpc_huffman mpc_huff_Res_2 [12] ICONST_ATTR = { | ||
243 | {0x4000, 2, 3}, {0x2000, 3, 4}, {0x1000, 4, 5}, {0x0800, 5, 6}, | ||
244 | {0x0400, 6, 7}, {0x0200, 7, 8}, {0x0100, 8, 9}, {0x0080, 9, 10}, | ||
245 | {0x0040, 10, 11}, {0x0020, 11, 12}, {0x0010, 12, 13}, {0x0000, 14, 16} | ||
246 | }; // 12 | ||
247 | static const mpc_int8_t mpc_sym_Res_2 [17] ICONST_ATTR = { | ||
248 | 16, 1, 0, 2, 15, 3, 14, 4, 5, 13, 6, 12, 7, 11, 10, 9, 8 | ||
249 | }; | ||
250 | |||
251 | static const mpc_huffman mpc_huff_Q1 [10] ICONST_ATTR = { | ||
252 | {0x6000, 3, 7}, {0x1000, 4, 10}, {0x0800, 5, 11}, {0x0400, 6, 12}, | ||
253 | {0x0200, 7, 13}, {0x0100, 8, 14}, {0x0080, 9, 15}, {0x0040, 10, 16}, | ||
254 | {0x0020, 11, 17}, {0x0000, 12, 18} | ||
255 | }; // 10 | ||
256 | static const mpc_int8_t mpc_sym_Q1 [19] ICONST_ATTR = { | ||
257 | 7, 6, 5, 4, 3, 10, 9, 8, 2, 1, 11, 0, 12, 13, 14, 15, 16, 18, 17 | ||
258 | }; | ||
259 | |||
260 | static const mpc_huffman mpc_huff_Q2_1 [10] ICONST_ATTR = { | ||
261 | {0xe000, 3, 7}, {0x8000, 4, 14}, {0x3c00, 6, 38}, {0x2a00, 7, 53}, | ||
262 | {0x1200, 8, 74}, {0x0600, 9, 92}, {0x03c0, 10,104}, {0x0060, 11,119}, | ||
263 | {0x0020, 12,122}, {0x0000, 13,124} | ||
264 | }; // 10 | ||
265 | static const mpc_int8_t mpc_sym_Q2_1 [125] ICONST_ATTR = { | ||
266 | 62, 87, 67, 63, 61, 57, 37, 93, 92, 88, 86, 83, 82, 81, 68, 66, 58, 56, 42, 41, 38, 36, 32, 31,112, | ||
267 | 91, 72, 64, 60, 52, 43, 33, 12,117,113,111,107, 97, 89, 85, 77, 73, 71, 69, 65, 59, 55, 53, 51, 47, | ||
268 | 39, 35, 27, 17, 13, 11, 7,118,116,108,106, 98, 96, 94, 90, 84, 80, 78, 76, 48, 46, 44, 40, 34, 30, | ||
269 | 28, 26, 18, 16, 8, 6,122,110,102, 74, 70, 54, 50, 22, 2,123,121,119,115,114,109,105,103,101, 99, | ||
270 | 95, 79, 75, 49, 45, 29, 25, 23, 21, 19, 15, 14, 10, 9, 5, 3, 1,124,104, 20, 0,120,100, 24, 4 | ||
271 | }; | ||
272 | static const mpc_huffman mpc_huff_Q2_2 [9] ICONST_ATTR = { | ||
273 | {0xf000, 4, 15}, {0x7000, 5, 30}, {0x4800, 6, 44}, | ||
274 | {0x3c00, 7, 62}, {0x0c00, 8, 92}, {0x0780, 9,104}, | ||
275 | {0x00c0, 10,119}, {0x0040, 11,122}, {0x0000, 12,124} | ||
276 | }; // 9 | ||
277 | static const mpc_int8_t mpc_sym_Q2_2 [125] ICONST_ATTR = { | ||
278 | 62, 92, 87, 86, 82, 68, 67, 66, 63, 61, 58, 57, 56, 42, 38, 37, 32, 93, 91, 88, 83, 81, 43, 41, 36, | ||
279 | 33, 31,112, 72, 64, 60, 52, 12,118,117,116,113,111,108,107,106, 98, 97, 96, 94, 90, 89, 85, 84, 80, | ||
280 | 78, 77, 76, 73, 71, 69, 65, 59, 55, 53, 51, 48, 47, 46, 44, 40, 39, 35, 34, 30, 28, 27, 26, 18, 17, | ||
281 | 16, 13, 11, 8, 7, 6,122,110, 74, 70, 54, 50, 22, 14, 2,123,121,119,115,114,109,105,103,102,101, | ||
282 | 99, 95, 79, 75, 49, 45, 29, 25, 23, 21, 19, 15, 10, 9, 5, 3, 1,124,104, 20, 0,120,100, 24, 4 | ||
283 | }; | ||
284 | |||
285 | static const mpc_huffman mpc_huff_Q3 [7] ICONST_ATTR = { | ||
286 | {0xe000, 3, 7}, {0x8000, 4, 14}, {0x5000, 5, 22}, {0x2400, 6, 32}, | ||
287 | {0x0a00, 7, 41}, {0x0200, 8, 46}, {0x0000, 9, 48} | ||
288 | }; // 7 | ||
289 | static const mpc_int8_t mpc_sym_Q3 [49] ICONST_ATTR = { | ||
290 | 0, 17, 16, 1, 15,-16, -1, | ||
291 | 32, 31, 2, 14,-15,-32, 34, | ||
292 | 33, 47, 46, 18, 30,-14, -2, | ||
293 | -31,-17,-18, 49, 48, 63, 19, | ||
294 | 29, 3, 13,-13, -3,-30,-47, | ||
295 | -48,-33, 50, 62, 35, 45,-29, | ||
296 | -19,-46,-34, 51, 61,-45,-35 | ||
297 | }; | ||
298 | |||
299 | static const mpc_huffman mpc_huff_Q4 [8] ICONST_ATTR = { | ||
300 | {0xf000, 4, 15}, {0x9000, 5, 30}, {0x3400, 6, 48}, {0x1800, 7, 61}, | ||
301 | {0x0500, 8, 73}, {0x0100, 9, 78}, {0x0000, 10, 80}, {0x0000, 0, 90} | ||
302 | }; // 8 | ||
303 | static const mpc_int8_t mpc_sym_Q4 [91] ICONST_ATTR = { | ||
304 | 0, 32, 17, 16, 31, 2, 1, 15, 14,-15,-16, -1,-32, 49, 48, | ||
305 | 34, 33, 47, 46, 19, 18, 30, 29, 3, 13,-13,-14, -2, -3,-30, | ||
306 | -31,-17,-18,-47,-48,-33, 64, 50, 63, 62, 35, 45, 4, 12,-29, | ||
307 | -19,-46,-34,-64,-49, 66, 65, 79, 78, 51, 61, 36, 44, 20, 28, | ||
308 | -12, -4,-28,-20,-45,-35,-62,-63,-50, 67, 77, 52, 60,-44,-36, | ||
309 | -61,-51, 68, 76,-60,-52, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
310 | 0 | ||
311 | }; | ||
312 | |||
313 | static const mpc_huffman mpc_huff_Q5_1 [6] ICONST_ATTR = { | ||
314 | {0xc000, 2, 3}, {0x4000, 3, 6}, {0x2000, 4, 8}, | ||
315 | {0x1000, 5, 10}, {0x0800, 6, 12}, {0x0000, 7, 14} | ||
316 | }; // 6 | ||
317 | static const mpc_int8_t mpc_sym_Q5_1 [15] ICONST_ATTR = { | ||
318 | 0, 2, 1, -1, -2, 3, -3, 4, -4, 5, -5, 7, 6, -6, -7 | ||
319 | }; | ||
320 | static const mpc_huffman mpc_huff_Q5_2 [4] ICONST_ATTR = { | ||
321 | {0x6000, 3, 7}, {0x2000, 4, 10}, {0x1000, 5, 12}, {0x0, 6, 14} | ||
322 | }; // 4 | ||
323 | static const mpc_int8_t mpc_sym_Q5_2 [15] ICONST_ATTR = { | ||
324 | 2, 1, 0, -1, -2, 4, 3, -3, -4, 5, -5, 7, 6, -6, -7 | ||
325 | }; | ||
326 | |||
327 | static const mpc_huffman mpc_huff_Q6_1 [8] ICONST_ATTR = { | ||
328 | {0xc000, 2, 3}, {0x8000, 3, 6}, {0x4000, 4, 10}, {0x2800, 5, 14}, | ||
329 | {0x0c00, 6, 19}, {0x0800, 7, 22}, {0x0400, 8, 26}, {0x0000, 9, 30} | ||
330 | }; // 8 | ||
331 | static const mpc_int8_t mpc_sym_Q6_1 [31] ICONST_ATTR = { | ||
332 | 0, 1, -1, 3, 2, -2, -3, 4, -4, -5, 8, 7, 6, 5, -6, | ||
333 | -7, -8, 9, -9, 11, 10,-10,-11, 15, 14, 13, 12,-12,-13,-14, | ||
334 | -15 | ||
335 | }; | ||
336 | static const mpc_huffman mpc_huff_Q6_2 [5] ICONST_ATTR = { | ||
337 | {0x5000, 4, 15}, {0x2000, 5, 20}, {0x1000, 6, 24}, {0x400, 7, 28}, {0x0, 8, 30} | ||
338 | }; // 5 | ||
339 | static const mpc_int8_t mpc_sym_Q6_2 [31] ICONST_ATTR = { | ||
340 | 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, 8, 7, 6, -6, | ||
341 | -7, -8, 10, 9, -9,-10, 13, 12, 11,-11,-12,-13, 15, 14,-14, | ||
342 | -15 | ||
343 | }; | ||
344 | |||
345 | static const mpc_huffman mpc_huff_Q7_1 [9] ICONST_ATTR_MPC_LARGE_IRAM = { | ||
346 | {0xc000, 2, 3}, {0x8000, 3, 6}, {0x6000, 4, 10}, | ||
347 | {0x4000, 5, 16}, {0x2800, 6, 24}, {0x1400, 7, 34}, | ||
348 | {0x0a00, 8, 44}, {0x0400, 9, 54}, {0x0000, 10, 62} | ||
349 | }; // 9 | ||
350 | static const mpc_int8_t mpc_sym_Q7_1 [63] ICONST_ATTR_MPC_LARGE_IRAM = { | ||
351 | 0, 1, -1, 2, -2, 4, 3, -3, -4, 7, 6, 5, -5, -6, -7, | ||
352 | 13, 11, 10, 9, 8, -8, -9,-10,-11,-12, 17, 16, 15, 14, 12, | ||
353 | -13,-14,-15,-16,-17, 28, 27, 21, 20, 19, 18,-18,-19,-20,-21, | ||
354 | -27,-28, 31, 30, 29, 26, 25, 24, 23, 22,-22,-23,-24,-25,-26, | ||
355 | -29,-30,-31 | ||
356 | }; | ||
357 | static const mpc_huffman mpc_huff_Q7_2 [5] ICONST_ATTR_MPC_LARGE_IRAM = { | ||
358 | {0x6000, 5, 31}, {0x2400, 6, 43}, {0x1000, 7, 52}, {0x200, 8, 60}, {0x0, 9, 62} | ||
359 | }; // 5 | ||
360 | static const mpc_int8_t mpc_sym_Q7_2 [63] ICONST_ATTR_MPC_LARGE_IRAM = { | ||
361 | 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, | ||
362 | -5, -6, -7, -8, -9, 17, 16, 15, 14, 13, 12, 11,-10,-11,-12, | ||
363 | -13,-14,-15,-16,-17, 22, 21, 20, 19, 18,-18,-19,-20,-21,-22, | ||
364 | 29, 28, 27, 26, 25, 24, 23,-23,-24,-25,-26,-27,-28,-29, 31, | ||
365 | 30,-30,-31 | ||
366 | }; | ||
367 | |||
368 | static const mpc_huffman mpc_huff_Q8_1 [11] ICONST_ATTR_MPC_LARGE_IRAM = { | ||
369 | {0xc000, 2, 3}, {0x8000, 3, 6}, {0x7000, 4, 10}, {0x5800, 5, 17}, | ||
370 | {0x3800, 6, 28}, {0x2800, 7, 42}, {0x1900, 8, 62}, {0x0d00, 9, 87}, | ||
371 | {0x0280, 10,113}, {0x0060, 11,123}, {0x0000, 12,126} | ||
372 | }; // 11 | ||
373 | static const mpc_int8_t mpc_sym_Q8_1 [127] ICONST_ATTR_MPC_LARGE_IRAM = { | ||
374 | 0, 1, -1, -2, 3, 2, -3, 7, 6, 5, 4, -4, -5, -6, -7, 11, 10, 9, 8, -8, | ||
375 | -9,-10,-11, 19, 18, 17, 16, 15, 14, 13, 12,-12,-13,-14,-15,-16,-17,-19, 56, 55, | ||
376 | 31, 28, 27, 26, 25, 24, 23, 22, 21, 20,-18,-20,-21,-22,-23,-24,-25,-26,-27,-33, | ||
377 | -54,-56, 63, 62, 61, 60, 59, 58, 57, 54, 53, 43, 40, 39, 38, 37, 36, 35, 34, 33, | ||
378 | 32, 30, 29,-28,-29,-30,-31,-32,-34,-35,-36,-37,-38,-39,-40,-41,-43,-53,-55,-57, | ||
379 | -58,-59,-60,-61, 49, 47, 46, 45, 44, 42, 41,-42,-44,-45,-46,-47,-48,-49,-50,-62, | ||
380 | -63, 52, 51, 50, 48,-51,-52 | ||
381 | }; | ||
382 | static const mpc_huffman mpc_huff_Q8_2 [4] ICONST_ATTR_MPC_LARGE_IRAM = { | ||
383 | {0x9800, 6, 63}, {0x2a00, 7, 101}, {0x400, 8, 122}, {0x0, 9, 126} | ||
384 | }; // 4 | ||
385 | static const mpc_int8_t mpc_sym_Q8_2 [127] ICONST_ATTR_MPC_LARGE_IRAM = { | ||
386 | 13, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, | ||
387 | -8, -9,-10,-11,-12,-13, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, | ||
388 | 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 12,-14,-15,-16,-17,-18,-19,-20, | ||
389 | -21,-22,-23,-24,-25,-26,-27,-28,-29,-30,-31,-32,-33,-34,-35,-36,-37,-38,-39,-40, | ||
390 | -41, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, | ||
391 | 40,-42,-43,-44,-45,-46,-47,-48,-49,-50,-51,-52,-53,-54,-55,-56,-57,-58,-59, 63, | ||
392 | 62, 61, 60,-60,-61,-62,-63 | ||
393 | }; | ||
394 | |||
395 | static const mpc_huffman mpc_huff_Q9up [6] ICONST_ATTR_MPC_LARGE_IRAM = { | ||
396 | {0xf800, 6, 63}, {0xac00, 7,125}, {0x2600, 8, -45}, | ||
397 | {0x0280, 9, -7}, {0x0040, 10, -2}, {0x0000, 11, -1} | ||
398 | }; // 6 | ||
399 | static const mpc_int8_t mpc_sym_Q9up [256] ICONST_ATTR_MPC_LARGE_IRAM = { | ||
400 | -128, 127,-108,-110,-111,-112,-113,-114,-115,-116,-117,-118,-119,-120,-121,-122, | ||
401 | -123,-124,-125,-126,-127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, | ||
402 | 115, 114, 113, 112, 111, 110, 109, 108, -44, -45, -46, -47, -48, -49, -50, -51, | ||
403 | -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, | ||
404 | -68, -69, -70, -71, -72, -73, -74, -75, -76, -77, -78, -79, -80, -81, -82, -83, | ||
405 | -84, -85, -86, -87, -88, -89, -90, -91, -92, -93, -94, -95, -96, -97, -98, -99, | ||
406 | -100,-101,-102,-103,-104,-105,-106,-107,-109, 107, 106, 105, 104, 103, 102, 101, | ||
407 | 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, | ||
408 | 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, | ||
409 | 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, | ||
410 | 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 40, 20, 19, -7, -8, | ||
411 | -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20, -21, -22, -23, -24, | ||
412 | -25, -26, -27, -28, -29, -30, -31, -32, -33, -34, -35, -36, -37, -38, -39, -40, | ||
413 | -41, -42, -43, 41, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, | ||
414 | 27, 26, 25, 24, 23, 22, 21, 18, 17, 16, 15, 14, 13, 12, 11, 10, | ||
415 | 9, 8, 7, 6, 5, -3, -4, -5, -6, 4, 3, 2, 1, 0, -1, -2 | ||
416 | }; | ||
417 | |||
418 | /* sv7 lookup tables */ | ||
419 | mpc_lut_data mpc_HuffHdr IBSS_ATTR_MPC_LARGE_IRAM; | ||
420 | mpc_lut_data mpc_HuffDSCF IBSS_ATTR_MPC_LARGE_IRAM; | ||
421 | mpc_lut_data mpc_HuffQ [7] [2] IBSS_ATTR_MPC_LARGE_IRAM; | ||
422 | |||
423 | /* sv8 lookup tables */ | ||
424 | mpc_can_data mpc_can_SCFI[2] IBSS_ATTR_MPC_LARGE_IRAM; | ||
425 | mpc_can_data mpc_can_DSCF[2] IBSS_ATTR_MPC_LARGE_IRAM; | ||
426 | mpc_can_data mpc_can_Bands IBSS_ATTR_MPC_LARGE_IRAM; | ||
427 | mpc_can_data mpc_can_Res[2] IBSS_ATTR_MPC_LARGE_IRAM; | ||
428 | mpc_can_data mpc_can_Q1 IBSS_ATTR_MPC_LARGE_IRAM; | ||
429 | mpc_can_data mpc_can_Q9up IBSS_ATTR_MPC_LARGE_IRAM; | ||
430 | mpc_can_data mpc_can_Q [6][2] IBSS_ATTR_MPC_LARGE_IRAM; | ||
431 | |||
432 | static void huff_fill_lut(const mpc_huffman *table, mpc_huff_lut *lut, const int bits) | ||
433 | { | ||
434 | int i, idx = 0; | ||
435 | const int shift = 16 - bits; | ||
436 | for (i = (1 << bits) - 1; i >= 0 ; i--) { | ||
437 | if ((table[idx].Code >> shift) < i) { | ||
438 | lut[i].Length = table[idx].Length; | ||
439 | lut[i].Value = table[idx].Value; | ||
440 | } else { | ||
441 | if (table[idx].Length <= bits) { | ||
442 | lut[i].Length = table[idx].Length; | ||
443 | lut[i].Value = table[idx].Value; | ||
444 | } else { | ||
445 | lut[i].Length = 0; | ||
446 | lut[i].Value = idx; | ||
447 | } | ||
448 | if (i != 0) | ||
449 | do { | ||
450 | idx++; | ||
451 | } while ((table[idx].Code >> shift) == i); | ||
452 | } | ||
453 | } | ||
454 | } | ||
455 | |||
456 | static void can_fill_lut(mpc_can_data * data, const int bits) | ||
457 | { | ||
458 | int i, idx = 0; | ||
459 | const int shift = 16 - bits; | ||
460 | const mpc_huffman * table = data->table; | ||
461 | const mpc_int8_t * sym = data->sym; | ||
462 | mpc_huff_lut * lut = data->lut; | ||
463 | for (i = (1 << bits) - 1; i >= 0 ; i--) { | ||
464 | if ((table[idx].Code >> shift) < i) { | ||
465 | if (table[idx].Length <= bits) { | ||
466 | lut[i].Length = table[idx].Length; | ||
467 | lut[i].Value = sym[(table[idx].Value - (i >> (bits - table[idx].Length))) & 0xFF]; | ||
468 | } else { | ||
469 | lut[i].Length = 0; | ||
470 | lut[i].Value = idx; | ||
471 | } | ||
472 | } else { | ||
473 | if (table[idx].Length <= bits) { | ||
474 | lut[i].Length = table[idx].Length; | ||
475 | lut[i].Value = sym[(table[idx].Value - (i >> (bits - table[idx].Length))) & 0xFF]; | ||
476 | } else { | ||
477 | lut[i].Length = 0; | ||
478 | lut[i].Value = idx; | ||
479 | } | ||
480 | if (i != 0) | ||
481 | do { | ||
482 | idx++; | ||
483 | } while ((table[idx].Code >> shift) == i); | ||
484 | } | ||
485 | } | ||
486 | } | ||
487 | |||
488 | void huff_init_lut(const int bits) | ||
489 | { | ||
490 | /* sv7: create vlc lookup tables */ | ||
491 | mpc_HuffDSCF.table = mpc_table_HuffDSCF ; huff_fill_lut(mpc_HuffDSCF.table , mpc_HuffDSCF.lut , bits); | ||
492 | mpc_HuffHdr.table = mpc_table_HuffHdr ; huff_fill_lut(mpc_HuffHdr.table , mpc_HuffHdr.lut , bits); | ||
493 | mpc_HuffQ[0][0].table = mpc_table_HuffQ1[0]; huff_fill_lut(mpc_HuffQ[0][0].table, mpc_HuffQ[0][0].lut, bits); | ||
494 | mpc_HuffQ[0][1].table = mpc_table_HuffQ1[1]; huff_fill_lut(mpc_HuffQ[0][1].table, mpc_HuffQ[0][1].lut, bits); | ||
495 | mpc_HuffQ[1][0].table = mpc_table_HuffQ2[0]; huff_fill_lut(mpc_HuffQ[1][0].table, mpc_HuffQ[1][0].lut, bits); | ||
496 | mpc_HuffQ[1][1].table = mpc_table_HuffQ2[1]; huff_fill_lut(mpc_HuffQ[1][1].table, mpc_HuffQ[1][1].lut, bits); | ||
497 | mpc_HuffQ[2][0].table = mpc_table_HuffQ3[0]; huff_fill_lut(mpc_HuffQ[2][0].table, mpc_HuffQ[2][0].lut, bits); | ||
498 | mpc_HuffQ[2][1].table = mpc_table_HuffQ3[1]; huff_fill_lut(mpc_HuffQ[2][1].table, mpc_HuffQ[2][1].lut, bits); | ||
499 | mpc_HuffQ[3][0].table = mpc_table_HuffQ4[0]; huff_fill_lut(mpc_HuffQ[3][0].table, mpc_HuffQ[3][0].lut, bits); | ||
500 | mpc_HuffQ[3][1].table = mpc_table_HuffQ4[1]; huff_fill_lut(mpc_HuffQ[3][1].table, mpc_HuffQ[3][1].lut, bits); | ||
501 | mpc_HuffQ[4][0].table = mpc_table_HuffQ5[0]; huff_fill_lut(mpc_HuffQ[4][0].table, mpc_HuffQ[4][0].lut, bits); | ||
502 | mpc_HuffQ[4][1].table = mpc_table_HuffQ5[1]; huff_fill_lut(mpc_HuffQ[4][1].table, mpc_HuffQ[4][1].lut, bits); | ||
503 | mpc_HuffQ[5][0].table = mpc_table_HuffQ6[0]; huff_fill_lut(mpc_HuffQ[5][0].table, mpc_HuffQ[5][0].lut, bits); | ||
504 | mpc_HuffQ[5][1].table = mpc_table_HuffQ6[1]; huff_fill_lut(mpc_HuffQ[5][1].table, mpc_HuffQ[5][1].lut, bits); | ||
505 | mpc_HuffQ[6][0].table = mpc_table_HuffQ7[0]; huff_fill_lut(mpc_HuffQ[6][0].table, mpc_HuffQ[6][0].lut, bits); | ||
506 | mpc_HuffQ[6][1].table = mpc_table_HuffQ7[1]; huff_fill_lut(mpc_HuffQ[6][1].table, mpc_HuffQ[6][1].lut, bits); | ||
507 | |||
508 | /* sv8: create vlc lookup tables */ | ||
509 | mpc_can_Bands.table = mpc_huff_Bands ; mpc_can_Bands.sym = mpc_sym_Bands; | ||
510 | mpc_can_SCFI[0].table = mpc_huff_SCFI_1; mpc_can_SCFI[0].sym = mpc_sym_SCFI_1; can_fill_lut(&mpc_can_SCFI[0], bits); | ||
511 | mpc_can_SCFI[1].table = mpc_huff_SCFI_2; mpc_can_SCFI[1].sym = mpc_sym_SCFI_2; can_fill_lut(&mpc_can_SCFI[1], bits); | ||
512 | mpc_can_DSCF[0].table = mpc_huff_DSCF_1; mpc_can_DSCF[0].sym = mpc_sym_DSCF_1; can_fill_lut(&mpc_can_DSCF[0], bits); | ||
513 | mpc_can_DSCF[1].table = mpc_huff_DSCF_2; mpc_can_DSCF[1].sym = mpc_sym_DSCF_2; can_fill_lut(&mpc_can_DSCF[1], bits); | ||
514 | mpc_can_Res[0].table = mpc_huff_Res_1 ; mpc_can_Res[0].sym = mpc_sym_Res_1 ; can_fill_lut(&mpc_can_Res[0] , bits); | ||
515 | mpc_can_Res[1].table = mpc_huff_Res_2 ; mpc_can_Res[1].sym = mpc_sym_Res_2 ; can_fill_lut(&mpc_can_Res[1] , bits); | ||
516 | mpc_can_Q1.table = mpc_huff_Q1 ; mpc_can_Q1.sym = mpc_sym_Q1 ; can_fill_lut(&mpc_can_Q1 , bits); | ||
517 | mpc_can_Q9up.table = mpc_huff_Q9up ; mpc_can_Q9up.sym = mpc_sym_Q9up ; can_fill_lut(&mpc_can_Q9up , bits); | ||
518 | mpc_can_Q[0][0].table = mpc_huff_Q2_1 ; mpc_can_Q[0][0].sym = mpc_sym_Q2_1 ; can_fill_lut(&mpc_can_Q[0][0], bits); | ||
519 | mpc_can_Q[0][1].table = mpc_huff_Q2_2 ; mpc_can_Q[0][1].sym = mpc_sym_Q2_2 ; can_fill_lut(&mpc_can_Q[0][1], bits); | ||
520 | mpc_can_Q[1][0].table = mpc_huff_Q3 ; mpc_can_Q[1][0].sym = mpc_sym_Q3 ; can_fill_lut(&mpc_can_Q[1][0], bits); | ||
521 | mpc_can_Q[1][1].table = mpc_huff_Q4 ; mpc_can_Q[1][1].sym = mpc_sym_Q4 ; can_fill_lut(&mpc_can_Q[1][1], bits); | ||
522 | mpc_can_Q[2][0].table = mpc_huff_Q5_1 ; mpc_can_Q[2][0].sym = mpc_sym_Q5_1 ; can_fill_lut(&mpc_can_Q[2][0], bits); | ||
523 | mpc_can_Q[2][1].table = mpc_huff_Q5_2 ; mpc_can_Q[2][1].sym = mpc_sym_Q5_2 ; can_fill_lut(&mpc_can_Q[2][1], bits); | ||
524 | mpc_can_Q[3][0].table = mpc_huff_Q6_1 ; mpc_can_Q[3][0].sym = mpc_sym_Q6_1 ; can_fill_lut(&mpc_can_Q[3][0], bits); | ||
525 | mpc_can_Q[3][1].table = mpc_huff_Q6_2 ; mpc_can_Q[3][1].sym = mpc_sym_Q6_2 ; can_fill_lut(&mpc_can_Q[3][1], bits); | ||
526 | mpc_can_Q[4][0].table = mpc_huff_Q7_1 ; mpc_can_Q[4][0].sym = mpc_sym_Q7_1 ; can_fill_lut(&mpc_can_Q[4][0], bits); | ||
527 | mpc_can_Q[4][1].table = mpc_huff_Q7_2 ; mpc_can_Q[4][1].sym = mpc_sym_Q7_2 ; can_fill_lut(&mpc_can_Q[4][1], bits); | ||
528 | mpc_can_Q[5][0].table = mpc_huff_Q8_1 ; mpc_can_Q[5][0].sym = mpc_sym_Q8_1 ; can_fill_lut(&mpc_can_Q[5][0], bits); | ||
529 | mpc_can_Q[5][1].table = mpc_huff_Q8_2 ; mpc_can_Q[5][1].sym = mpc_sym_Q8_2 ; can_fill_lut(&mpc_can_Q[5][1], bits); | ||
530 | } | ||
diff --git a/lib/rbcodec/codecs/libmusepack/huffman.h b/lib/rbcodec/codecs/libmusepack/huffman.h new file mode 100644 index 0000000000..1244149184 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/huffman.h | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | /// \file huffman.h | ||
35 | /// Data structures and functions for huffman coding. | ||
36 | |||
37 | #ifndef _MPCDEC_HUFFMAN_H_ | ||
38 | #define _MPCDEC_HUFFMAN_H_ | ||
39 | #ifdef WIN32 | ||
40 | #pragma once | ||
41 | #endif | ||
42 | |||
43 | #include "mpc_types.h" | ||
44 | |||
45 | #ifdef __cplusplus | ||
46 | extern "C" { | ||
47 | #endif | ||
48 | |||
49 | // LUT size parameter, LUT size is 1 << LUT_DEPTH | ||
50 | #define LUT_DEPTH 6 | ||
51 | |||
52 | /// Huffman table entry. | ||
53 | typedef struct mpc_huffman_t { | ||
54 | mpc_uint16_t Code; | ||
55 | mpc_uint8_t Length; | ||
56 | mpc_int8_t Value; | ||
57 | } mpc_huffman; | ||
58 | |||
59 | /// Huffman LUT entry. | ||
60 | typedef struct mpc_huff_lut_t { | ||
61 | mpc_uint8_t Length; | ||
62 | mpc_int8_t Value; | ||
63 | } mpc_huff_lut; | ||
64 | |||
65 | /// Type used for huffman LUT decoding | ||
66 | typedef struct mpc_lut_data_t { | ||
67 | mpc_huffman const *table; | ||
68 | mpc_huff_lut lut[1 << LUT_DEPTH]; | ||
69 | } mpc_lut_data; | ||
70 | |||
71 | /// Type used for canonical huffman decoding | ||
72 | typedef struct mpc_can_data_t { | ||
73 | mpc_huffman const *table; | ||
74 | mpc_int8_t const *sym; | ||
75 | mpc_huff_lut lut[1 << LUT_DEPTH]; | ||
76 | } mpc_can_data; | ||
77 | |||
78 | void huff_init_lut(const int bits); | ||
79 | |||
80 | #ifdef __cplusplus | ||
81 | } | ||
82 | #endif | ||
83 | #endif | ||
diff --git a/lib/rbcodec/codecs/libmusepack/internal.h b/lib/rbcodec/codecs/libmusepack/internal.h new file mode 100644 index 0000000000..897e6a7b17 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/internal.h | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | /// \file internal.h | ||
35 | /// Definitions and structures used only internally by the libmpcdec. | ||
36 | #ifndef _MPCDEC_INTERNAL_H_ | ||
37 | #define _MPCDEC_INTERNAL_H_ | ||
38 | #ifdef WIN32 | ||
39 | #pragma once | ||
40 | #endif | ||
41 | #ifdef __cplusplus | ||
42 | extern "C" { | ||
43 | #endif | ||
44 | |||
45 | #include "mpcdec.h" | ||
46 | |||
47 | /* rockbox: not used, rockbox's swap32 is used now. | ||
48 | /// Big/little endian 32 bit byte swapping routine. | ||
49 | static mpc_inline | ||
50 | mpc_uint32_t mpc_swap32(mpc_uint32_t val) { | ||
51 | return (((val & 0xFF000000) >> 24) | ((val & 0x00FF0000) >> 8) | ||
52 | | ((val & 0x0000FF00) << 8) | ((val & 0x000000FF) << 24)); | ||
53 | } | ||
54 | */ | ||
55 | typedef struct mpc_block_t { | ||
56 | char key[2]; // block key | ||
57 | mpc_uint64_t size; // block size minus the block header size | ||
58 | } mpc_block; | ||
59 | |||
60 | #define MAX_FRAME_SIZE 4352 | ||
61 | #define DEMUX_BUFFER_SIZE (32768 - MAX_FRAME_SIZE) // need some space as sand box | ||
62 | |||
63 | struct mpc_demux_t { | ||
64 | mpc_reader * r; | ||
65 | mpc_decoder * d; | ||
66 | mpc_streaminfo si; | ||
67 | |||
68 | // buffer | ||
69 | mpc_uint8_t *buffer; | ||
70 | mpc_size_t bytes_total; | ||
71 | mpc_bits_reader bits_reader; | ||
72 | mpc_int32_t block_bits; /// bits remaining in current audio block | ||
73 | mpc_uint_t block_frames; /// frames remaining in current audio block | ||
74 | |||
75 | // seeking | ||
76 | mpc_seek_t * seek_table; | ||
77 | mpc_uint_t seek_pwr; /// distance between 2 frames in seek_table = 2^seek_pwr | ||
78 | mpc_uint32_t seek_table_size; /// used size in seek_table | ||
79 | |||
80 | // chapters | ||
81 | /* rockbox: not used | ||
82 | mpc_seek_t chap_pos; /// supposed position of the first chapter block | ||
83 | mpc_int_t chap_nb; /// number of chapters (-1 if unknown, 0 if no chapter) | ||
84 | mpc_chap_info * chap; /// chapters position and tag | ||
85 | */ | ||
86 | }; | ||
87 | |||
88 | /** | ||
89 | * checks if a block key is valid | ||
90 | * @param key the two caracters key to check | ||
91 | * @return MPC_STATUS_FAIL if the key is invalid, MPC_STATUS_OK else | ||
92 | */ | ||
93 | static mpc_inline mpc_status mpc_check_key(char * key) | ||
94 | { | ||
95 | if (key[0] < 65 || key[0] > 90 || key[1] < 65 || key[1] > 90) | ||
96 | return MPC_STATUS_FAIL; | ||
97 | return MPC_STATUS_OK; | ||
98 | } | ||
99 | |||
100 | /// helper functions used by multiple files | ||
101 | mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c | ||
102 | void mpc_decoder_init_quant(mpc_decoder *d, MPC_SAMPLE_FORMAT factor); // in requant.c | ||
103 | void mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData, mpc_int_t channels); | ||
104 | unsigned long mpc_crc32(unsigned char *buf, int len); | ||
105 | |||
106 | // streaminfo.c | ||
107 | mpc_status streaminfo_read_header_sv8(mpc_streaminfo* si, | ||
108 | const mpc_bits_reader * r_in, | ||
109 | mpc_size_t block_size); | ||
110 | mpc_status streaminfo_read_header_sv7(mpc_streaminfo* si, mpc_bits_reader * r_in); | ||
111 | void streaminfo_encoder_info(mpc_streaminfo* si, const mpc_bits_reader * r_in); | ||
112 | void streaminfo_gain(mpc_streaminfo* si, const mpc_bits_reader * r_in); | ||
113 | |||
114 | // mpc_decoder.c | ||
115 | void mpc_decoder_reset_scf(mpc_decoder * d, int value); | ||
116 | |||
117 | #define MPC_IS_FAILURE(X) ((int)(X) < (int)MPC_STATUS_OK) | ||
118 | #define MPC_AUTO_FAIL(X) { mpc_status s = (X); if (MPC_IS_FAILURE(s)) return s; } | ||
119 | |||
120 | #ifdef __cplusplus | ||
121 | } | ||
122 | #endif | ||
123 | #endif | ||
diff --git a/lib/rbcodec/codecs/libmusepack/libmusepack.make b/lib/rbcodec/codecs/libmusepack/libmusepack.make new file mode 100644 index 0000000000..53b07869bf --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/libmusepack.make | |||
@@ -0,0 +1,18 @@ | |||
1 | # __________ __ ___. | ||
2 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
3 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
4 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
5 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
6 | # \/ \/ \/ \/ \/ | ||
7 | # $Id$ | ||
8 | # | ||
9 | |||
10 | # libmusepack | ||
11 | MUSEPACKLIB := $(CODECDIR)/libmusepack.a | ||
12 | MUSEPACKLIB_SRC := $(call preprocess, $(RBCODECLIB_DIR)/codecs/libmusepack/SOURCES) | ||
13 | MUSEPACKLIB_OBJ := $(call c2obj, $(MUSEPACKLIB_SRC)) | ||
14 | OTHER_SRC += $(MUSEPACKLIB_SRC) | ||
15 | |||
16 | $(MUSEPACKLIB): $(MUSEPACKLIB_OBJ) | ||
17 | $(SILENT)$(shell rm -f $@) | ||
18 | $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null | ||
diff --git a/lib/rbcodec/codecs/libmusepack/minimax.h b/lib/rbcodec/codecs/libmusepack/minimax.h new file mode 100644 index 0000000000..1192626567 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/minimax.h | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * Musepack audio compression | ||
3 | * Copyright (C) 1999-2004 Buschmann/Klemm/Piecha/Wolf | ||
4 | * | ||
5 | * This library is free software; you can redistribute it and/or | ||
6 | * modify it under the terms of the GNU Lesser General Public | ||
7 | * License as published by the Free Software Foundation; either | ||
8 | * version 2.1 of the License, or (at your option) any later version. | ||
9 | * | ||
10 | * This library is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | * Lesser General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Lesser General Public | ||
16 | * License along with this library; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | # define clip(x,min,max) ( (x) < (min) ? (min) : (x) > (max) ? (max) : (x) ) | ||
23 | |||
24 | #ifdef __cplusplus | ||
25 | |||
26 | # define maxi(A,B) ( (A) >? (B) ) | ||
27 | # define mini(A,B) ( (A) <? (B) ) | ||
28 | # define maxd(A,B) ( (A) >? (B) ) | ||
29 | # define mind(A,B) ( (A) <? (B) ) | ||
30 | # define maxf(A,B) ( (A) >? (B) ) | ||
31 | # define minf(A,B) ( (A) <? (B) ) | ||
32 | |||
33 | #else | ||
34 | |||
35 | # define maxi(A,B) ( (A) > (B) ? (A) : (B) ) | ||
36 | # define mini(A,B) ( (A) < (B) ? (A) : (B) ) | ||
37 | # define maxd(A,B) ( (A) > (B) ? (A) : (B) ) | ||
38 | # define mind(A,B) ( (A) < (B) ? (A) : (B) ) | ||
39 | # define maxf(A,B) ( (A) > (B) ? (A) : (B) ) | ||
40 | # define minf(A,B) ( (A) < (B) ? (A) : (B) ) | ||
41 | |||
42 | #endif | ||
43 | |||
44 | #ifdef __GNUC__ | ||
45 | |||
46 | # define absi(A) abs (A) | ||
47 | # define absf(A) fabsf (A) | ||
48 | # define absd(A) fabs (A) | ||
49 | |||
50 | #else | ||
51 | |||
52 | # define absi(A) ( (A) >= 0 ? (A) : -(A) ) | ||
53 | # define absf(A) ( (A) >= 0.f ? (A) : -(A) ) | ||
54 | # define absd(A) ( (A) >= 0. ? (A) : -(A) ) | ||
55 | |||
56 | #endif | ||
57 | |||
diff --git a/lib/rbcodec/codecs/libmusepack/mpc_bits_reader.c b/lib/rbcodec/codecs/libmusepack/mpc_bits_reader.c new file mode 100644 index 0000000000..c917ad510a --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/mpc_bits_reader.c | |||
@@ -0,0 +1,181 @@ | |||
1 | /* | ||
2 | Copyright (c) 2007-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | #include "mpcdec.h" | ||
36 | #include "internal.h" | ||
37 | #include "huffman.h" | ||
38 | #include "mpc_bits_reader.h" | ||
39 | |||
40 | const mpc_uint32_t Cnk[MAX_ENUM / 2][MAX_ENUM] ICONST_ATTR_MPC_BITSREADER = | ||
41 | { | ||
42 | {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, | ||
43 | {0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465}, | ||
44 | {0, 0, 0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 364, 455, 560, 680, 816, 969, 1140, 1330, 1540, 1771, 2024, 2300, 2600, 2925, 3276, 3654, 4060, 4495}, | ||
45 | {0, 0, 0, 0, 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 8855, 10626, 12650, 14950, 17550, 20475, 23751, 27405, 31465}, | ||
46 | {0, 0, 0, 0, 0, 1, 6, 21, 56, 126, 252, 462, 792, 1287, 2002, 3003, 4368, 6188, 8568, 11628, 15504, 20349, 26334, 33649, 42504, 53130, 65780, 80730, 98280, 118755, 142506, 169911}, | ||
47 | {0, 0, 0, 0, 0, 0, 1, 7, 28, 84, 210, 462, 924, 1716, 3003, 5005, 8008, 12376, 18564, 27132, 38760, 54264, 74613, 100947, 134596, 177100, 230230, 296010, 376740, 475020, 593775, 736281}, | ||
48 | {0, 0, 0, 0, 0, 0, 0, 1, 8, 36, 120, 330, 792, 1716, 3432, 6435, 11440, 19448, 31824, 50388, 77520, 116280, 170544, 245157, 346104, 480700, 657800, 888030, 1184040, 1560780, 2035800, 2629575}, | ||
49 | {0, 0, 0, 0, 0, 0, 0, 0, 1, 9, 45, 165, 495, 1287, 3003, 6435, 12870, 24310, 43758, 75582, 125970, 203490, 319770, 490314, 735471, 1081575, 1562275, 2220075, 3108105, 4292145, 5852925, 7888725}, | ||
50 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 10, 55, 220, 715, 2002, 5005, 11440, 24310, 48620, 92378, 167960, 293930, 497420, 817190, 1307504, 2042975, 3124550, 4686825, 6906900, 10015005, 14307150, 20160075}, | ||
51 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 11, 66, 286, 1001, 3003, 8008, 19448, 43758, 92378, 184756, 352716, 646646, 1144066, 1961256, 3268760, 5311735, 8436285, 13123110, 20030010, 30045015, 44352165}, | ||
52 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 12, 78, 364, 1365, 4368, 12376, 31824, 75582, 167960, 352716, 705432, 1352078, 2496144, 4457400, 7726160, 13037895, 21474180, 34597290, 54627300, 84672315}, | ||
53 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 13, 91, 455, 1820, 6188, 18564, 50388, 125970, 293930, 646646, 1352078, 2704156, 5200300, 9657700, 17383860, 30421755, 51895935, 86493225, 141120525}, | ||
54 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 14, 105, 560, 2380, 8568, 27132, 77520, 203490, 497420, 1144066, 2496144, 5200300, 10400600, 20058300, 37442160, 67863915, 119759850, 206253075}, | ||
55 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 15, 120, 680, 3060, 11628, 38760, 116280, 319770, 817190, 1961256, 4457400, 9657700, 20058300, 40116600, 77558760, 145422675, 265182525}, | ||
56 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 16, 136, 816, 3876, 15504, 54264, 170544, 490314, 1307504, 3268760, 7726160, 17383860, 37442160, 77558760, 155117520, 300540195}, | ||
57 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 17, 153, 969, 4845, 20349, 74613, 245157, 735471, 2042975, 5311735, 13037895, 30421755, 67863915, 145422675, 300540195} | ||
58 | }; | ||
59 | |||
60 | const mpc_uint8_t Cnk_len[MAX_ENUM / 2][MAX_ENUM] ICONST_ATTR_MPC_BITSREADER = | ||
61 | { | ||
62 | {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, | ||
63 | {0, 0, 2, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9}, | ||
64 | {0, 0, 0, 2, 4, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13}, | ||
65 | {0, 0, 0, 0, 3, 4, 6, 7, 7, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16}, | ||
66 | {0, 0, 0, 0, 0, 3, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18}, | ||
67 | {0, 0, 0, 0, 0, 0, 3, 5, 7, 8, 9, 10, 11, 12, 13, 13, 14, 15, 15, 16, 16, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20}, | ||
68 | {0, 0, 0, 0, 0, 0, 0, 3, 6, 7, 9, 10, 11, 12, 13, 14, 15, 15, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 21, 22, 22}, | ||
69 | {0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 8, 9, 11, 12, 13, 14, 15, 16, 17, 17, 18, 19, 19, 20, 21, 21, 22, 22, 23, 23, 23, 24}, | ||
70 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 8, 10, 11, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 21, 22, 23, 23, 24, 24, 25, 25}, | ||
71 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 9, 10, 12, 13, 15, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 24, 25, 25, 26, 26}, | ||
72 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 9, 11, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 23, 24, 25, 26, 26, 27, 27}, | ||
73 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 9, 11, 13, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 25, 26, 27, 28, 28}, | ||
74 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 10, 12, 14, 15, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 27, 28, 29}, | ||
75 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 10, 12, 14, 16, 17, 19, 20, 21, 23, 24, 25, 26, 27, 28, 28, 29}, | ||
76 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 10, 12, 14, 16, 18, 19, 21, 22, 23, 25, 26, 27, 28, 29, 30}, | ||
77 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 10, 13, 15, 17, 18, 20, 21, 23, 24, 25, 27, 28, 29, 30} | ||
78 | |||
79 | }; | ||
80 | |||
81 | const mpc_uint32_t Cnk_lost[MAX_ENUM / 2][MAX_ENUM] ICONST_ATTR_MPC_BITSREADER = | ||
82 | { | ||
83 | {0, 0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, | ||
84 | {0, 0, 1, 2, 6, 1, 11, 4, 28, 19, 9, 62, 50, 37, 23, 8, 120, 103, 85, 66, 46, 25, 3, 236, 212, 187, 161, 134, 106, 77, 47, 16}, | ||
85 | {0, 0, 0, 0, 6, 12, 29, 8, 44, 8, 91, 36, 226, 148, 57, 464, 344, 208, 55, 908, 718, 508, 277, 24, 1796, 1496, 1171, 820, 442, 36, 3697, 3232}, | ||
86 | {0, 0, 0, 0, 3, 1, 29, 58, 2, 46, 182, 17, 309, 23, 683, 228, 1716, 1036, 220, 3347, 2207, 877, 7529, 5758, 3734, 1434, 15218, 12293, 9017, 5363, 1303, 29576}, | ||
87 | {0, 0, 0, 0, 0, 2, 11, 8, 2, 4, 50, 232, 761, 46, 1093, 3824, 2004, 7816, 4756, 880, 12419, 6434, 31887, 23032, 12406, 65292, 50342, 32792, 12317, 119638, 92233, 60768}, | ||
88 | {0, 0, 0, 0, 0, 0, 1, 4, 44, 46, 50, 100, 332, 1093, 3187, 184, 4008, 14204, 5636, 26776, 11272, 56459, 30125, 127548, 85044, 31914, 228278, 147548, 49268, 454801, 312295, 142384}, | ||
89 | {0, 0, 0, 0, 0, 0, 0, 0, 28, 8, 182, 232, 332, 664, 1757, 4944, 13320, 944, 15148, 53552, 14792, 91600, 16987, 178184, 43588, 390776, 160546, 913112, 536372, 61352, 1564729, 828448}, | ||
90 | {0, 0, 0, 0, 0, 0, 0, 0, 7, 19, 91, 17, 761, 1093, 1757, 3514, 8458, 21778, 55490, 5102, 58654, 204518, 33974, 313105, 1015577, 534877, 1974229, 1086199, 4096463, 2535683, 499883, 6258916}, | ||
91 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 9, 36, 309, 46, 3187, 4944, 8458, 16916, 38694, 94184, 230358, 26868, 231386, 789648, 54177, 1069754, 3701783, 1481708, 6762211, 2470066, 13394357, 5505632}, | ||
92 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 62, 226, 23, 1093, 184, 13320, 21778, 38694, 77388, 171572, 401930, 953086, 135896, 925544, 3076873, 8340931, 3654106, 13524422, 3509417, 22756699, 2596624}, | ||
93 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 50, 148, 683, 3824, 4008, 944, 55490, 94184, 171572, 343144, 745074, 1698160, 3931208, 662448, 3739321, 12080252, 32511574, 12481564, 49545413, 5193248}, | ||
94 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 37, 57, 228, 2004, 14204, 15148, 5102, 230358, 401930, 745074, 1490148, 3188308, 7119516, 16170572, 3132677, 15212929, 47724503, 127314931, 42642616}, | ||
95 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 23, 464, 1716, 7816, 5636, 53552, 58654, 26868, 953086, 1698160, 3188308, 6376616, 13496132, 29666704, 66353813, 14457878, 62182381, 189497312}, | ||
96 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 8, 344, 1036, 4756, 26776, 14792, 204518, 231386, 135896, 3931208, 7119516, 13496132, 26992264, 56658968, 123012781, 3252931, 65435312}, | ||
97 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 208, 220, 880, 11272, 91600, 33974, 789648, 925544, 662448, 16170572, 29666704, 56658968, 113317936, 236330717, 508019104}, | ||
98 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 103, 55, 3347, 12419, 56459, 16987, 313105, 54177, 3076873, 3739321, 3132677, 66353813, 123012781, 236330717} | ||
99 | }; | ||
100 | |||
101 | static const mpc_uint8_t log2[32] ICONST_ATTR_MPC_BITSREADER = | ||
102 | { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6}; | ||
103 | |||
104 | static const mpc_uint8_t log2_lost[32] ICONST_ATTR_MPC_BITSREADER = | ||
105 | { 0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31}; | ||
106 | |||
107 | mpc_int32_t mpc_bits_golomb_dec(mpc_bits_reader * r, const mpc_uint_t k) | ||
108 | { | ||
109 | unsigned int l = 0; | ||
110 | unsigned int code = r->buff[0] & ((1 << r->count) - 1); | ||
111 | |||
112 | while( code == 0 ) { | ||
113 | l += r->count; | ||
114 | r->buff++; | ||
115 | code = r->buff[0]; | ||
116 | r->count = 8; | ||
117 | } | ||
118 | |||
119 | while( ((1 << (r->count - 1)) & code) == 0 ) { | ||
120 | l++; | ||
121 | r->count--; | ||
122 | } | ||
123 | r->count--; | ||
124 | |||
125 | while( r->count < k ) { | ||
126 | r->buff++; | ||
127 | r->count += 8; | ||
128 | code = (code << 8) | r->buff[0]; | ||
129 | } | ||
130 | |||
131 | r->count -= k; | ||
132 | |||
133 | return (l << k) | ((code >> r->count) & ((1 << k) - 1)); | ||
134 | } | ||
135 | |||
136 | mpc_uint32_t mpc_bits_log_dec(mpc_bits_reader * r, mpc_uint_t max) | ||
137 | { | ||
138 | mpc_uint32_t value = 0; | ||
139 | if (max == 0) | ||
140 | return 0; | ||
141 | if (log2[max - 1] > 1) | ||
142 | value = mpc_bits_read(r, log2[max - 1] - 1); | ||
143 | if (value >= log2_lost[max - 1]) | ||
144 | value = ((value << 1) | mpc_bits_read(r, 1)) - log2_lost[max - 1]; | ||
145 | return value; | ||
146 | } | ||
147 | |||
148 | unsigned int mpc_bits_get_size(mpc_bits_reader * r, mpc_uint64_t * p_size) | ||
149 | { | ||
150 | unsigned char tmp; | ||
151 | mpc_uint64_t size = 0; | ||
152 | unsigned int ret = 0; | ||
153 | |||
154 | do { | ||
155 | tmp = mpc_bits_read(r, 8); | ||
156 | size = (size << 7) | (tmp & 0x7F); | ||
157 | ret++; | ||
158 | } while((tmp & 0x80)); | ||
159 | |||
160 | *p_size = size; | ||
161 | return ret; | ||
162 | } | ||
163 | |||
164 | int mpc_bits_get_block(mpc_bits_reader * r, mpc_block * p_block) | ||
165 | { | ||
166 | int size = 2; | ||
167 | |||
168 | p_block->size = 0; | ||
169 | p_block->key[0] = mpc_bits_read(r, 8); | ||
170 | p_block->key[1] = mpc_bits_read(r, 8); | ||
171 | |||
172 | size += mpc_bits_get_size(r, &(p_block->size)); | ||
173 | |||
174 | if (p_block->size >= (mpc_uint64_t)size) // check if the block size doesn't conflict with the header size | ||
175 | p_block->size -= (mpc_uint64_t)size; | ||
176 | |||
177 | return size; | ||
178 | } | ||
179 | |||
180 | |||
181 | |||
diff --git a/lib/rbcodec/codecs/libmusepack/mpc_bits_reader.h b/lib/rbcodec/codecs/libmusepack/mpc_bits_reader.h new file mode 100644 index 0000000000..1233720c74 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/mpc_bits_reader.h | |||
@@ -0,0 +1,175 @@ | |||
1 | /* | ||
2 | Copyright (c) 2007-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | #define MAX_ENUM 32 | ||
36 | |||
37 | MPC_API int mpc_bits_get_block(mpc_bits_reader * r, mpc_block * p_block); | ||
38 | mpc_int32_t mpc_bits_golomb_dec(mpc_bits_reader * r, const mpc_uint_t k); | ||
39 | MPC_API unsigned int mpc_bits_get_size(mpc_bits_reader * r, mpc_uint64_t * p_size); | ||
40 | mpc_uint32_t mpc_bits_log_dec(mpc_bits_reader * r, mpc_uint_t max); | ||
41 | |||
42 | extern const mpc_uint32_t Cnk [MAX_ENUM / 2][MAX_ENUM]; | ||
43 | extern const mpc_uint8_t Cnk_len [MAX_ENUM / 2][MAX_ENUM]; | ||
44 | extern const mpc_uint32_t Cnk_lost[MAX_ENUM / 2][MAX_ENUM]; | ||
45 | |||
46 | // can read up to 31 bits | ||
47 | static mpc_inline mpc_uint32_t mpc_bits_read(mpc_bits_reader * r, const unsigned int nb_bits) | ||
48 | { | ||
49 | mpc_uint32_t ret; | ||
50 | |||
51 | r->buff -= (int)(r->count - nb_bits) >> 3; | ||
52 | r->count = (r->count - nb_bits) & 0x07; | ||
53 | |||
54 | ret = (r->buff[0] | (r->buff[-1] << 8)) >> r->count; | ||
55 | if (nb_bits > (16 - r->count)) { | ||
56 | ret |= (mpc_uint32_t)((r->buff[-2] << 16) | (r->buff[-3] << 24)) >> r->count; | ||
57 | if (nb_bits > 24 && r->count != 0) | ||
58 | ret |= r->buff[-4] << (32 - r->count); | ||
59 | } | ||
60 | |||
61 | return ret & ((1 << nb_bits) - 1); | ||
62 | } | ||
63 | |||
64 | #if defined(CPU_COLDFIRE) | ||
65 | /* rockbox: This is specific code to optimize demux performance on Coldfire | ||
66 | * CPUs. Coldfire CPUs are very sensible to RAM accesses. As the bitstream | ||
67 | * buffer does not fit into IRAM the read accesses to the uint8 buffer are very | ||
68 | * expensive in terms of CPU cycles. | ||
69 | * The following code uses two variables in IRAM. The variable last_code keeps | ||
70 | * the 4-byte value of buf[0]<<16 | buf[1]<<8 | buf[2]. As long as buf[0] will | ||
71 | * read from the same address the following code will avoid re-reading of the | ||
72 | * buffers. If buf[0] did advance to the next uint8-entry since the last call | ||
73 | * the following will only need to load 1 uint8-entry instead of 3. | ||
74 | */ | ||
75 | static mpc_inline mpc_uint16_t get_code_from_buffer(mpc_bits_reader *r) | ||
76 | { | ||
77 | /* Buffer advanced by 1 entry since last call */ | ||
78 | if (r->buff == r->buffered_addr + 1) { | ||
79 | r->buffered_code = (r->buffered_code<<8) | r->buff[2]; | ||
80 | r->buffered_addr = r->buff; | ||
81 | } | ||
82 | /* Buffer must be fully re-read */ | ||
83 | else if (r->buff != r->buffered_addr) { | ||
84 | r->buffered_code = (r->buff[0] << 16) | (r->buff[1] << 8) | r->buff[2]; | ||
85 | r->buffered_addr = r->buff; | ||
86 | } | ||
87 | |||
88 | return (mpc_uint16_t)((r->buffered_code >> r->count) & 0xFFFF); | ||
89 | } | ||
90 | #else | ||
91 | /* Use the decoder's default implementation. This is faster on non-Coldfire targets */ | ||
92 | #define get_code_from_buffer(r) (mpc_uint16_t)((((r->buff[0] << 16) | (r->buff[1] << 8) | r->buff[2]) >> r->count) & 0xFFFF); | ||
93 | #endif | ||
94 | |||
95 | // basic huffman decoding routine | ||
96 | // works with maximum lengths up to 16 | ||
97 | static mpc_inline mpc_int32_t mpc_bits_huff_dec(mpc_bits_reader * r, const mpc_huffman *Table) | ||
98 | { | ||
99 | const mpc_uint16_t code = get_code_from_buffer(r); | ||
100 | |||
101 | while (code < Table->Code) Table++; | ||
102 | |||
103 | r->buff -= (int)(r->count - Table->Length) >> 3; | ||
104 | r->count = (r->count - Table->Length) & 0x07; | ||
105 | |||
106 | return Table->Value; | ||
107 | } | ||
108 | |||
109 | static mpc_inline mpc_int32_t mpc_bits_can_dec(mpc_bits_reader * r, const mpc_can_data *can) | ||
110 | { | ||
111 | const mpc_uint16_t code = get_code_from_buffer(r); | ||
112 | const mpc_huff_lut tmp = can->lut[code >> (16 - LUT_DEPTH)]; | ||
113 | const mpc_huffman * Table; | ||
114 | |||
115 | if (tmp.Length != 0) { | ||
116 | r->buff -= (int)(r->count - tmp.Length) >> 3; | ||
117 | r->count = (r->count - tmp.Length) & 0x07; | ||
118 | return tmp.Value; | ||
119 | } | ||
120 | |||
121 | Table = can->table + (unsigned char)tmp.Value; | ||
122 | while (code < Table->Code) Table++; | ||
123 | |||
124 | r->buff -= (int)(r->count - Table->Length) >> 3; | ||
125 | r->count = (r->count - Table->Length) & 0x07; | ||
126 | |||
127 | return can->sym[(Table->Value - (code >> (16 - Table->Length))) & 0xFF] ; | ||
128 | } | ||
129 | |||
130 | // LUT-based huffman decoding routine | ||
131 | // works with maximum lengths up to 16 | ||
132 | static mpc_inline mpc_int32_t mpc_bits_huff_lut(mpc_bits_reader * r, const mpc_lut_data *lut) | ||
133 | { | ||
134 | const mpc_uint16_t code = get_code_from_buffer(r); | ||
135 | const mpc_huff_lut tmp = lut->lut[code >> (16 - LUT_DEPTH)]; | ||
136 | const mpc_huffman * Table; | ||
137 | |||
138 | if (tmp.Length != 0) { | ||
139 | r->buff -= (int)(r->count - tmp.Length) >> 3; | ||
140 | r->count = (r->count - tmp.Length) & 0x07; | ||
141 | return tmp.Value; | ||
142 | } | ||
143 | |||
144 | Table = lut->table + (unsigned char)tmp.Value; | ||
145 | while (code < Table->Code) Table++; | ||
146 | |||
147 | r->buff -= (int)(r->count - Table->Length) >> 3; | ||
148 | r->count = (r->count - Table->Length) & 0x07; | ||
149 | |||
150 | return Table->Value; | ||
151 | } | ||
152 | |||
153 | static mpc_inline mpc_uint32_t mpc_bits_enum_dec(mpc_bits_reader * r, mpc_uint_t k, mpc_uint_t n) | ||
154 | { | ||
155 | mpc_uint32_t bits = 0; | ||
156 | mpc_uint32_t code; | ||
157 | const mpc_uint32_t * C = Cnk[k-1]; | ||
158 | |||
159 | code = mpc_bits_read(r, Cnk_len[k-1][n-1] - 1); | ||
160 | |||
161 | if (code >= Cnk_lost[k-1][n-1]) | ||
162 | code = ((code << 1) | mpc_bits_read(r, 1)) - Cnk_lost[k-1][n-1]; | ||
163 | |||
164 | do { | ||
165 | n--; | ||
166 | if (code >= C[n]) { | ||
167 | bits |= 1 << n; | ||
168 | code -= C[n]; | ||
169 | C -= MAX_ENUM; | ||
170 | k--; | ||
171 | } | ||
172 | } while(k > 0); | ||
173 | |||
174 | return bits; | ||
175 | } | ||
diff --git a/lib/rbcodec/codecs/libmusepack/mpc_decoder.c b/lib/rbcodec/codecs/libmusepack/mpc_decoder.c new file mode 100644 index 0000000000..3bfc4cc7fc --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/mpc_decoder.c | |||
@@ -0,0 +1,767 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | /// \file mpc_decoder.c | ||
35 | /// Core decoding routines and logic. | ||
36 | |||
37 | #include <string.h> | ||
38 | #include <codecs.h> | ||
39 | #include "mpcdec.h" | ||
40 | #include "minimax.h" | ||
41 | #include "decoder.h" | ||
42 | #include "huffman.h" | ||
43 | #include "internal.h" | ||
44 | #include "mpcdec_math.h" | ||
45 | #include "requant.h" | ||
46 | #include "mpc_bits_reader.h" | ||
47 | |||
48 | //SV7 tables | ||
49 | extern const mpc_lut_data mpc_HuffQ [7] [2]; | ||
50 | extern const mpc_lut_data mpc_HuffHdr; | ||
51 | extern const mpc_huffman mpc_table_HuffSCFI [ 4]; | ||
52 | extern const mpc_lut_data mpc_HuffDSCF; | ||
53 | |||
54 | //SV8 tables | ||
55 | extern const mpc_can_data mpc_can_Bands; | ||
56 | extern const mpc_can_data mpc_can_SCFI[2]; | ||
57 | extern const mpc_can_data mpc_can_DSCF[2]; | ||
58 | extern const mpc_can_data mpc_can_Res [2]; | ||
59 | extern const mpc_can_data mpc_can_Q [8][2]; | ||
60 | extern const mpc_can_data mpc_can_Q1; | ||
61 | extern const mpc_can_data mpc_can_Q9up; | ||
62 | |||
63 | //Decoder globals (g_Y_L and g_Y_R do not fit into iram for all targets) | ||
64 | static mpc_decoder g_mpc_decoder IBSS_ATTR; | ||
65 | static MPC_SAMPLE_FORMAT g_V_L[MPC_V_MEM + 960 ] IBSS_ATTR MEM_ALIGN_ATTR; | ||
66 | static MPC_SAMPLE_FORMAT g_Y_L[MPC_FRAME_LENGTH] IBSS_ATTR_MPC_LARGE_IRAM MEM_ALIGN_ATTR; | ||
67 | static MPC_SAMPLE_FORMAT g_V_R[MPC_V_MEM + 960 ] IBSS_ATTR MEM_ALIGN_ATTR; | ||
68 | static MPC_SAMPLE_FORMAT g_Y_R[MPC_FRAME_LENGTH] IBSS_ATTR_MPC_LARGE_IRAM MEM_ALIGN_ATTR; | ||
69 | |||
70 | //SV7 globals (decoding results for bundled quantizers (3- and 5-step)) | ||
71 | static const mpc_int32_t g_sv7_idx30[] ICONST_ATTR = | ||
72 | {-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}; | ||
73 | static const mpc_int32_t g_sv7_idx31[] ICONST_ATTR = | ||
74 | {-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1}; | ||
75 | static const mpc_int32_t g_sv7_idx32[] ICONST_ATTR = | ||
76 | {-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}; | ||
77 | static const mpc_int32_t g_sv7_idx50[] ICONST_ATTR = | ||
78 | {-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2}; | ||
79 | static const mpc_int32_t g_sv7_idx51[] ICONST_ATTR = | ||
80 | {-2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2}; | ||
81 | |||
82 | //SV8 globals (decoding results for bundled quantizers (3- and 5-step)) | ||
83 | static const mpc_int8_t g_sv8_idx50[125] ICONST_ATTR = | ||
84 | {-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2, | ||
85 | -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2, | ||
86 | -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2, | ||
87 | -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2, | ||
88 | -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2}; | ||
89 | static const mpc_int8_t g_sv8_idx51[125] ICONST_ATTR = | ||
90 | {-2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, | ||
91 | -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, | ||
92 | -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, | ||
93 | -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, | ||
94 | -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2}; | ||
95 | static const mpc_int8_t g_sv8_idx52[125] ICONST_ATTR = | ||
96 | {-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, | ||
97 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
98 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
99 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | ||
100 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}; | ||
101 | static const mpc_int8_t g_sv8_HuffQ2_var[125] ICONST_ATTR = | ||
102 | { 6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 6, | ||
103 | 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, | ||
104 | 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, | ||
105 | 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, | ||
106 | 6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 6}; | ||
107 | |||
108 | //------------------------------------------------------------------------------ | ||
109 | // types | ||
110 | //------------------------------------------------------------------------------ | ||
111 | enum | ||
112 | { | ||
113 | MEMSIZE = MPC_DECODER_MEMSIZE, // overall buffer size | ||
114 | MEMSIZE2 = (MEMSIZE/2), // size of one buffer | ||
115 | MEMMASK = (MEMSIZE-1) | ||
116 | }; | ||
117 | |||
118 | //------------------------------------------------------------------------------ | ||
119 | // forward declarations | ||
120 | //------------------------------------------------------------------------------ | ||
121 | static void mpc_decoder_requantisierung (mpc_decoder *d) | ||
122 | ICODE_ATTR_MPC_LARGE_IRAM; | ||
123 | static void mpc_decoder_read_bitstream_sv7(mpc_decoder * d, | ||
124 | mpc_bits_reader * r) | ||
125 | ICODE_ATTR_MPC_LARGE_IRAM; | ||
126 | static void mpc_decoder_read_bitstream_sv8(mpc_decoder * d, | ||
127 | mpc_bits_reader * r, | ||
128 | mpc_bool_t is_key_frame) | ||
129 | ICODE_ATTR_MPC_SV8_BS_DEC; | ||
130 | |||
131 | //------------------------------------------------------------------------------ | ||
132 | // macros | ||
133 | //------------------------------------------------------------------------------ | ||
134 | #define REQUANT_M1_S1_SAMPLES(IDX) \ | ||
135 | *(YL+=IDX) = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++)); \ | ||
136 | *(YR+=IDX) = templ - tempr; | ||
137 | |||
138 | #define REQUANT_M1_S1(SUBFRAME) \ | ||
139 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][SUBFRAME] & 0xFF); \ | ||
140 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][SUBFRAME] & 0xFF); \ | ||
141 | for (n = 0; n < 12; n+=4, YL += 32, YR += 32) { \ | ||
142 | REQUANT_M1_S1_SAMPLES( 0); \ | ||
143 | REQUANT_M1_S1_SAMPLES(32); \ | ||
144 | REQUANT_M1_S1_SAMPLES(32); \ | ||
145 | REQUANT_M1_S1_SAMPLES(32); \ | ||
146 | } | ||
147 | |||
148 | #define REQUANT_M1_S0_SAMPLES(IDX) \ | ||
149 | *(YR+=IDX) = *(YL+=IDX) = MPC_MULTIPLY_FLOAT_INT(facL,*L++); | ||
150 | |||
151 | #define REQUANT_M1_S0(SUBFRAME) \ | ||
152 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][SUBFRAME] & 0xFF); \ | ||
153 | for (n = 0; n < 12; n+=4, YL += 32, YR += 32) { \ | ||
154 | REQUANT_M1_S0_SAMPLES( 0); \ | ||
155 | REQUANT_M1_S0_SAMPLES(32); \ | ||
156 | REQUANT_M1_S0_SAMPLES(32); \ | ||
157 | REQUANT_M1_S0_SAMPLES(32); \ | ||
158 | } | ||
159 | |||
160 | #define REQUANT_M0_S1_SAMPLES(IDX) \ | ||
161 | *(YR+=IDX) = -(*(YL+=IDX) = MPC_MULTIPLY_FLOAT_INT(facR,*R++)); | ||
162 | |||
163 | #define REQUANT_M0_S1(SUBFRAME) \ | ||
164 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][SUBFRAME] & 0xFF); \ | ||
165 | for (n = 0; n < 12; n+=4, YL += 32, YR += 32) { \ | ||
166 | REQUANT_M0_S1_SAMPLES( 0); \ | ||
167 | REQUANT_M0_S1_SAMPLES(32); \ | ||
168 | REQUANT_M0_S1_SAMPLES(32); \ | ||
169 | REQUANT_M0_S1_SAMPLES(32); \ | ||
170 | } | ||
171 | |||
172 | #define REQUANT_L1_R1_SAMPLES(IDX) \ | ||
173 | *(YL+=IDX) = MPC_MULTIPLY_FLOAT_INT(facL,*L++); \ | ||
174 | *(YR+=IDX) = MPC_MULTIPLY_FLOAT_INT(facR,*R++); | ||
175 | |||
176 | #define REQUANT_L1_R1(SUBFRAME) \ | ||
177 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][SUBFRAME] & 0xFF); \ | ||
178 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][SUBFRAME] & 0xFF); \ | ||
179 | for (n = 0; n < 12; n+=4, YL += 32, YR += 32) { \ | ||
180 | REQUANT_L1_R1_SAMPLES( 0); \ | ||
181 | REQUANT_L1_R1_SAMPLES(32); \ | ||
182 | REQUANT_L1_R1_SAMPLES(32); \ | ||
183 | REQUANT_L1_R1_SAMPLES(32); \ | ||
184 | } | ||
185 | |||
186 | #define REQUANT_L1_R0_SAMPLES(IDX) \ | ||
187 | *(YL+=IDX) = MPC_MULTIPLY_FLOAT_INT(facL,*L++); \ | ||
188 | *(YR+=IDX) = 0; | ||
189 | |||
190 | #define REQUANT_L1_R0(SUBFRAME) \ | ||
191 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][SUBFRAME] & 0xFF); \ | ||
192 | for (n = 0; n < 12; n+=4, YL += 32, YR += 32) { \ | ||
193 | REQUANT_L1_R0_SAMPLES( 0); \ | ||
194 | REQUANT_L1_R0_SAMPLES(32); \ | ||
195 | REQUANT_L1_R0_SAMPLES(32); \ | ||
196 | REQUANT_L1_R0_SAMPLES(32); \ | ||
197 | } | ||
198 | |||
199 | #define REQUANT_L0_R1_SAMPLES(IDX) \ | ||
200 | *(YL+=IDX) = 0; \ | ||
201 | *(YR+=IDX) = MPC_MULTIPLY_FLOAT_INT(facR,*R++); | ||
202 | |||
203 | #define REQUANT_L0_R1(SUBFRAME) \ | ||
204 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][SUBFRAME] & 0xFF); \ | ||
205 | for (n = 0; n < 12; n+=4, YL += 32, YR += 32) { \ | ||
206 | REQUANT_L0_R1_SAMPLES( 0); \ | ||
207 | REQUANT_L0_R1_SAMPLES(32); \ | ||
208 | REQUANT_L0_R1_SAMPLES(32); \ | ||
209 | REQUANT_L0_R1_SAMPLES(32); \ | ||
210 | } | ||
211 | |||
212 | #define REQUANT_SILENCE_SAMPLES(IDX) \ | ||
213 | *(YR+=IDX) = *(YL+=IDX) = 0; | ||
214 | |||
215 | #define REQUANT_SILENCE \ | ||
216 | for (n = 0; n < 36; n+=4, YL += 32, YR += 32) { \ | ||
217 | REQUANT_SILENCE_SAMPLES( 0); \ | ||
218 | REQUANT_SILENCE_SAMPLES(32); \ | ||
219 | REQUANT_SILENCE_SAMPLES(32); \ | ||
220 | REQUANT_SILENCE_SAMPLES(32); \ | ||
221 | } | ||
222 | |||
223 | /** | ||
224 | * set the scf indexes for seeking use | ||
225 | * needed only for sv7 seeking | ||
226 | * @param d | ||
227 | */ | ||
228 | void mpc_decoder_reset_scf(mpc_decoder * d, int value) | ||
229 | { | ||
230 | memset(d->SCF_Index_L, value, sizeof d->SCF_Index_L ); | ||
231 | memset(d->SCF_Index_R, value, sizeof d->SCF_Index_R ); | ||
232 | } | ||
233 | |||
234 | static void mpc_decoder_setup(mpc_decoder *d) | ||
235 | { | ||
236 | #if defined(CPU_COLDFIRE) | ||
237 | coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE); | ||
238 | #endif | ||
239 | |||
240 | memset(d, 0, sizeof *d); | ||
241 | |||
242 | d->__r1 = 1; | ||
243 | d->__r2 = 1; | ||
244 | d->V_L = g_V_L; | ||
245 | d->V_R = g_V_R; | ||
246 | d->Y_L = g_Y_L; | ||
247 | d->Y_R = g_Y_R; | ||
248 | |||
249 | memset(d->V_L, 0, sizeof(g_V_L)); | ||
250 | memset(d->V_R, 0, sizeof(g_V_R)); | ||
251 | memset(d->Y_L, 0, sizeof(g_Y_L)); | ||
252 | memset(d->Y_R, 0, sizeof(g_Y_R)); | ||
253 | |||
254 | mpc_decoder_init_quant(d, MAKE_MPC_SAMPLE(1.0)); | ||
255 | } | ||
256 | |||
257 | static void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si) | ||
258 | { | ||
259 | d->stream_version = si->stream_version; | ||
260 | d->ms = si->ms; | ||
261 | d->max_band = si->max_band; | ||
262 | d->channels = si->channels; | ||
263 | d->samples_to_skip = MPC_DECODER_SYNTH_DELAY + si->beg_silence; | ||
264 | |||
265 | if (si->stream_version == 7 && si->is_true_gapless) | ||
266 | d->samples = ((si->samples + MPC_FRAME_LENGTH - 1) / MPC_FRAME_LENGTH) * MPC_FRAME_LENGTH; | ||
267 | else | ||
268 | d->samples = si->samples; | ||
269 | } | ||
270 | |||
271 | mpc_decoder * mpc_decoder_init(mpc_streaminfo *si) | ||
272 | { | ||
273 | mpc_decoder* p_tmp = &g_mpc_decoder; | ||
274 | |||
275 | if (p_tmp != 0) { | ||
276 | mpc_decoder_setup(p_tmp); | ||
277 | mpc_decoder_set_streaminfo(p_tmp, si); | ||
278 | huff_init_lut(LUT_DEPTH); | ||
279 | } | ||
280 | |||
281 | return p_tmp; | ||
282 | } | ||
283 | |||
284 | /* rockbox: not used | ||
285 | void mpc_decoder_exit(mpc_decoder *d) | ||
286 | { | ||
287 | (void)d; | ||
288 | } | ||
289 | */ | ||
290 | |||
291 | void mpc_decoder_decode_frame(mpc_decoder * d, | ||
292 | mpc_bits_reader * r, | ||
293 | mpc_frame_info * i) | ||
294 | { | ||
295 | mpc_bits_reader r_sav = *r; | ||
296 | mpc_int64_t samples_left; | ||
297 | |||
298 | samples_left = d->samples - d->decoded_samples + MPC_DECODER_SYNTH_DELAY; | ||
299 | |||
300 | if (samples_left <= 0 && d->samples != 0) { | ||
301 | i->samples = 0; | ||
302 | i->bits = -1; | ||
303 | return; | ||
304 | } | ||
305 | |||
306 | if (d->stream_version == 8) { | ||
307 | mpc_decoder_read_bitstream_sv8(d, r, i->is_key_frame); | ||
308 | } else { | ||
309 | mpc_decoder_read_bitstream_sv7(d, r); | ||
310 | } | ||
311 | |||
312 | if (d->samples_to_skip < MPC_FRAME_LENGTH + MPC_DECODER_SYNTH_DELAY) { | ||
313 | mpc_decoder_requantisierung(d); | ||
314 | mpc_decoder_synthese_filter_float(d, i->buffer, d->channels); | ||
315 | } | ||
316 | |||
317 | d->decoded_samples += MPC_FRAME_LENGTH; | ||
318 | |||
319 | // reconstruct exact filelength | ||
320 | if (d->decoded_samples - d->samples < MPC_FRAME_LENGTH && d->stream_version == 7) { | ||
321 | int last_frame_samples = mpc_bits_read(r, 11); | ||
322 | if (d->decoded_samples == d->samples) { | ||
323 | if (last_frame_samples == 0) last_frame_samples = MPC_FRAME_LENGTH; | ||
324 | d->samples += last_frame_samples - MPC_FRAME_LENGTH; | ||
325 | samples_left += last_frame_samples - MPC_FRAME_LENGTH; | ||
326 | } | ||
327 | } | ||
328 | |||
329 | i->samples = samples_left > MPC_FRAME_LENGTH ? MPC_FRAME_LENGTH : samples_left < 0 ? 0 : (mpc_uint32_t) samples_left; | ||
330 | i->bits = (mpc_uint32_t) (((r->buff - r_sav.buff) << 3) + r_sav.count - r->count); | ||
331 | |||
332 | if (d->samples_to_skip) { | ||
333 | if (i->samples <= d->samples_to_skip) { | ||
334 | d->samples_to_skip -= i->samples; | ||
335 | i->samples = 0; | ||
336 | } else { | ||
337 | i->samples -= d->samples_to_skip; | ||
338 | |||
339 | /* move valid samples to beginning for channel 0. noninterleaved! */ | ||
340 | memmove(i->buffer, | ||
341 | i->buffer + d->samples_to_skip, | ||
342 | i->samples * sizeof(MPC_SAMPLE_FORMAT)); | ||
343 | /* move valid samples to beginning for channel 1. noninterleaved! */ | ||
344 | memmove(i->buffer + MPC_FRAME_LENGTH, | ||
345 | i->buffer + MPC_FRAME_LENGTH + d->samples_to_skip, | ||
346 | i->samples * sizeof(MPC_SAMPLE_FORMAT)); | ||
347 | |||
348 | d->samples_to_skip = 0; | ||
349 | } | ||
350 | } | ||
351 | } | ||
352 | |||
353 | static void | ||
354 | mpc_decoder_requantisierung(mpc_decoder *d) | ||
355 | { | ||
356 | mpc_int32_t Band; | ||
357 | mpc_int32_t n; | ||
358 | MPC_SAMPLE_FORMAT facL; | ||
359 | MPC_SAMPLE_FORMAT facR; | ||
360 | MPC_SAMPLE_FORMAT templ; | ||
361 | MPC_SAMPLE_FORMAT tempr; | ||
362 | MPC_SAMPLE_FORMAT* YL; | ||
363 | MPC_SAMPLE_FORMAT* YR; | ||
364 | mpc_int16_t* L; | ||
365 | mpc_int16_t* R; | ||
366 | const mpc_int32_t Last_Band = d->max_band; | ||
367 | |||
368 | #ifdef MPC_FIXED_POINT | ||
369 | #if MPC_FIXED_POINT_FRACTPART == 14 | ||
370 | #define MPC_MULTIPLY_SCF(CcVal, SCF_idx) \ | ||
371 | MPC_MULTIPLY_EX(CcVal, d->SCF[SCF_idx], d->SCF_shift[SCF_idx]) | ||
372 | #else | ||
373 | |||
374 | #error FIXME, Cc table is in 18.14 format | ||
375 | |||
376 | #endif | ||
377 | #else | ||
378 | #define MPC_MULTIPLY_SCF(CcVal, SCF_idx) \ | ||
379 | MPC_MULTIPLY(CcVal, d->SCF[SCF_idx]) | ||
380 | #endif | ||
381 | // requantization and scaling of subband-samples | ||
382 | for ( Band = 0; Band <= Last_Band; Band++ ) { // setting pointers | ||
383 | YL = d->Y_L + Band; | ||
384 | YR = d->Y_R + Band; | ||
385 | L = d->Q[Band].L; | ||
386 | R = d->Q[Band].R; | ||
387 | /************************** MS-coded **************************/ | ||
388 | if ( d->MS_Flag [Band] ) { | ||
389 | if ( d->Res_L [Band] ) { | ||
390 | if ( d->Res_R [Band] ) { // M!=0, S!=0 | ||
391 | REQUANT_M1_S1(0); | ||
392 | REQUANT_M1_S1(1); | ||
393 | REQUANT_M1_S1(2); | ||
394 | } else { // M!=0, S==0 | ||
395 | REQUANT_M1_S0(0); | ||
396 | REQUANT_M1_S0(1); | ||
397 | REQUANT_M1_S0(2); | ||
398 | } | ||
399 | } else { | ||
400 | if ( d->Res_R[Band] ) // M==0, S!=0 | ||
401 | { | ||
402 | REQUANT_M0_S1(0); | ||
403 | REQUANT_M0_S1(1); | ||
404 | REQUANT_M0_S1(2); | ||
405 | } else { // M==0, S==0 | ||
406 | REQUANT_SILENCE; | ||
407 | } | ||
408 | } | ||
409 | } | ||
410 | /************************** LR-coded **************************/ | ||
411 | else { | ||
412 | if ( d->Res_L [Band] ) { | ||
413 | if ( d->Res_R [Band] ) { // L!=0, R!=0 | ||
414 | REQUANT_L1_R1(0); | ||
415 | REQUANT_L1_R1(1); | ||
416 | REQUANT_L1_R1(2); | ||
417 | } else { // L!=0, R==0 | ||
418 | REQUANT_L1_R0(0); | ||
419 | REQUANT_L1_R0(1); | ||
420 | REQUANT_L1_R0(2); | ||
421 | } | ||
422 | } | ||
423 | else { | ||
424 | if ( d->Res_R [Band] ) { // L==0, R!=0 | ||
425 | REQUANT_L0_R1(0); | ||
426 | REQUANT_L0_R1(1); | ||
427 | REQUANT_L0_R1(2); | ||
428 | } else { // L==0, R==0 | ||
429 | REQUANT_SILENCE; | ||
430 | } | ||
431 | } | ||
432 | } | ||
433 | } | ||
434 | } | ||
435 | |||
436 | static void mpc_decoder_read_bitstream_sv7(mpc_decoder * d, mpc_bits_reader * r) | ||
437 | { | ||
438 | mpc_int32_t n, idx, Max_used_Band = 0; | ||
439 | |||
440 | /***************************** Header *****************************/ | ||
441 | |||
442 | // first subband | ||
443 | d->Res_L[0] = mpc_bits_read(r, 4); | ||
444 | d->Res_R[0] = mpc_bits_read(r, 4); | ||
445 | if (!(d->Res_L[0] == 0 && d->Res_R[0] == 0)) { | ||
446 | if (d->ms) | ||
447 | d->MS_Flag[0] = mpc_bits_read(r, 1); | ||
448 | Max_used_Band = 1; | ||
449 | } | ||
450 | |||
451 | // consecutive subbands | ||
452 | for ( n = 1; n <= d->max_band; n++ ) { | ||
453 | idx = mpc_bits_huff_lut(r, & mpc_HuffHdr); | ||
454 | d->Res_L[n] = (idx!=4) ? d->Res_L[n - 1] + idx : (int) mpc_bits_read(r, 4); | ||
455 | |||
456 | idx = mpc_bits_huff_lut(r, & mpc_HuffHdr); | ||
457 | d->Res_R[n] = (idx!=4) ? d->Res_R[n - 1] + idx : (int) mpc_bits_read(r, 4); | ||
458 | |||
459 | if (!(d->Res_L[n] == 0 && d->Res_R[n] == 0)) { | ||
460 | if (d->ms) | ||
461 | d->MS_Flag[n] = mpc_bits_read(r, 1); | ||
462 | Max_used_Band = n + 1; | ||
463 | } | ||
464 | } | ||
465 | |||
466 | /****************************** SCFI ******************************/ | ||
467 | for ( n = 0; n < Max_used_Band; n++ ) { | ||
468 | if (d->Res_L[n]) | ||
469 | d->SCFI_L[n] = mpc_bits_huff_dec(r, mpc_table_HuffSCFI); | ||
470 | if (d->Res_R[n]) | ||
471 | d->SCFI_R[n] = mpc_bits_huff_dec(r, mpc_table_HuffSCFI); | ||
472 | } | ||
473 | |||
474 | /**************************** SCF/DSCF ****************************/ | ||
475 | for ( n = 0; n < Max_used_Band; n++ ) { | ||
476 | mpc_int32_t * SCF = d->SCF_Index_L[n]; | ||
477 | mpc_uint32_t Res = d->Res_L[n], SCFI = d->SCFI_L[n]; | ||
478 | do { | ||
479 | if (Res) { | ||
480 | switch (SCFI) { | ||
481 | case 1: | ||
482 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); | ||
483 | SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); | ||
484 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); | ||
485 | SCF[1] = (idx!=8) ? SCF[0] + idx : (int) mpc_bits_read(r, 6); | ||
486 | SCF[2] = SCF[1]; | ||
487 | break; | ||
488 | case 3: | ||
489 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); | ||
490 | SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); | ||
491 | SCF[1] = SCF[0]; | ||
492 | SCF[2] = SCF[1]; | ||
493 | break; | ||
494 | case 2: | ||
495 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); | ||
496 | SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); | ||
497 | SCF[1] = SCF[0]; | ||
498 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); | ||
499 | SCF[2] = (idx!=8) ? SCF[1] + idx : (int) mpc_bits_read(r, 6); | ||
500 | break; | ||
501 | case 0: | ||
502 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); | ||
503 | SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); | ||
504 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); | ||
505 | SCF[1] = (idx!=8) ? SCF[0] + idx : (int) mpc_bits_read(r, 6); | ||
506 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); | ||
507 | SCF[2] = (idx!=8) ? SCF[1] + idx : (int) mpc_bits_read(r, 6); | ||
508 | break; | ||
509 | default: | ||
510 | return; | ||
511 | } | ||
512 | if (SCF[0] > 1024) | ||
513 | SCF[0] = 0x8080; | ||
514 | if (SCF[1] > 1024) | ||
515 | SCF[1] = 0x8080; | ||
516 | if (SCF[2] > 1024) | ||
517 | SCF[2] = 0x8080; | ||
518 | } | ||
519 | Res = d->Res_R[n]; | ||
520 | SCFI = d->SCFI_R[n]; | ||
521 | } while ( SCF == d->SCF_Index_L[n] && (SCF = d->SCF_Index_R[n])); | ||
522 | } | ||
523 | |||
524 | // if (d->seeking == TRUE) | ||
525 | // return; | ||
526 | |||
527 | /***************************** Samples ****************************/ | ||
528 | for ( n = 0; n < Max_used_Band; n++ ) { | ||
529 | mpc_int16_t *q = d->Q[n].L, Res = d->Res_L[n]; | ||
530 | do { | ||
531 | mpc_uint32_t nbit; | ||
532 | mpc_int32_t k, dc; | ||
533 | const mpc_lut_data *Table; | ||
534 | switch (Res) { | ||
535 | case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9: | ||
536 | case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17: case 0: | ||
537 | break; | ||
538 | case -1: | ||
539 | for (k=0; k<36; k++ ) { | ||
540 | mpc_uint32_t tmp = mpc_random_int(d); | ||
541 | q[k] = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; | ||
542 | } | ||
543 | break; | ||
544 | case 1: | ||
545 | Table = & mpc_HuffQ[0][mpc_bits_read(r, 1)]; | ||
546 | for ( k = 0; k < 36; k += 3) { | ||
547 | idx = mpc_bits_huff_lut(r, Table); | ||
548 | q[k] = g_sv7_idx30[idx]; | ||
549 | q[k + 1] = g_sv7_idx31[idx]; | ||
550 | q[k + 2] = g_sv7_idx32[idx]; | ||
551 | } | ||
552 | break; | ||
553 | case 2: | ||
554 | Table = & mpc_HuffQ[1][mpc_bits_read(r, 1)]; | ||
555 | for ( k = 0; k < 36; k += 2) { | ||
556 | idx = mpc_bits_huff_lut(r, Table); | ||
557 | q[k] = g_sv7_idx50[idx]; | ||
558 | q[k + 1] = g_sv7_idx51[idx]; | ||
559 | } | ||
560 | break; | ||
561 | case 3: | ||
562 | case 4: | ||
563 | case 5: | ||
564 | case 6: | ||
565 | case 7: | ||
566 | Table = & mpc_HuffQ[Res - 1][mpc_bits_read(r, 1)]; | ||
567 | for ( k = 0; k < 36; k++ ) | ||
568 | q[k] = mpc_bits_huff_lut(r, Table); | ||
569 | break; | ||
570 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: | ||
571 | nbit = Res_bit[Res]; | ||
572 | dc = Dc[Res]; | ||
573 | for ( k = 0; k < 36; k++ ) | ||
574 | q[k] = (mpc_int32_t)mpc_bits_read(r, nbit) - dc; | ||
575 | break; | ||
576 | default: | ||
577 | return; | ||
578 | } | ||
579 | |||
580 | Res = d->Res_R[n]; | ||
581 | } while (q == d->Q[n].L && (q = d->Q[n].R)); | ||
582 | } | ||
583 | } | ||
584 | |||
585 | static void mpc_decoder_read_bitstream_sv8(mpc_decoder * d, mpc_bits_reader * r, mpc_bool_t is_key_frame) | ||
586 | { | ||
587 | mpc_int32_t n, Max_used_Band; | ||
588 | const mpc_can_data * Table, * Tables[2]; | ||
589 | |||
590 | /***************************** Header *****************************/ | ||
591 | |||
592 | if (is_key_frame == MPC_TRUE) { | ||
593 | Max_used_Band = mpc_bits_log_dec(r, d->max_band + 1); | ||
594 | } else { | ||
595 | Max_used_Band = d->last_max_band + mpc_bits_can_dec(r, & mpc_can_Bands); | ||
596 | if (Max_used_Band > 32) Max_used_Band -= 33; | ||
597 | } | ||
598 | d->last_max_band = Max_used_Band; | ||
599 | |||
600 | if (Max_used_Band) { | ||
601 | d->Res_L[Max_used_Band-1] = mpc_bits_can_dec(r, & mpc_can_Res[0]); | ||
602 | d->Res_R[Max_used_Band-1] = mpc_bits_can_dec(r, & mpc_can_Res[0]); | ||
603 | if (d->Res_L[Max_used_Band-1] > 15) d->Res_L[Max_used_Band-1] -= 17; | ||
604 | if (d->Res_R[Max_used_Band-1] > 15) d->Res_R[Max_used_Band-1] -= 17; | ||
605 | for ( n = Max_used_Band - 2; n >= 0; n--) { | ||
606 | d->Res_L[n] = mpc_bits_can_dec(r, & mpc_can_Res[d->Res_L[n + 1] > 2]) + d->Res_L[n + 1]; | ||
607 | if (d->Res_L[n] > 15) d->Res_L[n] -= 17; | ||
608 | d->Res_R[n] = mpc_bits_can_dec(r, & mpc_can_Res[d->Res_R[n + 1] > 2]) + d->Res_R[n + 1]; | ||
609 | if (d->Res_R[n] > 15) d->Res_R[n] -= 17; | ||
610 | } | ||
611 | |||
612 | if (d->ms) { | ||
613 | mpc_uint_t cnt = 0, tot = 0; | ||
614 | mpc_uint32_t tmp = 0; | ||
615 | for( n = 0; n < Max_used_Band; n++) | ||
616 | if ( d->Res_L[n] != 0 || d->Res_R[n] != 0 ) | ||
617 | tot++; | ||
618 | cnt = mpc_bits_log_dec(r, tot); | ||
619 | if (cnt != 0 && cnt != tot) | ||
620 | tmp = mpc_bits_enum_dec(r, mini(cnt, tot-cnt), tot); | ||
621 | if (cnt * 2 > tot) tmp = ~tmp; | ||
622 | for( n = Max_used_Band - 1; n >= 0; n--) | ||
623 | if ( d->Res_L[n] != 0 || d->Res_R[n] != 0 ) { | ||
624 | d->MS_Flag[n] = tmp & 1; | ||
625 | tmp >>= 1; | ||
626 | } | ||
627 | } | ||
628 | } | ||
629 | |||
630 | for( n = Max_used_Band; n <= d->max_band; n++) | ||
631 | d->Res_L[n] = d->Res_R[n] = 0; | ||
632 | |||
633 | /****************************** SCFI ******************************/ | ||
634 | if (is_key_frame == MPC_TRUE){ | ||
635 | for( n = 0; n < 32; n++) | ||
636 | d->DSCF_Flag_L[n] = d->DSCF_Flag_R[n] = 1; // new block -> force key frame | ||
637 | } | ||
638 | |||
639 | Tables[0] = & mpc_can_SCFI[0]; | ||
640 | Tables[1] = & mpc_can_SCFI[1]; | ||
641 | for ( n = 0; n < Max_used_Band; n++ ) { | ||
642 | int tmp = 0, cnt = -1; | ||
643 | if (d->Res_L[n]) cnt++; | ||
644 | if (d->Res_R[n]) cnt++; | ||
645 | if (cnt >= 0) { | ||
646 | tmp = mpc_bits_can_dec(r, Tables[cnt]); | ||
647 | if (d->Res_L[n]) d->SCFI_L[n] = tmp >> (2 * cnt); | ||
648 | if (d->Res_R[n]) d->SCFI_R[n] = tmp & 3; | ||
649 | } | ||
650 | } | ||
651 | |||
652 | /**************************** SCF/DSCF ****************************/ | ||
653 | |||
654 | for ( n = 0; n < Max_used_Band; n++ ) { | ||
655 | mpc_int32_t * SCF = d->SCF_Index_L[n]; | ||
656 | mpc_uint32_t Res = d->Res_L[n], SCFI = d->SCFI_L[n]; | ||
657 | mpc_bool_t * DSCF_Flag = &d->DSCF_Flag_L[n]; | ||
658 | |||
659 | do { | ||
660 | if ( Res ) { | ||
661 | int m; | ||
662 | if (*DSCF_Flag == 1) { | ||
663 | SCF[0] = (mpc_int32_t)mpc_bits_read(r, 7) - 6; | ||
664 | *DSCF_Flag = 0; | ||
665 | } else { | ||
666 | mpc_uint_t tmp = mpc_bits_can_dec(r, & mpc_can_DSCF[1]); | ||
667 | if (tmp == 64) | ||
668 | tmp += mpc_bits_read(r, 6); | ||
669 | SCF[0] = ((SCF[2] - 25 + tmp) & 127) - 6; | ||
670 | } | ||
671 | for( m = 0; m < 2; m++){ | ||
672 | if (((SCFI << m) & 2) == 0) { | ||
673 | mpc_uint_t tmp = mpc_bits_can_dec(r, & mpc_can_DSCF[0]); | ||
674 | if (tmp == 31) | ||
675 | tmp = 64 + mpc_bits_read(r, 6); | ||
676 | SCF[m + 1] = ((SCF[m] - 25 + tmp) & 127) - 6; | ||
677 | } else | ||
678 | SCF[m + 1] = SCF[m]; | ||
679 | } | ||
680 | } | ||
681 | Res = d->Res_R[n]; | ||
682 | SCFI = d->SCFI_R[n]; | ||
683 | DSCF_Flag = &d->DSCF_Flag_R[n]; | ||
684 | } while ( SCF == d->SCF_Index_L[n] && (SCF = d->SCF_Index_R[n])); | ||
685 | } | ||
686 | |||
687 | /***************************** Samples ****************************/ | ||
688 | for ( n = 0; n < Max_used_Band; n++ ) { | ||
689 | mpc_int16_t *q = d->Q[n].L, Res = d->Res_L[n]; | ||
690 | static const mpc_uint32_t thres[] = {0, 0, 3, 0, 0, 1, 3, 4, 8}; | ||
691 | do { | ||
692 | mpc_uint32_t nbit; | ||
693 | mpc_uint32_t k = 0, idx = 1, dc; | ||
694 | if (Res != 0) { | ||
695 | if (Res == 2) { | ||
696 | Tables[0] = & mpc_can_Q [0][0]; | ||
697 | Tables[1] = & mpc_can_Q [0][1]; | ||
698 | idx = 2 * thres[Res]; | ||
699 | for ( ; k < 36; k += 3) { | ||
700 | int tmp = mpc_bits_can_dec(r, Tables[idx > thres[Res]]); | ||
701 | q[k] = g_sv8_idx50[tmp]; | ||
702 | q[k + 1] = g_sv8_idx51[tmp]; | ||
703 | q[k + 2] = g_sv8_idx52[tmp]; | ||
704 | idx = (idx >> 1) + g_sv8_HuffQ2_var[tmp]; | ||
705 | } | ||
706 | } else if (Res == 1) { | ||
707 | Table = & mpc_can_Q1; | ||
708 | for( ; k < 36; ){ | ||
709 | mpc_uint32_t kmax = k + 18; | ||
710 | mpc_uint_t cnt = mpc_bits_can_dec(r, Table); | ||
711 | idx = 0; | ||
712 | if (cnt > 0 && cnt < 18) | ||
713 | idx = mpc_bits_enum_dec(r, cnt <= 9 ? cnt : 18 - cnt, 18); | ||
714 | if (cnt > 9) idx = ~idx; | ||
715 | for ( ; k < kmax; k++) { | ||
716 | q[k] = 0; | ||
717 | if ( idx & (1 << 17) ) | ||
718 | q[k] = (mpc_bits_read(r, 1) << 1) - 1; | ||
719 | idx <<= 1; | ||
720 | } | ||
721 | } | ||
722 | } else if (Res == -1) { | ||
723 | for ( ; k<36; k++ ) { | ||
724 | mpc_uint32_t tmp = mpc_random_int(d); | ||
725 | q[k] = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; | ||
726 | } | ||
727 | } else if (Res <= 4) { | ||
728 | Table = & mpc_can_Q[1][Res - 3]; | ||
729 | for ( ; k < 36; k += 2 ) { | ||
730 | union { | ||
731 | mpc_int8_t sym; | ||
732 | struct { mpc_int8_t s1:4, s2:4; }; | ||
733 | } tmp; | ||
734 | tmp.sym = mpc_bits_can_dec(r, Table); | ||
735 | q[k] = tmp.s1; | ||
736 | q[k + 1] = tmp.s2; | ||
737 | } | ||
738 | } else if (Res <= 8) { | ||
739 | Tables[0] = & mpc_can_Q [Res - 3][0]; | ||
740 | Tables[1] = & mpc_can_Q [Res - 3][1]; | ||
741 | idx = 2 * thres[Res]; | ||
742 | for ( ; k < 36; k++ ) { | ||
743 | q[k] = mpc_bits_can_dec(r, Tables[idx > thres[Res]]); | ||
744 | idx = (idx >> 1) + absi(q[k]); | ||
745 | } | ||
746 | } else if (Res == 9) { | ||
747 | dc = Dc[Res]; | ||
748 | for ( ; k < 36; k++ ) { | ||
749 | q[k] = (unsigned char) mpc_bits_can_dec(r, & mpc_can_Q9up); | ||
750 | q[k] -= dc; | ||
751 | } | ||
752 | } else { | ||
753 | nbit = (Res - 9); | ||
754 | dc = Dc[Res]; | ||
755 | for ( ; k < 36; k++ ) { | ||
756 | q[k] = (unsigned char) mpc_bits_can_dec(r, & mpc_can_Q9up); | ||
757 | q[k] = (q[k] << nbit) | mpc_bits_read(r, nbit); | ||
758 | q[k] -= dc; | ||
759 | } | ||
760 | } | ||
761 | } | ||
762 | |||
763 | Res = d->Res_R[n]; | ||
764 | } while (q == d->Q[n].L && (q = d->Q[n].R)); | ||
765 | } | ||
766 | } | ||
767 | |||
diff --git a/lib/rbcodec/codecs/libmusepack/mpc_demux.c b/lib/rbcodec/codecs/libmusepack/mpc_demux.c new file mode 100644 index 0000000000..9523163c0e --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/mpc_demux.c | |||
@@ -0,0 +1,730 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | #include <math.h> | ||
36 | #include <string.h> | ||
37 | #include "streaminfo.h" | ||
38 | #include "mpcdec.h" | ||
39 | #include "internal.h" | ||
40 | #include "decoder.h" | ||
41 | #include "huffman.h" | ||
42 | #include "mpc_bits_reader.h" | ||
43 | |||
44 | #include <codeclib.h> | ||
45 | |||
46 | /// maximum number of seek points in the table. The distance between points will | ||
47 | /// be adapted so this value is never exceeded. | ||
48 | #define MAX_SEEK_TABLE_SIZE 8192 | ||
49 | |||
50 | // defines | ||
51 | #define MAX_BUFFER_SIZE (DEMUX_BUFFER_SIZE + MAX_FRAME_SIZE) | ||
52 | |||
53 | // globals | ||
54 | static mpc_uint8_t g_buffer[MAX_BUFFER_SIZE] IBSS_ATTR_MPC_BITBUFFER; | ||
55 | static mpc_seek_t g_seek_table[MAX_SEEK_TABLE_SIZE]; | ||
56 | static mpc_demux g_mpc_demux IBSS_ATTR; | ||
57 | |||
58 | enum { | ||
59 | MPC_BUFFER_SWAP = 1, | ||
60 | MPC_BUFFER_FULL = 2, | ||
61 | }; | ||
62 | |||
63 | static void mpc_demux_clear_buff(mpc_demux * d) | ||
64 | { | ||
65 | d->bytes_total = 0; | ||
66 | d->bits_reader.buff = d->buffer; | ||
67 | d->bits_reader.count = 8; | ||
68 | d->bits_reader.buffered_addr = 0; | ||
69 | d->bits_reader.buffered_code = 0; | ||
70 | d->block_bits = 0; | ||
71 | d->block_frames = 0; | ||
72 | memset(d->buffer, 0, sizeof(g_buffer)); | ||
73 | } | ||
74 | |||
75 | static mpc_uint32_t | ||
76 | mpc_demux_fill(mpc_demux * d, mpc_uint32_t min_bytes, int flags) | ||
77 | { | ||
78 | mpc_uint32_t unread_bytes = d->bytes_total + d->buffer - d->bits_reader.buff | ||
79 | - ((8 - d->bits_reader.count) >> 3); | ||
80 | mpc_int32_t offset = 0; | ||
81 | |||
82 | if (min_bytes == 0 || min_bytes > MAX_BUFFER_SIZE || | ||
83 | (unread_bytes < min_bytes && flags & MPC_BUFFER_FULL)) | ||
84 | min_bytes = MAX_BUFFER_SIZE; | ||
85 | |||
86 | if (unread_bytes < min_bytes) { | ||
87 | mpc_uint32_t bytes2read = min_bytes - unread_bytes; | ||
88 | mpc_uint32_t bytes_free = MAX_BUFFER_SIZE - d->bytes_total; | ||
89 | |||
90 | if (flags & MPC_BUFFER_SWAP) { | ||
91 | bytes2read &= -1 << 2; | ||
92 | offset = (unread_bytes + 3) & ( -1 << 2); | ||
93 | offset -= unread_bytes; | ||
94 | } | ||
95 | |||
96 | if (bytes2read > bytes_free) { | ||
97 | if (d->bits_reader.count == 0) { | ||
98 | d->bits_reader.count = 8; | ||
99 | d->bits_reader.buff++; | ||
100 | } | ||
101 | memmove(d->buffer + offset, d->bits_reader.buff, unread_bytes); | ||
102 | d->bits_reader.buff = d->buffer + offset; | ||
103 | d->bytes_total = unread_bytes + offset; | ||
104 | /* reset Coldfire optimized read when rebuffering */ | ||
105 | d->bits_reader.buffered_addr = 0; | ||
106 | d->bits_reader.buffered_code = 0; | ||
107 | } | ||
108 | bytes2read = d->r->read(d->r, d->buffer + d->bytes_total, bytes2read); | ||
109 | if (flags & MPC_BUFFER_SWAP){ | ||
110 | unsigned int i, * tmp = (unsigned int *) (d->buffer + d->bytes_total); | ||
111 | for(i = 0 ;i < (bytes2read >> 2); i++) | ||
112 | tmp[i] = swap32(tmp[i]); | ||
113 | } | ||
114 | d->bytes_total += bytes2read; | ||
115 | return bytes2read; | ||
116 | } | ||
117 | |||
118 | return (mpc_uint32_t) -1; | ||
119 | } | ||
120 | |||
121 | /** | ||
122 | * seek to a bit position in the stream | ||
123 | * @param d demuxer context | ||
124 | * @param fpos position in the stream in bits from the beginning of mpc datas | ||
125 | * @param min_bytes number of bytes to load after seeking | ||
126 | */ | ||
127 | static mpc_status | ||
128 | mpc_demux_seek(mpc_demux * d, mpc_seek_t fpos, mpc_uint32_t min_bytes) { | ||
129 | // d->bits_reader.buff - d->buffer = current byte position within buffer | ||
130 | // d->bytes_total = buffer is filled with bytes_total bytes | ||
131 | // fpos = desired file position in bit (not byte) | ||
132 | // buf_fpos = desired byte position within buffer | ||
133 | mpc_seek_t next_pos = fpos>>3; | ||
134 | mpc_int_t buf_fpos = next_pos - d->r->tell(d->r) + d->bytes_total; | ||
135 | |||
136 | // is desired byte position within lower and upper boundaries of buffer? | ||
137 | if (buf_fpos >= 0 && buf_fpos + min_bytes <= d->bytes_total) { | ||
138 | // desired bytes are available in current buffer | ||
139 | d->bits_reader.buff += buf_fpos - (d->bits_reader.buff - d->buffer); | ||
140 | d->bits_reader.count = 8 - (fpos & 7); | ||
141 | } else { | ||
142 | // buffer needs to be refilled | ||
143 | if (d->si.stream_version == 7) | ||
144 | next_pos = ((next_pos - d->si.header_position) & (-1 << 2)) + d->si.header_position; | ||
145 | buf_fpos = fpos - (next_pos << 3); | ||
146 | if (!d->r->seek(d->r, (mpc_int32_t) next_pos)) | ||
147 | return MPC_STATUS_FAIL; | ||
148 | mpc_demux_clear_buff(d); | ||
149 | if (d->si.stream_version == 7) | ||
150 | mpc_demux_fill(d, MAX_BUFFER_SIZE, MPC_BUFFER_FULL | MPC_BUFFER_SWAP); | ||
151 | else | ||
152 | mpc_demux_fill(d, MAX_BUFFER_SIZE, MPC_BUFFER_FULL); | ||
153 | d->bits_reader.buff += buf_fpos >> 3; | ||
154 | d->bits_reader.count = 8 - (buf_fpos & 7); | ||
155 | } | ||
156 | |||
157 | return MPC_STATUS_OK; | ||
158 | } | ||
159 | |||
160 | /** | ||
161 | * return the current position in the stream (in bits) from the beginning | ||
162 | * of the file | ||
163 | * @param d demuxer context | ||
164 | * @return current stream position in bits | ||
165 | */ | ||
166 | static mpc_seek_t mpc_demux_pos(mpc_demux * d) | ||
167 | { | ||
168 | return (((mpc_seek_t)(d->r->tell(d->r)) - d->bytes_total + | ||
169 | d->bits_reader.buff - d->buffer) << 3) + 8 - d->bits_reader.count; | ||
170 | } | ||
171 | |||
172 | /** | ||
173 | * Searches for a ID3v2-tag and reads the length (in bytes) of it. | ||
174 | * | ||
175 | * @param d demuxer context | ||
176 | * @return size of tag, in bytes | ||
177 | * @return MPC_STATUS_FAIL on errors of any kind | ||
178 | */ | ||
179 | static mpc_int32_t mpc_demux_skip_id3v2(mpc_demux * d) | ||
180 | { | ||
181 | mpc_uint8_t tmp [4]; | ||
182 | mpc_bool_t footerPresent; // ID3v2.4-flag | ||
183 | mpc_int32_t size; | ||
184 | |||
185 | // we must be at the beginning of the stream | ||
186 | mpc_demux_fill(d, 3, 0); | ||
187 | |||
188 | // check id3-tag | ||
189 | if ( 0 != memcmp( d->bits_reader.buff, "ID3", 3 ) ) | ||
190 | return 0; | ||
191 | |||
192 | mpc_demux_fill(d, 10, 0); | ||
193 | |||
194 | mpc_bits_read(&d->bits_reader, 24); // read ID3 | ||
195 | mpc_bits_read(&d->bits_reader, 16); // read tag version | ||
196 | |||
197 | tmp[0] = mpc_bits_read(&d->bits_reader, 8); // read flags | ||
198 | footerPresent = tmp[0] & 0x10; | ||
199 | if ( tmp[0] & 0x0F ) | ||
200 | return MPC_STATUS_FAIL; // not (yet???) allowed | ||
201 | |||
202 | tmp[0] = mpc_bits_read(&d->bits_reader, 8); // read size | ||
203 | tmp[1] = mpc_bits_read(&d->bits_reader, 8); // read size | ||
204 | tmp[2] = mpc_bits_read(&d->bits_reader, 8); // read size | ||
205 | tmp[3] = mpc_bits_read(&d->bits_reader, 8); // read size | ||
206 | |||
207 | if ( (tmp[0] | tmp[1] | tmp[2] | tmp[3]) & 0x80 ) | ||
208 | return MPC_STATUS_FAIL; // not allowed | ||
209 | |||
210 | // read headerSize (syncsave: 4 * $0xxxxxxx = 28 significant bits) | ||
211 | size = tmp[0] << 21; | ||
212 | size |= tmp[1] << 14; | ||
213 | size |= tmp[2] << 7; | ||
214 | size |= tmp[3]; | ||
215 | |||
216 | size += 10; //header | ||
217 | |||
218 | if ( footerPresent ) size += 10; | ||
219 | |||
220 | // This is called before file headers get read, streamversion etc isn't yet known, demuxing isn't properly initialized and we can't call mpc_demux_seek() from here. | ||
221 | mpc_demux_clear_buff(d); | ||
222 | if (!d->r->seek(d->r, size)) | ||
223 | return MPC_STATUS_FAIL; | ||
224 | |||
225 | return size; | ||
226 | } | ||
227 | |||
228 | static mpc_status mpc_demux_seek_init(mpc_demux * d) | ||
229 | { | ||
230 | size_t seek_table_size; | ||
231 | if (d->seek_table != 0) | ||
232 | return MPC_STATUS_OK; | ||
233 | |||
234 | d->seek_pwr = 6; | ||
235 | if (d->si.block_pwr > d->seek_pwr) | ||
236 | d->seek_pwr = d->si.block_pwr; | ||
237 | seek_table_size = (2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)); | ||
238 | while (seek_table_size > MAX_SEEK_TABLE_SIZE) { | ||
239 | d->seek_pwr++; | ||
240 | seek_table_size = (2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)); | ||
241 | } | ||
242 | d->seek_table = g_seek_table; | ||
243 | if (d->seek_table == 0) | ||
244 | return MPC_STATUS_FAIL; | ||
245 | d->seek_table[0] = (mpc_seek_t)mpc_demux_pos(d); | ||
246 | d->seek_table_size = 1; | ||
247 | |||
248 | return MPC_STATUS_OK; | ||
249 | } | ||
250 | |||
251 | /* rockbox: do not use | ||
252 | static mpc_status mpc_demux_ST(mpc_demux * d) | ||
253 | { | ||
254 | mpc_uint64_t tmp; | ||
255 | mpc_seek_t * table, last[2]; | ||
256 | mpc_bits_reader r = d->bits_reader; | ||
257 | mpc_uint_t i, diff_pwr = 0, mask; | ||
258 | mpc_uint32_t file_table_size; | ||
259 | |||
260 | if (d->seek_table != 0) | ||
261 | return MPC_STATUS_OK; | ||
262 | |||
263 | mpc_bits_get_size(&r, &tmp); | ||
264 | file_table_size = (mpc_seek_t) tmp; | ||
265 | d->seek_pwr = d->si.block_pwr + mpc_bits_read(&r, 4); | ||
266 | |||
267 | tmp = 2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr); | ||
268 | while (tmp > MAX_SEEK_TABLE_SIZE) { | ||
269 | d->seek_pwr++; | ||
270 | diff_pwr++; | ||
271 | tmp = 2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr); | ||
272 | } | ||
273 | if ((file_table_size >> diff_pwr) > tmp) | ||
274 | file_table_size = tmp << diff_pwr; | ||
275 | d->seek_table = g_seek_table; | ||
276 | d->seek_table_size = (file_table_size + ((1 << diff_pwr) - 1)) >> diff_pwr; | ||
277 | |||
278 | table = d->seek_table; | ||
279 | mpc_bits_get_size(&r, &tmp); | ||
280 | table[0] = last[0] = (mpc_seek_t) (tmp + d->si.header_position) * 8; | ||
281 | |||
282 | if (d->seek_table_size == 1) | ||
283 | return MPC_STATUS_OK; | ||
284 | |||
285 | mpc_bits_get_size(&r, &tmp); | ||
286 | last[1] = (mpc_seek_t) (tmp + d->si.header_position) * 8; | ||
287 | if (diff_pwr == 0) table[1] = last[1]; | ||
288 | |||
289 | mask = (1 << diff_pwr) - 1; | ||
290 | for (i = 2; i < file_table_size; i++) { | ||
291 | int code = mpc_bits_golomb_dec(&r, 12); | ||
292 | if (code & 1) | ||
293 | code = -(code & (-1 << 1)); | ||
294 | code <<= 2; | ||
295 | last[i & 1] = code + 2 * last[(i-1) & 1] - last[i & 1]; | ||
296 | if ((i & mask) == 0) | ||
297 | table[i >> diff_pwr] = last[i & 1]; | ||
298 | } | ||
299 | return MPC_STATUS_OK; | ||
300 | } | ||
301 | |||
302 | static mpc_status mpc_demux_SP(mpc_demux * d, int size, int block_size) | ||
303 | { | ||
304 | mpc_seek_t cur; | ||
305 | mpc_uint64_t ptr; | ||
306 | mpc_block b; | ||
307 | int st_head_size; | ||
308 | |||
309 | cur = mpc_demux_pos(d); | ||
310 | mpc_bits_get_size(&d->bits_reader, &ptr); | ||
311 | MPC_AUTO_FAIL( mpc_demux_seek(d, (ptr - size) * 8 + cur, 11) ); | ||
312 | st_head_size = mpc_bits_get_block(&d->bits_reader, &b); | ||
313 | if (memcmp(b.key, "ST", 2) == 0) { | ||
314 | d->chap_pos = (ptr - size + b.size + st_head_size) * 8 + cur; | ||
315 | d->chap_nb = -1; | ||
316 | if (mpc_demux_fill(d, (mpc_uint32_t) b.size, 0) < b.size) | ||
317 | return MPC_STATUS_FAIL; | ||
318 | MPC_AUTO_FAIL( mpc_demux_ST(d) ); | ||
319 | } | ||
320 | return mpc_demux_seek(d, cur, 11 + block_size); | ||
321 | } | ||
322 | */ | ||
323 | /* rockbox: not used | ||
324 | static void mpc_demux_chap_empty(mpc_demux * d) { | ||
325 | free(d->chap); d->chap = 0; | ||
326 | d->chap_nb = 0; // -1 for undefined, 0 for no chapters | ||
327 | d->chap_pos = 0; | ||
328 | } | ||
329 | */ | ||
330 | /* rockbox: not used | ||
331 | static mpc_status mpc_demux_chap_find_inner(mpc_demux * d) | ||
332 | { | ||
333 | mpc_block b; | ||
334 | int tag_size = 0, chap_size = 0, size, i = 0; | ||
335 | |||
336 | d->chap_nb = 0; | ||
337 | |||
338 | if (d->si.stream_version < 8) | ||
339 | return MPC_STATUS_OK; | ||
340 | |||
341 | if (d->chap_pos == 0) { | ||
342 | mpc_uint64_t cur_pos = (d->si.header_position + 4) * 8; | ||
343 | MPC_AUTO_FAIL( mpc_demux_seek(d, cur_pos, 11) ); // seek to the beginning of the stream | ||
344 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
345 | while (memcmp(b.key, "SE", 2) != 0) { | ||
346 | mpc_uint64_t new_pos = cur_pos + (size + b.size) * 8; | ||
347 | MPC_AUTO_FAIL(mpc_check_key(b.key)); | ||
348 | |||
349 | if (memcmp(b.key, "CT", 2) == 0) { | ||
350 | if (d->chap_pos == 0) d->chap_pos = cur_pos; | ||
351 | } else { | ||
352 | d->chap_pos = 0; | ||
353 | } | ||
354 | if (new_pos <= cur_pos) | ||
355 | return MPC_STATUS_FAIL; | ||
356 | cur_pos = new_pos; | ||
357 | |||
358 | MPC_AUTO_FAIL( mpc_demux_seek(d, cur_pos, 11) ); | ||
359 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
360 | } | ||
361 | if (d->chap_pos == 0) | ||
362 | d->chap_pos = cur_pos; | ||
363 | } | ||
364 | |||
365 | mpc_demux_seek(d, d->chap_pos, 20); | ||
366 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
367 | while (memcmp(b.key, "CT", 2) == 0) { | ||
368 | mpc_uint64_t chap_sample; | ||
369 | d->chap_nb++; | ||
370 | chap_size += size; | ||
371 | size = mpc_bits_get_size(&d->bits_reader, &chap_sample) + 4; | ||
372 | chap_size += size; | ||
373 | tag_size += b.size - size; | ||
374 | MPC_AUTO_FAIL( mpc_demux_seek(d, d->chap_pos + (chap_size + tag_size) * 8, 20) ); | ||
375 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
376 | } | ||
377 | |||
378 | if (d->chap_nb > 0) { | ||
379 | char * ptag; | ||
380 | d->chap = malloc(sizeof(mpc_chap_info) * d->chap_nb + tag_size); | ||
381 | if (d->chap == 0) | ||
382 | return MPC_STATUS_FAIL; | ||
383 | |||
384 | ptag = (char*)(d->chap + d->chap_nb); | ||
385 | |||
386 | MPC_AUTO_FAIL( mpc_demux_seek(d, d->chap_pos, 11) ); | ||
387 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
388 | while (memcmp(b.key, "CT", 2) == 0) { | ||
389 | mpc_uint_t tmp_size; | ||
390 | char * tmp_ptag = ptag; | ||
391 | if (mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0) < b.size) | ||
392 | return MPC_STATUS_FAIL; | ||
393 | size = mpc_bits_get_size(&d->bits_reader, &d->chap[i].sample) + 4; | ||
394 | d->chap[i].gain = (mpc_uint16_t) mpc_bits_read(&d->bits_reader, 16); | ||
395 | d->chap[i].peak = (mpc_uint16_t) mpc_bits_read(&d->bits_reader, 16); | ||
396 | |||
397 | tmp_size = b.size - size; | ||
398 | do { | ||
399 | mpc_uint_t rd_size = tmp_size; | ||
400 | mpc_uint8_t * tmp_buff = d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3); | ||
401 | mpc_uint32_t avail_bytes = d->bytes_total + d->buffer - tmp_buff; | ||
402 | rd_size = mini(rd_size, avail_bytes); | ||
403 | memcpy(tmp_ptag, tmp_buff, rd_size); | ||
404 | tmp_size -= rd_size; | ||
405 | tmp_ptag += rd_size; | ||
406 | d->bits_reader.buff += rd_size; | ||
407 | mpc_demux_fill(d, tmp_size, 0); | ||
408 | } while (tmp_size > 0); | ||
409 | |||
410 | d->chap[i].tag_size = b.size - size; | ||
411 | d->chap[i].tag = ptag; | ||
412 | ptag += b.size - size; | ||
413 | i++; | ||
414 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
415 | } | ||
416 | } | ||
417 | |||
418 | d->bits_reader.buff -= size; | ||
419 | return MPC_STATUS_OK; | ||
420 | } | ||
421 | */ | ||
422 | /* rockbox: not used | ||
423 | static mpc_status mpc_demux_chap_find(mpc_demux * d) { | ||
424 | mpc_status s = mpc_demux_chap_find_inner(d); | ||
425 | if (MPC_IS_FAILURE(s)) | ||
426 | mpc_demux_chap_empty(d); | ||
427 | return s; | ||
428 | } | ||
429 | */ | ||
430 | /** | ||
431 | * Gets the number of chapters in the stream | ||
432 | * @param d pointer to a musepack demuxer | ||
433 | * @return the number of chapters found in the stream | ||
434 | */ | ||
435 | /* rockbox: not used | ||
436 | mpc_int_t mpc_demux_chap_nb(mpc_demux * d) | ||
437 | { | ||
438 | if (d->chap_nb == -1) | ||
439 | mpc_demux_chap_find(d); | ||
440 | return d->chap_nb; | ||
441 | } | ||
442 | */ | ||
443 | /** | ||
444 | * Gets datas associated to a given chapter | ||
445 | * The chapter tag is an APEv2 tag without the preamble | ||
446 | * @param d pointer to a musepack demuxer | ||
447 | * @param chap_nb chapter number you want datas (from 0 to mpc_demux_chap_nb(d) - 1) | ||
448 | * @return the chapter information structure | ||
449 | */ | ||
450 | /* rockbox: not used | ||
451 | mpc_chap_info const * mpc_demux_chap(mpc_demux * d, int chap_nb) | ||
452 | { | ||
453 | if (d->chap_nb == -1) | ||
454 | mpc_demux_chap_find(d); | ||
455 | if (chap_nb >= d->chap_nb || chap_nb < 0) | ||
456 | return 0; | ||
457 | return &d->chap[chap_nb]; | ||
458 | } | ||
459 | */ | ||
460 | |||
461 | static mpc_status mpc_demux_header(mpc_demux * d) | ||
462 | { | ||
463 | char magic[4]; | ||
464 | |||
465 | d->si.pns = 0xFF; | ||
466 | /* rockbox: not used | ||
467 | d->si.profile_name = "n.a."; | ||
468 | */ | ||
469 | // get header position | ||
470 | d->si.header_position = mpc_demux_skip_id3v2(d); | ||
471 | if(d->si.header_position < 0) | ||
472 | return MPC_STATUS_FAIL; | ||
473 | |||
474 | d->si.tag_offset = d->si.total_file_length = d->r->get_size(d->r); | ||
475 | |||
476 | mpc_demux_fill(d, 4, 0); | ||
477 | magic[0] = mpc_bits_read(&d->bits_reader, 8); | ||
478 | magic[1] = mpc_bits_read(&d->bits_reader, 8); | ||
479 | magic[2] = mpc_bits_read(&d->bits_reader, 8); | ||
480 | magic[3] = mpc_bits_read(&d->bits_reader, 8); | ||
481 | |||
482 | if (memcmp(magic, "MP+", 3) == 0) { | ||
483 | d->si.stream_version = magic[3] & 15; | ||
484 | d->si.pns = magic[3] >> 4; | ||
485 | if (d->si.stream_version != 7) | ||
486 | return MPC_STATUS_FAIL; | ||
487 | if (mpc_demux_fill(d, 6 * 4, MPC_BUFFER_SWAP) < 6 * 4) // header block size + endian convertion | ||
488 | return MPC_STATUS_FAIL; | ||
489 | MPC_AUTO_FAIL( streaminfo_read_header_sv7(&d->si, &d->bits_reader) ); | ||
490 | } else if (memcmp(magic, "MPCK", 4) == 0) { | ||
491 | mpc_block b; | ||
492 | int size; | ||
493 | mpc_demux_fill(d, 11, 0); // max header block size | ||
494 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
495 | while( memcmp(b.key, "AP", 2) != 0 ){ // scan all blocks until audio | ||
496 | if (mpc_check_key(b.key) != MPC_STATUS_OK) | ||
497 | return MPC_STATUS_FAIL; | ||
498 | if (b.size > (mpc_uint64_t) MAX_BUFFER_SIZE - 11) | ||
499 | return MPC_STATUS_FAIL; | ||
500 | |||
501 | if (mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0) <= b.size) | ||
502 | return MPC_STATUS_FAIL; | ||
503 | |||
504 | if (memcmp(b.key, "SH", 2) == 0) { | ||
505 | MPC_AUTO_FAIL( streaminfo_read_header_sv8(&d->si, &d->bits_reader, (mpc_uint32_t) b.size) ); | ||
506 | } else if (memcmp(b.key, "RG", 2) == 0) { | ||
507 | streaminfo_gain(&d->si, &d->bits_reader); | ||
508 | } else if (memcmp(b.key, "EI", 2) == 0) { | ||
509 | streaminfo_encoder_info(&d->si, &d->bits_reader); | ||
510 | /* rockbox: do not use | ||
511 | } else if (memcmp(b.key, "SO", 2) == 0) { | ||
512 | MPC_AUTO_FAIL( mpc_demux_SP(d, size, (mpc_uint32_t) b.size) ); | ||
513 | } else if (memcmp(b.key, "ST", 2) == 0) { | ||
514 | MPC_AUTO_FAIL( mpc_demux_ST(d) ); | ||
515 | */ | ||
516 | } | ||
517 | d->bits_reader.buff += b.size; | ||
518 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
519 | } | ||
520 | d->bits_reader.buff -= size; | ||
521 | if (d->si.stream_version == 0) // si not initialized !!! | ||
522 | return MPC_STATUS_FAIL; | ||
523 | } else { | ||
524 | return MPC_STATUS_FAIL; | ||
525 | } | ||
526 | |||
527 | return MPC_STATUS_OK; | ||
528 | } | ||
529 | |||
530 | mpc_demux * mpc_demux_init(mpc_reader * p_reader) | ||
531 | { | ||
532 | mpc_demux* p_tmp = &g_mpc_demux; | ||
533 | |||
534 | if (p_tmp != 0) { | ||
535 | memset(p_tmp, 0, sizeof(mpc_demux)); | ||
536 | p_tmp->buffer = g_buffer; | ||
537 | p_tmp->r = p_reader; | ||
538 | /* rockbox: not used | ||
539 | p_tmp->chap_nb = -1; | ||
540 | */ | ||
541 | mpc_demux_clear_buff(p_tmp); | ||
542 | if (mpc_demux_header(p_tmp) == MPC_STATUS_OK && | ||
543 | mpc_demux_seek_init(p_tmp) == MPC_STATUS_OK) { | ||
544 | p_tmp->d = mpc_decoder_init(&p_tmp->si); | ||
545 | } else { | ||
546 | if (p_tmp->seek_table) | ||
547 | memset(p_tmp->seek_table, 0, sizeof(g_seek_table)); | ||
548 | p_tmp = 0; | ||
549 | } | ||
550 | } | ||
551 | |||
552 | return p_tmp; | ||
553 | } | ||
554 | |||
555 | /* rockbox: not used | ||
556 | void mpc_demux_exit(mpc_demux * d) | ||
557 | { | ||
558 | mpc_decoder_exit(d->d); | ||
559 | memset(d->seek_table, 0, sizeof(g_seek_table)); | ||
560 | } | ||
561 | */ | ||
562 | |||
563 | void mpc_demux_get_info(mpc_demux * d, mpc_streaminfo * i) | ||
564 | { | ||
565 | memcpy(i, &d->si, sizeof d->si); | ||
566 | } | ||
567 | |||
568 | static mpc_status mpc_demux_decode_inner(mpc_demux * d, mpc_frame_info * i) | ||
569 | { | ||
570 | mpc_bits_reader r; | ||
571 | if (d->si.stream_version >= 8) { | ||
572 | i->is_key_frame = MPC_FALSE; | ||
573 | |||
574 | if (d->block_frames == 0) { | ||
575 | mpc_block b = {{0,0},0}; | ||
576 | d->bits_reader.count &= -8; | ||
577 | if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { | ||
578 | d->seek_table[d->seek_table_size] = (mpc_seek_t) mpc_demux_pos(d); | ||
579 | d->seek_table_size ++; | ||
580 | } | ||
581 | mpc_demux_fill(d, 11, MPC_BUFFER_FULL); // max header block size | ||
582 | mpc_bits_get_block(&d->bits_reader, &b); | ||
583 | while( memcmp(b.key, "AP", 2) != 0 ) { // scan all blocks until audio | ||
584 | MPC_AUTO_FAIL( mpc_check_key(b.key) ); | ||
585 | |||
586 | if (memcmp(b.key, "SE", 2) == 0) { // end block | ||
587 | i->bits = -1; | ||
588 | return MPC_STATUS_OK; | ||
589 | } | ||
590 | |||
591 | if (mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, MPC_BUFFER_FULL) < b.size) | ||
592 | return MPC_STATUS_FAIL; | ||
593 | |||
594 | d->bits_reader.buff += b.size; | ||
595 | mpc_bits_get_block(&d->bits_reader, &b); | ||
596 | } | ||
597 | d->block_bits = (mpc_uint32_t) b.size * 8; | ||
598 | d->block_frames = 1 << d->si.block_pwr; | ||
599 | i->is_key_frame = MPC_TRUE; | ||
600 | } | ||
601 | mpc_demux_fill(d, MAX_FRAME_SIZE, MPC_BUFFER_FULL); | ||
602 | r = d->bits_reader; | ||
603 | mpc_decoder_decode_frame(d->d, &d->bits_reader, i); | ||
604 | d->block_bits -= ((d->bits_reader.buff - r.buff) << 3) + r.count - d->bits_reader.count; | ||
605 | d->block_frames--; | ||
606 | if (d->block_bits < 0 || (d->block_frames == 0 && d->block_bits > 7)) | ||
607 | return MPC_STATUS_FAIL; | ||
608 | } else { | ||
609 | if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { | ||
610 | d->seek_table[d->seek_table_size] = (mpc_seek_t) mpc_demux_pos(d); | ||
611 | d->seek_table_size ++; | ||
612 | } | ||
613 | mpc_demux_fill(d, MAX_FRAME_SIZE, MPC_BUFFER_FULL | MPC_BUFFER_SWAP); | ||
614 | d->block_bits = (mpc_int_t) mpc_bits_read(&d->bits_reader, 20); // read frame size | ||
615 | if (MPC_FRAME_LENGTH > d->d->samples - d->d->decoded_samples - 1) d->block_bits += 11; // we will read last frame size | ||
616 | r = d->bits_reader; | ||
617 | mpc_decoder_decode_frame(d->d, &d->bits_reader, i); | ||
618 | if (i->bits != -1 && d->block_bits != (mpc_int32_t)(((d->bits_reader.buff - r.buff) << 3) + r.count - d->bits_reader.count)) | ||
619 | return MPC_STATUS_FAIL; | ||
620 | } | ||
621 | if (i->bits != -1 && d->buffer + d->bytes_total < d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3)) | ||
622 | return MPC_STATUS_FAIL; | ||
623 | |||
624 | return MPC_STATUS_OK; | ||
625 | } | ||
626 | |||
627 | mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i) { | ||
628 | mpc_status s = mpc_demux_decode_inner(d, i); | ||
629 | if (MPC_IS_FAILURE(s)) | ||
630 | i->bits = -1; // we pretend it's end of file | ||
631 | return s; | ||
632 | } | ||
633 | |||
634 | /* rockbox: not used | ||
635 | mpc_status mpc_demux_seek_second(mpc_demux * d, double seconds) | ||
636 | { | ||
637 | return mpc_demux_seek_sample(d, (mpc_int64_t)(seconds * (double)d->si.sample_freq + 0.5)); | ||
638 | } | ||
639 | */ | ||
640 | |||
641 | mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample) | ||
642 | { | ||
643 | mpc_uint32_t fwd, samples_to_skip, i; | ||
644 | mpc_uint32_t block_samples = MPC_FRAME_LENGTH << d->si.block_pwr; | ||
645 | mpc_seek_t fpos; | ||
646 | |||
647 | destsample += d->si.beg_silence; | ||
648 | if (destsample > d->si.samples) destsample = d->si.samples; | ||
649 | fwd = (mpc_uint32_t) (destsample / block_samples); | ||
650 | samples_to_skip = MPC_DECODER_SYNTH_DELAY + | ||
651 | (mpc_uint32_t) (destsample % block_samples); | ||
652 | if (d->si.stream_version == 7) { | ||
653 | if (fwd > 32) { | ||
654 | fwd -= 32; | ||
655 | samples_to_skip += MPC_FRAME_LENGTH * 32; | ||
656 | } else { | ||
657 | samples_to_skip += MPC_FRAME_LENGTH * fwd; | ||
658 | fwd = 0; | ||
659 | } | ||
660 | } | ||
661 | |||
662 | i = fwd >> (d->seek_pwr - d->si.block_pwr); | ||
663 | if (i >= d->seek_table_size) | ||
664 | i = d->seek_table_size - 1; | ||
665 | fpos = d->seek_table[i]; | ||
666 | i <<= d->seek_pwr - d->si.block_pwr; | ||
667 | d->d->decoded_samples = i * block_samples; | ||
668 | |||
669 | if (d->si.stream_version >= 8) { | ||
670 | mpc_block b; | ||
671 | int size; | ||
672 | mpc_demux_seek(d, fpos, 11); | ||
673 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
674 | while(i < fwd) { | ||
675 | if (memcmp(b.key, "AP", 2) == 0) { | ||
676 | if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { | ||
677 | d->seek_table[d->seek_table_size] = (mpc_seek_t) mpc_demux_pos(d) - 8 * size; | ||
678 | d->seek_table_size ++; | ||
679 | } | ||
680 | d->d->decoded_samples += block_samples; | ||
681 | i++; | ||
682 | } | ||
683 | fpos += ((mpc_uint32_t)b.size + size) * 8; | ||
684 | mpc_demux_seek(d, fpos, 11); | ||
685 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
686 | } | ||
687 | d->bits_reader.buff -= size; | ||
688 | } else { | ||
689 | mpc_decoder_reset_scf(d->d, fwd != 0); | ||
690 | mpc_demux_seek(d, fpos, 4); | ||
691 | for( ; i < fwd; i++){ | ||
692 | if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { | ||
693 | d->seek_table[d->seek_table_size] = (mpc_seek_t) mpc_demux_pos(d); | ||
694 | d->seek_table_size ++; | ||
695 | } | ||
696 | d->d->decoded_samples += block_samples; | ||
697 | fpos += mpc_bits_read(&d->bits_reader, 20) + 20; | ||
698 | mpc_demux_seek(d, fpos, 4); | ||
699 | } | ||
700 | } | ||
701 | d->d->samples_to_skip = samples_to_skip; | ||
702 | return MPC_STATUS_OK; | ||
703 | } | ||
704 | |||
705 | /* rockbox: not used | ||
706 | void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain, | ||
707 | mpc_bool_t use_title, mpc_bool_t clip_prevention) | ||
708 | { | ||
709 | float peak = (float) ( use_title ? d->si.peak_title : d->si.peak_album ); | ||
710 | float gain = (float) ( use_title ? d->si.gain_title : d->si.gain_album ); | ||
711 | |||
712 | if(!use_gain && !clip_prevention) | ||
713 | return; | ||
714 | |||
715 | if(!peak) | ||
716 | peak = 1.; | ||
717 | else | ||
718 | peak = (float) ( (1 << 15) / pow(10, peak / (20 * 256)) ); | ||
719 | |||
720 | if(!gain) | ||
721 | gain = 1.; | ||
722 | else | ||
723 | gain = (float) pow(10, (level - gain / 256) / 20); | ||
724 | |||
725 | if(clip_prevention && (peak < gain || !use_gain)) | ||
726 | gain = peak; | ||
727 | |||
728 | mpc_decoder_scale_output(d->d, gain); | ||
729 | } | ||
730 | */ | ||
diff --git a/lib/rbcodec/codecs/libmusepack/mpc_types.h b/lib/rbcodec/codecs/libmusepack/mpc_types.h new file mode 100644 index 0000000000..0e7aa9d2c3 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/mpc_types.h | |||
@@ -0,0 +1,145 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | #ifndef _MPC_TYPES_H_ | ||
35 | #define _MPC_TYPES_H_ | ||
36 | #ifdef WIN32 | ||
37 | #pragma once | ||
38 | #endif | ||
39 | |||
40 | #include <stdlib.h> | ||
41 | #include <inttypes.h> | ||
42 | |||
43 | #ifdef __cplusplus | ||
44 | extern "C" { | ||
45 | #endif | ||
46 | |||
47 | #ifdef _MSC_VER | ||
48 | typedef __int8 mpc_int8_t; | ||
49 | typedef unsigned __int8 mpc_uint8_t; | ||
50 | typedef __int16 mpc_int16_t; | ||
51 | typedef unsigned __int16 mpc_uint16_t; | ||
52 | typedef __int32 mpc_int32_t; | ||
53 | typedef unsigned __int32 mpc_uint32_t; | ||
54 | typedef __int64 mpc_int64_t; | ||
55 | typedef unsigned __int64 mpc_uint64_t; | ||
56 | #define mpc_inline __inline | ||
57 | #else | ||
58 | typedef signed char mpc_int8_t; | ||
59 | typedef unsigned char mpc_uint8_t; | ||
60 | typedef short mpc_int16_t; | ||
61 | typedef unsigned short mpc_uint16_t; | ||
62 | typedef int mpc_int32_t; | ||
63 | typedef unsigned int mpc_uint32_t; | ||
64 | typedef long long mpc_int64_t; | ||
65 | typedef unsigned long long mpc_uint64_t; | ||
66 | #define mpc_inline inline | ||
67 | #endif | ||
68 | |||
69 | typedef int mpc_int_t; | ||
70 | typedef unsigned int mpc_uint_t; | ||
71 | typedef size_t mpc_size_t; | ||
72 | typedef mpc_uint8_t mpc_bool_t; | ||
73 | |||
74 | // #define LONG_SEEK_TABLE | ||
75 | #ifdef LONG_SEEK_TABLE // define as needed (mpc_uint32_t supports files up to 512 MB) | ||
76 | typedef mpc_uint64_t mpc_seek_t; | ||
77 | #else | ||
78 | typedef mpc_uint32_t mpc_seek_t; | ||
79 | #endif | ||
80 | |||
81 | # define mpc_int64_min -9223372036854775808ll | ||
82 | # define mpc_int64_max 9223372036854775807ll | ||
83 | |||
84 | typedef struct mpc_quantizer { | ||
85 | mpc_int16_t L [36]; | ||
86 | mpc_int16_t R [36]; | ||
87 | } mpc_quantizer; | ||
88 | |||
89 | /// Libmpcdec error codes | ||
90 | typedef enum mpc_status { | ||
91 | // Success. | ||
92 | MPC_STATUS_OK = 0, | ||
93 | // Generic failure (I/O error or invalid file). | ||
94 | MPC_STATUS_FAIL = -1 | ||
95 | } mpc_status; | ||
96 | |||
97 | #define MPC_FIXED_POINT | ||
98 | #define MPC_FIXED_POINT_SHIFT 16 | ||
99 | |||
100 | #ifdef MPC_FIXED_POINT | ||
101 | # define MPC_FIXED_POINT_FRACTPART 14 | ||
102 | # define MPC_FIXED_POINT_SCALE_SHIFT (MPC_FIXED_POINT_SHIFT + MPC_FIXED_POINT_FRACTPART) | ||
103 | # define MPC_FIXED_POINT_SCALE (1 << (MPC_FIXED_POINT_SCALE_SHIFT - 1)) | ||
104 | typedef mpc_int32_t MPC_SAMPLE_FORMAT; | ||
105 | #else | ||
106 | typedef float MPC_SAMPLE_FORMAT; | ||
107 | #endif | ||
108 | |||
109 | enum { | ||
110 | MPC_FALSE = 0, | ||
111 | MPC_TRUE = !MPC_FALSE | ||
112 | }; | ||
113 | |||
114 | //// 'Cdecl' forces the use of standard C/C++ calling convention /////// | ||
115 | #if defined _WIN32 | ||
116 | # define mpc_cdecl __cdecl | ||
117 | #elif defined __ZTC__ | ||
118 | # define mpc_cdecl _cdecl | ||
119 | #elif defined __TURBOC__ | ||
120 | # define mpc_cdecl cdecl | ||
121 | #else | ||
122 | # define mpc_cdecl | ||
123 | #endif | ||
124 | |||
125 | /* DLL building support on win32 hosts */ | ||
126 | #ifndef MPC_API | ||
127 | # ifdef DLL_EXPORT /* defined by libtool (if required) */ | ||
128 | # define MPC_API __declspec(dllexport) | ||
129 | # endif | ||
130 | # ifdef MPC_DLL_IMPORT /* define if linking with this dll */ | ||
131 | # define MPC_API __declspec(dllimport) | ||
132 | # endif | ||
133 | # ifndef MPC_API /* static linking or !_WIN32 */ | ||
134 | # if defined(__GNUC__) && (__GNUC__ >= 4) | ||
135 | # define MPC_API __attribute__ ((visibility("default"))) | ||
136 | # else | ||
137 | # define MPC_API | ||
138 | # endif | ||
139 | # endif | ||
140 | #endif | ||
141 | |||
142 | #ifdef __cplusplus | ||
143 | } | ||
144 | #endif | ||
145 | #endif | ||
diff --git a/lib/rbcodec/codecs/libmusepack/mpcdec.h b/lib/rbcodec/codecs/libmusepack/mpcdec.h new file mode 100644 index 0000000000..85536e726a --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/mpcdec.h | |||
@@ -0,0 +1,212 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | /// \file mpcdec.h | ||
35 | /// Top level include file for libmpcdec. | ||
36 | #ifndef _MPCDEC_H_ | ||
37 | #define _MPCDEC_H_ | ||
38 | #ifdef WIN32 | ||
39 | #pragma once | ||
40 | #endif | ||
41 | |||
42 | #include "reader.h" | ||
43 | #include "streaminfo.h" | ||
44 | #include "config.h" | ||
45 | |||
46 | #ifdef __cplusplus | ||
47 | extern "C" { | ||
48 | #endif | ||
49 | |||
50 | #if (CONFIG_CPU == MCF5250) | ||
51 | /* Enough IRAM but performance suffers with ICODE_ATTR. */ | ||
52 | #define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR | ||
53 | #define ICODE_ATTR_MPC_LARGE_IRAM | ||
54 | #define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR | ||
55 | /* Does not fit into IRAM. */ | ||
56 | #define IBSS_ATTR_MPC_BITBUFFER | ||
57 | #define ICODE_ATTR_MPC_SV8_BS_DEC | ||
58 | /* Keep the data arrays of bitsreadr.c in IRAM. */ | ||
59 | #define ICONST_ATTR_MPC_BITSREADER ICONST_ATTR | ||
60 | |||
61 | #elif (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) | ||
62 | /* Enough IRAM to move additional data and code to it. */ | ||
63 | #define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR | ||
64 | #define ICODE_ATTR_MPC_LARGE_IRAM ICODE_ATTR | ||
65 | #define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR | ||
66 | /* Does not fit into IRAM. */ | ||
67 | #define IBSS_ATTR_MPC_BITBUFFER | ||
68 | #define ICODE_ATTR_MPC_SV8_BS_DEC | ||
69 | /* Not putting the data arrays of bitsreader.c to IRAM allows to move the | ||
70 | * sv7/sv8 bitstream demuxing into IRAM. This config is faster. */ | ||
71 | #define ICONST_ATTR_MPC_BITSREADER | ||
72 | |||
73 | #elif defined(CPU_S5L870X) | ||
74 | /* Enough IRAM to move additional data and code to it. */ | ||
75 | #define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR | ||
76 | #define ICODE_ATTR_MPC_LARGE_IRAM ICODE_ATTR | ||
77 | #define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR | ||
78 | /* Faster when moved to IRAM. */ | ||
79 | #define IBSS_ATTR_MPC_BITBUFFER IBSS_ATTR | ||
80 | #define ICODE_ATTR_MPC_SV8_BS_DEC ICODE_ATTR | ||
81 | /* Not faster when moved to IRAM. */ | ||
82 | #define ICONST_ATTR_MPC_BITSREADER | ||
83 | |||
84 | #else | ||
85 | /* Not enough IRAM available. */ | ||
86 | #define IBSS_ATTR_MPC_LARGE_IRAM | ||
87 | #define ICODE_ATTR_MPC_LARGE_IRAM | ||
88 | #define ICONST_ATTR_MPC_LARGE_IRAM | ||
89 | #define IBSS_ATTR_MPC_BITBUFFER | ||
90 | #define ICODE_ATTR_MPC_SV8_BS_DEC | ||
91 | #define ICONST_ATTR_MPC_BITSREADER | ||
92 | #endif | ||
93 | |||
94 | enum { | ||
95 | MPC_FRAME_LENGTH = (36 * 32), ///< Samples per mpc frame | ||
96 | MPC_DECODER_BUFFER_LENGTH = (MPC_FRAME_LENGTH * 2), ///< Required buffer size for decoder (2 channels) | ||
97 | MPC_DECODER_SYNTH_DELAY = 481 | ||
98 | }; | ||
99 | |||
100 | typedef struct mpc_decoder_t mpc_decoder; | ||
101 | typedef struct mpc_demux_t mpc_demux; | ||
102 | |||
103 | typedef struct mpc_bits_reader_t { | ||
104 | unsigned char * buff; /// pointer on current byte | ||
105 | unsigned int count; /// unread bits in current byte | ||
106 | mpc_uint8_t *buffered_addr; /// used for rockbox Coldfire optimization only | ||
107 | mpc_uint32_t buffered_code; /// used for rockbox Coldfire optimization only | ||
108 | } mpc_bits_reader; | ||
109 | |||
110 | typedef struct mpc_frame_info_t { | ||
111 | mpc_uint32_t samples; /// number of samples in the frame (counting once for multiple channels) | ||
112 | mpc_int32_t bits; /// number of bits consumed by this frame (-1) if end of stream | ||
113 | MPC_SAMPLE_FORMAT * buffer; /// frame samples buffer (size = samples * channels * sizeof(MPC_SAMPLE_FORMAT)) | ||
114 | mpc_bool_t is_key_frame; /// 1 if this frame is a key frame (first in block) 0 else. Set by the demuxer. | ||
115 | } mpc_frame_info; | ||
116 | |||
117 | /* rockbox: not used | ||
118 | typedef struct mpc_chap_info_t { | ||
119 | mpc_uint64_t sample; /// sample where the chapter starts | ||
120 | mpc_uint16_t gain; /// replaygain chapter value | ||
121 | mpc_uint16_t peak; /// peak chapter loudness level | ||
122 | mpc_uint_t tag_size; /// size of the tag element (0 if no tag is present for this chapter) | ||
123 | char * tag; /// pointer to an APEv2 tag without the preamble | ||
124 | } mpc_chap_info; | ||
125 | */ | ||
126 | |||
127 | /// Initializes mpc decoder with the supplied stream info parameters. | ||
128 | /// \param si streaminfo structure indicating format of source stream | ||
129 | /// \return pointer on the initialized decoder structure if successful, 0 if not | ||
130 | MPC_API mpc_decoder * mpc_decoder_init(mpc_streaminfo *si); | ||
131 | |||
132 | /* rockbox: not used | ||
133 | /// Releases input mpc decoder | ||
134 | MPC_API void mpc_decoder_exit(mpc_decoder *p_dec); | ||
135 | */ | ||
136 | |||
137 | /** | ||
138 | * Sets decoder sample scaling factor. All decoded samples will be multiplied | ||
139 | * by this factor. Useful for applying replay gain. | ||
140 | * @param scale_factor multiplicative scaling factor | ||
141 | */ | ||
142 | /* rockbox: changed to static | ||
143 | MPC_API void mpc_decoder_scale_output(mpc_decoder *p_dec, double scale_factor); | ||
144 | */ | ||
145 | |||
146 | MPC_API void mpc_decoder_decode_frame(mpc_decoder * d, mpc_bits_reader * r, mpc_frame_info * i); | ||
147 | |||
148 | // This is the gain reference used in old replaygain | ||
149 | #define MPC_OLD_GAIN_REF 64.82 | ||
150 | |||
151 | /** | ||
152 | * init demuxer | ||
153 | * @param p_reader initialized mpc_reader pointer | ||
154 | * @return an initialized mpc_demux pointer | ||
155 | */ | ||
156 | MPC_API mpc_demux * mpc_demux_init(mpc_reader * p_reader); | ||
157 | /* rockbox: not used | ||
158 | /// free demuxer | ||
159 | MPC_API void mpc_demux_exit(mpc_demux * d); | ||
160 | */ | ||
161 | /** | ||
162 | * Calls mpc_decoder_scale_output to set the scaling factor according to the | ||
163 | * replay gain stream information and the supplied ouput level | ||
164 | * @param d pointer to a musepack demuxer | ||
165 | * @param level the desired ouput level (in db). Must be MPC_OLD_GAIN_REF (64.82 db) if you want to get the old replaygain behavior | ||
166 | * @param use_gain set it to MPC_TRUE if you want to set the scaling factor according to the stream gain | ||
167 | * @param use_title MPC_TRUE : uses the title gain, MPC_FALSE : uses the album gain | ||
168 | * @param clip_prevention MPC_TRUE : uses cliping prevention | ||
169 | */ | ||
170 | /* rockbox: not used | ||
171 | MPC_API void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain, | ||
172 | mpc_bool_t use_title, mpc_bool_t clip_prevention); | ||
173 | */ | ||
174 | /// decode frame | ||
175 | MPC_API mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i); | ||
176 | /// get streaminfo | ||
177 | MPC_API void mpc_demux_get_info(mpc_demux * d, mpc_streaminfo * i); | ||
178 | /// seeks to a given sample | ||
179 | MPC_API mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample); | ||
180 | /* rockbox: not used | ||
181 | /// seeks to a given second | ||
182 | MPC_API mpc_status mpc_demux_seek_second(mpc_demux * d, double seconds); | ||
183 | */ | ||
184 | |||
185 | /* rockbox: keep static | ||
186 | /// \return the current position in the stream (in bits) from the beginning of the file | ||
187 | MPC_API mpc_seek_t mpc_demux_pos(mpc_demux * d); | ||
188 | */ | ||
189 | |||
190 | /// chapters : only for sv8 streams | ||
191 | /** | ||
192 | * Gets the number of chapters in the stream | ||
193 | * @param d pointer to a musepack demuxer | ||
194 | * @return the number of chapters found in the stream | ||
195 | */ | ||
196 | /* rockbox: not used | ||
197 | MPC_API mpc_int_t mpc_demux_chap_nb(mpc_demux * d); | ||
198 | */ | ||
199 | /** | ||
200 | * Gets datas associated to a given chapter | ||
201 | * The chapter tag is an APEv2 tag without the preamble | ||
202 | * @param d pointer to a musepack demuxer | ||
203 | * @param chap_nb chapter number you want datas (from 0 to mpc_demux_chap_nb(d) - 1) | ||
204 | * @return the chapter information structure | ||
205 | */ | ||
206 | /* rockbox: not used | ||
207 | MPC_API mpc_chap_info const * mpc_demux_chap(mpc_demux * d, int chap_nb); | ||
208 | */ | ||
209 | #ifdef __cplusplus | ||
210 | } | ||
211 | #endif | ||
212 | #endif | ||
diff --git a/lib/rbcodec/codecs/libmusepack/mpcdec_math.h b/lib/rbcodec/codecs/libmusepack/mpcdec_math.h new file mode 100644 index 0000000000..955681f4e5 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/mpcdec_math.h | |||
@@ -0,0 +1,231 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | /// \file math.h | ||
36 | /// Libmpcdec internal math routines. | ||
37 | |||
38 | #ifndef _mpcdec_math_h_ | ||
39 | #define _mpcdec_math_h_ | ||
40 | |||
41 | #include "mpc_types.h" | ||
42 | |||
43 | #define MPC_FIXED_POINT_SHIFT 16 | ||
44 | |||
45 | #ifdef MPC_FIXED_POINT | ||
46 | |||
47 | #ifdef _WIN32_WCE | ||
48 | #include <cmnintrin.h> | ||
49 | #define MPC_HAVE_MULHIGH | ||
50 | #endif | ||
51 | |||
52 | typedef mpc_int64_t MPC_SAMPLE_FORMAT_MULTIPLY; | ||
53 | |||
54 | #define MAKE_MPC_SAMPLE(X) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<MPC_FIXED_POINT_FRACTPART)) | ||
55 | #define MAKE_MPC_SAMPLE_EX(X,Y) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<(Y))) | ||
56 | |||
57 | #define MPC_SHR_RND(X, Y) ((X+(1<<(Y-1)))>>Y) | ||
58 | |||
59 | #if defined(CPU_COLDFIRE) | ||
60 | |||
61 | #define MPC_MULTIPLY(X,Y) mpc_multiply((X), (Y)) | ||
62 | #define MPC_MULTIPLY_EX(X,Y,Z) mpc_multiply_ex((X), (Y), (Z)) | ||
63 | |||
64 | static inline MPC_SAMPLE_FORMAT mpc_multiply(MPC_SAMPLE_FORMAT x, | ||
65 | MPC_SAMPLE_FORMAT y) | ||
66 | { | ||
67 | MPC_SAMPLE_FORMAT t1, t2; | ||
68 | asm volatile ( | ||
69 | "mac.l %[x],%[y],%%acc0\n" /* multiply */ | ||
70 | "mulu.l %[y],%[x] \n" /* get lower half, avoid emac stall */ | ||
71 | "movclr.l %%acc0,%[t1] \n" /* get higher half */ | ||
72 | "moveq.l #17,%[t2] \n" | ||
73 | "asl.l %[t2],%[t1] \n" /* hi <<= 17, plus one free */ | ||
74 | "moveq.l #14,%[t2] \n" | ||
75 | "lsr.l %[t2],%[x] \n" /* (unsigned)lo >>= 14 */ | ||
76 | "or.l %[x],%[t1] \n" /* combine result */ | ||
77 | : /* outputs */ | ||
78 | [t1]"=&d"(t1), | ||
79 | [t2]"=&d"(t2), | ||
80 | [x] "+d" (x) | ||
81 | : /* inputs */ | ||
82 | [y] "d" (y) | ||
83 | ); | ||
84 | return t1; | ||
85 | } | ||
86 | |||
87 | static inline MPC_SAMPLE_FORMAT mpc_multiply_ex(MPC_SAMPLE_FORMAT x, | ||
88 | MPC_SAMPLE_FORMAT y, | ||
89 | unsigned shift) | ||
90 | { | ||
91 | MPC_SAMPLE_FORMAT t1, t2; | ||
92 | asm volatile ( | ||
93 | "mac.l %[x],%[y],%%acc0\n" /* multiply */ | ||
94 | "mulu.l %[y],%[x] \n" /* get lower half, avoid emac stall */ | ||
95 | "movclr.l %%acc0,%[t1] \n" /* get higher half */ | ||
96 | "moveq.l #31,%[t2] \n" | ||
97 | "sub.l %[sh],%[t2] \n" /* t2 = 31 - shift */ | ||
98 | "ble.s 1f \n" | ||
99 | "asl.l %[t2],%[t1] \n" /* hi <<= 31 - shift */ | ||
100 | "lsr.l %[sh],%[x] \n" /* (unsigned)lo >>= shift */ | ||
101 | "or.l %[x],%[t1] \n" /* combine result */ | ||
102 | "bra.s 2f \n" | ||
103 | "1: \n" | ||
104 | "neg.l %[t2] \n" /* t2 = shift - 31 */ | ||
105 | "asr.l %[t2],%[t1] \n" /* hi >>= t2 */ | ||
106 | "2: \n" | ||
107 | : /* outputs */ | ||
108 | [t1]"=&d"(t1), | ||
109 | [t2]"=&d"(t2), | ||
110 | [x] "+d" (x) | ||
111 | : /* inputs */ | ||
112 | [y] "d" (y), | ||
113 | [sh]"d" (shift) | ||
114 | ); | ||
115 | return t1; | ||
116 | } | ||
117 | #elif defined(CPU_ARM) | ||
118 | /* Calculate: result = (X*Y)>>14 */ | ||
119 | #define MPC_MULTIPLY(X,Y) \ | ||
120 | ({ \ | ||
121 | MPC_SAMPLE_FORMAT lo; \ | ||
122 | MPC_SAMPLE_FORMAT hi; \ | ||
123 | asm volatile ( \ | ||
124 | "smull %[lo], %[hi], %[x], %[y] \n\t" /* multiply */ \ | ||
125 | "mov %[lo], %[lo], lsr #14 \n\t" /* lo >>= 14 */ \ | ||
126 | "orr %[lo], %[lo], %[hi], lsl #18" /* lo |= (hi << 18) */ \ | ||
127 | : [lo]"=&r"(lo), [hi]"=&r"(hi) \ | ||
128 | : [x]"r"(X), [y]"r"(Y)); \ | ||
129 | lo; \ | ||
130 | }) | ||
131 | |||
132 | /* Calculate: result = (X*Y)>>Z */ | ||
133 | #define MPC_MULTIPLY_EX(X,Y,Z) \ | ||
134 | ({ \ | ||
135 | MPC_SAMPLE_FORMAT lo; \ | ||
136 | MPC_SAMPLE_FORMAT hi; \ | ||
137 | asm volatile ( \ | ||
138 | "smull %[lo], %[hi], %[x], %[y] \n\t" /* multiply */ \ | ||
139 | "mov %[lo], %[lo], lsr %[shr] \n\t" /* lo >>= Z */ \ | ||
140 | "orr %[lo], %[lo], %[hi], lsl %[shl]" /* lo |= (hi << (32-Z)) */ \ | ||
141 | : [lo]"=&r"(lo), [hi]"=&r"(hi) \ | ||
142 | : [x]"r"(X), [y]"r"(Y), [shr]"r"(Z), [shl]"r"(32-Z)); \ | ||
143 | lo; \ | ||
144 | }) | ||
145 | #else /* libmusepack standard */ | ||
146 | |||
147 | #define MPC_MULTIPLY_NOTRUNCATE(X,Y) \ | ||
148 | (((MPC_SAMPLE_FORMAT_MULTIPLY)(X) * (MPC_SAMPLE_FORMAT_MULTIPLY)(Y)) >> MPC_FIXED_POINT_FRACTPART) | ||
149 | |||
150 | #define MPC_MULTIPLY_EX_NOTRUNCATE(X,Y,Z) \ | ||
151 | (((MPC_SAMPLE_FORMAT_MULTIPLY)(X) * (MPC_SAMPLE_FORMAT_MULTIPLY)(Y)) >> (Z)) | ||
152 | |||
153 | #ifdef _DEBUG | ||
154 | static inline MPC_SAMPLE_FORMAT MPC_MULTIPLY(MPC_SAMPLE_FORMAT item1,MPC_SAMPLE_FORMAT item2) | ||
155 | { | ||
156 | MPC_SAMPLE_FORMAT_MULTIPLY temp = MPC_MULTIPLY_NOTRUNCATE(item1,item2); | ||
157 | assert(temp == (MPC_SAMPLE_FORMAT_MULTIPLY)(MPC_SAMPLE_FORMAT)temp); | ||
158 | return (MPC_SAMPLE_FORMAT)temp; | ||
159 | } | ||
160 | |||
161 | static inline MPC_SAMPLE_FORMAT MPC_MULTIPLY_EX(MPC_SAMPLE_FORMAT item1,MPC_SAMPLE_FORMAT item2,unsigned shift) | ||
162 | { | ||
163 | MPC_SAMPLE_FORMAT_MULTIPLY temp = MPC_MULTIPLY_EX_NOTRUNCATE(item1,item2,shift); | ||
164 | assert(temp == (MPC_SAMPLE_FORMAT_MULTIPLY)(MPC_SAMPLE_FORMAT)temp); | ||
165 | return (MPC_SAMPLE_FORMAT)temp; | ||
166 | } | ||
167 | #else | ||
168 | #define MPC_MULTIPLY(X,Y) ((MPC_SAMPLE_FORMAT)MPC_MULTIPLY_NOTRUNCATE(X,Y)) | ||
169 | #define MPC_MULTIPLY_EX(X,Y,Z) ((MPC_SAMPLE_FORMAT)MPC_MULTIPLY_EX_NOTRUNCATE(X,Y,Z)) | ||
170 | #endif | ||
171 | |||
172 | #endif | ||
173 | |||
174 | #ifdef MPC_HAVE_MULHIGH | ||
175 | #define MPC_MULTIPLY_FRACT(X,Y) _MulHigh(X,Y) | ||
176 | #else | ||
177 | #if defined(CPU_COLDFIRE) | ||
178 | /* loses one bit of accuracy. The rest of the macros won't be as easy as this... */ | ||
179 | #define MPC_MULTIPLY_FRACT(X,Y) \ | ||
180 | ({ \ | ||
181 | MPC_SAMPLE_FORMAT t; \ | ||
182 | asm volatile ( \ | ||
183 | "mac.l %[A], %[B], %%acc0\n\t" \ | ||
184 | "movclr.l %%acc0, %[t] \n\t" \ | ||
185 | "asr.l #1, %[t] \n\t" \ | ||
186 | : [t] "=d" (t) \ | ||
187 | : [A] "r" ((X)), [B] "r" ((Y))); \ | ||
188 | t; \ | ||
189 | }) | ||
190 | #elif defined(CPU_ARM) | ||
191 | /* Calculate: result = (X*Y)>>32, without need for >>32 */ | ||
192 | #define MPC_MULTIPLY_FRACT(X,Y) \ | ||
193 | ({ \ | ||
194 | MPC_SAMPLE_FORMAT lo; \ | ||
195 | MPC_SAMPLE_FORMAT hi; \ | ||
196 | asm volatile ( \ | ||
197 | "smull %[lo], %[hi], %[x], %[y]" /* hi = result */ \ | ||
198 | : [lo]"=&r"(lo), [hi]"=&r"(hi) \ | ||
199 | : [x]"r"(X), [y]"r"(Y)); \ | ||
200 | hi; \ | ||
201 | }) | ||
202 | #else | ||
203 | #define MPC_MULTIPLY_FRACT(X,Y) MPC_MULTIPLY_EX(X,Y,32) | ||
204 | #endif | ||
205 | #endif | ||
206 | |||
207 | #define MPC_MAKE_FRACT_CONST(X) (MPC_SAMPLE_FORMAT)((X) * (double)(((mpc_int64_t)1)<<32) ) | ||
208 | |||
209 | #define MPC_MULTIPLY_FLOAT_INT(X,Y) ((X)*(Y)) | ||
210 | |||
211 | #else | ||
212 | //in floating-point mode, decoded samples are in -1...1 range | ||
213 | |||
214 | typedef float MPC_SAMPLE_FORMAT; | ||
215 | |||
216 | #define MAKE_MPC_SAMPLE(X) ((MPC_SAMPLE_FORMAT)(X)) | ||
217 | #define MAKE_MPC_SAMPLE_EX(X,Y) ((MPC_SAMPLE_FORMAT)(X)) | ||
218 | |||
219 | #define MPC_MULTIPLY_FRACT(X,Y) ((X)*(Y)) | ||
220 | #define MPC_MAKE_FRACT_CONST(X) (X) | ||
221 | |||
222 | #define MPC_MULTIPLY_FLOAT_INT(X,Y) ((X)*(Y)) | ||
223 | #define MPC_MULTIPLY(X,Y) ((X)*(Y)) | ||
224 | #define MPC_MULTIPLY_EX(X,Y,Z) ((X)*(Y)) | ||
225 | |||
226 | #define MPC_SHR_RND(X, Y) (X) | ||
227 | |||
228 | #endif | ||
229 | |||
230 | #endif // _mpcdec_math_h_ | ||
231 | |||
diff --git a/lib/rbcodec/codecs/libmusepack/reader.h b/lib/rbcodec/codecs/libmusepack/reader.h new file mode 100644 index 0000000000..c46844cd59 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/reader.h | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | /// \file reader.h | ||
35 | #ifndef _MPCDEC_READER_H_ | ||
36 | #define _MPCDEC_READER_H_ | ||
37 | #ifdef WIN32 | ||
38 | #pragma once | ||
39 | #endif | ||
40 | |||
41 | #include "mpc_types.h" | ||
42 | #include <stdio.h> | ||
43 | |||
44 | #ifdef __cplusplus | ||
45 | extern "C" { | ||
46 | #endif | ||
47 | |||
48 | |||
49 | /// \brief Stream reader interface structure. | ||
50 | /// | ||
51 | /// This is the structure you must supply to the musepack decoding library | ||
52 | /// to feed it with raw data. Implement the five member functions to provide | ||
53 | /// a functional reader. | ||
54 | typedef struct mpc_reader_t mpc_reader; | ||
55 | struct mpc_reader_t { | ||
56 | /// Reads size bytes of data into buffer at ptr. | ||
57 | mpc_int32_t (*read)(mpc_reader *p_reader, void *ptr, mpc_int32_t size); | ||
58 | |||
59 | /// Seeks to byte position offset. | ||
60 | mpc_bool_t (*seek)(mpc_reader *p_reader, mpc_int32_t offset); | ||
61 | |||
62 | /// Returns the current byte offset in the stream. | ||
63 | mpc_int32_t (*tell)(mpc_reader *p_reader); | ||
64 | |||
65 | /// Returns the total length of the source stream, in bytes. | ||
66 | mpc_int32_t (*get_size)(mpc_reader *p_reader); | ||
67 | |||
68 | /* rockbox: not used | ||
69 | /// True if the stream is a seekable stream. | ||
70 | mpc_bool_t (*canseek)(mpc_reader *p_reader); | ||
71 | |||
72 | /// Field that can be used to identify a particular instance of | ||
73 | /// reader or carry along data associated with that reader. | ||
74 | void *data; | ||
75 | */ | ||
76 | }; | ||
77 | /* rockbox: not used | ||
78 | /// Initializes reader with default stdio file reader implementation. Use | ||
79 | /// this if you're just reading from a plain file. | ||
80 | /// | ||
81 | /// \param r p_reader handle to initialize | ||
82 | /// \param filename input filename to attach to the reader | ||
83 | MPC_API mpc_status mpc_reader_init_stdio(mpc_reader *p_reader, const char *filename); | ||
84 | |||
85 | /// Initializes reader with default stdio file reader implementation. Use | ||
86 | /// this if you prefer to open the file yourself. | ||
87 | /// | ||
88 | /// \param r p_reader handle to initialize | ||
89 | /// \param p_file input file handle (already open) | ||
90 | MPC_API mpc_status mpc_reader_init_stdio_stream(mpc_reader * p_reader, FILE * p_file); | ||
91 | |||
92 | /// Release reader with default stdio file reader implementation. | ||
93 | /// | ||
94 | /// \param r reader handle to release | ||
95 | MPC_API void mpc_reader_exit_stdio(mpc_reader *p_reader); | ||
96 | */ | ||
97 | #ifdef __cplusplus | ||
98 | } | ||
99 | #endif | ||
100 | #endif | ||
diff --git a/lib/rbcodec/codecs/libmusepack/requant.c b/lib/rbcodec/codecs/libmusepack/requant.c new file mode 100644 index 0000000000..fc27dfd199 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/requant.c | |||
@@ -0,0 +1,184 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | /// \file requant.c | ||
35 | /// Requantization function implementations. | ||
36 | /// \todo document me | ||
37 | #include "mpcdec.h" | ||
38 | #include "requant.h" | ||
39 | #include "mpcdec_math.h" | ||
40 | #include "decoder.h" | ||
41 | #include "internal.h" | ||
42 | #include <string.h> | ||
43 | |||
44 | /* C O N S T A N T S */ | ||
45 | // Bits per sample for chosen quantizer | ||
46 | const mpc_uint8_t Res_bit [18] ICONST_ATTR = { | ||
47 | 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 | ||
48 | }; | ||
49 | |||
50 | // Requantization coefficients | ||
51 | // 65536/step bzw. 65536/(2*D+1) | ||
52 | |||
53 | #define _(X) MAKE_MPC_SAMPLE_EX(X,14) | ||
54 | |||
55 | const MPC_SAMPLE_FORMAT __Cc [1 + 18] ICONST_ATTR = { | ||
56 | _(111.285962475327f), // 32768/2/255*sqrt(3) | ||
57 | _(65536.000000000000f), _(21845.333333333332f), _(13107.200000000001f), _(9362.285714285713f), | ||
58 | _(7281.777777777777f), _(4369.066666666666f), _(2114.064516129032f), _(1040.253968253968f), | ||
59 | _(516.031496062992f), _(257.003921568627f), _(128.250489236790f), _(64.062561094819f), | ||
60 | _(32.015632633121f), _(16.003907203907f), _(8.000976681723f), _(4.000244155527f), | ||
61 | _(2.000061037018f), _(1.000015259021f) | ||
62 | }; | ||
63 | |||
64 | #undef _ | ||
65 | |||
66 | // Requantization offset | ||
67 | // 2*D+1 = steps of quantizer | ||
68 | const mpc_int16_t __Dc [1 + 18] ICONST_ATTR = { | ||
69 | 2, | ||
70 | 0, 1, 2, 3, 4, 7, 15, 31, 63, | ||
71 | 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767 | ||
72 | }; | ||
73 | |||
74 | // Table'ized SCF calculated from mpc_decoder_scale_output(d, 1.0) | ||
75 | static const mpc_uint32_t SCF[] = { | ||
76 | 1289035711, 1073741824, 1788812356, 1490046106, 1241179595, 1033878604, 861200887, 717363687, | ||
77 | 597550081, 497747664, 414614180, 345365595, 287682863, 239634262, 199610707, 166271859, | ||
78 | 138501244, 115368858, 96100028, 80049465, 66679657, 55542865, 46266132, 38538793, | ||
79 | 32102070, 26740403, 22274239, 18554010, 15455132, 12873826, 10723648, 8932591, | ||
80 | 7440676, 6197939, 5162763, 4300482, 3582218, 2983918, 2485546, 2070412, | ||
81 | 1724613, 1436569, 1196634, 996773, 830293, 691618, 576104, 479883, | ||
82 | 399734, 332970, 277358, 231034, 192446, 160304, 133530, 111228, | ||
83 | 92651, 77176, 64286, 53549, 44605, 37155, 30949, 25780, | ||
84 | 21474, 17888, 14900, 12411, 10338, 8612, 7173, 5975, | ||
85 | 4977, 4146, 3453, 2876, 2396, 1996, 1662, 1385, | ||
86 | 1153, 961, 800, 666, 555, 462, 385, 321, | ||
87 | 267, 222, 185, 154, 128, 107, 89, 74, | ||
88 | 61, 51, 43, 35, 29, 24, 20, 17, | ||
89 | 14, 11, 9, 8, 6, 5, 4, 3, | ||
90 | 3, 2, 2, 1, 1, 1, 1, 0, | ||
91 | 0, 0, 0, 0, 0, 0, 0, 0, | ||
92 | 0, 2147483648, 2147483648, 2147483648, 2147483648, 2147483648, 2147483648, 2147483648, | ||
93 | 2147483648, 2147483648, 2147483648, 2147483648, 1930697728, 1608233877, 1339627724, 1115883992, | ||
94 | 1859019579, 1548527365, 1289893354, 1074456223, 1790002518, 1491037488, 1242005398, 2069132964, | ||
95 | 1723547752, 1435681952, 1195895306, 1992315335, 1659560152, 1382381519, 1151497076, 1918349601, | ||
96 | 1597948125, 1331059892, 1108747153, 1847129882, 1538623477, 1281643607, 2135168687, 1778554232, | ||
97 | 1481501287, 1234061927, 2055899448, 1712524489, 1426499787, 1188246741, 1979573121, 1648946134, | ||
98 | 1373540247, 1144132468, 1906080447, 1587728158, 1322546856, 1101655960, 1835316227, 1528782931, | ||
99 | 1273446622, 2121512828, 1767179166, 1472026076, 1226169259, 2042750570, 1701571728, 1417376349, | ||
100 | 1180647093, 1966912401, 1638400000, 1364755521, 1136814961, 1893889764, 1577573554, 1314088268, | ||
101 | 1094610119, 1823578129, 1519005322, 1265302063, 2107944308, 1755876851, 1462611466, 1218327071, | ||
102 | 2029685788, 1690689017, 1408311261, 1173096050, 1954332656, 1627921315, 1356026979, 1129544254, | ||
103 | 1881777048, 1567483896, 1305683778, 1087609341, 1811915104, 1509290248, 1257209594, 2094462567, | ||
104 | 1744646821, 1453257069, 1210535039, 2016704564, 1679875908, 1399304151, 1165593302, 1941833367, | ||
105 | 1617509648, 1347354262, 1122320049, 1869741801, 1557458768, 1297333040, 1080653338, 1800326672, | ||
106 | 1499637308, 1249168882, 2081067051, 1733488616, 1443962500, 1202792843, 2003806364, 1669131957, | ||
107 | 1390354647, 1158138538, 1929414019, 1607164572, 1338737013, 1115142047, 1857783528, 1547497758 | ||
108 | }; | ||
109 | |||
110 | // Table'ized SCF_shift calculated from mpc_decoder_scale_output(d, 1.0) | ||
111 | static const mpc_uint8_t SCF_shift[] = { | ||
112 | 30, 30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, | ||
113 | 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, | ||
114 | 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, | ||
115 | 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, | ||
116 | 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, | ||
117 | 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, | ||
118 | 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, | ||
119 | 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, | ||
120 | 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
121 | 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, | ||
122 | 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, | ||
123 | 9, 9, 10, 10, 10, 10, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, | ||
124 | 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 17, 17, 17, 17, | ||
125 | 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 22, | ||
126 | 22, 22, 22, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 26, | ||
127 | 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 30, 30 | ||
128 | }; | ||
129 | |||
130 | /* F U N C T I O N S */ | ||
131 | /* not used anymore, tables from above are used | ||
132 | #ifdef MPC_FIXED_POINT | ||
133 | static mpc_uint32_t find_shift(double fval) | ||
134 | { | ||
135 | mpc_int64_t val = (mpc_int64_t) fval; | ||
136 | mpc_uint32_t ptr = 0; | ||
137 | if(val<0) | ||
138 | val = -val; | ||
139 | while(val) | ||
140 | { | ||
141 | val >>= 1; | ||
142 | ptr++; | ||
143 | } | ||
144 | return ptr > 31 ? 0 : 31 - ptr; | ||
145 | } | ||
146 | #endif | ||
147 | |||
148 | #define SET_SCF(N,X) d->SCF[N] = MAKE_MPC_SAMPLE_EX(X,d->SCF_shift[N] = (mpc_uint8_t) find_shift(X)); | ||
149 | |||
150 | static void | ||
151 | mpc_decoder_scale_output(mpc_decoder *d, double factor) | ||
152 | { | ||
153 | mpc_int32_t n; double f1, f2; | ||
154 | |||
155 | #ifndef MPC_FIXED_POINT | ||
156 | factor *= 1.0 / (double) (1<<(MPC_FIXED_POINT_SHIFT-1)); | ||
157 | #else | ||
158 | factor *= 1.0 / (double) (1<<(16-MPC_FIXED_POINT_SHIFT)); | ||
159 | #endif | ||
160 | f1 = f2 = factor; | ||
161 | |||
162 | // handles +1.58...-98.41 dB, where's scf[n] / scf[n-1] = 1.20050805774840750476 | ||
163 | |||
164 | SET_SCF(1,factor); | ||
165 | |||
166 | f1 *= 0.83298066476582673961; | ||
167 | f2 *= 1/0.83298066476582673961; | ||
168 | |||
169 | for ( n = 1; n <= 128; n++ ) { | ||
170 | SET_SCF((mpc_uint8_t)(1+n),f1); | ||
171 | SET_SCF((mpc_uint8_t)(1-n),f2); | ||
172 | f1 *= 0.83298066476582673961; | ||
173 | f2 *= 1/0.83298066476582673961; | ||
174 | } | ||
175 | } | ||
176 | */ | ||
177 | void | ||
178 | mpc_decoder_init_quant(mpc_decoder *d, MPC_SAMPLE_FORMAT factor) | ||
179 | { | ||
180 | //mpc_decoder_scale_output(d, (double)factor / MPC_FIXED_POINT_SHIFT) | ||
181 | (void)factor; | ||
182 | memcpy(d->SCF, SCF, sizeof(d->SCF)); | ||
183 | memcpy(d->SCF_shift, SCF_shift, sizeof(d->SCF_shift)); | ||
184 | } | ||
diff --git a/lib/rbcodec/codecs/libmusepack/requant.h b/lib/rbcodec/codecs/libmusepack/requant.h new file mode 100644 index 0000000000..908fda30eb --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/requant.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | /// \file requant.h | ||
35 | /// Requantization function definitions. | ||
36 | #ifndef _MPCDEC_REQUANT_H_ | ||
37 | #define _MPCDEC_REQUANT_H_ | ||
38 | #ifdef WIN32 | ||
39 | #pragma once | ||
40 | #endif | ||
41 | |||
42 | #include "mpc_types.h" | ||
43 | |||
44 | #ifdef __cplusplus | ||
45 | extern "C" { | ||
46 | #endif | ||
47 | |||
48 | |||
49 | /* C O N S T A N T S */ | ||
50 | extern const mpc_uint8_t Res_bit [18]; ///< Bits per sample for chosen quantizer | ||
51 | extern const MPC_SAMPLE_FORMAT __Cc [1 + 18]; ///< Requantization coefficients | ||
52 | extern const mpc_int16_t __Dc [1 + 18]; ///< Requantization offset | ||
53 | |||
54 | #define Cc (__Cc + 1) | ||
55 | #define Dc (__Dc + 1) | ||
56 | |||
57 | |||
58 | #ifdef __cplusplus | ||
59 | } | ||
60 | #endif | ||
61 | #endif | ||
diff --git a/lib/rbcodec/codecs/libmusepack/streaminfo.c b/lib/rbcodec/codecs/libmusepack/streaminfo.c new file mode 100644 index 0000000000..6b4d3df0c1 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/streaminfo.c | |||
@@ -0,0 +1,255 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | /// \file streaminfo.c | ||
35 | /// Implementation of streaminfo reading functions. | ||
36 | |||
37 | #include <math.h> | ||
38 | #include "mpcdec.h" | ||
39 | #include "streaminfo.h" | ||
40 | #include <stdio.h> | ||
41 | #include "internal.h" | ||
42 | #include "huffman.h" | ||
43 | #include "mpc_bits_reader.h" | ||
44 | |||
45 | /* rockbox: not used | ||
46 | static const char na[] = "n.a."; | ||
47 | static char const * const versionNames[] = { | ||
48 | na, "'Unstable/Experimental'", na, na, na, "'quality 0'", "'quality 1'", | ||
49 | "'Telephone'", "'Thumb'", "'Radio'", "'Standard'", "'Extreme'", "'Insane'", | ||
50 | "'BrainDead'", "'quality 9'", "'quality 10'" | ||
51 | }; | ||
52 | */ | ||
53 | static const mpc_int32_t samplefreqs[8] = { 44100, 48000, 37800, 32000 }; | ||
54 | /* rockbox: not used | ||
55 | static const char * | ||
56 | mpc_get_version_string(float profile) // profile is 0...15, where 7...13 is used | ||
57 | { | ||
58 | return profile >= sizeof versionNames / sizeof *versionNames ? na : versionNames[(int)profile]; | ||
59 | } | ||
60 | */ | ||
61 | /* rockbox: not used | ||
62 | static void | ||
63 | mpc_get_encoder_string(mpc_streaminfo* si) | ||
64 | { | ||
65 | int ver = si->encoder_version; | ||
66 | if (si->stream_version >= 8) | ||
67 | ver = (si->encoder_version >> 24) * 100 + ((si->encoder_version >> 16) & 0xFF); | ||
68 | if (ver <= 116) { | ||
69 | if (ver == 0) { | ||
70 | sprintf(si->encoder, "Buschmann 1.7.0...9, Klemm 0.90...1.05"); | ||
71 | } else { | ||
72 | switch (ver % 10) { | ||
73 | case 0: | ||
74 | sprintf(si->encoder, "Release %u.%u", ver / 100, | ||
75 | ver / 10 % 10); | ||
76 | break; | ||
77 | case 2: case 4: case 6: case 8: | ||
78 | sprintf(si->encoder, "Beta %u.%02u", ver / 100, | ||
79 | ver % 100); | ||
80 | break; | ||
81 | default: | ||
82 | sprintf(si->encoder, "--Alpha-- %u.%02u", | ||
83 | ver / 100, ver % 100); | ||
84 | break; | ||
85 | } | ||
86 | } | ||
87 | } else { | ||
88 | int major = si->encoder_version >> 24; | ||
89 | int minor = (si->encoder_version >> 16) & 0xFF; | ||
90 | int build = (si->encoder_version >> 8) & 0xFF; | ||
91 | char * tmp = "--Stable--"; | ||
92 | |||
93 | if (minor & 1) | ||
94 | tmp = "--Unstable--"; | ||
95 | |||
96 | sprintf(si->encoder, "%s %u.%u.%u", tmp, major, minor, build); | ||
97 | } | ||
98 | } | ||
99 | */ | ||
100 | |||
101 | static mpc_status check_streaminfo(mpc_streaminfo * si) | ||
102 | { | ||
103 | if (si->max_band == 0 || si->max_band >= 32 | ||
104 | || si->channels > 2 || si->channels == 0 || si->sample_freq == 0) | ||
105 | return MPC_STATUS_FAIL; | ||
106 | return MPC_STATUS_OK; | ||
107 | } | ||
108 | |||
109 | /// Reads streaminfo from SV7 header. | ||
110 | mpc_status | ||
111 | streaminfo_read_header_sv7(mpc_streaminfo* si, mpc_bits_reader * r) | ||
112 | { | ||
113 | mpc_uint32_t frames, last_frame_samples; | ||
114 | |||
115 | si->bitrate = 0; | ||
116 | frames = (mpc_bits_read(r, 16) << 16) | mpc_bits_read(r, 16); | ||
117 | mpc_bits_read(r, 1); // intensity stereo : should be 0 | ||
118 | si->ms = mpc_bits_read(r, 1); | ||
119 | si->max_band = mpc_bits_read(r, 6); | ||
120 | si->profile = mpc_bits_read(r, 4); | ||
121 | /* rockbox: not used | ||
122 | si->profile_name = mpc_get_version_string(si->profile); | ||
123 | */ | ||
124 | mpc_bits_read(r, 2); // Link ? | ||
125 | si->sample_freq = samplefreqs[mpc_bits_read(r, 2)]; | ||
126 | mpc_bits_read(r, 16); // Estimatedpeak_title | ||
127 | si->gain_title = (mpc_uint16_t) mpc_bits_read(r, 16); | ||
128 | si->peak_title = (mpc_uint16_t) mpc_bits_read(r, 16); | ||
129 | si->gain_album = (mpc_uint16_t) mpc_bits_read(r, 16); | ||
130 | si->peak_album = (mpc_uint16_t) mpc_bits_read(r, 16); | ||
131 | si->is_true_gapless = mpc_bits_read(r, 1); // true gapless: used? | ||
132 | last_frame_samples = mpc_bits_read(r, 11); // true gapless: valid samples for last frame | ||
133 | si->fast_seek = mpc_bits_read(r, 1); // fast seeking | ||
134 | mpc_bits_read(r, 19); // unused | ||
135 | si->encoder_version = mpc_bits_read(r, 8); | ||
136 | si->channels = 2; | ||
137 | si->block_pwr = 0; | ||
138 | |||
139 | /* rockbox: not used | ||
140 | // convert gain info | ||
141 | if (si->gain_title != 0) { | ||
142 | int tmp = (int)((MPC_OLD_GAIN_REF - (mpc_int16_t)si->gain_title / 100.) * 256. + .5); | ||
143 | if (tmp >= (1 << 16) || tmp < 0) tmp = 0; | ||
144 | si->gain_title = (mpc_int16_t) tmp; | ||
145 | } | ||
146 | |||
147 | if (si->gain_album != 0) { | ||
148 | int tmp = (int)((MPC_OLD_GAIN_REF - (mpc_int16_t)si->gain_album / 100.) * 256. + .5); | ||
149 | if (tmp >= (1 << 16) || tmp < 0) tmp = 0; | ||
150 | si->gain_album = (mpc_int16_t) tmp; | ||
151 | } | ||
152 | |||
153 | if (si->peak_title != 0) | ||
154 | si->peak_title = (mpc_uint16_t) (log10(si->peak_title) * 20 * 256 + .5); | ||
155 | |||
156 | if (si->peak_album != 0) | ||
157 | si->peak_album = (mpc_uint16_t) (log10(si->peak_album) * 20 * 256 + .5); | ||
158 | |||
159 | mpc_get_encoder_string(si); | ||
160 | */ | ||
161 | |||
162 | if (last_frame_samples == 0) last_frame_samples = MPC_FRAME_LENGTH; | ||
163 | else if (last_frame_samples > MPC_FRAME_LENGTH) return MPC_STATUS_FAIL; | ||
164 | si->samples = (mpc_int64_t) frames * MPC_FRAME_LENGTH; | ||
165 | if (si->is_true_gapless) | ||
166 | si->samples -= (MPC_FRAME_LENGTH - last_frame_samples); | ||
167 | else | ||
168 | si->samples -= MPC_DECODER_SYNTH_DELAY; | ||
169 | |||
170 | si->average_bitrate = 8LL * (si->tag_offset - si->header_position) | ||
171 | * si->sample_freq / si->samples; | ||
172 | |||
173 | return check_streaminfo(si); | ||
174 | } | ||
175 | |||
176 | /// Reads replay gain datas | ||
177 | void streaminfo_gain(mpc_streaminfo* si, const mpc_bits_reader * r_in) | ||
178 | { | ||
179 | mpc_bits_reader r = *r_in; | ||
180 | |||
181 | int version = mpc_bits_read(&r, 8); // gain version | ||
182 | if (version != 1) // we only know ver 1 | ||
183 | return; | ||
184 | si->gain_title = (mpc_uint16_t) mpc_bits_read(&r, 16); | ||
185 | si->peak_title = (mpc_uint16_t) mpc_bits_read(&r, 16); | ||
186 | si->gain_album = (mpc_uint16_t) mpc_bits_read(&r, 16); | ||
187 | si->peak_album = (mpc_uint16_t) mpc_bits_read(&r, 16); | ||
188 | } | ||
189 | |||
190 | /// Reads streaminfo from SV8 header. | ||
191 | mpc_status | ||
192 | streaminfo_read_header_sv8(mpc_streaminfo* si, const mpc_bits_reader * r_in, | ||
193 | mpc_size_t block_size) | ||
194 | { | ||
195 | mpc_uint32_t CRC; | ||
196 | mpc_bits_reader r = *r_in; | ||
197 | |||
198 | CRC = (mpc_bits_read(&r, 16) << 16) | mpc_bits_read(&r, 16); | ||
199 | if (CRC != mpc_crc32(r.buff + 1 - (r.count >> 3), (int)block_size - 4)) | ||
200 | return MPC_STATUS_FAIL; | ||
201 | |||
202 | si->stream_version = mpc_bits_read(&r, 8); | ||
203 | if (si->stream_version != 8) | ||
204 | return MPC_STATUS_FAIL; | ||
205 | |||
206 | mpc_bits_get_size(&r, &si->samples); | ||
207 | mpc_bits_get_size(&r, &si->beg_silence); | ||
208 | |||
209 | si->is_true_gapless = 1; | ||
210 | si->sample_freq = samplefreqs[mpc_bits_read(&r, 3)]; | ||
211 | si->max_band = mpc_bits_read(&r, 5) + 1; | ||
212 | si->channels = mpc_bits_read(&r, 4) + 1; | ||
213 | si->ms = mpc_bits_read(&r, 1); | ||
214 | si->block_pwr = mpc_bits_read(&r, 3) * 2; | ||
215 | |||
216 | si->bitrate = 0; | ||
217 | |||
218 | if ((si->samples - si->beg_silence) != 0) | ||
219 | si->average_bitrate = 8LL * (si->tag_offset - si->header_position) | ||
220 | * si->sample_freq / (si->samples - si->beg_silence); | ||
221 | |||
222 | return check_streaminfo(si); | ||
223 | } | ||
224 | |||
225 | /// Reads encoder informations | ||
226 | void streaminfo_encoder_info(mpc_streaminfo* si, const mpc_bits_reader * r_in) | ||
227 | { | ||
228 | mpc_bits_reader r = *r_in; | ||
229 | |||
230 | si->profile = mpc_bits_read(&r, 7); // to be divided by 8 | ||
231 | /* rockbox: not used | ||
232 | si->profile_name = mpc_get_version_string(si->profile); | ||
233 | */ | ||
234 | si->pns = mpc_bits_read(&r, 1); | ||
235 | si->encoder_version = mpc_bits_read(&r, 8) << 24; // major | ||
236 | si->encoder_version |= mpc_bits_read(&r, 8) << 16; // minor | ||
237 | si->encoder_version |= mpc_bits_read(&r, 8) << 8; // build | ||
238 | |||
239 | /* rockbox: not used | ||
240 | mpc_get_encoder_string(si); | ||
241 | */ | ||
242 | } | ||
243 | |||
244 | /* rockbox: not used | ||
245 | double | ||
246 | mpc_streaminfo_get_length(mpc_streaminfo * si) | ||
247 | { | ||
248 | return (double) (si->samples - si->beg_silence) / si->sample_freq; | ||
249 | } | ||
250 | |||
251 | mpc_int64_t mpc_streaminfo_get_length_samples(mpc_streaminfo *si) | ||
252 | { | ||
253 | return si->samples - si->beg_silence; | ||
254 | } | ||
255 | */ | ||
diff --git a/lib/rbcodec/codecs/libmusepack/streaminfo.h b/lib/rbcodec/codecs/libmusepack/streaminfo.h new file mode 100644 index 0000000000..52e97936a0 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/streaminfo.h | |||
@@ -0,0 +1,114 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005-2009, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | /// \file streaminfo.h | ||
35 | #ifndef _MPCDEC_STREAMINFO_H_ | ||
36 | #define _MPCDEC_STREAMINFO_H_ | ||
37 | #ifdef WIN32 | ||
38 | #pragma once | ||
39 | #endif | ||
40 | |||
41 | #include "mpc_types.h" | ||
42 | |||
43 | #ifdef __cplusplus | ||
44 | extern "C" { | ||
45 | #endif | ||
46 | |||
47 | |||
48 | typedef mpc_int32_t mpc_streaminfo_off_t; | ||
49 | |||
50 | /// \brief mpc stream properties structure | ||
51 | /// | ||
52 | /// Structure containing all the properties of an mpc stream. Populated | ||
53 | /// by the streaminfo_read function. | ||
54 | typedef struct mpc_streaminfo { | ||
55 | /// @name Core mpc stream properties | ||
56 | //@{ | ||
57 | mpc_uint32_t sample_freq; ///< Sample frequency of stream | ||
58 | mpc_uint32_t channels; ///< Number of channels in stream | ||
59 | mpc_uint32_t stream_version; ///< Streamversion of stream | ||
60 | mpc_uint32_t bitrate; ///< Bitrate of stream file (in bps) | ||
61 | mpc_uint32_t average_bitrate; ///< Average bitrate of stream (in bits/sec) | ||
62 | mpc_uint32_t max_band; ///< Maximum band-index used in stream (0...31) | ||
63 | mpc_uint32_t ms; ///< Mid/side stereo (0: off, 1: on) | ||
64 | mpc_uint32_t fast_seek; ///< True if stream supports fast-seeking (sv7) | ||
65 | mpc_uint32_t block_pwr; ///< Number of frames in a block = 2^block_pwr (sv8) | ||
66 | //@} | ||
67 | |||
68 | /// @name Replaygain properties | ||
69 | //@{ | ||
70 | mpc_uint16_t gain_title; ///< Replaygain title value | ||
71 | mpc_uint16_t gain_album; ///< Replaygain album value | ||
72 | mpc_uint16_t peak_album; ///< Peak album loudness level | ||
73 | mpc_uint16_t peak_title; ///< Peak title loudness level | ||
74 | //@} | ||
75 | |||
76 | /// @name True gapless properties | ||
77 | //@{ | ||
78 | mpc_uint32_t is_true_gapless; ///< True gapless? (0: no, 1: yes) | ||
79 | mpc_uint64_t samples; ///< Number of samples in the stream | ||
80 | mpc_uint64_t beg_silence; ///< Number of samples that must not be played at the beginning of the stream | ||
81 | //@} | ||
82 | |||
83 | /// @name Encoder informations | ||
84 | //@{ | ||
85 | mpc_uint32_t encoder_version; ///< Version of encoder used | ||
86 | /* rockbox: not used | ||
87 | char encoder[256]; ///< Encoder name | ||
88 | */ | ||
89 | mpc_bool_t pns; ///< pns used | ||
90 | mpc_uint32_t profile; ///< Quality profile of stream | ||
91 | /* rockbox: not used | ||
92 | const char* profile_name; ///< Name of profile used by stream | ||
93 | */ | ||
94 | //@} | ||
95 | |||
96 | |||
97 | mpc_streaminfo_off_t header_position; ///< Byte offset of position of header in stream | ||
98 | mpc_streaminfo_off_t tag_offset; ///< Offset to file tags | ||
99 | mpc_streaminfo_off_t total_file_length; ///< Total length of underlying file | ||
100 | } mpc_streaminfo; | ||
101 | |||
102 | /* rockbox: not used | ||
103 | /// Gets length of stream si, in seconds. | ||
104 | /// \return length of stream in seconds | ||
105 | MPC_API double mpc_streaminfo_get_length(mpc_streaminfo *si); | ||
106 | |||
107 | /// Returns length of stream si, in samples. | ||
108 | /// \return length of stream in samples | ||
109 | MPC_API mpc_int64_t mpc_streaminfo_get_length_samples(mpc_streaminfo *si); | ||
110 | */ | ||
111 | #ifdef __cplusplus | ||
112 | } | ||
113 | #endif | ||
114 | #endif | ||
diff --git a/lib/rbcodec/codecs/libmusepack/synth_filter.c b/lib/rbcodec/codecs/libmusepack/synth_filter.c new file mode 100644 index 0000000000..3ad2b236a0 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/synth_filter.c | |||
@@ -0,0 +1,610 @@ | |||
1 | /* | ||
2 | Copyright (c) 2005, The Musepack Development Team | ||
3 | All rights reserved. | ||
4 | |||
5 | Redistribution and use in source and binary forms, with or without | ||
6 | modification, are permitted provided that the following conditions are | ||
7 | met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright | ||
10 | notice, this list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above | ||
13 | copyright notice, this list of conditions and the following | ||
14 | disclaimer in the documentation and/or other materials provided | ||
15 | with the distribution. | ||
16 | |||
17 | * Neither the name of the The Musepack Development Team nor the | ||
18 | names of its contributors may be used to endorse or promote | ||
19 | products derived from this software without specific prior | ||
20 | written permission. | ||
21 | |||
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
26 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
28 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
29 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
30 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
33 | */ | ||
34 | |||
35 | /// \file synth_filter.c | ||
36 | /// Synthesis functions. | ||
37 | /// \todo document me | ||
38 | #include <string.h> | ||
39 | #include <codecs.h> | ||
40 | #include "mpcdec.h" | ||
41 | #include "decoder.h" | ||
42 | #include "mpcdec_math.h" | ||
43 | #include "internal.h" | ||
44 | |||
45 | /* C O N S T A N T S */ | ||
46 | #undef _ | ||
47 | |||
48 | #if defined(MPC_FIXED_POINT) | ||
49 | #if defined(CPU_ARM) | ||
50 | #if ARM_ARCH >= 6 | ||
51 | // on ARMv6 we use 32*32=64>>32 multiplies (smmul/smmla) so we need to scale up the D coefficients | ||
52 | // the ARM11 multiplier doesn't have early termination so the magnitude of the multiplicands does not | ||
53 | // matter for speed. | ||
54 | #define D(value) (value << (14)) | ||
55 | #else | ||
56 | // do not up-scale D-values to achieve higher speed in smull/mlal | ||
57 | // operations. saves ~14/8 = 1.75 cycles per multiplication | ||
58 | #define D(value) (value) | ||
59 | #endif | ||
60 | // in this configuration a post-shift by >>16 is needed after synthesis | ||
61 | #else | ||
62 | // saturate to +/- 2^31 (= value << (31-17)), D-values are +/- 2^17 | ||
63 | #define D(value) (value << (14)) | ||
64 | #endif | ||
65 | #else | ||
66 | // IMPORTANT: internal scaling is somehow strange for floating point, therefore we scale the coefficients Di_opt | ||
67 | // by the correct amount to have proper scaled output | ||
68 | #define D(value) MAKE_MPC_SAMPLE((double)value*(double)(0x1000)) | ||
69 | #endif | ||
70 | |||
71 | // Di_opt coefficients are +/- 2^17 (pre-shifted by <<16) | ||
72 | static const MPC_SAMPLE_FORMAT Di_opt [512] ICONST_ATTR MEM_ALIGN_ATTR = { | ||
73 | /* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */ | ||
74 | /* 0 */ D( 0), -D( 29), D(213), -D( 459), D(2037), -D(5153), D( 6574), -D(37489), D(75038), D(37489), D(6574), D(5153), D(2037), D(459), D(213), D(29), | ||
75 | /* 1 */ -D( 1), -D( 31), D(218), -D( 519), D(2000), -D(5517), D( 5959), -D(39336), D(74992), D(35640), D(7134), D(4788), D(2063), D(401), D(208), D(26), | ||
76 | /* 2 */ -D( 1), -D( 35), D(222), -D( 581), D(1952), -D(5879), D( 5288), -D(41176), D(74856), D(33791), D(7640), D(4425), D(2080), D(347), D(202), D(24), | ||
77 | /* 3 */ -D( 1), -D( 38), D(225), -D( 645), D(1893), -D(6237), D( 4561), -D(43006), D(74630), D(31947), D(8092), D(4063), D(2087), D(294), D(196), D(21), | ||
78 | /* 4 */ -D( 1), -D( 41), D(227), -D( 711), D(1822), -D(6589), D( 3776), -D(44821), D(74313), D(30112), D(8492), D(3705), D(2085), D(244), D(190), D(19), | ||
79 | /* 5 */ -D( 1), -D( 45), D(228), -D( 779), D(1739), -D(6935), D( 2935), -D(46617), D(73908), D(28289), D(8840), D(3351), D(2075), D(197), D(183), D(17), | ||
80 | /* 6 */ -D( 1), -D( 49), D(228), -D( 848), D(1644), -D(7271), D( 2037), -D(48390), D(73415), D(26482), D(9139), D(3004), D(2057), D(153), D(176), D(16), | ||
81 | /* 7 */ -D( 2), -D( 53), D(227), -D( 919), D(1535), -D(7597), D( 1082), -D(50137), D(72835), D(24694), D(9389), D(2663), D(2032), D(111), D(169), D(14), | ||
82 | /* 8 */ -D( 2), -D( 58), D(224), -D( 991), D(1414), -D(7910), D( 70), -D(51853), D(72169), D(22929), D(9592), D(2330), D(2001), D( 72), D(161), D(13), | ||
83 | /* 9 */ -D( 2), -D( 63), D(221), -D(1064), D(1280), -D(8209), -D( 998), -D(53534), D(71420), D(21189), D(9750), D(2006), D(1962), D( 36), D(154), D(11), | ||
84 | /* 10 */ -D( 2), -D( 68), D(215), -D(1137), D(1131), -D(8491), -D( 2122), -D(55178), D(70590), D(19478), D(9863), D(1692), D(1919), D( 2), D(147), D(10), | ||
85 | /* 11 */ -D( 3), -D( 73), D(208), -D(1210), D( 970), -D(8755), -D( 3300), -D(56778), D(69679), D(17799), D(9935), D(1388), D(1870), -D( 29), D(139), D( 9), | ||
86 | /* 12 */ -D( 3), -D( 79), D(200), -D(1283), D( 794), -D(8998), -D( 4533), -D(58333), D(68692), D(16155), D(9966), D(1095), D(1817), -D( 57), D(132), D( 8), | ||
87 | /* 13 */ -D( 4), -D( 85), D(189), -D(1356), D( 605), -D(9219), -D( 5818), -D(59838), D(67629), D(14548), D(9959), D( 814), D(1759), -D( 83), D(125), D( 7), | ||
88 | /* 14 */ -D( 4), -D( 91), D(177), -D(1428), D( 402), -D(9416), -D( 7154), -D(61289), D(66494), D(12980), D(9916), D( 545), D(1698), -D(106), D(117), D( 7), | ||
89 | /* 15 */ -D( 5), -D( 97), D(163), -D(1498), D( 185), -D(9585), -D( 8540), -D(62684), D(65290), D(11455), D(9838), D( 288), D(1634), -D(127), D(111), D( 6), | ||
90 | /* 16 */ -D( 5), -D(104), D(146), -D(1567), -D( 45), -D(9727), -D( 9975), -D(64019), D(64019), D( 9975), D(9727), D( 45), D(1567), -D(146), D(104), D( 5), | ||
91 | /* 17 */ -D( 6), -D(111), D(127), -D(1634), -D( 288), -D(9838), -D(11455), -D(65290), D(62684), D( 8540), D(9585), -D( 185), D(1498), -D(163), D( 97), D( 5), | ||
92 | /* 18 */ -D( 7), -D(117), D(106), -D(1698), -D( 545), -D(9916), -D(12980), -D(66494), D(61289), D( 7154), D(9416), -D( 402), D(1428), -D(177), D( 91), D( 4), | ||
93 | /* 19 */ -D( 7), -D(125), D( 83), -D(1759), -D( 814), -D(9959), -D(14548), -D(67629), D(59838), D( 5818), D(9219), -D( 605), D(1356), -D(189), D( 85), D( 4), | ||
94 | /* 20 */ -D( 8), -D(132), D( 57), -D(1817), -D(1095), -D(9966), -D(16155), -D(68692), D(58333), D( 4533), D(8998), -D( 794), D(1283), -D(200), D( 79), D( 3), | ||
95 | /* 21 */ -D( 9), -D(139), D( 29), -D(1870), -D(1388), -D(9935), -D(17799), -D(69679), D(56778), D( 3300), D(8755), -D( 970), D(1210), -D(208), D( 73), D( 3), | ||
96 | /* 22 */ -D(10), -D(147), -D( 2), -D(1919), -D(1692), -D(9863), -D(19478), -D(70590), D(55178), D( 2122), D(8491), -D(1131), D(1137), -D(215), D( 68), D( 2), | ||
97 | /* 23 */ -D(11), -D(154), -D( 36), -D(1962), -D(2006), -D(9750), -D(21189), -D(71420), D(53534), D( 998), D(8209), -D(1280), D(1064), -D(221), D( 63), D( 2), | ||
98 | /* 24 */ -D(13), -D(161), -D( 72), -D(2001), -D(2330), -D(9592), -D(22929), -D(72169), D(51853), -D( 70), D(7910), -D(1414), D( 991), -D(224), D( 58), D( 2), | ||
99 | /* 25 */ -D(14), -D(169), -D(111), -D(2032), -D(2663), -D(9389), -D(24694), -D(72835), D(50137), -D( 1082), D(7597), -D(1535), D( 919), -D(227), D( 53), D( 2), | ||
100 | /* 26 */ -D(16), -D(176), -D(153), -D(2057), -D(3004), -D(9139), -D(26482), -D(73415), D(48390), -D( 2037), D(7271), -D(1644), D( 848), -D(228), D( 49), D( 1), | ||
101 | /* 27 */ -D(17), -D(183), -D(197), -D(2075), -D(3351), -D(8840), -D(28289), -D(73908), D(46617), -D( 2935), D(6935), -D(1739), D( 779), -D(228), D( 45), D( 1), | ||
102 | /* 28 */ -D(19), -D(190), -D(244), -D(2085), -D(3705), -D(8492), -D(30112), -D(74313), D(44821), -D( 3776), D(6589), -D(1822), D( 711), -D(227), D( 41), D( 1), | ||
103 | /* 29 */ -D(21), -D(196), -D(294), -D(2087), -D(4063), -D(8092), -D(31947), -D(74630), D(43006), -D( 4561), D(6237), -D(1893), D( 645), -D(225), D( 38), D( 1), | ||
104 | /* 30 */ -D(24), -D(202), -D(347), -D(2080), -D(4425), -D(7640), -D(33791), -D(74856), D(41176), -D( 5288), D(5879), -D(1952), D( 581), -D(222), D( 35), D( 1), | ||
105 | /* 31 */ -D(26), -D(208), -D(401), -D(2063), -D(4788), -D(7134), -D(35640), -D(74992), D(39336), -D( 5959), D(5517), -D(2000), D( 519), -D(218), D( 31), D( 1) | ||
106 | }; | ||
107 | |||
108 | #undef D | ||
109 | |||
110 | // DCT32-coefficients were expanded (<<) by DCT32_COEFFICIENT_EXPAND | ||
111 | #define DCT32_COEFFICIENT_EXPAND 31 | ||
112 | |||
113 | #if defined(MPC_FIXED_POINT) | ||
114 | // define 64=32x32-multiplication for DCT-coefficients with samples. Via usage of MPC_FRACT highly optimized assembler might be used | ||
115 | // MULTIPLY_FRACT will perform >>32 after multiplication, as coef were expanded by DCT32_COEFFICIENT_EXPAND we'll correct this on the result. | ||
116 | // Will loose 4 bit accuracy on result in fract part without effect on final audio result | ||
117 | #define MPC_DCT32_MUL(sample, coef) (MPC_MULTIPLY_FRACT(sample,coef) << (32-DCT32_COEFFICIENT_EXPAND)) | ||
118 | #define MPC_DCT32_SHIFT(sample) (sample) | ||
119 | #else | ||
120 | // for floating point use the standard multiplication macro | ||
121 | #define MPC_DCT32_MUL(sample, coef) (MPC_MULTIPLY(sample, coef) ) | ||
122 | #define MPC_DCT32_SHIFT(sample) (sample) | ||
123 | #endif | ||
124 | |||
125 | /****************************************************************************** | ||
126 | * mpc_dct32(const int *in, int *out) | ||
127 | * | ||
128 | * mpc_dct32 is a dct32 with in[32]->dct[32] that contains the mirroring from | ||
129 | * dct[32] to the expected out[64]. The symmetry is | ||
130 | * out[16] = 0, | ||
131 | * out[ 0..15] = dct[ 0..15], | ||
132 | * out[32..17] = -dct[ 0..15], | ||
133 | * out[33..48] = -dct[16..31], | ||
134 | * out[63..48] = -dct[16..31]. | ||
135 | * The cos-tab has the format s0.31. | ||
136 | *****************************************************************************/ | ||
137 | void | ||
138 | mpc_dct32(const MPC_SAMPLE_FORMAT *in, MPC_SAMPLE_FORMAT *v) | ||
139 | ICODE_ATTR_MPC_LARGE_IRAM; | ||
140 | |||
141 | void | ||
142 | mpc_dct32(const MPC_SAMPLE_FORMAT *in, MPC_SAMPLE_FORMAT *v) | ||
143 | { | ||
144 | MPC_SAMPLE_FORMAT t0, t1, t2, t3, t4, t5, t6, t7; | ||
145 | MPC_SAMPLE_FORMAT t8, t9, t10, t11, t12, t13, t14, t15; | ||
146 | MPC_SAMPLE_FORMAT t16, t17, t18, t19, t20, t21, t22, t23; | ||
147 | MPC_SAMPLE_FORMAT t24, t25, t26, t27, t28, t29, t30, t31; | ||
148 | MPC_SAMPLE_FORMAT t32, t33, t34, t35, t36, t37, t38, t39; | ||
149 | MPC_SAMPLE_FORMAT t40, t41, t42, t43, t44, t45, t46, t47; | ||
150 | MPC_SAMPLE_FORMAT t48, t49, t50, t51, t52, t53, t54, t55; | ||
151 | MPC_SAMPLE_FORMAT t56, t57, t58, t59, t60, t61, t62, t63; | ||
152 | MPC_SAMPLE_FORMAT t64, t65, t66, t67, t68, t69, t70, t71; | ||
153 | MPC_SAMPLE_FORMAT t72, t73, t74, t75, t76, t77, t78, t79; | ||
154 | MPC_SAMPLE_FORMAT t80, t81, t82, t83, t84, t85, t86, t87; | ||
155 | MPC_SAMPLE_FORMAT t88, t89, t90, t91, t92, t93, t94, t95; | ||
156 | MPC_SAMPLE_FORMAT t96, t97, t98, t99, t100, t101, t102, t103; | ||
157 | MPC_SAMPLE_FORMAT t104, t105, t106, t107, t108, t109, t110, t111; | ||
158 | MPC_SAMPLE_FORMAT t112, t113, t114, t115, t116, t117, t118, t119; | ||
159 | MPC_SAMPLE_FORMAT t120, t121, t122, t123, t124, t125, t126, t127; | ||
160 | MPC_SAMPLE_FORMAT t128, t129, t130, t131, t132, t133, t134, t135; | ||
161 | MPC_SAMPLE_FORMAT t136, t137, t138, t139, t140, t141, t142, t143; | ||
162 | MPC_SAMPLE_FORMAT t144, t145, t146, t147, t148, t149, t150, t151; | ||
163 | MPC_SAMPLE_FORMAT t152, t153, t154, t155, t156, t157, t158, t159; | ||
164 | MPC_SAMPLE_FORMAT t160, t161, t162, t163, t164, t165, t166, t167; | ||
165 | MPC_SAMPLE_FORMAT t168, t169, t170, t171, t172, t173, t174, t175; | ||
166 | MPC_SAMPLE_FORMAT t176; | ||
167 | |||
168 | /* costab[i] = cos(PI / (2 * 32) * i) */ | ||
169 | #define costab01 (0x7fd8878e) /* 0.998795456 */ | ||
170 | #define costab02 (0x7f62368f) /* 0.995184727 */ | ||
171 | #define costab03 (0x7e9d55fc) /* 0.989176510 */ | ||
172 | #define costab04 (0x7d8a5f40) /* 0.980785280 */ | ||
173 | #define costab05 (0x7c29fbee) /* 0.970031253 */ | ||
174 | #define costab06 (0x7a7d055b) /* 0.956940336 */ | ||
175 | #define costab07 (0x78848414) /* 0.941544065 */ | ||
176 | #define costab08 (0x7641af3d) /* 0.923879533 */ | ||
177 | #define costab09 (0x73b5ebd1) /* 0.903989293 */ | ||
178 | #define costab10 (0x70e2cbc6) /* 0.881921264 */ | ||
179 | #define costab11 (0x6dca0d14) /* 0.857728610 */ | ||
180 | #define costab12 (0x6a6d98a4) /* 0.831469612 */ | ||
181 | #define costab13 (0x66cf8120) /* 0.803207531 */ | ||
182 | #define costab14 (0x62f201ac) /* 0.773010453 */ | ||
183 | #define costab15 (0x5ed77c8a) /* 0.740951125 */ | ||
184 | #define costab16 (0x5a82799a) /* 0.707106781 */ | ||
185 | #define costab17 (0x55f5a4d2) /* 0.671558955 */ | ||
186 | #define costab18 (0x5133cc94) /* 0.634393284 */ | ||
187 | #define costab19 (0x4c3fdff4) /* 0.595699304 */ | ||
188 | #define costab20 (0x471cece7) /* 0.555570233 */ | ||
189 | #define costab21 (0x41ce1e65) /* 0.514102744 */ | ||
190 | #define costab22 (0x3c56ba70) /* 0.471396737 */ | ||
191 | #define costab23 (0x36ba2014) /* 0.427555093 */ | ||
192 | #define costab24 (0x30fbc54d) /* 0.382683432 */ | ||
193 | #define costab25 (0x2b1f34eb) /* 0.336889853 */ | ||
194 | #define costab26 (0x25280c5e) /* 0.290284677 */ | ||
195 | #define costab27 (0x1f19f97b) /* 0.242980180 */ | ||
196 | #define costab28 (0x18f8b83c) /* 0.195090322 */ | ||
197 | #define costab29 (0x12c8106f) /* 0.146730474 */ | ||
198 | #define costab30 (0x0c8bd35e) /* 0.098017140 */ | ||
199 | #define costab31 (0x0647d97c) /* 0.049067674 */ | ||
200 | |||
201 | t0 = in[ 0] + in[31]; t16 = MPC_DCT32_MUL(in[ 0] - in[31], costab01); | ||
202 | t1 = in[15] + in[16]; t17 = MPC_DCT32_MUL(in[15] - in[16], costab31); | ||
203 | |||
204 | t41 = t16 + t17; | ||
205 | t59 = MPC_DCT32_MUL(t16 - t17, costab02); | ||
206 | t33 = t0 + t1; | ||
207 | t50 = MPC_DCT32_MUL(t0 - t1, costab02); | ||
208 | |||
209 | t2 = in[ 7] + in[24]; t18 = MPC_DCT32_MUL(in[ 7] - in[24], costab15); | ||
210 | t3 = in[ 8] + in[23]; t19 = MPC_DCT32_MUL(in[ 8] - in[23], costab17); | ||
211 | |||
212 | t42 = t18 + t19; | ||
213 | t60 = MPC_DCT32_MUL(t18 - t19, costab30); | ||
214 | t34 = t2 + t3; | ||
215 | t51 = MPC_DCT32_MUL(t2 - t3, costab30); | ||
216 | |||
217 | t4 = in[ 3] + in[28]; t20 = MPC_DCT32_MUL(in[ 3] - in[28], costab07); | ||
218 | t5 = in[12] + in[19]; t21 = MPC_DCT32_MUL(in[12] - in[19], costab25); | ||
219 | |||
220 | t43 = t20 + t21; | ||
221 | t61 = MPC_DCT32_MUL(t20 - t21, costab14); | ||
222 | t35 = t4 + t5; | ||
223 | t52 = MPC_DCT32_MUL(t4 - t5, costab14); | ||
224 | |||
225 | t6 = in[ 4] + in[27]; t22 = MPC_DCT32_MUL(in[ 4] - in[27], costab09); | ||
226 | t7 = in[11] + in[20]; t23 = MPC_DCT32_MUL(in[11] - in[20], costab23); | ||
227 | |||
228 | t44 = t22 + t23; | ||
229 | t62 = MPC_DCT32_MUL(t22 - t23, costab18); | ||
230 | t36 = t6 + t7; | ||
231 | t53 = MPC_DCT32_MUL(t6 - t7, costab18); | ||
232 | |||
233 | t8 = in[ 1] + in[30]; t24 = MPC_DCT32_MUL(in[ 1] - in[30], costab03); | ||
234 | t9 = in[14] + in[17]; t25 = MPC_DCT32_MUL(in[14] - in[17], costab29); | ||
235 | |||
236 | t45 = t24 + t25; | ||
237 | t63 = MPC_DCT32_MUL(t24 - t25, costab06); | ||
238 | t37 = t8 + t9; | ||
239 | t54 = MPC_DCT32_MUL(t8 - t9, costab06); | ||
240 | |||
241 | t10 = in[ 6] + in[25]; t26 = MPC_DCT32_MUL(in[ 6] - in[25], costab13); | ||
242 | t11 = in[ 9] + in[22]; t27 = MPC_DCT32_MUL(in[ 9] - in[22], costab19); | ||
243 | |||
244 | t46 = t26 + t27; | ||
245 | t64 = MPC_DCT32_MUL(t26 - t27, costab26); | ||
246 | t38 = t10 + t11; | ||
247 | t55 = MPC_DCT32_MUL(t10 - t11, costab26); | ||
248 | |||
249 | t12 = in[ 2] + in[29]; t28 = MPC_DCT32_MUL(in[ 2] - in[29], costab05); | ||
250 | t13 = in[13] + in[18]; t29 = MPC_DCT32_MUL(in[13] - in[18], costab27); | ||
251 | |||
252 | t47 = t28 + t29; | ||
253 | t65 = MPC_DCT32_MUL(t28 - t29, costab10); | ||
254 | t39 = t12 + t13; | ||
255 | t56 = MPC_DCT32_MUL(t12 - t13, costab10); | ||
256 | |||
257 | t14 = in[ 5] + in[26]; t30 = MPC_DCT32_MUL(in[ 5] - in[26], costab11); | ||
258 | t15 = in[10] + in[21]; t31 = MPC_DCT32_MUL(in[10] - in[21], costab21); | ||
259 | |||
260 | t48 = t30 + t31; | ||
261 | t66 = MPC_DCT32_MUL(t30 - t31, costab22); | ||
262 | t40 = t14 + t15; | ||
263 | t57 = MPC_DCT32_MUL(t14 - t15, costab22); | ||
264 | |||
265 | t69 = t33 + t34; t89 = MPC_DCT32_MUL(t33 - t34, costab04); | ||
266 | t70 = t35 + t36; t90 = MPC_DCT32_MUL(t35 - t36, costab28); | ||
267 | t71 = t37 + t38; t91 = MPC_DCT32_MUL(t37 - t38, costab12); | ||
268 | t72 = t39 + t40; t92 = MPC_DCT32_MUL(t39 - t40, costab20); | ||
269 | t73 = t41 + t42; t94 = MPC_DCT32_MUL(t41 - t42, costab04); | ||
270 | t74 = t43 + t44; t95 = MPC_DCT32_MUL(t43 - t44, costab28); | ||
271 | t75 = t45 + t46; t96 = MPC_DCT32_MUL(t45 - t46, costab12); | ||
272 | t76 = t47 + t48; t97 = MPC_DCT32_MUL(t47 - t48, costab20); | ||
273 | |||
274 | t78 = t50 + t51; t100 = MPC_DCT32_MUL(t50 - t51, costab04); | ||
275 | t79 = t52 + t53; t101 = MPC_DCT32_MUL(t52 - t53, costab28); | ||
276 | t80 = t54 + t55; t102 = MPC_DCT32_MUL(t54 - t55, costab12); | ||
277 | t81 = t56 + t57; t103 = MPC_DCT32_MUL(t56 - t57, costab20); | ||
278 | |||
279 | t83 = t59 + t60; t106 = MPC_DCT32_MUL(t59 - t60, costab04); | ||
280 | t84 = t61 + t62; t107 = MPC_DCT32_MUL(t61 - t62, costab28); | ||
281 | t85 = t63 + t64; t108 = MPC_DCT32_MUL(t63 - t64, costab12); | ||
282 | t86 = t65 + t66; t109 = MPC_DCT32_MUL(t65 - t66, costab20); | ||
283 | |||
284 | t113 = t69 + t70; | ||
285 | t114 = t71 + t72; | ||
286 | |||
287 | /* 0 */ v[48] = -MPC_DCT32_SHIFT(t113 + t114); | ||
288 | /* 16 */ v[32] = -(v[ 0] = MPC_DCT32_SHIFT(MPC_DCT32_MUL(t113 - t114, costab16))); | ||
289 | |||
290 | t115 = t73 + t74; | ||
291 | t116 = t75 + t76; | ||
292 | |||
293 | t32 = t115 + t116; | ||
294 | |||
295 | /* 1 */ v[49] = v[47] = -MPC_DCT32_SHIFT(t32); | ||
296 | |||
297 | t118 = t78 + t79; | ||
298 | t119 = t80 + t81; | ||
299 | |||
300 | t58 = t118 + t119; | ||
301 | |||
302 | /* 2 */ v[50] = v[46] = -MPC_DCT32_SHIFT(t58); | ||
303 | |||
304 | t121 = t83 + t84; | ||
305 | t122 = t85 + t86; | ||
306 | |||
307 | t67 = t121 + t122; | ||
308 | |||
309 | t49 = (t67 * 2) - t32; | ||
310 | |||
311 | /* 3 */ v[51] = v[45] = -MPC_DCT32_SHIFT(t49); | ||
312 | |||
313 | t125 = t89 + t90; | ||
314 | t126 = t91 + t92; | ||
315 | |||
316 | t93 = t125 + t126; | ||
317 | |||
318 | /* 4 */ v[52] = v[44] = -MPC_DCT32_SHIFT(t93); | ||
319 | |||
320 | t128 = t94 + t95; | ||
321 | t129 = t96 + t97; | ||
322 | |||
323 | t98 = t128 + t129; | ||
324 | |||
325 | t68 = (t98 * 2) - t49; | ||
326 | |||
327 | /* 5 */ v[53] = v[43] = -MPC_DCT32_SHIFT(t68); | ||
328 | |||
329 | t132 = t100 + t101; | ||
330 | t133 = t102 + t103; | ||
331 | |||
332 | t104 = t132 + t133; | ||
333 | |||
334 | t82 = (t104 * 2) - t58; | ||
335 | |||
336 | /* 6 */ v[54] = v[42] = -MPC_DCT32_SHIFT(t82); | ||
337 | |||
338 | t136 = t106 + t107; | ||
339 | t137 = t108 + t109; | ||
340 | |||
341 | t110 = t136 + t137; | ||
342 | |||
343 | t87 = (t110 * 2) - t67; | ||
344 | |||
345 | t77 = (t87 * 2) - t68; | ||
346 | |||
347 | /* 7 */ v[55] = v[41] = -MPC_DCT32_SHIFT(t77); | ||
348 | |||
349 | t141 = MPC_DCT32_MUL(t69 - t70, costab08); | ||
350 | t142 = MPC_DCT32_MUL(t71 - t72, costab24); | ||
351 | t143 = t141 + t142; | ||
352 | |||
353 | /* 8 */ v[56] = v[40] = -MPC_DCT32_SHIFT(t143); | ||
354 | /* 24 */ v[24] = -(v[ 8] = MPC_DCT32_SHIFT((MPC_DCT32_MUL(t141 - t142, costab16) * 2) - t143)); | ||
355 | |||
356 | t144 = MPC_DCT32_MUL(t73 - t74, costab08); | ||
357 | t145 = MPC_DCT32_MUL(t75 - t76, costab24); | ||
358 | t146 = t144 + t145; | ||
359 | |||
360 | t88 = (t146 * 2) - t77; | ||
361 | |||
362 | /* 9 */ v[57] = v[39] = -MPC_DCT32_SHIFT(t88); | ||
363 | |||
364 | t148 = MPC_DCT32_MUL(t78 - t79, costab08); | ||
365 | t149 = MPC_DCT32_MUL(t80 - t81, costab24); | ||
366 | t150 = t148 + t149; | ||
367 | |||
368 | t105 = (t150 * 2) - t82; | ||
369 | |||
370 | /* 10 */ v[58] = v[38] = -MPC_DCT32_SHIFT(t105); | ||
371 | |||
372 | t152 = MPC_DCT32_MUL(t83 - t84, costab08); | ||
373 | t153 = MPC_DCT32_MUL(t85 - t86, costab24); | ||
374 | t154 = t152 + t153; | ||
375 | |||
376 | t111 = (t154 * 2) - t87; | ||
377 | |||
378 | t99 = (t111 * 2) - t88; | ||
379 | |||
380 | /* 11 */ v[59] = v[37] = -MPC_DCT32_SHIFT(t99); | ||
381 | |||
382 | t157 = MPC_DCT32_MUL(t89 - t90, costab08); | ||
383 | t158 = MPC_DCT32_MUL(t91 - t92, costab24); | ||
384 | t159 = t157 + t158; | ||
385 | |||
386 | t127 = (t159 * 2) - t93; | ||
387 | |||
388 | /* 12 */ v[60] = v[36] = -MPC_DCT32_SHIFT(t127); | ||
389 | |||
390 | t160 = (MPC_DCT32_MUL(t125 - t126, costab16) * 2) - t127; | ||
391 | |||
392 | /* 20 */ v[28] = -(v[ 4] = MPC_DCT32_SHIFT(t160)); | ||
393 | /* 28 */ v[20] = -(v[12] = MPC_DCT32_SHIFT((((MPC_DCT32_MUL(t157 - t158, costab16) * 2) - t159) * 2) - t160)); | ||
394 | |||
395 | t161 = MPC_DCT32_MUL(t94 - t95, costab08); | ||
396 | t162 = MPC_DCT32_MUL(t96 - t97, costab24); | ||
397 | t163 = t161 + t162; | ||
398 | |||
399 | t130 = (t163 * 2) - t98; | ||
400 | |||
401 | t112 = (t130 * 2) - t99; | ||
402 | |||
403 | /* 13 */ v[61] = v[35] = -MPC_DCT32_SHIFT(t112); | ||
404 | |||
405 | t164 = (MPC_DCT32_MUL(t128 - t129, costab16) * 2) - t130; | ||
406 | |||
407 | t166 = MPC_DCT32_MUL(t100 - t101, costab08); | ||
408 | t167 = MPC_DCT32_MUL(t102 - t103, costab24); | ||
409 | t168 = t166 + t167; | ||
410 | |||
411 | t134 = (t168 * 2) - t104; | ||
412 | |||
413 | t120 = (t134 * 2) - t105; | ||
414 | |||
415 | /* 14 */ v[62] = v[34] = -MPC_DCT32_SHIFT(t120); | ||
416 | |||
417 | t135 = (MPC_DCT32_MUL(t118 - t119, costab16) * 2) - t120; | ||
418 | |||
419 | /* 18 */ v[30] = -(v[ 2] = MPC_DCT32_SHIFT(t135)); | ||
420 | |||
421 | t169 = (MPC_DCT32_MUL(t132 - t133, costab16) * 2) - t134; | ||
422 | |||
423 | t151 = (t169 * 2) - t135; | ||
424 | |||
425 | /* 22 */ v[26] = -(v[ 6] = MPC_DCT32_SHIFT(t151)); | ||
426 | |||
427 | t170 = (((MPC_DCT32_MUL(t148 - t149, costab16) * 2) - t150) * 2) - t151; | ||
428 | |||
429 | /* 26 */ v[22] = -(v[10] = MPC_DCT32_SHIFT(t170)); | ||
430 | /* 30 */ v[18] = -(v[14] = MPC_DCT32_SHIFT((((((MPC_DCT32_MUL(t166 - t167, costab16) * 2) - t168) * 2) - t169) * 2) - t170)); | ||
431 | |||
432 | t171 = MPC_DCT32_MUL(t106 - t107, costab08); | ||
433 | t172 = MPC_DCT32_MUL(t108 - t109, costab24); | ||
434 | t173 = t171 + t172; | ||
435 | |||
436 | t138 = (t173 * 2) - t110; | ||
437 | |||
438 | t123 = (t138 * 2) - t111; | ||
439 | |||
440 | t139 = (MPC_DCT32_MUL(t121 - t122, costab16) * 2) - t123; | ||
441 | |||
442 | t117 = (t123 * 2) - t112; | ||
443 | |||
444 | /* 15 */ v[63] = v[33] =-MPC_DCT32_SHIFT(t117); | ||
445 | |||
446 | t124 = (MPC_DCT32_MUL(t115 - t116, costab16) * 2) - t117; | ||
447 | |||
448 | /* 17 */ v[31] = -(v[ 1] = MPC_DCT32_SHIFT(t124)); | ||
449 | |||
450 | t131 = (t139 * 2) - t124; | ||
451 | |||
452 | /* 19 */ v[29] = -(v[ 3] = MPC_DCT32_SHIFT(t131)); | ||
453 | |||
454 | t140 = (t164 * 2) - t131; | ||
455 | |||
456 | /* 21 */ v[27] = -(v[ 5] = MPC_DCT32_SHIFT(t140)); | ||
457 | |||
458 | t174 = (MPC_DCT32_MUL(t136 - t137, costab16) * 2) - t138; | ||
459 | |||
460 | t155 = (t174 * 2) - t139; | ||
461 | |||
462 | t147 = (t155 * 2) - t140; | ||
463 | |||
464 | /* 23 */ v[25] = -(v[ 7] = MPC_DCT32_SHIFT(t147)); | ||
465 | |||
466 | t156 = (((MPC_DCT32_MUL(t144 - t145, costab16) * 2) - t146) * 2) - t147; | ||
467 | |||
468 | /* 25 */ v[23] = -(v[ 9] = MPC_DCT32_SHIFT(t156)); | ||
469 | |||
470 | t175 = (((MPC_DCT32_MUL(t152 - t153, costab16) * 2) - t154) * 2) - t155; | ||
471 | |||
472 | t165 = (t175 * 2) - t156; | ||
473 | |||
474 | /* 27 */ v[21] = -(v[11] = MPC_DCT32_SHIFT(t165)); | ||
475 | |||
476 | t176 = (((((MPC_DCT32_MUL(t161 - t162, costab16) * 2) - t163) * 2) - t164) * 2) - t165; | ||
477 | |||
478 | /* 29 */ v[19] = -(v[13] = MPC_DCT32_SHIFT(t176)); | ||
479 | /* 31 */ v[17] = -(v[15] = MPC_DCT32_SHIFT((((((((MPC_DCT32_MUL(t171 - t172, costab16) * 2) - t173) * 2) - t174) * 2) - t175) * 2) - t176)); | ||
480 | } | ||
481 | |||
482 | #if defined(CPU_ARM) || defined(CPU_COLDFIRE) | ||
483 | extern void | ||
484 | mpc_decoder_windowing_D(MPC_SAMPLE_FORMAT * Data, | ||
485 | const MPC_SAMPLE_FORMAT * V, | ||
486 | const MPC_SAMPLE_FORMAT * D); | ||
487 | #else | ||
488 | static void | ||
489 | mpc_decoder_windowing_D(MPC_SAMPLE_FORMAT * Data, | ||
490 | const MPC_SAMPLE_FORMAT * V, | ||
491 | const MPC_SAMPLE_FORMAT * D) | ||
492 | { | ||
493 | mpc_int32_t k; | ||
494 | |||
495 | // 64=64x64-multiply (FIXED_POINT) or float=float*float (!FIXED_POINT) in C | ||
496 | for ( k = 0; k < 32; k++, D += 16, V++ ) | ||
497 | { | ||
498 | *Data = MPC_MULTIPLY_EX(V[ 0],D[ 0],30) + MPC_MULTIPLY_EX(V[ 96],D[ 1],30) | ||
499 | + MPC_MULTIPLY_EX(V[128],D[ 2],30) + MPC_MULTIPLY_EX(V[224],D[ 3],30) | ||
500 | + MPC_MULTIPLY_EX(V[256],D[ 4],30) + MPC_MULTIPLY_EX(V[352],D[ 5],30) | ||
501 | + MPC_MULTIPLY_EX(V[384],D[ 6],30) + MPC_MULTIPLY_EX(V[480],D[ 7],30) | ||
502 | + MPC_MULTIPLY_EX(V[512],D[ 8],30) + MPC_MULTIPLY_EX(V[608],D[ 9],30) | ||
503 | + MPC_MULTIPLY_EX(V[640],D[10],30) + MPC_MULTIPLY_EX(V[736],D[11],30) | ||
504 | + MPC_MULTIPLY_EX(V[768],D[12],30) + MPC_MULTIPLY_EX(V[864],D[13],30) | ||
505 | + MPC_MULTIPLY_EX(V[896],D[14],30) + MPC_MULTIPLY_EX(V[992],D[15],30); | ||
506 | Data += 1; | ||
507 | // total: 16 muls, 15 adds, 16 shifts | ||
508 | } | ||
509 | } | ||
510 | #endif /* CPU_ARM || CPU_COLDFIRE */ | ||
511 | |||
512 | static void | ||
513 | mpc_full_synthesis_filter(MPC_SAMPLE_FORMAT *OutData, MPC_SAMPLE_FORMAT *V, | ||
514 | const MPC_SAMPLE_FORMAT *Y) ICODE_ATTR_MPC_LARGE_IRAM; | ||
515 | static void | ||
516 | mpc_full_synthesis_filter(MPC_SAMPLE_FORMAT *OutData, MPC_SAMPLE_FORMAT *V, | ||
517 | const MPC_SAMPLE_FORMAT *Y) | ||
518 | { | ||
519 | mpc_uint32_t n; | ||
520 | |||
521 | if (NULL != OutData) | ||
522 | { | ||
523 | for ( n = 0; n < 36; n++, Y += 32, OutData += 32 ) | ||
524 | { | ||
525 | V -= 64; | ||
526 | mpc_dct32(Y, V); | ||
527 | mpc_decoder_windowing_D( OutData, V, Di_opt ); | ||
528 | } | ||
529 | } | ||
530 | } | ||
531 | |||
532 | void | ||
533 | mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT *OutData, | ||
534 | int num_channels) | ||
535 | { | ||
536 | (void)num_channels; | ||
537 | |||
538 | /********* left channel ********/ | ||
539 | memmove(d->V_L + MPC_V_MEM, d->V_L, 960 * sizeof(MPC_SAMPLE_FORMAT) ); | ||
540 | mpc_full_synthesis_filter(OutData, | ||
541 | (MPC_SAMPLE_FORMAT *)(d->V_L + MPC_V_MEM), | ||
542 | (MPC_SAMPLE_FORMAT *)(d->Y_L)); | ||
543 | |||
544 | /******** right channel ********/ | ||
545 | memmove(d->V_R + MPC_V_MEM, d->V_R, 960 * sizeof(MPC_SAMPLE_FORMAT) ); | ||
546 | mpc_full_synthesis_filter((OutData == NULL ? NULL : OutData + MPC_FRAME_LENGTH), | ||
547 | (MPC_SAMPLE_FORMAT *)(d->V_R + MPC_V_MEM), | ||
548 | (MPC_SAMPLE_FORMAT *)(d->Y_R)); | ||
549 | } | ||
550 | |||
551 | /*******************************************/ | ||
552 | /* */ | ||
553 | /* dithered synthesis */ | ||
554 | /* */ | ||
555 | /*******************************************/ | ||
556 | |||
557 | static const unsigned char Parity [256] = { // parity | ||
558 | 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1, | ||
559 | 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0, | ||
560 | 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0, | ||
561 | 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1, | ||
562 | 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0, | ||
563 | 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1, | ||
564 | 0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1, | ||
565 | 1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0 | ||
566 | }; | ||
567 | |||
568 | /* | ||
569 | * This is a simple random number generator with good quality for audio purposes. | ||
570 | * It consists of two polycounters with opposite rotation direction and different | ||
571 | * periods. The periods are coprime, so the total period is the product of both. | ||
572 | * | ||
573 | * ------------------------------------------------------------------------------------------------- | ||
574 | * +-> |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0| | ||
575 | * | ------------------------------------------------------------------------------------------------- | ||
576 | * | | | | | | | | ||
577 | * | +--+--+--+-XOR-+--------+ | ||
578 | * | | | ||
579 | * +--------------------------------------------------------------------------------------+ | ||
580 | * | ||
581 | * ------------------------------------------------------------------------------------------------- | ||
582 | * |31:30:29:28:27:26:25:24:23:22:21:20:19:18:17:16:15:14:13:12:11:10: 9: 8: 7: 6: 5: 4: 3: 2: 1: 0| <-+ | ||
583 | * ------------------------------------------------------------------------------------------------- | | ||
584 | * | | | | | | ||
585 | * +--+----XOR----+--+ | | ||
586 | * | | | ||
587 | * +----------------------------------------------------------------------------------------+ | ||
588 | * | ||
589 | * | ||
590 | * The first has an period of 3*5*17*257*65537, the second of 7*47*73*178481, | ||
591 | * which gives a period of 18.410.713.077.675.721.215. The result is the | ||
592 | * XORed values of both generators. | ||
593 | */ | ||
594 | mpc_uint32_t | ||
595 | mpc_random_int(mpc_decoder *d) | ||
596 | { | ||
597 | #if 1 | ||
598 | mpc_uint32_t t1, t2, t3, t4; | ||
599 | |||
600 | t3 = t1 = d->__r1; t4 = t2 = d->__r2; // Parity calculation is done via table lookup, this is also available | ||
601 | t1 &= 0xF5; t2 >>= 25; // on CPUs without parity, can be implemented in C and avoid unpredictable | ||
602 | t1 = Parity [t1]; t2 &= 0x63; // jumps and slow rotate through the carry flag operations. | ||
603 | t1 <<= 31; t2 = Parity [t2]; | ||
604 | |||
605 | return (d->__r1 = (t3 >> 1) | t1 ) ^ (d->__r2 = (t4 + t4) | t2 ); | ||
606 | #else | ||
607 | return (d->__r1 = (d->__r1 >> 1) | ((mpc_uint32_t)Parity [d->__r1 & 0xF5] << 31) ) ^ | ||
608 | (d->__r2 = (d->__r2 << 1) | (mpc_uint32_t)Parity [(d->__r2 >> 25) & 0x63] ); | ||
609 | #endif | ||
610 | } | ||
diff --git a/lib/rbcodec/codecs/libmusepack/synth_filter_arm.S b/lib/rbcodec/codecs/libmusepack/synth_filter_arm.S new file mode 100644 index 0000000000..9bd4e04626 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/synth_filter_arm.S | |||
@@ -0,0 +1,693 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 by Andree Buschmann | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | |||
24 | #if defined(CPU_S5L870X) | ||
25 | /* Moving this asm routine to iram is (little) faster on S5L870x. */ | ||
26 | .section .icode, "ax", %progbits | ||
27 | #else | ||
28 | .section .text, "ax", %progbits | ||
29 | #endif | ||
30 | |||
31 | /**************************************************************************** | ||
32 | * void mpc_decoder_windowing_D(...) | ||
33 | * | ||
34 | * 2nd step within synthesis filter. Does the dewindowing. | ||
35 | * 64=32x32 multiplies | ||
36 | * Uses un-shifted D[]-values. D[] will always be the second operand of | ||
37 | * smull/smlal to achieve higher speed as D[] has lower amplitude than V[]. | ||
38 | ****************************************************************************/ | ||
39 | .align 2 | ||
40 | .global mpc_decoder_windowing_D | ||
41 | .type mpc_decoder_windowing_D, %function | ||
42 | #if 0 | ||
43 | mpc_decoder_windowing_D: | ||
44 | /* r0 = Data[] */ | ||
45 | /* r1 = V[] */ | ||
46 | /* r2 = D[] */ | ||
47 | /* lr = counter */ | ||
48 | /************************************************************************ | ||
49 | * Reference implementation. | ||
50 | ***********************************************************************/ | ||
51 | stmfd sp!, {r4-r8, lr} | ||
52 | |||
53 | mov lr, #32 | ||
54 | .loop32: | ||
55 | ldmia r2!, { r3-r6 } /* load D[00..03] */ | ||
56 | ldr r7, [r1] /* 0 */ | ||
57 | smull r8, r12, r7, r3 | ||
58 | ldr r7, [r1, #96*4] /* 1 */ | ||
59 | smlal r8, r12, r7, r4 | ||
60 | ldr r7, [r1, #128*4] /* 2 */ | ||
61 | smlal r8, r12, r7, r5 | ||
62 | ldr r7, [r1, #224*4] /* 3 */ | ||
63 | smlal r8, r12, r7, r6 | ||
64 | ldmia r2!, { r3-r6 } /* load D[04..07] */ | ||
65 | ldr r7, [r1, #256*4] /* 4 */ | ||
66 | smlal r8, r12, r7, r3 | ||
67 | ldr r7, [r1, #352*4] /* 5 */ | ||
68 | smlal r8, r12, r7, r4 | ||
69 | ldr r7, [r1, #384*4] /* 6 */ | ||
70 | smlal r8, r12, r7, r5 | ||
71 | ldr r7, [r1, #480*4] /* 7 */ | ||
72 | smlal r8, r12, r7, r6 | ||
73 | ldmia r2!, { r3-r6 } /* load D[08..11] */ | ||
74 | ldr r7, [r1, #512*4] /* 8 */ | ||
75 | smlal r8, r12, r7, r3 | ||
76 | ldr r7, [r1, #608*4] /* 9 */ | ||
77 | smlal r8, r12, r7, r4 | ||
78 | ldr r7, [r1, #640*4] /* 10 */ | ||
79 | smlal r8, r12, r7, r5 | ||
80 | ldr r7, [r1, #736*4] /* 11 */ | ||
81 | smlal r8, r12, r7, r6 | ||
82 | ldmia r2!, { r3-r6 } /* load D[12..15] */ | ||
83 | ldr r7, [r1, #768*4] /* 12 */ | ||
84 | smlal r8, r12, r7, r3 | ||
85 | ldr r7, [r1, #864*4] /* 13 */ | ||
86 | smlal r8, r12, r7, r4 | ||
87 | ldr r7, [r1, #896*4] /* 14 */ | ||
88 | smlal r8, r12, r7, r5 | ||
89 | ldr r7, [r1, #992*4] /* 15 */ | ||
90 | smlal r8, r12, r7, r6 | ||
91 | mov r8, r8, lsr #16 | ||
92 | orr r8, r8, r12, lsl #16 /* (lo>>16) || (hi<<16) */ | ||
93 | str r8, [r0], #4 /* store Data */ | ||
94 | add r1, r1, #4 /* V++ */ | ||
95 | |||
96 | subs lr, lr, #1 | ||
97 | bgt .loop32 | ||
98 | |||
99 | ldmpc regs=r4-r8 | ||
100 | #elif defined(CPU_ARM7TDMI) /* arm7 only */ | ||
101 | mpc_decoder_windowing_D: | ||
102 | /* r0 = Data[] */ | ||
103 | /* r1 = V[] */ | ||
104 | /* r2 = D[] */ | ||
105 | /* lr = counter */ | ||
106 | /************************************************************************ | ||
107 | * Further speed up through making use of symmetries within D[]-window. | ||
108 | * The row V[00] can be extracted as it has symmetries within this single | ||
109 | * row. 8 smull/mlal and 8 ldr's can be saved at the cost of 2 add's. | ||
110 | * The rows V[01..15] are symmetric to V[31..17]. 15 x 16 ldr's can be | ||
111 | * saved at the cost of 15 x 4 + 1 add's. | ||
112 | * The row V[16] can be extracted as it has symmetries within this single | ||
113 | * row. 8 smull/mlal and 8 ldr's can be saved. | ||
114 | * Used for arm7 only. For arm9 and above see implementation below. | ||
115 | ***********************************************************************/ | ||
116 | stmfd sp!, {r4-r11, lr} | ||
117 | |||
118 | /****************************************** | ||
119 | * row 0 with internal symmetry | ||
120 | *****************************************/ | ||
121 | add r2, r2, #4 /* D+=1, r2 = D[01] as D[00] = 0 */ | ||
122 | ldmia r2!, { r3-r6 } /* load D[01..04] */ | ||
123 | ldr r7 , [r1, #96*4] /* 1 */ | ||
124 | ldr r10, [r1, #992*4] /* 15 */ | ||
125 | rsb r10, r10, r7 /* V[01] - V[15] */ | ||
126 | smull r8, r9, r10, r3 | ||
127 | ldr r7 , [r1, #128*4] /* 2 */ | ||
128 | ldr r10, [r1, #896*4] /* 14 */ | ||
129 | add r10, r10, r7 /* V[02] + V[14] */ | ||
130 | smlal r8, r9, r10, r4 | ||
131 | ldr r7 , [r1, #224*4] /* 3 */ | ||
132 | ldr r10, [r1, #864*4] /* 13 */ | ||
133 | rsb r10, r10, r7 /* V[03] - V[13] */ | ||
134 | smlal r8, r9, r10, r5 | ||
135 | ldr r7 , [r1, #256*4] /* 4 */ | ||
136 | ldr r10, [r1, #768*4] /* 12 */ | ||
137 | add r10, r10, r7 /* V[04] + V[12] */ | ||
138 | smlal r8, r9, r10, r6 | ||
139 | ldmia r2!, { r3-r6 } /* load D[05..08] */ | ||
140 | ldr r7 , [r1, #352*4] /* 5 */ | ||
141 | ldr r10, [r1, #736*4] /* 11 */ | ||
142 | rsb r10, r10, r7 /* V[05] - V[11] */ | ||
143 | smlal r8, r9, r10, r3 | ||
144 | ldr r7 , [r1, #384*4] /* 6 */ | ||
145 | ldr r10, [r1, #640*4] /* 10 */ | ||
146 | add r10, r10, r7 /* V[06] + V[10] */ | ||
147 | smlal r8, r9, r10, r4 | ||
148 | ldr r7 , [r1, #480*4] /* 7 */ | ||
149 | ldr r10, [r1, #608*4] /* 9 */ | ||
150 | rsb r10, r10, r7 /* V[07] - V[09] */ | ||
151 | smlal r8, r9, r10, r5 | ||
152 | ldr r10, [r1, #512*4] /* 8 */ | ||
153 | smlal r8, r9, r10, r6 | ||
154 | mov r8, r8, lsr #16 | ||
155 | orr r8, r8, r9, lsl #16 /* (lo>>16) || (hi<<16) */ | ||
156 | str r8, [r0], #4 /* store Data */ | ||
157 | add r1, r1, #4 /* V+=1, r1 = V[01] */ | ||
158 | add r2, r2, #7*4 /* D+=7, r2 = D[16] */ | ||
159 | |||
160 | /****************************************** | ||
161 | * rows 01..15 are symmetric to rows 31..17 | ||
162 | * r8 = lo, r9 = hi of 01..15 | ||
163 | * r1 = V[01..15] | ||
164 | * r10 = lo, r11 = hi of 31..17 | ||
165 | * r12 = V[31..16] | ||
166 | *****************************************/ | ||
167 | mov lr, #15*8 | ||
168 | add r12, r1, #30*4 /* r12 = V[31] */ | ||
169 | .loop15: | ||
170 | ldmia r2!, { r3-r6 } /* load D[00..03] */ | ||
171 | ldr r7, [r12, #768*4] /* 12 */ | ||
172 | smull r10, r11, r7, r6 | ||
173 | ldr r7, [r12, #864*4] /* 13 */ | ||
174 | smlal r10, r11, r7, r5 | ||
175 | ldr r7, [r12, #896*4] /* 14 */ | ||
176 | smlal r10, r11, r7, r4 | ||
177 | ldr r7, [r12, #992*4] /* 15 */ | ||
178 | smlal r10, r11, r7, r3 | ||
179 | ldr r7, [r1] /* 0 */ | ||
180 | smull r8, r9, r7, r3 | ||
181 | ldr r7, [r1, #96*4] /* 1 */ | ||
182 | smlal r8, r9, r7, r4 | ||
183 | ldr r7, [r1, #128*4] /* 2 */ | ||
184 | smlal r8, r9, r7, r5 | ||
185 | ldr r7, [r1, #224*4] /* 3 */ | ||
186 | smlal r8, r9, r7, r6 | ||
187 | ldmia r2!, { r3-r6 } /* load D[04..07] */ | ||
188 | ldr r7, [r1, #256*4] /* 4 */ | ||
189 | smlal r8, r9, r7, r3 | ||
190 | ldr r7, [r1, #352*4] /* 5 */ | ||
191 | smlal r8, r9, r7, r4 | ||
192 | ldr r7, [r1, #384*4] /* 6 */ | ||
193 | smlal r8, r9, r7, r5 | ||
194 | ldr r7, [r1, #480*4] /* 7 */ | ||
195 | smlal r8, r9, r7, r6 | ||
196 | ldr r7, [r12, #512*4] /* 8 */ | ||
197 | smlal r10, r11, r7, r6 | ||
198 | ldr r7, [r12, #608*4] /* 9 */ | ||
199 | smlal r10, r11, r7, r5 | ||
200 | ldr r7, [r12, #640*4] /* 10 */ | ||
201 | smlal r10, r11, r7, r4 | ||
202 | ldr r7, [r12, #736*4] /* 11 */ | ||
203 | smlal r10, r11, r7, r3 | ||
204 | ldmia r2!, { r3-r6 } /* load D[08..11] */ | ||
205 | ldr r7, [r12, #256*4] /* 4 */ | ||
206 | smlal r10, r11, r7, r6 | ||
207 | ldr r7, [r12, #352*4] /* 5 */ | ||
208 | smlal r10, r11, r7, r5 | ||
209 | ldr r7, [r12, #384*4] /* 6 */ | ||
210 | smlal r10, r11, r7, r4 | ||
211 | ldr r7, [r12, #480*4] /* 7 */ | ||
212 | smlal r10, r11, r7, r3 | ||
213 | ldr r7, [r1, #512*4] /* 8 */ | ||
214 | smlal r8, r9, r7, r3 | ||
215 | ldr r7, [r1, #608*4] /* 9 */ | ||
216 | smlal r8, r9, r7, r4 | ||
217 | ldr r7, [r1, #640*4] /* 10 */ | ||
218 | smlal r8, r9, r7, r5 | ||
219 | ldr r7, [r1, #736*4] /* 11 */ | ||
220 | smlal r8, r9, r7, r6 | ||
221 | ldmia r2!, { r3-r6 } /* load D[12..15] */ | ||
222 | ldr r7, [r1, #768*4] /* 12 */ | ||
223 | smlal r8, r9, r7, r3 | ||
224 | ldr r7, [r1, #864*4] /* 13 */ | ||
225 | smlal r8, r9, r7, r4 | ||
226 | ldr r7, [r1, #896*4] /* 14 */ | ||
227 | smlal r8, r9, r7, r5 | ||
228 | ldr r7, [r1, #992*4] /* 15 */ | ||
229 | smlal r8, r9, r7, r6 | ||
230 | ldr r7, [r12] /* 0 */ | ||
231 | smlal r10, r11, r7, r6 | ||
232 | ldr r7, [r12, #96*4] /* 1 */ | ||
233 | smlal r10, r11, r7, r5 | ||
234 | ldr r7, [r12, #128*4] /* 2 */ | ||
235 | smlal r10, r11, r7, r4 | ||
236 | ldr r7, [r12, #224*4] /* 3 */ | ||
237 | smlal r10, r11, r7, r3 | ||
238 | /* store Data[01..15] */ | ||
239 | mov r8, r8, lsr #16 | ||
240 | orr r8, r8, r9, lsl #16 /* (lo>>16) || (hi<<16) */ | ||
241 | /* store Data[31..17] */ | ||
242 | mov r10, r10, lsr #16 | ||
243 | orr r10, r10, r11, lsl #16 /* (lo>>16) || (hi<<16) */ | ||
244 | rsb r10, r10, #0 /* r10 = -r10 */ | ||
245 | str r10, [r0, lr] /* store Data */ | ||
246 | str r8, [r0], #4 /* store Data */ | ||
247 | /* correct adresses for next loop */ | ||
248 | sub r12, r12, #4 /* r12 = V-- */ | ||
249 | add r1, r1, #4 /* r1 = V++ */ | ||
250 | /* next loop */ | ||
251 | subs lr, lr, #8 | ||
252 | bgt .loop15 | ||
253 | |||
254 | /****************************************** | ||
255 | * V[16] with internal symmetry | ||
256 | *****************************************/ | ||
257 | ldmia r2!, { r3-r6 } /* load D[00..03] */ | ||
258 | ldr r7 , [r1] /* 0 */ | ||
259 | ldr r10, [r1, #992*4] /* 15 */ | ||
260 | rsb r10, r10, r7 /* V[00] - V[15] */ | ||
261 | smull r8, r9, r10, r3 | ||
262 | ldr r7 , [r1, #96*4] /* 1 */ | ||
263 | ldr r10, [r1, #896*4] /* 14 */ | ||
264 | rsb r10, r10, r7 /* V[01] - V[14] */ | ||
265 | smlal r8, r9, r10, r4 | ||
266 | ldr r7 , [r1, #128*4] /* 2 */ | ||
267 | ldr r10, [r1, #864*4] /* 13 */ | ||
268 | rsb r10, r10, r7 /* V[02] - V[13] */ | ||
269 | smlal r8, r9, r10, r5 | ||
270 | ldr r7 , [r1, #224*4] /* 3 */ | ||
271 | ldr r10, [r1, #768*4] /* 12 */ | ||
272 | rsb r10, r10, r7 /* V[03] - V[12] */ | ||
273 | smlal r8, r9, r10, r6 | ||
274 | ldmia r2!, { r3-r6 } /* load D[04..07] */ | ||
275 | ldr r7 , [r1, #256*4] /* 4 */ | ||
276 | ldr r10, [r1, #736*4] /* 11 */ | ||
277 | rsb r10, r10, r7 /* V[04] - V[11] */ | ||
278 | smlal r8, r9, r10, r3 | ||
279 | ldr r7 , [r1, #352*4] /* 5 */ | ||
280 | ldr r10, [r1, #640*4] /* 10 */ | ||
281 | rsb r10, r10, r7 /* V[05] - V[10] */ | ||
282 | smlal r8, r9, r10, r4 | ||
283 | ldr r7 , [r1, #384*4] /* 6 */ | ||
284 | ldr r10, [r1, #608*4] /* 9 */ | ||
285 | rsb r10, r10, r7 /* V[06] - V[09] */ | ||
286 | smlal r8, r9, r10, r5 | ||
287 | ldr r7 , [r1, #480*4] /* 7 */ | ||
288 | ldr r10, [r1, #512*4] /* 8 */ | ||
289 | rsb r10, r10, r7 /* V[07] - V[08] */ | ||
290 | smlal r8, r9, r10, r6 | ||
291 | mov r8, r8, lsr #16 | ||
292 | orr r8, r8, r9, lsl #16 /* (lo>>16) || (hi<<16) */ | ||
293 | str r8, [r0], #4 /* store Data */ | ||
294 | |||
295 | ldmpc regs=r4-r11 | ||
296 | #elif ARM_ARCH < 6 /* arm9 and above */ | ||
297 | mpc_decoder_windowing_D: | ||
298 | /* r0 = Data[] */ | ||
299 | /* r1 = V[] */ | ||
300 | /* r2 = D[] */ | ||
301 | /* lr = counter */ | ||
302 | /************************************************************************ | ||
303 | * Further speed up through making use of symmetries within D[]-window. | ||
304 | * The row V[00] can be extracted as it has symmetries within this single | ||
305 | * row. 8 smull/mlal and 8 ldr's can be saved at the cost of 2 add's. | ||
306 | * The rows V[01..15] are symmetric to V[31..17]. 15 x 16 ldr's can be | ||
307 | * saved at the cost of 15 x 4 + 1 add's. | ||
308 | * The row V[16] can be extracted as it has symmetries within this single | ||
309 | * row. 8 smull/mlal and 8 ldr's can be saved. | ||
310 | * On arm9 (still armv4 architecture) reducing stalls after ldr/ldm speeds | ||
311 | * up decoding even though several ldm-calls are replaced with ldr to free | ||
312 | * 2 registers. | ||
313 | ***********************************************************************/ | ||
314 | stmfd sp!, {r4-r11, lr} | ||
315 | |||
316 | /****************************************** | ||
317 | * row 0 with internal symmetry | ||
318 | *****************************************/ | ||
319 | add r2, r2, #4 /* D+=1, r2 = D[01] as D[00] = 0 */ | ||
320 | ldmia r2!, { r3-r6 } /* load D[01..04] */ | ||
321 | ldr r7 , [r1, #96*4] /* 1 */ | ||
322 | ldr r10, [r1, #992*4] /* 15 */ | ||
323 | ldr r11, [r1, #128*4] /* 2 */ | ||
324 | ldr r12, [r1, #896*4] /* 14 */ | ||
325 | rsb r10, r10, r7 /* V[01] - V[15] */ | ||
326 | smull r8, r9, r10, r3 | ||
327 | ldr r7 , [r1, #224*4] /* 3 */ | ||
328 | ldr r10, [r1, #864*4] /* 13 */ | ||
329 | add r12, r12, r11 /* V[02] + V[14] */ | ||
330 | smlal r8, r9, r12, r4 | ||
331 | ldr r11, [r1, #256*4] /* 4 */ | ||
332 | ldr r12, [r1, #768*4] /* 12 */ | ||
333 | rsb r10, r10, r7 /* V[03] - V[13] */ | ||
334 | smlal r8, r9, r10, r5 | ||
335 | ldr r7 , [r1, #352*4] /* 5 */ | ||
336 | ldr r10, [r1, #736*4] /* 11 */ | ||
337 | add r12, r12, r11 /* V[04] + V[12] */ | ||
338 | smlal r8, r9, r12, r6 | ||
339 | ldmia r2!, { r3-r6 } /* load D[05..08] */ | ||
340 | ldr r11, [r1, #384*4] /* 6 */ | ||
341 | ldr r12, [r1, #640*4] /* 10 */ | ||
342 | rsb r10, r10, r7 /* V[05] - V[11] */ | ||
343 | smlal r8, r9, r10, r3 | ||
344 | ldr r7 , [r1, #480*4] /* 7 */ | ||
345 | ldr r10, [r1, #608*4] /* 9 */ | ||
346 | add r12, r12, r11 /* V[06] + V[10] */ | ||
347 | smlal r8, r9, r12, r4 | ||
348 | ldr r11, [r1, #512*4] /* 8 */ | ||
349 | rsb r10, r10, r7 /* V[07] - V[09] */ | ||
350 | smlal r8, r9, r10, r5 | ||
351 | smlal r8, r9, r11, r6 | ||
352 | mov r8, r8, lsr #16 | ||
353 | orr r8, r8, r9, lsl #16 /* (lo>>16) || (hi<<16) */ | ||
354 | str r8, [r0], #4 /* store Data */ | ||
355 | add r1, r1, #4 /* V+=1, r1 = V[01] */ | ||
356 | add r2, r2, #7*4 /* D+=7, r2 = D[16] */ | ||
357 | |||
358 | /****************************************** | ||
359 | * rows 01..15 are symmetric to rows 31..17 | ||
360 | * r8 = lo, r9 = hi of 01..15 | ||
361 | * r1 = V[01..15] | ||
362 | * r10 = lo, r11 = hi of 31..17 | ||
363 | * r12 = V[31..16] | ||
364 | *****************************************/ | ||
365 | mov lr, #15*8 | ||
366 | add r12, r1, #30*4 /* r12 = V[31] */ | ||
367 | .loop15: | ||
368 | ldmia r2!, { r3-r4 } /* load D[00..01] */ | ||
369 | ldr r7, [r12, #896*4] /* 14 */ | ||
370 | ldr r5, [r12, #992*4] /* 15 */ | ||
371 | smull r10, r11, r7, r4 | ||
372 | ldr r7, [r1] /* 0 */ | ||
373 | smlal r10, r11, r5, r3 | ||
374 | ldr r5, [r1, #96*4] /* 1 */ | ||
375 | smull r8, r9, r7, r3 | ||
376 | ldr r7, [r12, #768*4] /* 12 */ | ||
377 | smlal r8, r9, r5, r4 | ||
378 | ldmia r2!, { r3-r4 } /* load D[02..03] */ | ||
379 | ldr r5, [r12, #864*4] /* 13 */ | ||
380 | smlal r10, r11, r7, r4 | ||
381 | ldr r7, [r1, #128*4] /* 2 */ | ||
382 | smlal r10, r11, r5, r3 | ||
383 | ldr r5, [r1, #224*4] /* 3 */ | ||
384 | smlal r8, r9, r7, r3 | ||
385 | ldr r7, [r1, #256*4] /* 4 */ | ||
386 | smlal r8, r9, r5, r4 | ||
387 | ldmia r2!, { r3-r4 } /* load D[04..04] */ | ||
388 | ldr r5, [r1, #352*4] /* 5 */ | ||
389 | smlal r8, r9, r7, r3 | ||
390 | ldr r7, [r12, #640*4] /* 10 */ | ||
391 | smlal r8, r9, r5, r4 | ||
392 | ldr r5, [r12, #736*4] /* 11 */ | ||
393 | smlal r10, r11, r7, r4 | ||
394 | ldr r7, [r1, #384*4] /* 6 */ | ||
395 | smlal r10, r11, r5, r3 | ||
396 | ldmia r2!, { r3-r4 } /* load D[06..07] */ | ||
397 | ldr r5, [r1, #480*4] /* 7 */ | ||
398 | smlal r8, r9, r7, r3 | ||
399 | ldr r7, [r12, #512*4] /* 8 */ | ||
400 | smlal r8, r9, r5, r4 | ||
401 | ldr r5, [r12, #608*4] /* 9 */ | ||
402 | smlal r10, r11, r7, r4 | ||
403 | ldr r7, [r12, #384*4] /* 6 */ | ||
404 | smlal r10, r11, r5, r3 | ||
405 | ldmia r2!, { r3-r4 } /* load D[08..09] */ | ||
406 | ldr r5, [r12, #480*4] /* 7 */ | ||
407 | smlal r10, r11, r7, r4 | ||
408 | ldr r7, [r1, #512*4] /* 8 */ | ||
409 | smlal r10, r11, r5, r3 | ||
410 | ldr r5, [r1, #608*4] /* 9 */ | ||
411 | smlal r8, r9, r7, r3 | ||
412 | ldr r7, [r1, #640*4] /* 10 */ | ||
413 | smlal r8, r9, r5, r4 | ||
414 | ldmia r2!, { r3-r4 } /* load D[10..11] */ | ||
415 | ldr r5, [r1, #736*4] /* 11 */ | ||
416 | smlal r8, r9, r7, r3 | ||
417 | ldr r7, [r12, #256*4] /* 4 */ | ||
418 | smlal r8, r9, r5, r4 | ||
419 | ldr r5, [r12, #352*4] /* 5 */ | ||
420 | smlal r10, r11, r7, r4 | ||
421 | ldr r7, [r1, #768*4] /* 12 */ | ||
422 | smlal r10, r11, r5, r3 | ||
423 | ldmia r2!, { r3-r4 } /* load D[12..13] */ | ||
424 | ldr r5, [r1, #864*4] /* 13 */ | ||
425 | smlal r8, r9, r7, r3 | ||
426 | ldr r7, [r12, #128*4] /* 2 */ | ||
427 | smlal r8, r9, r5, r4 | ||
428 | ldr r5, [r12, #224*4] /* 3 */ | ||
429 | smlal r10, r11, r7, r4 | ||
430 | ldr r7, [r12] /* 0 */ | ||
431 | smlal r10, r11, r5, r3 | ||
432 | ldmia r2!, { r3-r4 } /* load D[14..15] */ | ||
433 | ldr r5, [r12, #96*4] /* 1 */ | ||
434 | smlal r10, r11, r7, r4 | ||
435 | ldr r7, [r1, #896*4] /* 14 */ | ||
436 | smlal r10, r11, r5, r3 | ||
437 | ldr r5, [r1, #992*4] /* 15 */ | ||
438 | smlal r8, r9, r7, r3 | ||
439 | smlal r8, r9, r5, r4 | ||
440 | /* store Data[01..15] */ | ||
441 | mov r8, r8, lsr #16 | ||
442 | orr r8, r8, r9, lsl #16 /* (lo>>16) || (hi<<16) */ | ||
443 | /* store Data[31..17] */ | ||
444 | mov r10, r10, lsr #16 | ||
445 | orr r10, r10, r11, lsl #16 /* (lo>>16) || (hi<<16) */ | ||
446 | rsb r10, r10, #0 /* r10 = -r10 */ | ||
447 | str r10, [r0, lr] /* store Data */ | ||
448 | str r8, [r0], #4 /* store Data */ | ||
449 | /* correct adresses for next loop */ | ||
450 | sub r12, r12, #4 /* r12 = V-- */ | ||
451 | add r1, r1, #4 /* r1 = V++ */ | ||
452 | /* next loop */ | ||
453 | subs lr, lr, #8 | ||
454 | bgt .loop15 | ||
455 | |||
456 | /****************************************** | ||
457 | * V[16] with internal symmetry | ||
458 | *****************************************/ | ||
459 | ldmia r2!, { r3-r6 } /* load D[00..03] */ | ||
460 | ldr r7 , [r1] /* 0 */ | ||
461 | ldr r10, [r1, #992*4] /* 15 */ | ||
462 | ldr r11, [r1, #96*4] /* 1 */ | ||
463 | ldr r12, [r1, #896*4] /* 14 */ | ||
464 | rsb r10, r10, r7 /* V[00] - V[15] */ | ||
465 | smull r8, r9, r10, r3 | ||
466 | ldr r7 , [r1, #128*4] /* 2 */ | ||
467 | ldr r10, [r1, #864*4] /* 13 */ | ||
468 | rsb r12, r12, r11 /* V[01] - V[14] */ | ||
469 | smlal r8, r9, r12, r4 | ||
470 | ldr r11, [r1, #224*4] /* 3 */ | ||
471 | ldr r12, [r1, #768*4] /* 12 */ | ||
472 | rsb r10, r10, r7 /* V[02] - V[13] */ | ||
473 | smlal r8, r9, r10, r5 | ||
474 | ldr r7 , [r1, #256*4] /* 4 */ | ||
475 | ldr r10, [r1, #736*4] /* 11 */ | ||
476 | rsb r12, r12, r11 /* V[03] - V[12] */ | ||
477 | smlal r8, r9, r12, r6 | ||
478 | ldmia r2!, { r3-r6 } /* load D[04..07] */ | ||
479 | ldr r11, [r1, #352*4] /* 5 */ | ||
480 | ldr r12, [r1, #640*4] /* 10 */ | ||
481 | rsb r10, r10, r7 /* V[04] - V[11] */ | ||
482 | smlal r8, r9, r10, r3 | ||
483 | ldr r7 , [r1, #384*4] /* 6 */ | ||
484 | ldr r10, [r1, #608*4] /* 9 */ | ||
485 | rsb r12, r12, r11 /* V[05] - V[10] */ | ||
486 | smlal r8, r9, r12, r4 | ||
487 | ldr r11, [r1, #480*4] /* 7 */ | ||
488 | ldr r12, [r1, #512*4] /* 8 */ | ||
489 | rsb r10, r10, r7 /* V[06] - V[09] */ | ||
490 | smlal r8, r9, r10, r5 | ||
491 | rsb r12, r12, r11 /* V[07] - V[08] */ | ||
492 | smlal r8, r9, r12, r6 | ||
493 | mov r8, r8, lsr #16 | ||
494 | orr r8, r8, r9, lsl #16 /* (lo>>16) || (hi<<16) */ | ||
495 | str r8, [r0], #4 /* store Data */ | ||
496 | |||
497 | ldmpc regs=r4-r11 | ||
498 | #else | ||
499 | mpc_decoder_windowing_D: | ||
500 | /* r0 = Data[] */ | ||
501 | /* r1 = V[] */ | ||
502 | /* r2 = D[] */ | ||
503 | /* lr = counter */ | ||
504 | /************************************************************************ | ||
505 | * Further speed up through making use of symmetries within D[]-window. | ||
506 | * The row V[00] can be extracted as it has symmetries within this single | ||
507 | * row. 8 smull/mlal and 8 ldr's can be saved at the cost of 2 add's. | ||
508 | * The rows V[01..15] are symmetric to V[31..17]. 15 x 16 ldr's can be | ||
509 | * saved at the cost of 15 x 4 + 1 add's. | ||
510 | * The row V[16] can be extracted as it has symmetries within this single | ||
511 | * row. 8 smull/mlal and 8 ldr's can be saved. | ||
512 | * On armv6 use smmulr/smlalr which are faster than smull/smlal and only | ||
513 | * accumulate the top 32 bits of the result so that frees up 2 | ||
514 | * registers so we can ldm larger blocks. | ||
515 | ***********************************************************************/ | ||
516 | stmfd sp!, {r4-r11, lr} | ||
517 | |||
518 | /****************************************** | ||
519 | * row 0 with internal symmetry | ||
520 | *****************************************/ | ||
521 | add r2, r2, #4 /* D+=1, r2 = D[01] as D[00] = 0 */ | ||
522 | ldmia r2!, { r3-r6 } /* load D[01..04] */ | ||
523 | ldr r7 , [r1, #96*4] /* 1 */ | ||
524 | ldr r10, [r1, #992*4] /* 15 */ | ||
525 | ldr r11, [r1, #128*4] /* 2 */ | ||
526 | rsb r10, r10, r7 /* V[01] - V[15] */ | ||
527 | ldr r12, [r1, #896*4] /* 14 */ | ||
528 | smmulr r9, r10, r3 | ||
529 | ldr r7 , [r1, #224*4] /* 3 */ | ||
530 | add r12, r12, r11 /* V[02] + V[14] */ | ||
531 | ldr r10, [r1, #864*4] /* 13 */ | ||
532 | smmlar r9, r12, r4, r9 | ||
533 | ldr r11, [r1, #256*4] /* 4 */ | ||
534 | rsb r10, r10, r7 /* V[03] - V[13] */ | ||
535 | ldr r12, [r1, #768*4] /* 12 */ | ||
536 | smmlar r9, r10, r5, r9 | ||
537 | ldr r7 , [r1, #352*4] /* 5 */ | ||
538 | add r12, r12, r11 /* V[04] + V[12] */ | ||
539 | ldr r10, [r1, #736*4] /* 11 */ | ||
540 | smmlar r9, r12, r6, r9 | ||
541 | ldmia r2!, { r3-r6 } /* load D[05..08] */ | ||
542 | ldr r11, [r1, #384*4] /* 6 */ | ||
543 | rsb r10, r10, r7 /* V[05] - V[11] */ | ||
544 | ldr r12, [r1, #640*4] /* 10 */ | ||
545 | smmlar r9, r10, r3, r9 | ||
546 | ldr r7 , [r1, #480*4] /* 7 */ | ||
547 | add r12, r12, r11 /* V[06] + V[10] */ | ||
548 | ldr r10, [r1, #608*4] /* 9 */ | ||
549 | smmlar r9, r12, r4, r9 | ||
550 | rsb r10, r10, r7 /* V[07] - V[09] */ | ||
551 | ldr r11, [r1, #512*4] /* 8 */ | ||
552 | smmlar r9, r10, r5, r9 | ||
553 | add r1, r1, #4 /* V+=1, r1 = V[01] */ | ||
554 | smmlar r9, r11, r6, r9 | ||
555 | add r2, r2, #7*4 /* D+=7, r2 = D[16] */ | ||
556 | mov r9, r9, lsl #2 | ||
557 | str r9, [r0], #4 /* store Data */ | ||
558 | |||
559 | /****************************************** | ||
560 | * rows 01..15 are symmetric to rows 31..17 | ||
561 | * r9 = acc of 01..15 | ||
562 | * r1 = V[01..15] | ||
563 | * r11 = acc of 31..17 | ||
564 | * r12 = V[31..16] | ||
565 | *****************************************/ | ||
566 | mov lr, #15*8 | ||
567 | add r12, r1, #30*4 /* r12 = V[31] */ | ||
568 | .loop15: | ||
569 | ldmia r2!, { r3-r6 } /* load D[00..03] */ | ||
570 | ldr r7, [r12, #896*4] /* 14 */ | ||
571 | ldr r8, [r12, #992*4] /* 15 */ | ||
572 | smmulr r11, r7, r4 | ||
573 | ldr r7, [r1] /* 0 */ | ||
574 | smmlar r11, r8, r3, r11 | ||
575 | ldr r8, [r1, #96*4] /* 1 */ | ||
576 | smmulr r9, r7, r3 | ||
577 | ldr r7, [r12, #768*4] /* 12 */ | ||
578 | smmlar r9, r8, r4, r9 | ||
579 | ldr r8, [r12, #864*4] /* 13 */ | ||
580 | smmlar r11, r7, r6, r11 | ||
581 | ldr r7, [r1, #128*4] /* 2 */ | ||
582 | smmlar r11, r8, r5, r11 | ||
583 | ldr r8, [r1, #224*4] /* 3 */ | ||
584 | smmlar r9, r7, r5, r9 | ||
585 | ldr r7, [r1, #256*4] /* 4 */ | ||
586 | smmlar r9, r8, r6, r9 | ||
587 | ldmia r2!, { r3-r6 } /* load D[04..07] */ | ||
588 | ldr r8, [r1, #352*4] /* 5 */ | ||
589 | smmlar r9, r7, r3, r9 | ||
590 | ldr r7, [r12, #640*4] /* 10 */ | ||
591 | smmlar r9, r8, r4, r9 | ||
592 | ldr r8, [r12, #736*4] /* 11 */ | ||
593 | smmlar r11, r7, r4, r11 | ||
594 | ldr r7, [r1, #384*4] /* 6 */ | ||
595 | smmlar r11, r8, r3, r11 | ||
596 | ldr r8, [r1, #480*4] /* 7 */ | ||
597 | smmlar r9, r7, r5, r9 | ||
598 | ldr r7, [r12, #512*4] /* 8 */ | ||
599 | smmlar r9, r8, r6, r9 | ||
600 | ldr r8, [r12, #608*4] /* 9 */ | ||
601 | smmlar r11, r7, r6, r11 | ||
602 | ldr r7, [r12, #384*4] /* 6 */ | ||
603 | smmlar r11, r8, r5, r11 | ||
604 | ldmia r2!, { r3-r6 } /* load D[08..11] */ | ||
605 | ldr r8, [r12, #480*4] /* 7 */ | ||
606 | smmlar r11, r7, r4, r11 | ||
607 | ldr r7, [r1, #512*4] /* 8 */ | ||
608 | smmlar r11, r8, r3, r11 | ||
609 | ldr r8, [r1, #608*4] /* 9 */ | ||
610 | smmlar r9, r7, r3, r9 | ||
611 | ldr r7, [r1, #640*4] /* 10 */ | ||
612 | smmlar r9, r8, r4, r9 | ||
613 | ldr r8, [r1, #736*4] /* 11 */ | ||
614 | smmlar r9, r7, r5, r9 | ||
615 | ldr r7, [r12, #256*4] /* 4 */ | ||
616 | smmlar r9, r8, r6, r9 | ||
617 | ldr r8, [r12, #352*4] /* 5 */ | ||
618 | smmlar r11, r7, r6, r11 | ||
619 | ldr r7, [r1, #768*4] /* 12 */ | ||
620 | smmlar r11, r8, r5, r11 | ||
621 | ldmia r2!, { r3-r6 } /* load D[12..15] */ | ||
622 | ldr r8, [r1, #864*4] /* 13 */ | ||
623 | smmlar r9, r7, r3, r9 | ||
624 | ldr r7, [r12, #128*4] /* 2 */ | ||
625 | smmlar r9, r8, r4, r9 | ||
626 | ldr r8, [r12, #224*4] /* 3 */ | ||
627 | smmlar r11, r7, r4, r11 | ||
628 | ldr r7, [r12] /* 0 */ | ||
629 | smmlar r11, r8, r3, r11 | ||
630 | ldr r8, [r12, #96*4] /* 1 */ | ||
631 | smmlar r11, r7, r6, r11 | ||
632 | ldr r7, [r1, #896*4] /* 14 */ | ||
633 | smmlar r11, r8, r5, r11 | ||
634 | ldr r8, [r1, #992*4] /* 15 */ | ||
635 | smmlar r9, r7, r5, r9 | ||
636 | sub r12, r12, #4 /* r12 = V-- correct adresses for next loop */ | ||
637 | smmlar r9, r8, r6, r9 | ||
638 | add r1, r1, #4 /* r1 = V++ correct adresses for next loop */ | ||
639 | rsb r11, r11, #0 /* r11 = -r11 */ | ||
640 | /* store Data[01..15] */ | ||
641 | mov r9, r9, lsl #2 | ||
642 | /* store Data[31..17] */ | ||
643 | mov r11, r11, lsl #2 | ||
644 | str r11, [r0, lr] /* store Data */ | ||
645 | str r9, [r0], #4 /* store Data */ | ||
646 | /* next loop */ | ||
647 | subs lr, lr, #8 | ||
648 | bgt .loop15 | ||
649 | |||
650 | /****************************************** | ||
651 | * V[16] with internal symmetry | ||
652 | *****************************************/ | ||
653 | ldmia r2!, { r3-r6 } /* load D[00..03] */ | ||
654 | ldr r7 , [r1] /* 0 */ | ||
655 | ldr r10, [r1, #992*4] /* 15 */ | ||
656 | ldr r11, [r1, #96*4] /* 1 */ | ||
657 | rsb r10, r10, r7 /* V[00] - V[15] */ | ||
658 | ldr r12, [r1, #896*4] /* 14 */ | ||
659 | smmulr r9, r10, r3 | ||
660 | ldr r7 , [r1, #128*4] /* 2 */ | ||
661 | rsb r12, r12, r11 /* V[01] - V[14] */ | ||
662 | ldr r10, [r1, #864*4] /* 13 */ | ||
663 | smmlar r9, r12, r4, r9 | ||
664 | ldr r11, [r1, #224*4] /* 3 */ | ||
665 | rsb r10, r10, r7 /* V[02] - V[13] */ | ||
666 | ldr r12, [r1, #768*4] /* 12 */ | ||
667 | smmlar r9, r10, r5, r9 | ||
668 | ldr r7 , [r1, #256*4] /* 4 */ | ||
669 | rsb r12, r12, r11 /* V[03] - V[12] */ | ||
670 | ldr r10, [r1, #736*4] /* 11 */ | ||
671 | smmlar r9, r12, r6, r9 | ||
672 | ldmia r2!, { r3-r6 } /* load D[04..07] */ | ||
673 | ldr r11, [r1, #352*4] /* 5 */ | ||
674 | rsb r10, r10, r7 /* V[04] - V[11] */ | ||
675 | ldr r12, [r1, #640*4] /* 10 */ | ||
676 | smmlar r9, r10, r3, r9 | ||
677 | ldr r7 , [r1, #384*4] /* 6 */ | ||
678 | rsb r12, r12, r11 /* V[05] - V[10] */ | ||
679 | ldr r10, [r1, #608*4] /* 9 */ | ||
680 | smmlar r9, r12, r4, r9 | ||
681 | ldr r11, [r1, #480*4] /* 7 */ | ||
682 | rsb r10, r10, r7 /* V[06] - V[09] */ | ||
683 | ldr r12, [r1, #512*4] /* 8 */ | ||
684 | smmlar r9, r10, r5, r9 | ||
685 | rsb r12, r12, r11 /* V[07] - V[08] */ | ||
686 | smmlar r9, r12, r6, r9 | ||
687 | mov r9, r9, lsl #2 | ||
688 | str r9, [r0], #4 /* store Data */ | ||
689 | |||
690 | ldmpc regs=r4-r11 | ||
691 | #endif | ||
692 | .mpc_dewindowing_end: | ||
693 | .size mpc_decoder_windowing_D,.mpc_dewindowing_end-mpc_decoder_windowing_D | ||
diff --git a/lib/rbcodec/codecs/libmusepack/synth_filter_coldfire.S b/lib/rbcodec/codecs/libmusepack/synth_filter_coldfire.S new file mode 100644 index 0000000000..758ab3d496 --- /dev/null +++ b/lib/rbcodec/codecs/libmusepack/synth_filter_coldfire.S | |||
@@ -0,0 +1,78 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 by Thom Johansen | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | /* | ||
24 | * static void | ||
25 | * mpc_decoder_windowing_D(MPC_SAMPLE_FORMAT * Data, | ||
26 | * const MPC_SAMPLE_FORMAT * V, | ||
27 | * const MPC_SAMPLE_FORMAT * D) | ||
28 | */ | ||
29 | |||
30 | #if defined(USE_IRAM) | ||
31 | .section .icode | ||
32 | #else | ||
33 | .text | ||
34 | #endif | ||
35 | .align 2 | ||
36 | .global mpc_decoder_windowing_D | ||
37 | .type mpc_decoder_windowing_D, @function | ||
38 | |||
39 | mpc_decoder_windowing_D: | ||
40 | lea.l (-9*4, %sp), %sp | ||
41 | movem.l %d2-%d7/%a2-%a4, (%sp) | save some registers | ||
42 | movem.l (9*4+4, %sp), %a0-%a2 | a0 = Data, a1 = V, a2 = D | ||
43 | moveq.l #32, %d0 | loop counter | ||
44 | |||
45 | move.l (%a1), %a4 | ||
46 | 0: | loop | ||
47 | movem.l (%a2), %d1-%d7/%a3 | ||
48 | |||
49 | mac.l %d1, %a4, ( 96*4, %a1), %a4, %acc0 | ||
50 | mac.l %d2, %a4, (128*4, %a1), %a4, %acc0 | ||
51 | mac.l %d3, %a4, (224*4, %a1), %a4, %acc0 | ||
52 | mac.l %d4, %a4, (256*4, %a1), %a4, %acc0 | ||
53 | mac.l %d5, %a4, (352*4, %a1), %a4, %acc0 | ||
54 | mac.l %d6, %a4, (384*4, %a1), %a4, %acc0 | ||
55 | mac.l %d7, %a4, (480*4, %a1), %a4, %acc0 | ||
56 | mac.l %a3, %a4, (512*4, %a1), %a4, %acc0 | ||
57 | movem.l (8*4, %a2), %d1-%d7/%a3 | ||
58 | mac.l %d1, %a4, (608*4, %a1), %a4, %acc0 | ||
59 | mac.l %d2, %a4, (640*4, %a1), %a4, %acc0 | ||
60 | mac.l %d3, %a4, (736*4, %a1), %a4, %acc0 | ||
61 | mac.l %d4, %a4, (768*4, %a1), %a4, %acc0 | ||
62 | mac.l %d5, %a4, (864*4, %a1), %a4, %acc0 | ||
63 | mac.l %d6, %a4, (896*4, %a1), %a4, %acc0 | ||
64 | mac.l %d7, %a4, (992*4, %a1), %a4, %acc0 | ||
65 | mac.l %a3, %a4, ( 4, %a1), %a4, %acc0 | ||
66 | |||
67 | lea.l (16*4, %a2), %a2 | ||
68 | addq.l #4, %a1 | ||
69 | movclr.l %acc0, %d1 | ||
70 | lsl.l #1, %d1 | ||
71 | move.l %d1, (%a0)+ | ||
72 | subq.l #1, %d0 | ||
73 | bne 0b | ||
74 | |||
75 | movem.l (%sp), %d2-%d7/%a2-%a4 | restore stacked regs | ||
76 | lea.l (9*4, %sp), %sp | ||
77 | rts | ||
78 | |||