Browse code

Musepack SV8 demuxer and decoder

Originally committed as revision 10938 to svn://svn.ffmpeg.org/ffmpeg/trunk

Kostya Shishkov authored on 2007/11/07 14:35:46
Showing 11 changed files
... ...
@@ -314,7 +314,7 @@ following image formats are supported:
314 314
 @tab Codec used in Delphine Software games.
315 315
 @item Intel Music Coder      @tab      @tab X
316 316
 @item Musepack               @tab      @tab X
317
-@tab Only SV7 is supported
317
+@tab SV7 and SV8 are supported
318 318
 @item DT$ Coherent Audio     @tab      @tab X
319 319
 @item ATRAC 3                @tab      @tab X
320 320
 @item Monkey's Audio         @tab      @tab X @tab Only versions 3.97-3.99 are supported
... ...
@@ -115,6 +115,7 @@ OBJS-$(CONFIG_MP3_DECODER)             += mpegaudiodec.o mpegaudiodecheader.o mp
115 115
 OBJS-$(CONFIG_MP3ADU_DECODER)          += mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o
116 116
 OBJS-$(CONFIG_MP3ON4_DECODER)          += mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o
117 117
 OBJS-$(CONFIG_MPC7_DECODER)            += mpc7.o mpc.o mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o
118
+OBJS-$(CONFIG_MPC8_DECODER)            += mpc8.o mpc.o mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o
118 119
 OBJS-$(CONFIG_MPEG1VIDEO_ENCODER)      += mpeg12enc.o mpeg12data.o mpegvideo_enc.o motion_est.o ratecontrol.o
119 120
 OBJS-$(CONFIG_MPEG2VIDEO_ENCODER)      += mpeg12enc.o mpeg12data.o mpegvideo_enc.o motion_est.o ratecontrol.o
120 121
 OBJS-$(CONFIG_MPEG4_DECODER)           += h263dec.o h263.o
... ...
@@ -187,6 +187,7 @@ void avcodec_register_all(void)
187 187
     REGISTER_DECODER (MP3ADU, mp3adu);
188 188
     REGISTER_DECODER (MP3ON4, mp3on4);
189 189
     REGISTER_DECODER (MPC7, mpc7);
190
+    REGISTER_DECODER (MPC8, mpc8);
190 191
     REGISTER_DECODER (NELLYMOSER, nellymoser);
191 192
     REGISTER_DECODER (QDM2, qdm2);
192 193
     REGISTER_DECODER (RA_144, ra_144);
... ...
@@ -33,8 +33,8 @@
33 33
 #define AV_STRINGIFY(s)         AV_TOSTRING(s)
34 34
 #define AV_TOSTRING(s) #s
35 35
 
36
-#define LIBAVCODEC_VERSION_INT  ((51<<16)+(47<<8)+2)
37
-#define LIBAVCODEC_VERSION      51.47.2
36
+#define LIBAVCODEC_VERSION_INT  ((51<<16)+(48<<8)+0)
37
+#define LIBAVCODEC_VERSION      51.48.0
38 38
 #define LIBAVCODEC_BUILD        LIBAVCODEC_VERSION_INT
39 39
 
40 40
 #define LIBAVCODEC_IDENT        "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
