diff options
36 files changed, 3159 insertions, 2762 deletions
diff --git a/apps/codecs/libmusepack/AUTHORS b/apps/codecs/libmusepack/AUTHORS index 3f61a8a0a0..1bcac63765 100644 --- a/apps/codecs/libmusepack/AUTHORS +++ b/apps/codecs/libmusepack/AUTHORS | |||
@@ -1,4 +1,4 @@ | |||
1 | libmusepack is the result of the work of many people: | 1 | libmpcdec is the result of the work of many people: |
2 | 2 | ||
3 | * Andree Buschmann and Frank Klemm | 3 | * Andree Buschmann and Frank Klemm |
4 | Original implementation and core development. | 4 | Original implementation and core development. |
diff --git a/apps/codecs/libmusepack/ChangeLog b/apps/codecs/libmusepack/ChangeLog index 6a9b7dfdf8..6c998480bd 100644 --- a/apps/codecs/libmusepack/ChangeLog +++ b/apps/codecs/libmusepack/ChangeLog | |||
@@ -1,3 +1,31 @@ | |||
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 | ||
1 | 29 | ||
2 | 1.1 | 30 | 1.1 |
3 | * add compliance & cleanup patches from Michael Roitzsch of xine project | 31 | * add compliance & cleanup patches from Michael Roitzsch of xine project |
diff --git a/apps/codecs/libmusepack/README b/apps/codecs/libmusepack/README deleted file mode 100644 index 5bc42b70db..0000000000 --- a/apps/codecs/libmusepack/README +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | Musepack Decoder Library 1.1: | ||
2 | |||
3 | run "./configure; make" | ||
4 | |||
5 | To create a sample app using the musepack decoder library in src/ | ||
6 | Check src/sample.cpp for more details. | ||
diff --git a/apps/codecs/libmusepack/README.rockbox b/apps/codecs/libmusepack/README.rockbox deleted file mode 100644 index 13c93a2518..0000000000 --- a/apps/codecs/libmusepack/README.rockbox +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | Library: libmusepack-1.1 (Released 2005-01-22 (I think)) | ||
2 | Imported: 2005-04-12 by Thom Johansen | ||
3 | |||
4 | |||
5 | This directory contains a local version of libmusepack for use by Rockbox | ||
6 | for software decoding and encoding of Musepack files. | ||
7 | |||
8 | |||
9 | LICENSING INFORMATION | ||
10 | |||
11 | libmusepack is distributed under a modified BSD license - see the files AUTHORS | ||
12 | and COPYING in this directory for details. | ||
13 | |||
14 | |||
15 | IMPORT DETAILS | ||
16 | |||
17 | The base version first imported into Rockbox was the libmusepack included | ||
18 | in the libmusepack-1.1.tar.bz2 distribution, downloaded on 2005-04-11 from | ||
19 | www.musepack.net. | ||
20 | |||
21 | The contents of the libmusepack-1.1/, libmusepack-1.1/src/ and | ||
22 | libmusepack-1.1/include/ were all put in one directory for simplicity, and | ||
23 | the sample decoder and automake/autoconf stuff were removed. The default | ||
24 | FILE* based IO handlers in mpc_reader.c were also removed. Some small | ||
25 | modifications to make the library compilable and compatible with Rockbox | ||
26 | was made. | ||
27 | |||
diff --git a/apps/codecs/libmusepack/SOURCES b/apps/codecs/libmusepack/SOURCES index 0de114336f..31848214e0 100644 --- a/apps/codecs/libmusepack/SOURCES +++ b/apps/codecs/libmusepack/SOURCES | |||
@@ -1,7 +1,8 @@ | |||
1 | huffsv46.c | 1 | crc32.c |
2 | huffsv7.c | 2 | huffman.c |
3 | idtag.c | 3 | mpc_bits_reader.c |
4 | mpc_decoder.c | 4 | mpc_decoder.c |
5 | mpc_demux.c | ||
5 | requant.c | 6 | requant.c |
6 | streaminfo.c | 7 | streaminfo.c |
7 | synth_filter.c | 8 | synth_filter.c |
diff --git a/apps/codecs/libmusepack/config-mpc.h b/apps/codecs/libmusepack/config-mpc.h deleted file mode 100644 index 8d764c4031..0000000000 --- a/apps/codecs/libmusepack/config-mpc.h +++ /dev/null | |||
@@ -1,105 +0,0 @@ | |||
1 | /* include/config.h. Generated by configure. */ | ||
2 | /* include/config.h.in. Generated from configure.in by autoheader. */ | ||
3 | |||
4 | /* Define to 1 if you have the <dlfcn.h> header file. */ | ||
5 | #define HAVE_DLFCN_H 1 | ||
6 | |||
7 | /* Define to 1 if you have the <inttypes.h> header file. */ | ||
8 | #define HAVE_INTTYPES_H 1 | ||
9 | |||
10 | /* Define to 1 if you have the `memmove' function. */ | ||
11 | #define HAVE_MEMMOVE 1 | ||
12 | |||
13 | /* Define to 1 if you have the <memory.h> header file. */ | ||
14 | #define HAVE_MEMORY_H 1 | ||
15 | |||
16 | /* Define to 1 if you have the `memset' function. */ | ||
17 | #define HAVE_MEMSET 1 | ||
18 | |||
19 | /* Define to 1 if the system has the type `ptrdiff_t'. */ | ||
20 | #define HAVE_PTRDIFF_T 1 | ||
21 | |||
22 | /* Define to 1 if you have the `sqrt' function. */ | ||
23 | /* #undef HAVE_SQRT */ | ||
24 | |||
25 | /* Define to 1 if stdbool.h conforms to C99. */ | ||
26 | #define HAVE_STDBOOL_H 1 | ||
27 | |||
28 | /* Define to 1 if you have the <stdint.h> header file. */ | ||
29 | #define HAVE_STDINT_H 1 | ||
30 | |||
31 | /* Define to 1 if you have the <stdlib.h> header file. */ | ||
32 | #define HAVE_STDLIB_H 1 | ||
33 | |||
34 | /* Define to 1 if you have the <strings.h> header file. */ | ||
35 | #define HAVE_STRINGS_H 1 | ||
36 | |||
37 | /* Define to 1 if you have the <string.h> header file. */ | ||
38 | #define HAVE_STRING_H 1 | ||
39 | |||
40 | /* Define to 1 if you have the <sys/stat.h> header file. */ | ||
41 | #define HAVE_SYS_STAT_H 1 | ||
42 | |||
43 | /* Define to 1 if you have the <sys/types.h> header file. */ | ||
44 | #define HAVE_SYS_TYPES_H 1 | ||
45 | |||
46 | /* Define to 1 if you have the <unistd.h> header file. */ | ||
47 | #define HAVE_UNISTD_H 1 | ||
48 | |||
49 | /* Define to 1 if the system has the type `_Bool'. */ | ||
50 | #define HAVE__BOOL 1 | ||
51 | |||
52 | /* Name of package */ | ||
53 | #define PACKAGE "libmusepack" | ||
54 | |||
55 | /* Define to the address where bug reports for this package should be sent. */ | ||
56 | #define PACKAGE_BUGREPORT "" | ||
57 | |||
58 | /* Define to the full name of this package. */ | ||
59 | #define PACKAGE_NAME "" | ||
60 | |||
61 | /* Define to the full name and version of this package. */ | ||
62 | #define PACKAGE_STRING "" | ||
63 | |||
64 | /* Define to the one symbol short name of this package. */ | ||
65 | #define PACKAGE_TARNAME "" | ||
66 | |||
67 | /* Define to the version of this package. */ | ||
68 | #define PACKAGE_VERSION "" | ||
69 | |||
70 | /* The size of a `int', as computed by sizeof. */ | ||
71 | #define SIZEOF_INT 4 | ||
72 | |||
73 | /* The size of a `long', as computed by sizeof. */ | ||
74 | #define SIZEOF_LONG 4 | ||
75 | |||
76 | /* The size of a `long long', as computed by sizeof. */ | ||
77 | #define SIZEOF_LONG_LONG 8 | ||
78 | |||
79 | /* The size of a `short', as computed by sizeof. */ | ||
80 | #define SIZEOF_SHORT 2 | ||
81 | |||
82 | /* Define to 1 if you have the ANSI C header files. */ | ||
83 | #define STDC_HEADERS 1 | ||
84 | |||
85 | /* Version number of package */ | ||
86 | #define VERSION "1.1" | ||
87 | |||
88 | /* Define to 1 if your processor stores words with the most significant byte | ||
89 | first (like Motorola and SPARC, unlike Intel and VAX). */ | ||
90 | /* #undef WORDS_BIGENDIAN */ | ||
91 | |||
92 | /* Define to empty if `const' does not conform to ANSI C. */ | ||
93 | /* #undef const */ | ||
94 | |||
95 | /* Define to `__inline__' or `__inline' if that's what the C compiler | ||
96 | calls it, or to nothing if 'inline' is not supported under any name. */ | ||
97 | #ifndef __cplusplus | ||
98 | /* #undef inline */ | ||
99 | #endif | ||
100 | |||
101 | /* Define to `long' if <sys/types.h> does not define. */ | ||
102 | /* #undef off_t */ | ||
103 | |||
104 | /* Define to `unsigned' if <sys/types.h> does not define. */ | ||
105 | /* #undef size_t */ | ||
diff --git a/apps/codecs/libmusepack/config_types.h b/apps/codecs/libmusepack/config_types.h deleted file mode 100644 index 96e8b90430..0000000000 --- a/apps/codecs/libmusepack/config_types.h +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
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 | #ifndef __MUSEPACK_CONFIG_TYPES_H__ | ||
36 | #define __MUSEPACK_CONFIG_TYPES_H__ | ||
37 | |||
38 | typedef unsigned char mpc_bool_t; | ||
39 | #define TRUE 1 | ||
40 | #define FALSE 0 | ||
41 | |||
42 | /* these are filled in by configure */ | ||
43 | typedef signed char mpc_int8_t; | ||
44 | typedef unsigned char mpc_uint8_t; | ||
45 | typedef short mpc_int16_t; | ||
46 | typedef unsigned short mpc_uint16_t; | ||
47 | typedef int mpc_int32_t; | ||
48 | typedef unsigned int mpc_uint32_t; | ||
49 | typedef long long mpc_int64_t; | ||
50 | |||
51 | #endif // __MUSEPACK_CONFIG_TYPES_H__ | ||
diff --git a/apps/codecs/libmusepack/crc32.c b/apps/codecs/libmusepack/crc32.c new file mode 100755 index 0000000000..f9f3b8a73d --- /dev/null +++ b/apps/codecs/libmusepack/crc32.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | * C Implementation: crc32 | ||
3 | * | ||
4 | * code from http://www.w3.org/TR/PNG/#D-CRCAppendix | ||
5 | * | ||
6 | */ | ||
7 | |||
8 | /* Table of CRCs of all 8-bit messages. */ | ||
9 | static unsigned long crc_table[256]; | ||
10 | |||
11 | /* Flag: has the table been computed? Initially false. */ | ||
12 | static int crc_table_computed = 0; | ||
13 | |||
14 | /* Make the table for a fast CRC. */ | ||
15 | static void make_crc_table(void) | ||
16 | { | ||
17 | unsigned long c; | ||
18 | int n, k; | ||
19 | |||
20 | for (n = 0; n < 256; n++) { | ||
21 | c = (unsigned long) n; | ||
22 | for (k = 0; k < 8; k++) { | ||
23 | if (c & 1) | ||
24 | c = 0xedb88320L ^ (c >> 1); | ||
25 | else | ||
26 | c = c >> 1; | ||
27 | } | ||
28 | crc_table[n] = c; | ||
29 | } | ||
30 | crc_table_computed = 1; | ||
31 | } | ||
32 | |||
33 | |||
34 | /* Update a running CRC with the bytes buf[0..len-1]--the CRC | ||
35 | should be initialized to all 1's, and the transmitted value | ||
36 | is the 1's complement of the final running CRC (see the | ||
37 | crc() routine below). */ | ||
38 | |||
39 | static unsigned long update_crc(unsigned long crc, unsigned char *buf, int len) | ||
40 | { | ||
41 | unsigned long c = crc; | ||
42 | int n; | ||
43 | |||
44 | if (!crc_table_computed) | ||
45 | make_crc_table(); | ||
46 | for (n = 0; n < len; n++) { | ||
47 | c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); | ||
48 | } | ||
49 | return c; | ||
50 | } | ||
51 | |||
52 | /* Return the CRC of the bytes buf[0..len-1]. */ | ||
53 | unsigned long mpc_crc32(unsigned char *buf, int len) | ||
54 | { | ||
55 | return update_crc(0xffffffffL, buf, len) ^ 0xffffffffL; | ||
56 | } | ||
diff --git a/apps/codecs/libmusepack/decoder.h b/apps/codecs/libmusepack/decoder.h index 9031bf29e7..b3d24cf4ea 100644 --- a/apps/codecs/libmusepack/decoder.h +++ b/apps/codecs/libmusepack/decoder.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2005, The Musepack Development Team | 2 | Copyright (c) 2005-2009, The Musepack Development Team |
3 | All rights reserved. | 3 | All rights reserved. |
4 | 4 | ||
5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
@@ -31,107 +31,71 @@ | |||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | 33 | */ |
34 | |||
35 | /// \file decoder.h | 34 | /// \file decoder.h |
35 | #ifndef _MPCDEC_DECODER_H_ | ||
36 | #define _MPCDEC_DECODER_H_ | ||
37 | #ifdef WIN32 | ||
38 | #pragma once | ||
39 | #endif | ||
36 | 40 | ||
37 | #ifndef _mpcdec_decoder_h_ | ||
38 | #define _mpcdec_decoder_h_ | ||
39 | |||
40 | #include "huffman.h" | ||
41 | #include "math.h" | ||
42 | #include "musepack.h" | ||
43 | #include "reader.h" | 41 | #include "reader.h" |
44 | #include "streaminfo.h" | ||
45 | 42 | ||
46 | // define this to enable/disable support for streamversion SV4-6 | 43 | #ifdef __cplusplus |
47 | //#define MPC_SUPPORT_SV456 | 44 | extern "C" { |
45 | #endif | ||
48 | 46 | ||
49 | // SCF_HACK is used to avoid possible distortion after seeking with mpc files | 47 | #define SEEKING_TABLE_SIZE 256u |
50 | // background: scf's are coded differential in time domain. if you seek to the | 48 | // set it to SLOW_SEEKING_WINDOW to not use fast seeking |
51 | // desired postion it might happen that the baseline is missed and the resulting | 49 | #define FAST_SEEKING_WINDOW 32 |
52 | // scf is much too high (hissing noise). this hack uses the lowest scaling until | 50 | // set it to FAST_SEEKING_WINDOW to only use fast seeking |
53 | // a non-differential scf could be decoded after seek. through this hack subbands | 51 | #define SLOW_SEEKING_WINDOW 0x80000000 |
54 | // are faded out until there was at least a single non-differential scf found. | ||
55 | #define SCF_HACK | ||
56 | 52 | ||
57 | enum { | 53 | enum { |
58 | MPC_V_MEM = 2304, | 54 | MPC_V_MEM = 2304, |
59 | MPC_DECODER_MEMSIZE = 16384, // overall buffer size (words) | 55 | MPC_DECODER_MEMSIZE = 16384, // overall buffer size |
60 | MPC_SEEK_BUFFER_SIZE = 8192, // seek buffer size (words) | ||
61 | }; | 56 | }; |
62 | 57 | ||
63 | typedef struct { | 58 | struct mpc_decoder_t { |
64 | mpc_int16_t L [36]; | ||
65 | mpc_int16_t R [36]; | ||
66 | } QuantTyp; | ||
67 | |||
68 | typedef struct mpc_decoder_t { | ||
69 | mpc_reader *r; | ||
70 | |||
71 | /// @name internal state variables | 59 | /// @name internal state variables |
72 | //@{ | 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 | ||
73 | 65 | ||
74 | mpc_uint32_t next; | 66 | mpc_uint64_t samples; ///< Number of samples in stream |
75 | mpc_uint32_t dword; /// currently decoded 32bit-word | ||
76 | mpc_uint32_t pos; /// bit-position within dword | ||
77 | mpc_uint32_t *Speicher; /// read-buffer | ||
78 | mpc_uint32_t Zaehler; /// actual index within read-buffer | ||
79 | mpc_uint32_t Ring; | ||
80 | |||
81 | mpc_uint32_t samples_to_skip; | ||
82 | mpc_uint32_t last_block_samples; | ||
83 | mpc_uint32_t FwdJumpInfo; | ||
84 | mpc_uint32_t ActDecodePos; | ||
85 | |||
86 | |||
87 | mpc_uint32_t DecodedFrames; | ||
88 | mpc_uint32_t OverallFrames; | ||
89 | mpc_int32_t SampleRate; // Sample frequency | ||
90 | |||
91 | mpc_uint32_t StreamVersion; // version of bitstream | ||
92 | mpc_int32_t Max_Band; | ||
93 | mpc_uint32_t MPCHeaderPos; // AB: needed to support ID3v2 | ||
94 | 67 | ||
95 | mpc_uint32_t FrameWasValid; | 68 | mpc_uint64_t decoded_samples; ///< Number of samples decoded from file begining |
96 | mpc_uint32_t MS_used; // MS-coding used ? | 69 | mpc_uint32_t samples_to_skip; ///< Number samples to skip (used for seeking) |
97 | mpc_uint32_t TrueGaplessPresent; | 70 | mpc_int32_t last_max_band; ///< number of bands used in the last frame |
98 | |||
99 | mpc_uint32_t WordsRead; // counts amount of decoded dwords | ||
100 | 71 | ||
101 | // randomizer state variables | 72 | // randomizer state variables |
102 | mpc_uint32_t __r1; | 73 | mpc_uint32_t __r1; |
103 | mpc_uint32_t __r2; | 74 | mpc_uint32_t __r2; |
104 | 75 | ||
105 | mpc_int8_t SCF_Index_L [32] [3]; | 76 | mpc_int32_t SCF_Index_L [32] [3]; |
106 | mpc_int8_t SCF_Index_R [32] [3]; // holds scalefactor-indices | 77 | mpc_int32_t SCF_Index_R [32] [3]; // holds scalefactor-indices |
107 | QuantTyp Q [32]; // holds quantized samples | 78 | mpc_quantizer Q [32]; // holds quantized samples |
108 | mpc_int8_t Res_L [32]; | 79 | mpc_int32_t Res_L [32]; |
109 | mpc_int8_t Res_R [32]; // holds the chosen quantizer for each subband | 80 | mpc_int32_t Res_R [32]; // holds the chosen quantizer for each subband |
110 | #ifdef MPC_SUPPORT_SV456 | ||
111 | mpc_bool_t DSCF_Flag_L [32]; | 81 | mpc_bool_t DSCF_Flag_L [32]; |
112 | mpc_bool_t DSCF_Flag_R [32]; // differential SCF used? | 82 | mpc_bool_t DSCF_Flag_R [32]; // differential SCF used? |
113 | #endif | 83 | mpc_int32_t SCFI_L [32]; |
114 | mpc_int8_t SCFI_L [32]; | 84 | mpc_int32_t SCFI_R [32]; // describes order of transmitted SCF |
115 | mpc_int8_t SCFI_R [32]; // describes order of transmitted SCF | ||
116 | mpc_bool_t MS_Flag[32]; // MS used? | 85 | mpc_bool_t MS_Flag[32]; // MS used? |
117 | |||
118 | mpc_uint32_t SeekTableCounter; // used to sum up skip info, if SeekTable_Step != 1 | ||
119 | mpc_uint32_t MaxDecodedFrames; // Maximum frames decoded (indicates usable seek table entries) | ||
120 | mpc_uint32_t* SeekTable; // seek table itself | ||
121 | mpc_uint8_t SeekTable_Step; // 1<<SeekTable_Step = frames per table index | ||
122 | mpc_uint32_t SeekTable_Mask; // used to avoid modulo-operation in seek | ||
123 | |||
124 | #ifdef MPC_FIXED_POINT | 86 | #ifdef MPC_FIXED_POINT |
125 | mpc_uint8_t SCF_shift[256]; | 87 | mpc_uint8_t SCF_shift[256]; |
126 | #endif | 88 | #endif |
127 | 89 | ||
128 | MPC_SAMPLE_FORMAT V_L[MPC_V_MEM + 960]; | 90 | MPC_SAMPLE_FORMAT V_L[MPC_V_MEM + 960]; |
129 | MPC_SAMPLE_FORMAT V_R[MPC_V_MEM + 960]; | 91 | MPC_SAMPLE_FORMAT V_R[MPC_V_MEM + 960]; |
130 | MPC_SAMPLE_FORMAT (*Y_L)[32]; | 92 | MPC_SAMPLE_FORMAT *Y_L; |
131 | MPC_SAMPLE_FORMAT (*Y_R)[32]; | 93 | MPC_SAMPLE_FORMAT *Y_R; |
132 | MPC_SAMPLE_FORMAT SCF[256]; ///< holds adapted scalefactors (for clipping prevention) | 94 | MPC_SAMPLE_FORMAT SCF[256]; ///< holds adapted scalefactors (for clipping prevention) |
133 | //@} | 95 | //@} |
96 | }; | ||
134 | 97 | ||
135 | } mpc_decoder; | 98 | #ifdef __cplusplus |
136 | 99 | } | |
137 | #endif // _mpc_decoder_h | 100 | #endif |
101 | #endif | ||
diff --git a/apps/codecs/libmusepack/huffman.c b/apps/codecs/libmusepack/huffman.c new file mode 100755 index 0000000000..c304775623 --- /dev/null +++ b/apps/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/apps/codecs/libmusepack/huffman.h b/apps/codecs/libmusepack/huffman.h index 87fd5c15a4..1244149184 100644 --- a/apps/codecs/libmusepack/huffman.h +++ b/apps/codecs/libmusepack/huffman.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2005, The Musepack Development Team | 2 | Copyright (c) 2005-2009, The Musepack Development Team |
3 | All rights reserved. | 3 | All rights reserved. |
4 | 4 | ||
5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
@@ -31,23 +31,53 @@ | |||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | 33 | */ |
34 | |||
35 | /// \file huffman.h | 34 | /// \file huffman.h |
36 | /// Data structures and functions for huffman coding. | 35 | /// Data structures and functions for huffman coding. |
37 | 36 | ||
38 | #ifndef _mpcdec_huffman_h_ | 37 | #ifndef _MPCDEC_HUFFMAN_H_ |
39 | #define _mpcdec_huffman_h_ | 38 | #define _MPCDEC_HUFFMAN_H_ |
39 | #ifdef WIN32 | ||
40 | #pragma once | ||
41 | #endif | ||
42 | |||
43 | #include "mpc_types.h" | ||
40 | 44 | ||
41 | #include "config_types.h" | 45 | #ifdef __cplusplus |
42 | #include "decoder.h" | 46 | extern "C" { |
47 | #endif | ||
43 | 48 | ||
44 | struct mpc_decoder_t; // forward declare to break circular dependencies | 49 | // LUT size parameter, LUT size is 1 << LUT_DEPTH |
50 | #define LUT_DEPTH 6 | ||
45 | 51 | ||
46 | /// Huffman table entry. | 52 | /// Huffman table entry. |
47 | typedef struct huffman_type_t { | 53 | typedef struct mpc_huffman_t { |
48 | mpc_uint32_t Code; | 54 | mpc_uint16_t Code; |
49 | mpc_uint8_t Length; | 55 | mpc_uint8_t Length; |
50 | mpc_int8_t Value; | 56 | mpc_int8_t Value; |
51 | } HuffmanTyp; | 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); | ||
52 | 79 | ||
53 | #endif // _mpcdec_huffman_h_ | 80 | #ifdef __cplusplus |
81 | } | ||
82 | #endif | ||
83 | #endif | ||
diff --git a/apps/codecs/libmusepack/huffsv46.c b/apps/codecs/libmusepack/huffsv46.c deleted file mode 100644 index 20d754c7bb..0000000000 --- a/apps/codecs/libmusepack/huffsv46.c +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
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 huffsv46.c | ||
36 | /// Implementations of huffman decoding for streamversions < 7. | ||
37 | |||
38 | #include "musepack.h" | ||
39 | #include "requant.h" | ||
40 | #include "huffman.h" | ||
41 | |||
42 | #ifdef MPC_SUPPORT_SV456 | ||
43 | |||
44 | |||
45 | const HuffmanTyp mpc_table_SCFI_Bundle [ 8] = | ||
46 | {{2147483648u,1,7},{1073741824u,2,3},{939524096u,5,1},{805306368u,5,2},{738197504u,6,0},{671088640u,6,6},{536870912u,5,4},{0u,3,5},}; | ||
47 | const HuffmanTyp mpc_table_DSCF_Entropie [13] = | ||
48 | {{3758096384u,3,1},{3489660928u,4,3},{3355443200u,5,5},{3221225472u,5,-3},{2952790016u,4,-2},{2684354560u,4,4},{2147483648u,3,-1},{1610612736u,3,2},{1476395008u,5,-5},{1409286144u,6,6},{1342177280u,6,-6},{1073741824u,4,-4},{0u,2,0},}; | ||
49 | const HuffmanTyp mpc_table_Region_A [16] = | ||
50 | {{2147483648u,1,1},{2013265920u,5,3},{1946157056u,6,4},{1912602624u,7,7},{1895825408u,8,8},{1887436800u,9,9},{1883242496u,10,10},{1881145344u,11,11},{1880096768u,12,12},{1879572480u,13,13},{1879310336u,14,14},{1879048192u,14,15},{1744830464u,5,5},{1610612736u,5,6},{1073741824u,3,0},{0u,2,2},}; | ||
51 | const HuffmanTyp mpc_table_Region_B [ 8] = | ||
52 | {{2147483648u,1,1},{1073741824u,2,0},{536870912u,3,2},{268435456u,4,3},{134217728u,5,4},{67108864u,6,5},{33554432u,7,6},{0u,7,7},}; | ||
53 | const HuffmanTyp mpc_table_Region_C [ 4] = | ||
54 | {{2147483648u,1,0},{1073741824u,2,1},{536870912u,3,2},{0u,3,3},}; | ||
55 | |||
56 | static const HuffmanTyp mpc_table_Entropie_1 [ 3] = | ||
57 | {{2147483648u,1,0},{1073741824u,2,-1},{0u,2,1},}; | ||
58 | static const HuffmanTyp mpc_table_Entropie_2 [ 5] = | ||
59 | {{3221225472u,2,0},{2684354560u,3,2},{2147483648u,3,-2},{1073741824u,2,1},{0u,2,-1},}; | ||
60 | static const HuffmanTyp mpc_table_Entropie_3 [ 7] = | ||
61 | {{3221225472u,2,0},{2684354560u,3,-2},{2415919104u,4,2},{2281701376u,5,-3},{2147483648u,5,3},{1073741824u,2,-1},{0u,2,1},}; | ||
62 | static const HuffmanTyp mpc_table_Entropie_4 [ 9] = | ||
63 | {{4026531840u,4,3},{3758096384u,4,-3},{3221225472u,3,1},{2684354560u,3,-1},{2147483648u,3,2},{1610612736u,3,-2},{1342177280u,4,-4},{1073741824u,4,4},{0u,2,0},}; | ||
64 | static const HuffmanTyp mpc_table_Entropie_5 [15] = | ||
65 | {{4026531840u,4,-2},{3892314112u,5,-5},{3825205248u,6,-7},{3758096384u,6,7},{3489660928u,4,-3},{3221225472u,4,3},{3087007744u,5,-6},{2952790016u,5,6},{2684354560u,4,4},{2147483648u,3,0},{1610612736u,3,1},{1073741824u,3,-1},{805306368u,4,-4},{536870912u,4,5},{0u,3,2},}; | ||
66 | static const HuffmanTyp mpc_table_Entropie_6 [31] = | ||
67 | {{4160749568u,5,-4},{4026531840u,5,5},{3892314112u,5,-5},{3825205248u,6,10},{3758096384u,6,-10},{3623878656u,5,-6},{3489660928u,5,6},{3355443200u,5,7},{3221225472u,5,-7},{3087007744u,5,-8},{3019898880u,6,-11},{2986344448u,7,14},{2952790016u,7,-14},{2818572288u,5,8},{2751463424u,6,11},{2684354560u,6,-13},{2415919104u,4,0},{2147483648u,4,1},{1879048192u,4,-1},{1610612736u,4,3},{1342177280u,4,2},{1207959552u,5,-9},{1140850688u,6,12},{1073741824u,6,13},{805306368u,4,-3},{536870912u,4,-2},{402653184u,5,9},{335544320u,6,-12},{301989888u,7,15},{268435456u,7,-15},{0u,4,4},}; | ||
68 | static const HuffmanTyp mpc_table_Entropie_7 [63] = | ||
69 | {{4278190080u,8,28},{4261412864u,8,26},{4227858432u,7,-20},{4160749568u,6,8},{4093640704u,6,-8},{4026531840u,6,-9},{3959422976u,6,9},{3925868544u,7,20},{3892314112u,7,21},{3825205248u,6,-10},{3758096384u,6,-11},{3690987520u,6,10},{3623878656u,6,11},{3590324224u,7,-21},{3573547008u,8,29},{3556769792u,8,-29},{3489660928u,6,13},{3422552064u,6,-13},{3355443200u,6,-12},{3288334336u,6,12},{3254779904u,7,-22},{3221225472u,7,22},{3154116608u,6,14},{3087007744u,6,15},{3019898880u,6,-14},{2986344448u,7,-23},{2952790016u,7,23},{2885681152u,6,-15},{2818572288u,6,-16},{2751463424u,6,16},{2717908992u,7,27},{2684354560u,7,-27},{2617245696u,6,17},{2550136832u,6,-17},{2533359616u,8,-30},{2516582400u,8,30},{2483027968u,7,24},{2415919104u,6,-18},{2281701376u,5,-1},{2147483648u,5,1},{2113929216u,7,-24},{2080374784u,7,25},{2013265920u,6,18},{1879048192u,5,-3},{1744830464u,5,3},{1610612736u,5,5},{1476395008u,5,0},{1342177280u,5,-2},{1275068416u,6,19},{1207959552u,6,-19},{1073741824u,5,-5},{939524096u,5,-4},{805306368u,5,-7},{671088640u,5,2},{536870912u,5,4},{402653184u,5,7},{369098752u,7,-25},{335544320u,7,-26},{301989888u,7,-28},{285212672u,8,-31},{268435456u,8,31},{134217728u,5,6},{0u,5,-6},}; | ||
70 | |||
71 | const HuffmanTyp* mpc_table_SampleHuff [18] = { | ||
72 | NULL,mpc_table_Entropie_1,mpc_table_Entropie_2,mpc_table_Entropie_3,mpc_table_Entropie_4,mpc_table_Entropie_5,mpc_table_Entropie_6,mpc_table_Entropie_7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL | ||
73 | }; | ||
74 | |||
75 | #endif //#ifdef MPC_SUPPORT_SV456 | ||
diff --git a/apps/codecs/libmusepack/huffsv7.c b/apps/codecs/libmusepack/huffsv7.c deleted file mode 100644 index 9ca77ceaa5..0000000000 --- a/apps/codecs/libmusepack/huffsv7.c +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
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 huffsv7.c | ||
36 | /// Implementations of sv7 huffman decoding functions. | ||
37 | |||
38 | #include "musepack.h" | ||
39 | #include "huffman.h" | ||
40 | #include "requant.h" | ||
41 | |||
42 | const HuffmanTyp mpc_table_HuffHdr [10] ICONST_ATTR = | ||
43 | {{2147483648u,1,0},{1610612736u,3,1},{1577058304u,7,-4},{1568669696u,9,3},{1560281088u,9,4},{1543503872u,8,-5},{1476395008u,6,2},{1342177280u,5,-3},{1073741824u,4,-2},{0u,2,-1},}; | ||
44 | const HuffmanTyp mpc_table_HuffSCFI [ 4] ICONST_ATTR = | ||
45 | {{2147483648u,1,1},{1610612736u,3,2},{1073741824u,3,0},{0u,2,3},}; | ||
46 | const HuffmanTyp mpc_table_HuffDSCF [16] ICONST_ATTR = | ||
47 | {{4160749568u,5,5},{4026531840u,5,-4},{3758096384u,4,3},{3489660928u,4,-3},{3221225472u,4,8},{2684354560u,3,1},{2415919104u,4,0},{2281701376u,5,-5},{2214592512u,6,7},{2147483648u,6,-7},{1610612736u,3,-1},{1073741824u,3,2},{805306368u,4,4},{671088640u,5,6},{536870912u,5,-6},{0u,3,-2},}; | ||
48 | |||
49 | static const HuffmanTyp mpc_table_HuffQ1 [2] [3*3*3] ICONST_ATTR = { | ||
50 | {{3758096384u,3,13},{3690987520u,6,26},{3623878656u,6,0},{3556769792u,6,20},{3489660928u,6,6},{3221225472u,4,14},{2952790016u,4,12},{2684354560u,4,4},{2415919104u,4,22},{2348810240u,6,8},{2281701376u,6,18},{2214592512u,6,24},{2147483648u,6,2},{1879048192u,4,16},{1610612736u,4,10},{1476395008u,5,17},{1342177280u,5,9},{1207959552u,5,1},{1073741824u,5,25},{939524096u,5,5},{805306368u,5,21},{671088640u,5,3},{536870912u,5,11},{402653184u,5,15},{268435456u,5,23},{134217728u,5,19},{0u,5,7},}, | ||
51 | {{2147483648u,1,13},{2113929216u,7,15},{2080374784u,7,1},{2046820352u,7,11},{2013265920u,7,7},{1979711488u,7,17},{1946157056u,7,25},{1912602624u,7,19},{1904214016u,9,8},{1895825408u,9,18},{1887436800u,9,2},{1879048192u,9,24},{1845493760u,7,3},{1811939328u,7,23},{1778384896u,7,21},{1744830464u,7,5},{1728053248u,8,0},{1711276032u,8,26},{1694498816u,8,6},{1677721600u,8,20},{1610612736u,6,9},{1342177280u,4,14},{1073741824u,4,12},{805306368u,4,4},{536870912u,4,22},{268435456u,4,16},{0u,4,10},}, | ||
52 | }; | ||
53 | static const HuffmanTyp mpc_table_HuffQ2 [2] [5*5] ICONST_ATTR = { | ||
54 | {{4026531840u,4,13},{3758096384u,4,17},{3489660928u,4,7},{3221225472u,4,11},{3154116608u,6,1},{3087007744u,6,23},{3053453312u,7,4},{3019898880u,7,20},{2986344448u,7,0},{2952790016u,7,24},{2818572288u,5,22},{2684354560u,5,10},{2147483648u,3,12},{2013265920u,5,2},{1879048192u,5,14},{1610612736u,4,6},{1342177280u,4,18},{1073741824u,4,8},{805306368u,4,16},{671088640u,5,9},{536870912u,5,5},{402653184u,5,15},{268435456u,5,21},{134217728u,5,19},{0u,5,3},}, | ||
55 | {{4160749568u,5,18},{4026531840u,5,6},{3892314112u,5,8},{3875536896u,8,3},{3871342592u,10,24},{3867148288u,10,4},{3862953984u,10,0},{3858759680u,10,20},{3825205248u,7,23},{3791650816u,7,1},{3758096384u,7,19},{3623878656u,5,16},{3590324224u,7,15},{3556769792u,7,21},{3523215360u,7,9},{3489660928u,7,5},{3422552064u,6,2},{3355443200u,6,10},{3288334336u,6,14},{3221225472u,6,22},{2147483648u,2,12},{1610612736u,3,13},{1073741824u,3,17},{536870912u,3,11},{0u,3,7},}, | ||
56 | }; | ||
57 | static const HuffmanTyp mpc_table_HuffQ3 [2] [ 7] ICONST_ATTR = { | ||
58 | {{3758096384u,3,1},{3489660928u,4,3},{3221225472u,4,-3},{2684354560u,3,2},{2147483648u,3,-2},{1073741824u,2,0},{0u,2,-1},}, | ||
59 | {{3221225472u,2,0},{2147483648u,2,-1},{1073741824u,2,1},{805306368u,4,-2},{671088640u,5,3},{536870912u,5,-3},{0u,3,2},}, | ||
60 | }; | ||
61 | static const HuffmanTyp mpc_table_HuffQ4 [2] [ 9] ICONST_ATTR = { | ||
62 | {{3758096384u,3,0},{3221225472u,3,-1},{2684354560u,3,1},{2147483648u,3,-2},{1610612736u,3,2},{1342177280u,4,-4},{1073741824u,4,4},{536870912u,3,3},{0u,3,-3},}, | ||
63 | {{3758096384u,3,1},{3489660928u,4,2},{3221225472u,4,-3},{2147483648u,2,0},{1610612736u,3,-2},{1342177280u,4,3},{1207959552u,5,-4},{1073741824u,5,4},{0u,2,-1},}, | ||
64 | }; | ||
65 | static const HuffmanTyp mpc_table_HuffQ5 [2] [15] ICONST_ATTR = { | ||
66 | {{4026531840u,4,2},{3892314112u,5,5},{3825205248u,6,-7},{3758096384u,6,7},{3489660928u,4,-3},{3221225472u,4,3},{3087007744u,5,-6},{2952790016u,5,6},{2684354560u,4,-4},{2415919104u,4,4},{2147483648u,4,-5},{1610612736u,3,0},{1073741824u,3,-1},{536870912u,3,1},{0u,3,-2},}, | ||
67 | {{4026531840u,4,3},{3892314112u,5,4},{3858759680u,7,6},{3841982464u,8,-7},{3825205248u,8,7},{3758096384u,6,-6},{3221225472u,3,0},{2684354560u,3,-1},{2147483648u,3,1},{1610612736u,3,-2},{1073741824u,3,2},{939524096u,5,-5},{805306368u,5,5},{536870912u,4,-4},{0u,3,-3},}, | ||
68 | }; | ||
69 | static const HuffmanTyp mpc_table_HuffQ6 [2] [31] ICONST_ATTR = { | ||
70 | {{4160749568u,5,3},{4026531840u,5,-4},{3959422976u,6,-11},{3892314112u,6,12},{3758096384u,5,4},{3623878656u,5,6},{3489660928u,5,-5},{3355443200u,5,5},{3221225472u,5,7},{3087007744u,5,-7},{3019898880u,6,-12},{2952790016u,6,-13},{2818572288u,5,-6},{2684354560u,5,8},{2550136832u,5,-8},{2415919104u,5,9},{2281701376u,5,-9},{2214592512u,6,13},{2181038080u,7,-15},{2147483648u,7,15},{1879048192u,4,0},{1744830464u,5,-10},{1610612736u,5,10},{1342177280u,4,-1},{1073741824u,4,2},{805306368u,4,1},{536870912u,4,-2},{469762048u,6,14},{402653184u,6,-14},{268435456u,5,11},{0u,4,-3},}, | ||
71 | {{4160749568u,5,-6},{4026531840u,5,6},{3758096384u,4,1},{3489660928u,4,-1},{3456106496u,7,10},{3422552064u,7,-10},{3405774848u,8,-11},{3397386240u,9,-12},{3395289088u,11,13},{3394764800u,13,15},{3394240512u,13,-14},{3393716224u,13,14},{3393191936u,13,-15},{3388997632u,10,-13},{3372220416u,8,11},{3355443200u,8,12},{3288334336u,6,-9},{3221225472u,6,9},{2952790016u,4,-2},{2684354560u,4,2},{2415919104u,4,3},{2147483648u,4,-3},{2013265920u,5,-7},{1879048192u,5,7},{1610612736u,4,-4},{1342177280u,4,4},{1207959552u,5,-8},{1073741824u,5,8},{805306368u,4,5},{536870912u,4,-5},{0u,3,0},}, | ||
72 | }; | ||
73 | static const HuffmanTyp mpc_table_HuffQ7 [2] [63] ICONST_ATTR = { | ||
74 | {{4227858432u,6,7},{4160749568u,6,8},{4093640704u,6,9},{4026531840u,6,-8},{3959422976u,6,11},{3925868544u,7,21},{3909091328u,8,-28},{3892314112u,8,28},{3825205248u,6,-9},{3791650816u,7,-22},{3758096384u,7,-21},{3690987520u,6,-10},{3623878656u,6,-11},{3556769792u,6,10},{3489660928u,6,12},{3422552064u,6,-13},{3388997632u,7,22},{3355443200u,7,23},{3288334336u,6,-12},{3221225472u,6,13},{3154116608u,6,14},{3087007744u,6,-14},{3053453312u,7,-23},{3036676096u,8,-29},{3019898880u,8,29},{2952790016u,6,-15},{2885681152u,6,15},{2818572288u,6,16},{2751463424u,6,-16},{2717908992u,7,-24},{2684354560u,7,24},{2617245696u,6,17},{2583691264u,7,-25},{2566914048u,8,-30},{2550136832u,8,30},{2483027968u,6,-17},{2415919104u,6,18},{2348810240u,6,-18},{2315255808u,7,25},{2281701376u,7,26},{2214592512u,6,19},{2181038080u,7,-26},{2147483648u,7,-27},{2013265920u,5,2},{1946157056u,6,-19},{1879048192u,6,20},{1744830464u,5,-1},{1728053248u,8,-31},{1711276032u,8,31},{1677721600u,7,27},{1610612736u,6,-20},{1476395008u,5,1},{1342177280u,5,-5},{1207959552u,5,-3},{1073741824u,5,3},{939524096u,5,0},{805306368u,5,-2},{671088640u,5,-4},{536870912u,5,4},{402653184u,5,5},{268435456u,5,-6},{134217728u,5,6},{0u,5,-7},}, | ||
75 | {{4160749568u,5,-1},{4026531840u,5,2},{3892314112u,5,-2},{3758096384u,5,3},{3741319168u,8,-20},{3737124864u,10,24},{3736862720u,14,28},{3736600576u,14,-28},{3736338432u,14,-30},{3736076288u,14,30},{3735027712u,12,-27},{3734765568u,14,29},{3734503424u,14,-29},{3734241280u,14,31},{3733979136u,14,-31},{3732930560u,12,27},{3724541952u,9,-22},{3690987520u,7,-17},{3623878656u,6,-11},{3489660928u,5,-3},{3355443200u,5,4},{3221225472u,5,-4},{3187671040u,7,17},{3170893824u,8,20},{3162505216u,9,22},{3158310912u,10,-25},{3154116608u,10,-26},{3087007744u,6,12},{2952790016u,5,5},{2818572288u,5,-5},{2684354560u,5,6},{2550136832u,5,-6},{2483027968u,6,-12},{2449473536u,7,-18},{2415919104u,7,18},{2348810240u,6,13},{2281701376u,6,-13},{2147483648u,5,-7},{2080374784u,6,14},{2063597568u,8,21},{2046820352u,8,-21},{2013265920u,7,-19},{1879048192u,5,7},{1744830464u,5,8},{1677721600u,6,-14},{1610612736u,6,-15},{1476395008u,5,-8},{1409286144u,6,15},{1375731712u,7,19},{1371537408u,10,25},{1367343104u,10,26},{1358954496u,9,-23},{1350565888u,9,23},{1342177280u,9,-24},{1207959552u,5,-9},{1073741824u,5,9},{1006632960u,6,16},{939524096u,6,-16},{805306368u,5,10},{536870912u,4,0},{402653184u,5,-10},{268435456u,5,11},{0u,4,1},}, | ||
76 | }; | ||
77 | |||
78 | const HuffmanTyp* mpc_table_HuffQ [2] [8] = { | ||
79 | {0,mpc_table_HuffQ1[0],mpc_table_HuffQ2[0],mpc_table_HuffQ3[0],mpc_table_HuffQ4[0],mpc_table_HuffQ5[0],mpc_table_HuffQ6[0],mpc_table_HuffQ7[0]}, | ||
80 | {0,mpc_table_HuffQ1[1],mpc_table_HuffQ2[1],mpc_table_HuffQ3[1],mpc_table_HuffQ4[1],mpc_table_HuffQ5[1],mpc_table_HuffQ6[1],mpc_table_HuffQ7[1]}, | ||
81 | }; | ||
diff --git a/apps/codecs/libmusepack/idtag.c b/apps/codecs/libmusepack/idtag.c deleted file mode 100644 index 8af5ce4d3b..0000000000 --- a/apps/codecs/libmusepack/idtag.c +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
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 idtag.c | ||
36 | /// Rudimentary id3tag handling routines, just enough to skip id3v2 tags, | ||
37 | /// if present. | ||
38 | |||
39 | #include "musepack.h" | ||
40 | #include "internal.h" | ||
41 | |||
42 | mpc_int32_t | ||
43 | JumpID3v2 (mpc_reader* r) { | ||
44 | unsigned char tmp [10]; | ||
45 | mpc_uint32_t Unsynchronisation; // ID3v2.4-flag | ||
46 | mpc_uint32_t ExtHeaderPresent; // ID3v2.4-flag | ||
47 | mpc_uint32_t ExperimentalFlag; // ID3v2.4-flag | ||
48 | mpc_uint32_t FooterPresent; // ID3v2.4-flag | ||
49 | mpc_int32_t ret; | ||
50 | |||
51 | // seek to first byte of mpc data | ||
52 | if (!r->seek (r->data, 0)) { | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | r->read(r->data, tmp, sizeof(tmp)); | ||
57 | |||
58 | // check id3-tag | ||
59 | if ( 0 != memcmp ( tmp, "ID3", 3) ) | ||
60 | return 0; | ||
61 | |||
62 | // read flags | ||
63 | Unsynchronisation = tmp[5] & 0x80; | ||
64 | ExtHeaderPresent = tmp[5] & 0x40; | ||
65 | ExperimentalFlag = tmp[5] & 0x20; | ||
66 | FooterPresent = tmp[5] & 0x10; | ||
67 | |||
68 | if ( tmp[5] & 0x0F ) | ||
69 | return -1; // not (yet???) allowed | ||
70 | if ( (tmp[6] | tmp[7] | tmp[8] | tmp[9]) & 0x80 ) | ||
71 | return -1; // not allowed | ||
72 | |||
73 | // read HeaderSize (syncsave: 4 * $0xxxxxxx = 28 significant bits) | ||
74 | ret = tmp[6] << 21; | ||
75 | ret += tmp[7] << 14; | ||
76 | ret += tmp[8] << 7; | ||
77 | ret += tmp[9] ; | ||
78 | ret += 10; | ||
79 | if ( FooterPresent ) | ||
80 | ret += 10; | ||
81 | |||
82 | return ret; | ||
83 | } | ||
diff --git a/apps/codecs/libmusepack/internal.h b/apps/codecs/libmusepack/internal.h index 45f2b41eea..d12c39c96b 100644 --- a/apps/codecs/libmusepack/internal.h +++ b/apps/codecs/libmusepack/internal.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2005, The Musepack Development Team | 2 | Copyright (c) 2005-2009, The Musepack Development Team |
3 | All rights reserved. | 3 | All rights reserved. |
4 | 4 | ||
5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
@@ -31,43 +31,77 @@ | |||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | 33 | */ |
34 | |||
35 | /// \file internal.h | 34 | /// \file internal.h |
36 | /// Definitions and structures used only internally by the libmpcdec. | 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 | ||
37 | 44 | ||
38 | #ifndef _mpcdec_internal_h | 45 | #include "mpcdec.h" |
39 | #define _mpcdec_internal_h | ||
40 | |||
41 | |||
42 | enum { | ||
43 | MPC_DECODER_SYNTH_DELAY = 481 | ||
44 | }; | ||
45 | 46 | ||
47 | /* rockbox: not used, rockbox's swap32 is used now. | ||
46 | /// Big/little endian 32 bit byte swapping routine. | 48 | /// Big/little endian 32 bit byte swapping routine. |
47 | /* Use our Rockbox (maybe) optimised swap routine instead */ | 49 | static mpc_inline |
48 | #define mpc_swap32(x) swap32(x) | ||
49 | #if 0 | ||
50 | static __inline | ||
51 | mpc_uint32_t mpc_swap32(mpc_uint32_t val) { | 50 | mpc_uint32_t mpc_swap32(mpc_uint32_t val) { |
52 | return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | | 51 | return (((val & 0xFF000000) >> 24) | ((val & 0x00FF0000) >> 8) |
53 | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24)); | 52 | | ((val & 0x0000FF00) << 8) | ((val & 0x000000FF) << 24)); |
54 | } | 53 | } |
55 | #endif | 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; | ||
56 | 59 | ||
57 | #ifndef min | 60 | #define MAX_FRAME_SIZE 4352 |
58 | #define min(a, b) (((a) < (b)) ? (a) : (b)) | 61 | #define DEMUX_BUFFER_SIZE (65536 - MAX_FRAME_SIZE) // need some space as sand box |
59 | #endif | 62 | |
63 | struct mpc_demux_t { | ||
64 | mpc_reader * r; | ||
65 | mpc_decoder * d; | ||
66 | mpc_streaminfo si; | ||
60 | 67 | ||
61 | /// Searches for a ID3v2-tag and reads the length (in bytes) of it. | 68 | // buffer |
62 | /// \param reader supplying raw stream data | 69 | mpc_uint8_t *buffer; |
63 | /// \return size of tag, in bytes | 70 | mpc_size_t bytes_total; |
64 | /// \return -1 on errors of any kind | 71 | mpc_bits_reader bits_reader; |
65 | mpc_int32_t JumpID3v2(mpc_reader* fp); | 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 | mpc_seek_t chap_pos; /// supposed position of the first chapter block | ||
82 | mpc_int_t chap_nb; /// number of chapters (-1 if unknown, 0 if no chapter) | ||
83 | mpc_chap_info * chap; /// chapters position and tag | ||
84 | |||
85 | }; | ||
86 | |||
87 | /** | ||
88 | * checks if a block key is valid | ||
89 | * @param key the two caracters key to check | ||
90 | * @return MPC_STATUS_INVALIDSV if the key is invalid, MPC_STATUS_OK else | ||
91 | */ | ||
92 | static mpc_inline mpc_status mpc_check_key(char * key) | ||
93 | { | ||
94 | if (key[0] < 65 || key[0] > 90 || key[1] < 65 || key[1] > 90) | ||
95 | return MPC_STATUS_INVALIDSV; | ||
96 | return MPC_STATUS_OK; | ||
97 | } | ||
66 | 98 | ||
67 | /// helper functions used by multiple files | 99 | /// helper functions used by multiple files |
68 | mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c | 100 | mpc_uint32_t mpc_random_int(mpc_decoder *d); // in synth_filter.c |
69 | void mpc_decoder_initialisiere_quantisierungstabellen(mpc_decoder *d, double scale_factor); | 101 | void mpc_decoder_init_quant(mpc_decoder *d, double scale_factor); |
70 | void mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData); | 102 | void mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT* OutData, mpc_int_t channels); |
71 | |||
72 | #endif // _mpcdec_internal_h | ||
73 | 103 | ||
104 | #ifdef __cplusplus | ||
105 | } | ||
106 | #endif | ||
107 | #endif | ||
diff --git a/apps/codecs/libmusepack/mainpage.h b/apps/codecs/libmusepack/mainpage.h deleted file mode 100644 index a51174aa3a..0000000000 --- a/apps/codecs/libmusepack/mainpage.h +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | /** | ||
2 | \mainpage libmusepack documentation | ||
3 | |||
4 | \section whats what is libmusepack | ||
5 | libmusepack is a library that decodes musepack compressed audio data. Musepack | ||
6 | is a free, high performance, high quality lossy audio compression codec. For | ||
7 | more information on musepack visit http://www.musepack.net. | ||
8 | |||
9 | \section using using libmusepack | ||
10 | |||
11 | Using libmusepack is very straightforward. There are typically four things you must | ||
12 | do to use libmusepack in your application. | ||
13 | |||
14 | \subsection step1 step 1: implement an mpc_reader to provide raw data to the decoder library | ||
15 | The role of the mpc_reader is to provide raw mpc stream data to the mpc decoding library. | ||
16 | This data can come from a file, a network socket, or any other source you wish. | ||
17 | |||
18 | See the documentation of | ||
19 | \link mpc_reader_t mpc_reader \endlink | ||
20 | for more information. | ||
21 | |||
22 | \subsection step2 step2: read the streaminfo properties structure from the stream | ||
23 | This is a simple matter of calling the streaminfo_init() and streaminfo_read() functions, | ||
24 | supplying your mpc_reader as a source of raw data. This reads the stream properties header from the | ||
25 | mpc stream. This information will be used to prime the decoder for decoding in | ||
26 | the next step. | ||
27 | |||
28 | \subsection step3 step 3: initialize an mpc_decoder with your mpc_reader source | ||
29 | This is just a matter of calling the mpc_decoder_setup() and mpc_decoder_initialize() | ||
30 | functions with your mpc_decoder, mpc_reader data source and streaminfo information. | ||
31 | |||
32 | \subsection step4 step 4: iteratively read raw sample data from the mpc decoder | ||
33 | Once you've initialized the decoding library you just iteratively call the | ||
34 | mpc_decoder_decode routine until it indicates that the entire stream has been read. | ||
35 | |||
36 | For a simple example of all of these steps see the sample application distributed with | ||
37 | libmusepack in src/sample.cpp. | ||
38 | */ | ||
diff --git a/apps/codecs/libmusepack/minimax.h b/apps/codecs/libmusepack/minimax.h new file mode 100755 index 0000000000..1192626567 --- /dev/null +++ b/apps/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/apps/codecs/libmusepack/mpc_bits_reader.c b/apps/codecs/libmusepack/mpc_bits_reader.c new file mode 100755 index 0000000000..bc86cd1a72 --- /dev/null +++ b/apps/codecs/libmusepack/mpc_bits_reader.c | |||
@@ -0,0 +1,179 @@ | |||
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_LARGE_IRAM = | ||
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_LARGE_IRAM = | ||
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_LARGE_IRAM = | ||
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_LARGE_IRAM = | ||
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_LARGE_IRAM = | ||
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 (log2[max - 1] > 1) | ||
140 | value = mpc_bits_read(r, log2[max - 1] - 1); | ||
141 | if (value >= log2_lost[max - 1]) | ||
142 | value = ((value << 1) | mpc_bits_read(r, 1)) - log2_lost[max - 1]; | ||
143 | return value; | ||
144 | } | ||
145 | |||
146 | unsigned int mpc_bits_get_size(mpc_bits_reader * r, mpc_uint64_t * p_size) | ||
147 | { | ||
148 | unsigned char tmp; | ||
149 | mpc_uint64_t size = 0; | ||
150 | unsigned int ret = 0; | ||
151 | |||
152 | do { | ||
153 | tmp = mpc_bits_read(r, 8); | ||
154 | size = (size << 7) | (tmp & 0x7F); | ||
155 | ret++; | ||
156 | } while((tmp & 0x80)); | ||
157 | |||
158 | *p_size = size; | ||
159 | return ret; | ||
160 | } | ||
161 | |||
162 | int mpc_bits_get_block(mpc_bits_reader * r, mpc_block * p_block) | ||
163 | { | ||
164 | int size = 2; | ||
165 | |||
166 | p_block->size = 0; | ||
167 | p_block->key[0] = mpc_bits_read(r, 8); | ||
168 | p_block->key[1] = mpc_bits_read(r, 8); | ||
169 | |||
170 | size += mpc_bits_get_size(r, &(p_block->size)); | ||
171 | |||
172 | if (p_block->size >= (mpc_uint64_t)size) // check if the block size doesn't conflict with the header size | ||
173 | p_block->size -= (mpc_uint64_t)size; | ||
174 | |||
175 | return size; | ||
176 | } | ||
177 | |||
178 | |||
179 | |||
diff --git a/apps/codecs/libmusepack/mpc_bits_reader.h b/apps/codecs/libmusepack/mpc_bits_reader.h new file mode 100755 index 0000000000..1233720c74 --- /dev/null +++ b/apps/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/apps/codecs/libmusepack/mpc_config.h b/apps/codecs/libmusepack/mpc_config.h deleted file mode 100644 index 7bc922c4a7..0000000000 --- a/apps/codecs/libmusepack/mpc_config.h +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
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 | #ifndef _mpc_config_h_ | ||
23 | #define _mpc_config_h_ | ||
24 | |||
25 | #include "config.h" | ||
26 | |||
27 | /* choose fixed point or floating point */ | ||
28 | #define MPC_FIXED_POINT | ||
29 | |||
30 | #ifndef MPC_FIXED_POINT | ||
31 | #error FIXME, mpc will not with floating point now | ||
32 | #endif | ||
33 | |||
34 | /* choose speed vs. accuracy for MPC_FIXED_POINT | ||
35 | * speed-setting will increase decoding speed on ARM only (+20%), loss of accuracy | ||
36 | * equals about 5 dB SNR (15bit output precision) to not use the speed-optimization | ||
37 | * -> comment OPTIMIZE_FOR_SPEED here for desired target */ | ||
38 | #if defined(MPC_FIXED_POINT) | ||
39 | #if defined(CPU_COLDFIRE) | ||
40 | // do nothing | ||
41 | #elif defined(CPU_ARM) | ||
42 | //#define OPTIMIZE_FOR_SPEED | ||
43 | #else | ||
44 | #define OPTIMIZE_FOR_SPEED | ||
45 | #endif | ||
46 | #else | ||
47 | // do nothing | ||
48 | #endif | ||
49 | |||
50 | #endif | ||
diff --git a/apps/codecs/libmusepack/mpc_decoder.c b/apps/codecs/libmusepack/mpc_decoder.c index d211980782..5a78c943a6 100644 --- a/apps/codecs/libmusepack/mpc_decoder.c +++ b/apps/codecs/libmusepack/mpc_decoder.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2005, The Musepack Development Team | 2 | Copyright (c) 2005-2009, The Musepack Development Team |
3 | All rights reserved. | 3 | All rights reserved. |
4 | 4 | ||
5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
@@ -31,577 +31,217 @@ | |||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | 33 | */ |
34 | |||
35 | /// \file mpc_decoder.c | 34 | /// \file mpc_decoder.c |
36 | /// Core decoding routines and logic. | 35 | /// Core decoding routines and logic. |
37 | 36 | ||
38 | #include "musepack.h" | 37 | #include <string.h> |
38 | #include "mpcdec.h" | ||
39 | #include "minimax.h" | ||
40 | #include "decoder.h" | ||
41 | #include "huffman.h" | ||
39 | #include "internal.h" | 42 | #include "internal.h" |
43 | #include "mpcdec_math.h" | ||
40 | #include "requant.h" | 44 | #include "requant.h" |
41 | #include "huffman.h" | 45 | #include "mpc_bits_reader.h" |
42 | 46 | ||
43 | //SV7 tables | 47 | //SV7 tables |
44 | extern const HuffmanTyp* mpc_table_HuffQ [2] [8]; | 48 | extern const mpc_lut_data mpc_HuffQ [7] [2]; |
45 | extern const HuffmanTyp mpc_table_HuffHdr [10]; | 49 | extern const mpc_lut_data mpc_HuffHdr; |
46 | extern const HuffmanTyp mpc_table_HuffSCFI [ 4]; | 50 | extern const mpc_huffman mpc_table_HuffSCFI [ 4]; |
47 | extern const HuffmanTyp mpc_table_HuffDSCF [16]; | 51 | extern const mpc_lut_data mpc_HuffDSCF; |
48 | 52 | ||
49 | 53 | //SV8 tables | |
50 | #ifdef MPC_SUPPORT_SV456 | 54 | extern const mpc_can_data mpc_can_Bands; |
51 | //SV4/5/6 tables | 55 | extern const mpc_can_data mpc_can_SCFI[2]; |
52 | extern const HuffmanTyp* mpc_table_SampleHuff [18]; | 56 | extern const mpc_can_data mpc_can_DSCF[2]; |
53 | extern const HuffmanTyp mpc_table_SCFI_Bundle [ 8]; | 57 | extern const mpc_can_data mpc_can_Res [2]; |
54 | extern const HuffmanTyp mpc_table_DSCF_Entropie [13]; | 58 | extern const mpc_can_data mpc_can_Q [8][2]; |
55 | extern const HuffmanTyp mpc_table_Region_A [16]; | 59 | extern const mpc_can_data mpc_can_Q1; |
56 | extern const HuffmanTyp mpc_table_Region_B [ 8]; | 60 | extern const mpc_can_data mpc_can_Q9up; |
57 | extern const HuffmanTyp mpc_table_Region_C [ 4]; | 61 | |
58 | 62 | //Decoder globals (g_Y_L and g_Y_R do not fit into iram for all targets) | |
59 | #endif | 63 | static mpc_decoder g_mpc_decoder IBSS_ATTR; |
60 | 64 | static MPC_SAMPLE_FORMAT g_Y_L[MPC_FRAME_LENGTH] IBSS_ATTR_MPC_LARGE_IRAM; | |
61 | #ifndef MPC_LITTLE_ENDIAN | 65 | static MPC_SAMPLE_FORMAT g_Y_R[MPC_FRAME_LENGTH] IBSS_ATTR_MPC_LARGE_IRAM; |
62 | #define SWAP(X) mpc_swap32(X) | 66 | |
63 | #else | 67 | //SV7 globals (decoding results for bundled quantizers (3- and 5-step)) |
64 | #define SWAP(X) X | 68 | static const mpc_int32_t g_sv7_idx30[] ICONST_ATTR = |
65 | #endif | 69 | {-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}; |
66 | 70 | static const mpc_int32_t g_sv7_idx31[] ICONST_ATTR = | |
67 | #ifdef SCF_HACK | 71 | {-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}; |
68 | #define SCF_DIFF(SCF, D) (SCF == 127 ? 127 : SCF + D) | 72 | static const mpc_int32_t g_sv7_idx32[] ICONST_ATTR = |
69 | #else | 73 | {-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}; |
70 | #define SCF_DIFF(SCF, D) SCF + D | 74 | static const mpc_int32_t g_sv7_idx50[] ICONST_ATTR = |
71 | #endif | 75 | {-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}; |
72 | 76 | static const mpc_int32_t g_sv7_idx51[] ICONST_ATTR = | |
73 | #define LOOKUP(x, e, q) mpc_decoder_make_huffman_lookup ( (q), sizeof(q), (x), (e) ) | 77 | {-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}; |
74 | #define Decode_DSCF() HUFFMAN_DECODE_FASTEST ( d, mpc_table_HuffDSCF, LUTDSCF, 6 ) | 78 | |
75 | #define HUFFMAN_DECODE_FASTEST(d,a,b,c) mpc_decoder_huffman_decode_fastest ( (d), (a), (b), 32-(c) ) | 79 | //SV8 globals (decoding results for bundled quantizers (3- and 5-step)) |
76 | #define HUFFMAN_DECODE_FASTERER(d,a,b,c) mpc_decoder_huffman_decode_fasterer ( (d), (a), (b), 32-(c) ) | 80 | static const mpc_int8_t g_sv8_idx50[125] ICONST_ATTR = |
77 | 81 | {-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, | |
78 | mpc_uint8_t LUT1_0 [1<< 6] IBSS_ATTR_MPC_LARGE_IRAM; | 82 | -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 | mpc_uint8_t LUT1_1 [1<< 9] IBSS_ATTR_MPC_LARGE_IRAM; // 576 Bytes | 83 | -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, |
80 | mpc_uint8_t LUT2_0 [1<< 7] IBSS_ATTR_MPC_LARGE_IRAM; | 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, |
81 | mpc_uint8_t LUT2_1 [1<<10] IBSS_ATTR_MPC_LARGE_IRAM; // 1152 Bytes | 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}; |
82 | mpc_uint8_t LUT3_0 [1<< 4] IBSS_ATTR_MPC_LARGE_IRAM; | 86 | static const mpc_int8_t g_sv8_idx51[125] ICONST_ATTR = |
83 | mpc_uint8_t LUT3_1 [1<< 5] IBSS_ATTR_MPC_LARGE_IRAM; // 48 Bytes | 87 | {-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, |
84 | mpc_uint8_t LUT4_0 [1<< 4] IBSS_ATTR_MPC_LARGE_IRAM; | 88 | -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, |
85 | mpc_uint8_t LUT4_1 [1<< 5] IBSS_ATTR_MPC_LARGE_IRAM; // 48 Bytes | 89 | -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, |
86 | mpc_uint8_t LUT5_0 [1<< 6] IBSS_ATTR_MPC_LARGE_IRAM; | 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, |
87 | mpc_uint8_t LUT5_1 [1<< 8] IBSS_ATTR_MPC_LARGE_IRAM; // 320 Bytes | 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}; |
88 | mpc_uint8_t LUT6_0 [1<< 7] IBSS_ATTR_MPC_LARGE_IRAM; | 92 | static const mpc_int8_t g_sv8_idx52[125] ICONST_ATTR = |
89 | mpc_uint8_t LUT6_1 [1<< 7] IBSS_ATTR_MPC_LARGE_IRAM; // 256 Bytes | 93 | {-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, |
90 | mpc_uint8_t LUT7_0 [1<< 8] IBSS_ATTR_MPC_LARGE_IRAM; | 94 | -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, |
91 | mpc_uint8_t LUT7_1 [1<< 8] IBSS_ATTR_MPC_LARGE_IRAM; // 512 Bytes | 95 | 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, |
92 | mpc_uint8_t LUTDSCF [1<< 6] IBSS_ATTR_MPC_LARGE_IRAM; // 64 Bytes = 2976 Bytes | 96 | 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, |
97 | 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}; | ||
98 | static const mpc_int8_t g_sv8_HuffQ2_var[125] ICONST_ATTR = | ||
99 | { 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, | ||
100 | 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, | ||
101 | 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, | ||
102 | 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, | ||
103 | 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}; | ||
93 | 104 | ||
94 | //------------------------------------------------------------------------------ | 105 | //------------------------------------------------------------------------------ |
95 | // types | 106 | // types |
96 | //------------------------------------------------------------------------------ | 107 | //------------------------------------------------------------------------------ |
97 | enum | 108 | enum |
98 | { | ||
99 | SEEK_PRE_DECODE = 33, // number of frames to be pre-decoded | ||
100 | MEMSIZE = MPC_DECODER_MEMSIZE, // overall buffer size | ||
101 | MEMSIZE2 = (MEMSIZE/2), // size of one buffer | ||
102 | MEMMASK = (MEMSIZE-1) | ||
103 | }; | ||
104 | |||
105 | //------------------------------------------------------------------------------ | ||
106 | // forward declarations | ||
107 | //------------------------------------------------------------------------------ | ||
108 | void mpc_decoder_read_bitstream_sv6(mpc_decoder *d); | ||
109 | void mpc_decoder_read_bitstream_sv7(mpc_decoder *d, mpc_bool_t fastSeeking); | ||
110 | void mpc_decoder_update_buffer(mpc_decoder *d); | ||
111 | mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample); | ||
112 | void mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band); | ||
113 | void mpc_decoder_seek_to(mpc_decoder *d, mpc_uint32_t bitPos); | ||
114 | void mpc_decoder_seek_forward(mpc_decoder *d, mpc_uint32_t bits); | ||
115 | mpc_uint32_t mpc_decoder_jump_frame(mpc_decoder *d); | ||
116 | void mpc_decoder_fill_buffer(mpc_decoder *d); | ||
117 | void mpc_decoder_reset_state(mpc_decoder *d); | ||
118 | static mpc_uint32_t get_initial_fpos(mpc_decoder *d, mpc_uint32_t StreamVersion); | ||
119 | static inline mpc_int32_t mpc_decoder_huffman_decode_fastest(mpc_decoder *d, const HuffmanTyp* Table, const mpc_uint8_t* tab, mpc_uint16_t unused_bits); | ||
120 | static void mpc_move_next(mpc_decoder *d); | ||
121 | |||
122 | mpc_uint32_t Seekbuffer[MPC_SEEK_BUFFER_SIZE]; | ||
123 | mpc_uint32_t Speicher[MPC_DECODER_MEMSIZE]; | ||
124 | MPC_SAMPLE_FORMAT Y_L[36][32] IBSS_ATTR_MPC_LARGE_IRAM; | ||
125 | MPC_SAMPLE_FORMAT Y_R[36][32] IBSS_ATTR_MPC_LARGE_IRAM; | ||
126 | |||
127 | //------------------------------------------------------------------------------ | ||
128 | // utility functions | ||
129 | //------------------------------------------------------------------------------ | ||
130 | static mpc_int32_t f_read(mpc_decoder *d, void *ptr, size_t size) | ||
131 | { | ||
132 | return d->r->read(d->r->data, ptr, size); | ||
133 | }; | ||
134 | |||
135 | static mpc_bool_t f_seek(mpc_decoder *d, mpc_int32_t offset) | ||
136 | { | ||
137 | return d->r->seek(d->r->data, offset); | ||
138 | }; | ||
139 | |||
140 | static mpc_int32_t f_read_dword(mpc_decoder *d, mpc_uint32_t * ptr, mpc_uint32_t count) | ||
141 | { | 109 | { |
142 | count = f_read(d, ptr, count << 2) >> 2; | 110 | MEMSIZE = MPC_DECODER_MEMSIZE, // overall buffer size |
143 | return count; | 111 | MEMSIZE2 = (MEMSIZE/2), // size of one buffer |
144 | } | 112 | MEMMASK = (MEMSIZE-1) |
113 | }; | ||
145 | 114 | ||
146 | //------------------------------------------------------------------------------ | 115 | //------------------------------------------------------------------------------ |
147 | // huffman & bitstream functions | 116 | // forward declarations |
148 | //------------------------------------------------------------------------------ | 117 | //------------------------------------------------------------------------------ |
149 | static const mpc_uint32_t mask [33] ICONST_ATTR = { | 118 | void mpc_decoder_read_bitstream_sv7(mpc_decoder * d, mpc_bits_reader * r); |
150 | 0x00000000, 0x00000001, 0x00000003, 0x00000007, | 119 | void mpc_decoder_read_bitstream_sv8(mpc_decoder * d, mpc_bits_reader * r, |
151 | 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F, | 120 | mpc_bool_t is_key_frame); |
152 | 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF, | 121 | static void mpc_decoder_requantisierung(mpc_decoder *d); |
153 | 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF, | 122 | |
154 | 0x0000FFFF, 0x0001FFFF, 0x0003FFFF, 0x0007FFFF, | 123 | /** |
155 | 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF, | 124 | * set the scf indexes for seeking use |
156 | 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, | 125 | * needed only for sv7 seeking |
157 | 0x0FFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, | 126 | * @param d |
158 | 0xFFFFFFFF | 127 | */ |
159 | }; | 128 | void mpc_decoder_reset_scf(mpc_decoder * d, int value) |
160 | |||
161 | /* F U N C T I O N S */ | ||
162 | |||
163 | // resets bitstream decoding | ||
164 | static void | ||
165 | mpc_decoder_reset_bitstream_decode(mpc_decoder *d) | ||
166 | { | ||
167 | d->dword = 0; | ||
168 | d->next = 0; | ||
169 | d->pos = 0; | ||
170 | d->Zaehler = 0; | ||
171 | d->WordsRead = 0; | ||
172 | } | ||
173 | |||
174 | // reports the number of read bits | ||
175 | static mpc_uint32_t | ||
176 | mpc_decoder_bits_read(mpc_decoder *d) | ||
177 | { | ||
178 | return 32 * d->WordsRead + d->pos; | ||
179 | } | ||
180 | |||
181 | static void mpc_move_next(mpc_decoder *d) { | ||
182 | d->Zaehler = (d->Zaehler + 1) & MEMMASK; | ||
183 | d->dword = d->next; | ||
184 | d->next = SWAP(d->Speicher[(d->Zaehler + 1) & MEMMASK]); | ||
185 | d->pos -= 32; | ||
186 | ++(d->WordsRead); | ||
187 | } | ||
188 | |||
189 | // read desired number of bits out of the bitstream | ||
190 | static inline mpc_uint32_t | ||
191 | mpc_decoder_bitstream_read(mpc_decoder *d, const mpc_uint32_t bits) | ||
192 | { | ||
193 | mpc_uint32_t out = d->dword; | ||
194 | |||
195 | d->pos += bits; | ||
196 | |||
197 | if (d->pos < 32) { | ||
198 | out >>= (32 - d->pos); | ||
199 | } | ||
200 | else { | ||
201 | mpc_move_next(d); | ||
202 | if (d->pos) { | ||
203 | out <<= d->pos; | ||
204 | out |= d->dword >> (32 - d->pos); | ||
205 | } | ||
206 | } | ||
207 | |||
208 | return out & mask[bits]; | ||
209 | } | ||
210 | |||
211 | static void | ||
212 | mpc_decoder_make_huffman_lookup( | ||
213 | mpc_uint8_t* lookup, size_t length, const HuffmanTyp* Table, size_t elements ) | ||
214 | { | ||
215 | size_t i; | ||
216 | size_t idx = elements; | ||
217 | mpc_uint32_t dval = (mpc_uint32_t)0x80000000L / length * 2; | ||
218 | mpc_uint32_t val = dval - 1; | ||
219 | |||
220 | for ( i = 0; i < length; i++, val += dval ) { | ||
221 | while ( idx > 0 && val >= Table[idx-1].Code ) | ||
222 | idx--; | ||
223 | *lookup++ = (mpc_uint8_t)idx; | ||
224 | } | ||
225 | |||
226 | return; | ||
227 | } | ||
228 | |||
229 | #ifdef MPC_SUPPORT_SV456 | ||
230 | // decode SCFI-bundle (sv4,5,6) | ||
231 | static void | ||
232 | mpc_decoder_scfi_bundle_read( | ||
233 | mpc_decoder *d, | ||
234 | const HuffmanTyp* Table, mpc_int8_t* SCFI, mpc_bool_t* DSCF) | ||
235 | { | ||
236 | // load preview and decode | ||
237 | mpc_uint32_t code = d->dword << d->pos; | ||
238 | |||
239 | if (d->pos > 26) { | ||
240 | code |= d->next >> (32 - d->pos); | ||
241 | } | ||
242 | while (code < Table->Code) { | ||
243 | Table++; | ||
244 | } | ||
245 | |||
246 | // set the new position within bitstream without performing a dummy-read | ||
247 | if ((d->pos += Table->Length) >= 32) { | ||
248 | mpc_move_next(d); | ||
249 | } | ||
250 | |||
251 | *SCFI = Table->Value >> 1; | ||
252 | *DSCF = Table->Value & 1; | ||
253 | } | ||
254 | |||
255 | // basic huffman decoding routine | ||
256 | // works with maximum lengths up to 14 | ||
257 | static mpc_int32_t | ||
258 | mpc_decoder_huffman_decode(mpc_decoder *d, const HuffmanTyp *Table) | ||
259 | { | 129 | { |
260 | // load preview and decode | 130 | memset(d->SCF_Index_L, value, sizeof d->SCF_Index_L ); |
261 | mpc_uint32_t code = d->dword << d->pos; | 131 | memset(d->SCF_Index_R, value, sizeof d->SCF_Index_R ); |
262 | |||
263 | if (d->pos > 18) { | ||
264 | code |= d->next >> (32 - d->pos); | ||
265 | } | ||
266 | while (code < Table->Code) { | ||
267 | Table++; | ||
268 | } | ||
269 | |||
270 | // set the new position within bitstream without performing a dummy-read | ||
271 | if ((d->pos += Table->Length) >= 32) { | ||
272 | mpc_move_next(d); | ||
273 | } | ||
274 | |||
275 | return Table->Value; | ||
276 | } | 132 | } |
277 | #endif | ||
278 | 133 | ||
279 | // faster huffman through previewing less bits | 134 | void mpc_decoder_setup(mpc_decoder *d) |
280 | // works with maximum lengths up to 10 | ||
281 | static mpc_int32_t | ||
282 | mpc_decoder_huffman_decode_fast(mpc_decoder *d, const HuffmanTyp* Table) | ||
283 | { | 135 | { |
284 | // load preview and decode | 136 | memset(d, 0, sizeof *d); |
285 | mpc_uint32_t code = d->dword << d->pos; | ||
286 | |||
287 | if (d->pos > 22) { | ||
288 | code |= d->next >> (32 - d->pos); | ||
289 | } | ||
290 | while (code < Table->Code) { | ||
291 | Table++; | ||
292 | } | ||
293 | |||
294 | // set the new position within bitstream without performing a dummy-read | ||
295 | if ((d->pos += Table->Length) >= 32) { | ||
296 | mpc_move_next(d); | ||
297 | } | ||
298 | |||
299 | return Table->Value; | ||
300 | } | ||
301 | 137 | ||
302 | // even faster huffman through previewing even less bits | 138 | d->__r1 = 1; |
303 | // works with maximum lengths up to 5 | 139 | d->__r2 = 1; |
304 | static mpc_int32_t | 140 | d->Y_L = g_Y_L; |
305 | mpc_decoder_huffman_decode_faster(mpc_decoder *d, const HuffmanTyp* Table) | 141 | d->Y_R = g_Y_R; |
306 | { | ||
307 | // load preview and decode | ||
308 | mpc_uint32_t code = d->dword << d->pos; | ||
309 | 142 | ||
310 | if (d->pos > 27) { | 143 | memset(d->Y_L, 0, sizeof(g_Y_L)); |
311 | code |= d->next >> (32 - d->pos); | 144 | memset(d->Y_R, 0, sizeof(g_Y_R)); |
312 | } | ||
313 | while (code < Table->Code) { | ||
314 | Table++; | ||
315 | } | ||
316 | 145 | ||
317 | // set the new position within bitstream without performing a dummy-read | 146 | mpc_decoder_init_quant(d, 1.0f); |
318 | if ((d->pos += Table->Length) >= 32) { | ||
319 | mpc_move_next(d); | ||
320 | } | ||
321 | |||
322 | return Table->Value; | ||
323 | } | 147 | } |
324 | 148 | ||
325 | /* partial lookup table decode */ | 149 | void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si) |
326 | static mpc_int32_t | ||
327 | mpc_decoder_huffman_decode_fasterer(mpc_decoder *d, const HuffmanTyp* Table, const mpc_uint8_t* tab, mpc_uint16_t unused_bits) | ||
328 | { | 150 | { |
329 | // load preview and decode | 151 | d->stream_version = si->stream_version; |
330 | mpc_uint32_t code = d->dword << d->pos; | 152 | d->ms = si->ms; |
331 | 153 | d->max_band = si->max_band; | |
332 | if (d->pos > 18) { // preview 14 bits | 154 | d->channels = si->channels; |
333 | code |= d->next >> (32 - d->pos); | 155 | d->samples_to_skip = MPC_DECODER_SYNTH_DELAY + si->beg_silence; |
334 | } | ||
335 | |||
336 | Table += tab [(size_t)(code >> unused_bits) ]; | ||
337 | |||
338 | while (code < Table->Code) { | ||
339 | Table++; | ||
340 | } | ||
341 | |||
342 | // set the new position within bitstream without performing a dummy-read | ||
343 | if ((d->pos += Table->Length) >= 32) { | ||
344 | mpc_move_next(d); | ||
345 | } | ||
346 | 156 | ||
347 | return Table->Value; | 157 | if (si->stream_version == 7 && si->is_true_gapless) |
158 | d->samples = ((si->samples + MPC_FRAME_LENGTH - 1) / MPC_FRAME_LENGTH) * MPC_FRAME_LENGTH; | ||
159 | else | ||
160 | d->samples = si->samples; | ||
348 | } | 161 | } |
349 | 162 | ||
350 | /* full decode using lookup table */ | 163 | mpc_decoder * mpc_decoder_init(mpc_streaminfo *si) |
351 | static inline mpc_int32_t | ||
352 | mpc_decoder_huffman_decode_fastest(mpc_decoder *d, const HuffmanTyp* Table, const mpc_uint8_t* tab, mpc_uint16_t unused_bits) | ||
353 | { | 164 | { |
354 | // load preview and decode | 165 | mpc_decoder* p_tmp = &g_mpc_decoder; |
355 | mpc_uint32_t code = d->dword << d->pos; | ||
356 | 166 | ||
357 | if (d->pos > unused_bits) { | 167 | if (p_tmp != 0) { |
358 | code |= d->next >> (32 - d->pos); | 168 | mpc_decoder_setup(p_tmp); |
169 | mpc_decoder_set_streaminfo(p_tmp, si); | ||
170 | huff_init_lut(LUT_DEPTH); | ||
359 | } | 171 | } |
360 | 172 | ||
361 | Table+=tab [(size_t)(code >> unused_bits) ]; | 173 | return p_tmp; |
362 | |||
363 | // set the new position within bitstream without performing a dummy-read | ||
364 | if ((d->pos += Table->Length) >= 32) { | ||
365 | mpc_move_next(d); | ||
366 | } | ||
367 | |||
368 | return Table->Value; | ||
369 | } | ||
370 | |||
371 | static void | ||
372 | mpc_decoder_reset_v(mpc_decoder *d) | ||
373 | { | ||
374 | memset(d->V_L, 0, sizeof d->V_L); | ||
375 | memset(d->V_R, 0, sizeof d->V_R); | ||
376 | } | ||
377 | |||
378 | static void | ||
379 | mpc_decoder_reset_synthesis(mpc_decoder *d) | ||
380 | { | ||
381 | mpc_decoder_reset_v(d); | ||
382 | } | ||
383 | |||
384 | static void | ||
385 | mpc_decoder_reset_y(mpc_decoder *d) | ||
386 | { | ||
387 | memset(d->Y_L, 0, sizeof Y_L); | ||
388 | memset(d->Y_R, 0, sizeof Y_R); | ||
389 | } | ||
390 | |||
391 | static void | ||
392 | mpc_decoder_reset_globals(mpc_decoder *d) | ||
393 | { | ||
394 | mpc_decoder_reset_bitstream_decode(d); | ||
395 | |||
396 | d->DecodedFrames = 0; | ||
397 | d->MaxDecodedFrames = 0; | ||
398 | d->StreamVersion = 0; | ||
399 | d->MS_used = 0; | ||
400 | |||
401 | memset(d->Y_L , 0, sizeof Y_L ); | ||
402 | memset(d->Y_R , 0, sizeof Y_R ); | ||
403 | memset(d->SCF_Index_L , 0, sizeof d->SCF_Index_L); | ||
404 | memset(d->SCF_Index_R , 0, sizeof d->SCF_Index_R); | ||
405 | memset(d->Res_L , 0, sizeof d->Res_L ); | ||
406 | memset(d->Res_R , 0, sizeof d->Res_R ); | ||
407 | memset(d->SCFI_L , 0, sizeof d->SCFI_L ); | ||
408 | memset(d->SCFI_R , 0, sizeof d->SCFI_R ); | ||
409 | #ifdef MPC_SUPPORT_SV456 | ||
410 | memset(d->DSCF_Flag_L , 0, sizeof d->DSCF_Flag_L); | ||
411 | memset(d->DSCF_Flag_R , 0, sizeof d->DSCF_Flag_R); | ||
412 | #endif | ||
413 | memset(d->Q , 0, sizeof d->Q ); | ||
414 | memset(d->MS_Flag , 0, sizeof d->MS_Flag ); | ||
415 | } | 174 | } |
416 | 175 | ||
417 | mpc_uint32_t | 176 | void mpc_decoder_exit(mpc_decoder *d) |
418 | mpc_decoder_decode_frame(mpc_decoder *d, mpc_uint32_t *in_buffer, | ||
419 | mpc_uint32_t in_len, MPC_SAMPLE_FORMAT *out_buffer) | ||
420 | { | 177 | { |
421 | mpc_decoder_reset_bitstream_decode(d); | 178 | (void)d; |
422 | if (in_len > sizeof(Speicher)) in_len = sizeof(Speicher); | ||
423 | memcpy(d->Speicher, in_buffer, in_len); | ||
424 | d->dword = SWAP(d->Speicher[0]); | ||
425 | d->next = SWAP(d->Speicher[1]); | ||
426 | switch (d->StreamVersion) { | ||
427 | #ifdef MPC_SUPPORT_SV456 | ||
428 | case 0x04: | ||
429 | case 0x05: | ||
430 | case 0x06: | ||
431 | mpc_decoder_read_bitstream_sv6(d); | ||
432 | break; | ||
433 | #endif | ||
434 | case 0x07: | ||
435 | case 0x17: | ||
436 | mpc_decoder_read_bitstream_sv7(d, FALSE); | ||
437 | break; | ||
438 | default: | ||
439 | return (mpc_uint32_t)(-1); | ||
440 | } | ||
441 | mpc_decoder_requantisierung(d, d->Max_Band); | ||
442 | mpc_decoder_synthese_filter_float(d, out_buffer); | ||
443 | return mpc_decoder_bits_read(d); | ||
444 | } | 179 | } |
445 | 180 | ||
446 | static mpc_uint32_t | 181 | void mpc_decoder_decode_frame(mpc_decoder * d, |
447 | mpc_decoder_decode_internal(mpc_decoder *d, MPC_SAMPLE_FORMAT *buffer) | 182 | mpc_bits_reader * r, |
183 | mpc_frame_info * i) | ||
448 | { | 184 | { |
449 | mpc_uint32_t output_frame_length = MPC_FRAME_LENGTH; | 185 | mpc_bits_reader r_sav = *r; |
450 | 186 | mpc_int64_t samples_left; | |
451 | mpc_uint32_t FrameBitCnt = 0; | ||
452 | 187 | ||
453 | // output the last part of the last frame here, if needed | 188 | samples_left = d->samples - d->decoded_samples + MPC_DECODER_SYNTH_DELAY; |
454 | if (d->last_block_samples > 0) { | ||
455 | output_frame_length = d->last_block_samples; | ||
456 | d->last_block_samples = 0; // it's going to be handled now, so reset it | ||
457 | if (!d->TrueGaplessPresent) { | ||
458 | mpc_decoder_reset_y(d); | ||
459 | } else { | ||
460 | mpc_decoder_bitstream_read(d, 20); | ||
461 | mpc_decoder_read_bitstream_sv7(d, FALSE); | ||
462 | mpc_decoder_requantisierung(d, d->Max_Band); | ||
463 | } | ||
464 | mpc_decoder_synthese_filter_float(d, buffer); | ||
465 | return output_frame_length; | ||
466 | } | ||
467 | |||
468 | if (d->DecodedFrames >= d->OverallFrames) { | ||
469 | return (mpc_uint32_t)(-1); // end of file -> abort decoding | ||
470 | } | ||
471 | 189 | ||
472 | if (d->DecodedFrames == 0) | 190 | if (samples_left <= 0 && d->samples != 0) { |
473 | { | 191 | i->samples = 0; |
474 | d->SeekTable[0] = mpc_decoder_bits_read(d); | 192 | i->bits = -1; |
475 | d->SeekTableCounter = 0; | 193 | return; |
476 | } | 194 | } |
477 | 195 | ||
478 | // read jump-info for validity check of frame | 196 | if (d->stream_version == 8) { |
479 | d->FwdJumpInfo = mpc_decoder_bitstream_read(d, 20); | 197 | mpc_decoder_read_bitstream_sv8(d, r, i->is_key_frame); |
480 | 198 | } else { | |
481 | d->ActDecodePos = (d->Zaehler << 5) + d->pos; | 199 | mpc_decoder_read_bitstream_sv7(d, r); |
482 | |||
483 | // decode data and check for validity of frame | ||
484 | FrameBitCnt = mpc_decoder_bits_read(d); | ||
485 | switch (d->StreamVersion) { | ||
486 | #ifdef MPC_SUPPORT_SV456 | ||
487 | case 0x04: | ||
488 | case 0x05: | ||
489 | case 0x06: | ||
490 | mpc_decoder_read_bitstream_sv6(d); | ||
491 | break; | ||
492 | #endif | ||
493 | case 0x07: | ||
494 | case 0x17: | ||
495 | mpc_decoder_read_bitstream_sv7(d, FALSE); | ||
496 | break; | ||
497 | default: | ||
498 | return (mpc_uint32_t)(-1); | ||
499 | } | 200 | } |
500 | d->FrameWasValid = mpc_decoder_bits_read(d) - FrameBitCnt == d->FwdJumpInfo; | ||
501 | 201 | ||
502 | d->DecodedFrames++; | 202 | if (d->samples_to_skip < MPC_FRAME_LENGTH + MPC_DECODER_SYNTH_DELAY) { |
503 | 203 | mpc_decoder_requantisierung(d); | |
504 | /* update seek table */ | 204 | mpc_decoder_synthese_filter_float(d, i->buffer, d->channels); |
505 | d->SeekTableCounter += d->FwdJumpInfo + 20; | ||
506 | if (0 == ((d->DecodedFrames) & (d->SeekTable_Mask))) | ||
507 | { | ||
508 | d->SeekTable[d->DecodedFrames>>d->SeekTable_Step] = d->SeekTableCounter; | ||
509 | d->MaxDecodedFrames = d->DecodedFrames; | ||
510 | d->SeekTableCounter = 0; | ||
511 | } | 205 | } |
512 | 206 | ||
513 | // synthesize signal | 207 | d->decoded_samples += MPC_FRAME_LENGTH; |
514 | mpc_decoder_requantisierung(d, d->Max_Band); | ||
515 | |||
516 | mpc_decoder_synthese_filter_float(d, buffer); | ||
517 | |||
518 | // cut off first MPC_DECODER_SYNTH_DELAY zero-samples | ||
519 | if (d->DecodedFrames == d->OverallFrames && d->StreamVersion >= 6) { | ||
520 | // reconstruct exact filelength | ||
521 | mpc_int32_t mod_block = mpc_decoder_bitstream_read(d, 11); | ||
522 | mpc_int32_t FilterDecay; | ||
523 | 208 | ||
524 | if (mod_block == 0) { | 209 | // reconstruct exact filelength |
525 | // Encoder bugfix | 210 | if (d->decoded_samples - d->samples < MPC_FRAME_LENGTH && d->stream_version == 7) { |
526 | mod_block = 1152; | 211 | int last_frame_samples = mpc_bits_read(r, 11); |
527 | } | 212 | if (d->decoded_samples == d->samples) { |
528 | FilterDecay = (mod_block + MPC_DECODER_SYNTH_DELAY) % MPC_FRAME_LENGTH; | 213 | if (last_frame_samples == 0) last_frame_samples = MPC_FRAME_LENGTH; |
529 | 214 | d->samples += last_frame_samples - MPC_FRAME_LENGTH; | |
530 | // additional FilterDecay samples are needed for decay of synthesis filter | 215 | samples_left += last_frame_samples - MPC_FRAME_LENGTH; |
531 | if (MPC_DECODER_SYNTH_DELAY + mod_block >= MPC_FRAME_LENGTH) { | ||
532 | // this variable will be checked for at the top of the function | ||
533 | d->last_block_samples = FilterDecay; | ||
534 | } | ||
535 | else { // there are only FilterDecay samples needed for this frame | ||
536 | output_frame_length = FilterDecay; | ||
537 | } | 216 | } |
538 | } | 217 | } |
539 | 218 | ||
219 | i->samples = samples_left > MPC_FRAME_LENGTH ? MPC_FRAME_LENGTH : samples_left < 0 ? 0 : (mpc_uint32_t) samples_left; | ||
220 | i->bits = (mpc_uint32_t) (((r->buff - r_sav.buff) << 3) + r_sav.count - r->count); | ||
221 | |||
540 | if (d->samples_to_skip) { | 222 | if (d->samples_to_skip) { |
541 | if (output_frame_length < d->samples_to_skip) { | 223 | if (i->samples <= d->samples_to_skip) { |
542 | d->samples_to_skip -= output_frame_length; | 224 | d->samples_to_skip -= i->samples; |
543 | output_frame_length = 0; | 225 | i->samples = 0; |
544 | } | 226 | } else { |
545 | else { | 227 | i->samples -= d->samples_to_skip; |
546 | output_frame_length -= d->samples_to_skip; | 228 | |
547 | memmove( | 229 | /* move valid samples to beginning for channel 0. noninterleaved! */ |
548 | buffer, | 230 | memmove(i->buffer, |
549 | buffer + d->samples_to_skip, | 231 | i->buffer + d->samples_to_skip, |
550 | output_frame_length * sizeof (MPC_SAMPLE_FORMAT)); | 232 | i->samples * sizeof(MPC_SAMPLE_FORMAT)); |
551 | memmove( | 233 | /* move valid samples to beginning for channel 1. noninterleaved! */ |
552 | buffer + MPC_FRAME_LENGTH, | 234 | memmove(i->buffer + MPC_FRAME_LENGTH, |
553 | buffer + MPC_FRAME_LENGTH + d->samples_to_skip, | 235 | i->buffer + MPC_FRAME_LENGTH + d->samples_to_skip, |
554 | output_frame_length * sizeof (MPC_SAMPLE_FORMAT)); | 236 | i->samples * sizeof(MPC_SAMPLE_FORMAT)); |
237 | |||
555 | d->samples_to_skip = 0; | 238 | d->samples_to_skip = 0; |
556 | } | 239 | } |
557 | } | 240 | } |
558 | |||
559 | return output_frame_length; | ||
560 | } | ||
561 | |||
562 | mpc_uint32_t mpc_decoder_decode( | ||
563 | mpc_decoder *d, | ||
564 | MPC_SAMPLE_FORMAT *buffer, | ||
565 | mpc_uint32_t *vbr_update_acc, | ||
566 | mpc_uint32_t *vbr_update_bits) | ||
567 | { | ||
568 | for(;;) | ||
569 | { | ||
570 | mpc_uint32_t RING = d->Zaehler; | ||
571 | mpc_int32_t vbr_ring = (RING << 5) + d->pos; | ||
572 | |||
573 | mpc_uint32_t valid_samples = mpc_decoder_decode_internal(d, buffer); | ||
574 | |||
575 | if (valid_samples == (mpc_uint32_t)(-1) ) { | ||
576 | return 0; | ||
577 | } | ||
578 | |||
579 | /**************** ERROR CONCEALMENT *****************/ | ||
580 | if (d->FrameWasValid == 0 ) { | ||
581 | // error occurred in bitstream | ||
582 | return (mpc_uint32_t)(-1); | ||
583 | } | ||
584 | else { | ||
585 | if (vbr_update_acc && vbr_update_bits) { | ||
586 | (*vbr_update_acc) ++; | ||
587 | vbr_ring = (d->Zaehler << 5) + d->pos - vbr_ring; | ||
588 | if (vbr_ring < 0) { | ||
589 | vbr_ring += 524288; | ||
590 | } | ||
591 | (*vbr_update_bits) += vbr_ring; | ||
592 | } | ||
593 | |||
594 | } | ||
595 | mpc_decoder_update_buffer(d); | ||
596 | |||
597 | if (valid_samples > 0) { | ||
598 | return valid_samples; | ||
599 | } | ||
600 | } | ||
601 | } | 241 | } |
602 | 242 | ||
603 | void | 243 | void |
604 | mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) | 244 | mpc_decoder_requantisierung(mpc_decoder *d) |
605 | { | 245 | { |
606 | mpc_int32_t Band; | 246 | mpc_int32_t Band; |
607 | mpc_int32_t n; | 247 | mpc_int32_t n; |
@@ -613,6 +253,7 @@ mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) | |||
613 | MPC_SAMPLE_FORMAT* YR; | 253 | MPC_SAMPLE_FORMAT* YR; |
614 | mpc_int16_t* L; | 254 | mpc_int16_t* L; |
615 | mpc_int16_t* R; | 255 | mpc_int16_t* R; |
256 | const mpc_int32_t Last_Band = d->max_band; | ||
616 | 257 | ||
617 | #ifdef MPC_FIXED_POINT | 258 | #ifdef MPC_FIXED_POINT |
618 | #if MPC_FIXED_POINT_FRACTPART == 14 | 259 | #if MPC_FIXED_POINT_FRACTPART == 14 |
@@ -629,42 +270,42 @@ mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) | |||
629 | #endif | 270 | #endif |
630 | // requantization and scaling of subband-samples | 271 | // requantization and scaling of subband-samples |
631 | for ( Band = 0; Band <= Last_Band; Band++ ) { // setting pointers | 272 | for ( Band = 0; Band <= Last_Band; Band++ ) { // setting pointers |
632 | YL = d->Y_L[0] + Band; | 273 | YL = d->Y_L + Band; |
633 | YR = d->Y_R[0] + Band; | 274 | YR = d->Y_R + Band; |
634 | L = d->Q[Band].L; | 275 | L = d->Q[Band].L; |
635 | R = d->Q[Band].R; | 276 | R = d->Q[Band].R; |
636 | /************************** MS-coded **************************/ | 277 | /************************** MS-coded **************************/ |
637 | if ( d->MS_Flag [Band] ) { | 278 | if ( d->MS_Flag [Band] ) { |
638 | if ( d->Res_L [Band] ) { | 279 | if ( d->Res_L [Band] ) { |
639 | if ( d->Res_R [Band] ) { // M!=0, S!=0 | 280 | if ( d->Res_R [Band] ) { // M!=0, S!=0 |
640 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]); | 281 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][0] & 0xFF); |
641 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]); | 282 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][0] & 0xFF); |
642 | for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { | 283 | for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { |
643 | *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++)); | 284 | *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++)); |
644 | *YR = templ - tempr; | 285 | *YR = templ - tempr; |
645 | } | 286 | } |
646 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]); | 287 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][1] & 0xFF); |
647 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]); | 288 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][1] & 0xFF); |
648 | for ( ; n < 24; n++, YL += 32, YR += 32 ) { | 289 | for ( ; n < 24; n++, YL += 32, YR += 32 ) { |
649 | *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++)); | 290 | *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++)); |
650 | *YR = templ - tempr; | 291 | *YR = templ - tempr; |
651 | } | 292 | } |
652 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]); | 293 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][2] & 0xFF); |
653 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]); | 294 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][2] & 0xFF); |
654 | for ( ; n < 36; n++, YL += 32, YR += 32 ) { | 295 | for ( ; n < 36; n++, YL += 32, YR += 32 ) { |
655 | *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++)); | 296 | *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++)); |
656 | *YR = templ - tempr; | 297 | *YR = templ - tempr; |
657 | } | 298 | } |
658 | } else { // M!=0, S==0 | 299 | } else { // M!=0, S==0 |
659 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]); | 300 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][0] & 0xFF); |
660 | for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { | 301 | for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { |
661 | *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); | 302 | *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); |
662 | } | 303 | } |
663 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]); | 304 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][1] & 0xFF); |
664 | for ( ; n < 24; n++, YL += 32, YR += 32 ) { | 305 | for ( ; n < 24; n++, YL += 32, YR += 32 ) { |
665 | *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); | 306 | *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); |
666 | } | 307 | } |
667 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]); | 308 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][2] & 0xFF); |
668 | for ( ; n < 36; n++, YL += 32, YR += 32 ) { | 309 | for ( ; n < 36; n++, YL += 32, YR += 32 ) { |
669 | *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); | 310 | *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); |
670 | } | 311 | } |
@@ -672,15 +313,15 @@ mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) | |||
672 | } else { | 313 | } else { |
673 | if (d->Res_R[Band]) // M==0, S!=0 | 314 | if (d->Res_R[Band]) // M==0, S!=0 |
674 | { | 315 | { |
675 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]); | 316 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][0] & 0xFF); |
676 | for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { | 317 | for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { |
677 | *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++))); | 318 | *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++))); |
678 | } | 319 | } |
679 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]); | 320 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][1] & 0xFF); |
680 | for ( ; n < 24; n++, YL += 32, YR += 32 ) { | 321 | for ( ; n < 24; n++, YL += 32, YR += 32 ) { |
681 | *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++))); | 322 | *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++))); |
682 | } | 323 | } |
683 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]); | 324 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][2] & 0xFF); |
684 | for ( ; n < 36; n++, YL += 32, YR += 32 ) { | 325 | for ( ; n < 36; n++, YL += 32, YR += 32 ) { |
685 | *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++))); | 326 | *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++))); |
686 | } | 327 | } |
@@ -695,36 +336,36 @@ mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) | |||
695 | else { | 336 | else { |
696 | if ( d->Res_L [Band] ) { | 337 | if ( d->Res_L [Band] ) { |
697 | if ( d->Res_R [Band] ) { // L!=0, R!=0 | 338 | if ( d->Res_R [Band] ) { // L!=0, R!=0 |
698 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]); | 339 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][0] & 0xFF); |
699 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]); | 340 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][0] & 0xFF); |
700 | for (n = 0; n < 12; n++, YL += 32, YR += 32 ) { | 341 | for (n = 0; n < 12; n++, YL += 32, YR += 32 ) { |
701 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); | 342 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); |
702 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); | 343 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); |
703 | } | 344 | } |
704 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]); | 345 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][1] & 0xFF); |
705 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]); | 346 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][1] & 0xFF); |
706 | for (; n < 24; n++, YL += 32, YR += 32 ) { | 347 | for (; n < 24; n++, YL += 32, YR += 32 ) { |
707 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); | 348 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); |
708 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); | 349 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); |
709 | } | 350 | } |
710 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]); | 351 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][2] & 0xFF); |
711 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]); | 352 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][2] & 0xFF); |
712 | for (; n < 36; n++, YL += 32, YR += 32 ) { | 353 | for (; n < 36; n++, YL += 32, YR += 32 ) { |
713 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); | 354 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); |
714 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); | 355 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); |
715 | } | 356 | } |
716 | } else { // L!=0, R==0 | 357 | } else { // L!=0, R==0 |
717 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][0]); | 358 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][0] & 0xFF); |
718 | for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { | 359 | for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { |
719 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); | 360 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); |
720 | *YR = 0; | 361 | *YR = 0; |
721 | } | 362 | } |
722 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][1]); | 363 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][1] & 0xFF); |
723 | for ( ; n < 24; n++, YL += 32, YR += 32 ) { | 364 | for ( ; n < 24; n++, YL += 32, YR += 32 ) { |
724 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); | 365 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); |
725 | *YR = 0; | 366 | *YR = 0; |
726 | } | 367 | } |
727 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (unsigned char)d->SCF_Index_L[Band][2]); | 368 | facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][2] & 0xFF); |
728 | for ( ; n < 36; n++, YL += 32, YR += 32 ) { | 369 | for ( ; n < 36; n++, YL += 32, YR += 32 ) { |
729 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); | 370 | *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); |
730 | *YR = 0; | 371 | *YR = 0; |
@@ -733,17 +374,17 @@ mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) | |||
733 | } | 374 | } |
734 | else { | 375 | else { |
735 | if ( d->Res_R [Band] ) { // L==0, R!=0 | 376 | if ( d->Res_R [Band] ) { // L==0, R!=0 |
736 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][0]); | 377 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][0] & 0xFF); |
737 | for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { | 378 | for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { |
738 | *YL = 0; | 379 | *YL = 0; |
739 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); | 380 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); |
740 | } | 381 | } |
741 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][1]); | 382 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][1] & 0xFF); |
742 | for ( ; n < 24; n++, YL += 32, YR += 32 ) { | 383 | for ( ; n < 24; n++, YL += 32, YR += 32 ) { |
743 | *YL = 0; | 384 | *YL = 0; |
744 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); | 385 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); |
745 | } | 386 | } |
746 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (unsigned char)d->SCF_Index_R[Band][2]); | 387 | facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][2] & 0xFF); |
747 | for ( ; n < 36; n++, YL += 32, YR += 32 ) { | 388 | for ( ; n < 36; n++, YL += 32, YR += 32 ) { |
748 | *YL = 0; | 389 | *YL = 0; |
749 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); | 390 | *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); |
@@ -758,1040 +399,324 @@ mpc_decoder_requantisierung(mpc_decoder *d, const mpc_int32_t Last_Band) | |||
758 | } | 399 | } |
759 | } | 400 | } |
760 | 401 | ||
761 | #ifdef MPC_SUPPORT_SV456 | 402 | void mpc_decoder_read_bitstream_sv7(mpc_decoder * d, mpc_bits_reader * r) |
762 | static const unsigned char Q_res[32][16] ICONST_ATTR = { | ||
763 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, | ||
764 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, | ||
765 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, | ||
766 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, | ||
767 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, | ||
768 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, | ||
769 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, | ||
770 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, | ||
771 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, | ||
772 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, | ||
773 | {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17}, | ||
774 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
775 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
776 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
777 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
778 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
779 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
780 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
781 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
782 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
783 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
784 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
785 | {0,1,2,3,4,5,6,17,0,0,0,0,0,0,0,0}, | ||
786 | {0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0}, | ||
787 | {0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0}, | ||
788 | {0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0}, | ||
789 | {0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0}, | ||
790 | {0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0}, | ||
791 | {0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0}, | ||
792 | {0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0}, | ||
793 | {0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0}, | ||
794 | {0,1,2,17,0,0,0,0,0,0,0,0,0,0,0,0}, | ||
795 | }; | ||
796 | |||
797 | /****************************************** SV 6 ******************************************/ | ||
798 | void | ||
799 | mpc_decoder_read_bitstream_sv6(mpc_decoder *d) | ||
800 | { | 403 | { |
801 | mpc_int32_t n,k; | 404 | mpc_int32_t n, idx, Max_used_Band = 0; |
802 | mpc_int32_t Max_used_Band=0; | ||
803 | const HuffmanTyp *Table; | ||
804 | const HuffmanTyp *x1; | ||
805 | const HuffmanTyp *x2; | ||
806 | mpc_int8_t *L; | ||
807 | mpc_int8_t *R; | ||
808 | mpc_int16_t *QL; | ||
809 | mpc_int16_t *QR; | ||
810 | mpc_int8_t *ResL = d->Res_L; | ||
811 | mpc_int8_t *ResR = d->Res_R; | ||
812 | 405 | ||
813 | /************************ HEADER **************************/ | 406 | /***************************** Header *****************************/ |
814 | ResL = d->Res_L; | ||
815 | ResR = d->Res_R; | ||
816 | for (n=0; n <= d->Max_Band; ++n, ++ResL, ++ResR) | ||
817 | { | ||
818 | if (n<11) Table = mpc_table_Region_A; | ||
819 | else if (n>=11 && n<=22) Table = mpc_table_Region_B; | ||
820 | else /*if (n>=23)*/ Table = mpc_table_Region_C; | ||
821 | 407 | ||
822 | *ResL = Q_res[n][mpc_decoder_huffman_decode(d, Table)]; | 408 | // first subband |
823 | if (d->MS_used) { | 409 | d->Res_L[0] = mpc_bits_read(r, 4); |
824 | d->MS_Flag[n] = mpc_decoder_bitstream_read(d, 1); | 410 | d->Res_R[0] = mpc_bits_read(r, 4); |
825 | } | 411 | if (!(d->Res_L[0] == 0 && d->Res_R[0] == 0)) { |
826 | *ResR = Q_res[n][mpc_decoder_huffman_decode(d, Table)]; | 412 | if (d->ms) |
413 | d->MS_Flag[0] = mpc_bits_read(r, 1); | ||
414 | Max_used_Band = 1; | ||
415 | } | ||
416 | |||
417 | // consecutive subbands | ||
418 | for ( n = 1; n <= d->max_band; n++ ) { | ||
419 | idx = mpc_bits_huff_lut(r, & mpc_HuffHdr); | ||
420 | d->Res_L[n] = (idx!=4) ? d->Res_L[n - 1] + idx : (int) mpc_bits_read(r, 4); | ||
827 | 421 | ||
828 | // only perform the following procedure up to the maximum non-zero subband | 422 | idx = mpc_bits_huff_lut(r, & mpc_HuffHdr); |
829 | if (*ResL || *ResR) Max_used_Band = n; | 423 | d->Res_R[n] = (idx!=4) ? d->Res_R[n - 1] + idx : (int) mpc_bits_read(r, 4); |
424 | |||
425 | if (!(d->Res_L[n] == 0 && d->Res_R[n] == 0)) { | ||
426 | if (d->ms) | ||
427 | d->MS_Flag[n] = mpc_bits_read(r, 1); | ||
428 | Max_used_Band = n + 1; | ||
429 | } | ||
830 | } | 430 | } |
831 | 431 | ||
832 | /************************* SCFI-Bundle *****************************/ | 432 | /****************************** SCFI ******************************/ |
833 | ResL = d->Res_L; | 433 | for ( n = 0; n < Max_used_Band; n++ ) { |
834 | ResR = d->Res_R; | 434 | if (d->Res_L[n]) |
835 | for (n=0; n<=Max_used_Band; ++n, ++ResL, ++ResR) { | 435 | d->SCFI_L[n] = mpc_bits_huff_dec(r, mpc_table_HuffSCFI); |
836 | if (*ResL) mpc_decoder_scfi_bundle_read(d, mpc_table_SCFI_Bundle, &(d->SCFI_L[n]), &(d->DSCF_Flag_L[n])); | 436 | if (d->Res_R[n]) |
837 | if (*ResR) mpc_decoder_scfi_bundle_read(d, mpc_table_SCFI_Bundle, &(d->SCFI_R[n]), &(d->DSCF_Flag_R[n])); | 437 | d->SCFI_R[n] = mpc_bits_huff_dec(r, mpc_table_HuffSCFI); |
838 | } | 438 | } |
839 | 439 | ||
840 | /***************************** SCFI ********************************/ | 440 | /**************************** SCF/DSCF ****************************/ |
841 | ResL = d->Res_L; | 441 | for ( n = 0; n < Max_used_Band; n++ ) { |
842 | ResR = d->Res_R; | 442 | mpc_int32_t * SCF = d->SCF_Index_L[n]; |
843 | L = d->SCF_Index_L[0]; | 443 | mpc_uint32_t Res = d->Res_L[n], SCFI = d->SCFI_L[n]; |
844 | R = d->SCF_Index_R[0]; | 444 | do { |
845 | for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR, L+=3, R+=3) | 445 | if (Res) { |
846 | { | 446 | switch (SCFI) { |
847 | if (*ResL) | 447 | case 1: |
848 | { | 448 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); |
849 | /*********** DSCF ************/ | 449 | SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); |
850 | if (d->DSCF_Flag_L[n]==1) | 450 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); |
851 | { | 451 | SCF[1] = (idx!=8) ? SCF[0] + idx : (int) mpc_bits_read(r, 6); |
852 | switch (d->SCFI_L[n]) | 452 | SCF[2] = SCF[1]; |
853 | { | 453 | break; |
854 | case 3: | 454 | case 3: |
855 | L[0] = L[2] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 455 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); |
856 | L[1] = L[0]; | 456 | SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); |
857 | L[2] = L[1]; | 457 | SCF[1] = SCF[0]; |
858 | break; | 458 | SCF[2] = SCF[1]; |
859 | case 1: | 459 | break; |
860 | L[0] = L[2] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 460 | case 2: |
861 | L[1] = L[0] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 461 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); |
862 | L[2] = L[1]; | 462 | SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); |
863 | break; | 463 | SCF[1] = SCF[0]; |
864 | case 2: | 464 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); |
865 | L[0] = L[2] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 465 | SCF[2] = (idx!=8) ? SCF[1] + idx : (int) mpc_bits_read(r, 6); |
866 | L[1] = L[0]; | 466 | break; |
867 | L[2] = L[1] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 467 | case 0: |
868 | break; | 468 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); |
869 | case 0: | 469 | SCF[0] = (idx!=8) ? SCF[2] + idx : (int) mpc_bits_read(r, 6); |
870 | L[0] = L[2] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 470 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); |
871 | L[1] = L[0] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 471 | SCF[1] = (idx!=8) ? SCF[0] + idx : (int) mpc_bits_read(r, 6); |
872 | L[2] = L[1] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 472 | idx = mpc_bits_huff_lut(r, & mpc_HuffDSCF); |
873 | break; | 473 | SCF[2] = (idx!=8) ? SCF[1] + idx : (int) mpc_bits_read(r, 6); |
874 | default: | 474 | break; |
875 | return; | 475 | default: |
876 | break; | 476 | return; |
877 | } | 477 | } |
478 | if (SCF[0] > 1024) | ||
479 | SCF[0] = 0x8080; | ||
480 | if (SCF[1] > 1024) | ||
481 | SCF[1] = 0x8080; | ||
482 | if (SCF[2] > 1024) | ||
483 | SCF[2] = 0x8080; | ||
878 | } | 484 | } |
879 | /************ SCF ************/ | 485 | Res = d->Res_R[n]; |
880 | else | 486 | SCFI = d->SCFI_R[n]; |
881 | { | 487 | } while ( SCF == d->SCF_Index_L[n] && (SCF = d->SCF_Index_R[n])); |
882 | switch (d->SCFI_L[n]) | 488 | } |
883 | { | 489 | |
884 | case 3: | 490 | // if (d->seeking == TRUE) |
885 | L[0] = mpc_decoder_bitstream_read(d, 6); | 491 | // return; |
886 | L[1] = L[0]; | 492 | |
887 | L[2] = L[1]; | 493 | /***************************** Samples ****************************/ |
888 | break; | 494 | for ( n = 0; n < Max_used_Band; n++ ) { |
889 | case 1: | 495 | mpc_int16_t *q = d->Q[n].L, Res = d->Res_L[n]; |
890 | L[0] = mpc_decoder_bitstream_read(d, 6); | 496 | do { |
891 | L[1] = mpc_decoder_bitstream_read(d, 6); | 497 | mpc_int32_t k; |
892 | L[2] = L[1]; | 498 | const mpc_lut_data *Table; |
893 | break; | 499 | switch (Res) { |
894 | case 2: | 500 | case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9: |
895 | L[0] = mpc_decoder_bitstream_read(d, 6); | 501 | case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17: case 0: |
896 | L[1] = L[0]; | ||
897 | L[2] = mpc_decoder_bitstream_read(d, 6); | ||
898 | break; | ||
899 | case 0: | ||
900 | L[0] = mpc_decoder_bitstream_read(d, 6); | ||
901 | L[1] = mpc_decoder_bitstream_read(d, 6); | ||
902 | L[2] = mpc_decoder_bitstream_read(d, 6); | ||
903 | break; | ||
904 | default: | ||
905 | return; | ||
906 | break; | 502 | break; |
907 | } | 503 | case -1: |
908 | } | 504 | for (k=0; k<36; k++ ) { |
909 | } | 505 | mpc_uint32_t tmp = mpc_random_int(d); |
910 | if (*ResR) | 506 | q[k] = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; |
911 | { | 507 | } |
912 | /*********** DSCF ************/ | ||
913 | if (d->DSCF_Flag_R[n]==1) | ||
914 | { | ||
915 | switch (d->SCFI_R[n]) | ||
916 | { | ||
917 | case 3: | ||
918 | R[0] = R[2] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | ||
919 | R[1] = R[0]; | ||
920 | R[2] = R[1]; | ||
921 | break; | 508 | break; |
922 | case 1: | 509 | case 1: |
923 | R[0] = R[2] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 510 | Table = & mpc_HuffQ[0][mpc_bits_read(r, 1)]; |
924 | R[1] = R[0] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 511 | for ( k = 0; k < 36; k += 3) { |
925 | R[2] = R[1]; | 512 | idx = mpc_bits_huff_lut(r, Table); |
513 | q[k] = g_sv7_idx30[idx]; | ||
514 | q[k + 1] = g_sv7_idx31[idx]; | ||
515 | q[k + 2] = g_sv7_idx32[idx]; | ||
516 | } | ||
926 | break; | 517 | break; |
927 | case 2: | 518 | case 2: |
928 | R[0] = R[2] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 519 | Table = & mpc_HuffQ[1][mpc_bits_read(r, 1)]; |
929 | R[1] = R[0]; | 520 | for ( k = 0; k < 36; k += 2) { |
930 | R[2] = R[1] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 521 | idx = mpc_bits_huff_lut(r, Table); |
931 | break; | 522 | q[k] = g_sv7_idx50[idx]; |
932 | case 0: | 523 | q[k + 1] = g_sv7_idx51[idx]; |
933 | R[0] = R[2] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | 524 | } |
934 | R[1] = R[0] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | ||
935 | R[2] = R[1] + mpc_decoder_huffman_decode_fast(d, mpc_table_DSCF_Entropie); | ||
936 | break; | ||
937 | default: | ||
938 | return; | ||
939 | break; | 525 | break; |
940 | } | ||
941 | } | ||
942 | /************ SCF ************/ | ||
943 | else | ||
944 | { | ||
945 | switch (d->SCFI_R[n]) | ||
946 | { | ||
947 | case 3: | 526 | case 3: |
948 | R[0] = mpc_decoder_bitstream_read(d, 6); | 527 | case 4: |
949 | R[1] = R[0]; | 528 | case 5: |
950 | R[2] = R[1]; | 529 | case 6: |
951 | break; | 530 | case 7: |
952 | case 1: | 531 | Table = & mpc_HuffQ[Res - 1][mpc_bits_read(r, 1)]; |
953 | R[0] = mpc_decoder_bitstream_read(d, 6); | 532 | for ( k = 0; k < 36; k++ ) |
954 | R[1] = mpc_decoder_bitstream_read(d, 6); | 533 | q[k] = mpc_bits_huff_lut(r, Table); |
955 | R[2] = R[1]; | ||
956 | break; | ||
957 | case 2: | ||
958 | R[0] = mpc_decoder_bitstream_read(d, 6); | ||
959 | R[1] = R[0]; | ||
960 | R[2] = mpc_decoder_bitstream_read(d, 6); | ||
961 | break; | 534 | break; |
962 | case 0: | 535 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: |
963 | R[0] = mpc_decoder_bitstream_read(d, 6); | 536 | for ( k = 0; k < 36; k++ ) |
964 | R[1] = mpc_decoder_bitstream_read(d, 6); | 537 | q[k] = (mpc_int32_t)mpc_bits_read(r, Res_bit[Res]) - Dc[Res]; |
965 | R[2] = mpc_decoder_bitstream_read(d, 6); | ||
966 | break; | 538 | break; |
967 | default: | 539 | default: |
968 | return; | 540 | return; |
969 | break; | ||
970 | } | ||
971 | } | ||
972 | } | ||
973 | } | ||
974 | |||
975 | /**************************** Samples ****************************/ | ||
976 | ResL = d->Res_L; | ||
977 | ResR = d->Res_R; | ||
978 | for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR) | ||
979 | { | ||
980 | // setting pointers | ||
981 | x1 = mpc_table_SampleHuff[*ResL]; | ||
982 | x2 = mpc_table_SampleHuff[*ResR]; | ||
983 | QL = d->Q[n].L; | ||
984 | QR = d->Q[n].R; | ||
985 | |||
986 | if (x1!=NULL || x2!=NULL) | ||
987 | for (k=0; k<36; ++k) | ||
988 | { | ||
989 | if (x1 != NULL) *QL++ = mpc_decoder_huffman_decode_fast(d, x1); | ||
990 | if (x2 != NULL) *QR++ = mpc_decoder_huffman_decode_fast(d, x2); | ||
991 | } | 541 | } |
992 | 542 | ||
993 | if (*ResL>7 || *ResR>7) | 543 | Res = d->Res_R[n]; |
994 | for (k=0; k<36; ++k) | 544 | } while (q == d->Q[n].L && (q = d->Q[n].R)); |
995 | { | ||
996 | if (*ResL>7) *QL++ = (mpc_int16_t)mpc_decoder_bitstream_read(d, Res_bit[*ResL]) - Dc[*ResL]; | ||
997 | if (*ResR>7) *QR++ = (mpc_int16_t)mpc_decoder_bitstream_read(d, Res_bit[*ResR]) - Dc[*ResR]; | ||
998 | } | ||
999 | } | 545 | } |
1000 | } | 546 | } |
1001 | #endif //MPC_SUPPORT_SV456 | 547 | |
1002 | /****************************************** SV 7 ******************************************/ | 548 | void mpc_decoder_read_bitstream_sv8(mpc_decoder * d, mpc_bits_reader * r, mpc_bool_t is_key_frame) |
1003 | void | ||
1004 | mpc_decoder_read_bitstream_sv7(mpc_decoder *d, mpc_bool_t fastSeeking) | ||
1005 | { | 549 | { |
1006 | mpc_int32_t n,k; | 550 | mpc_int32_t n, Max_used_Band; |
1007 | mpc_int32_t Max_used_Band=0; | 551 | const mpc_can_data * Table, * Tables[2]; |
1008 | const HuffmanTyp *Table; | ||
1009 | mpc_int32_t idx; | ||
1010 | mpc_int8_t *L ,*R; | ||
1011 | mpc_int16_t *LQ ,*RQ; | ||
1012 | mpc_int8_t *ResL,*ResR; | ||
1013 | mpc_uint32_t tmp; | ||
1014 | mpc_uint8_t *LUT; | ||
1015 | mpc_uint8_t max_length; | ||
1016 | 552 | ||
1017 | /***************************** Header *****************************/ | 553 | /***************************** Header *****************************/ |
1018 | ResL = d->Res_L; | ||
1019 | ResR = d->Res_R; | ||
1020 | 554 | ||
1021 | // first subband | 555 | if (is_key_frame == MPC_TRUE) { |
1022 | *ResL = mpc_decoder_bitstream_read(d, 4); | 556 | Max_used_Band = mpc_bits_log_dec(r, d->max_band + 1); |
1023 | *ResR = mpc_decoder_bitstream_read(d, 4); | ||
1024 | if (d->MS_used && !(*ResL==0 && *ResR==0)) { | ||
1025 | d->MS_Flag[0] = mpc_decoder_bitstream_read(d, 1); | ||
1026 | } else { | 557 | } else { |
1027 | d->MS_Flag[0] = 0; | 558 | Max_used_Band = d->last_max_band + mpc_bits_can_dec(r, & mpc_can_Bands); |
1028 | } | 559 | if (Max_used_Band > 32) Max_used_Band -= 33; |
1029 | 560 | } | |
1030 | // consecutive subbands | 561 | d->last_max_band = Max_used_Band; |
1031 | ++ResL; ++ResR; // increase pointers | 562 | |
1032 | for (n=1; n <= d->Max_Band; ++n, ++ResL, ++ResR) | 563 | if (Max_used_Band) { |
1033 | { | 564 | d->Res_L[Max_used_Band-1] = mpc_bits_can_dec(r, & mpc_can_Res[0]); |
1034 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffHdr); | 565 | d->Res_R[Max_used_Band-1] = mpc_bits_can_dec(r, & mpc_can_Res[0]); |
1035 | *ResL = (idx!=4) ? *(ResL-1) + idx : (int) mpc_decoder_bitstream_read(d, 4); | 566 | if (d->Res_L[Max_used_Band-1] > 15) d->Res_L[Max_used_Band-1] -= 17; |
1036 | 567 | if (d->Res_R[Max_used_Band-1] > 15) d->Res_R[Max_used_Band-1] -= 17; | |
1037 | idx = mpc_decoder_huffman_decode_fast(d, mpc_table_HuffHdr); | 568 | for ( n = Max_used_Band - 2; n >= 0; n--) { |
1038 | *ResR = (idx!=4) ? *(ResR-1) + idx : (int) mpc_decoder_bitstream_read(d, 4); | 569 | d->Res_L[n] = mpc_bits_can_dec(r, & mpc_can_Res[d->Res_L[n + 1] > 2]) + d->Res_L[n + 1]; |
1039 | 570 | if (d->Res_L[n] > 15) d->Res_L[n] -= 17; | |
1040 | if (d->MS_used && !(*ResL==0 && *ResR==0)) { | 571 | d->Res_R[n] = mpc_bits_can_dec(r, & mpc_can_Res[d->Res_R[n + 1] > 2]) + d->Res_R[n + 1]; |
1041 | d->MS_Flag[n] = mpc_decoder_bitstream_read(d, 1); | 572 | if (d->Res_R[n] > 15) d->Res_R[n] -= 17; |
1042 | } | 573 | } |
1043 | 574 | ||
1044 | // only perform following procedures up to the maximum non-zero subband | 575 | if (d->ms) { |
1045 | if (*ResL!=0 || *ResR!=0) { | 576 | int cnt = 0, tot = 0; |
1046 | Max_used_Band = n; | 577 | mpc_uint32_t tmp = 0; |
1047 | } else { | 578 | for( n = 0; n < Max_used_Band; n++) |
1048 | d->MS_Flag[n] = 0; | 579 | if ( d->Res_L[n] != 0 || d->Res_R[n] != 0 ) |
580 | tot++; | ||
581 | cnt = mpc_bits_log_dec(r, tot); | ||
582 | if (cnt != 0 && cnt != tot) | ||
583 | tmp = mpc_bits_enum_dec(r, mini(cnt, tot-cnt), tot); | ||
584 | if (cnt * 2 > tot) tmp = ~tmp; | ||
585 | for( n = Max_used_Band - 1; n >= 0; n--) | ||
586 | if ( d->Res_L[n] != 0 || d->Res_R[n] != 0 ) { | ||
587 | d->MS_Flag[n] = tmp & 1; | ||
588 | tmp >>= 1; | ||
589 | } | ||
1049 | } | 590 | } |
1050 | } | 591 | } |
1051 | /****************************** SCFI ******************************/ | ||
1052 | L = d->SCFI_L; | ||
1053 | R = d->SCFI_R; | ||
1054 | ResL = d->Res_L; | ||
1055 | ResR = d->Res_R; | ||
1056 | for (n=0; n <= Max_used_Band; ++n, ++L, ++R, ++ResL, ++ResR) { | ||
1057 | if (*ResL) *L = mpc_decoder_huffman_decode_faster(d, mpc_table_HuffSCFI); | ||
1058 | if (*ResR) *R = mpc_decoder_huffman_decode_faster(d, mpc_table_HuffSCFI); | ||
1059 | } | ||
1060 | 592 | ||
1061 | /**************************** SCF/DSCF ****************************/ | 593 | for( n = Max_used_Band; n <= d->max_band; n++) |
1062 | ResL = d->Res_L; | 594 | d->Res_L[n] = d->Res_R[n] = 0; |
1063 | ResR = d->Res_R; | 595 | |
1064 | L = d->SCF_Index_L[0]; | 596 | /****************************** SCFI ******************************/ |
1065 | R = d->SCF_Index_R[0]; | 597 | if (is_key_frame == MPC_TRUE){ |
1066 | for (n=0; n<=Max_used_Band; ++n, ++ResL, ++ResR, L+=3, R+=3) { | 598 | for( n = 0; n < 32; n++) |
1067 | if (*ResL) | 599 | d->DSCF_Flag_L[n] = d->DSCF_Flag_R[n] = 1; // new block -> force key frame |
1068 | { | 600 | } |
1069 | switch (d->SCFI_L[n]) | 601 | |
1070 | { | 602 | Tables[0] = & mpc_can_SCFI[0]; |
1071 | case 1: | 603 | Tables[1] = & mpc_can_SCFI[1]; |
1072 | idx = Decode_DSCF (); | 604 | for ( n = 0; n < Max_used_Band; n++ ) { |
1073 | L[0] = (idx!=8) ? SCF_DIFF(L[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); | 605 | int tmp = 0, cnt = -1; |
1074 | idx = Decode_DSCF (); | 606 | if (d->Res_L[n]) cnt++; |
1075 | L[1] = (idx!=8) ? SCF_DIFF(L[0], idx) : (int) mpc_decoder_bitstream_read(d, 6); | 607 | if (d->Res_R[n]) cnt++; |
1076 | L[2] = L[1]; | 608 | if (cnt >= 0) { |
1077 | break; | 609 | tmp = mpc_bits_can_dec(r, Tables[cnt]); |
1078 | case 3: | 610 | if (d->Res_L[n]) d->SCFI_L[n] = tmp >> (2 * cnt); |
1079 | idx = Decode_DSCF (); | 611 | if (d->Res_R[n]) d->SCFI_R[n] = tmp & 3; |
1080 | L[0] = (idx!=8) ? SCF_DIFF(L[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1081 | L[1] = L[0]; | ||
1082 | L[2] = L[1]; | ||
1083 | break; | ||
1084 | case 2: | ||
1085 | idx = Decode_DSCF (); | ||
1086 | L[0] = (idx!=8) ? SCF_DIFF(L[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1087 | L[1] = L[0]; | ||
1088 | idx = Decode_DSCF (); | ||
1089 | L[2] = (idx!=8) ? SCF_DIFF(L[1], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1090 | break; | ||
1091 | case 0: | ||
1092 | idx = Decode_DSCF (); | ||
1093 | L[0] = (idx!=8) ? SCF_DIFF(L[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1094 | idx = Decode_DSCF (); | ||
1095 | L[1] = (idx!=8) ? SCF_DIFF(L[0], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1096 | idx = Decode_DSCF (); | ||
1097 | L[2] = (idx!=8) ? SCF_DIFF(L[1], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1098 | break; | ||
1099 | default: | ||
1100 | return; | ||
1101 | break; | ||
1102 | } | ||
1103 | } | ||
1104 | if (*ResR) | ||
1105 | { | ||
1106 | switch (d->SCFI_R[n]) | ||
1107 | { | ||
1108 | case 1: | ||
1109 | idx = Decode_DSCF (); | ||
1110 | R[0] = (idx!=8) ? SCF_DIFF(R[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1111 | idx = Decode_DSCF (); | ||
1112 | R[1] = (idx!=8) ? SCF_DIFF(R[0], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1113 | R[2] = R[1]; | ||
1114 | break; | ||
1115 | case 3: | ||
1116 | idx = Decode_DSCF (); | ||
1117 | R[0] = (idx!=8) ? SCF_DIFF(R[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1118 | R[1] = R[0]; | ||
1119 | R[2] = R[1]; | ||
1120 | break; | ||
1121 | case 2: | ||
1122 | idx = Decode_DSCF (); | ||
1123 | R[0] = (idx!=8) ? SCF_DIFF(R[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1124 | R[1] = R[0]; | ||
1125 | idx = Decode_DSCF (); | ||
1126 | R[2] = (idx!=8) ? SCF_DIFF(R[1], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1127 | break; | ||
1128 | case 0: | ||
1129 | idx = Decode_DSCF (); | ||
1130 | R[0] = (idx!=8) ? SCF_DIFF(R[2], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1131 | idx = Decode_DSCF (); | ||
1132 | R[1] = (idx!=8) ? SCF_DIFF(R[0], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1133 | idx = Decode_DSCF (); | ||
1134 | R[2] = (idx!=8) ? SCF_DIFF(R[1], idx) : (int) mpc_decoder_bitstream_read(d, 6); | ||
1135 | break; | ||
1136 | default: | ||
1137 | return; | ||
1138 | break; | ||
1139 | } | ||
1140 | } | 612 | } |
1141 | } | 613 | } |
1142 | 614 | ||
1143 | if (fastSeeking) | 615 | /**************************** SCF/DSCF ****************************/ |
1144 | return; | ||
1145 | 616 | ||
1146 | /***************************** Samples ****************************/ | 617 | for ( n = 0; n < Max_used_Band; n++ ) { |
1147 | ResL = d->Res_L; | 618 | mpc_int32_t * SCF = d->SCF_Index_L[n]; |
1148 | ResR = d->Res_R; | 619 | mpc_uint32_t Res = d->Res_L[n], SCFI = d->SCFI_L[n]; |
1149 | LQ = d->Q[0].L; | 620 | mpc_bool_t * DSCF_Flag = &d->DSCF_Flag_L[n]; |
1150 | RQ = d->Q[0].R; | 621 | |
1151 | for (n=0; n <= Max_used_Band; ++n, ++ResL, ++ResR, LQ+=36, RQ+=36) | 622 | do { |
1152 | { | 623 | if ( Res ) { |
1153 | /************** links **************/ | 624 | int m; |
1154 | switch (*ResL) | 625 | if (*DSCF_Flag == 1) { |
1155 | { | 626 | SCF[0] = (mpc_int32_t)mpc_bits_read(r, 7) - 6; |
1156 | case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9: | 627 | *DSCF_Flag = 0; |
1157 | case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17: | ||
1158 | LQ += 36; | ||
1159 | break; | ||
1160 | case -1: | ||
1161 | for (k=0; k<36; k++ ) { | ||
1162 | tmp = mpc_random_int(d); | ||
1163 | *LQ++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; | ||
1164 | } | ||
1165 | break; | ||
1166 | case 0: | ||
1167 | LQ += 36;// increase pointer | ||
1168 | break; | ||
1169 | case 1: | ||
1170 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1171 | Table = mpc_table_HuffQ[1][1]; | ||
1172 | LUT = LUT1_1; | ||
1173 | max_length = 9; | ||
1174 | } else { | ||
1175 | Table = mpc_table_HuffQ[0][1]; | ||
1176 | LUT = LUT1_0; | ||
1177 | max_length = 6; | ||
1178 | } | ||
1179 | for (k=0; k<12; ++k) | ||
1180 | { | ||
1181 | idx = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1182 | *LQ++ = idx30[idx]; | ||
1183 | *LQ++ = idx31[idx]; | ||
1184 | *LQ++ = idx32[idx]; | ||
1185 | } | ||
1186 | break; | ||
1187 | case 2: | ||
1188 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1189 | Table = mpc_table_HuffQ[1][2]; | ||
1190 | LUT = LUT2_1; | ||
1191 | max_length = 10; | ||
1192 | } else { | ||
1193 | Table = mpc_table_HuffQ[0][2]; | ||
1194 | LUT = LUT2_0; | ||
1195 | max_length = 7; | ||
1196 | } | ||
1197 | for (k=0; k<18; ++k) | ||
1198 | { | ||
1199 | idx = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1200 | *LQ++ = idx50[idx]; | ||
1201 | *LQ++ = idx51[idx]; | ||
1202 | } | ||
1203 | break; | ||
1204 | case 3: | ||
1205 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1206 | Table = mpc_table_HuffQ[1][3]; | ||
1207 | LUT = LUT3_1; | ||
1208 | max_length = 5; | ||
1209 | } else { | ||
1210 | Table = mpc_table_HuffQ[0][3]; | ||
1211 | LUT = LUT3_0; | ||
1212 | max_length = 4; | ||
1213 | } | ||
1214 | for (k=0; k<36; ++k) | ||
1215 | *LQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1216 | break; | ||
1217 | case 4: | ||
1218 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1219 | Table = mpc_table_HuffQ[1][4]; | ||
1220 | LUT = LUT4_1; | ||
1221 | max_length = 5; | ||
1222 | } else { | ||
1223 | Table = mpc_table_HuffQ[0][4]; | ||
1224 | LUT = LUT4_0; | ||
1225 | max_length = 4; | ||
1226 | } | ||
1227 | for (k=0; k<36; ++k) | ||
1228 | *LQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1229 | break; | ||
1230 | case 5: | ||
1231 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1232 | Table = mpc_table_HuffQ[1][5]; | ||
1233 | LUT = LUT5_1; | ||
1234 | max_length = 8; | ||
1235 | } else { | ||
1236 | Table = mpc_table_HuffQ[0][5]; | ||
1237 | LUT = LUT5_0; | ||
1238 | max_length = 6; | ||
1239 | } | ||
1240 | for (k=0; k<36; ++k) | ||
1241 | *LQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1242 | break; | ||
1243 | case 6: | ||
1244 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1245 | Table = mpc_table_HuffQ[1][6]; | ||
1246 | LUT = LUT6_1; | ||
1247 | max_length = 7; | ||
1248 | for (k=0; k<36; ++k) | ||
1249 | *LQ++ = HUFFMAN_DECODE_FASTERER ( d, Table, LUT, max_length ); | ||
1250 | } else { | ||
1251 | Table = mpc_table_HuffQ[0][6]; | ||
1252 | LUT = LUT6_0; | ||
1253 | max_length = 7; | ||
1254 | for (k=0; k<36; ++k) | ||
1255 | *LQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1256 | } | ||
1257 | break; | ||
1258 | case 7: | ||
1259 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1260 | Table = mpc_table_HuffQ[1][7]; | ||
1261 | LUT = LUT7_1; | ||
1262 | max_length = 8; | ||
1263 | for (k=0; k<36; ++k) | ||
1264 | *LQ++ = HUFFMAN_DECODE_FASTERER ( d, Table, LUT, max_length ); | ||
1265 | } else { | ||
1266 | Table = mpc_table_HuffQ[0][7]; | ||
1267 | LUT = LUT7_0; | ||
1268 | max_length = 8; | ||
1269 | for (k=0; k<36; ++k) | ||
1270 | *LQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1271 | } | ||
1272 | break; | ||
1273 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: | ||
1274 | tmp = Dc[*ResL]; | ||
1275 | for (k=0; k<36; ++k) | ||
1276 | *LQ++ = (mpc_int16_t)mpc_decoder_bitstream_read(d, Res_bit[*ResL]) - tmp; | ||
1277 | break; | ||
1278 | default: | ||
1279 | return; | ||
1280 | } | ||
1281 | /************** rechts **************/ | ||
1282 | switch (*ResR) | ||
1283 | { | ||
1284 | case -2: case -3: case -4: case -5: case -6: case -7: case -8: case -9: | ||
1285 | case -10: case -11: case -12: case -13: case -14: case -15: case -16: case -17: | ||
1286 | RQ += 36; | ||
1287 | break; | ||
1288 | case -1: | ||
1289 | for (k=0; k<36; k++ ) { | ||
1290 | tmp = mpc_random_int(d); | ||
1291 | *RQ++ = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; | ||
1292 | } | ||
1293 | break; | ||
1294 | case 0: | ||
1295 | RQ += 36;// increase pointer | ||
1296 | break; | ||
1297 | case 1: | ||
1298 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1299 | Table = mpc_table_HuffQ[1][1]; | ||
1300 | LUT = LUT1_1; | ||
1301 | max_length = 9; | ||
1302 | } else { | ||
1303 | Table = mpc_table_HuffQ[0][1]; | ||
1304 | LUT = LUT1_0; | ||
1305 | max_length = 6; | ||
1306 | } | ||
1307 | for (k=0; k<12; ++k) | ||
1308 | { | ||
1309 | idx = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1310 | *RQ++ = idx30[idx]; | ||
1311 | *RQ++ = idx31[idx]; | ||
1312 | *RQ++ = idx32[idx]; | ||
1313 | } | ||
1314 | break; | ||
1315 | case 2: | ||
1316 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1317 | Table = mpc_table_HuffQ[1][2]; | ||
1318 | LUT = LUT2_1; | ||
1319 | max_length = 10; | ||
1320 | } else { | ||
1321 | Table = mpc_table_HuffQ[0][2]; | ||
1322 | LUT = LUT2_0; | ||
1323 | max_length = 7; | ||
1324 | } | ||
1325 | for (k=0; k<18; ++k) | ||
1326 | { | ||
1327 | idx = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1328 | *RQ++ = idx50[idx]; | ||
1329 | *RQ++ = idx51[idx]; | ||
1330 | } | ||
1331 | break; | ||
1332 | case 3: | ||
1333 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1334 | Table = mpc_table_HuffQ[1][3]; | ||
1335 | LUT = LUT3_1; | ||
1336 | max_length = 5; | ||
1337 | } else { | ||
1338 | Table = mpc_table_HuffQ[0][3]; | ||
1339 | LUT = LUT3_0; | ||
1340 | max_length = 4; | ||
1341 | } | ||
1342 | for (k=0; k<36; ++k) | ||
1343 | *RQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1344 | break; | ||
1345 | case 4: | ||
1346 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1347 | Table = mpc_table_HuffQ[1][4]; | ||
1348 | LUT = LUT4_1; | ||
1349 | max_length = 5; | ||
1350 | } else { | 628 | } else { |
1351 | Table = mpc_table_HuffQ[0][4]; | 629 | mpc_uint_t tmp = mpc_bits_can_dec(r, & mpc_can_DSCF[1]); |
1352 | LUT = LUT4_0; | 630 | if (tmp == 64) |
1353 | max_length = 4; | 631 | tmp += mpc_bits_read(r, 6); |
632 | SCF[0] = ((SCF[2] - 25 + tmp) & 127) - 6; | ||
1354 | } | 633 | } |
1355 | for (k=0; k<36; ++k) | 634 | for( m = 0; m < 2; m++){ |
1356 | *RQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | 635 | if (((SCFI << m) & 2) == 0) { |
1357 | break; | 636 | mpc_uint_t tmp = mpc_bits_can_dec(r, & mpc_can_DSCF[0]); |
1358 | case 5: | 637 | if (tmp == 31) |
1359 | if (mpc_decoder_bitstream_read(d, 1)) { | 638 | tmp = 64 + mpc_bits_read(r, 6); |
1360 | Table = mpc_table_HuffQ[1][5]; | 639 | SCF[m + 1] = ((SCF[m] - 25 + tmp) & 127) - 6; |
1361 | LUT = LUT5_1; | 640 | } else |
1362 | max_length = 8; | 641 | SCF[m + 1] = SCF[m]; |
1363 | } else { | ||
1364 | Table = mpc_table_HuffQ[0][5]; | ||
1365 | LUT = LUT5_0; | ||
1366 | max_length = 6; | ||
1367 | } | 642 | } |
1368 | for (k=0; k<36; ++k) | ||
1369 | *RQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1370 | break; | ||
1371 | case 6: | ||
1372 | if (mpc_decoder_bitstream_read(d, 1)) { | ||
1373 | Table = mpc_table_HuffQ[1][6]; | ||
1374 | LUT = LUT6_1; | ||
1375 | max_length = 7; | ||
1376 | for (k=0; k<36; ++k) | ||
1377 | *RQ++ = HUFFMAN_DECODE_FASTERER ( d, Table, LUT, max_length ); | ||
1378 | } else { | ||
1379 | Table = mpc_table_HuffQ[0][6]; | ||
1380 | LUT = LUT6_0; | ||
1381 | max_length = 7; | ||
1382 | for (k=0; k<36; ++k) | ||
1383 | *RQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1384 | } | 643 | } |
1385 | break; | 644 | Res = d->Res_R[n]; |
1386 | case 7: | 645 | SCFI = d->SCFI_R[n]; |
1387 | if (mpc_decoder_bitstream_read(d, 1)) { | 646 | DSCF_Flag = &d->DSCF_Flag_R[n]; |
1388 | Table = mpc_table_HuffQ[1][7]; | 647 | } while ( SCF == d->SCF_Index_L[n] && (SCF = d->SCF_Index_R[n])); |
1389 | LUT = LUT7_1; | ||
1390 | max_length = 8; | ||
1391 | for (k=0; k<36; ++k) | ||
1392 | *RQ++ = HUFFMAN_DECODE_FASTERER ( d, Table, LUT, max_length ); | ||
1393 | } else { | ||
1394 | Table = mpc_table_HuffQ[0][7]; | ||
1395 | LUT = LUT7_0; | ||
1396 | max_length = 8; | ||
1397 | for (k=0; k<36; ++k) | ||
1398 | *RQ++ = HUFFMAN_DECODE_FASTEST ( d, Table, LUT, max_length ); | ||
1399 | } | ||
1400 | break; | ||
1401 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: | ||
1402 | tmp = Dc[*ResR]; | ||
1403 | for (k=0; k<36; ++k) | ||
1404 | *RQ++ = (mpc_int16_t)mpc_decoder_bitstream_read(d, Res_bit[*ResR]) - tmp; | ||
1405 | break; | ||
1406 | default: | ||
1407 | return; | ||
1408 | } | ||
1409 | } | ||
1410 | } | ||
1411 | |||
1412 | void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r) | ||
1413 | { | ||
1414 | d->r = r; | ||
1415 | |||
1416 | d->MPCHeaderPos = 0; | ||
1417 | d->StreamVersion = 0; | ||
1418 | d->MS_used = 0; | ||
1419 | d->FwdJumpInfo = 0; | ||
1420 | d->ActDecodePos = 0; | ||
1421 | d->FrameWasValid = 0; | ||
1422 | d->OverallFrames = 0; | ||
1423 | d->DecodedFrames = 0; | ||
1424 | d->MaxDecodedFrames = 0; | ||
1425 | d->TrueGaplessPresent = 0; | ||
1426 | d->last_block_samples = 0; | ||
1427 | d->WordsRead = 0; | ||
1428 | d->Max_Band = 0; | ||
1429 | d->SampleRate = 0; | ||
1430 | d->__r1 = 1; | ||
1431 | d->__r2 = 1; | ||
1432 | |||
1433 | d->dword = 0; | ||
1434 | d->pos = 0; | ||
1435 | d->Zaehler = 0; | ||
1436 | d->Ring = 0; | ||
1437 | d->WordsRead = 0; | ||
1438 | d->Max_Band = 0; | ||
1439 | d->SeekTable_Step = 0; | ||
1440 | d->SeekTable_Mask = 0; | ||
1441 | d->SeekTableCounter = 0; | ||
1442 | |||
1443 | mpc_decoder_initialisiere_quantisierungstabellen(d, 1.0f); | ||
1444 | |||
1445 | LOOKUP ( mpc_table_HuffQ[0][1], 27, LUT1_0 ); | ||
1446 | LOOKUP ( mpc_table_HuffQ[1][1], 27, LUT1_1 ); | ||
1447 | LOOKUP ( mpc_table_HuffQ[0][2], 25, LUT2_0 ); | ||
1448 | LOOKUP ( mpc_table_HuffQ[1][2], 25, LUT2_1 ); | ||
1449 | LOOKUP ( mpc_table_HuffQ[0][3], 7, LUT3_0 ); | ||
1450 | LOOKUP ( mpc_table_HuffQ[1][3], 7, LUT3_1 ); | ||
1451 | LOOKUP ( mpc_table_HuffQ[0][4], 9, LUT4_0 ); | ||
1452 | LOOKUP ( mpc_table_HuffQ[1][4], 9, LUT4_1 ); | ||
1453 | LOOKUP ( mpc_table_HuffQ[0][5], 15, LUT5_0 ); | ||
1454 | LOOKUP ( mpc_table_HuffQ[1][5], 15, LUT5_1 ); | ||
1455 | LOOKUP ( mpc_table_HuffQ[0][6], 31, LUT6_0 ); | ||
1456 | LOOKUP ( mpc_table_HuffQ[1][6], 31, LUT6_1 ); | ||
1457 | LOOKUP ( mpc_table_HuffQ[0][7], 63, LUT7_0 ); | ||
1458 | LOOKUP ( mpc_table_HuffQ[1][7], 63, LUT7_1 ); | ||
1459 | LOOKUP ( mpc_table_HuffDSCF, 16, LUTDSCF ); | ||
1460 | |||
1461 | d->SeekTable = Seekbuffer; | ||
1462 | d->Speicher = Speicher; | ||
1463 | d->Y_L = Y_L; | ||
1464 | d->Y_R = Y_R; | ||
1465 | |||
1466 | #if defined(CPU_COLDFIRE) | ||
1467 | coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE); | ||
1468 | #endif | ||
1469 | } | ||
1470 | |||
1471 | static void mpc_decoder_set_streaminfo(mpc_decoder *d, mpc_streaminfo *si) | ||
1472 | { | ||
1473 | mpc_uint32_t seekTableSize; | ||
1474 | |||
1475 | mpc_decoder_reset_synthesis(d); | ||
1476 | mpc_decoder_reset_globals(d); | ||
1477 | |||
1478 | d->StreamVersion = si->stream_version; | ||
1479 | d->MS_used = si->ms; | ||
1480 | d->Max_Band = si->max_band; | ||
1481 | d->OverallFrames = si->frames; | ||
1482 | d->MPCHeaderPos = si->header_position; | ||
1483 | d->TrueGaplessPresent = si->is_true_gapless; | ||
1484 | d->SampleRate = (mpc_int32_t)si->sample_freq; | ||
1485 | |||
1486 | d->samples_to_skip = MPC_DECODER_SYNTH_DELAY; | ||
1487 | |||
1488 | memset(d->SeekTable, 0, sizeof(Seekbuffer)); | ||
1489 | |||
1490 | // limit used table size to MPC_SEEK_BUFFER_SIZE | ||
1491 | seekTableSize = min(si->frames, MPC_SEEK_BUFFER_SIZE); | ||
1492 | // frames per buffer to not exceed buffer and to be able to seek full file | ||
1493 | while ( seekTableSize < si->frames / (1<<d->SeekTable_Step) ) | ||
1494 | { | ||
1495 | d->SeekTable_Step++; | ||
1496 | } | 648 | } |
1497 | d->SeekTable_Mask = (1 << d->SeekTable_Step) - 1; | ||
1498 | } | ||
1499 | |||
1500 | mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si) | ||
1501 | { | ||
1502 | mpc_uint32_t bitPos; | ||
1503 | mpc_uint32_t fpos; | ||
1504 | |||
1505 | mpc_decoder_set_streaminfo(d, si); | ||
1506 | |||
1507 | // setting position to the beginning of the data-bitstream | ||
1508 | bitPos = get_initial_fpos(d, d->StreamVersion); | ||
1509 | fpos = bitPos >> 5; | ||
1510 | 649 | ||
1511 | // fill buffer and initialize decoder | 650 | /***************************** Samples ****************************/ |
1512 | f_seek(d, fpos*4 + d->MPCHeaderPos); | 651 | for ( n = 0; n < Max_used_Band; n++ ) { |
1513 | f_read_dword(d, d->Speicher, MEMSIZE); | 652 | mpc_int16_t *q = d->Q[n].L, Res = d->Res_L[n]; |
1514 | d->Ring = 0; | 653 | static const int thres[] = {0, 0, 3, 0, 0, 1, 3, 4, 8}; |
1515 | d->Zaehler = 0; | 654 | do { |
1516 | d->pos = bitPos & 31; | 655 | mpc_int32_t k = 0, idx = 1; |
1517 | d->WordsRead = fpos; | 656 | if (Res != 0) { |
1518 | d->dword = SWAP(d->Speicher[0]); | 657 | if (Res == 2) { |
1519 | d->next = SWAP(d->Speicher[1]); | 658 | Tables[0] = & mpc_can_Q [0][0]; |
1520 | 659 | Tables[1] = & mpc_can_Q [0][1]; | |
1521 | return TRUE; | 660 | idx = 2 * thres[Res]; |
1522 | } | 661 | for ( ; k < 36; k += 3) { |
1523 | 662 | int tmp = mpc_bits_can_dec(r, Tables[idx > thres[Res]]); | |
1524 | // jumps over the current frame | 663 | q[k] = g_sv8_idx50[tmp]; |
1525 | mpc_uint32_t mpc_decoder_jump_frame(mpc_decoder *d) { | 664 | q[k + 1] = g_sv8_idx51[tmp]; |
1526 | 665 | q[k + 2] = g_sv8_idx52[tmp]; | |
1527 | mpc_uint32_t frameSize; | 666 | idx = (idx >> 1) + g_sv8_HuffQ2_var[tmp]; |
1528 | 667 | } | |
1529 | // ensure the buffer is full | 668 | } else if (Res == 1) { |
1530 | mpc_decoder_update_buffer(d); | 669 | Table = & mpc_can_Q1; |
1531 | 670 | for( ; k < 36; ){ | |
1532 | // bits in frame | 671 | int kmax = k + 18; |
1533 | frameSize = mpc_decoder_bitstream_read(d, 20); | 672 | mpc_uint_t cnt = mpc_bits_can_dec(r, Table); |
1534 | 673 | idx = 0; | |
1535 | // jump forward | 674 | if (cnt > 0 && cnt < 18) |
1536 | mpc_decoder_seek_forward(d, frameSize); | 675 | idx = mpc_bits_enum_dec(r, cnt <= 9 ? cnt : 18 - cnt, 18); |
1537 | 676 | if (cnt > 9) idx = ~idx; | |
1538 | return frameSize + 20; | 677 | for ( ; k < kmax; k++) { |
1539 | 678 | q[k] = 0; | |
1540 | } | 679 | if ( idx & (1 << 17) ) |
1541 | 680 | q[k] = (mpc_bits_read(r, 1) << 1) - 1; | |
1542 | static mpc_uint32_t get_initial_fpos(mpc_decoder *d, mpc_uint32_t StreamVersion) | 681 | idx <<= 1; |
1543 | { | 682 | } |
1544 | mpc_uint32_t fpos = 0; | 683 | } |
1545 | (void) StreamVersion; | 684 | } else if (Res == -1) { |
1546 | 685 | for ( ; k<36; k++ ) { | |
1547 | // setting position to the beginning of the data-bitstream | 686 | mpc_uint32_t tmp = mpc_random_int(d); |
1548 | switch ( d->StreamVersion ) { | 687 | q[k] = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; |
1549 | case 0x04: fpos = 48; break; | 688 | } |
1550 | case 0x05: | 689 | } else if (Res <= 4) { |
1551 | case 0x06: fpos = 64; break; | 690 | Table = & mpc_can_Q[1][Res - 3]; |
1552 | case 0x07: | 691 | for ( ; k < 36; k += 2 ) { |
1553 | case 0x17: fpos = 200; break; | 692 | union { |
1554 | } | 693 | mpc_int8_t sym; |
1555 | return fpos; | 694 | struct { mpc_int8_t s1:4, s2:4; }; |
1556 | } | 695 | } tmp; |
1557 | 696 | tmp.sym = mpc_bits_can_dec(r, Table); | |
1558 | mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds) | 697 | q[k] = tmp.s1; |
1559 | { | 698 | q[k + 1] = tmp.s2; |
1560 | return mpc_decoder_seek_sample(d, (mpc_int64_t)(seconds * (double)d->SampleRate + 0.5)); | 699 | } |
1561 | } | 700 | } else if (Res <= 8) { |
1562 | 701 | Tables[0] = & mpc_can_Q [Res - 3][0]; | |
1563 | void mpc_decoder_reset_state(mpc_decoder *d) { | 702 | Tables[1] = & mpc_can_Q [Res - 3][1]; |
1564 | 703 | idx = 2 * thres[Res]; | |
1565 | memset(d->Y_L , 0, sizeof Y_L ); | 704 | for ( ; k < 36; k++ ) { |
1566 | memset(d->Y_R , 0, sizeof Y_R ); | 705 | q[k] = mpc_bits_can_dec(r, Tables[idx > thres[Res]]); |
1567 | #ifdef SCF_HACK | 706 | idx = (idx >> 1) + absi(q[k]); |
1568 | memset(d->SCF_Index_L , 127, sizeof d->SCF_Index_L ); | 707 | } |
1569 | memset(d->SCF_Index_R , 127, sizeof d->SCF_Index_R ); | 708 | } else { |
1570 | #else | 709 | for ( ; k < 36; k++ ) { |
1571 | memset(d->SCF_Index_L , 0, sizeof d->SCF_Index_L ); | 710 | q[k] = (unsigned char) mpc_bits_can_dec(r, & mpc_can_Q9up); |
1572 | memset(d->SCF_Index_R , 0, sizeof d->SCF_Index_R ); | 711 | if (Res != 9) |
1573 | #endif | 712 | q[k] = (q[k] << (Res - 9)) | mpc_bits_read(r, Res - 9); |
1574 | memset(d->Res_L , 0, sizeof d->Res_L ); | 713 | q[k] -= Dc[Res]; |
1575 | memset(d->Res_R , 0, sizeof d->Res_R ); | 714 | } |
1576 | memset(d->SCFI_L , 0, sizeof d->SCFI_L ); | 715 | } |
1577 | memset(d->SCFI_R , 0, sizeof d->SCFI_R ); | ||
1578 | #ifdef MPC_SUPPORT_SV456 | ||
1579 | memset(d->DSCF_Flag_L , 0, sizeof d->DSCF_Flag_L ); | ||
1580 | memset(d->DSCF_Flag_R , 0, sizeof d->DSCF_Flag_R ); | ||
1581 | #endif | ||
1582 | memset(d->Q , 0, sizeof d->Q ); | ||
1583 | memset(d->MS_Flag , 0, sizeof d->MS_Flag ); | ||
1584 | |||
1585 | } | ||
1586 | |||
1587 | mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample) | ||
1588 | { | ||
1589 | mpc_uint32_t fpos = 0; // the bit to seek to | ||
1590 | mpc_uint32_t seekFrame = 0; // the frame to seek to | ||
1591 | mpc_uint32_t lastFrame = 0; // last frame to seek to before scanning scale factors | ||
1592 | mpc_int32_t delta = 0; // direction of seek | ||
1593 | |||
1594 | destsample += MPC_DECODER_SYNTH_DELAY; | ||
1595 | seekFrame = (mpc_uint32_t) ((destsample) / MPC_FRAME_LENGTH); | ||
1596 | d->samples_to_skip = (mpc_uint32_t)((destsample) % MPC_FRAME_LENGTH); | ||
1597 | |||
1598 | // prevent from desired position out of allowed range | ||
1599 | seekFrame = seekFrame < d->OverallFrames ? seekFrame : d->OverallFrames; | ||
1600 | |||
1601 | // seek direction (note: avoids casting to int64) | ||
1602 | delta = (d->DecodedFrames > seekFrame ? -(mpc_int32_t)(d->DecodedFrames - seekFrame) : (mpc_int32_t)(seekFrame - d->DecodedFrames)); | ||
1603 | |||
1604 | if (seekFrame > SEEK_PRE_DECODE) | ||
1605 | lastFrame = seekFrame - SEEK_PRE_DECODE + 1 - (1<<d->SeekTable_Step); | ||
1606 | |||
1607 | if (d->MaxDecodedFrames == 0) // nothing decoded yet, parse stream | ||
1608 | { | ||
1609 | mpc_decoder_reset_state(d); | ||
1610 | |||
1611 | // starts from the beginning since no frames have been decoded yet, or not using seek table | ||
1612 | fpos = get_initial_fpos(d, d->StreamVersion); | ||
1613 | |||
1614 | // seek to the first frame | ||
1615 | mpc_decoder_seek_to(d, fpos); | ||
1616 | |||
1617 | // jump to the last frame via parsing, updating seek table | ||
1618 | d->SeekTable[0] = (mpc_uint32_t)fpos; | ||
1619 | d->SeekTableCounter = 0; | ||
1620 | for (d->DecodedFrames = 0; d->DecodedFrames < lastFrame; d->DecodedFrames++) | ||
1621 | { | ||
1622 | d->SeekTableCounter += mpc_decoder_jump_frame(d); | ||
1623 | if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask))) | ||
1624 | { | ||
1625 | d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step] = d->SeekTableCounter; | ||
1626 | d->MaxDecodedFrames = d->DecodedFrames; | ||
1627 | d->SeekTableCounter = 0; | ||
1628 | } | ||
1629 | } | ||
1630 | } | ||
1631 | else if (delta < 0) // jump backwards, seek table is already available | ||
1632 | { | ||
1633 | mpc_decoder_reset_state(d); | ||
1634 | |||
1635 | // jumps backwards using the seek table | ||
1636 | fpos = d->SeekTable[0]; | ||
1637 | for (d->DecodedFrames = 0; d->DecodedFrames < lastFrame; d->DecodedFrames++) | ||
1638 | { | ||
1639 | if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask))) | ||
1640 | { | ||
1641 | fpos += d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step]; | ||
1642 | d->SeekTableCounter = 0; | ||
1643 | } | ||
1644 | } | ||
1645 | mpc_decoder_seek_to(d, fpos); | ||
1646 | } | ||
1647 | else if (delta > SEEK_PRE_DECODE) // jump forward, seek table is available | ||
1648 | { | ||
1649 | mpc_decoder_reset_state(d); | ||
1650 | |||
1651 | // 1st loop: jump to the last usable position in the seek table | ||
1652 | fpos = mpc_decoder_bits_read(d); | ||
1653 | for (; d->DecodedFrames < d->MaxDecodedFrames && d->DecodedFrames < lastFrame; d->DecodedFrames++) | ||
1654 | { | ||
1655 | if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask))) | ||
1656 | { | ||
1657 | fpos += d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step]; | ||
1658 | d->SeekTableCounter = 0; | ||
1659 | } | ||
1660 | } | ||
1661 | mpc_decoder_seek_to(d, fpos); | ||
1662 | |||
1663 | // 2nd loop: jump the residual frames via parsing, update seek table | ||
1664 | for (;d->DecodedFrames < lastFrame; d->DecodedFrames++) | ||
1665 | { | ||
1666 | d->SeekTableCounter += mpc_decoder_jump_frame(d); | ||
1667 | if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask))) | ||
1668 | { | ||
1669 | d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step] = d->SeekTableCounter; | ||
1670 | d->MaxDecodedFrames = d->DecodedFrames; | ||
1671 | d->SeekTableCounter = 0; | ||
1672 | } | 716 | } |
1673 | } | ||
1674 | } | ||
1675 | // until here we jumped to desired position -SEEK_PRE_DECODE frames | ||
1676 | |||
1677 | // now we decode the last SEEK_PRE_DECODE frames until we reach the seek | ||
1678 | // position. this is neccessary as mpc uses entropy coding in time domain | ||
1679 | for (;d->DecodedFrames < seekFrame; d->DecodedFrames++) | ||
1680 | { | ||
1681 | mpc_uint32_t FrameBitCnt; | ||
1682 | |||
1683 | d->FwdJumpInfo = mpc_decoder_bitstream_read(d, 20); // read jump-info | ||
1684 | d->ActDecodePos = (d->Zaehler << 5) + d->pos; | ||
1685 | FrameBitCnt = mpc_decoder_bits_read(d); | ||
1686 | // scanning the scalefactors (and check for validity of frame) | ||
1687 | if (d->StreamVersion >= 7) | ||
1688 | { | ||
1689 | mpc_decoder_read_bitstream_sv7(d, (d->DecodedFrames < seekFrame - 1)); | ||
1690 | } | ||
1691 | else | ||
1692 | { | ||
1693 | #ifdef MPC_SUPPORT_SV456 | ||
1694 | mpc_decoder_read_bitstream_sv6(d); | ||
1695 | #else | ||
1696 | return FALSE; | ||
1697 | #endif | ||
1698 | } | ||
1699 | 717 | ||
1700 | FrameBitCnt = mpc_decoder_bits_read(d) - FrameBitCnt; | 718 | Res = d->Res_R[n]; |
1701 | 719 | } while (q == d->Q[n].L && (q = d->Q[n].R)); | |
1702 | if (d->FwdJumpInfo > FrameBitCnt) | ||
1703 | mpc_decoder_seek_forward(d, d->FwdJumpInfo - FrameBitCnt); | ||
1704 | else if (FrameBitCnt != d->FwdJumpInfo ) | ||
1705 | // Bug in perform_jump; | ||
1706 | return FALSE; | ||
1707 | |||
1708 | // update seek table, if there new entries to fill | ||
1709 | d->SeekTableCounter += d->FwdJumpInfo + 20; | ||
1710 | if (0 == ((d->DecodedFrames+1) & (d->SeekTable_Mask))) | ||
1711 | { | ||
1712 | d->SeekTable[(d->DecodedFrames+1)>>d->SeekTable_Step] = d->SeekTableCounter; | ||
1713 | d->MaxDecodedFrames = d->DecodedFrames; | ||
1714 | d->SeekTableCounter = 0; | ||
1715 | } | ||
1716 | |||
1717 | // update buffer | ||
1718 | mpc_decoder_update_buffer(d); | ||
1719 | |||
1720 | if (d->DecodedFrames == seekFrame - 1) | ||
1721 | { | ||
1722 | // initialize the synth correctly for perfect decoding | ||
1723 | mpc_decoder_requantisierung(d, d->Max_Band); | ||
1724 | mpc_decoder_synthese_filter_float(d, NULL); | ||
1725 | } | ||
1726 | } | 720 | } |
1727 | |||
1728 | return TRUE; | ||
1729 | } | ||
1730 | |||
1731 | |||
1732 | void mpc_decoder_fill_buffer(mpc_decoder *d) { | ||
1733 | |||
1734 | f_read_dword(d, d->Speicher, MEMSIZE); | ||
1735 | d->dword = SWAP(d->Speicher[d->Zaehler = 0]); | ||
1736 | d->next = SWAP(d->Speicher[1]); | ||
1737 | d->Ring = 0; | ||
1738 | |||
1739 | } | ||
1740 | |||
1741 | |||
1742 | void mpc_decoder_update_buffer(mpc_decoder *d) | ||
1743 | { | ||
1744 | if ((d->Ring ^ d->Zaehler) & MEMSIZE2) { | ||
1745 | // update buffer | ||
1746 | f_read_dword(d, d->Speicher + (d->Ring & MEMSIZE2), MEMSIZE2); | ||
1747 | d->Ring = d->Zaehler; | ||
1748 | } | ||
1749 | } | ||
1750 | |||
1751 | |||
1752 | void mpc_decoder_seek_to(mpc_decoder *d, mpc_uint32_t bitPos) { | ||
1753 | |||
1754 | // required dword | ||
1755 | mpc_uint32_t fpos = (bitPos >> 5); | ||
1756 | mpc_uint32_t bufferStart = d->WordsRead - d->Zaehler; | ||
1757 | if ((d->Zaehler & MEMSIZE2) != FALSE) | ||
1758 | bufferStart += MEMSIZE2; | ||
1759 | |||
1760 | if (fpos >= bufferStart && fpos < bufferStart + MEMSIZE) { | ||
1761 | |||
1762 | // required position is within the buffer, no need to seek | ||
1763 | d->Zaehler = (fpos - bufferStart + ((d->Zaehler & MEMSIZE2) != FALSE ? MEMSIZE2 : 0)) & MEMMASK; | ||
1764 | d->pos = bitPos & 31; | ||
1765 | d->WordsRead = fpos; | ||
1766 | d->dword = SWAP(d->Speicher[d->Zaehler]); | ||
1767 | d->next = SWAP(d->Speicher[(d->Zaehler + 1) & MEMMASK]); | ||
1768 | |||
1769 | mpc_decoder_update_buffer(d); | ||
1770 | |||
1771 | |||
1772 | } else { | ||
1773 | |||
1774 | // DWORD aligned | ||
1775 | f_seek(d, fpos*4 + d->MPCHeaderPos); | ||
1776 | d->Zaehler = 0; | ||
1777 | d->pos = bitPos & 31; | ||
1778 | d->WordsRead = fpos; | ||
1779 | |||
1780 | mpc_decoder_fill_buffer(d); | ||
1781 | |||
1782 | } | ||
1783 | |||
1784 | } | ||
1785 | |||
1786 | void mpc_decoder_seek_forward(mpc_decoder *d, mpc_uint32_t bits) { | ||
1787 | |||
1788 | bits += d->pos; | ||
1789 | d->pos = bits & 31; | ||
1790 | bits = bits >> 5; // to DWORDs | ||
1791 | d->Zaehler = (d->Zaehler + bits) & MEMMASK; | ||
1792 | d->dword = SWAP(d->Speicher[d->Zaehler]); | ||
1793 | d->next = SWAP(d->Speicher[(d->Zaehler + 1) & MEMMASK]); | ||
1794 | d->WordsRead += bits; | ||
1795 | |||
1796 | } | 721 | } |
1797 | 722 | ||
diff --git a/apps/codecs/libmusepack/mpc_demux.c b/apps/codecs/libmusepack/mpc_demux.c new file mode 100755 index 0000000000..75d02bae54 --- /dev/null +++ b/apps/codecs/libmusepack/mpc_demux.c | |||
@@ -0,0 +1,666 @@ | |||
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 | // globals | ||
51 | static mpc_uint8_t g_buffer[DEMUX_BUFFER_SIZE + MAX_FRAME_SIZE]; | ||
52 | static mpc_seek_t g_seek_table[MAX_SEEK_TABLE_SIZE]; | ||
53 | static mpc_demux g_mpc_demux IBSS_ATTR; | ||
54 | |||
55 | // streaminfo.c | ||
56 | mpc_status streaminfo_read_header_sv8(mpc_streaminfo* si, | ||
57 | const mpc_bits_reader * r_in, | ||
58 | mpc_size_t block_size); | ||
59 | mpc_status streaminfo_read_header_sv7(mpc_streaminfo* si, mpc_bits_reader * r_in); | ||
60 | void streaminfo_encoder_info(mpc_streaminfo* si, const mpc_bits_reader * r_in); | ||
61 | void streaminfo_gain(mpc_streaminfo* si, const mpc_bits_reader * r_in); | ||
62 | |||
63 | // mpc_decoder.c | ||
64 | void mpc_decoder_reset_scf(mpc_decoder * d, int value); | ||
65 | |||
66 | enum { | ||
67 | MPC_BUFFER_SWAP = 1, | ||
68 | MPC_BUFFER_FULL = 2, | ||
69 | }; | ||
70 | |||
71 | static void mpc_demux_clear_buff(mpc_demux * d) | ||
72 | { | ||
73 | d->bytes_total = 0; | ||
74 | d->bits_reader.buff = d->buffer; | ||
75 | d->bits_reader.count = 8; | ||
76 | d->bits_reader.buffered_addr = 0; | ||
77 | d->bits_reader.buffered_code = 0; | ||
78 | d->block_bits = 0; | ||
79 | d->block_frames = 0; | ||
80 | memset(d->buffer, 0, sizeof(g_buffer)); | ||
81 | } | ||
82 | |||
83 | static mpc_uint32_t | ||
84 | mpc_demux_fill(mpc_demux * d, mpc_uint32_t min_bytes, int flags) | ||
85 | { | ||
86 | mpc_uint32_t unread_bytes = d->bytes_total + d->buffer - d->bits_reader.buff | ||
87 | - ((8 - d->bits_reader.count) >> 3); | ||
88 | int offset = 0; | ||
89 | |||
90 | if (min_bytes == 0 || min_bytes > DEMUX_BUFFER_SIZE || | ||
91 | (unread_bytes < min_bytes && flags & MPC_BUFFER_FULL)) | ||
92 | min_bytes = DEMUX_BUFFER_SIZE; | ||
93 | |||
94 | if (unread_bytes < min_bytes) { | ||
95 | mpc_uint32_t bytes2read = min_bytes - unread_bytes; | ||
96 | mpc_uint32_t bytes_free = DEMUX_BUFFER_SIZE - d->bytes_total; | ||
97 | |||
98 | if (flags & MPC_BUFFER_SWAP) { | ||
99 | bytes2read &= -1 << 2; | ||
100 | offset = (unread_bytes + 3) & ( -1 << 2); | ||
101 | offset -= unread_bytes; | ||
102 | } | ||
103 | |||
104 | if (bytes2read > bytes_free) { | ||
105 | if (d->bits_reader.count == 0) { | ||
106 | d->bits_reader.count = 8; | ||
107 | d->bits_reader.buff++; | ||
108 | } | ||
109 | memmove(d->buffer + offset, d->bits_reader.buff, unread_bytes); | ||
110 | d->bits_reader.buff = d->buffer + offset; | ||
111 | d->bytes_total = unread_bytes + offset; | ||
112 | } | ||
113 | bytes2read = d->r->read(d->r, d->buffer + d->bytes_total, bytes2read); | ||
114 | if (flags & MPC_BUFFER_SWAP){ | ||
115 | unsigned int i, * tmp = (unsigned int *) (d->buffer + d->bytes_total); | ||
116 | for(i = 0 ;i < (bytes2read >> 2); i++) | ||
117 | tmp[i] = swap32(tmp[i]); | ||
118 | } | ||
119 | d->bytes_total += bytes2read; | ||
120 | return bytes2read; | ||
121 | } | ||
122 | |||
123 | return (mpc_uint32_t) -1; | ||
124 | } | ||
125 | |||
126 | /** | ||
127 | * seek to a bit position in the stream | ||
128 | * @param d demuxer context | ||
129 | * @param fpos position in the stream in bits from the beginning of mpc datas | ||
130 | * @param min_bytes number of bytes to load after seeking | ||
131 | */ | ||
132 | static void | ||
133 | mpc_demux_seek(mpc_demux * d, mpc_seek_t fpos, mpc_uint32_t min_bytes) { | ||
134 | mpc_seek_t next_pos; | ||
135 | mpc_int_t bit_offset; | ||
136 | |||
137 | // FIXME : do not flush the buffer if fpos is in the current buffer | ||
138 | |||
139 | next_pos = fpos >> 3; | ||
140 | if (d->si.stream_version == 7) | ||
141 | next_pos = ((next_pos - d->si.header_position) & (-1 << 2)) + d->si.header_position; | ||
142 | bit_offset = (int) (fpos - (next_pos << 3)); | ||
143 | |||
144 | d->r->seek(d->r, (mpc_int32_t) next_pos); | ||
145 | mpc_demux_clear_buff(d); | ||
146 | if (d->si.stream_version == 7) | ||
147 | mpc_demux_fill(d, (min_bytes + ((bit_offset + 7) >> 3) + 3) & (~3), MPC_BUFFER_SWAP); | ||
148 | else | ||
149 | mpc_demux_fill(d, min_bytes + ((bit_offset + 7) >> 3), 0); | ||
150 | d->bits_reader.buff += bit_offset >> 3; | ||
151 | d->bits_reader.count = 8 - (bit_offset & 7); | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * return the current position in the stream (in bits) from the beginning | ||
156 | * of the file | ||
157 | * @param d demuxer context | ||
158 | * @return current stream position in bits | ||
159 | */ | ||
160 | mpc_seek_t mpc_demux_pos(mpc_demux * d) | ||
161 | { | ||
162 | return (((mpc_seek_t)(d->r->tell(d->r)) - d->bytes_total + | ||
163 | d->bits_reader.buff - d->buffer) << 3) + 8 - d->bits_reader.count; | ||
164 | } | ||
165 | |||
166 | /** | ||
167 | * Searches for a ID3v2-tag and reads the length (in bytes) of it. | ||
168 | * | ||
169 | * @param d demuxer context | ||
170 | * @return size of tag, in bytes | ||
171 | * @return MPC_STATUS_FILE on errors of any kind | ||
172 | */ | ||
173 | static mpc_int32_t mpc_demux_skip_id3v2(mpc_demux * d) | ||
174 | { | ||
175 | mpc_uint8_t tmp [4]; | ||
176 | mpc_bool_t footerPresent; // ID3v2.4-flag | ||
177 | mpc_int32_t size; | ||
178 | |||
179 | // we must be at the beginning of the stream | ||
180 | mpc_demux_fill(d, 3, 0); | ||
181 | |||
182 | // check id3-tag | ||
183 | if ( 0 != memcmp( d->bits_reader.buff, "ID3", 3 ) ) | ||
184 | return 0; | ||
185 | |||
186 | mpc_demux_fill(d, 10, 0); | ||
187 | |||
188 | mpc_bits_read(&d->bits_reader, 24); // read ID3 | ||
189 | mpc_bits_read(&d->bits_reader, 16); // read tag version | ||
190 | |||
191 | tmp[0] = mpc_bits_read(&d->bits_reader, 8); // read flags | ||
192 | footerPresent = tmp[0] & 0x10; | ||
193 | if ( tmp[0] & 0x0F ) | ||
194 | return MPC_STATUS_FILE; // not (yet???) allowed | ||
195 | |||
196 | tmp[0] = mpc_bits_read(&d->bits_reader, 8); // read size | ||
197 | tmp[1] = mpc_bits_read(&d->bits_reader, 8); // read size | ||
198 | tmp[2] = mpc_bits_read(&d->bits_reader, 8); // read size | ||
199 | tmp[3] = mpc_bits_read(&d->bits_reader, 8); // read size | ||
200 | |||
201 | if ( (tmp[0] | tmp[1] | tmp[2] | tmp[3]) & 0x80 ) | ||
202 | return MPC_STATUS_FILE; // not allowed | ||
203 | |||
204 | // read headerSize (syncsave: 4 * $0xxxxxxx = 28 significant bits) | ||
205 | size = tmp[0] << 21; | ||
206 | size |= tmp[1] << 14; | ||
207 | size |= tmp[2] << 7; | ||
208 | size |= tmp[3]; | ||
209 | |||
210 | size += 10; //header | ||
211 | |||
212 | if ( footerPresent ) size += 10; | ||
213 | |||
214 | // 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. | ||
215 | mpc_demux_clear_buff(d); | ||
216 | if (!d->r->seek(d->r, size)) return MPC_STATUS_FILE; | ||
217 | |||
218 | return size; | ||
219 | } | ||
220 | |||
221 | static mpc_status mpc_demux_seek_init(mpc_demux * d) | ||
222 | { | ||
223 | size_t seek_table_size; | ||
224 | if (d->seek_table != 0) | ||
225 | return MPC_STATUS_OK; | ||
226 | |||
227 | d->seek_pwr = 6; | ||
228 | if (d->si.block_pwr > d->seek_pwr) | ||
229 | d->seek_pwr = d->si.block_pwr; | ||
230 | seek_table_size = (2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)); | ||
231 | while (seek_table_size > MAX_SEEK_TABLE_SIZE) { | ||
232 | d->seek_pwr++; | ||
233 | seek_table_size = (2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr)); | ||
234 | } | ||
235 | d->seek_table = g_seek_table; | ||
236 | if (d->seek_table == 0) | ||
237 | return MPC_STATUS_FILE; | ||
238 | d->seek_table[0] = (mpc_seek_t)mpc_demux_pos(d); | ||
239 | d->seek_table_size = 1; | ||
240 | |||
241 | return MPC_STATUS_OK; | ||
242 | } | ||
243 | |||
244 | static void mpc_demux_ST(mpc_demux * d) | ||
245 | { | ||
246 | mpc_uint64_t tmp; | ||
247 | mpc_seek_t * table, last[2]; | ||
248 | mpc_bits_reader r = d->bits_reader; | ||
249 | mpc_uint_t i, diff_pwr = 0, mask; | ||
250 | mpc_uint32_t file_table_size; | ||
251 | |||
252 | if (d->seek_table != 0) | ||
253 | return; | ||
254 | |||
255 | mpc_bits_get_size(&r, &tmp); | ||
256 | file_table_size = (mpc_seek_t) tmp; | ||
257 | d->seek_pwr = d->si.block_pwr + mpc_bits_read(&r, 4); | ||
258 | |||
259 | tmp = 2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr); | ||
260 | while (tmp > MAX_SEEK_TABLE_SIZE) { | ||
261 | d->seek_pwr++; | ||
262 | diff_pwr++; | ||
263 | tmp = 2 + d->si.samples / (MPC_FRAME_LENGTH << d->seek_pwr); | ||
264 | } | ||
265 | if ((file_table_size >> diff_pwr) > tmp) | ||
266 | file_table_size = tmp << diff_pwr; | ||
267 | d->seek_table = g_seek_table; | ||
268 | d->seek_table_size = (file_table_size + ((1 << diff_pwr) - 1)) >> diff_pwr; | ||
269 | |||
270 | table = d->seek_table; | ||
271 | mpc_bits_get_size(&r, &tmp); | ||
272 | table[0] = last[0] = (mpc_seek_t) (tmp + d->si.header_position) * 8; | ||
273 | |||
274 | if (d->seek_table_size == 1) | ||
275 | return; | ||
276 | |||
277 | mpc_bits_get_size(&r, &tmp); | ||
278 | last[1] = (mpc_seek_t) (tmp + d->si.header_position) * 8; | ||
279 | if (diff_pwr == 0) table[1] = last[1]; | ||
280 | |||
281 | mask = (1 << diff_pwr) - 1; | ||
282 | for (i = 2; i < file_table_size; i++) { | ||
283 | int code = mpc_bits_golomb_dec(&r, 12); | ||
284 | if (code & 1) | ||
285 | code = -(code & (-1 << 1)); | ||
286 | code <<= 2; | ||
287 | last[i & 1] = code + 2 * last[(i-1) & 1] - last[i & 1]; | ||
288 | if ((i & mask) == 0) | ||
289 | table[i >> diff_pwr] = last[i & 1]; | ||
290 | } | ||
291 | } | ||
292 | |||
293 | static void mpc_demux_SP(mpc_demux * d, int size, int block_size) | ||
294 | { | ||
295 | mpc_seek_t cur; | ||
296 | mpc_uint64_t ptr; | ||
297 | mpc_block b; | ||
298 | int st_head_size; | ||
299 | |||
300 | cur = mpc_demux_pos(d); | ||
301 | mpc_bits_get_size(&d->bits_reader, &ptr); | ||
302 | mpc_demux_seek(d, (ptr - size) * 8 + cur, 11); | ||
303 | st_head_size = mpc_bits_get_block(&d->bits_reader, &b); | ||
304 | if (memcmp(b.key, "ST", 2) == 0) { | ||
305 | d->chap_pos = (ptr - size + b.size + st_head_size) * 8 + cur; | ||
306 | d->chap_nb = -1; | ||
307 | mpc_demux_fill(d, (mpc_uint32_t) b.size, 0); | ||
308 | mpc_demux_ST(d); | ||
309 | } | ||
310 | mpc_demux_seek(d, cur, 11 + block_size); | ||
311 | } | ||
312 | /* rockbox: not used | ||
313 | static void mpc_demux_chap_find(mpc_demux * d) | ||
314 | { | ||
315 | mpc_block b; | ||
316 | int tag_size = 0, chap_size = 0, size, i = 0; | ||
317 | |||
318 | d->chap_nb = 0; | ||
319 | |||
320 | if (d->si.stream_version < 8) | ||
321 | return; | ||
322 | |||
323 | if (d->chap_pos == 0) { | ||
324 | mpc_uint64_t cur_pos = (d->si.header_position + 4) * 8; | ||
325 | mpc_demux_seek(d, cur_pos, 11); // seek to the beginning of the stream | ||
326 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
327 | while (memcmp(b.key, "SE", 2) != 0) { | ||
328 | if (mpc_check_key(b.key) != MPC_STATUS_OK) | ||
329 | return; | ||
330 | if (memcmp(b.key, "CT", 2) == 0) { | ||
331 | if (d->chap_pos == 0) d->chap_pos = cur_pos; | ||
332 | } else | ||
333 | d->chap_pos = 0; | ||
334 | cur_pos += (size + b.size) * 8; | ||
335 | mpc_demux_seek(d, cur_pos, 11); | ||
336 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
337 | } | ||
338 | if (d->chap_pos == 0) | ||
339 | d->chap_pos = cur_pos; | ||
340 | } | ||
341 | |||
342 | mpc_demux_seek(d, d->chap_pos, 20); | ||
343 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
344 | while (memcmp(b.key, "CT", 2) == 0) { | ||
345 | mpc_uint64_t chap_sample; | ||
346 | d->chap_nb++; | ||
347 | chap_size += size; | ||
348 | size = mpc_bits_get_size(&d->bits_reader, &chap_sample) + 4; | ||
349 | chap_size += size; | ||
350 | tag_size += b.size - size; | ||
351 | mpc_demux_seek(d, d->chap_pos + (chap_size + tag_size) * 8, 20); | ||
352 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
353 | } | ||
354 | |||
355 | if (d->chap_nb > 0) { | ||
356 | char * ptag; | ||
357 | d->chap = malloc(sizeof(mpc_chap_info) * d->chap_nb + tag_size); | ||
358 | ptag = (char*)(d->chap + d->chap_nb); | ||
359 | |||
360 | mpc_demux_seek(d, d->chap_pos, 11); | ||
361 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
362 | while (memcmp(b.key, "CT", 2) == 0) { | ||
363 | mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0); | ||
364 | size = mpc_bits_get_size(&d->bits_reader, &d->chap[i].sample) + 4; | ||
365 | d->chap[i].gain = (mpc_uint16_t) mpc_bits_read(&d->bits_reader, 16); | ||
366 | d->chap[i].peak = (mpc_uint16_t) mpc_bits_read(&d->bits_reader, 16); | ||
367 | memcpy(ptag, d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3), b.size - size); | ||
368 | d->bits_reader.buff += b.size - size; | ||
369 | d->chap[i].tag_size = b.size - size; | ||
370 | d->chap[i].tag = ptag; | ||
371 | ptag += b.size - size; | ||
372 | i++; | ||
373 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
374 | } | ||
375 | } | ||
376 | |||
377 | d->bits_reader.buff -= size; | ||
378 | } | ||
379 | */ | ||
380 | |||
381 | /** | ||
382 | * Gets the number of chapters in the stream | ||
383 | * @param d pointer to a musepack demuxer | ||
384 | * @return the number of chapters found in the stream | ||
385 | */ | ||
386 | /* rockbox: not used | ||
387 | mpc_int_t mpc_demux_chap_nb(mpc_demux * d) | ||
388 | { | ||
389 | if (d->chap_nb == -1) | ||
390 | mpc_demux_chap_find(d); | ||
391 | return d->chap_nb; | ||
392 | } | ||
393 | */ | ||
394 | /** | ||
395 | * Gets datas associated to a given chapter | ||
396 | * The chapter tag is an APEv2 tag without the preamble | ||
397 | * @param d pointer to a musepack demuxer | ||
398 | * @param chap_nb chapter number you want datas (from 0 to mpc_demux_chap_nb(d) - 1) | ||
399 | * @return the chapter information structure | ||
400 | */ | ||
401 | /* rockbox: not used | ||
402 | mpc_chap_info const * mpc_demux_chap(mpc_demux * d, int chap_nb) | ||
403 | { | ||
404 | if (d->chap_nb == -1) | ||
405 | mpc_demux_chap_find(d); | ||
406 | if (chap_nb >= d->chap_nb || chap_nb < 0) | ||
407 | return 0; | ||
408 | return &d->chap[chap_nb]; | ||
409 | } | ||
410 | */ | ||
411 | |||
412 | static mpc_status mpc_demux_header(mpc_demux * d) | ||
413 | { | ||
414 | char magic[4]; | ||
415 | |||
416 | d->si.pns = 0xFF; | ||
417 | /* rockbox: not used | ||
418 | d->si.profile_name = "n.a."; | ||
419 | */ | ||
420 | // get header position | ||
421 | d->si.header_position = mpc_demux_skip_id3v2(d); | ||
422 | if(d->si.header_position < 0) return MPC_STATUS_FILE; | ||
423 | |||
424 | d->si.tag_offset = d->si.total_file_length = d->r->get_size(d->r); | ||
425 | |||
426 | mpc_demux_fill(d, 4, 0); | ||
427 | magic[0] = mpc_bits_read(&d->bits_reader, 8); | ||
428 | magic[1] = mpc_bits_read(&d->bits_reader, 8); | ||
429 | magic[2] = mpc_bits_read(&d->bits_reader, 8); | ||
430 | magic[3] = mpc_bits_read(&d->bits_reader, 8); | ||
431 | |||
432 | if (memcmp(magic, "MP+", 3) == 0) { | ||
433 | d->si.stream_version = magic[3] & 15; | ||
434 | d->si.pns = magic[3] >> 4; | ||
435 | if (d->si.stream_version == 7) { | ||
436 | mpc_status ret; | ||
437 | mpc_demux_fill(d, 6 * 4, MPC_BUFFER_SWAP); // header block size + endian convertion | ||
438 | ret = streaminfo_read_header_sv7(&d->si, &d->bits_reader); | ||
439 | if (ret != MPC_STATUS_OK) return ret; | ||
440 | } else { | ||
441 | return MPC_STATUS_INVALIDSV; | ||
442 | } | ||
443 | } else if (memcmp(magic, "MPCK", 4) == 0) { | ||
444 | mpc_block b; | ||
445 | int size; | ||
446 | mpc_demux_fill(d, 11, 0); // max header block size | ||
447 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
448 | while( memcmp(b.key, "AP", 2) != 0 ){ // scan all blocks until audio | ||
449 | if (mpc_check_key(b.key) != MPC_STATUS_OK) | ||
450 | return MPC_STATUS_INVALIDSV; | ||
451 | if (b.size > (mpc_uint64_t) DEMUX_BUFFER_SIZE - 11) | ||
452 | return MPC_STATUS_INVALIDSV; | ||
453 | mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0); | ||
454 | if (memcmp(b.key, "SH", 2) == 0){ | ||
455 | int ret = streaminfo_read_header_sv8(&d->si, &d->bits_reader, (mpc_uint32_t) b.size); | ||
456 | if (ret != MPC_STATUS_OK) return ret; | ||
457 | } else if (memcmp(b.key, "RG", 2) == 0) | ||
458 | streaminfo_gain(&d->si, &d->bits_reader); | ||
459 | else if (memcmp(b.key, "EI", 2) == 0) | ||
460 | streaminfo_encoder_info(&d->si, &d->bits_reader); | ||
461 | else if (memcmp(b.key, "SO", 2) == 0) | ||
462 | mpc_demux_SP(d, size, (mpc_uint32_t) b.size); | ||
463 | else if (memcmp(b.key, "ST", 2) == 0) | ||
464 | mpc_demux_ST(d); | ||
465 | d->bits_reader.buff += b.size; | ||
466 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
467 | } | ||
468 | d->bits_reader.buff -= size; | ||
469 | if (d->si.stream_version == 0) // si not initialized !!! | ||
470 | return MPC_STATUS_INVALIDSV; | ||
471 | } else | ||
472 | return MPC_STATUS_INVALIDSV; | ||
473 | |||
474 | return MPC_STATUS_OK; | ||
475 | } | ||
476 | |||
477 | mpc_demux * mpc_demux_init(mpc_reader * p_reader) | ||
478 | { | ||
479 | mpc_demux* p_tmp = &g_mpc_demux; | ||
480 | |||
481 | if (p_tmp != 0) { | ||
482 | memset(p_tmp, 0, sizeof(mpc_demux)); | ||
483 | p_tmp->buffer = g_buffer; | ||
484 | p_tmp->r = p_reader; | ||
485 | p_tmp->chap_nb = -1; | ||
486 | mpc_demux_clear_buff(p_tmp); | ||
487 | if (mpc_demux_header(p_tmp) == MPC_STATUS_OK && | ||
488 | mpc_demux_seek_init(p_tmp) == MPC_STATUS_OK) { | ||
489 | p_tmp->d = mpc_decoder_init(&p_tmp->si); | ||
490 | } else { | ||
491 | if (p_tmp->seek_table) | ||
492 | memset(p_tmp->seek_table, 0, sizeof(g_seek_table)); | ||
493 | p_tmp = 0; | ||
494 | } | ||
495 | } | ||
496 | |||
497 | return p_tmp; | ||
498 | } | ||
499 | |||
500 | void mpc_demux_exit(mpc_demux * d) | ||
501 | { | ||
502 | mpc_decoder_exit(d->d); | ||
503 | memset(d->seek_table, 0, sizeof(g_seek_table)); | ||
504 | } | ||
505 | |||
506 | void mpc_demux_get_info(mpc_demux * d, mpc_streaminfo * i) | ||
507 | { | ||
508 | memcpy(i, &d->si, sizeof d->si); | ||
509 | } | ||
510 | |||
511 | mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i) | ||
512 | { | ||
513 | mpc_bits_reader r; | ||
514 | if (d->si.stream_version >= 8) { | ||
515 | i->is_key_frame = MPC_FALSE; | ||
516 | |||
517 | if (d->block_frames == 0) { | ||
518 | mpc_block b = {{0,0},0}; | ||
519 | d->bits_reader.count &= -8; | ||
520 | if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { | ||
521 | d->seek_table[d->seek_table_size] = (mpc_seek_t) mpc_demux_pos(d); | ||
522 | d->seek_table_size ++; | ||
523 | } | ||
524 | mpc_demux_fill(d, 11, 0); // max header block size | ||
525 | mpc_bits_get_block(&d->bits_reader, &b); | ||
526 | while( memcmp(b.key, "AP", 2) != 0 ) { // scan all blocks until audio | ||
527 | if (mpc_check_key(b.key) != MPC_STATUS_OK) | ||
528 | goto error; | ||
529 | if (memcmp(b.key, "SE", 2) == 0) { // end block | ||
530 | i->bits = -1; | ||
531 | return MPC_STATUS_OK; | ||
532 | } | ||
533 | if (mpc_demux_fill(d, 11 + (mpc_uint32_t) b.size, 0) == 0) | ||
534 | goto error; | ||
535 | d->bits_reader.buff += b.size; | ||
536 | mpc_bits_get_block(&d->bits_reader, &b); | ||
537 | } | ||
538 | d->block_bits = (mpc_uint32_t) b.size * 8; | ||
539 | d->block_frames = 1 << d->si.block_pwr; | ||
540 | i->is_key_frame = MPC_TRUE; | ||
541 | } | ||
542 | if (d->buffer + d->bytes_total - d->bits_reader.buff <= MAX_FRAME_SIZE) | ||
543 | mpc_demux_fill(d, (d->block_bits >> 3) + 1, 0); | ||
544 | r = d->bits_reader; | ||
545 | mpc_decoder_decode_frame(d->d, &d->bits_reader, i); | ||
546 | d->block_bits -= ((d->bits_reader.buff - r.buff) << 3) + r.count - d->bits_reader.count; | ||
547 | d->block_frames--; | ||
548 | if (d->block_bits < 0 || (d->block_frames == 0 && d->block_bits > 7)) | ||
549 | goto error; | ||
550 | } else { | ||
551 | if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { | ||
552 | d->seek_table[d->seek_table_size] = (mpc_seek_t) mpc_demux_pos(d); | ||
553 | d->seek_table_size ++; | ||
554 | } | ||
555 | mpc_demux_fill(d, MAX_FRAME_SIZE, MPC_BUFFER_FULL | MPC_BUFFER_SWAP); | ||
556 | d->block_bits = (mpc_int_t) mpc_bits_read(&d->bits_reader, 20); // read frame size | ||
557 | if (MPC_FRAME_LENGTH > d->d->samples - d->d->decoded_samples - 1) d->block_bits += 11; // we will read last frame size | ||
558 | r = d->bits_reader; | ||
559 | mpc_decoder_decode_frame(d->d, &d->bits_reader, i); | ||
560 | if (i->bits != -1 && d->block_bits != (mpc_int32_t)(((d->bits_reader.buff - r.buff) << 3) + r.count - d->bits_reader.count)) | ||
561 | goto error; | ||
562 | } | ||
563 | if (i->bits != -1 && d->buffer + d->bytes_total < d->bits_reader.buff + ((8 - d->bits_reader.count) >> 3)) | ||
564 | goto error; | ||
565 | |||
566 | return MPC_STATUS_OK; | ||
567 | error: | ||
568 | i->bits = -1; // we pretend it's end of file | ||
569 | return MPC_STATUS_INVALIDSV; | ||
570 | } | ||
571 | |||
572 | mpc_status mpc_demux_seek_second(mpc_demux * d, double seconds) | ||
573 | { | ||
574 | return mpc_demux_seek_sample(d, (mpc_int64_t)(seconds * (double)d->si.sample_freq + 0.5)); | ||
575 | } | ||
576 | |||
577 | mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample) | ||
578 | { | ||
579 | mpc_uint32_t fwd, samples_to_skip, i; | ||
580 | mpc_uint32_t block_samples = MPC_FRAME_LENGTH << d->si.block_pwr; | ||
581 | mpc_seek_t fpos; | ||
582 | |||
583 | destsample += d->si.beg_silence; | ||
584 | if (destsample > d->si.samples) destsample = d->si.samples; | ||
585 | fwd = (mpc_uint32_t) (destsample / block_samples); | ||
586 | samples_to_skip = MPC_DECODER_SYNTH_DELAY + | ||
587 | (mpc_uint32_t) (destsample % block_samples); | ||
588 | if (d->si.stream_version == 7) { | ||
589 | if (fwd > 32) { | ||
590 | fwd -= 32; | ||
591 | samples_to_skip += MPC_FRAME_LENGTH * 32; | ||
592 | } else { | ||
593 | samples_to_skip += MPC_FRAME_LENGTH * fwd; | ||
594 | fwd = 0; | ||
595 | } | ||
596 | } | ||
597 | |||
598 | i = fwd >> (d->seek_pwr - d->si.block_pwr); | ||
599 | if (i >= d->seek_table_size) | ||
600 | i = d->seek_table_size - 1; | ||
601 | fpos = d->seek_table[i]; | ||
602 | i <<= d->seek_pwr - d->si.block_pwr; | ||
603 | d->d->decoded_samples = i * block_samples; | ||
604 | |||
605 | if (d->si.stream_version >= 8) { | ||
606 | mpc_block b; | ||
607 | int size; | ||
608 | mpc_demux_seek(d, fpos, 11); | ||
609 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
610 | while(i < fwd) { | ||
611 | if (memcmp(b.key, "AP", 2) == 0) { | ||
612 | if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { | ||
613 | d->seek_table[d->seek_table_size] = (mpc_seek_t) mpc_demux_pos(d) - 8 * size; | ||
614 | d->seek_table_size ++; | ||
615 | } | ||
616 | d->d->decoded_samples += block_samples; | ||
617 | i++; | ||
618 | } | ||
619 | fpos += ((mpc_uint32_t)b.size + size) * 8; | ||
620 | mpc_demux_seek(d, fpos, 11); | ||
621 | size = mpc_bits_get_block(&d->bits_reader, &b); | ||
622 | } | ||
623 | d->bits_reader.buff -= size; | ||
624 | } else { | ||
625 | mpc_decoder_reset_scf(d->d, fwd != 0); | ||
626 | mpc_demux_seek(d, fpos, 4); | ||
627 | for( ; i < fwd; i++){ | ||
628 | if (d->d->decoded_samples == (d->seek_table_size << d->seek_pwr) * MPC_FRAME_LENGTH) { | ||
629 | d->seek_table[d->seek_table_size] = (mpc_seek_t) mpc_demux_pos(d); | ||
630 | d->seek_table_size ++; | ||
631 | } | ||
632 | d->d->decoded_samples += block_samples; | ||
633 | fpos += mpc_bits_read(&d->bits_reader, 20) + 20; | ||
634 | mpc_demux_seek(d, fpos, 4); | ||
635 | } | ||
636 | } | ||
637 | d->d->samples_to_skip = samples_to_skip; | ||
638 | return MPC_STATUS_OK; | ||
639 | } | ||
640 | |||
641 | /* rockbox: not used | ||
642 | void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain, | ||
643 | mpc_bool_t use_title, mpc_bool_t clip_prevention) | ||
644 | { | ||
645 | float peak = use_title ? d->si.peak_title : d->si.peak_album; | ||
646 | float gain = use_title ? d->si.gain_title : d->si.gain_album; | ||
647 | |||
648 | if(!use_gain && !clip_prevention) | ||
649 | return; | ||
650 | |||
651 | if(!peak) | ||
652 | peak = 1.; | ||
653 | else | ||
654 | peak = (1 << 15) / pow(10, peak / (20 * 256)); | ||
655 | |||
656 | if(!gain) | ||
657 | gain = 1.; | ||
658 | else | ||
659 | gain = pow(10, (level - gain / 256) / 20); | ||
660 | |||
661 | if(clip_prevention && (peak < gain || !use_gain)) | ||
662 | gain = peak; | ||
663 | |||
664 | mpc_decoder_scale_output(d->d, gain); | ||
665 | } | ||
666 | */ | ||
diff --git a/apps/codecs/libmusepack/mpc_types.h b/apps/codecs/libmusepack/mpc_types.h new file mode 100755 index 0000000000..61ee5ea67f --- /dev/null +++ b/apps/codecs/libmusepack/mpc_types.h | |||
@@ -0,0 +1,148 @@ | |||
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 <memory.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 | MPC_STATUS_OK = 0, | ||
92 | MPC_STATUS_FILE = -1, | ||
93 | MPC_STATUS_SV7BETA = -2, | ||
94 | MPC_STATUS_CBR = -3, | ||
95 | MPC_STATUS_IS = -4, | ||
96 | MPC_STATUS_BLOCKSIZE = -5, | ||
97 | MPC_STATUS_INVALIDSV = -6 | ||
98 | } mpc_status; | ||
99 | |||
100 | #define MPC_FIXED_POINT | ||
101 | #define MPC_FIXED_POINT_SHIFT 16 | ||
102 | |||
103 | #ifdef MPC_FIXED_POINT | ||
104 | # define MPC_FIXED_POINT_FRACTPART 14 | ||
105 | # define MPC_FIXED_POINT_SCALE_SHIFT (MPC_FIXED_POINT_SHIFT + MPC_FIXED_POINT_FRACTPART) | ||
106 | # define MPC_FIXED_POINT_SCALE (1 << (MPC_FIXED_POINT_SCALE_SHIFT - 1)) | ||
107 | typedef mpc_int32_t MPC_SAMPLE_FORMAT; | ||
108 | #else | ||
109 | typedef float MPC_SAMPLE_FORMAT; | ||
110 | #endif | ||
111 | |||
112 | enum { | ||
113 | MPC_FALSE = 0, | ||
114 | MPC_TRUE = !MPC_FALSE | ||
115 | }; | ||
116 | |||
117 | //// 'Cdecl' forces the use of standard C/C++ calling convention /////// | ||
118 | #if defined _WIN32 | ||
119 | # define mpc_cdecl __cdecl | ||
120 | #elif defined __ZTC__ | ||
121 | # define mpc_cdecl _cdecl | ||
122 | #elif defined __TURBOC__ | ||
123 | # define mpc_cdecl cdecl | ||
124 | #else | ||
125 | # define mpc_cdecl | ||
126 | #endif | ||
127 | |||
128 | /* DLL building support on win32 hosts */ | ||
129 | #ifndef MPC_API | ||
130 | # ifdef DLL_EXPORT /* defined by libtool (if required) */ | ||
131 | # define MPC_API __declspec(dllexport) | ||
132 | # endif | ||
133 | # ifdef MPC_DLL_IMPORT /* define if linking with this dll */ | ||
134 | # define MPC_API __declspec(dllimport) | ||
135 | # endif | ||
136 | # ifndef MPC_API /* static linking or !_WIN32 */ | ||
137 | # if defined(__GNUC__) && (__GNUC__ >= 4) | ||
138 | # define MPC_API __attribute__ ((visibility("default"))) | ||
139 | # else | ||
140 | # define MPC_API | ||
141 | # endif | ||
142 | # endif | ||
143 | #endif | ||
144 | |||
145 | #ifdef __cplusplus | ||
146 | } | ||
147 | #endif | ||
148 | #endif | ||
diff --git a/apps/codecs/libmusepack/mpcdec.h b/apps/codecs/libmusepack/mpcdec.h new file mode 100755 index 0000000000..a359951745 --- /dev/null +++ b/apps/codecs/libmusepack/mpcdec.h | |||
@@ -0,0 +1,186 @@ | |||
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 | #ifndef IBSS_ATTR_MPC_LARGE_IRAM | ||
51 | #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250) | ||
52 | /* PP5022/24 and MCF5250 have 128KB of IRAM */ | ||
53 | #define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR | ||
54 | #else | ||
55 | /* other PP's and MCF5249 have 96KB of IRAM */ | ||
56 | #define IBSS_ATTR_MPC_LARGE_IRAM | ||
57 | #endif | ||
58 | #endif | ||
59 | |||
60 | #ifndef ICODE_ATTR_MPC_LARGE_IRAM | ||
61 | #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) | ||
62 | /* PP5022/24 have 128KB of IRAM and have better performance with ICODE_ATTR */ | ||
63 | #define ICODE_ATTR_MPC_LARGE_IRAM ICODE_ATTR | ||
64 | #else | ||
65 | /* all other targets either haven't enough IRAM or performance suffers */ | ||
66 | #define ICODE_ATTR_MPC_LARGE_IRAM | ||
67 | #endif | ||
68 | #endif | ||
69 | |||
70 | #ifndef ICONST_ATTR_MPC_LARGE_IRAM | ||
71 | #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250) | ||
72 | /* PP5022/24 and MCF5250 have 128KB of IRAM */ | ||
73 | #define ICONST_ATTR_MPC_LARGE_IRAM ICONST_ATTR | ||
74 | #else | ||
75 | /* other PP's and MCF5249 have 96KB of IRAM */ | ||
76 | #define ICONST_ATTR_MPC_LARGE_IRAM | ||
77 | #endif | ||
78 | #endif | ||
79 | |||
80 | enum { | ||
81 | MPC_FRAME_LENGTH = (36 * 32), ///< Samples per mpc frame | ||
82 | MPC_DECODER_BUFFER_LENGTH = (MPC_FRAME_LENGTH * 2), ///< Required buffer size for decoder (2 channels) | ||
83 | MPC_DECODER_SYNTH_DELAY = 481 | ||
84 | }; | ||
85 | |||
86 | typedef struct mpc_decoder_t mpc_decoder; | ||
87 | typedef struct mpc_demux_t mpc_demux; | ||
88 | |||
89 | typedef struct mpc_bits_reader_t { | ||
90 | unsigned char * buff; /// pointer on current byte | ||
91 | unsigned int count; /// unread bits in current byte | ||
92 | mpc_uint8_t *buffered_addr; /// used for rockbox Coldfire optimization only | ||
93 | mpc_uint32_t buffered_code; /// used for rockbox Coldfire optimization only | ||
94 | } mpc_bits_reader; | ||
95 | |||
96 | typedef struct mpc_frame_info_t { | ||
97 | mpc_uint32_t samples; /// number of samples in the frame (counting once for multiple channels) | ||
98 | mpc_int32_t bits; /// number of bits consumed by this frame (-1) if end of stream | ||
99 | MPC_SAMPLE_FORMAT * buffer; /// frame samples buffer (size = samples * channels * sizeof(MPC_SAMPLE_FORMAT)) | ||
100 | mpc_bool_t is_key_frame; /// 1 if this frame is a key frame (first in block) 0 else. Set by the demuxer. | ||
101 | } mpc_frame_info; | ||
102 | |||
103 | typedef struct mpc_chap_info_t { | ||
104 | mpc_uint64_t sample; /// sample where the chapter starts | ||
105 | mpc_uint16_t gain; /// replaygain chapter value | ||
106 | mpc_uint16_t peak; /// peak chapter loudness level | ||
107 | mpc_uint_t tag_size; /// size of the tag element (0 if no tag is present for this chapter) | ||
108 | char * tag; /// pointer to an APEv2 tag without the preamble | ||
109 | } mpc_chap_info; | ||
110 | |||
111 | /// Initializes mpc decoder with the supplied stream info parameters. | ||
112 | /// \param si streaminfo structure indicating format of source stream | ||
113 | /// \return pointer on the initialized decoder structure if successful, 0 if not | ||
114 | MPC_API mpc_decoder * mpc_decoder_init(mpc_streaminfo *si); | ||
115 | |||
116 | /// Releases input mpc decoder | ||
117 | MPC_API void mpc_decoder_exit(mpc_decoder *p_dec); | ||
118 | |||
119 | /** | ||
120 | * Sets decoder sample scaling factor. All decoded samples will be multiplied | ||
121 | * by this factor. Useful for applying replay gain. | ||
122 | * @param scale_factor multiplicative scaling factor | ||
123 | */ | ||
124 | MPC_API void mpc_decoder_scale_output(mpc_decoder *p_dec, double scale_factor); | ||
125 | |||
126 | MPC_API void mpc_decoder_decode_frame(mpc_decoder * d, mpc_bits_reader * r, mpc_frame_info * i); | ||
127 | |||
128 | // This is the gain reference used in old replaygain | ||
129 | #define MPC_OLD_GAIN_REF 64.82 | ||
130 | |||
131 | /** | ||
132 | * init demuxer | ||
133 | * @param p_reader initialized mpc_reader pointer | ||
134 | * @return an initialized mpc_demux pointer | ||
135 | */ | ||
136 | MPC_API mpc_demux * mpc_demux_init(mpc_reader * p_reader); | ||
137 | /// free demuxer | ||
138 | MPC_API void mpc_demux_exit(mpc_demux * d); | ||
139 | /** | ||
140 | * Calls mpc_decoder_scale_output to set the scaling factor according to the | ||
141 | * replay gain stream information and the supplied ouput level | ||
142 | * @param d pointer to a musepack demuxer | ||
143 | * @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 | ||
144 | * @param use_gain set it to MPC_TRUE if you want to set the scaling factor according to the stream gain | ||
145 | * @param use_title MPC_TRUE : uses the title gain, MPC_FALSE : uses the album gain | ||
146 | * @param clip_prevention MPC_TRUE : uses cliping prevention | ||
147 | */ | ||
148 | /* rockbox: not used | ||
149 | MPC_API void mpc_set_replay_level(mpc_demux * d, float level, mpc_bool_t use_gain, | ||
150 | mpc_bool_t use_title, mpc_bool_t clip_prevention); | ||
151 | */ | ||
152 | /// decode frame | ||
153 | MPC_API mpc_status mpc_demux_decode(mpc_demux * d, mpc_frame_info * i); | ||
154 | /// get streaminfo | ||
155 | MPC_API void mpc_demux_get_info(mpc_demux * d, mpc_streaminfo * i); | ||
156 | /// seeks to a given sample | ||
157 | MPC_API mpc_status mpc_demux_seek_sample(mpc_demux * d, mpc_uint64_t destsample); | ||
158 | /// seeks to a given second | ||
159 | MPC_API mpc_status mpc_demux_seek_second(mpc_demux * d, double seconds); | ||
160 | |||
161 | /// \return the current position in the stream (in bits) from the beginning of the file | ||
162 | MPC_API mpc_seek_t mpc_demux_pos(mpc_demux * d); | ||
163 | |||
164 | /// chapters : only for sv8 streams | ||
165 | /** | ||
166 | * Gets the number of chapters in the stream | ||
167 | * @param d pointer to a musepack demuxer | ||
168 | * @return the number of chapters found in the stream | ||
169 | */ | ||
170 | /* rockbox: not used | ||
171 | MPC_API mpc_int_t mpc_demux_chap_nb(mpc_demux * d); | ||
172 | */ | ||
173 | /** | ||
174 | * Gets datas associated to a given chapter | ||
175 | * The chapter tag is an APEv2 tag without the preamble | ||
176 | * @param d pointer to a musepack demuxer | ||
177 | * @param chap_nb chapter number you want datas (from 0 to mpc_demux_chap_nb(d) - 1) | ||
178 | * @return the chapter information structure | ||
179 | */ | ||
180 | /* rockbox: not used | ||
181 | MPC_API mpc_chap_info const * mpc_demux_chap(mpc_demux * d, int chap_nb); | ||
182 | */ | ||
183 | #ifdef __cplusplus | ||
184 | } | ||
185 | #endif | ||
186 | #endif | ||
diff --git a/apps/codecs/libmusepack/math.h b/apps/codecs/libmusepack/mpcdec_math.h index e4c2ffce20..55295dba32 100644..100755 --- a/apps/codecs/libmusepack/math.h +++ b/apps/codecs/libmusepack/mpcdec_math.h | |||
@@ -38,7 +38,7 @@ | |||
38 | #ifndef _mpcdec_math_h_ | 38 | #ifndef _mpcdec_math_h_ |
39 | #define _mpcdec_math_h_ | 39 | #define _mpcdec_math_h_ |
40 | 40 | ||
41 | #include "mpc_config.h" | 41 | #include "mpc_types.h" |
42 | 42 | ||
43 | #define MPC_FIXED_POINT_SHIFT 16 | 43 | #define MPC_FIXED_POINT_SHIFT 16 |
44 | 44 | ||
@@ -48,15 +48,9 @@ | |||
48 | #include <cmnintrin.h> | 48 | #include <cmnintrin.h> |
49 | #define MPC_HAVE_MULHIGH | 49 | #define MPC_HAVE_MULHIGH |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | #define MPC_FIXED_POINT_SCALE_SHIFT (MPC_FIXED_POINT_SHIFT + MPC_FIXED_POINT_FRACTPART) | ||
53 | #define MPC_FIXED_POINT_SCALE (1 << (MPC_FIXED_POINT_SCALE_SHIFT - 1)) | ||
54 | //in fixedpoint mode, results in decode output buffer are in -MPC_FIXED_POINT_SCALE ... MPC_FIXED_POINT_SCALE range | ||
55 | |||
56 | #define MPC_FIXED_POINT_FRACTPART 14 | ||
57 | typedef mpc_int32_t MPC_SAMPLE_FORMAT; | ||
58 | typedef mpc_int64_t MPC_SAMPLE_FORMAT_MULTIPLY; | 52 | typedef mpc_int64_t MPC_SAMPLE_FORMAT_MULTIPLY; |
59 | 53 | ||
60 | #define MAKE_MPC_SAMPLE(X) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<MPC_FIXED_POINT_FRACTPART)) | 54 | #define MAKE_MPC_SAMPLE(X) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<MPC_FIXED_POINT_FRACTPART)) |
61 | #define MAKE_MPC_SAMPLE_EX(X,Y) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<(Y))) | 55 | #define MAKE_MPC_SAMPLE_EX(X,Y) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)<<(Y))) |
62 | 56 | ||
diff --git a/apps/codecs/libmusepack/musepack.h b/apps/codecs/libmusepack/musepack.h deleted file mode 100644 index 1c98de654b..0000000000 --- a/apps/codecs/libmusepack/musepack.h +++ /dev/null | |||
@@ -1,163 +0,0 @@ | |||
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 mpcdec.h | ||
36 | /// Top level include file for libmpcdec. | ||
37 | |||
38 | #ifndef _mpcdec_h_ | ||
39 | #define _mpcdec_h_ | ||
40 | |||
41 | #ifdef __cplusplus | ||
42 | extern "C" { | ||
43 | #endif | ||
44 | |||
45 | //#include <stdlib.h> | ||
46 | #include <string.h> | ||
47 | |||
48 | #ifndef SIMULATOR | ||
49 | #include "codecs.h" | ||
50 | #endif | ||
51 | #include "config_types.h" | ||
52 | #include "decoder.h" | ||
53 | #include "math.h" | ||
54 | #include "reader.h" | ||
55 | #include "streaminfo.h" | ||
56 | |||
57 | #ifndef IBSS_ATTR_MPC_SAMPLE_BUF | ||
58 | #define IBSS_ATTR_MPC_SAMPLE_BUF IBSS_ATTR | ||
59 | #endif | ||
60 | |||
61 | #ifndef IBSS_ATTR_MPC_LARGE_IRAM | ||
62 | #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250) | ||
63 | /* PP5022/24 and MCF5250 have 128KB of IRAM */ | ||
64 | #define IBSS_ATTR_MPC_LARGE_IRAM IBSS_ATTR | ||
65 | #else | ||
66 | /* other PP's and MCF5249 have 96KB of IRAM */ | ||
67 | #define IBSS_ATTR_MPC_LARGE_IRAM | ||
68 | #endif | ||
69 | #endif | ||
70 | |||
71 | #ifndef ICODE_ATTR_MPC_LARGE_IRAM | ||
72 | #if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) | ||
73 | /* PP5022/24 have 128KB of IRAM and have better performance with ICODE_ATTR */ | ||
74 | #define ICODE_ATTR_MPC_LARGE_IRAM ICODE_ATTR | ||
75 | #else | ||
76 | /* all other targets either haven't enough IRAM or performance suffers */ | ||
77 | #define ICODE_ATTR_MPC_LARGE_IRAM | ||
78 | #endif | ||
79 | #endif | ||
80 | |||
81 | #ifdef ROCKBOX_LITTLE_ENDIAN | ||
82 | #define MPC_LITTLE_ENDIAN | ||
83 | #endif | ||
84 | |||
85 | enum { | ||
86 | MPC_FRAME_LENGTH = (36 * 32), /// samples per mpc frame | ||
87 | MPC_DECODER_BUFFER_LENGTH = 2 * MPC_FRAME_LENGTH /// required buffer size for decoder | ||
88 | }; | ||
89 | |||
90 | // error codes | ||
91 | #define ERROR_CODE_OK 0 | ||
92 | #define ERROR_CODE_FILE -1 | ||
93 | #define ERROR_CODE_SV7BETA 1 | ||
94 | #define ERROR_CODE_CBR 2 | ||
95 | #define ERROR_CODE_IS 3 | ||
96 | #define ERROR_CODE_BLOCKSIZE 4 | ||
97 | #define ERROR_CODE_INVALIDSV 5 | ||
98 | |||
99 | /// Initializes a streaminfo structure. | ||
100 | /// \param si streaminfo structure to initialize | ||
101 | void mpc_streaminfo_init(mpc_streaminfo *si); | ||
102 | |||
103 | /// Reads streaminfo header from the mpc stream supplied by r. | ||
104 | /// \param si streaminfo pointer to which info will be written | ||
105 | /// \param r stream reader to supply raw data | ||
106 | /// \return error code | ||
107 | mpc_int32_t mpc_streaminfo_read(mpc_streaminfo *si, mpc_reader *r); | ||
108 | |||
109 | /// Gets length of stream si, in seconds. | ||
110 | /// \return length of stream in seconds | ||
111 | double mpc_streaminfo_get_length(mpc_streaminfo *si); | ||
112 | |||
113 | /// Returns length of stream si, in samples. | ||
114 | /// \return length of stream in samples | ||
115 | mpc_int64_t mpc_streaminfo_get_length_samples(mpc_streaminfo *si); | ||
116 | |||
117 | /// Sets up decoder library. | ||
118 | /// Call this first when preparing to decode an mpc stream. | ||
119 | /// \param r reader that will supply raw data to the decoder | ||
120 | void mpc_decoder_setup(mpc_decoder *d, mpc_reader *r); | ||
121 | |||
122 | /// Initializes mpc decoder with the supplied stream info parameters. | ||
123 | /// Call this next after calling mpc_decoder_setup. | ||
124 | /// \param si streaminfo structure indicating format of source stream | ||
125 | /// \return TRUE if decoder was initalized successfully, FALSE otherwise | ||
126 | mpc_bool_t mpc_decoder_initialize(mpc_decoder *d, mpc_streaminfo *si); | ||
127 | |||
128 | /// Sets decoder sample scaling factor. All decoded samples will be multiplied | ||
129 | /// by this factor. | ||
130 | /// \param scale_factor multiplicative scaling factor | ||
131 | void mpc_decoder_scale_output(mpc_decoder *d, double scale_factor); | ||
132 | |||
133 | /// Actually reads data from previously initialized stream. Call | ||
134 | /// this iteratively to decode the mpc stream. | ||
135 | /// \param buffer destination buffer for decoded samples | ||
136 | /// \param vbr_update_acc \todo document me | ||
137 | /// \param vbr_update_bits \todo document me | ||
138 | /// \return -1 if an error is encountered | ||
139 | /// \return 0 if the stream has been completely decoded successfully and there are no more samples | ||
140 | /// \return > 0 to indicate the number of bytes that were actually read from the stream. | ||
141 | mpc_uint32_t mpc_decoder_decode( | ||
142 | mpc_decoder *d, | ||
143 | MPC_SAMPLE_FORMAT *buffer, | ||
144 | mpc_uint32_t *vbr_update_acc, | ||
145 | mpc_uint32_t *vbr_update_bits); | ||
146 | |||
147 | mpc_uint32_t mpc_decoder_decode_frame( | ||
148 | mpc_decoder *d, | ||
149 | mpc_uint32_t *in_buffer, | ||
150 | mpc_uint32_t in_len, | ||
151 | MPC_SAMPLE_FORMAT *out_buffer); | ||
152 | |||
153 | /// Seeks to the specified sample in the source stream. | ||
154 | mpc_bool_t mpc_decoder_seek_sample(mpc_decoder *d, mpc_int64_t destsample); | ||
155 | |||
156 | /// Seeks to specified position in seconds in the source stream. | ||
157 | mpc_bool_t mpc_decoder_seek_seconds(mpc_decoder *d, double seconds); | ||
158 | |||
159 | #ifdef __cplusplus | ||
160 | } | ||
161 | #endif // __cplusplus | ||
162 | |||
163 | #endif // _mpcdec_h_ | ||
diff --git a/apps/codecs/libmusepack/reader.h b/apps/codecs/libmusepack/reader.h index 397319b292..60a0ef939d 100644 --- a/apps/codecs/libmusepack/reader.h +++ b/apps/codecs/libmusepack/reader.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2005, The Musepack Development Team | 2 | Copyright (c) 2005-2009, The Musepack Development Team |
3 | All rights reserved. | 3 | All rights reserved. |
4 | 4 | ||
5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
@@ -31,52 +31,68 @@ | |||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | 33 | */ |
34 | |||
35 | /// \file reader.h | 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 | ||
36 | 47 | ||
37 | #ifndef _mpcdec_reader_h_ | ||
38 | #define _mpcdec_reader_h_ | ||
39 | 48 | ||
40 | /// \brief Stream reader interface structure. | 49 | /// \brief Stream reader interface structure. |
41 | /// | 50 | /// |
42 | /// This is the structure you must supply to the musepack decoding library | 51 | /// This is the structure you must supply to the musepack decoding library |
43 | /// to feed it with raw data. Implement the five member functions to provide | 52 | /// to feed it with raw data. Implement the five member functions to provide |
44 | /// a functional reader. | 53 | /// a functional reader. |
45 | typedef struct mpc_reader_t { | 54 | typedef struct mpc_reader_t mpc_reader; |
55 | struct mpc_reader_t { | ||
46 | /// Reads size bytes of data into buffer at ptr. | 56 | /// Reads size bytes of data into buffer at ptr. |
47 | mpc_int32_t (*read)(void *t, void *ptr, mpc_int32_t size); | 57 | mpc_int32_t (*read)(mpc_reader *p_reader, void *ptr, mpc_int32_t size); |
48 | 58 | ||
49 | /// Seeks to byte position offset. | 59 | /// Seeks to byte position offset. |
50 | mpc_bool_t (*seek)(void *t, mpc_int32_t offset); | 60 | mpc_bool_t (*seek)(mpc_reader *p_reader, mpc_int32_t offset); |
51 | 61 | ||
52 | /// Returns the current byte offset in the stream. | 62 | /// Returns the current byte offset in the stream. |
53 | mpc_int32_t (*tell)(void *t); | 63 | mpc_int32_t (*tell)(mpc_reader *p_reader); |
54 | 64 | ||
55 | /// Returns the total length of the source stream, in bytes. | 65 | /// Returns the total length of the source stream, in bytes. |
56 | mpc_int32_t (*get_size)(void *t); | 66 | mpc_int32_t (*get_size)(mpc_reader *p_reader); |
57 | 67 | ||
58 | /// True if the stream is a seekable stream. | 68 | /// True if the stream is a seekable stream. |
59 | mpc_bool_t (*canseek)(void *t); | 69 | mpc_bool_t (*canseek)(mpc_reader *p_reader); |
60 | 70 | ||
61 | /// Field that can be used to identify a particular instance of | 71 | /// Field that can be used to identify a particular instance of |
62 | /// reader or carry along data associated with that reader. | 72 | /// reader or carry along data associated with that reader. |
63 | void *data; | 73 | void *data; |
64 | 74 | }; | |
65 | } mpc_reader; | 75 | /* rockbox: not used |
66 | /* No standard STDIO based reader in Rockbox | ||
67 | typedef struct mpc_reader_file_t { | ||
68 | mpc_reader reader; | ||
69 | |||
70 | FILE *file; | ||
71 | long file_size; | ||
72 | mpc_bool_t is_seekable; | ||
73 | } mpc_reader_file; | ||
74 | */ | ||
75 | /// Initializes reader with default stdio file reader implementation. Use | 76 | /// Initializes reader with default stdio file reader implementation. Use |
76 | /// this if you're just reading from a plain file. | 77 | /// this if you're just reading from a plain file. |
77 | /// | 78 | /// |
78 | /// \param r reader struct to initalize | 79 | /// \param r p_reader handle to initialize |
79 | /// \param input input stream to attach to the reader | 80 | /// \param filename input filename to attach to the reader |
80 | /* void mpc_reader_setup_file_reader(mpc_reader_file *r, FILE *input); */ | 81 | MPC_API mpc_status mpc_reader_init_stdio(mpc_reader *p_reader, const char *filename); |
81 | 82 | ||
82 | #endif // _mpcdec_reader_h_ | 83 | /// Initializes reader with default stdio file reader implementation. Use |
84 | /// this if you prefer to open the file yourself. | ||
85 | /// | ||
86 | /// \param r p_reader handle to initialize | ||
87 | /// \param p_file input file handle (already open) | ||
88 | MPC_API mpc_status mpc_reader_init_stdio_stream(mpc_reader * p_reader, FILE * p_file); | ||
89 | |||
90 | /// Release reader with default stdio file reader implementation. | ||
91 | /// | ||
92 | /// \param r reader handle to release | ||
93 | MPC_API void mpc_reader_exit_stdio(mpc_reader *p_reader); | ||
94 | */ | ||
95 | #ifdef __cplusplus | ||
96 | } | ||
97 | #endif | ||
98 | #endif | ||
diff --git a/apps/codecs/libmusepack/requant.c b/apps/codecs/libmusepack/requant.c index d40f36fded..d8ded7ecf9 100644 --- a/apps/codecs/libmusepack/requant.c +++ b/apps/codecs/libmusepack/requant.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2005, The Musepack Development Team | 2 | Copyright (c) 2005-2009, The Musepack Development Team |
3 | All rights reserved. | 3 | All rights reserved. |
4 | 4 | ||
5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
@@ -31,117 +31,93 @@ | |||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | 33 | */ |
34 | |||
35 | /// \file requant.c | 34 | /// \file requant.c |
36 | /// Requantization function implementations. | 35 | /// Requantization function implementations. |
37 | /// \todo document me | 36 | /// \todo document me |
38 | 37 | #include "mpcdec.h" | |
39 | #include "musepack.h" | 38 | #include "requant.h" |
40 | #include "internal.h" | 39 | #include "mpcdec_math.h" |
40 | #include "decoder.h" | ||
41 | 41 | ||
42 | /* C O N S T A N T S */ | 42 | /* C O N S T A N T S */ |
43 | // bits per sample for chosen quantizer | 43 | // Bits per sample for chosen quantizer |
44 | const mpc_uint32_t Res_bit [18] ICONST_ATTR = { | 44 | const mpc_uint8_t Res_bit [18] ICONST_ATTR = { |
45 | 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 | 45 | 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 |
46 | }; | 46 | }; |
47 | 47 | ||
48 | // coefficients for requantization | 48 | // Requantization coefficients |
49 | // 65536/step bzw. 65536/(2*D+1) | 49 | // 65536/step bzw. 65536/(2*D+1) |
50 | 50 | ||
51 | #define _(X) MAKE_MPC_SAMPLE_EX(X,14) | 51 | #define _(X) MAKE_MPC_SAMPLE_EX(X,14) |
52 | 52 | ||
53 | const MPC_SAMPLE_FORMAT __Cc [1 + 18] ICONST_ATTR = { | 53 | const MPC_SAMPLE_FORMAT __Cc [1 + 18] ICONST_ATTR = { |
54 | _(111.285962475327f), // 32768/2/255*sqrt(3) | 54 | _(111.285962475327f), // 32768/2/255*sqrt(3) |
55 | _(65536.000000000000f), _(21845.333333333332f), _(13107.200000000001f), _(9362.285714285713f), | 55 | _(65536.000000000000f), _(21845.333333333332f), _(13107.200000000001f), _(9362.285714285713f), |
56 | _(7281.777777777777f), _(4369.066666666666f), _(2114.064516129032f), _(1040.253968253968f), | 56 | _(7281.777777777777f), _(4369.066666666666f), _(2114.064516129032f), _(1040.253968253968f), |
57 | _(516.031496062992f), _(257.003921568627f), _(128.250489236790f), _(64.062561094819f), | 57 | _(516.031496062992f), _(257.003921568627f), _(128.250489236790f), _(64.062561094819f), |
58 | _(32.015632633121f), _(16.003907203907f), _(8.000976681723f), _(4.000244155527f), | 58 | _(32.015632633121f), _(16.003907203907f), _(8.000976681723f), _(4.000244155527f), |
59 | _(2.000061037018f), _(1.000015259021f) | 59 | _(2.000061037018f), _(1.000015259021f) |
60 | }; | 60 | }; |
61 | 61 | ||
62 | #undef _ | 62 | #undef _ |
63 | 63 | ||
64 | // offset for requantization | 64 | // Requantization offset |
65 | // 2*D+1 = steps of quantizer | 65 | // 2*D+1 = steps of quantizer |
66 | const mpc_int32_t __Dc [1 + 18] ICONST_ATTR = { | 66 | const mpc_int16_t __Dc [1 + 18] ICONST_ATTR = { |
67 | 2, | 67 | 2, |
68 | 0, 1, 2, 3, 4, 7, 15, 31, 63, | 68 | 0, 1, 2, 3, 4, 7, 15, 31, 63, |
69 | 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767 | 69 | 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767 |
70 | }; | 70 | }; |
71 | 71 | ||
72 | // decoding results (requantized) for bundled quantizers (3- and 5-step) | ||
73 | // 1st value of bundled 3-step quantizer | ||
74 | const mpc_int32_t idx30[27] ICONST_ATTR = { -1, 0, 1,-1, 0, 1,-1, 0, 1, | ||
75 | -1, 0, 1,-1, 0, 1,-1, 0, 1, | ||
76 | -1, 0, 1,-1, 0, 1,-1, 0, 1}; | ||
77 | // 2nd value of bundled 3-step quantizer | ||
78 | const mpc_int32_t idx31[27] ICONST_ATTR = { -1,-1,-1, 0, 0, 0, 1, 1, 1, | ||
79 | -1,-1,-1, 0, 0, 0, 1, 1, 1, | ||
80 | -1,-1,-1, 0, 0, 0, 1, 1, 1}; | ||
81 | // 3rd value of bundled 3-step quantizer | ||
82 | const mpc_int32_t idx32[27] ICONST_ATTR = { -1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
83 | 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
84 | 1, 1, 1, 1, 1, 1, 1, 1, 1}; | ||
85 | // 1st value of bundled 5-step quantizer | ||
86 | const mpc_int32_t idx50[25] ICONST_ATTR = { -2,-1, 0, 1, 2, | ||
87 | -2,-1, 0, 1, 2, | ||
88 | -2,-1, 0, 1, 2, | ||
89 | -2,-1, 0, 1, 2, | ||
90 | -2,-1, 0, 1, 2}; | ||
91 | // 2nd value of bundled 5-step quantizer | ||
92 | const mpc_int32_t idx51[25] ICONST_ATTR = { -2,-2,-2,-2,-2, | ||
93 | -1,-1,-1,-1,-1, | ||
94 | 0, 0, 0, 0, 0, | ||
95 | 1, 1, 1, 1, 1, | ||
96 | 2, 2, 2, 2, 2}; | ||
97 | |||
98 | |||
99 | #ifdef MPC_FIXED_POINT | 72 | #ifdef MPC_FIXED_POINT |
100 | static mpc_uint32_t find_shift(double fval) | 73 | static mpc_uint32_t find_shift(double fval) |
101 | { | 74 | { |
102 | mpc_int64_t val = (mpc_int64_t)fval; | 75 | mpc_int64_t val = (mpc_int64_t) fval; |
103 | mpc_uint32_t ptr = 0; | 76 | mpc_uint32_t ptr = 0; |
104 | if (val<0) val = -val; | 77 | if(val<0) |
105 | while(val) {val>>=1;ptr++;} | 78 | val = -val; |
106 | 79 | while(val) | |
80 | { | ||
81 | val >>= 1; | ||
82 | ptr++; | ||
83 | } | ||
107 | return ptr > 31 ? 0 : 31 - ptr; | 84 | return ptr > 31 ? 0 : 31 - ptr; |
108 | } | 85 | } |
109 | #endif | 86 | #endif |
110 | 87 | ||
111 | /* F U N C T I O N S */ | 88 | /* F U N C T I O N S */ |
112 | 89 | ||
113 | #define SET_SCF(N,X) d->SCF[N] = MAKE_MPC_SAMPLE_EX(X,d->SCF_shift[N] = (unsigned char)find_shift(X)); | 90 | #define SET_SCF(N,X) d->SCF[N] = MAKE_MPC_SAMPLE_EX(X,d->SCF_shift[N] = (mpc_uint8_t) find_shift(X)); |
114 | 91 | ||
115 | void | 92 | void |
116 | mpc_decoder_scale_output(mpc_decoder *d, double factor) | 93 | mpc_decoder_scale_output(mpc_decoder *d, double factor) |
117 | { | 94 | { |
118 | mpc_int32_t n; | 95 | mpc_int32_t n; double f1, f2; |
119 | double f1; | 96 | |
120 | double f2; | ||
121 | #ifndef MPC_FIXED_POINT | 97 | #ifndef MPC_FIXED_POINT |
122 | factor *= 1.0 / (double)(1<<(MPC_FIXED_POINT_SHIFT-1)); | 98 | factor *= 1.0 / (double) (1<<(MPC_FIXED_POINT_SHIFT-1)); |
123 | #else | 99 | #else |
124 | factor *= 1.0 / (double)(1<<(16 - MPC_FIXED_POINT_SHIFT)); | 100 | factor *= 1.0 / (double) (1<<(16-MPC_FIXED_POINT_SHIFT)); |
125 | #endif | 101 | #endif |
126 | f1 = f2 = factor; | 102 | f1 = f2 = factor; |
127 | 103 | ||
128 | // handles +1.58...-98.41 dB, where's scf[n] / scf[n-1] = 1.20050805774840750476 | 104 | // handles +1.58...-98.41 dB, where's scf[n] / scf[n-1] = 1.20050805774840750476 |
129 | 105 | ||
130 | SET_SCF(1,factor); | 106 | SET_SCF(1,factor); |
131 | 107 | ||
132 | f1 *= 0.83298066476582673961; | 108 | f1 *= 0.83298066476582673961; |
133 | f2 *= 1/0.83298066476582673961; | 109 | f2 *= 1/0.83298066476582673961; |
134 | 110 | ||
135 | for ( n = 1; n <= 128; n++ ) { | 111 | for ( n = 1; n <= 128; n++ ) { |
136 | SET_SCF((unsigned char)(1+n),f1); | 112 | SET_SCF((mpc_uint8_t)(1+n),f1); |
137 | SET_SCF((unsigned char)(1-n),f2); | 113 | SET_SCF((mpc_uint8_t)(1-n),f2); |
138 | f1 *= 0.83298066476582673961; | 114 | f1 *= 0.83298066476582673961; |
139 | f2 *= 1/0.83298066476582673961; | 115 | f2 *= 1/0.83298066476582673961; |
140 | } | 116 | } |
141 | } | 117 | } |
142 | 118 | ||
143 | void | 119 | void |
144 | mpc_decoder_initialisiere_quantisierungstabellen(mpc_decoder *d, double scale_factor) | 120 | mpc_decoder_init_quant(mpc_decoder *d, double scale_factor) |
145 | { | 121 | { |
146 | mpc_decoder_scale_output(d, scale_factor); | 122 | mpc_decoder_scale_output(d, scale_factor); |
147 | } | 123 | } |
diff --git a/apps/codecs/libmusepack/requant.h b/apps/codecs/libmusepack/requant.h index 1a21c21143..8458d4d0fa 100644 --- a/apps/codecs/libmusepack/requant.h +++ b/apps/codecs/libmusepack/requant.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2005, The Musepack Development Team | 2 | Copyright (c) 2005-2009, The Musepack Development Team |
3 | All rights reserved. | 3 | All rights reserved. |
4 | 4 | ||
5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
@@ -31,27 +31,31 @@ | |||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | 33 | */ |
34 | |||
35 | /// \file requant.h | 34 | /// \file requant.h |
36 | /// Requantization function definitions. | 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" | ||
37 | 43 | ||
38 | #ifndef _mpcdec_requant_h | 44 | #ifdef __cplusplus |
39 | #define _mpcdec_requant_h_ | 45 | extern "C" { |
46 | #endif | ||
40 | 47 | ||
41 | #include "musepack.h" | ||
42 | 48 | ||
43 | /* C O N S T A N T S */ | 49 | /* C O N S T A N T S */ |
44 | extern const mpc_uint32_t Res_bit[18]; // bits per sample for chosen quantizer | 50 | const mpc_uint8_t Res_bit [18]; ///< Bits per sample for chosen quantizer |
45 | extern const MPC_SAMPLE_FORMAT __Cc[1 + 18]; // coefficients for requantization | 51 | const MPC_SAMPLE_FORMAT __Cc [1 + 18]; ///< Requantization coefficients |
46 | extern const mpc_int32_t __Dc[1 + 18]; // offset for requantization | 52 | const mpc_int16_t __Dc [1 + 18]; ///< Requantization offset |
47 | extern const mpc_int32_t idx30[27]; // 1st value of bundled 3-step quantizer | ||
48 | extern const mpc_int32_t idx31[27]; // 2nd value of bundled 3-step quantizer | ||
49 | extern const mpc_int32_t idx32[27]; // 3rd value of bundled 3-step quantizer | ||
50 | extern const mpc_int32_t idx50[25]; // 1st value of bundled 5-step quantizer | ||
51 | extern const mpc_int32_t idx51[25]; // 2nd value of bundled 5-step quantizer | ||
52 | 53 | ||
54 | #define Cc (__Cc + 1) | ||
55 | #define Dc (__Dc + 1) | ||
53 | 56 | ||
54 | #define Cc (__Cc + 1) | ||
55 | #define Dc (__Dc + 1) | ||
56 | 57 | ||
57 | #endif // _mpcdec_requant_h_ | 58 | #ifdef __cplusplus |
59 | } | ||
60 | #endif | ||
61 | #endif | ||
diff --git a/apps/codecs/libmusepack/streaminfo.c b/apps/codecs/libmusepack/streaminfo.c index 3edf50a5ea..5c135ef64a 100644 --- a/apps/codecs/libmusepack/streaminfo.c +++ b/apps/codecs/libmusepack/streaminfo.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2005, The Musepack Development Team | 2 | Copyright (c) 2005-2009, The Musepack Development Team |
3 | All rights reserved. | 3 | All rights reserved. |
4 | 4 | ||
5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
@@ -31,256 +31,226 @@ | |||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | 33 | */ |
34 | |||
35 | /// \file streaminfo.c | 34 | /// \file streaminfo.c |
36 | /// Implementation of streaminfo reading functions. | 35 | /// Implementation of streaminfo reading functions. |
37 | 36 | ||
38 | #include "musepack.h" | 37 | #include <math.h> |
38 | #include "mpcdec.h" | ||
39 | #include "streaminfo.h" | ||
40 | #include <stdio.h> | ||
39 | #include "internal.h" | 41 | #include "internal.h" |
40 | 42 | #include "huffman.h" | |
43 | #include "mpc_bits_reader.h" | ||
44 | |||
45 | unsigned long mpc_crc32(unsigned char *buf, int len); | ||
46 | /* rockbox: not used | ||
47 | static const char na[] = "n.a."; | ||
48 | static char const * const versionNames[] = { | ||
49 | na, "'Unstable/Experimental'", na, na, na, "'quality 0'", "'quality 1'", | ||
50 | "'Telephone'", "'Thumb'", "'Radio'", "'Standard'", "'Extreme'", "'Insane'", | ||
51 | "'BrainDead'", "'quality 9'", "'quality 10'" | ||
52 | }; | ||
53 | */ | ||
54 | static const mpc_int32_t samplefreqs[8] = { 44100, 48000, 37800, 32000 }; | ||
55 | /* rockbox: not used | ||
41 | static const char * | 56 | static const char * |
42 | Stringify(mpc_uint32_t profile) // profile is 0...15, where 7...13 is used | 57 | mpc_get_version_string(float profile) // profile is 0...15, where 7...13 is used |
43 | { | 58 | { |
44 | static const char na[] = "n.a."; | 59 | return profile >= sizeof versionNames / sizeof *versionNames ? na : versionNames[(int)profile]; |
45 | static const char *Names[] = { | ||
46 | na, "'Unstable/Experimental'", na, na, | ||
47 | na, "'quality 0'", "'quality 1'", "'Telephone'", | ||
48 | "'Thumb'", "'Radio'", "'Standard'", "'Xtreme'", | ||
49 | "'Insane'", "'BrainDead'", "'quality 9'", "'quality 10'" | ||
50 | }; | ||
51 | |||
52 | return profile >= sizeof(Names) / sizeof(*Names) ? na : Names[profile]; | ||
53 | } | 60 | } |
54 | 61 | */ | |
55 | void | 62 | /* rockbox: not used |
56 | mpc_streaminfo_init(mpc_streaminfo * si) | 63 | static void |
64 | mpc_get_encoder_string(mpc_streaminfo* si) | ||
57 | { | 65 | { |
58 | memset(si, 0, sizeof(mpc_streaminfo)); | 66 | int ver = si->encoder_version; |
67 | if (si->stream_version >= 8) | ||
68 | ver = (si->encoder_version >> 24) * 100 + ((si->encoder_version >> 16) & 0xFF); | ||
69 | if (ver <= 116) { | ||
70 | if (ver == 0) { | ||
71 | sprintf(si->encoder, "Buschmann 1.7.0...9, Klemm 0.90...1.05"); | ||
72 | } else { | ||
73 | switch (ver % 10) { | ||
74 | case 0: | ||
75 | sprintf(si->encoder, "Release %u.%u", ver / 100, | ||
76 | ver / 10 % 10); | ||
77 | break; | ||
78 | case 2: case 4: case 6: case 8: | ||
79 | sprintf(si->encoder, "Beta %u.%02u", ver / 100, | ||
80 | ver % 100); | ||
81 | break; | ||
82 | default: | ||
83 | sprintf(si->encoder, "--Alpha-- %u.%02u", | ||
84 | ver / 100, ver % 100); | ||
85 | break; | ||
86 | } | ||
87 | } | ||
88 | } else { | ||
89 | int major = si->encoder_version >> 24; | ||
90 | int minor = (si->encoder_version >> 16) & 0xFF; | ||
91 | int build = (si->encoder_version >> 8) & 0xFF; | ||
92 | char * tmp = "--Stable--"; | ||
93 | |||
94 | if (minor & 1) | ||
95 | tmp = "--Unstable--"; | ||
96 | |||
97 | sprintf(si->encoder, "%s %u.%u.%u", tmp, major, minor, build); | ||
98 | } | ||
59 | } | 99 | } |
100 | */ | ||
60 | 101 | ||
61 | /// Reads streaminfo from SV7 header. | 102 | static mpc_status check_streaminfo(mpc_streaminfo * si) |
62 | static mpc_int32_t | ||
63 | streaminfo_read_header_sv7(mpc_streaminfo * si, mpc_uint32_t HeaderData[8]) | ||
64 | { | 103 | { |
65 | const mpc_int32_t samplefreqs[4] = { 44100, 48000, 37800, 32000 }; | 104 | if (si->max_band == 0 || si->max_band >= 32 |
105 | || si->channels > 2) | ||
106 | return MPC_STATUS_FILE; | ||
107 | return MPC_STATUS_OK; | ||
108 | } | ||
66 | 109 | ||
67 | //mpc_uint32_t HeaderData [8]; | 110 | /// Reads streaminfo from SV7 header. |
111 | mpc_status | ||
112 | streaminfo_read_header_sv7(mpc_streaminfo* si, mpc_bits_reader * r) | ||
113 | { | ||
68 | mpc_uint16_t Estimatedpeak_title = 0; | 114 | mpc_uint16_t Estimatedpeak_title = 0; |
69 | 115 | mpc_uint32_t frames, last_frame_samples; | |
70 | if (si->stream_version > 0x71) { | 116 | |
71 | // Update (si->stream_version); | 117 | si->bitrate = 0; |
72 | return 0; | 118 | frames = (mpc_bits_read(r, 16) << 16) | mpc_bits_read(r, 16); |
119 | mpc_bits_read(r, 1); // intensity stereo : should be 0 | ||
120 | si->ms = mpc_bits_read(r, 1); | ||
121 | si->max_band = mpc_bits_read(r, 6); | ||
122 | si->profile = mpc_bits_read(r, 4); | ||
123 | /* rockbox: not used | ||
124 | si->profile_name = mpc_get_version_string(si->profile); | ||
125 | */ | ||
126 | mpc_bits_read(r, 2); // Link ? | ||
127 | si->sample_freq = samplefreqs[mpc_bits_read(r, 2)]; | ||
128 | Estimatedpeak_title = (mpc_uint16_t) mpc_bits_read(r, 16); // read the ReplayGain data | ||
129 | si->gain_title = (mpc_uint16_t) mpc_bits_read(r, 16); | ||
130 | si->peak_title = (mpc_uint16_t) mpc_bits_read(r, 16); | ||
131 | si->gain_album = (mpc_uint16_t) mpc_bits_read(r, 16); | ||
132 | si->peak_album = (mpc_uint16_t) mpc_bits_read(r, 16); | ||
133 | si->is_true_gapless = mpc_bits_read(r, 1); // true gapless: used? | ||
134 | last_frame_samples = mpc_bits_read(r, 11); // true gapless: valid samples for last frame | ||
135 | si->fast_seek = mpc_bits_read(r, 1); // fast seeking | ||
136 | mpc_bits_read(r, 19); // unused | ||
137 | si->encoder_version = mpc_bits_read(r, 8); | ||
138 | si->channels = 2; | ||
139 | si->block_pwr = 0; | ||
140 | |||
141 | /* rockbox: not used | ||
142 | // convert gain info | ||
143 | if (si->gain_title != 0) { | ||
144 | int tmp = (int)((MPC_OLD_GAIN_REF - (mpc_int16_t)si->gain_title / 100.) * 256. + .5); | ||
145 | if (tmp >= (1 << 16) || tmp < 0) tmp = 0; | ||
146 | si->gain_title = (mpc_int16_t) tmp; | ||
73 | } | 147 | } |
74 | 148 | ||
75 | /* | 149 | if (si->gain_album != 0) { |
76 | if ( !fp->seek ( si->header_position ) ) // seek to header start | 150 | int tmp = (int)((MPC_OLD_GAIN_REF - (mpc_int16_t)si->gain_album / 100.) * 256. + .5); |
77 | return ERROR_CODE_FILE; | 151 | if (tmp >= (1 << 16) || tmp < 0) tmp = 0; |
78 | if ( fp->read ( HeaderData, sizeof HeaderData) != sizeof HeaderData ) | 152 | si->gain_album = (mpc_int16_t) tmp; |
79 | return ERROR_CODE_FILE; | ||
80 | */ | ||
81 | |||
82 | si->bitrate = 0; | ||
83 | si->frames = HeaderData[1]; | ||
84 | si->is = 0; | ||
85 | si->ms = (HeaderData[2] >> 30) & 0x0001; | ||
86 | si->max_band = (HeaderData[2] >> 24) & 0x003F; | ||
87 | si->block_size = 1; | ||
88 | si->profile = (HeaderData[2] << 8) >> 28; | ||
89 | si->profile_name = Stringify(si->profile); | ||
90 | si->sample_freq = samplefreqs[(HeaderData[2] >> 16) & 0x0003]; | ||
91 | Estimatedpeak_title = (mpc_uint16_t) (HeaderData[2] & 0xFFFF); // read the ReplayGain data | ||
92 | si->gain_title = (mpc_uint16_t) ((HeaderData[3] >> 16) & 0xFFFF); | ||
93 | si->peak_title = (mpc_uint16_t) (HeaderData[3] & 0xFFFF); | ||
94 | si->gain_album = (mpc_uint16_t) ((HeaderData[4] >> 16) & 0xFFFF); | ||
95 | si->peak_album = (mpc_uint16_t) (HeaderData[4] & 0xFFFF); | ||
96 | si->is_true_gapless = (HeaderData[5] >> 31) & 0x0001; // true gapless: used? | ||
97 | si->last_frame_samples = (HeaderData[5] >> 20) & 0x07FF; // true gapless: valid samples for last frame | ||
98 | si->encoder_version = (HeaderData[6] >> 24) & 0x00FF; | ||
99 | |||
100 | if (si->encoder_version == 0) { | ||
101 | //sprintf(si->encoder, "Buschmann 1.7.0...9, Klemm 0.90...1.05"); | ||
102 | } | ||
103 | else { | ||
104 | switch (si->encoder_version % 10) { | ||
105 | case 0: | ||
106 | //sprintf(si->encoder, "Release %u.%u", si->encoder_version / 100, | ||
107 | // si->encoder_version / 10 % 10); | ||
108 | break; | ||
109 | case 2: | ||
110 | case 4: | ||
111 | case 6: | ||
112 | case 8: | ||
113 | //sprintf(si->encoder, "Beta %u.%02u", si->encoder_version / 100, | ||
114 | // si->encoder_version % 100); | ||
115 | break; | ||
116 | default: | ||
117 | //sprintf(si->encoder, "--Alpha-- %u.%02u", | ||
118 | // si->encoder_version / 100, si->encoder_version % 100); | ||
119 | break; | ||
120 | } | ||
121 | } | 153 | } |
154 | |||
155 | if (si->peak_title != 0) | ||
156 | si->peak_title = (mpc_uint16_t) (log10(si->peak_title) * 20 * 256 + .5); | ||
157 | |||
158 | if (si->peak_album != 0) | ||
159 | si->peak_album = (mpc_uint16_t) (log10(si->peak_album) * 20 * 256 + .5); | ||
160 | |||
161 | mpc_get_encoder_string(si); | ||
162 | */ | ||
122 | 163 | ||
123 | // if ( si->peak_title == 0 ) // there is no correct peak_title contained within header | 164 | if (last_frame_samples == 0) last_frame_samples = MPC_FRAME_LENGTH; |
124 | // si->peak_title = (mpc_uint16_t)(Estimatedpeak_title * 1.18); | 165 | si->samples = (mpc_int64_t) frames * MPC_FRAME_LENGTH; |
125 | // if ( si->peak_album == 0 ) | 166 | if (si->is_true_gapless) |
126 | // si->peak_album = si->peak_title; // no correct peak_album, use peak_title | 167 | si->samples -= (MPC_FRAME_LENGTH - last_frame_samples); |
168 | else | ||
169 | si->samples -= MPC_DECODER_SYNTH_DELAY; | ||
127 | 170 | ||
128 | //si->sample_freq = 44100; // AB: used by all files up to SV7 | 171 | si->average_bitrate = (si->tag_offset - si->header_position) * 8.0 |
129 | si->channels = 2; | 172 | * si->sample_freq / si->samples; |
130 | 173 | ||
131 | return ERROR_CODE_OK; | 174 | return check_streaminfo(si); |
132 | } | 175 | } |
133 | 176 | ||
134 | // read information from SV4-SV6 header | 177 | /// Reads replay gain datas |
135 | #ifdef MPC_SUPPORT_SV456 | 178 | void streaminfo_gain(mpc_streaminfo* si, const mpc_bits_reader * r_in) |
136 | static mpc_int32_t | ||
137 | streaminfo_read_header_sv6(mpc_streaminfo * si, mpc_uint32_t HeaderData[8]) | ||
138 | { | 179 | { |
139 | //mpc_uint32_t HeaderData [8]; | 180 | mpc_bits_reader r = *r_in; |
140 | 181 | ||
141 | /* | 182 | int version = mpc_bits_read(&r, 8); // gain version |
142 | if ( !fp->seek ( si->header_position ) ) // seek to header start | 183 | if (version != 1) // we only know ver 1 |
143 | return ERROR_CODE_FILE; | 184 | return; |
144 | if ( fp->read ( HeaderData, sizeof HeaderData ) != sizeof HeaderData ) | 185 | si->gain_title = (mpc_uint16_t) mpc_bits_read(&r, 16); |
145 | return ERROR_CODE_FILE; | 186 | si->peak_title = (mpc_uint16_t) mpc_bits_read(&r, 16); |
146 | */ | 187 | si->gain_album = (mpc_uint16_t) mpc_bits_read(&r, 16); |
147 | 188 | si->peak_album = (mpc_uint16_t) mpc_bits_read(&r, 16); | |
148 | si->bitrate = (HeaderData[0] >> 23) & 0x01FF; // read the file-header (SV6 and below) | 189 | } |
149 | si->is = (HeaderData[0] >> 22) & 0x0001; | ||
150 | si->ms = (HeaderData[0] >> 21) & 0x0001; | ||
151 | si->stream_version = (HeaderData[0] >> 11) & 0x03FF; | ||
152 | si->max_band = (HeaderData[0] >> 6) & 0x001F; | ||
153 | si->block_size = (HeaderData[0]) & 0x003F; | ||
154 | si->profile = 0; | ||
155 | si->profile_name = Stringify((mpc_uint32_t) (-1)); | ||
156 | if (si->stream_version >= 5) | ||
157 | si->frames = HeaderData[1]; // 32 bit | ||
158 | else | ||
159 | si->frames = (HeaderData[1] >> 16); // 16 bit | ||
160 | 190 | ||
161 | si->gain_title = 0; // not supported | 191 | /// Reads streaminfo from SV8 header. |
162 | si->peak_title = 0; | 192 | mpc_status |
163 | si->gain_album = 0; | 193 | streaminfo_read_header_sv8(mpc_streaminfo* si, const mpc_bits_reader * r_in, |
164 | si->peak_album = 0; | 194 | mpc_size_t block_size) |
195 | { | ||
196 | mpc_uint32_t CRC; | ||
197 | mpc_bits_reader r = *r_in; | ||
165 | 198 | ||
166 | si->last_frame_samples = 0; | 199 | CRC = (mpc_bits_read(&r, 16) << 16) | mpc_bits_read(&r, 16); |
167 | si->is_true_gapless = 0; | 200 | if (CRC != mpc_crc32(r.buff + 1 - (r.count >> 3), (int)block_size - 4)) |
201 | return MPC_STATUS_FILE; | ||
168 | 202 | ||
169 | si->encoder_version = 0; | 203 | si->stream_version = mpc_bits_read(&r, 8); |
170 | si->encoder[0] = '\0'; | 204 | if (si->stream_version != 8) |
205 | return MPC_STATUS_INVALIDSV; | ||
171 | 206 | ||
172 | if (si->stream_version == 7) | 207 | mpc_bits_get_size(&r, &si->samples); |
173 | return ERROR_CODE_SV7BETA; // are there any unsupported parameters used? | 208 | mpc_bits_get_size(&r, &si->beg_silence); |
174 | if (si->bitrate != 0) | ||
175 | return ERROR_CODE_CBR; | ||
176 | if (si->is != 0) | ||
177 | return ERROR_CODE_IS; | ||
178 | if (si->block_size != 1) | ||
179 | return ERROR_CODE_BLOCKSIZE; | ||
180 | 209 | ||
181 | if (si->stream_version < 6) // Bugfix: last frame was invalid for up to SV5 | 210 | si->is_true_gapless = 1; |
182 | si->frames -= 1; | 211 | si->sample_freq = samplefreqs[mpc_bits_read(&r, 3)]; |
212 | si->max_band = mpc_bits_read(&r, 5) + 1; | ||
213 | si->channels = mpc_bits_read(&r, 4) + 1; | ||
214 | si->ms = mpc_bits_read(&r, 1); | ||
215 | si->block_pwr = mpc_bits_read(&r, 3) * 2; | ||
183 | 216 | ||
184 | si->sample_freq = 44100; // AB: used by all files up to SV7 | 217 | si->bitrate = 0; |
185 | si->channels = 2; | ||
186 | 218 | ||
187 | if (si->stream_version < 4 || si->stream_version > 7) | 219 | if ((si->samples - si->beg_silence) != 0) |
188 | return ERROR_CODE_INVALIDSV; | 220 | si->average_bitrate = (si->tag_offset - si->header_position) * 8.0 |
221 | * si->sample_freq / (si->samples - si->beg_silence); | ||
189 | 222 | ||
190 | return ERROR_CODE_OK; | 223 | return check_streaminfo(si); |
191 | } | 224 | } |
192 | #endif | ||
193 | // reads file header and tags | ||
194 | mpc_int32_t | ||
195 | mpc_streaminfo_read(mpc_streaminfo * si, mpc_reader * r) | ||
196 | { | ||
197 | mpc_uint32_t HeaderData[8]; | ||
198 | mpc_int32_t Error = 0; | ||
199 | |||
200 | // get header position | ||
201 | if ((si->header_position = JumpID3v2(r)) < 0) { | ||
202 | return ERROR_CODE_FILE; | ||
203 | } | ||
204 | // seek to first byte of mpc data | ||
205 | if (!r->seek(r->data, si->header_position)) { | ||
206 | return ERROR_CODE_FILE; | ||
207 | } | ||
208 | if (r->read(r->data, HeaderData, 8 * 4) != 8 * 4) { | ||
209 | return ERROR_CODE_FILE; | ||
210 | } | ||
211 | if (!r->seek(r->data, si->header_position + 6 * 4)) { | ||
212 | return ERROR_CODE_FILE; | ||
213 | } | ||
214 | |||
215 | si->total_file_length = r->get_size(r->data); | ||
216 | si->tag_offset = si->total_file_length; | ||
217 | if (memcmp(HeaderData, "MP+", 3) == 0) { | ||
218 | #ifndef MPC_LITTLE_ENDIAN | ||
219 | mpc_uint32_t ptr; | ||
220 | for (ptr = 0; ptr < 8; ptr++) { | ||
221 | HeaderData[ptr] = mpc_swap32(HeaderData[ptr]); | ||
222 | } | ||
223 | #endif | ||
224 | si->stream_version = HeaderData[0] >> 24; | ||
225 | |||
226 | // stream version 7 | ||
227 | if ((si->stream_version & 15) == 7) { | ||
228 | Error = streaminfo_read_header_sv7(si, HeaderData); | ||
229 | if (Error != ERROR_CODE_OK) return Error; | ||
230 | } else { | ||
231 | // only sv7 allowed with "MP+" signature | ||
232 | return ERROR_CODE_INVALIDSV; | ||
233 | } | ||
234 | } else if (memcmp(HeaderData, "MPCK", 4) == 0) { | ||
235 | // stream version 8 uses "MPCK" signature | ||
236 | return ERROR_CODE_INVALIDSV; | ||
237 | } else { | ||
238 | #ifdef MPC_SUPPORT_SV456 | ||
239 | #ifndef MPC_LITTLE_ENDIAN | ||
240 | mpc_uint32_t ptr; | ||
241 | for (ptr = 0; ptr < 8; ptr++) { | ||
242 | HeaderData[ptr] = mpc_swap32(HeaderData[ptr]); | ||
243 | } | ||
244 | #endif | ||
245 | // stream version 4-6 | ||
246 | Error = streaminfo_read_header_sv6(si, HeaderData); | ||
247 | if (Error != ERROR_CODE_OK) return Error; | ||
248 | #else | ||
249 | return ERROR_CODE_INVALIDSV; | ||
250 | #endif | ||
251 | } | ||
252 | 225 | ||
253 | // estimation, exact value needs too much time | 226 | /// Reads encoder informations |
254 | si->pcm_samples = 1152 * si->frames - 576; | 227 | void streaminfo_encoder_info(mpc_streaminfo* si, const mpc_bits_reader * r_in) |
228 | { | ||
229 | mpc_bits_reader r = *r_in; | ||
255 | 230 | ||
256 | if (si->pcm_samples > 0) { | 231 | si->profile = mpc_bits_read(&r, 7) / 8.; |
257 | si->average_bitrate = | 232 | /* rockbox: not used |
258 | (si->tag_offset - | 233 | si->profile_name = mpc_get_version_string(si->profile); |
259 | si->header_position) * 8.0 * si->sample_freq / si->pcm_samples; | 234 | */ |
260 | } | 235 | si->pns = mpc_bits_read(&r, 1); |
261 | else { | 236 | si->encoder_version = mpc_bits_read(&r, 8) << 24; // major |
262 | si->average_bitrate = 0; | 237 | si->encoder_version |= mpc_bits_read(&r, 8) << 16; // minor |
263 | } | 238 | si->encoder_version |= mpc_bits_read(&r, 8) << 8; // build |
264 | 239 | ||
265 | return ERROR_CODE_OK; | 240 | /* rockbox: not used |
241 | mpc_get_encoder_string(si); | ||
242 | */ | ||
266 | } | 243 | } |
267 | 244 | ||
245 | /* rockbox: not used | ||
268 | double | 246 | double |
269 | mpc_streaminfo_get_length(mpc_streaminfo * si) | 247 | mpc_streaminfo_get_length(mpc_streaminfo * si) |
270 | { | 248 | { |
271 | return (double)mpc_streaminfo_get_length_samples(si) / | 249 | return (double) (si->samples - si->beg_silence) / si->sample_freq; |
272 | (double)si->sample_freq; | ||
273 | } | 250 | } |
274 | 251 | ||
275 | mpc_int64_t | 252 | mpc_int64_t mpc_streaminfo_get_length_samples(mpc_streaminfo *si) |
276 | mpc_streaminfo_get_length_samples(mpc_streaminfo * si) | ||
277 | { | 253 | { |
278 | mpc_int64_t samples = (mpc_int64_t) si->frames * MPC_FRAME_LENGTH; | 254 | return si->samples - si->beg_silence; |
279 | if (si->is_true_gapless) { | ||
280 | samples -= (MPC_FRAME_LENGTH - si->last_frame_samples); | ||
281 | } | ||
282 | else { | ||
283 | samples -= MPC_DECODER_SYNTH_DELAY; | ||
284 | } | ||
285 | return samples; | ||
286 | } | 255 | } |
256 | */ | ||
diff --git a/apps/codecs/libmusepack/streaminfo.h b/apps/codecs/libmusepack/streaminfo.h index 6c4b4ca108..739d40acf3 100644 --- a/apps/codecs/libmusepack/streaminfo.h +++ b/apps/codecs/libmusepack/streaminfo.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2005, The Musepack Development Team | 2 | Copyright (c) 2005-2009, The Musepack Development Team |
3 | All rights reserved. | 3 | All rights reserved. |
4 | 4 | ||
5 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
@@ -31,11 +31,19 @@ | |||
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 32 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | 33 | */ |
34 | |||
35 | /// \file streaminfo.h | 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 | ||
36 | 46 | ||
37 | #ifndef _mpcdec_streaminfo_h_ | ||
38 | #define _mpcdec_streaminfo_h_ | ||
39 | 47 | ||
40 | typedef mpc_int32_t mpc_streaminfo_off_t; | 48 | typedef mpc_int32_t mpc_streaminfo_off_t; |
41 | 49 | ||
@@ -44,43 +52,63 @@ typedef mpc_int32_t mpc_streaminfo_off_t; | |||
44 | /// Structure containing all the properties of an mpc stream. Populated | 52 | /// Structure containing all the properties of an mpc stream. Populated |
45 | /// by the streaminfo_read function. | 53 | /// by the streaminfo_read function. |
46 | typedef struct mpc_streaminfo { | 54 | typedef struct mpc_streaminfo { |
47 | /// @name core mpc stream properties | 55 | /// @name Core mpc stream properties |
48 | //@{ | 56 | //@{ |
49 | mpc_uint32_t sample_freq; ///< sample frequency of stream | 57 | mpc_uint32_t sample_freq; ///< Sample frequency of stream |
50 | mpc_uint32_t channels; ///< number of channels in stream | 58 | mpc_uint32_t channels; ///< Number of channels in stream |
51 | mpc_streaminfo_off_t header_position; ///< byte offset of position of header in stream | 59 | mpc_uint32_t stream_version; ///< Streamversion of stream |
52 | mpc_uint32_t stream_version; ///< streamversion of stream | 60 | mpc_uint32_t bitrate; ///< Bitrate of stream file (in bps) |
53 | mpc_uint32_t bitrate; ///< bitrate of stream file (in bps) | 61 | double average_bitrate; ///< Average bitrate of stream (in bits/sec) |
54 | double average_bitrate; ///< average bitrate of stream (in bits/sec) | 62 | mpc_uint32_t max_band; ///< Maximum band-index used in stream (0...31) |
55 | mpc_uint32_t frames; ///< number of frames in stream | 63 | mpc_uint32_t ms; ///< Mid/side stereo (0: off, 1: on) |
56 | mpc_int64_t pcm_samples; | 64 | mpc_uint32_t fast_seek; ///< True if stream supports fast-seeking (sv7) |
57 | mpc_uint32_t max_band; ///< maximum band-index used in stream (0...31) | 65 | mpc_uint32_t block_pwr; ///< Number of frames in a block = 2^block_pwr (sv8) |
58 | mpc_uint32_t is; ///< intensity stereo (0: off, 1: on) | ||
59 | mpc_uint32_t ms; ///< mid/side stereo (0: off, 1: on) | ||
60 | mpc_uint32_t block_size; ///< only needed for SV4...SV6 -> not supported | ||
61 | mpc_uint32_t profile; ///< quality profile of stream | ||
62 | const char* profile_name; ///< name of profile used by stream | ||
63 | //@} | 66 | //@} |
64 | 67 | ||
65 | /// @name replaygain related fields | 68 | /// @name Replaygain properties |
66 | //@{ | 69 | //@{ |
67 | mpc_int16_t gain_title; ///< replaygain title value | 70 | mpc_uint16_t gain_title; ///< Replaygain title value |
68 | mpc_int16_t gain_album; ///< replaygain album value | 71 | mpc_uint16_t gain_album; ///< Replaygain album value |
69 | mpc_uint16_t peak_album; ///< peak album loudness level | 72 | mpc_uint16_t peak_album; ///< Peak album loudness level |
70 | mpc_uint16_t peak_title; ///< peak title loudness level | 73 | mpc_uint16_t peak_title; ///< Peak title loudness level |
71 | //@} | 74 | //@} |
72 | 75 | ||
73 | /// @name true gapless support data | 76 | /// @name True gapless properties |
74 | //@{ | 77 | //@{ |
75 | mpc_uint32_t is_true_gapless; ///< true gapless? (0: no, 1: yes) | 78 | mpc_uint32_t is_true_gapless; ///< True gapless? (0: no, 1: yes) |
76 | mpc_uint32_t last_frame_samples; ///< number of valid samples within last frame | 79 | mpc_uint64_t samples; ///< Number of samples in the stream |
77 | 80 | mpc_uint64_t beg_silence; ///< Number of samples that must not be played at the beginning of the stream | |
78 | mpc_uint32_t encoder_version; ///< version of encoder used | 81 | //@} |
79 | char encoder[256]; ///< encoder name | ||
80 | 82 | ||
81 | mpc_streaminfo_off_t tag_offset; ///< offset to file tags | 83 | /// @name Encoder informations |
82 | mpc_streaminfo_off_t total_file_length; ///< total length of underlying file | 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 | float profile; ///< Quality profile of stream | ||
91 | /* rockbox: not used | ||
92 | const char* profile_name; ///< Name of profile used by stream | ||
93 | */ | ||
83 | //@} | 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 | ||
84 | } mpc_streaminfo; | 100 | } mpc_streaminfo; |
85 | 101 | ||
86 | #endif // _mpcdec_streaminfo_h_ | 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/apps/codecs/libmusepack/synth_filter.c b/apps/codecs/libmusepack/synth_filter.c index 587b88dada..b6caf4a3d7 100644 --- a/apps/codecs/libmusepack/synth_filter.c +++ b/apps/codecs/libmusepack/synth_filter.c | |||
@@ -35,9 +35,10 @@ | |||
35 | /// \file synth_filter.c | 35 | /// \file synth_filter.c |
36 | /// Synthesis functions. | 36 | /// Synthesis functions. |
37 | /// \todo document me | 37 | /// \todo document me |
38 | 38 | #include <string.h> | |
39 | #include "musepack.h" | 39 | #include "mpcdec.h" |
40 | #include "internal.h" | 40 | #include "decoder.h" |
41 | #include "mpcdec_math.h" | ||
41 | 42 | ||
42 | /* C O N S T A N T S */ | 43 | /* C O N S T A N T S */ |
43 | #undef _ | 44 | #undef _ |
@@ -127,7 +128,7 @@ static const MPC_SAMPLE_FORMAT Di_opt [512] ICONST_ATTR = { | |||
127 | *****************************************************************************/ | 128 | *****************************************************************************/ |
128 | void | 129 | void |
129 | mpc_dct32(const MPC_SAMPLE_FORMAT *in, MPC_SAMPLE_FORMAT *v) | 130 | mpc_dct32(const MPC_SAMPLE_FORMAT *in, MPC_SAMPLE_FORMAT *v) |
130 | ICODE_ATTR_MPC_LARGE_IRAM; | 131 | ICODE_ATTR_MPC_LARGE_IRAM; |
131 | 132 | ||
132 | void | 133 | void |
133 | mpc_dct32(const MPC_SAMPLE_FORMAT *in, MPC_SAMPLE_FORMAT *v) | 134 | mpc_dct32(const MPC_SAMPLE_FORMAT *in, MPC_SAMPLE_FORMAT *v) |
@@ -548,27 +549,26 @@ mpc_full_synthesis_filter(MPC_SAMPLE_FORMAT *OutData, MPC_SAMPLE_FORMAT *V, cons | |||
548 | mpc_dct32(Y, V); | 549 | mpc_dct32(Y, V); |
549 | mpc_decoder_windowing_D( OutData, V, Di_opt ); | 550 | mpc_decoder_windowing_D( OutData, V, Di_opt ); |
550 | } | 551 | } |
551 | } | 552 | } |
552 | } | 553 | } |
553 | 554 | ||
554 | void | 555 | void |
555 | mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT *OutData) | 556 | mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT *OutData, |
557 | int num_channels) | ||
556 | { | 558 | { |
559 | (void)num_channels; | ||
560 | |||
557 | /********* left channel ********/ | 561 | /********* left channel ********/ |
558 | memmove(d->V_L + MPC_V_MEM, d->V_L, 960 * sizeof(MPC_SAMPLE_FORMAT) ); | 562 | memmove(d->V_L + MPC_V_MEM, d->V_L, 960 * sizeof(MPC_SAMPLE_FORMAT) ); |
559 | 563 | mpc_full_synthesis_filter(OutData, | |
560 | mpc_full_synthesis_filter( | 564 | (MPC_SAMPLE_FORMAT *)(d->V_L + MPC_V_MEM), |
561 | OutData, | 565 | (MPC_SAMPLE_FORMAT *)(d->Y_L)); |
562 | (MPC_SAMPLE_FORMAT *)(d->V_L + MPC_V_MEM), | ||
563 | (MPC_SAMPLE_FORMAT *)(d->Y_L [0])); | ||
564 | 566 | ||
565 | /******** right channel ********/ | 567 | /******** right channel ********/ |
566 | memmove(d->V_R + MPC_V_MEM, d->V_R, 960 * sizeof(MPC_SAMPLE_FORMAT) ); | 568 | memmove(d->V_R + MPC_V_MEM, d->V_R, 960 * sizeof(MPC_SAMPLE_FORMAT) ); |
567 | 569 | mpc_full_synthesis_filter((OutData == NULL ? NULL : OutData + MPC_FRAME_LENGTH), | |
568 | mpc_full_synthesis_filter( | 570 | (MPC_SAMPLE_FORMAT *)(d->V_R + MPC_V_MEM), |
569 | (OutData == NULL ? NULL : OutData + MPC_FRAME_LENGTH), | 571 | (MPC_SAMPLE_FORMAT *)(d->Y_R)); |
570 | (MPC_SAMPLE_FORMAT *)(d->V_R + MPC_V_MEM), | ||
571 | (MPC_SAMPLE_FORMAT *)(d->Y_R [0])); | ||
572 | } | 572 | } |
573 | 573 | ||
574 | /*******************************************/ | 574 | /*******************************************/ |
@@ -577,7 +577,7 @@ mpc_decoder_synthese_filter_float(mpc_decoder *d, MPC_SAMPLE_FORMAT *OutData) | |||
577 | /* */ | 577 | /* */ |
578 | /*******************************************/ | 578 | /*******************************************/ |
579 | 579 | ||
580 | static const unsigned char Parity [256] ICONST_ATTR = { // parity | 580 | static const unsigned char Parity [256] = { // parity |
581 | 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, | 581 | 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, |
582 | 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, | 582 | 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, |
583 | 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, | 583 | 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, |
diff --git a/apps/codecs/libmusepack/synth_filter_arm.S b/apps/codecs/libmusepack/synth_filter_arm.S index 51526040ca..3f78469948 100644 --- a/apps/codecs/libmusepack/synth_filter_arm.S +++ b/apps/codecs/libmusepack/synth_filter_arm.S | |||
@@ -18,8 +18,6 @@ | |||
18 | * KIND, either express or implied. | 18 | * KIND, either express or implied. |
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | |||
22 | #include "mpc_config.h" | ||
23 | 21 | ||
24 | .section .text, "ax", %progbits | 22 | .section .text, "ax", %progbits |
25 | 23 | ||
diff --git a/apps/codecs/mpc.c b/apps/codecs/mpc.c index 250a03fbfd..b9ae558c67 100644 --- a/apps/codecs/mpc.c +++ b/apps/codecs/mpc.c | |||
@@ -20,79 +20,81 @@ | |||
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | #include "codeclib.h" | 22 | #include "codeclib.h" |
23 | #include <codecs/libmusepack/musepack.h> | 23 | #include <codecs/libmusepack/mpcdec.h> |
24 | #include <codecs/libmusepack/internal.h> | ||
24 | 25 | ||
25 | CODEC_HEADER | 26 | CODEC_HEADER |
26 | 27 | ||
27 | mpc_decoder decoder IBSS_ATTR; | 28 | MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH] IBSS_ATTR; |
28 | 29 | ||
29 | /* Our implementations of the mpc_reader callback functions. */ | 30 | /* Our implementations of the mpc_reader callback functions. */ |
30 | static mpc_int32_t read_impl(void *data, void *ptr, mpc_int32_t size) | 31 | static mpc_int32_t read_impl(mpc_reader *reader, void *ptr, mpc_int32_t size) |
31 | { | 32 | { |
32 | struct codec_api *ci = (struct codec_api *)data; | 33 | struct codec_api *ci = (struct codec_api *)(reader->data); |
33 | |||
34 | return ((mpc_int32_t)(ci->read_filebuf(ptr, size))); | 34 | return ((mpc_int32_t)(ci->read_filebuf(ptr, size))); |
35 | } | 35 | } |
36 | 36 | ||
37 | static mpc_bool_t seek_impl(void *data, mpc_int32_t offset) | 37 | static mpc_bool_t seek_impl(mpc_reader *reader, mpc_int32_t offset) |
38 | { | 38 | { |
39 | struct codec_api *ci = (struct codec_api *)data; | 39 | struct codec_api *ci = (struct codec_api *)(reader->data); |
40 | 40 | ||
41 | /* WARNING: assumes we don't need to skip too far into the past, | 41 | /* WARNING: assumes we don't need to skip too far into the past, |
42 | this might not be supported by the buffering layer yet */ | 42 | this might not be supported by the buffering layer yet */ |
43 | return ci->seek_buffer(offset); | 43 | return ci->seek_buffer(offset); |
44 | } | 44 | } |
45 | 45 | ||
46 | static mpc_int32_t tell_impl(void *data) | 46 | static mpc_int32_t tell_impl(mpc_reader *reader) |
47 | { | 47 | { |
48 | struct codec_api *ci = (struct codec_api *)data; | 48 | struct codec_api *ci = (struct codec_api *)(reader->data); |
49 | 49 | ||
50 | return ci->curpos; | 50 | return ci->curpos; |
51 | } | 51 | } |
52 | 52 | ||
53 | static mpc_int32_t get_size_impl(void *data) | 53 | static mpc_int32_t get_size_impl(mpc_reader *reader) |
54 | { | 54 | { |
55 | struct codec_api *ci = (struct codec_api *)data; | 55 | struct codec_api *ci = (struct codec_api *)(reader->data); |
56 | 56 | ||
57 | return ci->filesize; | 57 | return ci->filesize; |
58 | } | 58 | } |
59 | 59 | ||
60 | static mpc_bool_t canseek_impl(void *data) | 60 | static mpc_bool_t canseek_impl(mpc_reader *reader) |
61 | { | 61 | { |
62 | (void)data; | 62 | (void)reader; |
63 | 63 | ||
64 | /* doesn't much matter, libmusepack ignores this anyway */ | 64 | /* doesn't much matter, libmusepack ignores this anyway */ |
65 | return true; | 65 | return true; |
66 | } | 66 | } |
67 | 67 | ||
68 | MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH] | ||
69 | IBSS_ATTR_MPC_SAMPLE_BUF; | ||
70 | |||
71 | /* this is the codec entry point */ | 68 | /* this is the codec entry point */ |
72 | enum codec_status codec_main(void) | 69 | enum codec_status codec_main(void) |
73 | { | 70 | { |
74 | mpc_int64_t samplesdone; | 71 | mpc_int64_t samplesdone; |
75 | uint32_t frequency; /* 0.1 kHz accuracy */ | 72 | uint32_t frequency; /* 0.1 kHz accuracy */ |
76 | uint32_t elapsed_time; /* milliseconds */ | 73 | uint32_t elapsed_time; /* milliseconds */ |
77 | unsigned status; | 74 | mpc_status status; |
78 | mpc_reader reader; | 75 | mpc_reader reader; |
79 | mpc_streaminfo info; | 76 | mpc_streaminfo info; |
77 | mpc_frame_info frame; | ||
78 | mpc_demux *demux = NULL; | ||
80 | int retval = CODEC_OK; | 79 | int retval = CODEC_OK; |
81 | 80 | ||
81 | frame.buffer = sample_buffer; | ||
82 | |||
82 | /* musepack's sample representation is 18.14 | 83 | /* musepack's sample representation is 18.14 |
83 | * DSP_SET_SAMPLE_DEPTH = 14 (FRACT) + 16 (NATIVE) - 1 (SIGN) = 29 */ | 84 | * DSP_SET_SAMPLE_DEPTH = 14 (FRACT) + 16 (NATIVE) - 1 (SIGN) = 29 */ |
84 | ci->configure(DSP_SET_SAMPLE_DEPTH, 29); | 85 | ci->configure(DSP_SET_SAMPLE_DEPTH, 29); |
85 | 86 | ||
86 | /* Create a decoder instance */ | 87 | /* Create a decoder instance */ |
87 | reader.read = read_impl; | 88 | reader.read = read_impl; |
88 | reader.seek = seek_impl; | 89 | reader.seek = seek_impl; |
89 | reader.tell = tell_impl; | 90 | reader.tell = tell_impl; |
90 | reader.get_size = get_size_impl; | 91 | reader.get_size = get_size_impl; |
91 | reader.canseek = canseek_impl; | 92 | reader.canseek = canseek_impl; |
92 | reader.data = ci; | 93 | reader.data = ci; |
93 | 94 | ||
94 | next_track: | 95 | next_track: |
95 | if (codec_init()) { | 96 | if (codec_init()) |
97 | { | ||
96 | retval = CODEC_ERROR; | 98 | retval = CODEC_ERROR; |
97 | goto exit; | 99 | goto exit; |
98 | } | 100 | } |
@@ -102,42 +104,45 @@ next_track: | |||
102 | 104 | ||
103 | samplesdone = ci->id3->offset; | 105 | samplesdone = ci->id3->offset; |
104 | 106 | ||
105 | /* read file's streaminfo data */ | 107 | /* initialize demux/decoder */ |
106 | mpc_streaminfo_init(&info); | 108 | demux = mpc_demux_init(&reader); |
107 | if (mpc_streaminfo_read(&info, &reader) != ERROR_CODE_OK) { | 109 | if (NULL == demux) |
110 | { | ||
108 | retval = CODEC_ERROR; | 111 | retval = CODEC_ERROR; |
109 | goto done; | 112 | goto done; |
110 | } | 113 | } |
114 | /* read file's streaminfo data */ | ||
115 | mpc_demux_get_info(demux, &info); | ||
116 | |||
117 | |||
111 | frequency = info.sample_freq / 100; /* 0.1 kHz accuracy */ | 118 | frequency = info.sample_freq / 100; /* 0.1 kHz accuracy */ |
112 | ci->configure(DSP_SWITCH_FREQUENCY, info.sample_freq); | 119 | ci->configure(DSP_SWITCH_FREQUENCY, info.sample_freq); |
113 | 120 | ||
114 | /* set playback engine up for correct number of channels */ | 121 | /* set playback engine up for correct number of channels */ |
115 | /* NOTE: current musepack format only allows for stereo files | 122 | /* NOTE: current musepack format only allows for stereo files |
116 | but code is here to handle other configurations anyway */ | 123 | but code is here to handle other configurations anyway */ |
117 | if (info.channels == 2) | 124 | if (info.channels == 2) |
118 | ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); | 125 | ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); |
119 | else if (info.channels == 1) | 126 | else if (info.channels == 1) |
120 | ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); | 127 | ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); |
121 | else { | 128 | else |
129 | { | ||
122 | retval = CODEC_ERROR; | 130 | retval = CODEC_ERROR; |
123 | goto done; | 131 | goto done; |
124 | } | 132 | } |
125 | 133 | ||
126 | codec_set_replaygain(ci->id3); | 134 | codec_set_replaygain(ci->id3); |
127 | /* instantiate a decoder with our file reader */ | 135 | |
128 | mpc_decoder_setup(&decoder, &reader); | ||
129 | if (!mpc_decoder_initialize(&decoder, &info)) { | ||
130 | retval = CODEC_ERROR; | ||
131 | goto done; | ||
132 | } | ||
133 | |||
134 | /* Resume to saved sample offset. */ | 136 | /* Resume to saved sample offset. */ |
135 | if (samplesdone > 0) { | 137 | if (samplesdone > 0) { |
136 | /* hack to improve seek time if filebuf goes empty */ | 138 | /* hack to improve seek time if filebuf goes empty */ |
137 | if (mpc_decoder_seek_sample(&decoder, samplesdone)) { | 139 | if (mpc_demux_seek_sample(demux, samplesdone) == MPC_STATUS_OK) |
140 | { | ||
138 | elapsed_time = (samplesdone*10)/frequency; | 141 | elapsed_time = (samplesdone*10)/frequency; |
139 | ci->set_elapsed(elapsed_time); | 142 | ci->set_elapsed(elapsed_time); |
140 | } else { | 143 | } |
144 | else | ||
145 | { | ||
141 | samplesdone = 0; | 146 | samplesdone = 0; |
142 | } | 147 | } |
143 | /* reset chunksize */ | 148 | /* reset chunksize */ |
@@ -146,10 +151,12 @@ next_track: | |||
146 | /* This is the decoding loop. */ | 151 | /* This is the decoding loop. */ |
147 | do { | 152 | do { |
148 | /* Complete seek handler. */ | 153 | /* Complete seek handler. */ |
149 | if (ci->seek_time) { | 154 | if (ci->seek_time) |
155 | { | ||
150 | /* hack to improve seek time if filebuf goes empty */ | 156 | /* hack to improve seek time if filebuf goes empty */ |
151 | mpc_int64_t new_offset = ((ci->seek_time - 1)/10)*frequency; | 157 | mpc_int64_t new_offset = ((ci->seek_time - 1)/10)*frequency; |
152 | if (mpc_decoder_seek_sample(&decoder, new_offset)) { | 158 | if (mpc_demux_seek_sample(demux, new_offset) == MPC_STATUS_OK) |
159 | { | ||
153 | samplesdone = new_offset; | 160 | samplesdone = new_offset; |
154 | ci->set_elapsed(ci->seek_time); | 161 | ci->set_elapsed(ci->seek_time); |
155 | } | 162 | } |
@@ -159,24 +166,24 @@ next_track: | |||
159 | if (ci->stop_codec || ci->new_track) | 166 | if (ci->stop_codec || ci->new_track) |
160 | break; | 167 | break; |
161 | 168 | ||
162 | status = mpc_decoder_decode(&decoder, sample_buffer, NULL, NULL); | 169 | status = mpc_demux_decode(demux, &frame); |
163 | ci->yield(); | 170 | ci->yield(); |
164 | if (status == 0) /* end of file reached */ | 171 | if (frame.bits == -1) /* decoding stopped */ |
165 | goto done; | 172 | { |
166 | if (status == (unsigned)(-1)) { /* decode error */ | 173 | retval = (status == MPC_STATUS_OK) ? CODEC_OK : CODEC_ERROR; |
167 | retval = CODEC_ERROR; | ||
168 | goto done; | 174 | goto done; |
169 | } else { | 175 | } |
170 | ci->pcmbuf_insert(sample_buffer, | 176 | else |
171 | sample_buffer + MPC_FRAME_LENGTH, | 177 | { |
172 | status); | 178 | ci->pcmbuf_insert(frame.buffer, |
173 | samplesdone += status; | 179 | frame.buffer + MPC_FRAME_LENGTH, |
180 | frame.samples); | ||
181 | samplesdone += frame.samples; | ||
174 | elapsed_time = (samplesdone*10)/frequency; | 182 | elapsed_time = (samplesdone*10)/frequency; |
175 | ci->set_elapsed(elapsed_time); | 183 | ci->set_elapsed(elapsed_time); |
176 | ci->set_offset(samplesdone); | 184 | ci->set_offset(samplesdone); |
177 | } | 185 | } |
178 | } while (status != 0); | 186 | } while (true); |
179 | retval = CODEC_OK; | ||
180 | 187 | ||
181 | done: | 188 | done: |
182 | if (ci->request_next_track()) | 189 | if (ci->request_next_track()) |
diff --git a/apps/metadata/mpc.c b/apps/metadata/mpc.c index 3f8907a934..9894bb8b54 100644 --- a/apps/metadata/mpc.c +++ b/apps/metadata/mpc.c | |||
@@ -28,15 +28,48 @@ | |||
28 | #include "logf.h" | 28 | #include "logf.h" |
29 | #include "replaygain.h" | 29 | #include "replaygain.h" |
30 | 30 | ||
31 | static int set_replaygain(struct mp3entry* id3, bool album, long value, | 31 | #include "fixedpoint.h" |
32 | long used) | 32 | #include <stdlib.h> |
33 | #include <stdbool.h> | ||
34 | #include <inttypes.h> | ||
35 | |||
36 | /* Needed for replay gain in sv8, please search MPC_OLD_GAIN_REF in libmusepack */ | ||
37 | #define SV8_TO_SV7_CONVERT_GAIN (64.82*100) | ||
38 | |||
39 | static int set_replaygain_sv7(struct mp3entry* id3, | ||
40 | bool album, | ||
41 | long value, | ||
42 | long used) | ||
33 | { | 43 | { |
34 | long gain = (int16_t) ((value >> 16) & 0xffff); | 44 | long gain = (int16_t) ((value >> 16) & 0xffff); |
35 | long peak = (uint16_t) (value & 0xffff); | 45 | long peak = (uint16_t) (value & 0xffff); |
36 | 46 | ||
47 | /* Remark: mpc sv7 outputs peak as amplitude, not as dB. The following | ||
48 | * useage of peak is not correct and needs to be fixed. */ | ||
49 | |||
37 | /* We use a peak value of 0 to indicate a given gain type isn't used. */ | 50 | /* We use a peak value of 0 to indicate a given gain type isn't used. */ |
38 | if (peak != 0) | 51 | if (peak != 0) { |
39 | { | 52 | /* Use the Xing TOC field to store ReplayGain strings for use in the |
53 | * ID3 screen, since Musepack files shouldn't need to use it in any | ||
54 | * other way. | ||
55 | */ | ||
56 | used += parse_replaygain_int(album, gain * 512 / 100, peak << 9, | ||
57 | id3, id3->toc + used, sizeof(id3->toc) - used); | ||
58 | } | ||
59 | |||
60 | return used; | ||
61 | } | ||
62 | |||
63 | static int set_replaygain_sv8(struct mp3entry* id3, | ||
64 | bool album, | ||
65 | long gain, | ||
66 | long peak, | ||
67 | long used) | ||
68 | { | ||
69 | gain = (long)(SV8_TO_SV7_CONVERT_GAIN - (gain*100./256.)); | ||
70 | |||
71 | /* We use a peak value of 0 to indicate a given gain type isn't used. */ | ||
72 | if (peak != 0) { | ||
40 | /* Use the Xing TOC field to store ReplayGain strings for use in the | 73 | /* Use the Xing TOC field to store ReplayGain strings for use in the |
41 | * ID3 screen, since Musepack files shouldn't need to use it in any | 74 | * ID3 screen, since Musepack files shouldn't need to use it in any |
42 | * other way. | 75 | * other way. |
@@ -48,9 +81,23 @@ static int set_replaygain(struct mp3entry* id3, bool album, long value, | |||
48 | return used; | 81 | return used; |
49 | } | 82 | } |
50 | 83 | ||
84 | static int sv8_get_size(uint8_t *buffer, int index, uint64_t *p_size) | ||
85 | { | ||
86 | unsigned char tmp; | ||
87 | uint64_t size = 0; | ||
88 | |||
89 | do { | ||
90 | tmp = buffer[index++]; | ||
91 | size = (size << 7) | (tmp & 0x7F); | ||
92 | } while((tmp & 0x80)); | ||
93 | |||
94 | *p_size = size; | ||
95 | return index; | ||
96 | } | ||
97 | |||
51 | bool get_musepack_metadata(int fd, struct mp3entry *id3) | 98 | bool get_musepack_metadata(int fd, struct mp3entry *id3) |
52 | { | 99 | { |
53 | static const int32_t sfreqs_sv7[4] = { 44100, 48000, 37800, 32000 }; | 100 | static const int32_t sfreqs[4] = { 44100, 48000, 37800, 32000 }; |
54 | uint32_t header[8]; | 101 | uint32_t header[8]; |
55 | uint64_t samples = 0; | 102 | uint64_t samples = 0; |
56 | int i; | 103 | int i; |
@@ -63,7 +110,6 @@ bool get_musepack_metadata(int fd, struct mp3entry *id3) | |||
63 | header[i] = letoh32(header[i]); | 110 | header[i] = letoh32(header[i]); |
64 | if (!memcmp(header, "MP+", 3)) { /* Compare to sig "MP+" */ | 111 | if (!memcmp(header, "MP+", 3)) { /* Compare to sig "MP+" */ |
65 | unsigned int streamversion; | 112 | unsigned int streamversion; |
66 | |||
67 | header[0] = letoh32(header[0]); | 113 | header[0] = letoh32(header[0]); |
68 | streamversion = (header[0] >> 24) & 15; | 114 | streamversion = (header[0] >> 24) & 15; |
69 | if (streamversion == 7) { | 115 | if (streamversion == 7) { |
@@ -71,20 +117,78 @@ bool get_musepack_metadata(int fd, struct mp3entry *id3) | |||
71 | unsigned int last_frame_samples = (header[5] >> 20) & 0x07ff; | 117 | unsigned int last_frame_samples = (header[5] >> 20) & 0x07ff; |
72 | unsigned int bufused = 0; | 118 | unsigned int bufused = 0; |
73 | 119 | ||
74 | id3->frequency = sfreqs_sv7[(header[2] >> 16) & 0x0003]; | 120 | id3->frequency = sfreqs[(header[2] >> 16) & 0x0003]; |
75 | samples = (uint64_t)header[1]*1152; /* 1152 is mpc frame size */ | 121 | samples = (uint64_t)header[1]*1152; /* 1152 is mpc frame size */ |
76 | if (gapless) | 122 | if (gapless) |
77 | samples -= 1152 - last_frame_samples; | 123 | samples -= 1152 - last_frame_samples; |
78 | else | 124 | else |
79 | samples -= 481; /* Musepack subband synth filter delay */ | 125 | samples -= 481; /* Musepack subband synth filter delay */ |
80 | 126 | ||
81 | bufused = set_replaygain(id3, false, header[3], bufused); | 127 | bufused = set_replaygain_sv7(id3, false, header[3], bufused); |
82 | bufused = set_replaygain(id3, true, header[4], bufused); | 128 | bufused = set_replaygain_sv7(id3, true , header[4], bufused); |
83 | } else { | 129 | } else { |
84 | return false; /* only SV7 is allowed within a "MP+" signature */ | 130 | return false; /* only SV7 is allowed within a "MP+" signature */ |
85 | } | 131 | } |
86 | } else if (!memcmp(header, "MPCK", 4)) { /* Compare to sig "MPCK" */ | 132 | } else if (!memcmp(header, "MPCK", 4)) { /* Compare to sig "MPCK" */ |
87 | return false; /* SV8 is not supported yet */ | 133 | uint8_t sv8_header[32]; |
134 | /* 4 bytes 'MPCK' */ | ||
135 | lseek(fd, 4, SEEK_SET); | ||
136 | if (read(fd, sv8_header, 2) != 2) return false; /* read frame ID */ | ||
137 | if (!memcmp(sv8_header, "SH", 2)) { /* Stream Header ID */ | ||
138 | int32_t k = 0; | ||
139 | uint32_t streamversion; | ||
140 | uint64_t size = 0; | ||
141 | |||
142 | /* 4 bytes 'MPCK' + 4 bytes crc + 2 'SH' */ | ||
143 | lseek(fd, 10, SEEK_SET); | ||
144 | if (read(fd, sv8_header, 32) != 32) return false; | ||
145 | |||
146 | /* dummy read the correct amount of bits within the header data. */ | ||
147 | size = sv8_header[k++]; | ||
148 | |||
149 | /* Read stream version */ | ||
150 | streamversion = sv8_header[k++]; | ||
151 | if (streamversion != 8) return false; /* Only SV8 is allowed. */ | ||
152 | |||
153 | /* Number of samples */ | ||
154 | k = sv8_get_size(sv8_header, k, &samples); | ||
155 | |||
156 | /* Number of leading zero-samples */ | ||
157 | k = sv8_get_size(sv8_header, k, &size); | ||
158 | |||
159 | /* Sampling frequency */ | ||
160 | id3->frequency = sfreqs[(sv8_header[k++] >> 5) & 0x0003]; | ||
161 | |||
162 | /* Number of channels */ | ||
163 | id3->channels = (sv8_header[k++] >> 4) + 1; | ||
164 | |||
165 | if (!memcmp(sv8_header+k, "RG", 2)) { /* Replay Gain ID */ | ||
166 | long peak, gain; | ||
167 | int bufused = 0; | ||
168 | |||
169 | k += 2; /* 2 bytes 'RG' */ | ||
170 | |||
171 | /* sv8_get_size must be called to skip the right amount of | ||
172 | * bits within the header data. */ | ||
173 | k = sv8_get_size(sv8_header, k, &size); | ||
174 | |||
175 | /* Read and set replay gain */ | ||
176 | if (sv8_header[k++] == 1) { | ||
177 | /* Title's peak and gain */ | ||
178 | gain = (int16_t) ((sv8_header[k]<<8) + sv8_header[k+1]); k += 2; | ||
179 | peak = (uint16_t)((sv8_header[k]<<8) + sv8_header[k+1]); k += 2; | ||
180 | bufused += set_replaygain_sv8(id3, false, gain, peak, bufused); | ||
181 | |||
182 | /* Album's peak and gain */ | ||
183 | gain = (int16_t) ((sv8_header[k]<<8) + sv8_header[k+1]); k += 2; | ||
184 | peak = (uint16_t)((sv8_header[k]<<8) + sv8_header[k+1]); k += 2; | ||
185 | bufused += set_replaygain_sv8(id3, true , gain, peak, bufused); | ||
186 | } | ||
187 | } | ||
188 | } else { | ||
189 | /* No sv8 stream header found */ | ||
190 | return false; | ||
191 | } | ||
88 | } else { | 192 | } else { |
89 | return false; /* SV4-6 is not supported anymore */ | 193 | return false; /* SV4-6 is not supported anymore */ |
90 | } | 194 | } |
diff --git a/manual/appendix/file_formats.tex b/manual/appendix/file_formats.tex index 92e2a06713..a60e7fc08d 100644 --- a/manual/appendix/file_formats.tex +++ b/manual/appendix/file_formats.tex | |||
@@ -114,7 +114,7 @@ | |||
114 | ADX & \fname{.adx} & \\ | 114 | ADX & \fname{.adx} & \\ |
115 | Advanced Audio Coding & \fname{.m4a, .m4b, .mp4} & \\ | 115 | Advanced Audio Coding & \fname{.m4a, .m4b, .mp4} & \\ |
116 | MPEG audio & \fname{.mp1, .mpa, .mp2, .mp3} & \\ | 116 | MPEG audio & \fname{.mp1, .mpa, .mp2, .mp3} & \\ |
117 | Musepack & \fname{.mpc} & Supports SV7 only \\ | 117 | Musepack & \fname{.mpc} & Supports SV7 and SV8 in mono/stereo \\ |
118 | OGG/Vorbis & \fname{.ogg, .oga} & Some old ``floor 0'' files may crash Rockbox. \\ | 118 | OGG/Vorbis & \fname{.ogg, .oga} & Some old ``floor 0'' files may crash Rockbox. \\ |
119 | Sony Audio & \fname{.oma, .aa3} & \\ | 119 | Sony Audio & \fname{.oma, .aa3} & \\ |
120 | RealAudio & \fname{.rm, .ra, .rmvb} & \\ | 120 | RealAudio & \fname{.rm, .ra, .rmvb} & \\ |