... ...
@@ -272,6 +272,7 @@ enum CodecID {
272 272
     CODEC_ID_VOXWARE,
273 273
     CODEC_ID_APE,
274 274
     CODEC_ID_NELLYMOSER,
275
+    CODEC_ID_MUSEPACK8,
275 276
 
276 277
     /* subtitle codecs */
277 278
     CODEC_ID_DVD_SUBTITLE= 0x17000,
278 279
new file mode 100644
... ...
@@ -0,0 +1,364 @@
0
+/*
1
+ * Musepack SV8 decoder
2
+ * Copyright (c) 2007 Konstantin Shishkov
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+/**
22
+ * @file mpc8.c Musepack SV8 decoder
23
+ * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples
24
+ * divided into 32 subbands.
25
+ */
26
+
27
+#include "avcodec.h"
28
+#include "bitstream.h"
29
+#include "dsputil.h"
30
+#include "random.h"
31
+
32
+#ifdef CONFIG_MPEGAUDIO_HP
33
+#define USE_HIGHPRECISION
34
+#endif
35
+#include "mpegaudio.h"
36
+
37
+#include "mpc.h"
38
+#include "mpcdata.h"
39
+#include "mpc8data.h"
40
+#include "mpc8huff.h"
41
+
42
+static VLC band_vlc, scfi_vlc[2], dscf_vlc[2], res_vlc[2];
43
+static VLC q1_vlc, q2_vlc[2], q3_vlc[2], quant_vlc[4][2], q9up_vlc;
44
+
45
+static const int q3_offsets[2] = { MPC8_Q3_OFFSET, MPC8_Q4_OFFSET };
46
+static const int quant_offsets[6] = { MPC8_Q5_OFFSET, MPC8_Q6_OFFSET, MPC8_Q7_OFFSET, MPC8_Q8_OFFSET };
47
+
48
+static inline int mpc8_dec_base(GetBitContext *gb, int k, int n)
49
+{
50
+    int code = get_bits(gb, mpc8_cnk_len[k-1][n-1] - 1);
51
+
52
+    if (code >= mpc8_cnk_lost[k-1][n-1])
53
+        code = ((code << 1) | get_bits1(gb)) - mpc8_cnk_lost[k-1][n-1];
54
+
55
+    return code;
56
+}
57
+
58
+static inline int mpc8_dec_enum(GetBitContext *gb, int k, int n)
59
+{
60
+    int bits = 0;
61
+    const uint32_t * C = mpc8_cnk[k-1];
62
+    int code = mpc8_dec_base(gb, k, n);
63
+
64
+    do {
65
+        n--;
66
+        if (code >= C[n]) {
67
+            bits |= 1 << n;
68
+            code -= C[n];
69
+            C -= 32;
70
+            k--;
71
+        }
72
+    } while(k > 0);
73
+
74
+    return bits;
75
+}
76
+
77
+static inline int mpc8_get_mod_golomb(GetBitContext *gb, int m)
78
+{
79
+    if(mpc8_cnk_len[0][m] < 1) return 0;
80
+    return mpc8_dec_base(gb, 1, m+1);
81
+}
82
+
83
+static int mpc8_get_mask(GetBitContext *gb, int size, int t)
84
+{
85
+    int mask = 0;
86
+
87
+    if(t && t != size)
88
+         mask = mpc8_dec_enum(gb, FFMIN(t, size - t), size);
89
+    if((t << 1) > size) mask = ~mask;
90
+
91
+    return mask;
92
+}
93
+
94
+static int mpc8_decode_init(AVCodecContext * avctx)
95
+{
96
+    int i;
97
+    MPCContext *c = avctx->priv_data;
98
+    GetBitContext gb;
99
+    static int vlc_inited = 0;
100
+
101
+    if(avctx->extradata_size < 2){
102
+        av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size);
103
+        return -1;
104
+    }
105
+    memset(c->oldDSCF, 0, sizeof(c->oldDSCF));
106
+    av_init_random(0xDEADBEEF, &c->rnd);
107
+    dsputil_init(&c->dsp, avctx);
108
+
109
+    ff_mpc_init();
110
+
111
+    init_get_bits(&gb, avctx->extradata, 16);
112
+
113
+    skip_bits(&gb, 3);//sample rate
114
+    c->maxbands = get_bits(&gb, 5) + 1;
115
+    skip_bits(&gb, 4);//channels
116
+    c->MSS = get_bits1(&gb);
117
+    c->frames = 1 << (get_bits(&gb, 3) * 2);
118
+
119
+    if(vlc_inited) return 0;
120
+    av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
121
+
122
+    init_vlc(&band_vlc, MPC8_BANDS_BITS, MPC8_BANDS_SIZE,
123
+             mpc8_bands_bits,  1, 1,
124
+             mpc8_bands_codes, 1, 1, INIT_VLC_USE_STATIC);
125
+
126
+    init_vlc(&q1_vlc, MPC8_Q1_BITS, MPC8_Q1_SIZE,
127
+             mpc8_q1_bits,  1, 1,
128
+             mpc8_q1_codes, 1, 1, INIT_VLC_USE_STATIC);
129
+    init_vlc(&q9up_vlc, MPC8_Q9UP_BITS, MPC8_Q9UP_SIZE,
130
+             mpc8_q9up_bits,  1, 1,
131
+             mpc8_q9up_codes, 1, 1, INIT_VLC_USE_STATIC);
132
+
133
+    init_vlc(&scfi_vlc[0], MPC8_SCFI0_BITS, MPC8_SCFI0_SIZE,
134
+             mpc8_scfi0_bits,  1, 1,
135
+             mpc8_scfi0_codes, 1, 1, INIT_VLC_USE_STATIC);
136
+    init_vlc(&scfi_vlc[1], MPC8_SCFI1_BITS, MPC8_SCFI1_SIZE,
137
+             mpc8_scfi1_bits,  1, 1,
138
+             mpc8_scfi1_codes, 1, 1, INIT_VLC_USE_STATIC);
139
+
140
+    init_vlc(&dscf_vlc[0], MPC8_DSCF0_BITS, MPC8_DSCF0_SIZE,
141
+             mpc8_dscf0_bits,  1, 1,
142
+             mpc8_dscf0_codes, 1, 1, INIT_VLC_USE_STATIC);
143
+    init_vlc(&dscf_vlc[1], MPC8_DSCF1_BITS, MPC8_DSCF1_SIZE,
144
+             mpc8_dscf1_bits,  1, 1,
145
+             mpc8_dscf1_codes, 1, 1, INIT_VLC_USE_STATIC);
146
+
147
+    init_vlc_sparse(&q3_vlc[0], MPC8_Q3_BITS, MPC8_Q3_SIZE,
148
+             mpc8_q3_bits,  1, 1,
149
+             mpc8_q3_codes, 1, 1,
150
+             mpc8_q3_syms,  1, 1, INIT_VLC_USE_STATIC);
151
+    init_vlc_sparse(&q3_vlc[1], MPC8_Q4_BITS, MPC8_Q4_SIZE,
152
+             mpc8_q4_bits,  1, 1,
153
+             mpc8_q4_codes, 1, 1,
154
+             mpc8_q4_syms,  1, 1, INIT_VLC_USE_STATIC);
155
+
156
+    for(i = 0; i < 2; i++){
157
+        init_vlc(&res_vlc[i], MPC8_RES_BITS, MPC8_RES_SIZE,
158
+                 &mpc8_res_bits[i],  1, 1,
159
+                 &mpc8_res_codes[i], 1, 1, INIT_VLC_USE_STATIC);
160
+
161
+        init_vlc(&q2_vlc[i], MPC8_Q2_BITS, MPC8_Q2_SIZE,
162
+                 &mpc8_q2_bits[i],  1, 1,
163
+                 &mpc8_q2_codes[i], 1, 1, INIT_VLC_USE_STATIC);
164
+
165
+        init_vlc(&quant_vlc[0][i], MPC8_Q5_BITS, MPC8_Q5_SIZE,
166
+                 &mpc8_q5_bits[i],  1, 1,
167
+                 &mpc8_q5_codes[i], 1, 1, INIT_VLC_USE_STATIC);
168
+        init_vlc(&quant_vlc[1][i], MPC8_Q6_BITS, MPC8_Q6_SIZE,
169
+                 &mpc8_q6_bits[i],  1, 1,
170
+                 &mpc8_q6_codes[i], 1, 1, INIT_VLC_USE_STATIC);
171
+        init_vlc(&quant_vlc[2][i], MPC8_Q7_BITS, MPC8_Q7_SIZE,
172
+                 &mpc8_q7_bits[i],  1, 1,
173
+                 &mpc8_q7_codes[i], 1, 1, INIT_VLC_USE_STATIC);
174
+        init_vlc(&quant_vlc[3][i], MPC8_Q8_BITS, MPC8_Q8_SIZE,
175
+                 &mpc8_q8_bits[i],  1, 1,
176
+                 &mpc8_q8_codes[i], 1, 1, INIT_VLC_USE_STATIC);
177
+    }
178
+    vlc_inited = 1;
179
+    return 0;
180
+}
181
+
182
+static int mpc8_decode_frame(AVCodecContext * avctx,
183
+                            void *data, int *data_size,
184
+                            uint8_t * buf, int buf_size)
185
+{
186
+    MPCContext *c = avctx->priv_data;
187
+    GetBitContext gb2, *gb = &gb2;
188
+    int i, j, k, ch, cnt, res, t;
189
+    Band *bands = c->bands;
190
+    int off;
191
+    int maxband, keyframe;
192
+    int last[2];
193
+
194
+    keyframe = c->cur_frame == 0;
195
+
196
+    if(keyframe){
197
+        memset(c->Q, 0, sizeof(c->Q));
198
+        c->last_bits_used = 0;
199
+    }
200
+    init_get_bits(gb, buf, buf_size * 8);
201
+    skip_bits(gb, c->last_bits_used & 7);
202
+
203
+    if(keyframe)
204
+        maxband = mpc8_get_mod_golomb(gb, c->maxbands + 1);
205
+    else{
206
+        maxband = c->last_max_band + get_vlc2(gb, band_vlc.table, MPC8_BANDS_BITS, 2);
207
+        if(maxband > 32) maxband -= 33;
208
+    }
209
+    c->last_max_band = maxband;
210
+
211
+    /* read subband indexes */
212
+    if(maxband){
213
+        last[0] = last[1] = 0;
214
+        for(i = maxband - 1; i >= 0; i--){
215
+            for(ch = 0; ch < 2; ch++){
216
+                last[ch] = get_vlc2(gb, res_vlc[last[ch] > 2].table, MPC8_RES_BITS, 2) + last[ch];
217
+                if(last[ch] > 15) last[ch] -= 17;
218
+                bands[i].res[ch] = last[ch];
219
+            }
220
+        }
221
+        if(c->MSS){
222
+            int mask;
223
+
224
+            cnt = 0;
225
+            for(i = 0; i < maxband; i++)
226
+                if(bands[i].res[0] || bands[i].res[1])
227
+                    cnt++;
228
+            t = mpc8_get_mod_golomb(gb, cnt);
229
+            mask = mpc8_get_mask(gb, cnt, t);
230
+            for(i = maxband - 1; i >= 0; i--)
231
+                if(bands[i].res[0] || bands[i].res[1]){
232
+                    bands[i].msf = mask & 1;
233
+                    mask >>= 1;
234
+                }
235
+        }
236
+    }
237
+    for(i = maxband; i < c->maxbands; i++)
238
+        bands[i].res[0] = bands[i].res[1] = 0;
239
+
240
+    if(keyframe){
241
+        for(i = 0; i < 32; i++)
242
+            c->oldDSCF[0][i] = c->oldDSCF[1][i] = 1;
243
+    }
244
+
245
+    for(i = 0; i < maxband; i++){
246
+        if(bands[i].res[0] || bands[i].res[1]){
247
+            cnt = !!bands[i].res[0] + !!bands[i].res[1] - 1;
248
+            if(cnt >= 0){
249
+                t = get_vlc2(gb, scfi_vlc[cnt].table, scfi_vlc[cnt].bits, 1);
250
+                if(bands[i].res[0]) bands[i].scfi[0] = t >> (2 * cnt);
251
+                if(bands[i].res[1]) bands[i].scfi[1] = t & 3;
252
+            }
253
+        }
254
+    }
255
+
256
+    for(i = 0; i < maxband; i++){
257
+        for(ch = 0; ch < 2; ch++){
258
+            if(!bands[i].res[ch]) continue;
259
+
260
+            if(c->oldDSCF[ch][i]){
261
+                bands[i].scf_idx[ch][0] = get_bits(gb, 7) - 6;
262
+                c->oldDSCF[ch][i] = 0;
263
+            }else{
264
+                t = get_vlc2(gb, dscf_vlc[1].table, MPC8_DSCF1_BITS, 2);
265
+                if(t == 64)
266
+                    t += get_bits(gb, 6);
267
+                bands[i].scf_idx[ch][0] = ((bands[i].scf_idx[ch][2] + t - 25) & 0x7F) - 6;
268
+            }
269
+            for(j = 0; j < 2; j++){
270
+                if((bands[i].scfi[ch] << j) & 2)
271
+                    bands[i].scf_idx[ch][j + 1] = bands[i].scf_idx[ch][j];
272
+                else{
273
+                    t = get_vlc2(gb, dscf_vlc[0].table, MPC8_DSCF0_BITS, 2);
274
+                    if(t == 31)
275
+                        t = 64 + get_bits(gb, 6);
276
+                    bands[i].scf_idx[ch][j + 1] = ((bands[i].scf_idx[ch][j] + t - 25) & 0x7F) - 6;
277
+                }
278
+            }
279
+        }
280
+    }
281
+
282
+    for(i = 0, off = 0; i < maxband; i++, off += SAMPLES_PER_BAND){
283
+        for(ch = 0; ch < 2; ch++){
284
+            res = bands[i].res[ch];
285
+            switch(res){
286
+            case -1:
287
+                for(j = 0; j < SAMPLES_PER_BAND; j++)
288
+                    c->Q[ch][off + j] = (av_random(&c->rnd) & 0x3FC) - 510;
289
+                break;
290
+            case 0:
291
+                break;
292
+            case 1:
293
+                for(j = 0; j < SAMPLES_PER_BAND; j += SAMPLES_PER_BAND / 2){
294
+                    cnt = get_vlc2(gb, q1_vlc.table, MPC8_Q1_BITS, 2);
295
+                    t = mpc8_get_mask(gb, 18, cnt);
296
+                    for(k = 0; k < SAMPLES_PER_BAND / 2; k++, t <<= 1)
297
+                        c->Q[ch][off + j + k] = (t & 0x20000) ? (get_bits1(gb) << 1) - 1 : 0;
298
+                }
299
+                break;
300
+            case 2:
301
+                cnt = 6;//2*mpc8_thres[res]
302
+                for(j = 0; j < SAMPLES_PER_BAND; j += 3){
303
+                    t = get_vlc2(gb, q2_vlc[cnt > 3].table, MPC8_Q2_BITS, 2);
304
+                    c->Q[ch][off + j + 0] = mpc8_idx50[t];
305
+                    c->Q[ch][off + j + 1] = mpc8_idx51[t];
306
+                    c->Q[ch][off + j + 2] = mpc8_idx52[t];
307
+                    cnt = (cnt >> 1) + mpc8_huffq2[t];
308
+                }
309
+                break;
310
+            case 3:
311
+            case 4:
312
+                for(j = 0; j < SAMPLES_PER_BAND; j += 2){
313
+                    t = get_vlc2(gb, q3_vlc[res - 3].table, MPC8_Q3_BITS, 2) + q3_offsets[res - 3];
314
+                    c->Q[ch][off + j + 1] = t >> 4;
315
+                    c->Q[ch][off + j + 0] = (t & 8) ? (t & 0xF) - 16 : (t & 0xF);
316
+                }
317
+                break;
318
+            case 5:
319
+            case 6:
320
+            case 7:
321
+            case 8:
322
+                cnt = 2 * mpc8_thres[res];
323
+                for(j = 0; j < SAMPLES_PER_BAND; j++){
324
+                    t = get_vlc2(gb, quant_vlc[res - 5][cnt > mpc8_thres[res]].table, quant_vlc[res - 5][cnt > mpc8_thres[res]].bits, 2) + quant_offsets[res - 5];
325
+                    c->Q[ch][off + j] = t;
326
+                    cnt = (cnt >> 1) + FFABS(c->Q[ch][off + j]);
327
+                }
328
+                break;
329
+            default:
330
+                for(j = 0; j < SAMPLES_PER_BAND; j++){
331
+                    c->Q[ch][off + j] = get_vlc2(gb, q9up_vlc.table, MPC8_Q9UP_BITS, 2);
332
+                    if(res != 9){
333
+                        c->Q[ch][off + j] <<= res - 9;
334
+                        c->Q[ch][off + j] |= get_bits(gb, res - 9);
335
+                    }
336
+                    c->Q[ch][off + j] -= (1 << (res - 2)) - 1;
337
+                }
338
+            }
339
+        }
340
+    }
341
+
342
+    ff_mpc_dequantize_and_synth(c, maxband, data);
343
+
344
+    c->cur_frame++;
345
+
346
+    c->last_bits_used = get_bits_count(gb);
347
+    if(c->cur_frame >= c->frames)
348
+        c->cur_frame = 0;
349
+    *data_size =  MPC_FRAME_SIZE * 4;
350
+
351
+    return c->cur_frame ? c->last_bits_used >> 3 : buf_size;
352
+}
353
+
354
+AVCodec mpc8_decoder = {
355
+    "mpc sv8",
356
+    CODEC_TYPE_AUDIO,
357
+    CODEC_ID_MUSEPACK8,
358
+    sizeof(MPCContext),
359
+    mpc8_decode_init,
360
+    NULL,
361
+    NULL,
362
+    mpc8_decode_frame,
363
+};
0 364
new file mode 100644
... ...
@@ -0,0 +1,121 @@
0
+/*
1
+ * Musepack SV8 decoder
2
+ * Copyright (c) 2007 Konstantin Shishkov
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#ifndef FFMPEG_MPC8DATA_H
22
+#define FFMPEG_MPC8DATA_H
23
+
24
+#include <stdint.h>
25
+
26
+static const int8_t mpc8_idx50[125] = {
27
+    -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,
28
+    -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,
29
+    -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,
30
+    -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,
31
+    -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
32
+};
33
+static const int8_t mpc8_idx51[125] = {
34
+    -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,
35
+    -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,
36
+    -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,
37
+    -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,
38
+    -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
39
+};
40
+static const int8_t mpc8_idx52[125] = {
41
+    -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,
42
+    -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,
43
+    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,
44
+    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,
45
+    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
46
+};
47
+
48
+static const unsigned int mpc8_thres[] = {0, 0, 3, 0, 0, 1, 3, 4, 8};
49
+static const int8_t mpc8_huffq2[5*5*5] = {
50
+    6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5,
51
+    6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3,
52
+    4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 2, 3, 4, 3,
53
+    2, 3, 4, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5,
54
+    4, 3, 4, 5, 6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5,
55
+    6, 5, 4, 5, 6
56
+};
57
+
58
+
59
+static const uint32_t mpc8_cnk[16][32] =
60
+{
61
+    {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},
62
+    {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},
63
+    {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},
64
+    {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},
65
+    {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},
66
+    {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},
67
+    {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},
68
+    {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},
69
+    {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},
70
+    {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},
71
+    {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},
72
+    {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},
73
+    {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},
74
+    {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},
75
+    {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},
76
+    {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}
77
+};
78
+
79
+const static uint8_t mpc8_cnk_len[16][33] =
80
+{
81
+    {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, 6},
82
+    {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, 0},
83
+    {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, 0},
84
+    {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, 0},
85
+    {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, 0},
86
+    {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, 0},
87
+    {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, 0},
88
+    {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, 0},
89
+    {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, 0},
90
+    {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, 0},
91
+    {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, 0},
92
+    {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, 0},
93
+    {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, 0},
94
+    {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, 0},
95
+    {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, 0},
96
+    {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, 0}
97
+
98
+};
99
+
100
+const static uint32_t mpc8_cnk_lost[16][33] =
101
+{
102
+    {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, 31},
103
+    {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, 0},
104
+    {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, 0},
105
+    {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, 0},
106
+    {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, 0},
107
+    {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, 0},
108
+    {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, 0},
109
+    {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, 0},
110
+    {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, 0},
111
+    {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, 0},
112
+    {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, 0},
113
+    {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, 0},
114
+    {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, 0},
115
+    {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, 0},
116
+    {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, 0},
117
+    {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, 0}
118
+};
119
+
120
+#endif /* FFMPEG_MPC8DATA_H */
0 121
new file mode 100644
... ...
@@ -0,0 +1,578 @@
0
+/*
1
+ * Musepack SV8 decoder
2
+ * Copyright (c) 2007 Konstantin Shishkov
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#ifndef FFMPEG_MPC8HUFF_H
22
+#define FFMPEG_MPC8HUFF_H
23
+
24
+#include <stdint.h>
25
+
26
+#define MPC8_BANDS_SIZE 33
27
+#define MPC8_BANDS_BITS 9
28
+
29
+static const uint8_t mpc8_bands_codes[MPC8_BANDS_SIZE] = {
30
+ 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04,
31
+ 0x05, 0x06, 0x01, 0x02, 0x03, 0x00, 0x04, 0x05,
32
+ 0x06, 0x07, 0x08, 0x01, 0x09, 0x0A, 0x0B, 0x07,
33
+ 0x08, 0x09, 0x06, 0x07, 0x05, 0x05, 0x03, 0x03,
34
+ 0x01,
35
+};
36
+static const int8_t mpc8_bands_bits[MPC8_BANDS_SIZE] = {
37
+  1,  3,  5,  6,  7,  8,  8,  9,
38
+ 10, 11, 12, 12, 12, 13, 12, 12,
39
+ 12, 12, 12, 13, 12, 12, 12, 11,
40
+ 11, 11, 10, 10,  9,  8,  6,  5,
41
+  2,
42
+};
43
+
44
+#define MPC8_SCFI0_SIZE 4
45
+#define MPC8_SCFI0_BITS 3
46
+
47
+static const uint8_t mpc8_scfi0_codes[MPC8_SCFI0_SIZE] = {
48
+ 0x00, 0x01, 0x01, 0x01,
49
+};
50
+static const int8_t mpc8_scfi0_bits[MPC8_SCFI0_SIZE] = {
51
+  3,  3,  1,  2,
52
+};
53
+
54
+#define MPC8_SCFI1_SIZE 16
55
+#define MPC8_SCFI1_BITS 7
56
+
57
+static const uint8_t mpc8_scfi1_codes[MPC8_SCFI1_SIZE] = {
58
+ 0x01, 0x00, 0x02, 0x03, 0x01, 0x03, 0x04, 0x05,
59
+ 0x04, 0x06, 0x02, 0x02, 0x05, 0x07, 0x03, 0x03,
60
+
61
+};
62
+static const int8_t mpc8_scfi1_bits[MPC8_SCFI1_SIZE] = {
63
+  6,  7,  6,  6,  7,  5,  5,  5,
64
+  6,  5,  2,  3,  6,  5,  3,  2,
65
+
66
+};
67
+
68
+#define MPC8_DSCF0_SIZE 64
69
+#define MPC8_DSCF0_BITS 9
70
+
71
+static const uint8_t mpc8_dscf0_codes[MPC8_DSCF0_SIZE] = {
72
+ 0x03, 0x04, 0x05, 0x04, 0x05, 0x06, 0x05, 0x06,
73
+ 0x07, 0x08, 0x09, 0x07, 0x08, 0x09, 0x0A, 0x07,
74
+ 0x08, 0x09, 0x0A, 0x07, 0x08, 0x09, 0x0A, 0x06,
75
+ 0x07, 0x05, 0x04, 0x05, 0x06, 0x06, 0x07, 0x0A,
76
+ 0x08, 0x05, 0x06, 0x07, 0x09, 0x07, 0x08, 0x09,
77
+ 0x0B, 0x0B, 0x0C, 0x0D, 0x0B, 0x0C, 0x0D, 0x0B,
78
+ 0x0C, 0x0D, 0x07, 0x08, 0x09, 0x06, 0x07, 0x03,
79
+ 0x04, 0x05, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
80
+};
81
+static const int8_t mpc8_dscf0_bits[MPC8_DSCF0_SIZE] = {
82
+ 12, 12, 12, 11, 11, 11, 10, 10,
83
+ 10, 10, 10,  9,  9,  9,  9,  8,
84
+  8,  8,  8,  7,  7,  7,  7,  6,
85
+  6,  5,  4,  4,  5,  4,  4, 10,
86
+  4,  3,  3,  3,  4,  5,  6,  6,
87
+  7,  8,  8,  8,  9,  9,  9, 10,
88
+ 10, 10, 11, 11, 11, 12, 12, 13,
89
+ 13, 13, 14, 14, 14, 14, 14, 14,
90
+
91
+};
92
+
93
+#define MPC8_DSCF1_SIZE 65
94
+#define MPC8_DSCF1_BITS 9
95
+
96
+static const uint8_t mpc8_dscf1_codes[MPC8_DSCF1_SIZE] = {
97
+ 0x00, 0x03, 0x04, 0x04, 0x05, 0x06, 0x05, 0x06,
98
+ 0x07, 0x08, 0x07, 0x08, 0x09, 0x0A, 0x07, 0x08,
99
+ 0x09, 0x0A, 0x07, 0x08, 0x09, 0x06, 0x07, 0x05,
100
+ 0x06, 0x04, 0x03, 0x03, 0x04, 0x03, 0x04, 0x05,
101
+ 0x06, 0x07, 0x05, 0x04, 0x05, 0x05, 0x07, 0x08,
102
+ 0x09, 0x0A, 0x0B, 0x0B, 0x0C, 0x0D, 0x0B, 0x0C,
103
+ 0x0D, 0x09, 0x0A, 0x0B, 0x0C, 0x07, 0x08, 0x09,
104
+ 0x05, 0x06, 0x07, 0x01, 0x02, 0x03, 0x04, 0x05,
105
+ 0x0D,
106
+};
107
+static const int8_t mpc8_dscf1_bits[MPC8_DSCF1_SIZE] = {
108
+ 15, 14, 14, 13, 13, 13, 12, 12,
109
+ 12, 12, 11, 11, 11, 11, 10, 10,
110
+ 10, 10,  9,  9,  9,  8,  8,  7,
111
+  7,  6,  5,  4,  4,  3,  3,  3,
112
+  3,  3,  4,  5,  5,  6,  7,  8,
113
+  8,  9,  9, 10, 10, 10, 11, 11,
114
+ 11, 12, 12, 12, 12, 13, 13, 13,
115
+ 14, 14, 14, 15, 15, 15, 15, 15,
116
+ 12,
117
+};
118
+
119
+#define MPC8_RES_SIZE 17
120
+#define MPC8_RES_BITS 9
121
+
122
+static const uint8_t mpc8_res_codes[2][MPC8_RES_SIZE] = {
123
+  {
124
+    0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
125
+    0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01,
126
+    0x01,
127
+  },
128
+  {
129
+    0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
130
+    0x00, 0x01, 0x02, 0x03, 0x01, 0x01, 0x01, 0x01,
131
+    0x03,
132
+  }
133
+};
134
+static const int8_t mpc8_res_bits[2][MPC8_RES_SIZE] = {
135
+  {
136
+     1,  2,  4,  5,  6,  7,  9, 10,
137
+    11, 12, 13, 14, 15, 16, 16,  8,
138
+     3,
139
+  },
140
+  {
141
+     2,  2,  3,  5,  7,  8, 10, 12,
142
+    14, 14, 14, 14, 11,  9,  6,  4,
143
+     2,
144
+  }
145
+};
146
+
147
+#define MPC8_Q1_SIZE 19
148
+#define MPC8_Q1_BITS 9
149
+
150
+static const uint8_t mpc8_q1_codes[MPC8_Q1_SIZE] = {
151
+ 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
152
+ 0x03, 0x04, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01,
153
+ 0x01, 0x00, 0x01,
154
+};
155
+static const int8_t mpc8_q1_bits[MPC8_Q1_SIZE] = {
156
+  6,  4,  4,  3,  3,  3,  3,  3,
157
+  4,  4,  4,  5,  7,  8,  9, 10,
158
+ 11, 12, 12,
159
+};
160
+
161
+#define MPC8_Q9UP_SIZE 256
162
+#define MPC8_Q9UP_BITS 9
163
+
164
+static const uint8_t mpc8_q9up_codes[MPC8_Q9UP_SIZE] = {
165
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x06, 0x07,
166
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
167
+ 0x10, 0x11, 0x12, 0x26, 0x27, 0x13, 0x14, 0x15,
168
+ 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
169
+ 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
170
+ 0x28, 0x26, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E,
171
+ 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
172
+ 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E,
173
+ 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
174
+ 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E,
175
+ 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
176
+ 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E,
177
+ 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
178
+ 0x67, 0x68, 0x69, 0x6A, 0x56, 0x57, 0x58, 0x59,
179
+ 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61,
180
+ 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x3E,
181
+ 0x3F, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
182
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
183
+ 0x78, 0x79, 0x7A, 0x6B, 0x7B, 0x6C, 0x6D, 0x6E,
184
+ 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
185
+ 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E,
186
+ 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86,
187
+ 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E,
188
+ 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
189
+ 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E,
190
+ 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
191
+ 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0x27, 0x28, 0x29,
192
+ 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31,
193
+ 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
194
+ 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41,
195
+ 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
196
+ 0x4A, 0x4B, 0x06, 0x07, 0x08, 0x09, 0x00, 0x01,
197
+};
198
+static const int8_t mpc8_q9up_bits[MPC8_Q9UP_SIZE] = {
199
+ 10, 10, 10, 10, 10,  9,  9,  9,
200
+  9,  9,  9,  9,  9,  9,  9,  9,
201
+  9,  9,  9,  8,  8,  9,  9,  9,
202
+  9,  9,  9,  9,  9,  9,  9,  9,
203
+  9,  9,  9,  9,  9,  9,  9,  9,
204
+  8,  9,  8,  8,  8,  8,  8,  8,
205
+  8,  8,  8,  8,  8,  8,  8,  8,
206
+  8,  8,  8,  8,  8,  8,  8,  8,
207
+  8,  8,  8,  8,  8,  8,  8,  8,
208
+  8,  8,  8,  8,  8,  8,  8,  8,
209
+  8,  8,  8,  8,  8,  8,  8,  8,
210
+  8,  8,  8,  8,  8,  8,  8,  8,
211
+  8,  8,  8,  8,  8,  8,  8,  8,
212
+  8,  8,  8,  8,  7,  7,  7,  7,
213
+  7,  7,  7,  7,  7,  7,  7,  7,
214
+  7,  7,  7,  7,  7,  7,  7,  6,
215
+  6,  7,  7,  7,  7,  7,  7,  7,
216
+  7,  7,  7,  7,  7,  7,  7,  7,
217
+  7,  7,  7,  8,  7,  8,  8,  8,
218
+  8,  8,  8,  8,  8,  8,  8,  8,
219
+  8,  8,  8,  8,  8,  8,  8,  8,
220
+  8,  8,  8,  8,  8,  8,  8,  8,
221
+  8,  8,  8,  8,  8,  8,  8,  8,
222
+  8,  8,  8,  8,  8,  8,  8,  8,
223
+  8,  8,  8,  8,  8,  8,  8,  8,
224
+  8,  8,  8,  8,  8,  8,  8,  8,
225
+  8,  8,  8,  8,  8,  9,  9,  9,
226
+  9,  9,  9,  9,  9,  9,  9,  9,
227
+  9,  9,  9,  9,  9,  9,  9,  9,
228
+  9,  9,  9,  9,  9,  9,  9,  9,
229
+  9,  9,  9,  9,  9,  9,  9,  9,
230
+  9,  9, 10, 10, 10, 10, 11, 11,
231
+};
232
+
233
+#define MPC8_Q2_SIZE 125
234
+#define MPC8_Q2_BITS 9
235
+
236
+static const uint8_t mpc8_q2_codes[2][MPC8_Q2_SIZE] = {
237
+{
238
+ 0x02, 0x03, 0x0F, 0x04, 0x00, 0x05, 0x0C, 0x12,
239
+ 0x0D, 0x06, 0x07, 0x13, 0x15, 0x14, 0x08, 0x09,
240
+ 0x0E, 0x15, 0x0F, 0x0A, 0x03, 0x0B, 0x10, 0x0C,
241
+ 0x01, 0x0D, 0x10, 0x16, 0x11, 0x0E, 0x12, 0x0F,
242
+ 0x10, 0x16, 0x13, 0x17, 0x11, 0x08, 0x12, 0x18,
243
+ 0x14, 0x13, 0x14, 0x17, 0x15, 0x0F, 0x16, 0x19,
244
+ 0x17, 0x10, 0x11, 0x1A, 0x18, 0x1B, 0x12, 0x1C,
245
+ 0x15, 0x09, 0x16, 0x1D, 0x19, 0x0A, 0x07, 0x0B,
246
+ 0x1A, 0x1E, 0x17, 0x0C, 0x18, 0x1F, 0x13, 0x20,
247
+ 0x1B, 0x21, 0x14, 0x11, 0x18, 0x22, 0x19, 0x12,
248
+ 0x1A, 0x19, 0x1A, 0x1B, 0x1B, 0x23, 0x1C, 0x0D,
249
+ 0x1D, 0x24, 0x1C, 0x1C, 0x1E, 0x1F, 0x1D, 0x13,
250
+ 0x1E, 0x25, 0x1F, 0x14, 0x02, 0x15, 0x15, 0x16,
251
+ 0x04, 0x17, 0x20, 0x26, 0x21, 0x18, 0x16, 0x27,
252
+ 0x1D, 0x28, 0x19, 0x1A, 0x22, 0x29, 0x23, 0x1B,
253
+ 0x03, 0x1C, 0x17, 0x1D, 0x05,
254
+},
255
+{
256
+ 0x02, 0x03, 0x0F, 0x04, 0x00, 0x05, 0x0C, 0x0D,
257
+ 0x0E, 0x06, 0x07, 0x0F, 0x1E, 0x10, 0x10, 0x08,
258
+ 0x11, 0x12, 0x13, 0x09, 0x03, 0x0A, 0x11, 0x0B,
259
+ 0x01, 0x0C, 0x14, 0x15, 0x16, 0x0D, 0x17, 0x12,
260
+ 0x0E, 0x13, 0x18, 0x19, 0x14, 0x0F, 0x10, 0x1A,
261
+ 0x1B, 0x15, 0x11, 0x16, 0x1C, 0x0E, 0x1D, 0x1E,
262
+ 0x1F, 0x0F, 0x12, 0x20, 0x1F, 0x21, 0x13, 0x22,
263
+ 0x12, 0x13, 0x14, 0x23, 0x20, 0x15, 0x0F, 0x16,
264
+ 0x21, 0x24, 0x17, 0x18, 0x19, 0x25, 0x14, 0x26,
265
+ 0x22, 0x27, 0x15, 0x10, 0x28, 0x29, 0x2A, 0x11,
266
+ 0x2B, 0x17, 0x1A, 0x18, 0x2C, 0x2D, 0x1B, 0x1C,
267
+ 0x19, 0x2E, 0x2F, 0x1A, 0x1D, 0x1B, 0x30, 0x12,
268
+ 0x31, 0x32, 0x33, 0x13, 0x02, 0x14, 0x15, 0x16,
269
+ 0x04, 0x17, 0x34, 0x35, 0x36, 0x18, 0x16, 0x37,
270
+ 0x23, 0x38, 0x19, 0x1A, 0x39, 0x3A, 0x3B, 0x1B,
271
+ 0x03, 0x1C, 0x17, 0x1D, 0x05,
272
+}
273
+};
274
+static const int8_t mpc8_q2_bits[2][MPC8_Q2_SIZE] = {
275
+{
276
+ 12, 11, 10, 11, 13, 11,  9,  8,
277
+  9, 11, 11,  8,  7,  8, 11, 11,
278
+  9,  8,  9, 11, 12, 11, 10, 11,
279
+ 13, 11,  9,  8,  9, 11,  9,  6,
280
+  6,  7,  9,  8,  6,  4,  6,  8,
281
+  9,  6,  6,  7,  9, 11,  9,  8,
282
+  9, 11, 10,  8,  7,  8, 10,  8,
283
+  6,  4,  6,  8,  7,  4,  3,  4,
284
+  7,  8,  6,  4,  6,  8, 10,  8,
285
+  7,  8, 10, 11,  9,  8,  9, 11,
286
+  9,  6,  6,  6,  9,  8,  6,  4,
287
+  6,  8,  9,  7,  6,  6,  9, 11,
288
+  9,  8,  9, 11, 13, 11, 10, 11,
289
+ 12, 11,  9,  8,  9, 11, 10,  8,
290
+  7,  8, 11, 11,  9,  8,  9, 11,
291
+ 13, 11, 10, 11, 12,
292
+},
293
+{
294
+ 11, 10,  9, 10, 12, 10,  8,  8,
295
+  8, 10, 10,  8,  7,  8,  9, 10,
296
+  8,  8,  8, 10, 11, 10,  9, 10,
297
+ 12, 10,  8,  8,  8, 10,  8,  6,
298
+  5,  6,  8,  8,  6,  5,  5,  8,
299
+  8,  6,  5,  6,  8, 10,  8,  8,
300
+  8, 10,  9,  8,  7,  8,  9,  8,
301
+  5,  5,  5,  8,  7,  5,  4,  5,
302
+  7,  8,  5,  5,  5,  8,  9,  8,
303
+  7,  8,  9, 10,  8,  8,  8, 10,
304
+  8,  6,  5,  6,  8,  8,  5,  5,
305
+  6,  8,  8,  6,  5,  6,  8, 10,
306
+  8,  8,  8, 10, 12, 10, 10, 10,
307
+ 11, 10,  8,  8,  8, 10,  9,  8,
308
+  7,  8, 10, 10,  8,  8,  8, 10,
309
+ 12, 10,  9, 10, 11,
310
+}
311
+};
312
+
313
+#define MPC8_Q3_SIZE 49
314
+#define MPC8_Q3_BITS 9
315
+#define MPC8_Q3_OFFSET -48
316
+
317
+static const uint8_t mpc8_q3_codes[MPC8_Q3_SIZE] = {
318
+ 0x07, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x0F,
319
+ 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x13, 0x12, 0x11,
320
+ 0x10, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09,
321
+ 0x11, 0x10, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A,
322
+ 0x09, 0x08, 0x07, 0x06, 0x05, 0x09, 0x08, 0x07,
323
+ 0x06, 0x05, 0x04, 0x03, 0x02, 0x03, 0x02, 0x01,
324
+ 0x00,
325
+};
326
+static const int8_t mpc8_q3_bits[MPC8_Q3_SIZE] = {
327
+  3,  4,  4,  4,  4,  4,  4,  5,
328
+  5,  5,  5,  5,  5,  6,  6,  6,
329
+  6,  6,  6,  6,  6,  6,  6,  6,
330
+  7,  7,  7,  7,  7,  7,  7,  7,
331
+  7,  7,  7,  7,  7,  8,  8,  8,
332
+  8,  8,  8,  8,  8,  9,  9,  9,
333
+  9,
334
+};
335
+static const int8_t mpc8_q3_syms[MPC8_Q3_SIZE] = {
336
+   48,    65,    64,    49,    63,    32,    47,    80,
337
+   79,    50,    62,    33,    16,    82,    81,    95,
338
+   94,    66,    78,    34,    46,    17,    31,    30,
339
+   97,    96,   111,    67,    77,    51,    61,    35,
340
+   45,    18,     1,     0,    15,    98,   110,    83,
341
+   93,    19,    29,     2,    14,    99,   109,     3,
342
+   13,
343
+};
344
+
345
+#define MPC8_Q4_SIZE 81
346
+#define MPC8_Q4_BITS 9
347
+#define MPC8_Q4_OFFSET -64
348
+
349
+static const uint8_t mpc8_q4_codes[MPC8_Q4_SIZE] = {
350
+ 0x0F, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x17,
351
+ 0x16, 0x15, 0x14, 0x13, 0x12, 0x23, 0x22, 0x21,
352
+ 0x20, 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19,
353
+ 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11,
354
+ 0x10, 0x0F, 0x0E, 0x0D, 0x19, 0x18, 0x17, 0x16,
355
+ 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0F, 0x0E,
356
+ 0x0D, 0x0C, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12,
357
+ 0x11, 0x10, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A,
358
+ 0x09, 0x08, 0x07, 0x06, 0x05, 0x09, 0x08, 0x07,
359
+ 0x06, 0x05, 0x04, 0x03, 0x02, 0x03, 0x02, 0x01,
360
+ 0x00,
361
+};
362
+static const int8_t mpc8_q4_bits[MPC8_Q4_SIZE] = {
363
+  4,  5,  5,  5,  5,  5,  5,  5,
364
+  5,  5,  5,  5,  5,  6,  6,  6,
365
+  6,  6,  6,  6,  6,  6,  6,  6,
366
+  6,  6,  6,  6,  6,  6,  6,  6,
367
+  6,  6,  6,  6,  7,  7,  7,  7,
368
+  7,  7,  7,  7,  7,  7,  7,  7,
369
+  7,  7,  8,  8,  8,  8,  8,  8,
370
+  8,  8,  8,  8,  8,  8,  8,  8,
371
+  8,  8,  8,  8,  8,  9,  9,  9,
372
+  9,  9,  9,  9,  9, 10, 10, 10,
373
+ 10,
374
+};
375
+static const int8_t mpc8_q4_syms[MPC8_Q4_SIZE] = {
376
+   64,    96,    81,    80,    95,    66,    65,    79,
377
+   78,    49,    48,    63,    32,   113,   112,    98,
378
+   97,   111,   110,    83,    82,    94,    93,    67,
379
+   77,    51,    50,    62,    61,    34,    33,    47,
380
+   46,    17,    16,    31,   128,   114,   127,   126,
381
+   99,   109,    68,    76,    35,    45,    18,    30,
382
+    0,    15,   130,   129,   143,   142,   115,   125,
383
+  100,   108,    84,    92,    52,    60,    36,    44,
384
+   19,    29,     2,     1,    14,   131,   141,   116,
385
+  124,    20,    28,     3,    13,   132,   140,     4,
386
+   12,
387
+};
388
+
389
+#define MPC8_Q5_SIZE 15
390
+#define MPC8_Q5_BITS 7
391
+#define MPC8_Q5_OFFSET -7
392
+
393
+static const uint8_t mpc8_q5_codes[2][MPC8_Q5_SIZE] = {
394
+{
395
+ 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03,
396
+ 0x04, 0x05, 0x03, 0x03, 0x03, 0x02, 0x03,
397
+},
398
+{
399
+ 0x00, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x05,
400
+ 0x06, 0x07, 0x04, 0x05, 0x03, 0x02, 0x03,
401
+}
402
+};
403
+static const int8_t mpc8_q5_bits[2][MPC8_Q5_SIZE] = {
404
+{
405
+  7,  7,  6,  5,  4,  3,  3,  2,
406
+  3,  3,  4,  5,  6,  7,  7,
407
+},
408
+{
409
+  6,  6,  5,  4,  4,  3,  3,  3,
410
+  3,  3,  4,  4,  5,  6,  6,
411
+}
412
+};
413
+
414
+#define MPC8_Q6_SIZE 31
415
+#define MPC8_Q6_BITS 9
416
+#define MPC8_Q6_OFFSET -15
417
+
418
+static const uint8_t mpc8_q6_codes[2][MPC8_Q6_SIZE] = {
419
+{
420
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x04, 0x03,
421
+ 0x04, 0x05, 0x05, 0x06, 0x04, 0x05, 0x04, 0x03,
422
+ 0x05, 0x06, 0x07, 0x07, 0x06, 0x07, 0x08, 0x09,
423
+ 0x05, 0x06, 0x07, 0x04, 0x05, 0x06, 0x07,
424
+},
425
+{
426
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x05, 0x04,
427
+ 0x05, 0x06, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
428
+ 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x07, 0x08, 0x09,
429
+ 0x06, 0x07, 0x05, 0x06, 0x07, 0x02, 0x03,
430
+}
431
+};
432
+static const int8_t mpc8_q6_bits[2][MPC8_Q6_SIZE] = {
433
+{
434
+  9,  9,  9,  9,  8,  8,  7,  6,
435
+  6,  6,  5,  5,  4,  4,  3,  2,
436
+  3,  4,  4,  5,  6,  6,  6,  6,
437
+  7,  8,  8,  9,  9,  9,  9,
438
+},
439
+{
440
+  8,  8,  7,  7,  7,  6,  6,  5,
441
+  5,  5,  4,  4,  4,  4,  4,  4,
442
+  4,  4,  4,  4,  4,  5,  5,  5,
443
+  6,  6,  7,  7,  7,  8,  8,
444
+}
445
+};
446
+
447
+#define MPC8_Q7_SIZE 63
448
+#define MPC8_Q7_BITS 9
449
+#define MPC8_Q7_OFFSET -31
450
+
451
+static const uint8_t mpc8_q7_codes[2][MPC8_Q7_SIZE] = {
452
+{
453
+ 0x00, 0x01, 0x02, 0x08, 0x09, 0x03, 0x04, 0x05,
454
+ 0x06, 0x07, 0x0A, 0x0B, 0x0C, 0x0D, 0x0A, 0x0B,
455
+ 0x0C, 0x0D, 0x0E, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
456
+ 0x0A, 0x0B, 0x0C, 0x08, 0x09, 0x06, 0x04, 0x03,
457
+ 0x05, 0x07, 0x0A, 0x0B, 0x0D, 0x0E, 0x0F, 0x0F,
458
+ 0x10, 0x11, 0x12, 0x0F, 0x13, 0x10, 0x11, 0x12,
459
+ 0x13, 0x0E, 0x0F, 0x10, 0x11, 0x08, 0x09, 0x0A,
460
+ 0x0B, 0x0C, 0x12, 0x13, 0x0D, 0x0E, 0x0F,
461
+},
462
+{
463
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
464
+ 0x08, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x09, 0x0A,
465
+ 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x0C, 0x0D,
466
+ 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
467
+ 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
468
+ 0x1E, 0x1F, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
469
+ 0x17, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x09, 0x0A,
470
+ 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x02, 0x03,
471
+}
472
+};
473
+static const int8_t mpc8_q7_bits[2][MPC8_Q7_SIZE] = {
474
+{
475
+ 10, 10, 10,  9,  9, 10, 10, 10,
476
+ 10, 10,  9,  9,  9,  9,  8,  8,
477
+  8,  8,  8,  7,  7,  7,  7,  7,
478
+  6,  6,  6,  5,  5,  4,  3,  2,
479
+  3,  4,  5,  5,  6,  6,  6,  7,
480
+  7,  7,  7,  8,  7,  8,  8,  8,
481
+  8,  9,  9,  9,  9, 10, 10, 10,
482
+ 10, 10,  9,  9, 10, 10, 10,
483
+},
484
+{
485
+  9,  9,  8,  8,  8,  8,  8,  8,
486
+  8,  7,  7,  7,  7,  7,  6,  6,
487
+  6,  6,  6,  6,  6,  6,  5,  5,
488
+  5,  5,  5,  5,  5,  5,  5,  5,
489
+  5,  5,  5,  5,  5,  5,  5,  5,
490
+  5,  5,  6,  6,  6,  6,  6,  6,
491
+  6,  7,  7,  7,  7,  7,  8,  8,
492
+  8,  8,  8,  8,  8,  9,  9,
493
+}
494
+};
495
+
496
+#define MPC8_Q8_SIZE 127
497
+#define MPC8_Q8_BITS 9
498
+#define MPC8_Q8_OFFSET -63
499
+
500
+static const uint8_t mpc8_q8_codes[2][MPC8_Q8_SIZE] = {
501
+{
502
+ 0x03, 0x04, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x1A,
503
+ 0x0F, 0x1B, 0x10, 0x00, 0x01, 0x05, 0x06, 0x07,
504
+ 0x08, 0x09, 0x0A, 0x0B, 0x11, 0x0C, 0x12, 0x13,
505
+ 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1C, 0x1A,
506
+ 0x1B, 0x1C, 0x1D, 0x1E, 0x1D, 0x1E, 0x1F, 0x20,
507
+ 0x21, 0x22, 0x23, 0x24, 0x19, 0x25, 0x1A, 0x1B,
508
+ 0x1C, 0x1D, 0x1E, 0x1F, 0x14, 0x15, 0x16, 0x17,
509
+ 0x0E, 0x0F, 0x10, 0x11, 0x0B, 0x07, 0x04, 0x03,
510
+ 0x05, 0x0C, 0x0D, 0x12, 0x13, 0x14, 0x15, 0x18,
511
+ 0x19, 0x1A, 0x1B, 0x20, 0x21, 0x22, 0x23, 0x24,
512
+ 0x25, 0x26, 0x27, 0x26, 0x27, 0x28, 0x29, 0x2A,
513
+ 0x2B, 0x2C, 0x2D, 0x2E, 0x1F, 0x20, 0x2F, 0x21,
514
+ 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,
515
+ 0x0D, 0x0E, 0x2A, 0x0F, 0x10, 0x11, 0x12, 0x02,
516
+ 0x13, 0x03, 0x04, 0x05, 0x2B, 0x2C, 0x30, 0x31,
517
+ 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33,
518
+},
519
+{
520
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
521
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
522
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x15, 0x16,
523
+ 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
524
+ 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
525
+ 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E,
526
+ 0x2F, 0x30, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B,
527
+ 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33,
528
+ 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
529
+ 0x3C, 0x3D, 0x3E, 0x31, 0x3F, 0x32, 0x33, 0x34,
530
+ 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C,
531
+ 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44,
532
+ 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x16,
533
+ 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
534
+ 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
535
+ 0x27, 0x28, 0x29, 0x04, 0x05, 0x06, 0x07,
536
+}
537
+};
538
+static const int8_t mpc8_q8_bits[2][MPC8_Q8_SIZE] = {
539
+{
540
+ 11, 11, 10, 10, 10, 10, 10,  9,
541
+ 10,  9, 10, 12, 12, 11, 11, 11,
542
+ 11, 11, 11, 11, 10, 11, 10, 10,
543
+ 10, 10, 10, 10, 10, 10,  9, 10,
544
+ 10, 10, 10, 10,  9,  9,  9,  9,
545
+  9,  9,  9,  9,  8,  9,  8,  8,
546
+  8,  8,  8,  8,  7,  7,  7,  7,
547
+  6,  6,  6,  6,  5,  4,  3,  2,
548
+  3,  5,  5,  6,  6,  6,  6,  7,
549
+  7,  7,  7,  8,  8,  8,  8,  8,
550
+  8,  8,  8,  9,  9,  9,  9,  9,
551
+  9,  9,  9,  9, 10, 10,  9, 10,
552
+ 10, 10, 10, 10, 10, 10, 10, 10,
553
+ 11, 11, 10, 11, 11, 11, 11, 12,
554
+ 11, 12, 12, 12, 10, 10,  9,  9,
555
+ 10, 10, 10, 10, 10, 10, 10,
556
+},
557
+{
558
+  9,  9,  9,  9,  8,  8,  8,  8,
559
+  8,  8,  8,  8,  8,  8,  8,  8,
560
+  8,  8,  8,  8,  8,  8,  7,  7,
561
+  7,  7,  7,  7,  7,  7,  7,  7,
562
+  7,  7,  7,  7,  7,  7,  7,  7,
563
+  7,  7,  7,  7,  7,  7,  7,  7,
564
+  7,  7,  6,  6,  6,  6,  6,  6,
565
+  6,  6,  6,  6,  6,  6,  6,  6,
566
+  6,  6,  6,  6,  6,  6,  6,  6,
567
+  6,  6,  6,  7,  6,  7,  7,  7,
568
+  7,  7,  7,  7,  7,  7,  7,  7,
569
+  7,  7,  7,  7,  7,  7,  7,  7,
570
+  7,  7,  7,  7,  7,  7,  7,  8,
571
+  8,  8,  8,  8,  8,  8,  8,  8,
572
+  8,  8,  8,  8,  8,  8,  8,  8,
573
+  8,  8,  8,  9,  9,  9,  9,
574
+}
575
+};
576
+
577
+#endif /* FFMPEG_MPC8HUFF_H */
... ...
@@ -86,6 +86,7 @@ OBJS-$(CONFIG_MP3_DEMUXER)               += mp3.o
86 86
 OBJS-$(CONFIG_MP3_MUXER)                 += mp3.o
87 87
 OBJS-$(CONFIG_MP4_MUXER)                 += movenc.o riff.o isom.o
88 88
 OBJS-$(CONFIG_MPC_DEMUXER)               += mpc.o
89
+OBJS-$(CONFIG_MPC8_DEMUXER)              += mpc8.o
89 90
 OBJS-$(CONFIG_MPEG1SYSTEM_MUXER)         += mpegenc.o
90 91
 OBJS-$(CONFIG_MPEG1VCD_MUXER)            += mpegenc.o
91 92
 OBJS-$(CONFIG_MPEG2DVD_MUXER)            += mpegenc.o
... ...
@@ -104,6 +104,7 @@ void av_register_all(void)
104 104
     REGISTER_MUXDEMUX (MP3, mp3);
105 105
     REGISTER_MUXER    (MP4, mp4);
106 106
     REGISTER_DEMUXER  (MPC, mpc);
107
+    REGISTER_DEMUXER  (MPC8, mpc8);
107 108
     REGISTER_MUXER    (MPEG1SYSTEM, mpeg1system);
108 109
     REGISTER_MUXER    (MPEG1VCD, mpeg1vcd);
109 110
     REGISTER_MUXER    (MPEG1VIDEO, mpeg1video);
... ...
@@ -21,8 +21,8 @@
21 21
 #ifndef FFMPEG_AVFORMAT_H
22 22
 #define FFMPEG_AVFORMAT_H
23 23
 
24
-#define LIBAVFORMAT_VERSION_INT ((51<<16)+(17<<8)+1)
25
-#define LIBAVFORMAT_VERSION     51.17.1
24
+#define LIBAVFORMAT_VERSION_INT ((51<<16)+(18<<8)+0)
25
+#define LIBAVFORMAT_VERSION     51.18.0
26 26
 #define LIBAVFORMAT_BUILD       LIBAVFORMAT_VERSION_INT
27 27
 
28 28
 #define LIBAVFORMAT_IDENT       "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
29 29
new file mode 100644
... ...
@@ -0,0 +1,244 @@
0
+/*
1
+ * Musepack SV8 demuxer
2
+ * Copyright (c) 2007 Konstantin Shishkov
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+#include "avformat.h"
21
+#include "bitstream.h"
22
+#include "unary.h"
23
+
24
+/// Two-byte MPC tag
25
+#define MKMPCTAG(a, b) (a | (b << 8))
26
+
27
+#define TAG_MPCK MKTAG('M','P','C','K')
28
+
29
+/// Reserved MPC tags
30
+enum MPCPacketTags{
31
+    TAG_STREAMHDR   = MKMPCTAG('S','H'),
32
+    TAG_STREAMEND   = MKMPCTAG('S','E'),
33
+
34
+    TAG_AUDIOPACKET = MKMPCTAG('A','P'),
35
+
36
+    TAG_SEEKTBLOFF  = MKMPCTAG('S','O'),
37
+    TAG_SEEKTABLE   = MKMPCTAG('S','T'),
38
+
39
+    TAG_REPLAYGAIN  = MKMPCTAG('R','G'),
40
+    TAG_ENCINFO     = MKMPCTAG('E','I'),
41
+};
42
+
43
+static const int mpc8_rate[8] = { 44100, 48000, 37800, 32000, -1, -1, -1, -1 };
44
+
45
+typedef struct {
46
+    int ver;
47
+    int frame;
48
+    int64_t header_pos;
49
+    int64_t samples;
50
+} MPCContext;
51
+
52
+static int mpc8_probe(AVProbeData *p)
53
+{
54
+    if (AV_RL32(p->buf) == TAG_MPCK)
55
+        return AVPROBE_SCORE_MAX;
56
+    return 0;
57
+}
58
+
59
+static inline int64_t gb_get_v(GetBitContext *gb)
60
+{
61
+    int64_t v = 0;
62
+    int bits = 0;
63
+    while(get_bits1(gb) && bits < 64-7){
64
+        v <<= 7;
65
+        v |= get_bits(gb, 7);
66
+        bits += 7;
67
+    }
68
+    v <<= 7;
69
+    v |= get_bits(gb, 7);
70
+
71
+    return v;
72
+}
73
+
74
+static void mpc8_get_chunk_header(ByteIOContext *pb, int *tag, int64_t *size)
75
+{
76
+    int64_t pos;
77
+    pos = url_ftell(pb);
78
+    *tag = get_le16(pb);
79
+    *size = ff_get_v(pb);
80
+    *size -= url_ftell(pb) - pos;
81
+}
82
+
83
+static void mpc8_parse_seektable(AVFormatContext *s, int64_t off)
84
+{
85
+    MPCContext *c = s->priv_data;
86
+    int tag;
87
+    int64_t size, pos, ppos[2];
88
+    uint8_t *buf;
89
+    int i, t, seekd;
90
+    GetBitContext gb;
91
+
92
+    url_fseek(&s->pb, off, SEEK_SET);
93
+    mpc8_get_chunk_header(&s->pb, &tag, &size);
94
+    if(tag != TAG_SEEKTABLE){
95
+        av_log(s, AV_LOG_ERROR, "No seek table at given position\n");
96
+        return;
97
+    }
98
+    if(!(buf = av_malloc(size)))
99
+        return;
100
+    get_buffer(&s->pb, buf, size);
101
+    init_get_bits(&gb, buf, size * 8);
102
+    size = gb_get_v(&gb);
103
+    if(size > UINT_MAX/4 || size > c->samples/1152){
104
+        av_log(s, AV_LOG_ERROR, "Seek table is too big\n");
105
+        return;
106
+    }
107
+    seekd = get_bits(&gb, 4);
108
+    for(i = 0; i < 2; i++){
109
+        pos = gb_get_v(&gb) + c->header_pos;
110
+        ppos[1 - i] = pos;
111
+        av_add_index_entry(s->streams[0], pos, i, 0, 0, AVINDEX_KEYFRAME);
112
+    }
113
+    for(; i < size; i++){
114
+        t = get_unary(&gb, 1, 33) << 12;
115
+        t += get_bits(&gb, 12);
116
+        if(t & 1)
117
+            t = -(t & ~1);
118
+        pos = (t >> 1) + ppos[0]*2 - ppos[1];
119
+        av_add_index_entry(s->streams[0], pos, i << seekd, 0, 0, AVINDEX_KEYFRAME);
120
+        ppos[1] = ppos[0];
121
+        ppos[0] = pos;
122
+    }
123
+    av_free(buf);
124
+}
125
+
126
+static void mpc8_handle_chunk(AVFormatContext *s, int tag, int64_t chunk_pos, int64_t size)
127
+{
128
+    ByteIOContext *pb = &s->pb;
129
+    int64_t pos, off;
130
+
131
+    switch(tag){
132
+    case TAG_SEEKTBLOFF:
133
+        pos = url_ftell(pb) + size;
134
+        off = ff_get_v(pb);
135
+        mpc8_parse_seektable(s, chunk_pos + off);
136
+        url_fseek(pb, pos, SEEK_SET);
137
+        break;
138
+    default:
139
+        url_fskip(pb, size);
140
+    }
141
+}
142
+
143
+static int mpc8_read_header(AVFormatContext *s, AVFormatParameters *ap)
144
+{
145
+    MPCContext *c = s->priv_data;
146
+    ByteIOContext *pb = &s->pb;
147
+    AVStream *st;
148
+    int tag = 0;
149
+    int64_t size, pos;
150
+
151
+    c->header_pos = url_ftell(pb);
152
+    if(get_le32(pb) != TAG_MPCK){
153
+        av_log(s, AV_LOG_ERROR, "Not a Musepack8 file\n");
154
+        return -1;
155
+    }
156
+
157
+    while(!url_feof(pb)){
158
+        pos = url_ftell(pb);
159
+        mpc8_get_chunk_header(pb, &tag, &size);
160
+        if(tag == TAG_STREAMHDR)
161
+            break;
162
+        mpc8_handle_chunk(s, tag, pos, size);
163
+    }
164
+    if(tag != TAG_STREAMHDR){
165
+        av_log(s, AV_LOG_ERROR, "Stream header not found\n");
166
+        return -1;
167
+    }
168
+    pos = url_ftell(pb);
169
+    url_fskip(pb, 4); //CRC
170
+    c->ver = get_byte(pb);
171
+    if(c->ver != 8){
172
+        av_log(s, AV_LOG_ERROR, "Unknown stream version %d\n", c->ver);
173
+        return -1;
174
+    }
175
+    c->samples = ff_get_v(pb);
176
+    ff_get_v(pb); //silence samples at the beginning
177
+
178
+    st = av_new_stream(s, 0);
179
+    if (!st)
180
+        return AVERROR(ENOMEM);
181
+    st->codec->codec_type = CODEC_TYPE_AUDIO;
182
+    st->codec->codec_id = CODEC_ID_MUSEPACK8;
183
+    st->codec->bits_per_sample = 16;
184
+
185
+    st->codec->extradata_size = 2;
186
+    st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
187
+    get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
188
+
189
+    st->codec->channels = (st->codec->extradata[1] >> 4) + 1;
190
+    st->codec->sample_rate = mpc8_rate[st->codec->extradata[0] >> 5];
191
+    av_set_pts_info(st, 32, 1152  << (st->codec->extradata[1]&3)*2, st->codec->sample_rate);
192
+    st->duration = c->samples / (1152 << (st->codec->extradata[1]&3)*2);
193
+    size -= url_ftell(pb) - pos;
194
+
195
+    return 0;
196
+}
197
+
198
+static int mpc8_read_packet(AVFormatContext *s, AVPacket *pkt)
199
+{
200
+    MPCContext *c = s->priv_data;
201
+    int tag;
202
+    int64_t pos, size;
203
+
204
+    while(!url_feof(&s->pb)){
205
+        pos = url_ftell(&s->pb);
206
+        mpc8_get_chunk_header(&s->pb, &tag, &size);
207
+        if(tag == TAG_AUDIOPACKET){
208
+            if(av_get_packet(&s->pb, pkt, size) < 0)
209
+                return AVERROR(ENOMEM);
210
+            pkt->stream_index = 0;
211
+            pkt->pts = c->frame;
212
+            return 0;
213
+        }
214
+        if(tag == TAG_STREAMEND)
215
+            return AVERROR(EIO);
216
+        mpc8_handle_chunk(s, tag, pos, size);
217
+    }
218
+    return 0;
219
+}
220
+
221
+static int mpc8_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
222
+{
223
+    AVStream *st = s->streams[stream_index];
224
+    MPCContext *c = s->priv_data;
225
+    int index = av_index_search_timestamp(st, timestamp, flags);
226
+
227
+    if(index < 0) return -1;
228
+    url_fseek(&s->pb, st->index_entries[index].pos, SEEK_SET);
229
+    c->frame = st->index_entries[index].timestamp;
230
+    return 0;
231
+}
232
+
233
+
234
+AVInputFormat mpc8_demuxer = {
235
+    "mpc8",
236
+    "musepack8",
237
+    sizeof(MPCContext),
238
+    mpc8_probe,
239
+    mpc8_read_header,
240
+    mpc8_read_packet,
241
+    NULL,
242
+    mpc8_read_seek,
243
+};