Browse code

ATRAC+ decoder

Cleanup by Diego Biurrun.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Maxim Poliakovski authored on 2013/10/11 03:32:14
Showing 12 changed files
... ...
@@ -15,6 +15,7 @@ version <next>
15 15
 - aeval filter
16 16
 - stereoscopic 3d metadata handling
17 17
 - WebP encoding via libwebp
18
+- ATRAC3+ decoder
18 19
 
19 20
 
20 21
 version 2.1:
... ...
@@ -139,6 +139,7 @@ Codecs:
139 139
   ass*                                  Aurelien Jacobs
140 140
   asv*                                  Michael Niedermayer
141 141
   atrac3*                               Benjamin Larsson
142
+  atrac3plus*                           Maxim Poliakovski
142 143
   bgmc.c, bgmc.h                        Thilo Borgmann
143 144
   bink.c                                Kostya Shishkov
144 145
   binkaudio.c                           Peter Ross
... ...
@@ -1865,6 +1865,7 @@ asv2_decoder_select="dsputil"
1865 1865
 asv2_encoder_select="dsputil"
1866 1866
 atrac1_decoder_select="mdct sinewin"
1867 1867
 atrac3_decoder_select="mdct"
1868
+atrac3p_decoder_select="mdct sinewin"
1868 1869
 avrn_decoder_select="exif"
1869 1870
 bink_decoder_select="dsputil hpeldsp"
1870 1871
 binkaudio_dct_decoder_select="mdct rdft dct sinewin"
... ...
@@ -833,6 +833,7 @@ following image formats are supported:
833 833
     @tab QuickTime fourcc 'alac'
834 834
 @item ATRAC1                 @tab     @tab  X
835 835
 @item ATRAC3                 @tab     @tab  X
836
+@item ATRAC3+                @tab     @tab  X
836 837
 @item Bink Audio             @tab     @tab  X
837 838
     @tab Used in Bink and Smacker files in many games.
838 839
 @item CELT                   @tab     @tab  E
... ...
@@ -124,6 +124,8 @@ OBJS-$(CONFIG_ASV2_DECODER)            += asvdec.o asv.o mpeg12data.o
124 124
 OBJS-$(CONFIG_ASV2_ENCODER)            += asvenc.o asv.o mpeg12data.o
125 125
 OBJS-$(CONFIG_ATRAC1_DECODER)          += atrac1.o atrac.o
126 126
 OBJS-$(CONFIG_ATRAC3_DECODER)          += atrac3.o atrac.o
127
+OBJS-$(CONFIG_ATRAC3P_DECODER)         += atrac3plusdec.o atrac3plus.o \
128
+                                          atrac3plusdsp.o atrac.o
127 129
 OBJS-$(CONFIG_AURA_DECODER)            += cyuv.o
128 130
 OBJS-$(CONFIG_AURA2_DECODER)           += aura.o
129 131
 OBJS-$(CONFIG_AVRN_DECODER)            += avrndec.o mjpegdec.o mjpeg.o
... ...
@@ -328,6 +328,7 @@ void avcodec_register_all(void)
328 328
     REGISTER_DECODER(APE,               ape);
329 329
     REGISTER_DECODER(ATRAC1,            atrac1);
330 330
     REGISTER_DECODER(ATRAC3,            atrac3);
331
+    REGISTER_DECODER(ATRAC3P,           atrac3p);
331 332
     REGISTER_DECODER(BINKAUDIO_DCT,     binkaudio_dct);
332 333
     REGISTER_DECODER(BINKAUDIO_RDFT,    binkaudio_rdft);
333 334
     REGISTER_DECODER(BMV_AUDIO,         bmv_audio);
334 335
new file mode 100644
... ...
@@ -0,0 +1,1813 @@
0
+/*
1
+ * ATRAC3+ compatible decoder
2
+ *
3
+ * Copyright (c) 2010-2013 Maxim Poliakovski
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * FFmpeg is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with FFmpeg; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+/**
23
+ * @file
24
+ * Bitstream parser for ATRAC3+ decoder.
25
+ */
26
+
27
+#include "libavutil/avassert.h"
28
+#include "avcodec.h"
29
+#include "get_bits.h"
30
+#include "atrac3plus.h"
31
+#include "atrac3plus_data.h"
32
+
33
+static VLC_TYPE tables_data[154276][2];
34
+static VLC wl_vlc_tabs[4];
35
+static VLC sf_vlc_tabs[8];
36
+static VLC ct_vlc_tabs[4];
37
+static VLC spec_vlc_tabs[112];
38
+static VLC gain_vlc_tabs[11];
39
+static VLC tone_vlc_tabs[7];
40
+
41
+#define GET_DELTA(gb, delta_bits) \
42
+    ((delta_bits) ? get_bits((gb), (delta_bits)) : 0)
43
+
44
+/**
45
+ * Generate canonical VLC table from given descriptor.
46
+ *
47
+ * @param[in]     cb          ptr to codebook descriptor
48
+ * @param[in]     xlat        ptr to translation table or NULL
49
+ * @param[in,out] tab_offset  starting offset to the generated vlc table
50
+ * @param[out]    out_vlc     ptr to vlc table to be generated
51
+ */
52
+static av_cold void build_canonical_huff(const uint8_t *cb, const uint8_t *xlat,
53
+                                         int *tab_offset, VLC *out_vlc)
54
+{
55
+    int i, b;
56
+    uint16_t codes[256];
57
+    uint8_t bits[256];
58
+    unsigned code = 0;
59
+    int index = 0;
60
+    int min_len = *cb++; // get shortest codeword length
61
+    int max_len = *cb++; // get longest  codeword length
62
+
63
+    for (b = min_len; b <= max_len; b++) {
64
+        for (i = *cb++; i > 0; i--) {
65
+            av_assert0(index < 256);
66
+            bits[index]  = b;
67
+            codes[index] = code++;
68
+            index++;
69
+        }
70
+        code <<= 1;
71
+    }
72
+
73
+    out_vlc->table = &tables_data[*tab_offset];
74
+    out_vlc->table_allocated = 1 << max_len;
75
+
76
+    ff_init_vlc_sparse(out_vlc, max_len, index, bits, 1, 1, codes, 2, 2,
77
+                       xlat, 1, 1, INIT_VLC_USE_NEW_STATIC);
78
+
79
+    *tab_offset += 1 << max_len;
80
+}
81
+
82
+av_cold void ff_atrac3p_init_vlcs(void)
83
+{
84
+    int i, wl_vlc_offs, ct_vlc_offs, sf_vlc_offs, tab_offset;
85
+
86
+    static int wl_nb_bits[4]  = { 2, 3, 5, 5 };
87
+    static int wl_nb_codes[4] = { 3, 5, 8, 8 };
88
+    static const uint8_t *wl_bits[4] = {
89
+        atrac3p_wl_huff_bits1, atrac3p_wl_huff_bits2,
90
+        atrac3p_wl_huff_bits3, atrac3p_wl_huff_bits4
91
+    };
92
+    static const uint8_t *wl_codes[4] = {
93
+        atrac3p_wl_huff_code1, atrac3p_wl_huff_code2,
94
+        atrac3p_wl_huff_code3, atrac3p_wl_huff_code4
95
+    };
96
+    static const uint8_t *wl_xlats[4] = {
97
+        atrac3p_wl_huff_xlat1, atrac3p_wl_huff_xlat2, NULL, NULL
98
+    };
99
+
100
+    static int ct_nb_bits[4]  = { 3, 4, 4, 4 };
101
+    static int ct_nb_codes[4] = { 4, 8, 8, 8 };
102
+    static const uint8_t *ct_bits[4]  = {
103
+        atrac3p_ct_huff_bits1, atrac3p_ct_huff_bits2,
104
+        atrac3p_ct_huff_bits2, atrac3p_ct_huff_bits3
105
+    };
106
+    static const uint8_t *ct_codes[4] = {
107
+        atrac3p_ct_huff_code1, atrac3p_ct_huff_code2,
108
+        atrac3p_ct_huff_code2, atrac3p_ct_huff_code3
109
+    };
110
+    static const uint8_t *ct_xlats[4] = {
111
+        NULL, NULL, atrac3p_ct_huff_xlat1, NULL
112
+    };
113
+
114
+    static int sf_nb_bits[8]  = {  9,  9,  9,  9,  6,  6,  7,  7 };
115
+    static int sf_nb_codes[8] = { 64, 64, 64, 64, 16, 16, 16, 16 };
116
+    static const uint8_t  *sf_bits[8]  = {
117
+        atrac3p_sf_huff_bits1, atrac3p_sf_huff_bits1, atrac3p_sf_huff_bits2,
118
+        atrac3p_sf_huff_bits3, atrac3p_sf_huff_bits4, atrac3p_sf_huff_bits4,
119
+        atrac3p_sf_huff_bits5, atrac3p_sf_huff_bits6
120
+    };
121
+    static const uint16_t *sf_codes[8] = {
122
+        atrac3p_sf_huff_code1, atrac3p_sf_huff_code1, atrac3p_sf_huff_code2,
123
+        atrac3p_sf_huff_code3, atrac3p_sf_huff_code4, atrac3p_sf_huff_code4,
124
+        atrac3p_sf_huff_code5, atrac3p_sf_huff_code6
125
+    };
126
+    static const uint8_t  *sf_xlats[8] = {
127
+        atrac3p_sf_huff_xlat1, atrac3p_sf_huff_xlat2, NULL, NULL,
128
+        atrac3p_sf_huff_xlat4, atrac3p_sf_huff_xlat5, NULL, NULL
129
+    };
130
+
131
+    static const uint8_t *gain_cbs[11] = {
132
+        atrac3p_huff_gain_npoints1_cb, atrac3p_huff_gain_npoints1_cb,
133
+        atrac3p_huff_gain_lev1_cb, atrac3p_huff_gain_lev2_cb,
134
+        atrac3p_huff_gain_lev3_cb, atrac3p_huff_gain_lev4_cb,
135
+        atrac3p_huff_gain_loc3_cb, atrac3p_huff_gain_loc1_cb,
136
+        atrac3p_huff_gain_loc4_cb, atrac3p_huff_gain_loc2_cb,
137
+        atrac3p_huff_gain_loc5_cb
138
+    };
139
+    static const uint8_t *gain_xlats[11] = {
140
+        NULL, atrac3p_huff_gain_npoints2_xlat, atrac3p_huff_gain_lev1_xlat,
141
+        atrac3p_huff_gain_lev2_xlat, atrac3p_huff_gain_lev3_xlat,
142
+        atrac3p_huff_gain_lev4_xlat, atrac3p_huff_gain_loc3_xlat,
143
+        atrac3p_huff_gain_loc1_xlat, atrac3p_huff_gain_loc4_xlat,
144
+        atrac3p_huff_gain_loc2_xlat, atrac3p_huff_gain_loc5_xlat
145
+    };
146
+
147
+    static const uint8_t *tone_cbs[7] = {
148
+        atrac3p_huff_tonebands_cb,  atrac3p_huff_numwavs1_cb,
149
+        atrac3p_huff_numwavs2_cb,   atrac3p_huff_wav_ampsf1_cb,
150
+        atrac3p_huff_wav_ampsf2_cb, atrac3p_huff_wav_ampsf3_cb,
151
+        atrac3p_huff_freq_cb
152
+    };
153
+    static const uint8_t *tone_xlats[7] = {
154
+        NULL, NULL, atrac3p_huff_numwavs2_xlat, atrac3p_huff_wav_ampsf1_xlat,
155
+        atrac3p_huff_wav_ampsf2_xlat, atrac3p_huff_wav_ampsf3_xlat,
156
+        atrac3p_huff_freq_xlat
157
+    };
158
+
159
+    for (i = 0, wl_vlc_offs = 0, ct_vlc_offs = 2508; i < 4; i++) {
160
+        wl_vlc_tabs[i].table = &tables_data[wl_vlc_offs];
161
+        wl_vlc_tabs[i].table_allocated = 1 << wl_nb_bits[i];
162
+        ct_vlc_tabs[i].table = &tables_data[ct_vlc_offs];
163
+        ct_vlc_tabs[i].table_allocated = 1 << ct_nb_bits[i];
164
+
165
+        ff_init_vlc_sparse(&wl_vlc_tabs[i], wl_nb_bits[i], wl_nb_codes[i],
166
+                           wl_bits[i],  1, 1,
167
+                           wl_codes[i], 1, 1,
168
+                           wl_xlats[i], 1, 1,
169
+                           INIT_VLC_USE_NEW_STATIC);
170
+
171
+        ff_init_vlc_sparse(&ct_vlc_tabs[i], ct_nb_bits[i], ct_nb_codes[i],
172
+                           ct_bits[i],  1, 1,
173
+                           ct_codes[i], 1, 1,
174
+                           ct_xlats[i], 1, 1,
175
+                           INIT_VLC_USE_NEW_STATIC);
176
+
177
+        wl_vlc_offs += wl_vlc_tabs[i].table_allocated;
178
+        ct_vlc_offs += ct_vlc_tabs[i].table_allocated;
179
+    }
180
+
181
+    for (i = 0, sf_vlc_offs = 76; i < 8; i++) {
182
+        sf_vlc_tabs[i].table = &tables_data[sf_vlc_offs];
183
+        sf_vlc_tabs[i].table_allocated = 1 << sf_nb_bits[i];
184
+
185
+        ff_init_vlc_sparse(&sf_vlc_tabs[i], sf_nb_bits[i], sf_nb_codes[i],
186
+                           sf_bits[i],  1, 1,
187
+                           sf_codes[i], 2, 2,
188
+                           sf_xlats[i], 1, 1,
189
+                           INIT_VLC_USE_NEW_STATIC);
190
+        sf_vlc_offs += sf_vlc_tabs[i].table_allocated;
191
+    }
192
+
193
+    tab_offset = 2564;
194
+
195
+    /* build huffman tables for spectrum decoding */
196
+    for (i = 0; i < 112; i++) {
197
+        if (atrac3p_spectra_tabs[i].cb)
198
+            build_canonical_huff(atrac3p_spectra_tabs[i].cb,
199
+                                 atrac3p_spectra_tabs[i].xlat,
200
+                                 &tab_offset, &spec_vlc_tabs[i]);
201
+        else
202
+            spec_vlc_tabs[i].table = 0;
203
+    }
204
+
205
+    /* build huffman tables for gain data decoding */
206
+    for (i = 0; i < 11; i++)
207
+        build_canonical_huff(gain_cbs[i], gain_xlats[i], &tab_offset, &gain_vlc_tabs[i]);
208
+
209
+    /* build huffman tables for tone decoding */
210
+    for (i = 0; i < 7; i++)
211
+        build_canonical_huff(tone_cbs[i], tone_xlats[i], &tab_offset, &tone_vlc_tabs[i]);
212
+}
213
+
214
+/**
215
+ * Decode number of coded quantization units.
216
+ *
217
+ * @param[in]     gb            the GetBit context
218
+ * @param[in,out] chan          ptr to the channel parameters
219
+ * @param[in,out] ctx           ptr to the channel unit context
220
+ * @param[in]     avctx         ptr to the AVCodecContext
221
+ * @return result code: 0 = OK, otherwise - error code
222
+ */
223
+static int num_coded_units(GetBitContext *gb, Atrac3pChanParams *chan,
224
+                           Atrac3pChanUnitCtx *ctx, AVCodecContext *avctx)
225
+{
226
+    chan->fill_mode = get_bits(gb, 2);
227
+    if (!chan->fill_mode) {
228
+        chan->num_coded_vals = ctx->num_quant_units;
229
+    } else {
230
+        chan->num_coded_vals = get_bits(gb, 5);
231
+        if (chan->num_coded_vals > ctx->num_quant_units) {
232
+            av_log(avctx, AV_LOG_ERROR,
233
+                   "Invalid number of transmitted units!\n");
234
+            return AVERROR_INVALIDDATA;
235
+        }
236
+
237
+        if (chan->fill_mode == 3)
238
+            chan->split_point = get_bits(gb, 2) + (chan->ch_num << 1) + 1;
239
+    }
240
+
241
+    return 0;
242
+}
243
+
244
+/**
245
+ * Add weighting coefficients to the decoded word-length information.
246
+ *
247
+ * @param[in,out] ctx           ptr to the channel unit context
248
+ * @param[in,out] chan          ptr to the channel parameters
249
+ * @param[in]     avctx         ptr to the AVCodecContext
250
+ * @return result code: 0 = OK, otherwise - error code
251
+ */
252
+static int add_wordlen_weights(Atrac3pChanUnitCtx *ctx,
253
+                               Atrac3pChanParams *chan, int wtab_idx,
254
+                               AVCodecContext *avctx)
255
+{
256
+    int i;
257
+    const int8_t *weights_tab =
258
+        &atrac3p_wl_weights[chan->ch_num * 3 + wtab_idx - 1][0];
259
+
260
+    for (i = 0; i < ctx->num_quant_units; i++) {
261
+        chan->qu_wordlen[i] += weights_tab[i];
262
+        if (chan->qu_wordlen[i] < 0 || chan->qu_wordlen[i] > 7) {
263
+            av_log(avctx, AV_LOG_ERROR,
264
+                   "WL index out of range: pos=%d, val=%d!\n",
265
+                   i, chan->qu_wordlen[i]);
266
+            return AVERROR_INVALIDDATA;
267
+        }
268
+    }
269
+
270
+    return 0;
271
+}
272
+
273
+/**
274
+ * Subtract weighting coefficients from decoded scalefactors.
275
+ *
276
+ * @param[in,out] ctx           ptr to the channel unit context
277
+ * @param[in,out] chan          ptr to the channel parameters
278
+ * @param[in]     wtab_idx      index of table of weights
279
+ * @param[in]     avctx         ptr to the AVCodecContext
280
+ * @return result code: 0 = OK, otherwise - error code
281
+ */
282
+static int subtract_sf_weights(Atrac3pChanUnitCtx *ctx,
283
+                               Atrac3pChanParams *chan, int wtab_idx,
284
+                               AVCodecContext *avctx)
285
+{
286
+    int i;
287
+    const int8_t *weights_tab = &atrac3p_sf_weights[wtab_idx - 1][0];
288
+
289
+    for (i = 0; i < ctx->used_quant_units; i++) {
290
+        chan->qu_sf_idx[i] -= weights_tab[i];
291
+        if (chan->qu_sf_idx[i] < 0 || chan->qu_sf_idx[i] > 63) {
292
+            av_log(avctx, AV_LOG_ERROR,
293
+                   "SF index out of range: pos=%d, val=%d!\n",
294
+                   i, chan->qu_sf_idx[i]);
295
+            return AVERROR_INVALIDDATA;
296
+        }
297
+    }
298
+
299
+    return 0;
300
+}
301
+
302
+/**
303
+ * Unpack vector quantization tables.
304
+ *
305
+ * @param[in]    start_val    start value for the unpacked table
306
+ * @param[in]    shape_vec    ptr to table to unpack
307
+ * @param[out]   dst          ptr to output array
308
+ * @param[in]    num_values   number of values to unpack
309
+ */
310
+static inline void unpack_vq_shape(int start_val, const int8_t *shape_vec,
311
+                                   int *dst, int num_values)
312
+{
313
+    int i;
314
+
315
+    if (num_values) {
316
+        dst[0] = dst[1] = dst[2] = start_val;
317
+        for (i = 3; i < num_values; i++)
318
+            dst[i] = start_val - shape_vec[atrac3p_qu_num_to_seg[i] - 1];
319
+    }
320
+}
321
+
322
+#define UNPACK_SF_VQ_SHAPE(gb, dst, num_vals)                            \
323
+    start_val = get_bits((gb), 6);                                       \
324
+    unpack_vq_shape(start_val, &atrac3p_sf_shapes[get_bits((gb), 6)][0], \
325
+                    (dst), (num_vals))
326
+
327
+/**
328
+ * Decode word length for each quantization unit of a channel.
329
+ *
330
+ * @param[in]     gb            the GetBit context
331
+ * @param[in,out] ctx           ptr to the channel unit context
332
+ * @param[in]     ch_num        channel to process
333
+ * @param[in]     avctx         ptr to the AVCodecContext
334
+ * @return result code: 0 = OK, otherwise - error code
335
+ */
336
+static int decode_channel_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
337
+                                  int ch_num, AVCodecContext *avctx)
338
+{
339
+    int i, weight_idx = 0, delta, diff, pos, delta_bits, min_val, flag,
340
+        ret, start_val;
341
+    VLC *vlc_tab;
342
+    Atrac3pChanParams *chan     = &ctx->channels[ch_num];
343
+    Atrac3pChanParams *ref_chan = &ctx->channels[0];
344
+
345
+    chan->fill_mode = 0;
346
+
347
+    switch (get_bits(gb, 2)) { /* switch according to coding mode */
348
+    case 0: /* coded using constant number of bits */
349
+        for (i = 0; i < ctx->num_quant_units; i++)
350
+            chan->qu_wordlen[i] = get_bits(gb, 3);
351
+        break;
352
+    case 1:
353
+        if (ch_num) {
354
+            if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0)
355
+                return ret;
356
+
357
+            if (chan->num_coded_vals) {
358
+                vlc_tab = &wl_vlc_tabs[get_bits(gb, 2)];
359
+
360
+                for (i = 0; i < chan->num_coded_vals; i++) {
361
+                    delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
362
+                    chan->qu_wordlen[i] = (ref_chan->qu_wordlen[i] + delta) & 7;
363
+                }
364
+            }
365
+        } else {
366
+            weight_idx = get_bits(gb, 2);
367
+            if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0)
368
+                return ret;
369
+
370
+            if (chan->num_coded_vals) {
371
+                pos = get_bits(gb, 5);
372
+                if (pos > chan->num_coded_vals) {
373
+                    av_log(avctx, AV_LOG_ERROR,
374
+                           "WL mode 1: invalid position!\n");
375
+                    return AVERROR_INVALIDDATA;
376
+                }
377
+
378
+                delta_bits = get_bits(gb, 2);
379
+                min_val    = get_bits(gb, 3);
380
+
381
+                for (i = 0; i < pos; i++)
382
+                    chan->qu_wordlen[i] = get_bits(gb, 3);
383
+
384
+                for (i = pos; i < chan->num_coded_vals; i++)
385
+                    chan->qu_wordlen[i] = (min_val + GET_DELTA(gb, delta_bits)) & 7;
386
+            }
387
+        }
388
+        break;
389
+    case 2:
390
+        if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0)
391
+            return ret;
392
+
393
+        if (ch_num && chan->num_coded_vals) {
394
+            vlc_tab = &wl_vlc_tabs[get_bits(gb, 2)];
395
+            delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
396
+            chan->qu_wordlen[0] = (ref_chan->qu_wordlen[0] + delta) & 7;
397
+
398
+            for (i = 1; i < chan->num_coded_vals; i++) {
399
+                diff = ref_chan->qu_wordlen[i] - ref_chan->qu_wordlen[i - 1];
400
+                delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
401
+                chan->qu_wordlen[i] = (chan->qu_wordlen[i - 1] + diff + delta) & 7;
402
+            }
403
+        } else if (chan->num_coded_vals) {
404
+            flag    = get_bits(gb, 1);
405
+            vlc_tab = &wl_vlc_tabs[get_bits(gb, 1)];
406
+
407
+            start_val = get_bits(gb, 3);
408
+            unpack_vq_shape(start_val,
409
+                            &atrac3p_wl_shapes[start_val][get_bits(gb, 4)][0],
410
+                            chan->qu_wordlen, chan->num_coded_vals);
411
+
412
+            if (!flag) {
413
+                for (i = 0; i < chan->num_coded_vals; i++) {
414
+                    delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
415
+                    chan->qu_wordlen[i] = (chan->qu_wordlen[i] + delta) & 7;
416
+                }
417
+            } else {
418
+                for (i = 0; i < (chan->num_coded_vals & - 2); i += 2)
419
+                    if (!get_bits1(gb)) {
420
+                        chan->qu_wordlen[i]     = (chan->qu_wordlen[i] +
421
+                                                   get_vlc2(gb, vlc_tab->table,
422
+                                                            vlc_tab->bits, 1)) & 7;
423
+                        chan->qu_wordlen[i + 1] = (chan->qu_wordlen[i + 1] +
424
+                                                   get_vlc2(gb, vlc_tab->table,
425
+                                                            vlc_tab->bits, 1)) & 7;
426
+                    }
427
+
428
+                if (chan->num_coded_vals & 1)
429
+                    chan->qu_wordlen[i] = (chan->qu_wordlen[i] +
430
+                                           get_vlc2(gb, vlc_tab->table,
431
+                                                    vlc_tab->bits, 1)) & 7;
432
+            }
433
+        }
434
+        break;
435
+    case 3:
436
+        weight_idx = get_bits(gb, 2);
437
+        if ((ret = num_coded_units(gb, chan, ctx, avctx)) < 0)
438
+            return ret;
439
+
440
+        if (chan->num_coded_vals) {
441
+            vlc_tab = &wl_vlc_tabs[get_bits(gb, 2)];
442
+
443
+            /* first coefficient is coded directly */
444
+            chan->qu_wordlen[0] = get_bits(gb, 3);
445
+
446
+            for (i = 1; i < chan->num_coded_vals; i++) {
447
+                delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
448
+                chan->qu_wordlen[i] = (chan->qu_wordlen[i - 1] + delta) & 7;
449
+            }
450
+        }
451
+        break;
452
+    }
453
+
454
+    if (chan->fill_mode == 2) {
455
+        for (i = chan->num_coded_vals; i < ctx->num_quant_units; i++)
456
+            chan->qu_wordlen[i] = ch_num ? get_bits1(gb) : 1;
457
+    } else if (chan->fill_mode == 3) {
458
+        pos = ch_num ? chan->num_coded_vals + chan->split_point
459
+                     : ctx->num_quant_units - chan->split_point;
460
+        for (i = chan->num_coded_vals; i < pos; i++)
461
+            chan->qu_wordlen[i] = 1;
462
+    }
463
+
464
+    if (weight_idx)
465
+        return add_wordlen_weights(ctx, chan, weight_idx, avctx);
466
+
467
+    return 0;
468
+}
469
+
470
+/**
471
+ * Decode scale factor indexes for each quant unit of a channel.
472
+ *
473
+ * @param[in]     gb            the GetBit context
474
+ * @param[in,out] ctx           ptr to the channel unit context
475
+ * @param[in]     ch_num        channel to process
476
+ * @param[in]     avctx         ptr to the AVCodecContext
477
+ * @return result code: 0 = OK, otherwise - error code
478
+ */
479
+static int decode_channel_sf_idx(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
480
+                                 int ch_num, AVCodecContext *avctx)
481
+{
482
+    int i, weight_idx = 0, delta, diff, num_long_vals,
483
+        delta_bits, min_val, vlc_sel, start_val;
484
+    VLC *vlc_tab;
485
+    Atrac3pChanParams *chan     = &ctx->channels[ch_num];
486
+    Atrac3pChanParams *ref_chan = &ctx->channels[0];
487
+
488
+    switch (get_bits(gb, 2)) { /* switch according to coding mode */
489
+    case 0: /* coded using constant number of bits */
490
+        for (i = 0; i < ctx->used_quant_units; i++)
491
+            chan->qu_sf_idx[i] = get_bits(gb, 6);
492
+        break;
493
+    case 1:
494
+        if (ch_num) {
495
+            vlc_tab = &sf_vlc_tabs[get_bits(gb, 2)];
496
+
497
+            for (i = 0; i < ctx->used_quant_units; i++) {
498
+                delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
499
+                chan->qu_sf_idx[i] = (ref_chan->qu_sf_idx[i] + delta) & 0x3F;
500
+            }
501
+        } else {
502
+            weight_idx = get_bits(gb, 2);
503
+            if (weight_idx == 3) {
504
+                UNPACK_SF_VQ_SHAPE(gb, chan->qu_sf_idx, ctx->used_quant_units);
505
+
506
+                num_long_vals = get_bits(gb, 5);
507
+                delta_bits    = get_bits(gb, 2);
508
+                min_val       = get_bits(gb, 4) - 7;
509
+
510
+                for (i = 0; i < num_long_vals; i++)
511
+                    chan->qu_sf_idx[i] = (chan->qu_sf_idx[i] +
512
+                                          get_bits(gb, 4) - 7) & 0x3F;
513
+
514
+                /* all others are: min_val + delta */
515
+                for (i = num_long_vals; i < ctx->used_quant_units; i++)
516
+                    chan->qu_sf_idx[i] = (chan->qu_sf_idx[i] + min_val +
517
+                                          GET_DELTA(gb, delta_bits)) & 0x3F;
518
+            } else {
519
+                num_long_vals = get_bits(gb, 5);
520
+                delta_bits    = get_bits(gb, 3);
521
+                min_val       = get_bits(gb, 6);
522
+                if (num_long_vals > ctx->used_quant_units || delta_bits == 7) {
523
+                    av_log(avctx, AV_LOG_ERROR,
524
+                           "SF mode 1: invalid parameters!\n");
525
+                    return AVERROR_INVALIDDATA;
526
+                }
527
+
528
+                /* read full-precision SF indexes */
529
+                for (i = 0; i < num_long_vals; i++)
530
+                    chan->qu_sf_idx[i] = get_bits(gb, 6);
531
+
532
+                /* all others are: min_val + delta */
533
+                for (i = num_long_vals; i < ctx->used_quant_units; i++)
534
+                    chan->qu_sf_idx[i] = (min_val +
535
+                                          GET_DELTA(gb, delta_bits)) & 0x3F;
536
+            }
537
+        }
538
+        break;
539
+    case 2:
540
+        if (ch_num) {
541
+            vlc_tab = &sf_vlc_tabs[get_bits(gb, 2)];
542
+
543
+            delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
544
+            chan->qu_sf_idx[0] = (ref_chan->qu_sf_idx[0] + delta) & 0x3F;
545
+
546
+            for (i = 1; i < ctx->used_quant_units; i++) {
547
+                diff  = ref_chan->qu_sf_idx[i] - ref_chan->qu_sf_idx[i - 1];
548
+                delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
549
+                chan->qu_sf_idx[i] = (chan->qu_sf_idx[i - 1] + diff + delta) & 0x3F;
550
+            }
551
+        } else {
552
+            vlc_tab = &sf_vlc_tabs[get_bits(gb, 2) + 4];
553
+
554
+            UNPACK_SF_VQ_SHAPE(gb, chan->qu_sf_idx, ctx->used_quant_units);
555
+
556
+            for (i = 0; i < ctx->used_quant_units; i++) {
557
+                delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
558
+                chan->qu_sf_idx[i] = (chan->qu_sf_idx[i] +
559
+                                      sign_extend(delta, 4)) & 0x3F;
560
+            }
561
+        }
562
+        break;
563
+    case 3:
564
+        if (ch_num) {
565
+            /* copy coefficients from reference channel */
566
+            for (i = 0; i < ctx->used_quant_units; i++)
567
+                chan->qu_sf_idx[i] = ref_chan->qu_sf_idx[i];
568
+        } else {
569
+            weight_idx = get_bits(gb, 2);
570
+            vlc_sel    = get_bits(gb, 2);
571
+            vlc_tab    = &sf_vlc_tabs[vlc_sel];
572
+
573
+            if (weight_idx == 3) {
574
+                vlc_tab = &sf_vlc_tabs[vlc_sel + 4];
575
+
576
+                UNPACK_SF_VQ_SHAPE(gb, chan->qu_sf_idx, ctx->used_quant_units);
577
+
578
+                diff               = (get_bits(gb, 4)    + 56)   & 0x3F;
579
+                chan->qu_sf_idx[0] = (chan->qu_sf_idx[0] + diff) & 0x3F;
580
+
581
+                for (i = 1; i < ctx->used_quant_units; i++) {
582
+                    delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
583
+                    diff               = (diff + sign_extend(delta, 4)) & 0x3F;
584
+                    chan->qu_sf_idx[i] = (diff + chan->qu_sf_idx[i])    & 0x3F;
585
+                }
586
+            } else {
587
+                /* 1st coefficient is coded directly */
588
+                chan->qu_sf_idx[0] = get_bits(gb, 6);
589
+
590
+                for (i = 1; i < ctx->used_quant_units; i++) {
591
+                    delta = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
592
+                    chan->qu_sf_idx[i] = (chan->qu_sf_idx[i - 1] + delta) & 0x3F;
593
+                }
594
+            }
595
+        }
596
+        break;
597
+    }
598
+
599
+    if (weight_idx && weight_idx < 3)
600
+        return subtract_sf_weights(ctx, chan, weight_idx, avctx);
601
+
602
+    return 0;
603
+}
604
+
605
+/**
606
+ * Decode word length information for each channel.
607
+ *
608
+ * @param[in]     gb            the GetBit context
609
+ * @param[in,out] ctx           ptr to the channel unit context
610
+ * @param[in]     num_channels  number of channels to process
611
+ * @param[in]     avctx         ptr to the AVCodecContext
612
+ * @return result code: 0 = OK, otherwise - error code
613
+ */
614
+static int decode_quant_wordlen(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
615
+                                int num_channels, AVCodecContext *avctx)
616
+{
617
+    int ch_num, i, ret;
618
+
619
+    for (ch_num = 0; ch_num < num_channels; ch_num++) {
620
+        memset(ctx->channels[ch_num].qu_wordlen, 0,
621
+               sizeof(ctx->channels[ch_num].qu_wordlen));
622
+
623
+        if ((ret = decode_channel_wordlen(gb, ctx, ch_num, avctx)) < 0)
624
+            return ret;
625
+    }
626
+
627
+    /* scan for last non-zero coeff in both channels and
628
+     * set number of quant units having coded spectrum */
629
+    for (i = ctx->num_quant_units - 1; i >= 0; i--)
630
+        if (ctx->channels[0].qu_wordlen[i] ||
631
+            (num_channels == 2 && ctx->channels[1].qu_wordlen[i]))
632
+            break;
633
+    ctx->used_quant_units = i + 1;
634
+
635
+    return 0;
636
+}
637
+
638
+/**
639
+ * Decode scale factor indexes for each channel.
640
+ *
641
+ * @param[in]     gb            the GetBit context
642
+ * @param[in,out] ctx           ptr to the channel unit context
643
+ * @param[in]     num_channels  number of channels to process
644
+ * @param[in]     avctx         ptr to the AVCodecContext
645
+ * @return result code: 0 = OK, otherwise - error code
646
+ */
647
+static int decode_scale_factors(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
648
+                                int num_channels, AVCodecContext *avctx)
649
+{
650
+    int ch_num, ret;
651
+
652
+    if (!ctx->used_quant_units)
653
+        return 0;
654
+
655
+    for (ch_num = 0; ch_num < num_channels; ch_num++) {
656
+        memset(ctx->channels[ch_num].qu_sf_idx, 0,
657
+               sizeof(ctx->channels[ch_num].qu_sf_idx));
658
+
659
+        if ((ret = decode_channel_sf_idx(gb, ctx, ch_num, avctx)) < 0)
660
+            return ret;
661
+    }
662
+
663
+    return 0;
664
+}
665
+
666
+/**
667
+ * Decode number of code table values.
668
+ *
669
+ * @param[in]     gb            the GetBit context
670
+ * @param[in,out] ctx           ptr to the channel unit context
671
+ * @param[in]     avctx         ptr to the AVCodecContext
672
+ * @return result code: 0 = OK, otherwise - error code
673
+ */
674
+static int get_num_ct_values(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
675
+                             AVCodecContext *avctx)
676
+{
677
+    int num_coded_vals;
678
+
679
+    if (get_bits1(gb)) {
680
+        num_coded_vals = get_bits(gb, 5);
681
+        if (num_coded_vals > ctx->used_quant_units) {
682
+            av_log(avctx, AV_LOG_ERROR,
683
+                   "Invalid number of code table indexes: %d!\n", num_coded_vals);
684
+            return AVERROR_INVALIDDATA;
685
+        }
686
+        return num_coded_vals;
687
+    } else
688
+        return ctx->used_quant_units;
689
+}
690
+
691
+#define DEC_CT_IDX_COMMON(OP)                                           \
692
+    num_vals = get_num_ct_values(gb, ctx, avctx);                       \
693
+    if (num_vals < 0)                                                   \
694
+        return num_vals;                                                \
695
+                                                                        \
696
+    for (i = 0; i < num_vals; i++) {                                    \
697
+        if (chan->qu_wordlen[i]) {                                      \
698
+            chan->qu_tab_idx[i] = OP;                                   \
699
+        } else if (ch_num && ref_chan->qu_wordlen[i])                   \
700
+            /* get clone master flag */                                 \
701
+            chan->qu_tab_idx[i] = get_bits1(gb);                        \
702
+    }
703
+
704
+#define CODING_DIRECT get_bits(gb, num_bits)
705
+
706
+#define CODING_VLC get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1)
707
+
708
+#define CODING_VLC_DELTA                                                \
709
+    (!i) ? CODING_VLC                                                   \
710
+         : (pred + get_vlc2(gb, delta_vlc->table,                       \
711
+                            delta_vlc->bits, 1)) & mask;                \
712
+    pred = chan->qu_tab_idx[i]
713
+
714
+#define CODING_VLC_DIFF                                                 \
715
+    (ref_chan->qu_tab_idx[i] +                                          \
716
+     get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1)) & mask
717
+
718
+/**
719
+ * Decode code table indexes for each quant unit of a channel.
720
+ *
721
+ * @param[in]     gb            the GetBit context
722
+ * @param[in,out] ctx           ptr to the channel unit context
723
+ * @param[in]     ch_num        channel to process
724
+ * @param[in]     avctx         ptr to the AVCodecContext
725
+ * @return result code: 0 = OK, otherwise - error code
726
+ */
727
+static int decode_channel_code_tab(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
728
+                                   int ch_num, AVCodecContext *avctx)
729
+{
730
+    int i, num_vals, num_bits, pred;
731
+    int mask = ctx->use_full_table ? 7 : 3; /* mask for modular arithmetic */
732
+    VLC *vlc_tab, *delta_vlc;
733
+    Atrac3pChanParams *chan     = &ctx->channels[ch_num];
734
+    Atrac3pChanParams *ref_chan = &ctx->channels[0];
735
+
736
+    chan->table_type = get_bits1(gb);
737
+
738
+    switch (get_bits(gb, 2)) { /* switch according to coding mode */
739
+    case 0: /* directly coded */
740
+        num_bits = ctx->use_full_table + 2;
741
+        DEC_CT_IDX_COMMON(CODING_DIRECT);
742
+        break;
743
+    case 1: /* entropy-coded */
744
+        vlc_tab = ctx->use_full_table ? &ct_vlc_tabs[1]
745
+                                      : ct_vlc_tabs;
746
+        DEC_CT_IDX_COMMON(CODING_VLC);
747
+        break;
748
+    case 2: /* entropy-coded delta */
749
+        if (ctx->use_full_table) {
750
+            vlc_tab   = &ct_vlc_tabs[1];
751
+            delta_vlc = &ct_vlc_tabs[2];
752
+        } else {
753
+            vlc_tab   = ct_vlc_tabs;
754
+            delta_vlc = ct_vlc_tabs;
755
+        }
756
+        pred = 0;
757
+        DEC_CT_IDX_COMMON(CODING_VLC_DELTA);
758
+        break;
759
+    case 3: /* entropy-coded difference to master */
760
+        if (ch_num) {
761
+            vlc_tab = ctx->use_full_table ? &ct_vlc_tabs[3]
762
+                                          : ct_vlc_tabs;
763
+            DEC_CT_IDX_COMMON(CODING_VLC_DIFF);
764
+        }
765
+        break;
766
+    }
767
+
768
+    return 0;
769
+}
770
+
771
+/**
772
+ * Decode code table indexes for each channel.
773
+ *
774
+ * @param[in]     gb            the GetBit context
775
+ * @param[in,out] ctx           ptr to the channel unit context
776
+ * @param[in]     num_channels  number of channels to process
777
+ * @param[in]     avctx         ptr to the AVCodecContext
778
+ * @return result code: 0 = OK, otherwise - error code
779
+ */
780
+static int decode_code_table_indexes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
781
+                                     int num_channels, AVCodecContext *avctx)
782
+{
783
+    int ch_num, ret;
784
+
785
+    if (!ctx->used_quant_units)
786
+        return 0;
787
+
788
+    ctx->use_full_table = get_bits1(gb);
789
+
790
+    for (ch_num = 0; ch_num < num_channels; ch_num++) {
791
+        memset(ctx->channels[ch_num].qu_tab_idx, 0,
792
+               sizeof(ctx->channels[ch_num].qu_tab_idx));
793
+
794
+        if ((ret = decode_channel_code_tab(gb, ctx, ch_num, avctx)) < 0)
795
+            return ret;
796
+    }
797
+
798
+    return 0;
799
+}
800
+
801
+/**
802
+ * Decode huffman-coded spectral lines for a given quant unit.
803
+ *
804
+ * This is a generalized version for all known coding modes.
805
+ * Its speed can be improved by creating separate functions for each mode.
806
+ *
807
+ * @param[in]   gb          the GetBit context
808
+ * @param[in]   tab         code table telling how to decode spectral lines
809
+ * @param[in]   vlc_tab     ptr to the huffman table associated with the code table
810
+ * @param[out]  out         pointer to buffer where decoded data should be stored
811
+ * @param[in]   num_specs   number of spectral lines to decode
812
+ */
813
+static void decode_qu_spectra(GetBitContext *gb, const Atrac3pSpecCodeTab *tab,
814
+                              VLC *vlc_tab, int16_t *out, const int num_specs)
815
+{
816
+    int i, j, pos, cf;
817
+    int group_size = tab->group_size;
818
+    int num_coeffs = tab->num_coeffs;
819
+    int bits       = tab->bits;
820
+    int is_signed  = tab->is_signed;
821
+    unsigned val, mask = (1 << bits) - 1;
822
+
823
+    for (pos = 0; pos < num_specs;) {
824
+        if (group_size == 1 || get_bits1(gb)) {
825
+            for (j = 0; j < group_size; j++) {
826
+                val = get_vlc2(gb, vlc_tab->table, vlc_tab->bits, 1);
827
+
828
+                for (i = 0; i < num_coeffs; i++) {
829
+                    cf = val & mask;
830
+                    if (is_signed)
831
+                        cf = sign_extend(cf, bits);
832
+                    else if (cf && get_bits1(gb))
833
+                        cf = -cf;
834
+
835
+                    out[pos++] = cf;
836
+                    val      >>= bits;
837
+                }
838
+            }
839
+        } else /* group skipped */
840
+            pos += group_size * num_coeffs;
841
+    }
842
+}
843
+
844
+/**
845
+ * Decode huffman-coded IMDCT spectrum for all channels.
846
+ *
847
+ * @param[in]     gb            the GetBit context
848
+ * @param[in,out] ctx           ptr to the channel unit context
849
+ * @param[in]     num_channels  number of channels to process
850
+ * @param[in]     avctx         ptr to the AVCodecContext
851
+ */
852
+static void decode_spectrum(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
853
+                            int num_channels, AVCodecContext *avctx)
854
+{
855
+    int i, ch_num, qu, wordlen, codetab, tab_index, num_specs;
856
+    const Atrac3pSpecCodeTab *tab;
857
+    Atrac3pChanParams *chan;
858
+
859
+    for (ch_num = 0; ch_num < num_channels; ch_num++) {
860
+        chan = &ctx->channels[ch_num];
861
+
862
+        memset(chan->spectrum, 0, sizeof(chan->spectrum));
863
+
864
+        /* set power compensation level to disabled */
865
+        memset(chan->power_levs, ATRAC3P_POWER_COMP_OFF, sizeof(chan->power_levs));
866
+
867
+        for (qu = 0; qu < ctx->used_quant_units; qu++) {
868
+            num_specs = ff_atrac3p_qu_to_spec_pos[qu + 1] -
869
+                        ff_atrac3p_qu_to_spec_pos[qu];
870
+
871
+            wordlen = chan->qu_wordlen[qu];
872
+            codetab = chan->qu_tab_idx[qu];
873
+            if (wordlen) {
874
+                if (!ctx->use_full_table)
875
+                    codetab = atrac3p_ct_restricted_to_full[chan->table_type][wordlen - 1][codetab];
876
+
877
+                tab_index = (chan->table_type * 8 + codetab) * 7 + wordlen - 1;
878
+                tab       = &atrac3p_spectra_tabs[tab_index];
879
+
880
+                /* this allows reusing VLC tables */
881
+                if (tab->redirect >= 0)
882
+                    tab_index = tab->redirect;
883
+
884
+                decode_qu_spectra(gb, tab, &spec_vlc_tabs[tab_index],
885
+                                  &chan->spectrum[ff_atrac3p_qu_to_spec_pos[qu]],
886
+                                  num_specs);
887
+            } else if (ch_num && ctx->channels[0].qu_wordlen[qu] && !codetab) {
888
+                /* copy coefficients from master */
889
+                memcpy(&chan->spectrum[ff_atrac3p_qu_to_spec_pos[qu]],
890
+                       &ctx->channels[0].spectrum[ff_atrac3p_qu_to_spec_pos[qu]],
891
+                       num_specs *
892
+                       sizeof(chan->spectrum[ff_atrac3p_qu_to_spec_pos[qu]]));
893
+                chan->qu_wordlen[qu] = ctx->channels[0].qu_wordlen[qu];
894
+            }
895
+        }
896
+
897
+        /* Power compensation levels only present in the bitstream
898
+         * if there are more than 2 quant units. The lowest two units
899
+         * correspond to the frequencies 0...351 Hz, whose shouldn't
900
+         * be affected by the power compensation. */
901
+        if (ctx->used_quant_units > 2) {
902
+            num_specs = atrac3p_subband_to_num_powgrps[ctx->num_coded_subbands - 1];
903
+            for (i = 0; i < num_specs; i++)
904
+                chan->power_levs[i] = get_bits(gb, 4);
905
+        }
906
+    }
907
+}
908
+
909
+/**
910
+ * Retrieve specified amount of flag bits from the input bitstream.
911
+ * The data can be shortened in the case of the following two common conditions:
912
+ * if all bits are zero then only one signal bit = 0 will be stored,
913
+ * if all bits are ones then two signal bits = 1,0 will be stored.
914
+ * Otherwise, all necessary bits will be directly stored
915
+ * prefixed by two signal bits = 1,1.
916
+ *
917
+ * @param[in]   gb              ptr to the GetBitContext
918
+ * @param[out]  out             where to place decoded flags
919
+ * @param[in]   num_flags       number of flags to process
920
+ * @return: 0 = all flag bits are zero, 1 = there is at least one non-zero flag bit
921
+ */
922
+static int get_subband_flags(GetBitContext *gb, uint8_t *out, int num_flags)
923
+{
924
+    int i, result;
925
+
926
+    memset(out, 0, num_flags);
927
+
928
+    result = get_bits1(gb);
929
+    if (result) {
930
+        if (get_bits1(gb))
931
+            for (i = 0; i < num_flags; i++)
932
+                out[i] = get_bits1(gb);
933
+        else
934
+            memset(out, 1, num_flags);
935
+    }
936
+
937
+    return result;
938
+}
939
+
940
+/**
941
+ * Decode mdct window shape flags for all channels.
942
+ *
943
+ * @param[in]     gb            the GetBit context
944
+ * @param[in,out] ctx           ptr to the channel unit context
945
+ * @param[in]     num_channels  number of channels to process
946
+ */
947
+static void decode_window_shape(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
948
+                                int num_channels)
949
+{
950
+    int ch_num;
951
+
952
+    for (ch_num = 0; ch_num < num_channels; ch_num++)
953
+        get_subband_flags(gb, ctx->channels[ch_num].wnd_shape,
954
+                          ctx->num_subbands);
955
+}
956
+
957
+/**
958
+ * Decode number of gain control points.
959
+ *
960
+ * @param[in]     gb              the GetBit context
961
+ * @param[in,out] ctx             ptr to the channel unit context
962
+ * @param[in]     ch_num          channel to process
963
+ * @param[in]     coded_subbands  number of subbands to process
964
+ * @return result code: 0 = OK, otherwise - error code
965
+ */
966
+static int decode_gainc_npoints(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
967
+                                int ch_num, int coded_subbands)
968
+{
969
+    int i, delta, delta_bits, min_val;
970
+    Atrac3pChanParams *chan     = &ctx->channels[ch_num];
971
+    Atrac3pChanParams *ref_chan = &ctx->channels[0];
972
+
973
+    switch (get_bits(gb, 2)) { /* switch according to coding mode */
974
+    case 0: /* fixed-length coding */
975
+        for (i = 0; i < coded_subbands; i++)
976
+            chan->gain_data[i].num_points = get_bits(gb, 3);
977
+        break;
978
+    case 1: /* variable-length coding */
979
+        for (i = 0; i < coded_subbands; i++)
980
+            chan->gain_data[i].num_points =
981
+                get_vlc2(gb, gain_vlc_tabs[0].table,
982
+                         gain_vlc_tabs[0].bits, 1);
983
+        break;
984
+    case 2:
985
+        if (ch_num) { /* VLC modulo delta to master channel */
986
+            for (i = 0; i < coded_subbands; i++) {
987
+                delta = get_vlc2(gb, gain_vlc_tabs[1].table,
988
+                                 gain_vlc_tabs[1].bits, 1);
989
+                chan->gain_data[i].num_points =
990
+                    (ref_chan->gain_data[i].num_points + delta) & 7;
991
+            }
992
+        } else { /* VLC modulo delta to previous */
993
+            chan->gain_data[0].num_points =
994
+                get_vlc2(gb, gain_vlc_tabs[0].table,
995
+                         gain_vlc_tabs[0].bits, 1);
996
+
997
+            for (i = 1; i < coded_subbands; i++) {
998
+                delta = get_vlc2(gb, gain_vlc_tabs[1].table,
999
+                                 gain_vlc_tabs[1].bits, 1);
1000
+                chan->gain_data[i].num_points =
1001
+                    (chan->gain_data[i - 1].num_points + delta) & 7;
1002
+            }
1003
+        }
1004
+        break;
1005
+    case 3:
1006
+        if (ch_num) { /* copy data from master channel */
1007
+            for (i = 0; i < coded_subbands; i++)
1008
+                chan->gain_data[i].num_points =
1009
+                    ref_chan->gain_data[i].num_points;
1010
+        } else { /* shorter delta to min */
1011
+            delta_bits = get_bits(gb, 2);
1012
+            min_val    = get_bits(gb, 3);
1013
+
1014
+            for (i = 0; i < coded_subbands; i++) {
1015
+                chan->gain_data[i].num_points = min_val + GET_DELTA(gb, delta_bits);
1016
+                if (chan->gain_data[i].num_points > 7)
1017
+                    return AVERROR_INVALIDDATA;
1018
+            }
1019
+        }
1020
+    }
1021
+
1022
+    return 0;
1023
+}
1024
+
1025
+/**
1026
+ * Implements coding mode 3 (slave) for gain compensation levels.
1027
+ *
1028
+ * @param[out]   dst   ptr to the output array
1029
+ * @param[in]    ref   ptr to the reference channel
1030
+ */
1031
+static inline void gainc_level_mode3s(AtracGainInfo *dst, AtracGainInfo *ref)
1032
+{
1033
+    int i;
1034
+
1035
+    for (i = 0; i < dst->num_points; i++)
1036
+        dst->lev_code[i] = (i >= ref->num_points) ? 7 : ref->lev_code[i];
1037
+}
1038
+
1039
+/**
1040
+ * Implements coding mode 1 (master) for gain compensation levels.
1041
+ *
1042
+ * @param[in]     gb     the GetBit context
1043
+ * @param[in]     ctx    ptr to the channel unit context
1044
+ * @param[out]    dst    ptr to the output array
1045
+ */
1046
+static inline void gainc_level_mode1m(GetBitContext *gb,
1047
+                                      Atrac3pChanUnitCtx *ctx,
1048
+                                      AtracGainInfo *dst)
1049
+{
1050
+    int i, delta;
1051
+
1052
+    if (dst->num_points > 0)
1053
+        dst->lev_code[0] = get_vlc2(gb, gain_vlc_tabs[2].table,
1054
+                                    gain_vlc_tabs[2].bits, 1);
1055
+
1056
+    for (i = 1; i < dst->num_points; i++) {
1057
+        delta = get_vlc2(gb, gain_vlc_tabs[3].table,
1058
+                         gain_vlc_tabs[3].bits, 1);
1059
+        dst->lev_code[i] = (dst->lev_code[i - 1] + delta) & 0xF;
1060
+    }
1061
+}
1062
+
1063
+/**
1064
+ * Decode level code for each gain control point.
1065
+ *
1066
+ * @param[in]     gb              the GetBit context
1067
+ * @param[in,out] ctx             ptr to the channel unit context
1068
+ * @param[in]     ch_num          channel to process
1069
+ * @param[in]     coded_subbands  number of subbands to process
1070
+ * @return result code: 0 = OK, otherwise - error code
1071
+ */
1072
+static int decode_gainc_levels(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1073
+                               int ch_num, int coded_subbands)
1074
+{
1075
+    int sb, i, delta, delta_bits, min_val, pred;
1076
+    Atrac3pChanParams *chan     = &ctx->channels[ch_num];
1077
+    Atrac3pChanParams *ref_chan = &ctx->channels[0];
1078
+
1079
+    switch (get_bits(gb, 2)) { /* switch according to coding mode */
1080
+    case 0: /* fixed-length coding */
1081
+        for (sb = 0; sb < coded_subbands; sb++)
1082
+            for (i = 0; i < chan->gain_data[sb].num_points; i++)
1083
+                chan->gain_data[sb].lev_code[i] = get_bits(gb, 4);
1084
+        break;
1085
+    case 1:
1086
+        if (ch_num) { /* VLC modulo delta to master channel */
1087
+            for (sb = 0; sb < coded_subbands; sb++)
1088
+                for (i = 0; i < chan->gain_data[sb].num_points; i++) {
1089
+                    delta = get_vlc2(gb, gain_vlc_tabs[5].table,
1090
+                                     gain_vlc_tabs[5].bits, 1);
1091
+                    pred = (i >= ref_chan->gain_data[sb].num_points)
1092
+                           ? 7 : ref_chan->gain_data[sb].lev_code[i];
1093
+                    chan->gain_data[sb].lev_code[i] = (pred + delta) & 0xF;
1094
+                }
1095
+        } else { /* VLC modulo delta to previous */
1096
+            for (sb = 0; sb < coded_subbands; sb++)
1097
+                gainc_level_mode1m(gb, ctx, &chan->gain_data[sb]);
1098
+        }
1099
+        break;
1100
+    case 2:
1101
+        if (ch_num) { /* VLC modulo delta to previous or clone master */
1102
+            for (sb = 0; sb < coded_subbands; sb++)
1103
+                if (chan->gain_data[sb].num_points > 0) {
1104
+                    if (get_bits1(gb))
1105
+                        gainc_level_mode1m(gb, ctx, &chan->gain_data[sb]);
1106
+                    else
1107
+                        gainc_level_mode3s(&chan->gain_data[sb],
1108
+                                           &ref_chan->gain_data[sb]);
1109
+                }
1110
+        } else { /* VLC modulo delta to lev_codes of previous subband */
1111
+            if (chan->gain_data[0].num_points > 0)
1112
+                gainc_level_mode1m(gb, ctx, &chan->gain_data[0]);
1113
+
1114
+            for (sb = 1; sb < coded_subbands; sb++)
1115
+                for (i = 0; i < chan->gain_data[sb].num_points; i++) {
1116
+                    delta = get_vlc2(gb, gain_vlc_tabs[4].table,
1117
+                                     gain_vlc_tabs[4].bits, 1);
1118
+                    pred = (i >= chan->gain_data[sb - 1].num_points)
1119
+                           ? 7 : chan->gain_data[sb - 1].lev_code[i];
1120
+                    chan->gain_data[sb].lev_code[i] = (pred + delta) & 0xF;
1121
+                }
1122
+        }
1123
+        break;
1124
+    case 3:
1125
+        if (ch_num) { /* clone master */
1126
+            for (sb = 0; sb < coded_subbands; sb++)
1127
+                gainc_level_mode3s(&chan->gain_data[sb],
1128
+                                   &ref_chan->gain_data[sb]);
1129
+        } else { /* shorter delta to min */
1130
+            delta_bits = get_bits(gb, 2);
1131
+            min_val    = get_bits(gb, 4);
1132
+
1133
+            for (sb = 0; sb < coded_subbands; sb++)
1134
+                for (i = 0; i < chan->gain_data[sb].num_points; i++) {
1135
+                    chan->gain_data[sb].lev_code[i] = min_val + GET_DELTA(gb, delta_bits);
1136
+                    if (chan->gain_data[sb].lev_code[i] > 15)
1137
+                        return AVERROR_INVALIDDATA;
1138
+                }
1139
+        }
1140
+        break;
1141
+    }
1142
+
1143
+    return 0;
1144
+}
1145
+
1146
+/**
1147
+ * Implements coding mode 0 for gain compensation locations.
1148
+ *
1149
+ * @param[in]     gb     the GetBit context
1150
+ * @param[in]     ctx    ptr to the channel unit context
1151
+ * @param[out]    dst    ptr to the output array
1152
+ * @param[in]     pos    position of the value to be processed
1153
+ */
1154
+static inline void gainc_loc_mode0(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1155
+                                   AtracGainInfo *dst, int pos)
1156
+{
1157
+    int delta_bits;
1158
+
1159
+    if (!pos || dst->loc_code[pos - 1] < 15)
1160
+        dst->loc_code[pos] = get_bits(gb, 5);
1161
+    else if (dst->loc_code[pos - 1] >= 30)
1162
+        dst->loc_code[pos] = 31;
1163
+    else {
1164
+        delta_bits         = av_log2(30 - dst->loc_code[pos - 1]) + 1;
1165
+        dst->loc_code[pos] = dst->loc_code[pos - 1] +
1166
+                             get_bits(gb, delta_bits) + 1;
1167
+    }
1168
+}
1169
+
1170
+/**
1171
+ * Implements coding mode 1 for gain compensation locations.
1172
+ *
1173
+ * @param[in]     gb     the GetBit context
1174
+ * @param[in]     ctx    ptr to the channel unit context
1175
+ * @param[out]    dst    ptr to the output array
1176
+ */
1177
+static inline void gainc_loc_mode1(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1178
+                                   AtracGainInfo *dst)
1179
+{
1180
+    int i;
1181
+    VLC *tab;
1182
+
1183
+    if (dst->num_points > 0) {
1184
+        /* 1st coefficient is stored directly */
1185
+        dst->loc_code[0] = get_bits(gb, 5);
1186
+
1187
+        for (i = 1; i < dst->num_points; i++) {
1188
+            /* switch VLC according to the curve direction
1189
+             * (ascending/descending) */
1190
+            tab              = (dst->lev_code[i] <= dst->lev_code[i - 1])
1191
+                               ? &gain_vlc_tabs[7]
1192
+                               : &gain_vlc_tabs[9];
1193
+            dst->loc_code[i] = dst->loc_code[i - 1] +
1194
+                               get_vlc2(gb, tab->table, tab->bits, 1);
1195
+        }
1196
+    }
1197
+}
1198
+
1199
+/**
1200
+ * Decode location code for each gain control point.
1201
+ *
1202
+ * @param[in]     gb              the GetBit context
1203
+ * @param[in,out] ctx             ptr to the channel unit context
1204
+ * @param[in]     ch_num          channel to process
1205
+ * @param[in]     coded_subbands  number of subbands to process
1206
+ * @param[in]     avctx           ptr to the AVCodecContext
1207
+ * @return result code: 0 = OK, otherwise - error code
1208
+ */
1209
+static int decode_gainc_loc_codes(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1210
+                                  int ch_num, int coded_subbands,
1211
+                                  AVCodecContext *avctx)
1212
+{
1213
+    int sb, i, delta, delta_bits, min_val, pred, more_than_ref;
1214
+    AtracGainInfo *dst, *ref;
1215
+    VLC *tab;
1216
+    Atrac3pChanParams *chan     = &ctx->channels[ch_num];
1217
+    Atrac3pChanParams *ref_chan = &ctx->channels[0];
1218
+
1219
+    switch (get_bits(gb, 2)) { /* switch according to coding mode */
1220
+    case 0: /* sequence of numbers in ascending order */
1221
+        for (sb = 0; sb < coded_subbands; sb++)
1222
+            for (i = 0; i < chan->gain_data[sb].num_points; i++)
1223
+                gainc_loc_mode0(gb, ctx, &chan->gain_data[sb], i);
1224
+        break;
1225
+    case 1:
1226
+        if (ch_num) {
1227
+            for (sb = 0; sb < coded_subbands; sb++) {
1228
+                if (chan->gain_data[sb].num_points <= 0)
1229
+                    continue;
1230
+                dst = &chan->gain_data[sb];
1231
+                ref = &ref_chan->gain_data[sb];
1232
+
1233
+                /* 1st value is vlc-coded modulo delta to master */
1234
+                delta = get_vlc2(gb, gain_vlc_tabs[10].table,
1235
+                                 gain_vlc_tabs[10].bits, 1);
1236
+                pred = ref->num_points > 0 ? ref->loc_code[0] : 0;
1237
+                dst->loc_code[0] = (pred + delta) & 0x1F;
1238
+
1239
+                for (i = 1; i < dst->num_points; i++) {
1240
+                    more_than_ref = i >= ref->num_points;
1241
+                    if (dst->lev_code[i] > dst->lev_code[i - 1]) {
1242
+                        /* ascending curve */
1243
+                        if (more_than_ref) {
1244
+                            delta =
1245
+                                get_vlc2(gb, gain_vlc_tabs[9].table,
1246
+                                         gain_vlc_tabs[9].bits, 1);
1247
+                            dst->loc_code[i] = dst->loc_code[i - 1] + delta;
1248
+                        } else {
1249
+                            if (get_bits1(gb))
1250
+                                gainc_loc_mode0(gb, ctx, dst, i);  // direct coding
1251
+                            else
1252
+                                dst->loc_code[i] = ref->loc_code[i];  // clone master
1253
+                        }
1254
+                    } else { /* descending curve */
1255
+                        tab   = more_than_ref ? &gain_vlc_tabs[7]
1256
+                                              : &gain_vlc_tabs[10];
1257
+                        delta = get_vlc2(gb, tab->table, tab->bits, 1);
1258
+                        if (more_than_ref)
1259
+                            dst->loc_code[i] = dst->loc_code[i - 1] + delta;
1260
+                        else
1261
+                            dst->loc_code[i] = (ref->loc_code[i] + delta) & 0x1F;
1262
+                    }
1263
+                }
1264
+            }
1265
+        } else /* VLC delta to previous */
1266
+            for (sb = 0; sb < coded_subbands; sb++)
1267
+                gainc_loc_mode1(gb, ctx, &chan->gain_data[sb]);
1268
+        break;
1269
+    case 2:
1270
+        if (ch_num) {
1271
+            for (sb = 0; sb < coded_subbands; sb++) {
1272
+                if (chan->gain_data[sb].num_points <= 0)
1273
+                    continue;
1274
+                dst = &chan->gain_data[sb];
1275
+                ref = &ref_chan->gain_data[sb];
1276
+                if (dst->num_points > ref->num_points || get_bits1(gb))
1277
+                    gainc_loc_mode1(gb, ctx, dst);
1278
+                else /* clone master for the whole subband */
1279
+                    for (i = 0; i < chan->gain_data[sb].num_points; i++)
1280
+                        dst->loc_code[i] = ref->loc_code[i];
1281
+            }
1282
+        } else {
1283
+            /* data for the first subband is coded directly */
1284
+            for (i = 0; i < chan->gain_data[0].num_points; i++)
1285
+                gainc_loc_mode0(gb, ctx, &chan->gain_data[0], i);
1286
+
1287
+            for (sb = 1; sb < coded_subbands; sb++) {
1288
+                if (chan->gain_data[sb].num_points <= 0)
1289
+                    continue;
1290
+                dst = &chan->gain_data[sb];
1291
+
1292
+                /* 1st value is vlc-coded modulo delta to the corresponding
1293
+                 * value of the previous subband if any or zero */
1294
+                delta = get_vlc2(gb, gain_vlc_tabs[6].table,
1295
+                                 gain_vlc_tabs[6].bits, 1);
1296
+                pred             = dst[-1].num_points > 0
1297
+                                   ? dst[-1].loc_code[0] : 0;
1298
+                dst->loc_code[0] = (pred + delta) & 0x1F;
1299
+
1300
+                for (i = 1; i < dst->num_points; i++) {
1301
+                    more_than_ref = i >= dst[-1].num_points;
1302
+                    /* Select VLC table according to curve direction and
1303
+                     * presence of prediction. */
1304
+                    tab = &gain_vlc_tabs[(dst->lev_code[i] > dst->lev_code[i - 1]) *
1305
+                                                   2 + more_than_ref + 6];
1306
+                    delta = get_vlc2(gb, tab->table, tab->bits, 1);
1307
+                    if (more_than_ref)
1308
+                        dst->loc_code[i] = dst->loc_code[i - 1] + delta;
1309
+                    else
1310
+                        dst->loc_code[i] = (dst[-1].loc_code[i] + delta) & 0x1F;
1311
+                }
1312
+            }
1313
+        }
1314
+        break;
1315
+    case 3:
1316
+        if (ch_num) { /* clone master or direct or direct coding */
1317
+            for (sb = 0; sb < coded_subbands; sb++)
1318
+                for (i = 0; i < chan->gain_data[sb].num_points; i++) {
1319
+                    if (i >= ref_chan->gain_data[sb].num_points)
1320
+                        gainc_loc_mode0(gb, ctx, &chan->gain_data[sb], i);
1321
+                    else
1322
+                        chan->gain_data[sb].loc_code[i] =
1323
+                            ref_chan->gain_data[sb].loc_code[i];
1324
+                }
1325
+        } else { /* shorter delta to min */
1326
+            delta_bits = get_bits(gb, 2) + 1;
1327
+            min_val    = get_bits(gb, 5);
1328
+
1329
+            for (sb = 0; sb < coded_subbands; sb++)
1330
+                for (i = 0; i < chan->gain_data[sb].num_points; i++)
1331
+                    chan->gain_data[sb].loc_code[i] = min_val + i +
1332
+                                                      get_bits(gb, delta_bits);
1333
+        }
1334
+        break;
1335
+    }
1336
+
1337
+    /* Validate decoded information */
1338
+    for (sb = 0; sb < coded_subbands; sb++) {
1339
+        dst = &chan->gain_data[sb];
1340
+        for (i = 0; i < chan->gain_data[sb].num_points; i++) {
1341
+            if (dst->loc_code[i] < 0 || dst->loc_code[i] > 31 ||
1342
+                (i && dst->loc_code[i] <= dst->loc_code[i - 1])) {
1343
+                av_log(avctx, AV_LOG_ERROR,
1344
+                       "Invalid gain location: ch=%d, sb=%d, pos=%d, val=%d\n",
1345
+                       ch_num, sb, i, dst->loc_code[i]);
1346
+                return AVERROR_INVALIDDATA;
1347
+            }
1348
+        }
1349
+    }
1350
+
1351
+    return 0;
1352
+}
1353
+
1354
+/**
1355
+ * Decode gain control data for all channels.
1356
+ *
1357
+ * @param[in]     gb            the GetBit context
1358
+ * @param[in,out] ctx           ptr to the channel unit context
1359
+ * @param[in]     num_channels  number of channels to process
1360
+ * @param[in]     avctx         ptr to the AVCodecContext
1361
+ * @return result code: 0 = OK, otherwise - error code
1362
+ */
1363
+static int decode_gainc_data(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1364
+                             int num_channels, AVCodecContext *avctx)
1365
+{
1366
+    int ch_num, coded_subbands, sb, ret;
1367
+
1368
+    for (ch_num = 0; ch_num < num_channels; ch_num++) {
1369
+        memset(ctx->channels[ch_num].gain_data, 0,
1370
+               sizeof(*ctx->channels[ch_num].gain_data) * ATRAC3P_SUBBANDS);
1371
+
1372
+        if (get_bits1(gb)) { /* gain control data present? */
1373
+            coded_subbands = get_bits(gb, 4) + 1;
1374
+            if (get_bits1(gb)) /* is high band gain data replication on? */
1375
+                ctx->channels[ch_num].num_gain_subbands = get_bits(gb, 4) + 1;
1376
+            else
1377
+                ctx->channels[ch_num].num_gain_subbands = coded_subbands;
1378
+
1379
+            if ((ret = decode_gainc_npoints(gb, ctx, ch_num, coded_subbands)) < 0 ||
1380
+                (ret = decode_gainc_levels(gb, ctx, ch_num, coded_subbands))  < 0 ||
1381
+                (ret = decode_gainc_loc_codes(gb, ctx, ch_num, coded_subbands, avctx)) < 0)
1382
+                return ret;
1383
+
1384
+            if (coded_subbands > 0) { /* propagate gain data if requested */
1385
+                for (sb = coded_subbands; sb < ctx->channels[ch_num].num_gain_subbands; sb++)
1386
+                    ctx->channels[ch_num].gain_data[sb] =
1387
+                        ctx->channels[ch_num].gain_data[sb - 1];
1388
+            }
1389
+        } else {
1390
+            ctx->channels[ch_num].num_gain_subbands = 0;
1391
+        }
1392
+    }
1393
+
1394
+    return 0;
1395
+}
1396
+
1397
+/**
1398
+ * Decode envelope for all tones of a channel.
1399
+ *
1400
+ * @param[in]     gb                the GetBit context
1401
+ * @param[in,out] ctx               ptr to the channel unit context
1402
+ * @param[in]     ch_num            channel to process
1403
+ * @param[in]     band_has_tones    ptr to an array of per-band-flags:
1404
+ *                                  1 - tone data present
1405
+ */
1406
+static void decode_tones_envelope(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1407
+                                  int ch_num, int band_has_tones[])
1408
+{
1409
+    int sb;
1410
+    Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info;
1411
+    Atrac3pWavesData *ref = ctx->channels[0].tones_info;
1412
+
1413
+    if (!ch_num || !get_bits1(gb)) { /* mode 0: fixed-length coding */
1414
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1415
+            if (!band_has_tones[sb])
1416
+                continue;
1417
+            dst[sb].pend_env.has_start_point = get_bits1(gb);
1418
+            dst[sb].pend_env.start_pos       = dst[sb].pend_env.has_start_point
1419
+                                               ? get_bits(gb, 5) : -1;
1420
+            dst[sb].pend_env.has_stop_point  = get_bits1(gb);
1421
+            dst[sb].pend_env.stop_pos        = dst[sb].pend_env.has_stop_point
1422
+                                               ? get_bits(gb, 5) : 32;
1423
+        }
1424
+    } else { /* mode 1(slave only): copy master */
1425
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1426
+            if (!band_has_tones[sb])
1427
+                continue;
1428
+            dst[sb].pend_env.has_start_point = ref[sb].pend_env.has_start_point;
1429
+            dst[sb].pend_env.has_stop_point  = ref[sb].pend_env.has_stop_point;
1430
+            dst[sb].pend_env.start_pos       = ref[sb].pend_env.start_pos;
1431
+            dst[sb].pend_env.stop_pos        = ref[sb].pend_env.stop_pos;
1432
+        }
1433
+    }
1434
+}
1435
+
1436
+/**
1437
+ * Decode number of tones for each subband of a channel.
1438
+ *
1439
+ * @param[in]     gb                the GetBit context
1440
+ * @param[in,out] ctx               ptr to the channel unit context
1441
+ * @param[in]     ch_num            channel to process
1442
+ * @param[in]     band_has_tones    ptr to an array of per-band-flags:
1443
+ *                                  1 - tone data present
1444
+ * @param[in]     avctx             ptr to the AVCodecContext
1445
+ * @return result code: 0 = OK, otherwise - error code
1446
+ */
1447
+static int decode_band_numwavs(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1448
+                               int ch_num, int band_has_tones[],
1449
+                               AVCodecContext *avctx)
1450
+{
1451
+    int mode, sb, delta;
1452
+    Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info;
1453
+    Atrac3pWavesData *ref = ctx->channels[0].tones_info;
1454
+
1455
+    mode = get_bits(gb, ch_num + 1);
1456
+    switch (mode) {
1457
+    case 0: /** fixed-length coding */
1458
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++)
1459
+            if (band_has_tones[sb])
1460
+                dst[sb].num_wavs = get_bits(gb, 4);
1461
+        break;
1462
+    case 1: /** variable-length coding */
1463
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++)
1464
+            if (band_has_tones[sb])
1465
+                dst[sb].num_wavs =
1466
+                    get_vlc2(gb, tone_vlc_tabs[1].table,
1467
+                             tone_vlc_tabs[1].bits, 1);
1468
+        break;
1469
+    case 2: /** VLC modulo delta to master (slave only) */
1470
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++)
1471
+            if (band_has_tones[sb]) {
1472
+                delta = get_vlc2(gb, tone_vlc_tabs[2].table,
1473
+                                 tone_vlc_tabs[2].bits, 1);
1474
+                delta = sign_extend(delta, 3);
1475
+                dst[sb].num_wavs = (ref[sb].num_wavs + delta) & 0xF;
1476
+            }
1477
+        break;
1478
+    case 3: /** copy master (slave only) */
1479
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++)
1480
+            if (band_has_tones[sb])
1481
+                dst[sb].num_wavs = ref[sb].num_wavs;
1482
+        break;
1483
+    }
1484
+
1485
+    /** initialize start tone index for each subband */
1486
+    for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++)
1487
+        if (band_has_tones[sb]) {
1488
+            if (ctx->waves_info->tones_index + dst[sb].num_wavs > 48) {
1489
+                av_log(avctx, AV_LOG_ERROR,
1490
+                       "Too many tones: %d (max. 48), frame: %d!\n",
1491
+                       ctx->waves_info->tones_index + dst[sb].num_wavs,
1492
+                       avctx->frame_number);
1493
+                return AVERROR_INVALIDDATA;
1494
+            }
1495
+            dst[sb].start_index           = ctx->waves_info->tones_index;
1496
+            ctx->waves_info->tones_index += dst[sb].num_wavs;
1497
+        }
1498
+
1499
+    return 0;
1500
+}
1501
+
1502
+/**
1503
+ * Decode frequency information for each subband of a channel.
1504
+ *
1505
+ * @param[in]     gb                the GetBit context
1506
+ * @param[in,out] ctx               ptr to the channel unit context
1507
+ * @param[in]     ch_num            channel to process
1508
+ * @param[in]     band_has_tones    ptr to an array of per-band-flags:
1509
+ *                                  1 - tone data present
1510
+ */
1511
+static void decode_tones_frequency(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1512
+                                   int ch_num, int band_has_tones[])
1513
+{
1514
+    int sb, i, direction, nbits, pred, delta;
1515
+    Atrac3pWaveParam *iwav, *owav;
1516
+    Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info;
1517
+    Atrac3pWavesData *ref = ctx->channels[0].tones_info;
1518
+
1519
+    if (!ch_num || !get_bits1(gb)) { /* mode 0: fixed-length coding */
1520
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1521
+            if (!band_has_tones[sb] || !dst[sb].num_wavs)
1522
+                continue;
1523
+            iwav      = &ctx->waves_info->waves[dst[sb].start_index];
1524
+            direction = (dst[sb].num_wavs > 1) ? get_bits1(gb) : 0;
1525
+            if (direction) { /** packed numbers in descending order */
1526
+                if (dst[sb].num_wavs)
1527
+                    iwav[dst[sb].num_wavs - 1].freq_index = get_bits(gb, 10);
1528
+                for (i = dst[sb].num_wavs - 2; i >= 0 ; i--) {
1529
+                    nbits = av_log2(iwav[i+1].freq_index) + 1;
1530
+                    iwav[i].freq_index = get_bits(gb, nbits);
1531
+                }
1532
+            } else { /** packed numbers in ascending order */
1533
+                for (i = 0; i < dst[sb].num_wavs; i++) {
1534
+                    if (!i || iwav[i - 1].freq_index < 512)
1535
+                        iwav[i].freq_index = get_bits(gb, 10);
1536
+                    else {
1537
+                        nbits = av_log2(1023 - iwav[i - 1].freq_index) + 1;
1538
+                        iwav[i].freq_index = get_bits(gb, nbits) +
1539
+                                             1024 - (1 << nbits);
1540
+                    }
1541
+                }
1542
+            }
1543
+        }
1544
+    } else { /* mode 1: VLC modulo delta to master (slave only) */
1545
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1546
+            if (!band_has_tones[sb] || !dst[sb].num_wavs)
1547
+                continue;
1548
+            iwav = &ctx->waves_info->waves[ref[sb].start_index];
1549
+            owav = &ctx->waves_info->waves[dst[sb].start_index];
1550
+            for (i = 0; i < dst[sb].num_wavs; i++) {
1551
+                delta = get_vlc2(gb, tone_vlc_tabs[6].table,
1552
+                                 tone_vlc_tabs[6].bits, 1);
1553
+                delta = sign_extend(delta, 8);
1554
+                pred  = (i < ref[sb].num_wavs) ? iwav[i].freq_index :
1555
+                        (ref[sb].num_wavs ? iwav[ref[sb].num_wavs - 1].freq_index : 0);
1556
+                owav[i].freq_index = (pred + delta) & 0x3FF;
1557
+            }
1558
+        }
1559
+    }
1560
+}
1561
+
1562
+/**
1563
+ * Decode amplitude information for each subband of a channel.
1564
+ *
1565
+ * @param[in]     gb                the GetBit context
1566
+ * @param[in,out] ctx               ptr to the channel unit context
1567
+ * @param[in]     ch_num            channel to process
1568
+ * @param[in]     band_has_tones    ptr to an array of per-band-flags:
1569
+ *                                  1 - tone data present
1570
+ */
1571
+static void decode_tones_amplitude(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1572
+                                   int ch_num, int band_has_tones[])
1573
+{
1574
+    int mode, sb, j, i, diff, maxdiff, fi, delta, pred;
1575
+    Atrac3pWaveParam *wsrc, *wref;
1576
+    int refwaves[48];
1577
+    Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info;
1578
+    Atrac3pWavesData *ref = ctx->channels[0].tones_info;
1579
+
1580
+    if (ch_num) {
1581
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1582
+            if (!band_has_tones[sb] || !dst[sb].num_wavs)
1583
+                continue;
1584
+            wsrc = &ctx->waves_info->waves[dst[sb].start_index];
1585
+            wref = &ctx->waves_info->waves[ref[sb].start_index];
1586
+            for (j = 0; j < dst[sb].num_wavs; j++) {
1587
+                for (i = 0, fi = 0, maxdiff = 1024; i < ref[sb].num_wavs; i++) {
1588
+                    diff = FFABS(wsrc[j].freq_index - wref[i].freq_index);
1589
+                    if (diff < maxdiff) {
1590
+                        maxdiff = diff;
1591
+                        fi      = i;
1592
+                    }
1593
+                }
1594
+
1595
+                if (maxdiff < 8)
1596
+                    refwaves[dst[sb].start_index + j] = fi + ref[sb].start_index;
1597
+                else if (j < ref[sb].num_wavs)
1598
+                    refwaves[dst[sb].start_index + j] = j + ref[sb].start_index;
1599
+                else
1600
+                    refwaves[dst[sb].start_index + j] = -1;
1601
+            }
1602
+        }
1603
+    }
1604
+
1605
+    mode = get_bits(gb, ch_num + 1);
1606
+
1607
+    switch (mode) {
1608
+    case 0: /** fixed-length coding */
1609
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1610
+            if (!band_has_tones[sb] || !dst[sb].num_wavs)
1611
+                continue;
1612
+            if (ctx->waves_info->amplitude_mode)
1613
+                for (i = 0; i < dst[sb].num_wavs; i++)
1614
+                    ctx->waves_info->waves[dst[sb].start_index + i].amp_sf = get_bits(gb, 6);
1615
+            else
1616
+                ctx->waves_info->waves[dst[sb].start_index].amp_sf = get_bits(gb, 6);
1617
+        }
1618
+        break;
1619
+    case 1: /** min + VLC delta */
1620
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1621
+            if (!band_has_tones[sb] || !dst[sb].num_wavs)
1622
+                continue;
1623
+            if (ctx->waves_info->amplitude_mode)
1624
+                for (i = 0; i < dst[sb].num_wavs; i++)
1625
+                    ctx->waves_info->waves[dst[sb].start_index + i].amp_sf =
1626
+                        get_vlc2(gb, tone_vlc_tabs[3].table,
1627
+                                 tone_vlc_tabs[3].bits, 1) + 20;
1628
+            else
1629
+                ctx->waves_info->waves[dst[sb].start_index].amp_sf =
1630
+                    get_vlc2(gb, tone_vlc_tabs[4].table,
1631
+                             tone_vlc_tabs[4].bits, 1) + 24;
1632
+        }
1633
+        break;
1634
+    case 2: /** VLC modulo delta to master (slave only) */
1635
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1636
+            if (!band_has_tones[sb] || !dst[sb].num_wavs)
1637
+                continue;
1638
+            for (i = 0; i < dst[sb].num_wavs; i++) {
1639
+                delta = get_vlc2(gb, tone_vlc_tabs[5].table,
1640
+                                 tone_vlc_tabs[5].bits, 1);
1641
+                delta = sign_extend(delta, 5);
1642
+                pred  = refwaves[dst[sb].start_index + i] >= 0 ?
1643
+                        ctx->waves_info->waves[refwaves[dst[sb].start_index + i]].amp_sf : 34;
1644
+                ctx->waves_info->waves[dst[sb].start_index + i].amp_sf = (pred + delta) & 0x3F;
1645
+            }
1646
+        }
1647
+        break;
1648
+    case 3: /** clone master (slave only) */
1649
+        for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1650
+            if (!band_has_tones[sb])
1651
+                continue;
1652
+            for (i = 0; i < dst[sb].num_wavs; i++)
1653
+                ctx->waves_info->waves[dst[sb].start_index + i].amp_sf =
1654
+                    refwaves[dst[sb].start_index + i] >= 0
1655
+                    ? ctx->waves_info->waves[refwaves[dst[sb].start_index + i]].amp_sf
1656
+                    : 32;
1657
+        }
1658
+        break;
1659
+    }
1660
+}
1661
+
1662
+/**
1663
+ * Decode phase information for each subband of a channel.
1664
+ *
1665
+ * @param[in]     gb                the GetBit context
1666
+ * @param[in,out] ctx               ptr to the channel unit context
1667
+ * @param[in]     ch_num            channel to process
1668
+ * @param[in]     band_has_tones    ptr to an array of per-band-flags:
1669
+ *                                  1 - tone data present
1670
+ */
1671
+static void decode_tones_phase(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1672
+                               int ch_num, int band_has_tones[])
1673
+{
1674
+    int sb, i;
1675
+    Atrac3pWaveParam *wparam;
1676
+    Atrac3pWavesData *dst = ctx->channels[ch_num].tones_info;
1677
+
1678
+    for (sb = 0; sb < ctx->waves_info->num_tone_bands; sb++) {
1679
+        if (!band_has_tones[sb])
1680
+            continue;
1681
+        wparam = &ctx->waves_info->waves[dst[sb].start_index];
1682
+        for (i = 0; i < dst[sb].num_wavs; i++)
1683
+            wparam[i].phase_index = get_bits(gb, 5);
1684
+    }
1685
+}
1686
+
1687
+/**
1688
+ * Decode tones info for all channels.
1689
+ *
1690
+ * @param[in]     gb            the GetBit context
1691
+ * @param[in,out] ctx           ptr to the channel unit context
1692
+ * @param[in]     num_channels  number of channels to process
1693
+ * @param[in]     avctx         ptr to the AVCodecContext
1694
+ * @return result code: 0 = OK, otherwise - error code
1695
+ */
1696
+static int decode_tones_info(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1697
+                             int num_channels, AVCodecContext *avctx)
1698
+{
1699
+    int ch_num, i, ret;
1700
+    int band_has_tones[16];
1701
+
1702
+    ctx->waves_info->tones_present = get_bits1(gb);
1703
+    if (!ctx->waves_info->tones_present)
1704
+        return 0;
1705
+
1706
+    memset(ctx->waves_info->waves, 0, sizeof(ctx->waves_info->waves));
1707
+
1708
+    ctx->waves_info->amplitude_mode = get_bits1(gb);
1709
+    if (!ctx->waves_info->amplitude_mode) {
1710
+        avpriv_report_missing_feature(avctx, "GHA amplitude mode 0");
1711
+        return AVERROR_PATCHWELCOME;
1712
+    }
1713
+
1714
+    ctx->waves_info->num_tone_bands =
1715
+        get_vlc2(gb, tone_vlc_tabs[0].table,
1716
+                 tone_vlc_tabs[0].bits, 1) + 1;
1717
+
1718
+    if (num_channels == 2) {
1719
+        get_subband_flags(gb, ctx->waves_info->tone_sharing, ctx->waves_info->num_tone_bands);
1720
+        get_subband_flags(gb, ctx->waves_info->tone_master,  ctx->waves_info->num_tone_bands);
1721
+        if (get_subband_flags(gb, ctx->waves_info->phase_shift,
1722
+                              ctx->waves_info->num_tone_bands)) {
1723
+            avpriv_report_missing_feature(avctx, "GHA Phase shifting");
1724
+            return AVERROR_PATCHWELCOME;
1725
+        }
1726
+    }
1727
+
1728
+    ctx->waves_info->tones_index = 0;
1729
+
1730
+    for (ch_num = 0; ch_num < num_channels; ch_num++) {
1731
+        for (i = 0; i < ctx->waves_info->num_tone_bands; i++)
1732
+            band_has_tones[i] = !ch_num ? 1 : !ctx->waves_info->tone_sharing[i];
1733
+
1734
+        decode_tones_envelope(gb, ctx, ch_num, band_has_tones);
1735
+        if ((ret = decode_band_numwavs(gb, ctx, ch_num, band_has_tones,
1736
+                                       avctx)) < 0)
1737
+            return ret;
1738
+
1739
+        decode_tones_frequency(gb, ctx, ch_num, band_has_tones);
1740
+        decode_tones_amplitude(gb, ctx, ch_num, band_has_tones);
1741
+        decode_tones_phase(gb, ctx, ch_num, band_has_tones);
1742
+    }
1743
+
1744
+    if (num_channels == 2) {
1745
+        for (i = 0; i < ctx->waves_info->num_tone_bands; i++) {
1746
+            if (ctx->waves_info->tone_sharing[i])
1747
+                ctx->channels[1].tones_info[i] = ctx->channels[0].tones_info[i];
1748
+
1749
+            if (ctx->waves_info->tone_master[i])
1750
+                FFSWAP(Atrac3pWavesData, ctx->channels[0].tones_info[i],
1751
+                       ctx->channels[1].tones_info[i]);
1752
+        }
1753
+    }
1754
+
1755
+    return 0;
1756
+}
1757
+
1758
+int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
1759
+                                   int num_channels, AVCodecContext *avctx)
1760
+{
1761
+    int ret;
1762
+
1763
+    /* parse sound header */
1764
+    ctx->num_quant_units = get_bits(gb, 5) + 1;
1765
+    if (ctx->num_quant_units > 28 && ctx->num_quant_units < 32) {
1766
+        av_log(avctx, AV_LOG_ERROR,
1767
+               "Invalid number of quantization units: %d!\n",
1768
+               ctx->num_quant_units);
1769
+        return AVERROR_INVALIDDATA;
1770
+    }
1771
+
1772
+    ctx->mute_flag = get_bits1(gb);
1773
+
1774
+    /* decode various sound parameters */
1775
+    if ((ret = decode_quant_wordlen(gb, ctx, num_channels, avctx)) < 0)
1776
+        return ret;
1777
+
1778
+    ctx->num_subbands       = atrac3p_qu_to_subband[ctx->num_quant_units - 1] + 1;
1779
+    ctx->num_coded_subbands = ctx->used_quant_units
1780
+                              ? atrac3p_qu_to_subband[ctx->used_quant_units - 1] + 1
1781
+                              : 0;
1782
+
1783
+    if ((ret = decode_scale_factors(gb, ctx, num_channels, avctx)) < 0)
1784
+        return ret;
1785
+
1786
+    if ((ret = decode_code_table_indexes(gb, ctx, num_channels, avctx)) < 0)
1787
+        return ret;
1788
+
1789
+    decode_spectrum(gb, ctx, num_channels, avctx);
1790
+
1791
+    if (num_channels == 2) {
1792
+        get_subband_flags(gb, ctx->swap_channels, ctx->num_coded_subbands);
1793
+        get_subband_flags(gb, ctx->negate_coeffs, ctx->num_coded_subbands);
1794
+    }
1795
+
1796
+    decode_window_shape(gb, ctx, num_channels);
1797
+
1798
+    if ((ret = decode_gainc_data(gb, ctx, num_channels, avctx)) < 0)
1799
+        return ret;
1800
+
1801
+    if ((ret = decode_tones_info(gb, ctx, num_channels, avctx)) < 0)
1802
+        return ret;
1803
+
1804
+    /* decode global noise info */
1805
+    ctx->noise_present = get_bits1(gb);
1806
+    if (ctx->noise_present) {
1807
+        ctx->noise_level_index = get_bits(gb, 4);
1808
+        ctx->noise_table_index = get_bits(gb, 4);
1809
+    }
1810
+
1811
+    return 0;
1812
+}
0 1813
new file mode 100644
... ...
@@ -0,0 +1,240 @@
0
+/*
1
+ * ATRAC3+ compatible decoder
2
+ *
3
+ * Copyright (c) 2010-2013 Maxim Poliakovski
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * FFmpeg is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with FFmpeg; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+/**
23
+ * @file
24
+ * Global structures, constants and data for ATRAC3+ decoder.
25
+ */
26
+
27
+#ifndef AVCODEC_ATRAC3PLUS_H
28
+#define AVCODEC_ATRAC3PLUS_H
29
+
30
+#include <stdint.h>
31
+
32
+#include "libavutil/float_dsp.h"
33
+#include "atrac.h"
34
+#include "avcodec.h"
35
+#include "fft.h"
36
+#include "get_bits.h"
37
+
38
+/** Global unit sizes */
39
+#define ATRAC3P_SUBBANDS        16  ///< number of PQF subbands
40
+#define ATRAC3P_SUBBAND_SAMPLES 128 ///< number of samples per subband
41
+#define ATRAC3P_FRAME_SAMPLES   (ATRAC3P_SUBBAND_SAMPLES * ATRAC3P_SUBBANDS)
42
+
43
+#define ATRAC3P_PQF_FIR_LEN     12  ///< length of the prototype FIR of the PQF
44
+
45
+/** Global constants */
46
+#define ATRAC3P_POWER_COMP_OFF  15  ///< disable power compensation
47
+
48
+/** ATRAC3+ channel unit types */
49
+enum Atrac3pChannelUnitTypes {
50
+    CH_UNIT_MONO       = 0, ///< unit containing one coded channel
51
+    CH_UNIT_STEREO     = 1, ///< unit containing two jointly-coded channels
52
+    CH_UNIT_EXTENSION  = 2, ///< unit containing extension information
53
+    CH_UNIT_TERMINATOR = 3  ///< unit sequence terminator
54
+};
55
+
56
+/** Per-channel IPQF history */
57
+typedef struct Atrac3pIPQFChannelCtx {
58
+    DECLARE_ALIGNED(32, float, buf1)[ATRAC3P_PQF_FIR_LEN * 2][8];
59
+    DECLARE_ALIGNED(32, float, buf2)[ATRAC3P_PQF_FIR_LEN * 2][8];
60
+    int pos;
61
+} Atrac3pIPQFChannelCtx;
62
+
63
+/** Amplitude envelope of a group of sine waves */
64
+typedef struct Atrac3pWaveEnvelope {
65
+    int has_start_point;    ///< indicates start point within the GHA window
66
+    int has_stop_point;     ///< indicates stop point within the GHA window
67
+    int start_pos;          ///< start position expressed in n*4 samples
68
+    int stop_pos;           ///< stop  position expressed in n*4 samples
69
+} Atrac3pWaveEnvelope;
70
+
71
+/** Parameters of a group of sine waves */
72
+typedef struct Atrac3pWavesData {
73
+    Atrac3pWaveEnvelope pend_env;   ///< pending envelope from the previous frame
74
+    Atrac3pWaveEnvelope curr_env;   ///< group envelope from the current frame
75
+    int num_wavs;           ///< number of sine waves in the group
76
+    int start_index;        ///< start index into global tones table for that subband
77
+} Atrac3pWavesData;
78
+
79
+/** Parameters of a single sine wave */
80
+typedef struct Atrac3pWaveParam {
81
+    int   freq_index;   ///< wave frequency index
82
+    int   amp_sf;       ///< quantized amplitude scale factor
83
+    int   amp_index;    ///< quantized amplitude index
84
+    int   phase_index;  ///< quantized phase index
85
+} Atrac3pWaveParam;
86
+
87
+/** Sound channel parameters */
88
+typedef struct Atrac3pChanParams {
89
+    int ch_num;
90
+    int num_coded_vals;         ///< number of transmitted quant unit values
91
+    int fill_mode;
92
+    int split_point;
93
+    int table_type;             ///< table type: 0 - tone?, 1- noise?
94
+    int qu_wordlen[32];         ///< array of word lengths for each quant unit
95
+    int qu_sf_idx[32];          ///< array of scale factor indexes for each quant unit
96
+    int qu_tab_idx[32];         ///< array of code table indexes for each quant unit
97
+    int16_t spectrum[2048];     ///< decoded IMDCT spectrum
98
+    uint8_t power_levs[5];      ///< power compensation levels
99
+
100
+    /* imdct window shape history (2 frames) for overlapping. */
101
+    uint8_t wnd_shape_hist[2][ATRAC3P_SUBBANDS];    ///< IMDCT window shape, 0=sine/1=steep
102
+    uint8_t *wnd_shape;         ///< IMDCT window shape for current frame
103
+    uint8_t *wnd_shape_prev;    ///< IMDCT window shape for previous frame
104
+
105
+    /* gain control data history (2 frames) for overlapping. */
106
+    AtracGainInfo gain_data_hist[2][ATRAC3P_SUBBANDS];  ///< gain control data for all subbands
107
+    AtracGainInfo *gain_data;       ///< gain control data for next frame
108
+    AtracGainInfo *gain_data_prev;  ///< gain control data for previous frame
109
+    int num_gain_subbands;      ///< number of subbands with gain control data
110
+
111
+    /* tones data history (2 frames) for overlapping. */
112
+    Atrac3pWavesData tones_info_hist[2][ATRAC3P_SUBBANDS];
113
+    Atrac3pWavesData *tones_info;
114
+    Atrac3pWavesData *tones_info_prev;
115
+} Atrac3pChanParams;
116
+
117
+/* Per-unit sine wave parameters */
118
+typedef struct Atrac3pWaveSynthParams {
119
+    int tones_present;                      ///< 1 - tones info present
120
+    int amplitude_mode;                     ///< 1 - low range, 0 - high range
121
+    int num_tone_bands;                     ///< number of PQF bands with tones
122
+    uint8_t tone_sharing[ATRAC3P_SUBBANDS]; ///< 1 - subband-wise tone sharing flags
123
+    uint8_t tone_master[ATRAC3P_SUBBANDS];  ///< 1 - subband-wise tone channel swapping
124
+    uint8_t phase_shift[ATRAC3P_SUBBANDS];  ///< 1 - subband-wise 180° phase shifting
125
+    int tones_index;                        ///< total sum of tones in this unit
126
+    Atrac3pWaveParam waves[48];
127
+} Atrac3pWaveSynthParams;
128
+
129
+/** Channel unit parameters */
130
+typedef struct Atrac3pChanUnitCtx {
131
+    /* channel unit variables */
132
+    int unit_type;                          ///< unit type (mono/stereo)
133
+    int num_quant_units;
134
+    int num_subbands;
135
+    int used_quant_units;                   ///< number of quant units with coded spectrum
136
+    int num_coded_subbands;                 ///< number of subbands with coded spectrum
137
+    int mute_flag;                          ///< mute flag
138
+    int use_full_table;                     ///< 1 - full table list, 0 - restricted one
139
+    int noise_present;                      ///< 1 - global noise info present
140
+    int noise_level_index;                  ///< global noise level index
141
+    int noise_table_index;                  ///< global noise RNG table index
142
+    uint8_t swap_channels[ATRAC3P_SUBBANDS];    ///< 1 - perform subband-wise channel swapping
143
+    uint8_t negate_coeffs[ATRAC3P_SUBBANDS];    ///< 1 - subband-wise IMDCT coefficients negation
144
+    Atrac3pChanParams channels[2];
145
+
146
+    /* Variables related to GHA tones */
147
+    Atrac3pWaveSynthParams wave_synth_hist[2];     ///< waves synth history for two frames
148
+    Atrac3pWaveSynthParams *waves_info;
149
+    Atrac3pWaveSynthParams *waves_info_prev;
150
+
151
+    Atrac3pIPQFChannelCtx ipqf_ctx[2];
152
+    DECLARE_ALIGNED(32, float, prev_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< overlapping buffer
153
+} Atrac3pChanUnitCtx;
154
+
155
+/**
156
+ * Initialize VLC tables for bitstream parsing.
157
+ */
158
+void ff_atrac3p_init_vlcs(void);
159
+
160
+/**
161
+ * Decode bitstream data of a channel unit.
162
+ *
163
+ * @param[in]     gb            the GetBit context
164
+ * @param[in,out] ctx           ptr to the channel unit context
165
+ * @param[in]     num_channels  number of channels to process
166
+ * @param[in]     avctx         ptr to the AVCodecContext
167
+ * @return result code: 0 = OK, otherwise - error code
168
+ */
169
+int ff_atrac3p_decode_channel_unit(GetBitContext *gb, Atrac3pChanUnitCtx *ctx,
170
+                                   int num_channels, AVCodecContext *avctx);
171
+
172
+/**
173
+ * Initialize IMDCT transform.
174
+ *
175
+ * @param[in]   avctx      ptr to the AVCodecContext
176
+ * @param[in]   mdct_ctx   pointer to MDCT transform context
177
+ */
178
+void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx);
179
+
180
+/**
181
+ * Initialize sine waves synthesizer.
182
+ */
183
+void ff_atrac3p_init_wave_synth(void);
184
+
185
+/**
186
+ * Synthesize sine waves for a particular subband.
187
+ *
188
+ * @param[in]   ch_unit   pointer to the channel unit context
189
+ * @param[in]   fdsp      pointer to float DSP context
190
+ * @param[in]   ch_num    which channel to process
191
+ * @param[in]   sb        which subband to process
192
+ * @param[out]  out       receives processed data
193
+ */
194
+void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp,
195
+                               int ch_num, int sb, float *out);
196
+
197
+/**
198
+ * Perform power compensation aka noise dithering.
199
+ *
200
+ * @param[in]      ctx         ptr to the channel context
201
+ * @param[in]      ch_index    which channel to process
202
+ * @param[in,out]  sp          ptr to channel spectrum to process
203
+ * @param[in]      rng_index   indicates which RNG table to use
204
+ * @param[in]      sb          which subband to process
205
+ */
206
+void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, int ch_index,
207
+                                   float *sp, int rng_index, int sb_num);
208
+
209
+/**
210
+ * Regular IMDCT and windowing without overlapping,
211
+ * with spectrum reversal in the odd subbands.
212
+ *
213
+ * @param[in]   fdsp       pointer to float DSP context
214
+ * @param[in]   mdct_ctx   pointer to MDCT transform context
215
+ * @param[in]   pIn        float input
216
+ * @param[out]  pOut       float output
217
+ * @param[in]   wind_id    which MDCT window to apply
218
+ * @param[in]   sb         subband number
219
+ */
220
+void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn,
221
+                      float *pOut, int wind_id, int sb);
222
+
223
+/**
224
+ * Subband synthesis filter based on the polyphase quadrature (pseudo-QMF)
225
+ * filter bank.
226
+ *
227
+ * @param[in]      dct_ctx   ptr to the pre-initialized IDCT context
228
+ * @param[in,out]  hist      ptr to the filter history
229
+ * @param[in]      in        input data to process
230
+ * @param[out]     out       receives processed data
231
+ */
232
+void ff_atrac3p_ipqf(FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist,
233
+                     const float *in, float *out);
234
+
235
+extern const uint16_t ff_atrac3p_qu_to_spec_pos[33];
236
+extern const float ff_atrac3p_sf_tab[64];
237
+extern const float ff_atrac3p_mant_tab[8];
238
+
239
+#endif /* AVCODEC_ATRAC3PLUS_H */
0 240
new file mode 100644
... ...
@@ -0,0 +1,1914 @@
0
+/*
1
+ * ATRAC3+ compatible decoder
2
+ *
3
+ * Copyright (c) 2010-2013 Maxim Poliakovski
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * FFmpeg is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with FFmpeg; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+#ifndef AVCODEC_ATRAC3PLUS_DATA_H
23
+#define AVCODEC_ATRAC3PLUS_DATA_H
24
+
25
+#include <stddef.h>
26
+#include <stdint.h>
27
+
28
+/** VLC tables for wordlen */
29
+static const uint8_t atrac3p_wl_huff_code1[3] = { 0, 2, 3 };
30
+
31
+static const uint8_t atrac3p_wl_huff_bits1[3] = { 1, 2, 2 };
32
+
33
+static const uint8_t atrac3p_wl_huff_xlat1[3] = { 0, 1, 7 };
34
+
35
+static const uint8_t atrac3p_wl_huff_code2[5] = { 0, 4, 5, 6, 7 };
36
+
37
+static const uint8_t atrac3p_wl_huff_bits2[5] = { 1, 3, 3, 3, 3 };
38
+
39
+static const uint8_t atrac3p_wl_huff_xlat2[5] = { 0, 1, 2, 6, 7 };
40
+
41
+static const uint8_t atrac3p_wl_huff_code3[8] = {
42
+    0, 4, 0xC, 0x1E, 0x1F, 0xD, 0xE, 5
43
+};
44
+
45
+static const uint8_t atrac3p_wl_huff_bits3[8] = { 1, 3, 4, 5, 5, 4, 4, 3 };
46
+
47
+static const uint8_t atrac3p_wl_huff_code4[8] = {
48
+    0, 4, 0xC, 0xD, 0x1E, 0x1F, 0xE, 5
49
+};
50
+
51
+static const uint8_t atrac3p_wl_huff_bits4[8] = { 1, 3, 4, 4, 5, 5, 4, 3 };
52
+
53
+/** VLC tables for scale factor indexes */
54
+static const uint16_t atrac3p_sf_huff_code1[64] = {
55
+        0,     2,     3,     4,     5,   0xC,   0xD,  0xE0,
56
+     0xE1,  0xE2,  0xE3,  0xE4,  0xE5,  0xE6, 0x1CE, 0x1CF,
57
+    0x1D0, 0x1D1, 0x1D2, 0x1D3, 0x1D4, 0x1D5, 0x1D6, 0x1D7,
58
+    0x1D8, 0x1D9, 0x1DA, 0x1DB, 0x1DC, 0x1DD, 0x1DE, 0x1DF,
59
+    0x1E0, 0x1E1, 0x1E2, 0x1E3, 0x1E4, 0x1E5, 0x1E6, 0x1E7,
60
+    0x1E8, 0x1E9, 0x1EA, 0x1EB, 0x1EC, 0x1ED, 0x1EE, 0x1EF,
61
+    0x1F0, 0x1F1, 0x1F2, 0x1F3, 0x1F4, 0x1F5, 0x1F6, 0x1F7,
62
+    0x1F8, 0x1F9, 0x1FA, 0x1FB, 0x1FC, 0x1FD, 0x1FE, 0x1FF
63
+};
64
+
65
+static const uint8_t atrac3p_sf_huff_bits1[64] = {
66
+    2, 3, 3, 3, 3, 4, 4, 8, 8, 8, 8, 8, 8, 8, 9, 9,
67
+    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
68
+    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
69
+    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9
70
+};
71
+
72
+static const uint8_t atrac3p_sf_huff_xlat1[64] = {
73
+     0,  1, 61, 62, 63,  2, 60,  3,  4,  5,  6, 57, 58, 59,  7,  8,
74
+     9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
75
+    25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
76
+    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56
77
+};
78
+
79
+static const uint8_t atrac3p_sf_huff_xlat2[64] = {
80
+    0,   1,  2, 62, 63,  3, 61,  4,  5,  6, 57, 58, 59, 60,  7,  8,
81
+    9,  10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
82
+    25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
83
+    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56
84
+};
85
+
86
+static const uint16_t atrac3p_sf_huff_code2[64] = {
87
+        0,     4,  0x18,  0x19,  0x70, 0x1CA, 0x1CB, 0x1CC,
88
+    0x1CD, 0x1CE, 0x1CF, 0x1D0, 0x1D1, 0x1D2, 0x1D3, 0x1D4,
89
+    0x1D5, 0x1D6, 0x1D7, 0x1D8, 0x1D9, 0x1DA, 0x1DB, 0x1DC,
90
+    0x1DD, 0x1DE, 0x1DF, 0x1E0, 0x1E1, 0x1E2, 0x1E3, 0x1E4,
91
+    0x1E5, 0x1E6, 0x1E7, 0x1E8, 0x1E9, 0x1EA, 0x1EB, 0x1EC,
92
+    0x1ED, 0x1EE, 0x1EF, 0x1F0, 0x1F1, 0x1F2, 0x1F3, 0x1F4,
93
+    0x1F5, 0x1F6, 0x1F7, 0x1F8, 0x1F9, 0x1FA, 0x1FB, 0x1FC,
94
+    0x1FD, 0x1FE, 0x1FF,  0xE4,  0x71,  0x1A,  0x1B,     5
95
+};
96
+
97
+static const uint8_t atrac3p_sf_huff_bits2[64] = {
98
+    1, 3, 5, 5, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
99
+    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
100
+    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
101
+    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 7, 5, 5, 3
102
+};
103
+
104
+static const uint16_t atrac3p_sf_huff_code3[64] = {
105
+        0,     2,     3,  0x18,  0x19,  0x70, 0x1CC, 0x1CD,
106
+    0x1CE, 0x1CF, 0x1D0, 0x1D1, 0x1D2, 0x1D3, 0x1D4, 0x1D5,
107
+    0x1D6, 0x1D7, 0x1D8, 0x1D9, 0x1DA, 0x1DB, 0x1DC, 0x1DD,
108
+    0x1DE, 0x1DF, 0x1E0, 0x1E1, 0x1E2, 0x1E3, 0x1E4, 0x1E5,
109
+    0x1E6, 0x1E7, 0x1E8, 0x1E9, 0x1EA, 0x1EB, 0x1EC, 0x1ED,
110
+    0x1EE, 0x1EF, 0x1F0, 0x1F1, 0x1F2, 0x1F3, 0x1F4, 0x1F5,
111
+    0x1F6, 0x1F7, 0x1F8, 0x1F9, 0x1FA, 0x1FB, 0x1FC, 0x1FD,
112
+    0x1FE, 0x1FF,  0x71,  0x72,  0x1A,  0x1B,     4,     5
113
+};
114
+
115
+static const uint8_t atrac3p_sf_huff_bits3[64] = {
116
+    2, 3, 3, 5, 5, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
117
+    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
118
+    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
119
+    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7, 5, 5, 3, 3
120
+};
121
+
122
+static const uint16_t atrac3p_sf_huff_code4[16] = {
123
+    0, 2, 3, 4, 5, 0xC, 0xD, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0, 0x3D, 0x3E, 0x3F
124
+};
125
+
126
+static const uint8_t atrac3p_sf_huff_bits4[16] = {
127
+    2, 3, 3, 3, 3, 4, 4, 6, 6, 6, 6, 6, 0, 6, 6, 6
128
+};
129
+
130
+static const uint8_t atrac3p_sf_huff_xlat4[16] = {
131
+    0, 1, 13, 14, 15, 2, 12, 3, 4, 5, 6, 7, 8, 9, 10, 11
132
+};
133
+
134
+static const uint8_t atrac3p_sf_huff_xlat5[16] = {
135
+    0, 1, 2, 14, 15, 3, 13, 4, 5, 6, 7, 9, 8, 10, 11, 12
136
+};
137
+
138
+static const uint16_t atrac3p_sf_huff_code5[16] = {
139
+    0,    4,  0xC, 0x1C, 0x78, 0x79, 0x7A, 0x7B,
140
+    0, 0x7C, 0x7D, 0x7E, 0x7F, 0x1D, 0xD,     5
141
+};
142
+
143
+static const uint8_t atrac3p_sf_huff_bits5[16] = {
144
+    1, 3, 4, 5, 7, 7, 7, 7, 0, 7, 7, 7, 7, 5, 4, 3
145
+};
146
+
147
+static const uint16_t atrac3p_sf_huff_code6[16] = {
148
+    0, 2, 3, 0xC, 0x1C, 0x3C, 0x7C, 0x7D, 0, 0x7E, 0x7F, 0x3D, 0x1D, 0xD, 4, 5
149
+};
150
+
151
+static const uint8_t atrac3p_sf_huff_bits6[16] = {
152
+    2, 3, 3, 4, 5, 6, 7, 7, 0, 7, 7, 6, 5, 4, 3, 3
153
+};
154
+
155
+/** VLC tables for code table indexes */
156
+static const uint8_t atrac3p_ct_huff_code1[4] = { 0, 2, 6, 7 };
157
+
158
+static const uint8_t atrac3p_ct_huff_bits1[4] = { 1, 2, 3, 3 };
159
+
160
+static const uint8_t atrac3p_ct_huff_code2[8] = { 0, 2, 3, 4, 5, 6, 0xE, 0xF };
161
+
162
+static const uint8_t atrac3p_ct_huff_bits2[8] = { 2, 3, 3, 3, 3, 3, 4, 4 };
163
+
164
+static const uint8_t atrac3p_ct_huff_xlat1[8] = { 0, 1, 2, 3, 6, 7, 4, 5 };
165
+
166
+static const uint8_t atrac3p_ct_huff_code3[8] = {
167
+    0, 4, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF
168
+};
169
+
170
+static const uint8_t atrac3p_ct_huff_bits3[8] = { 1, 3, 4, 4, 4, 4, 4, 4 };
171
+
172
+/* weights for quantized word lengths */
173
+static const int8_t atrac3p_wl_weights[6][32] = {
174
+    { 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0,
175
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
176
+    { 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0,
177
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
178
+    { 6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1,
179
+      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
180
+    { 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0,
181
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
182
+    { 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0,
183
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
184
+    { 6, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 2, 2, 1, 1,
185
+      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
186
+};
187
+
188
+/* weights for quantized scale factors
189
+ * sf_weights[i] = i / (tab_idx + 1)
190
+ * where tab_idx = [1,2] */
191
+static const int8_t atrac3p_sf_weights[2][32] = {
192
+    { 0, 0, 1, 1,  2,  2,  3,  3,  4,  4,  5,  5,  6,  6,  7,  7,
193
+      8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15 },
194
+    { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4,  4,  5,
195
+      5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10 }
196
+};
197
+
198
+/** Ungroup table for word length segments.
199
+ *  Numbers in this table tell which coeff belongs to which segment. */
200
+static const uint8_t atrac3p_qu_num_to_seg[32] = {
201
+    0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5,
202
+    5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9
203
+};
204
+
205
+/** Map quant unit number to subband number */
206
+static const uint8_t atrac3p_qu_to_subband[32] = {
207
+    0, 0, 0, 0, 0, 0, 0, 0, 1, 1,  1,  1,  2,  2,  2, 2,
208
+    3, 3, 4, 4, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
209
+};
210
+
211
+/** Map subband number to number of power compensation groups */
212
+static const int atrac3p_subband_to_num_powgrps[16] = {
213
+    1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5
214
+};
215
+
216
+/** 3D base shape tables. The values are grouped together as follows:
217
+ *  [num_start_values = 8][num_shape_tables = 16][num_seg_coeffs = 9]
218
+ *  For each of the 8 start values there are 16 different shapes each
219
+ *  9 coefficients long. */
220
+static const int8_t atrac3p_wl_shapes[8][16][9] = {
221
+    { {  0,  0,  0,  0,  0,  0,  0, -2, -1 },
222
+      {  0,  0,  0,  0,  0,  0,  0, -5, -1 },
223
+      {  0,  0,  0, -7,  0,  0,  0,  0,  0 },
224
+      {  0,  0,  0,  0,  0, -7,  0,  0,  0 },
225
+      {  0,  0,  0,  0,  0,  0, -5,  0,  0 },
226
+      {  0,  0,  0,  0, -5,  0,  0,  0,  0 },
227
+      { -7, -7,  0,  0,  0,  0,  0,  0,  0 },
228
+      {  0, -7,  0,  0,  0,  0,  0,  0,  0 },
229
+      { -2, -2, -5,  0,  0,  0,  0,  0,  0 },
230
+      {  0,  0,  0, -2, -5,  0,  0,  0,  0 },
231
+      {  0,  0,  0,  0,  0, -2, -5,  0,  0 },
232
+      {  0,  0,  0, -5,  0,  0,  0,  0,  0 },
233
+      {  0, -2, -7, -2,  0,  0,  0,  0,  0 },
234
+      {  0,  0,  0,  0, -2, -5,  0,  0,  0 },
235
+      {  0,  0,  0, -5, -5,  0,  0,  0,  0 },
236
+      {  0,  0,  0, -5, -2,  0,  0,  0,  0 } },
237
+    { { -1, -5, -3, -2, -1, -1,  0,  0,  0 },
238
+      { -2, -5, -3, -3, -2, -1, -1,  0,  0 },
239
+      {  0, -1, -1, -1,  0,  0,  0,  0,  0 },
240
+      { -1, -3,  0,  0,  0,  0,  0,  0,  0 },
241
+      { -1, -2,  0,  0,  0,  0,  0,  0,  0 },
242
+      { -1, -3, -1,  0,  0,  0,  0,  1,  1 },
243
+      { -1, -5, -3, -3, -2, -1,  0,  0,  0 },
244
+      { -1, -1, -4, -2, -2, -1, -1,  0,  0 },
245
+      { -1, -1, -3, -2, -3, -1, -1, -1,  0 },
246
+      { -1, -4, -2, -3, -1,  0,  0,  0,  0 },
247
+      {  0, -1, -2, -2, -1, -1,  0,  0,  0 },
248
+      {  0, -2, -1,  0,  0,  0,  0,  0,  0 },
249
+      { -1, -1,  0,  0,  0,  0,  0,  0,  0 },
250
+      { -1, -1, -3, -2, -2, -1, -1, -1,  0 },
251
+      {  0,  0,  0,  0,  0,  0,  0,  0,  0 },
252
+      {  0, -1, -3, -2, -2, -1, -1, -1,  0 }, },
253
+    { { -1, -2,  0,  1,  1,  1,  1,  1,  1 },
254
+      {  0, -1,  1,  1,  1,  1,  1,  1,  1 },
255
+      {  0, -2,  1,  1,  1,  1,  1,  1,  1 },
256
+      {  0, -2,  0,  1,  1,  1,  1,  1,  1 },
257
+      { -1, -1,  0,  1,  1,  1,  1,  1,  1 },
258
+      {  0,  0, -1,  0,  1,  1,  1,  1,  1 },
259
+      { -1, -1,  1,  1,  1,  1,  1,  1,  1 },
260
+      {  0,  0, -1,  1,  1,  1,  1,  1,  1 },
261
+      {  0, -1,  0,  1,  1,  1,  1,  1,  1 },
262
+      { -1, -1, -1,  1,  1,  1,  1,  1,  1 },
263
+      {  0,  0,  0,  0,  1,  1,  1,  1,  1 },
264
+      {  0,  0,  0,  1,  1,  1,  1,  1,  1 },
265
+      {  0, -1, -1,  1,  1,  1,  1,  1,  1 },
266
+      {  0,  1,  0,  1,  1,  1,  1,  1,  1 },
267
+      {  0, -3, -2,  1,  1,  1,  1,  2,  2 },
268
+      { -3, -5, -3,  2,  2,  2,  2,  2,  2 }, },
269
+    { { -1, -2,  0,  2,  2,  2,  2,  2,  2 },
270
+      { -1, -2,  0,  1,  2,  2,  2,  2,  2 },
271
+      {  0, -2,  0,  2,  2,  2,  2,  2,  2 },
272
+      { -1,  0,  1,  2,  2,  2,  2,  2,  2 },
273
+      {  0,  0,  1,  2,  2,  2,  2,  2,  2 },
274
+      {  0, -2,  0,  1,  2,  2,  2,  2,  2 },
275
+      {  0, -1,  1,  2,  2,  2,  2,  2,  2 },
276
+      { -1, -1,  0,  2,  2,  2,  2,  2,  2 },
277
+      { -1, -1,  0,  1,  2,  2,  2,  2,  2 },
278
+      { -1, -2, -1,  2,  2,  2,  2,  2,  2 },
279
+      {  0, -1,  0,  2,  2,  2,  2,  2,  2 },
280
+      {  1,  1,  0,  1,  2,  2,  2,  2,  2 },
281
+      {  0,  1,  2,  2,  2,  2,  2,  2,  2 },
282
+      {  1,  0,  0,  1,  2,  2,  2,  2,  2 },
283
+      {  0,  0,  0,  1,  2,  2,  2,  2,  2 },
284
+      { -1, -1, -1,  1,  2,  2,  2,  2,  2 }, },
285
+    { {  0,  1,  2,  3,  3,  3,  3,  3,  3 },
286
+      {  1,  1,  2,  3,  3,  3,  3,  3,  3 },
287
+      { -1,  0,  1,  2,  3,  3,  3,  3,  3 },
288
+      {  0,  0,  2,  3,  3,  3,  3,  3,  3 },
289
+      { -1,  0,  1,  3,  3,  3,  3,  3,  3 },
290
+      {  0,  0,  1,  3,  3,  3,  3,  3,  3 },
291
+      {  1,  2,  3,  3,  3,  3,  3,  3,  3 },
292
+      {  1,  2,  2,  3,  3,  3,  3,  3,  3 },
293
+      {  0,  1,  1,  3,  3,  3,  3,  3,  3 },
294
+      {  0,  0,  1,  2,  3,  3,  3,  3,  3 },
295
+      { -1,  1,  2,  3,  3,  3,  3,  3,  3 },
296
+      { -1,  0,  2,  3,  3,  3,  3,  3,  3 },
297
+      {  2,  2,  3,  3,  3,  3,  3,  3,  3 },
298
+      {  1,  1,  3,  3,  3,  3,  3,  3,  3 },
299
+      {  0,  2,  3,  3,  3,  3,  3,  3,  3 },
300
+      {  0,  1,  1,  2,  3,  3,  3,  3,  3 }, },
301
+    { {  0,  1,  2,  3,  4,  4,  4,  4,  4 },
302
+      {  1,  2,  3,  4,  4,  4,  4,  4,  4 },
303
+      {  0,  0,  2,  3,  4,  4,  4,  4,  4 },
304
+      {  1,  1,  2,  4,  4,  4,  4,  4,  4 },
305
+      {  0,  1,  2,  4,  4,  4,  4,  4,  4 },
306
+      { -1,  0,  1,  3,  4,  4,  4,  4,  4 },
307
+      {  0,  0,  1,  3,  4,  4,  4,  4,  4 },
308
+      {  1,  1,  2,  3,  4,  4,  4,  4,  4 },
309
+      {  0,  1,  1,  3,  4,  4,  4,  4,  4 },
310
+      {  2,  2,  3,  4,  4,  4,  4,  4,  4 },
311
+      {  1,  1,  3,  4,  4,  4,  4,  4,  4 },
312
+      {  1,  2,  2,  4,  4,  4,  4,  4,  4 },
313
+      { -1,  0,  2,  3,  4,  4,  4,  4,  4 },
314
+      {  0,  1,  3,  4,  4,  4,  4,  4,  4 },
315
+      {  1,  2,  2,  3,  4,  4,  4,  4,  4 },
316
+      {  0,  2,  3,  4,  4,  4,  4,  4,  4 }, },
317
+    { {  1,  2,  3,  4,  5,  5,  5,  5,  5 },
318
+      {  0,  1,  2,  3,  4,  5,  5,  5,  5 },
319
+      {  0,  1,  2,  3,  5,  5,  5,  5,  5 },
320
+      {  1,  1,  3,  4,  5,  5,  5,  5,  5 },
321
+      {  1,  1,  2,  4,  5,  5,  5,  5,  5 },
322
+      {  1,  2,  2,  4,  5,  5,  5,  5,  5 },
323
+      {  1,  1,  2,  3,  5,  5,  5,  5,  5 },
324
+      {  2,  2,  3,  4,  5,  5,  5,  5,  5 },
325
+      {  0,  1,  2,  4,  5,  5,  5,  5,  5 },
326
+      {  2,  2,  3,  5,  5,  5,  5,  5,  5 },
327
+      {  1,  2,  3,  5,  5,  5,  5,  5,  5 },
328
+      {  0,  1,  3,  4,  5,  5,  5,  5,  5 },
329
+      {  1,  2,  2,  3,  5,  5,  5,  5,  5 },
330
+      {  2,  3,  4,  5,  5,  5,  5,  5,  5 },
331
+      {  0,  2,  3,  4,  5,  5,  5,  5,  5 },
332
+      {  1,  1,  1,  3,  4,  5,  5,  5,  5 }, },
333
+    { {  1,  2,  3,  4,  5,  5,  5,  6,  6 },
334
+      {  1,  2,  3,  4,  5,  6,  6,  6,  6 },
335
+      {  2,  3,  4,  5,  6,  6,  6,  6,  6 },
336
+      {  1,  2,  3,  4,  6,  6,  6,  6,  6 },
337
+      {  2,  2,  3,  4,  5,  5,  5,  6,  6 },
338
+      {  1,  2,  3,  4,  5,  5,  6,  6,  6 },
339
+      {  2,  2,  3,  4,  6,  6,  6,  6,  6 },
340
+      {  2,  2,  3,  4,  5,  6,  6,  6,  6 },
341
+      {  2,  2,  4,  5,  6,  6,  6,  6,  6 },
342
+      {  2,  2,  3,  5,  6,  6,  6,  6,  6 },
343
+      {  1,  2,  3,  5,  6,  6,  6,  6,  6 },
344
+      {  2,  3,  3,  5,  6,  6,  6,  6,  6 },
345
+      {  1,  2,  4,  5,  6,  6,  6,  6,  6 },
346
+      {  2,  2,  3,  4,  5,  5,  6,  6,  6 },
347
+      {  2,  3,  3,  4,  6,  6,  6,  6,  6 },
348
+      {  1,  3,  4,  5,  6,  6,  6,  6,  6 } }
349
+};
350
+
351
+/** 2D base shape tables for scale factor coding.
352
+ *  The values are grouped together as follows:
353
+ *  [num_shape_tables = 64][num_seg_coeffs = 9] */
354
+static const int8_t atrac3p_sf_shapes[64][9] = {
355
+    { -3, -2, -1,  0,  3,  5,  6,  8, 40 },
356
+    { -3, -2,  0,  1,  7,  9, 11, 13, 20 },
357
+    { -1,  0,  0,  1,  6,  8, 10, 13, 41 },
358
+    {  0,  0,  0,  2,  5,  5,  6,  8, 14 },
359
+    {  0,  0,  0,  2,  6,  7,  8, 11, 47 },
360
+    {  0,  0,  1,  2,  5,  7,  8, 10, 32 },
361
+    {  0,  0,  1,  3,  8, 10, 12, 14, 47 },
362
+    {  0,  0,  2,  4,  9, 10, 12, 14, 40 },
363
+    {  0,  0,  3,  5,  9, 10, 12, 14, 22 },
364
+    {  0,  1,  3,  5, 10, 14, 18, 22, 31 },
365
+    {  0,  2,  5,  6, 10, 10, 10, 12, 46 },
366
+    {  0,  2,  5,  7, 12, 14, 15, 18, 44 },
367
+    {  1,  1,  4,  5,  7,  7,  8,  9, 15 },
368
+    {  1,  2,  2,  2,  4,  5,  7,  9, 26 },
369
+    {  1,  2,  2,  3,  6,  7,  7,  8, 47 },
370
+    {  1,  2,  2,  3,  6,  8, 10, 13, 22 },
371
+    {  1,  3,  4,  7, 13, 17, 21, 24, 41 },
372
+    {  1,  4,  0,  4, 10, 12, 13, 14, 17 },
373
+    {  2,  3,  3,  3,  6,  8, 10, 13, 48 },
374
+    {  2,  3,  3,  4,  9, 12, 14, 17, 47 },
375
+    {  2,  3,  3,  5, 10, 12, 14, 17, 25 },
376
+    {  2,  3,  5,  7,  8,  9,  9,  9, 13 },
377
+    {  2,  3,  5,  9, 16, 21, 25, 28, 33 },
378
+    {  2,  4,  5,  8, 12, 14, 17, 19, 26 },
379
+    {  2,  4,  6,  8, 12, 13, 13, 15, 20 },
380
+    {  2,  4,  7, 12, 20, 26, 30, 32, 35 },
381
+    {  3,  3,  5,  6, 12, 14, 16, 19, 34 },
382
+    {  3,  4,  4,  5,  7,  9, 10, 11, 48 },
383
+    {  3,  4,  5,  6,  8,  9, 10, 11, 16 },
384
+    {  3,  5,  5,  5,  7,  9, 10, 13, 35 },
385
+    {  3,  5,  5,  7, 10, 12, 13, 15, 49 },
386
+    {  3,  5,  7,  7,  8,  7,  9, 12, 21 },
387
+    {  3,  5,  7,  8, 12, 14, 15, 15, 24 },
388
+    {  3,  5,  7, 10, 16, 21, 24, 27, 44 },
389
+    {  3,  5,  8, 14, 21, 26, 28, 29, 42 },
390
+    {  3,  6, 10, 13, 18, 19, 20, 22, 27 },
391
+    {  3,  6, 11, 16, 24, 27, 28, 29, 31 },
392
+    {  4,  5,  4,  3,  4,  6,  8, 11, 18 },
393
+    {  4,  6,  5,  6,  9, 10, 12, 14, 20 },
394
+    {  4,  6,  7,  6,  6,  6,  7,  8, 46 },
395
+    {  4,  6,  7,  9, 13, 16, 18, 20, 48 },
396
+    {  4,  6,  7,  9, 14, 17, 20, 23, 31 },
397
+    {  4,  6,  9, 11, 14, 15, 15, 17, 21 },
398
+    {  4,  8, 13, 20, 27, 32, 35, 36, 38 },
399
+    {  5,  6,  6,  4,  5,  6,  7,  6,  6 },
400
+    {  5,  7,  7,  8,  9,  9, 10, 12, 49 },
401
+    {  5,  8,  9,  9, 10, 11, 12, 13, 42 },
402
+    {  5,  8, 10, 12, 15, 16, 17, 19, 42 },
403
+    {  5,  8, 12, 17, 26, 31, 32, 33, 44 },
404
+    {  5,  9, 13, 16, 20, 22, 23, 23, 35 },
405
+    {  6,  8,  8,  7,  6,  5,  6,  8, 15 },
406
+    {  6,  8,  8,  8,  9, 10, 12, 16, 24 },
407
+    {  6,  8,  8,  9, 10, 10, 11, 11, 13 },
408
+    {  6,  8, 10, 13, 19, 21, 24, 26, 32 },
409
+    {  6,  9, 10, 11, 13, 13, 14, 16, 49 },
410
+    {  7,  9,  9, 10, 13, 14, 16, 19, 27 },
411
+    {  7, 10, 12, 13, 16, 16, 17, 17, 27 },
412
+    {  7, 10, 12, 14, 17, 19, 20, 22, 48 },
413
+    {  8,  9, 10,  9, 10, 11, 11, 11, 19 },
414
+    {  8, 11, 12, 12, 13, 13, 13, 13, 17 },
415
+    {  8, 11, 13, 14, 16, 17, 19, 20, 27 },
416
+    {  8, 12, 17, 22, 26, 28, 29, 30, 33 },
417
+    { 10, 14, 16, 19, 21, 22, 22, 24, 28 },
418
+    { 10, 15, 17, 18, 21, 22, 23, 25, 43 }
419
+};
420
+
421
+static const uint8_t atrac3p_ct_restricted_to_full[2][7][4] = {
422
+    { { 0, 5, 4, 1 },
423
+      { 0, 1, 2, 3 },
424
+      { 3, 0, 4, 2 },
425
+      { 4, 0, 1, 2 },
426
+      { 1, 0, 4, 3 },
427
+      { 3, 0, 2, 1 },
428
+      { 0, 3, 1, 2 } },
429
+    { { 4, 0, 1, 2 },
430
+      { 0, 3, 2, 1 },
431
+      { 0, 1, 2, 3 },
432
+      { 0, 1, 2, 4 },
433
+      { 0, 1, 2, 3 },
434
+      { 1, 4, 2, 0 },
435
+      { 0, 1, 2, 3 } }
436
+};
437
+
438
+/** Tables for spectrum coding */
439
+static const uint8_t huff_a01_cb[14] = {
440
+    1, 12, 1, 0, 0, 1, 7, 0, 19, 5, 13, 21, 6, 8
441
+};
442
+
443
+static const uint8_t huff_a01_xlat[81] = {
444
+    0x00, 0x03, 0x40, 0xC0, 0x10, 0x30, 0x04, 0x0C, 0x01, 0x50, 0xD0, 0x70,
445
+    0xF0, 0xC4, 0x14, 0x34, 0x4C, 0x1C, 0x3C, 0x41, 0xC1, 0x31, 0x05, 0x0D,
446
+    0xC3, 0x13, 0x07, 0x0F, 0x44, 0xCC, 0x11, 0x43, 0x33, 0x54, 0x74, 0xDC,
447
+    0xFC, 0x71, 0x15, 0x4D, 0xCD, 0x1D, 0xD3, 0xC7, 0x37, 0x3F, 0xD4, 0xF4,
448
+    0x5C, 0x7C, 0x51, 0xD1, 0xF1, 0x45, 0xC5, 0x35, 0xDD, 0x3D, 0x53, 0x73,
449
+    0xF3, 0x47, 0x17, 0x77, 0x4F, 0xCF, 0x1F, 0x55, 0xF5, 0x7D, 0xD7, 0x5F,
450
+    0xFF, 0xD5, 0x75, 0x5D, 0xFD, 0x57, 0xF7, 0xDF, 0x7F
451
+};
452
+
453
+static const uint8_t huff_a02_cb[13] = {
454
+    2, 12, 1, 0, 4, 11, 0, 1, 29, 6, 20, 7, 2
455
+};
456
+
457
+static const uint8_t huff_a02_xlat[81] = {
458
+    0x00, 0x40, 0x10, 0x04, 0x01, 0x50, 0x44, 0x14, 0x54, 0x41, 0x11, 0x51,
459
+    0x05, 0x45, 0x15, 0x55, 0x90, 0x80, 0x20, 0x60, 0x84, 0x94, 0x24, 0x64,
460
+    0x08, 0x48, 0x18, 0x58, 0x81, 0x91, 0x21, 0x85, 0x95, 0x65, 0x09, 0x49,
461
+    0x19, 0x59, 0x02, 0x42, 0x12, 0x52, 0x06, 0x46, 0x16, 0x56, 0x88, 0x61,
462
+    0x25, 0x29, 0x69, 0x5A, 0xA0, 0xA4, 0x98, 0x28, 0x68, 0xA1, 0xA5, 0x89,
463
+    0x99, 0xA9, 0x82, 0x92, 0x22, 0x62, 0x96, 0x26, 0x66, 0x0A, 0x4A, 0x1A,
464
+    0xA8, 0x86, 0xA6, 0x8A, 0x9A, 0x2A, 0x6A, 0xA2, 0xAA
465
+};
466
+
467
+static const uint8_t huff_a03_cb[9] = { 3, 9, 1, 8, 0, 13, 18, 7, 2 };
468
+
469
+static const uint8_t huff_a03_xlat[49] = {
470
+    0x00, 0x08, 0x38, 0x01, 0x09, 0x39, 0x07, 0x0F, 0x3F, 0x10, 0x30, 0x11,
471
+    0x31, 0x02, 0x0A, 0x3A, 0x05, 0x06, 0x0E, 0x3E, 0x17, 0x37, 0x18, 0x28,
472
+    0x19, 0x29, 0x2A, 0x32, 0x03, 0x0B, 0x33, 0x3B, 0x0D, 0x15, 0x3D, 0x16,
473
+    0x1E, 0x36, 0x1F, 0x2F, 0x12, 0x1A, 0x13, 0x2B, 0x1D, 0x35, 0x2E, 0x1B,
474
+    0x2D
475
+};
476
+
477
+static const uint8_t huff_a04_cb[4]   = { 2, 3, 2, 4 };
478
+static const uint8_t huff_a04_xlat[6] = { 1, 2, 0, 3, 4, 5 };
479
+
480
+static const uint8_t huff_a05_cb[12] = {
481
+    3, 12, 1, 3, 5, 8, 12, 23, 72, 68, 31, 2
482
+};
483
+
484
+static const uint8_t huff_a05_xlat[225] = {
485
+    0x00, 0x10, 0xF0, 0x01, 0x11, 0xF1, 0x0F, 0x1F, 0xFF, 0x20, 0xE0, 0xE1,
486
+    0x02, 0xF2, 0x0E, 0x1E, 0x2F, 0x30, 0xD0, 0x21, 0x12, 0x22, 0xE2, 0x03,
487
+    0x0D, 0x2E, 0xEE, 0xFE, 0xEF, 0x40, 0xC0, 0x31, 0xC1, 0xD1, 0x32, 0xD2,
488
+    0x13, 0x23, 0xE3, 0xF3, 0x04, 0xF4, 0x0C, 0x1C, 0x1D, 0x2D, 0xED, 0xFD,
489
+    0x3E, 0xDE, 0x3F, 0xDF, 0x50, 0x60, 0x70, 0x90, 0xA0, 0xB0, 0x41, 0x51,
490
+    0x61, 0x71, 0x91, 0xA1, 0xB1, 0x42, 0x62, 0x92, 0xA2, 0xC2, 0x33, 0xC3,
491
+    0xD3, 0x14, 0x24, 0x34, 0xD4, 0xE4, 0x05, 0x15, 0xF5, 0x06, 0x16, 0x26,
492
+    0xE6, 0xF6, 0x07, 0x17, 0xE7, 0xF7, 0x09, 0x19, 0x29, 0xF9, 0x0A, 0x1A,
493
+    0x2A, 0xEA, 0xFA, 0x0B, 0x1B, 0xFB, 0x2C, 0x3C, 0xDC, 0xEC, 0xFC, 0x3D,
494
+    0x4D, 0xCD, 0xDD, 0x4E, 0x6E, 0x7E, 0xAE, 0xCE, 0x4F, 0x5F, 0x6F, 0x7F,
495
+    0x9F, 0xAF, 0xBF, 0xCF, 0x52, 0x72, 0xB2, 0x43, 0x53, 0x63, 0x73, 0x93,
496
+    0xA3, 0xB3, 0x44, 0x64, 0x74, 0x94, 0xA4, 0xB4, 0xC4, 0x25, 0x35, 0xA5,
497
+    0xC5, 0xD5, 0xE5, 0x36, 0x46, 0xB6, 0xC6, 0xD6, 0x27, 0x37, 0x47, 0xB7,
498
+    0xC7, 0xD7, 0x39, 0x49, 0x59, 0xC9, 0xD9, 0xE9, 0x3A, 0x4A, 0x5A, 0xCA,
499
+    0xDA, 0x2B, 0x3B, 0x4B, 0x6B, 0x7B, 0xDB, 0xEB, 0x4C, 0x5C, 0x6C, 0x7C,
500
+    0x9C, 0xAC, 0xCC, 0x5D, 0x6D, 0x7D, 0x9D, 0xAD, 0xBD, 0x5E, 0x9E, 0xBE,
501
+    0x54, 0x45, 0x55, 0x65, 0x75, 0x95, 0xB5, 0x56, 0x66, 0x76, 0x96, 0xA6,
502
+    0x57, 0x67, 0x97, 0xA7, 0x69, 0x79, 0xA9, 0xB9, 0x6A, 0x7A, 0x9A, 0xAA,
503
+    0xBA, 0x5B, 0x9B, 0xAB, 0xBB, 0xCB, 0xBC, 0x77, 0x99
504
+};
505
+
506
+static const uint8_t huff_a06_cb[7] = {
507
+    2, 6, 1, 3, 2, 6, 4
508
+};
509
+
510
+static const uint8_t huff_a06_xlat[16] = {
511
+    1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 13, 14, 10, 11, 12, 15
512
+};
513
+
514
+static const uint8_t huff_a07_cb[11] = {
515
+    2, 10, 1, 2, 2, 2, 6, 14, 21, 13, 2
516
+};
517
+
518
+static const uint8_t huff_a07_xlat[63] = {
519
+    0,   1, 63,  2, 62,  3, 61,  4,  5,  6, 58, 59, 60,  7,  8,  9,
520
+    10, 26, 27, 28, 36, 37, 38, 54, 55, 56, 57, 11, 12, 13, 14, 15,
521
+    16, 25, 29, 30, 31, 33, 34, 35, 39, 47, 48, 49, 50, 51, 52, 53,
522
+    17, 18, 19, 20, 21, 22, 23, 41, 42, 43, 44, 45, 46, 24, 40
523
+};
524
+
525
+static const uint8_t huff_a11_cb[13] = {
526
+    1, 11, 1, 0, 0, 0, 8, 1, 18, 9, 22, 10, 12
527
+};
528
+
529
+static const uint8_t huff_a11_xlat[81] = {
530
+    0x00, 0x40, 0xC0, 0x10, 0x30, 0x04, 0x0C, 0x01, 0x03, 0xD0, 0x50, 0x70,
531
+    0xF0, 0xC4, 0x34, 0x4C, 0xCC, 0x1C, 0x41, 0xC1, 0x31, 0x05, 0x0D, 0x43,
532
+    0xC3, 0x13, 0x07, 0x0F, 0x44, 0x14, 0x74, 0xDC, 0x3C, 0x11, 0x1D, 0x33,
533
+    0x37, 0x54, 0xD4, 0xF4, 0x5C, 0x7C, 0xFC, 0xD1, 0x71, 0xF1, 0x15, 0x35,
534
+    0x4D, 0xCD, 0xDD, 0x3D, 0xD3, 0x73, 0x47, 0xC7, 0x17, 0x77, 0x3F, 0x51,
535
+    0x45, 0xC5, 0x55, 0x53, 0xF3, 0x4F, 0xCF, 0x1F, 0xFF, 0xD5, 0x75, 0xF5,
536
+    0x5D, 0x7D, 0xFD, 0x57, 0xD7, 0xF7, 0x5F, 0xDF, 0x7F
537
+};
538
+
539
+static const uint8_t huff_a12_cb[8] = { 5, 10, 16, 11, 32, 19, 1, 2 };
540
+
541
+static const uint8_t huff_a12_xlat[81] = {
542
+    0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54, 0x01, 0x41, 0x11, 0x51,
543
+    0x05, 0x45, 0x15, 0x55, 0x90, 0x94, 0x58, 0x91, 0x95, 0x19, 0x59, 0x06,
544
+    0x46, 0x16, 0x56, 0x80, 0x60, 0x84, 0x24, 0x64, 0xA4, 0x08, 0x48, 0x18,
545
+    0x68, 0x81, 0x21, 0x61, 0xA1, 0x85, 0x25, 0x65, 0xA5, 0x09, 0x49, 0x99,
546
+    0x69, 0xA9, 0x02, 0x42, 0x12, 0x52, 0x96, 0x26, 0x66, 0x1A, 0x5A, 0x20,
547
+    0xA0, 0x88, 0x98, 0x28, 0xA8, 0x89, 0x29, 0x82, 0x92, 0x22, 0x62, 0x86,
548
+    0xA6, 0x0A, 0x4A, 0x9A, 0x6A, 0xAA, 0xA2, 0x8A, 0x2A
549
+};
550
+
551
+static const uint8_t huff_a13_cb[12] = {
552
+    1, 10, 1, 0, 0, 4, 2, 2, 9, 15, 12, 4
553
+};
554
+
555
+static const uint8_t huff_a13_xlat[49] = {
556
+    0x00, 0x08, 0x38, 0x01, 0x07, 0x39, 0x0F, 0x09, 0x3F, 0x10, 0x30, 0x31,
557
+    0x02, 0x3A, 0x06, 0x0E, 0x3E, 0x17, 0x18, 0x28, 0x11, 0x29, 0x0A, 0x32,
558
+    0x03, 0x0B, 0x3B, 0x05, 0x0D, 0x3D, 0x16, 0x1F, 0x37, 0x19, 0x12, 0x1A,
559
+    0x2A, 0x13, 0x33, 0x15, 0x35, 0x1E, 0x2E, 0x36, 0x2F, 0x1B, 0x2B, 0x1D,
560
+    0x2D
561
+};
562
+
563
+static const uint8_t huff_a14_cb[12] = {
564
+    2, 11, 1, 0, 4, 3, 5, 16, 28, 34, 26, 4
565
+};
566
+
567
+static const uint8_t huff_a14_xlat[121] = {
568
+    0x00, 0x10, 0xF0, 0x01, 0x0F, 0xF1, 0x1F, 0xFF, 0x20, 0xE0, 0x11, 0x02,
569
+    0x0E, 0x30, 0x50, 0xB0, 0xD0, 0x21, 0xE1, 0x12, 0xF2, 0x03, 0x05, 0x0B,
570
+    0x0D, 0x1E, 0xFE, 0x2F, 0xEF, 0x40, 0xC0, 0x31, 0x51, 0xB1, 0xC1, 0xD1,
571
+    0x22, 0x52, 0xE2, 0x13, 0xF3, 0x04, 0x15, 0xF5, 0x1B, 0xEB, 0xFB, 0x0C,
572
+    0x1D, 0xFD, 0x2E, 0x5E, 0xEE, 0x3F, 0x5F, 0xBF, 0xDF, 0x41, 0x32, 0x42,
573
+    0xB2, 0xD2, 0x23, 0x53, 0xB3, 0xE3, 0x14, 0x24, 0xE4, 0xF4, 0x25, 0x35,
574
+    0xD5, 0xE5, 0x2B, 0x3B, 0xDB, 0x1C, 0x2C, 0xBC, 0xEC, 0xFC, 0x2D, 0xBD,
575
+    0xED, 0x3E, 0x4E, 0xBE, 0xDE, 0x4F, 0xCF, 0xC2, 0x33, 0x43, 0xC3, 0xD3,
576
+    0x34, 0x44, 0x54, 0xB4, 0xD4, 0x45, 0x55, 0xC5, 0x4B, 0xCB, 0x3C, 0x4C,
577
+    0x5C, 0xCC, 0xDC, 0x3D, 0x4D, 0x5D, 0xCD, 0xDD, 0xCE, 0xC4, 0xB5, 0x5B,
578
+    0xBB
579
+};
580
+
581
+static const uint8_t huff_a15_cb[9] = { 5, 11, 9, 12, 16, 44, 98, 42, 4 };
582
+
583
+static const uint8_t huff_a15_xlat[225] = {
584
+    0x00, 0x10, 0xF0, 0x01, 0x11, 0xF1, 0x0F, 0x1F, 0xFF, 0x20, 0xE0, 0x21,
585
+    0xE1, 0x02, 0x12, 0xF2, 0x0E, 0x1E, 0xFE, 0x2F, 0xEF, 0x30, 0xD0, 0x31,
586
+    0xD1, 0x22, 0xE2, 0x03, 0x13, 0xF3, 0x0D, 0x1D, 0xFD, 0x2E, 0xEE, 0x3F,
587
+    0xDF, 0x40, 0x60, 0x70, 0x90, 0xA0, 0xC0, 0x41, 0xC1, 0x32, 0x42, 0xC2,
588
+    0xD2, 0x23, 0x33, 0xD3, 0xE3, 0x04, 0x14, 0x24, 0xE4, 0xF4, 0x06, 0x16,
589
+    0xF6, 0x07, 0x09, 0x0A, 0x1A, 0xFA, 0x0C, 0x1C, 0x2C, 0xEC, 0xFC, 0x2D,
590
+    0x3D, 0xDD, 0xED, 0x3E, 0x4E, 0xCE, 0xDE, 0x4F, 0xCF, 0x50, 0xB0, 0x51,
591
+    0x61, 0x71, 0x91, 0xA1, 0xB1, 0x52, 0x62, 0x72, 0x92, 0xA2, 0xB2, 0x43,
592
+    0x53, 0x63, 0x73, 0x93, 0xA3, 0xC3, 0x34, 0x44, 0x64, 0xA4, 0xC4, 0xD4,
593
+    0x05, 0x15, 0x25, 0x35, 0xD5, 0xE5, 0xF5, 0x26, 0x36, 0x46, 0xC6, 0xD6,
594
+    0xE6, 0x17, 0x27, 0x37, 0xC7, 0xD7, 0xE7, 0xF7, 0x19, 0x29, 0x39, 0xC9,
595
+    0xD9, 0xE9, 0xF9, 0x2A, 0x3A, 0x4A, 0x5A, 0xCA, 0xDA, 0xEA, 0x0B, 0x1B,
596
+    0x2B, 0x3B, 0xCB, 0xDB, 0xEB, 0xFB, 0x3C, 0x4C, 0x6C, 0x7C, 0x9C, 0xAC,
597
+    0xBC, 0xCC, 0xDC, 0x4D, 0x5D, 0x6D, 0x7D, 0x9D, 0xAD, 0xBD, 0xCD, 0x5E,
598
+    0x6E, 0x7E, 0x9E, 0xAE, 0xBE, 0x5F, 0x6F, 0x7F, 0x9F, 0xAF, 0xBF, 0xB3,
599
+    0x54, 0x74, 0x94, 0xB4, 0x45, 0x55, 0x65, 0x75, 0x95, 0xA5, 0xB5, 0xC5,
600
+    0x56, 0x66, 0x76, 0x96, 0xA6, 0xB6, 0x47, 0x57, 0x67, 0xA7, 0xB7, 0x49,
601
+    0x59, 0x69, 0xA9, 0xB9, 0x6A, 0x7A, 0x9A, 0xAA, 0xBA, 0x4B, 0x5B, 0x6B,
602
+    0x7B, 0x9B, 0xAB, 0xBB, 0x5C, 0x77, 0x97, 0x79, 0x99
603
+};
604
+
605
+static const uint8_t huff_a16_cb[13] = {
606
+    2, 12, 1, 1, 2, 2, 5, 7, 21, 54, 85, 62, 16
607
+};
608
+
609
+static const uint8_t huff_a16_xlat[256] = {
610
+    0x00, 0x01, 0x10, 0x11, 0x21, 0x12, 0x20, 0x31, 0x02, 0x22, 0x13, 0x30,
611
+    0x41, 0x32, 0x03, 0x23, 0x14, 0x24, 0x40, 0x51, 0x61, 0xD1, 0xE1, 0x42,
612
+    0x52, 0xD2, 0x33, 0x43, 0xD3, 0x04, 0x34, 0x05, 0x15, 0x25, 0x16, 0x1D,
613
+    0x2D, 0x1E, 0x2E, 0x50, 0x60, 0xD0, 0xE0, 0xF0, 0x71, 0x81, 0xF1, 0x62,
614
+    0x72, 0xE2, 0xF2, 0x53, 0x63, 0xE3, 0xF3, 0x44, 0x54, 0xD4, 0xE4, 0xF4,
615
+    0x35, 0x45, 0x55, 0xD5, 0xE5, 0xF5, 0x06, 0x26, 0x36, 0xD6, 0x07, 0x17,
616
+    0x27, 0x37, 0xD7, 0x18, 0x28, 0x1C, 0x0D, 0x3D, 0x4D, 0x5D, 0x6D, 0x8D,
617
+    0x0E, 0x3E, 0x4E, 0x5E, 0x0F, 0x1F, 0x2F, 0x3F, 0x5F, 0x70, 0x80, 0x90,
618
+    0xC0, 0x91, 0xA1, 0xB1, 0xC1, 0x82, 0x92, 0xA2, 0xC2, 0x73, 0x83, 0x93,
619
+    0xA3, 0xC3, 0x64, 0x74, 0x84, 0x94, 0xA4, 0xC4, 0x65, 0x75, 0x85, 0x46,
620
+    0x56, 0x66, 0xC6, 0xE6, 0xF6, 0x47, 0x57, 0xE7, 0xF7, 0x08, 0x38, 0x48,
621
+    0x58, 0x68, 0xD8, 0xE8, 0xF8, 0x09, 0x19, 0x29, 0x39, 0x59, 0xD9, 0xE9,
622
+    0xF9, 0x1A, 0x2A, 0x3A, 0xDA, 0xEA, 0xFA, 0x1B, 0x2B, 0xDB, 0xEB, 0xFB,
623
+    0x0C, 0x2C, 0x3C, 0xDC, 0xEC, 0x7D, 0x9D, 0xAD, 0xBD, 0xCD, 0x6E, 0x7E,
624
+    0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0x4F, 0x6F, 0x7F, 0x8F, 0xAF, 0xA0, 0xB2,
625
+    0xB3, 0xB4, 0x95, 0xA5, 0xB5, 0xC5, 0x76, 0x86, 0x96, 0xA6, 0xB6, 0x67,
626
+    0x77, 0x87, 0x97, 0xC7, 0x78, 0x88, 0x98, 0xC8, 0x49, 0x69, 0x79, 0x89,
627
+    0x99, 0xC9, 0x0A, 0x4A, 0x5A, 0x6A, 0x7A, 0xCA, 0x0B, 0x3B, 0x4B, 0x5B,
628
+    0x6B, 0xCB, 0x4C, 0x5C, 0x6C, 0x7C, 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xFC,
629
+    0xDD, 0xED, 0xFD, 0xDE, 0xEE, 0xFE, 0x9F, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF,
630
+    0xB0, 0xA7, 0xB7, 0xA8, 0xB8, 0xA9, 0xB9, 0x8A, 0x9A, 0xAA, 0xBA, 0x7B,
631
+    0x8B, 0x9B, 0xAB, 0xBB
632
+};
633
+
634
+static const uint8_t huff_a17_cb[9] = { 3, 9, 3, 2, 5, 7, 17, 23, 6 };
635
+
636
+static const uint8_t huff_a17_xlat[63] = {
637
+    0,   1, 63,  2, 62,  3,  4, 59, 60, 61,  5,  6,  7,  8, 56, 57,
638
+    58,  9, 10, 11, 12, 13, 14, 26, 27, 36, 37, 38, 50, 51, 52, 53,
639
+    54, 55, 15, 16, 17, 18, 19, 20, 21, 25, 28, 29, 30, 31, 33, 34,
640
+    35, 39, 43, 44, 45, 46, 47, 48, 49, 22, 23, 24, 40, 41, 42
641
+};
642
+
643
+static const uint8_t huff_a21_cb[14] = {
644
+    1, 12, 1, 0, 0, 2, 6, 0, 7, 21, 15, 17, 8, 4
645
+};
646
+
647
+static const uint8_t huff_a21_xlat[81] = {
648
+    0x00, 0x40, 0xC0, 0x10, 0x30, 0x04, 0x0C, 0x01, 0x03, 0xD0, 0x70, 0x34,
649
+    0x1C, 0x0D, 0x13, 0x07, 0x50, 0xF0, 0x44, 0xC4, 0x14, 0x74, 0x4C, 0xCC,
650
+    0xDC, 0x3C, 0x41, 0xC1, 0x11, 0x31, 0x05, 0x1D, 0x43, 0xC3, 0x33, 0x37,
651
+    0x0F, 0x54, 0xF4, 0xFC, 0xD1, 0x71, 0x15, 0x4D, 0xCD, 0xDD, 0xD3, 0x73,
652
+    0x47, 0xC7, 0x77, 0x3F, 0xD4, 0x5C, 0x7C, 0x51, 0xF1, 0x45, 0xC5, 0x55,
653
+    0x35, 0x3D, 0x53, 0xF3, 0x17, 0x4F, 0xCF, 0x1F, 0xFF, 0x75, 0xF5, 0x5D,
654
+    0x7D, 0xD7, 0xF7, 0x5F, 0xDF, 0xD5, 0xFD, 0x57, 0x7F
655
+};
656
+
657
+static const uint8_t huff_a22_cb[10] = { 2, 9, 1, 4, 0, 4, 3, 8, 3, 2 };
658
+
659
+static const uint8_t huff_a22_xlat[25] = {
660
+    0x00, 0x08, 0x38, 0x01, 0x07, 0x09, 0x39, 0x0F, 0x3F, 0x10, 0x02, 0x06,
661
+    0x30, 0x11, 0x31, 0x0A, 0x3A, 0x0E, 0x17, 0x37, 0x32, 0x16, 0x3E, 0x12,
662
+    0x36
663
+};
664
+
665
+static const uint8_t huff_a23_cb[9] = { 3, 9, 5, 0, 4, 6, 10, 16, 8 };
666
+
667
+static const uint8_t huff_a23_xlat[49] = {
668
+    0x00, 0x08, 0x38, 0x01, 0x07, 0x09, 0x39, 0x0F, 0x3F, 0x10, 0x30, 0x02,
669
+    0x3A, 0x06, 0x0E, 0x18, 0x28, 0x11, 0x31, 0x0A, 0x03, 0x05, 0x3E, 0x17,
670
+    0x37, 0x19, 0x29, 0x12, 0x2A, 0x32, 0x0B, 0x33, 0x3B, 0x0D, 0x15, 0x3D,
671
+    0x16, 0x1E, 0x36, 0x1F, 0x2F, 0x1A, 0x13, 0x1B, 0x2B, 0x1D, 0x2D, 0x35,
672
+    0x2E
673
+};
674
+
675
+static const uint8_t huff_a24_cb[5] = { 2, 4, 3, 1, 2 };
676
+
677
+static const uint8_t huff_a25_cb[5] = { 2, 4, 1, 5, 2 };
678
+
679
+static const uint8_t huff_a25_xlat[8] = { 1, 0, 2, 3, 4, 5, 6, 7 };
680
+
681
+static const uint8_t huff_a26_cb[10] = { 4, 11, 3, 4, 12, 15, 34, 83, 75, 30 };
682
+
683
+static const uint8_t huff_a26_xlat[256] = {
684
+    0x00, 0x01, 0x11, 0x10, 0x21, 0x12, 0x22, 0x20, 0x30, 0x31, 0x41, 0x02,
685
+    0x32, 0x03, 0x13, 0x23, 0x33, 0x14, 0x24, 0x40, 0x51, 0x61, 0x42, 0x52,
686
+    0x43, 0x53, 0x04, 0x34, 0x44, 0x15, 0x25, 0x35, 0x16, 0x26, 0x50, 0x60,
687
+    0x71, 0x81, 0xD1, 0x62, 0x72, 0x82, 0xD2, 0x63, 0x73, 0xD3, 0x54, 0x64,
688
+    0x05, 0x45, 0x55, 0x65, 0x06, 0x36, 0x46, 0x56, 0x17, 0x27, 0x37, 0x47,
689
+    0x18, 0x28, 0x38, 0x19, 0x1D, 0x2D, 0x3D, 0x1E, 0x70, 0x80, 0x90, 0xD0,
690
+    0xE0, 0x91, 0xA1, 0xB1, 0xC1, 0xE1, 0xF1, 0x92, 0xA2, 0xC2, 0xE2, 0xF2,
691
+    0x83, 0x93, 0xA3, 0xC3, 0xE3, 0xF3, 0x74, 0x84, 0x94, 0xA4, 0xC4, 0xD4,
692
+    0xE4, 0xF4, 0x75, 0x85, 0x95, 0xD5, 0xE5, 0x66, 0x76, 0x86, 0xD6, 0xE6,
693
+    0x07, 0x57, 0x67, 0x77, 0xD7, 0x08, 0x48, 0x58, 0x68, 0xD8, 0x09, 0x29,
694
+    0x39, 0x49, 0x59, 0x69, 0x1A, 0x2A, 0x3A, 0x4A, 0x1B, 0x2B, 0x1C, 0x2C,
695
+    0x3C, 0x4C, 0x0D, 0x4D, 0x5D, 0x6D, 0x7D, 0x8D, 0x0E, 0x2E, 0x3E, 0x4E,
696
+    0x5E, 0x6E, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0xA0, 0xB0, 0xC0, 0xF0, 0xB2,
697
+    0xB3, 0xB4, 0xA5, 0xB5, 0xC5, 0xF5, 0x96, 0xA6, 0xB6, 0xC6, 0xF6, 0x87,
698
+    0x97, 0xA7, 0xB7, 0xC7, 0xE7, 0xF7, 0x78, 0x88, 0x98, 0xA8, 0xC8, 0xE8,
699
+    0xF8, 0x79, 0x89, 0x99, 0xC9, 0xD9, 0xE9, 0xF9, 0x0A, 0x5A, 0x6A, 0x7A,
700
+    0x8A, 0xDA, 0xEA, 0xFA, 0x0B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B, 0x8B, 0xDB,
701
+    0x0C, 0x5C, 0x6C, 0x7C, 0x8C, 0x9C, 0xDC, 0x9D, 0xAD, 0xBD, 0xCD, 0x7E,
702
+    0x8E, 0x9E, 0xAE, 0xBE, 0x0F, 0x6F, 0x7F, 0x8F, 0x9F, 0xAF, 0xB8, 0xA9,
703
+    0xB9, 0x9A, 0xAA, 0xBA, 0xCA, 0x9B, 0xAB, 0xBB, 0xCB, 0xEB, 0xFB, 0xAC,
704
+    0xBC, 0xCC, 0xEC, 0xFC, 0xDD, 0xED, 0xFD, 0xCE, 0xDE, 0xEE, 0xFE, 0xBF,
705
+    0xCF, 0xDF, 0xEF, 0xFF
706
+};
707
+
708
+static const uint8_t huff_a27_cb[7] = { 4, 8, 3, 14, 10, 20, 16 };
709
+
710
+static const uint8_t huff_a27_xlat[63] = {
711
+     0,  2,  3,  1,  5,  6,  7,  9, 54, 55, 56, 58, 59, 60, 61, 62,
712
+    63,  4,  8, 10, 11, 12, 14, 49, 52, 53, 57, 13, 15, 16, 17, 18,
713
+    19, 22, 23, 25, 26, 30, 39, 43, 44, 45, 46, 47, 48, 50, 51, 20,
714
+    21, 24, 27, 28, 29, 31, 33, 34, 35, 36, 37, 38, 40, 41, 42
715
+};
716
+
717
+static const uint8_t huff_a31_cb[8] = { 1, 6, 1, 0, 3, 1, 0, 4 };
718
+
719
+static const uint8_t huff_a31_xlat[9] = {
720
+    0x00, 0x04, 0x0C, 0x01, 0x03, 0x05, 0x0D, 0x07, 0x0F
721
+};
722
+
723
+static const uint8_t huff_a32_cb[13] = {
724
+    1, 11, 1, 0, 0, 2, 2, 6, 12, 18, 19, 15, 6
725
+};
726
+
727
+static const uint8_t huff_a32_xlat[81] = {
728
+    0x00, 0x40, 0x01, 0x10, 0x04, 0x80, 0x50, 0x20, 0x14, 0x05, 0x02, 0x90,
729
+    0x60, 0x44, 0x54, 0x24, 0x08, 0x18, 0x41, 0x11, 0x15, 0x09, 0x06, 0xA0,
730
+    0x84, 0x94, 0x64, 0xA4, 0x48, 0x58, 0x28, 0x51, 0x21, 0x45, 0x55, 0x25,
731
+    0x19, 0x12, 0x16, 0x0A, 0x1A, 0x68, 0xA8, 0x81, 0x91, 0x61, 0xA1, 0x85,
732
+    0x95, 0x65, 0xA5, 0x49, 0x59, 0x29, 0x69, 0x42, 0x52, 0x46, 0x56, 0x2A,
733
+    0x88, 0x98, 0x89, 0x99, 0xA9, 0x82, 0x92, 0x22, 0x62, 0x86, 0x26, 0x66,
734
+    0x4A, 0x5A, 0x6A, 0xA2, 0x96, 0xA6, 0x8A, 0x9A, 0xAA
735
+};
736
+
737
+static const uint8_t huff_a33_cb[12] = {
738
+    3, 12, 1, 1, 13, 1, 14, 28, 33, 81, 32, 52
739
+};
740
+
741
+static const uint8_t huff_a33_xlat[256] = {
742
+    0x00, 0x10, 0x40, 0x50, 0x04, 0x44, 0x14, 0x54, 0x01, 0x41, 0x11, 0x51,
743
+    0x05, 0x45, 0x15, 0x55, 0x90, 0x20, 0x94, 0x64, 0x18, 0x21, 0x95, 0x19,
744
+    0x69, 0x02, 0x52, 0x06, 0x46, 0x16, 0x80, 0x60, 0x84, 0xD4, 0x24, 0x08,
745
+    0x48, 0x58, 0x68, 0x81, 0x91, 0x61, 0x85, 0x25, 0x65, 0xA5, 0x09, 0x49,
746
+    0x59, 0x29, 0x42, 0x12, 0x56, 0x96, 0xA6, 0x0A, 0x17, 0x1B, 0xD0, 0xC4,
747
+    0x74, 0xF4, 0x88, 0xC8, 0x28, 0xA1, 0x71, 0xC5, 0xD5, 0x75, 0x99, 0xB9,
748
+    0x4D, 0x1D, 0x2D, 0x6D, 0x22, 0x62, 0x66, 0x4A, 0x1A, 0x9A, 0x6A, 0x8E,
749
+    0x5E, 0x43, 0x23, 0x07, 0x47, 0x57, 0x6B, 0xC0, 0xA0, 0xE0, 0x70, 0xB0,
750
+    0xA4, 0xE4, 0x34, 0xB4, 0x98, 0xD8, 0xA8, 0x38, 0x78, 0x0C, 0x4C, 0x1C,
751
+    0x5C, 0x9C, 0x6C, 0x7C, 0xC1, 0xD1, 0xE1, 0x31, 0xE5, 0x35, 0xB5, 0xF5,
752
+    0x89, 0xA9, 0x79, 0xF9, 0x0D, 0xCD, 0x9D, 0xDD, 0xAD, 0x3D, 0x7D, 0x82,
753
+    0xC2, 0x92, 0xD2, 0xE2, 0x72, 0xF2, 0x86, 0xD6, 0xE6, 0x76, 0xB6, 0x8A,
754
+    0x5A, 0xDA, 0xEA, 0xFA, 0x4E, 0x1E, 0x9E, 0xEE, 0x03, 0x13, 0x53, 0x97,
755
+    0xB7, 0x0B, 0x4B, 0x8B, 0x5B, 0x9B, 0xEB, 0x7B, 0x0F, 0x4F, 0x1F, 0x5F,
756
+    0x9F, 0x2F, 0x3F, 0xBF, 0xE8, 0xB8, 0xF8, 0x8C, 0x2C, 0x3C, 0xFC, 0xB1,
757
+    0xC9, 0xD9, 0xE9, 0x39, 0x5D, 0xED, 0xBD, 0xA2, 0x32, 0x26, 0x36, 0x2A,
758
+    0xAA, 0xBA, 0x0E, 0x2E, 0x6E, 0x83, 0xC3, 0x93, 0x63, 0xB3, 0xA7, 0x37,
759
+    0x30, 0xF0, 0xCC, 0xDC, 0xAC, 0xEC, 0xBC, 0xF1, 0x8D, 0xFD, 0xB2, 0xC6,
760
+    0xF6, 0xCA, 0x3A, 0x7A, 0xCE, 0xDE, 0xAE, 0x3E, 0x7E, 0xBE, 0xFE, 0xD3,
761
+    0xA3, 0xE3, 0x33, 0x73, 0xF3, 0x87, 0xC7, 0xD7, 0x27, 0x67, 0xE7, 0x77,
762
+    0xF7, 0xCB, 0xDB, 0x2B, 0xAB, 0x3B, 0xBB, 0xFB, 0x8F, 0xCF, 0xDF, 0x6F,
763
+    0xAF, 0xEF, 0x7F, 0xFF
764
+};
765
+
766
+static const uint8_t huff_a34_cb[7] = { 1, 5, 1, 1, 1, 1, 2 };
767
+
768
+static const uint8_t huff_a34_xlat[6] = { 1, 0, 2, 3, 4, 5 };
769
+
770
+static const uint8_t huff_a35_cb[11] = { 2, 10, 1, 0, 2, 3, 6, 19, 9, 75, 110 };
771
+
772
+static const uint8_t huff_a35_xlat[225] = {
773
+    0x00, 0xF0, 0x0F, 0x10, 0x01, 0xFF, 0x20, 0xE0, 0x11, 0xF1, 0x0E, 0x1F,
774
+    0x30, 0x40, 0xD0, 0x21, 0xE1, 0x02, 0x12, 0x22, 0xE2, 0xF2, 0x03, 0x13,
775
+    0x1E, 0x2E, 0x3E, 0xEE, 0xFE, 0x2F, 0xEF, 0xD2, 0x43, 0xF3, 0x04, 0x0D,
776
+    0x2D, 0x3D, 0x3F, 0xDF, 0x50, 0x60, 0x70, 0x90, 0xB0, 0x31, 0x41, 0x91,
777
+    0xA1, 0xC1, 0xD1, 0x42, 0xA2, 0xC2, 0x23, 0x33, 0xE3, 0x24, 0x34, 0xB4,
778
+    0xD4, 0xF4, 0x05, 0x15, 0x45, 0xE5, 0x16, 0x36, 0x56, 0xA6, 0xC6, 0xD6,
779
+    0xF6, 0x57, 0xC7, 0xF7, 0x09, 0x29, 0x49, 0x59, 0x69, 0xF9, 0x0A, 0x2A,
780
+    0x3A, 0x4A, 0xDA, 0xEA, 0xFA, 0x0B, 0x2B, 0xAB, 0xEB, 0xFB, 0x0C, 0x1C,
781
+    0x2C, 0x3C, 0x4C, 0x5C, 0xCC, 0xDC, 0xFC, 0x1D, 0x4D, 0x6D, 0xBD, 0xCD,
782
+    0xED, 0xFD, 0x4E, 0x6E, 0xCE, 0xDE, 0x7F, 0xA0, 0xC0, 0x51, 0x61, 0x71,
783
+    0xB1, 0x32, 0x52, 0x62, 0x72, 0x92, 0xB2, 0x53, 0x63, 0x73, 0x93, 0xA3,
784
+    0xB3, 0xC3, 0xD3, 0x14, 0x44, 0x54, 0x64, 0x74, 0x94, 0xA4, 0xC4, 0xE4,
785
+    0x25, 0x35, 0x55, 0x65, 0x75, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xF5, 0x06,
786
+    0x26, 0x46, 0x66, 0x76, 0x96, 0xB6, 0xE6, 0x07, 0x17, 0x27, 0x37, 0x47,
787
+    0x67, 0x77, 0x97, 0xA7, 0xB7, 0xD7, 0xE7, 0x19, 0x39, 0x79, 0x99, 0xA9,
788
+    0xB9, 0xC9, 0xD9, 0xE9, 0x1A, 0x5A, 0x6A, 0x7A, 0x9A, 0xAA, 0xBA, 0xCA,
789
+    0x1B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B, 0x9B, 0xBB, 0xCB, 0xDB, 0x6C, 0x7C,
790
+    0x9C, 0xAC, 0xBC, 0xEC, 0x5D, 0x7D, 0x9D, 0xAD, 0xDD, 0x5E, 0x7E, 0x9E,
791
+    0xAE, 0xBE, 0x4F, 0x5F, 0x6F, 0x9F, 0xAF, 0xBF, 0xCF
792
+};
793
+
794
+static const uint8_t huff_a36_cb[12] = {
795
+    3, 12, 1, 3, 5, 5, 13, 27, 69, 96, 35, 2
796
+};
797
+
798
+static const uint8_t huff_a36_xlat[256] = {
799
+    0x00, 0x10, 0x01, 0x11, 0x20, 0x21, 0x02, 0x12, 0x22, 0x31, 0x41, 0x32,
800
+    0x13, 0x23, 0x30, 0x40, 0x51, 0x42, 0x03, 0x33, 0x43, 0x04, 0x14, 0x24,
801
+    0x34, 0x15, 0x25, 0x50, 0x61, 0x71, 0xD1, 0x52, 0x62, 0x72, 0xD2, 0x53,
802
+    0x63, 0xD3, 0x44, 0x54, 0x64, 0x05, 0x35, 0x45, 0x55, 0x16, 0x26, 0x36,
803
+    0x46, 0x17, 0x27, 0x1D, 0x2D, 0x3D, 0x60, 0x70, 0xD0, 0x81, 0x91, 0xA1,
804
+    0xC1, 0xE1, 0xF1, 0x82, 0x92, 0xC2, 0xE2, 0xF2, 0x73, 0x83, 0xE3, 0xF3,
805
+    0x74, 0x84, 0xC4, 0xD4, 0xE4, 0xF4, 0x65, 0x75, 0x85, 0xD5, 0xE5, 0x06,
806
+    0x56, 0x66, 0xD6, 0xE6, 0x07, 0x37, 0x47, 0x57, 0x67, 0xD7, 0xE7, 0x18,
807
+    0x28, 0x38, 0x48, 0x58, 0xD8, 0x19, 0x29, 0x2A, 0x1C, 0x2C, 0x0D, 0x4D,
808
+    0x5D, 0x6D, 0x7D, 0x8D, 0x9D, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
809
+    0x1F, 0x2F, 0x3F, 0x80, 0x90, 0xA0, 0xC0, 0xE0, 0xF0, 0xB1, 0xA2, 0xB2,
810
+    0x93, 0xA3, 0xB3, 0xC3, 0x94, 0xA4, 0xB4, 0x95, 0xA5, 0xB5, 0xC5, 0xF5,
811
+    0x76, 0x86, 0x96, 0xA6, 0xC6, 0xF6, 0x77, 0x87, 0x97, 0xA7, 0xC7, 0xF7,
812
+    0x08, 0x68, 0x78, 0x88, 0x98, 0xC8, 0xE8, 0xF8, 0x09, 0x39, 0x49, 0x59,
813
+    0x69, 0x79, 0x89, 0xD9, 0xE9, 0xF9, 0x0A, 0x1A, 0x3A, 0x4A, 0x5A, 0x6A,
814
+    0xDA, 0xEA, 0xFA, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0xDB, 0xEB, 0xFB, 0x0C,
815
+    0x3C, 0x4C, 0x5C, 0x6C, 0x7C, 0x8C, 0x9C, 0xDC, 0xEC, 0xAD, 0xBD, 0xCD,
816
+    0xDD, 0xED, 0x0E, 0x8E, 0x9E, 0xAE, 0xBE, 0x0F, 0x4F, 0x5F, 0x6F, 0x7F,
817
+    0x8F, 0x9F, 0xAF, 0xB0, 0xB6, 0xB7, 0xA8, 0xB8, 0x99, 0xA9, 0xB9, 0xC9,
818
+    0x7A, 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0x0B, 0x6B, 0x7B, 0x8B, 0x9B, 0xCB,
819
+    0xAC, 0xBC, 0xCC, 0xFC, 0xFD, 0xCE, 0xDE, 0xEE, 0xFE, 0xBF, 0xCF, 0xDF,
820
+    0xEF, 0xFF, 0xAB, 0xBB
821
+};
822
+
823
+static const uint8_t huff_a37_cb[7] = { 4, 8, 7, 6, 8, 22, 20 };
824
+
825
+static const uint8_t huff_a37_xlat[63] = {
826
+     0,  1,  2,  3, 61, 62, 63,  4,  5,  6, 58, 59, 60,  7,  8,  9,
827
+    10, 54, 55, 56, 57, 11, 12, 13, 14, 15, 16, 25, 26, 27, 28, 29,
828
+    30, 35, 36, 37, 38, 48, 49, 50, 51, 52, 53, 17, 18, 19, 20, 21,
829
+    22, 23, 24, 31, 33, 34, 39, 40, 41, 42, 43, 44, 45, 46, 47
830
+};
831
+
832
+static const uint8_t huff_a41_cb[14] = {
833
+    1, 12, 1, 0, 0, 6, 2, 0, 0, 0, 19, 9, 24, 20
834
+};
835
+
836
+static const uint8_t huff_a41_xlat[81] = {
837
+    0x00, 0x40, 0xC0, 0x10, 0x30, 0x04, 0x0C, 0x01, 0x03, 0x50, 0xD0, 0x70,
838
+    0xF0, 0xC4, 0x34, 0x4C, 0xCC, 0x1C, 0x41, 0xC1, 0x31, 0x05, 0x0D, 0x43,
839
+    0xC3, 0x13, 0x07, 0x0F, 0x44, 0x14, 0x74, 0xDC, 0x3C, 0x11, 0x1D, 0x33,
840
+    0x37, 0x54, 0xD4, 0xF4, 0x5C, 0x7C, 0xFC, 0xD1, 0x71, 0xF1, 0xC5, 0x15,
841
+    0x35, 0x4D, 0xCD, 0xDD, 0x3D, 0xD3, 0x73, 0x47, 0xC7, 0x17, 0x77, 0x1F,
842
+    0x3F, 0x51, 0x45, 0x55, 0xD5, 0x75, 0xF5, 0x5D, 0x7D, 0xFD, 0x53, 0xF3,
843
+    0x57, 0xD7, 0xF7, 0x4F, 0xCF, 0x5F, 0xDF, 0x7F, 0xFF
844
+};
845
+
846
+static const uint8_t huff_a42_cb[10] = { 3, 10, 1, 2, 13, 1, 31, 13, 16, 4 };
847
+
848
+static const uint8_t huff_a42_xlat[81] = {
849
+    0x00, 0x40, 0x01, 0x10, 0x50, 0x04, 0x44, 0x14, 0x54, 0x41, 0x11, 0x51,
850
+    0x05, 0x45, 0x15, 0x55, 0x59, 0x80, 0x90, 0x20, 0x60, 0x84, 0x94, 0x24,
851
+    0x64, 0x08, 0x48, 0x18, 0x58, 0x81, 0x91, 0x21, 0x61, 0x85, 0x95, 0x25,
852
+    0x65, 0x09, 0x49, 0x19, 0x02, 0x42, 0x12, 0x52, 0x06, 0x46, 0x16, 0x56,
853
+    0xA0, 0xA4, 0x68, 0xA1, 0xA5, 0x99, 0x29, 0x69, 0x96, 0x66, 0x4A, 0x1A,
854
+    0x5A, 0x88, 0x98, 0x28, 0x89, 0xA9, 0x82, 0x92, 0x22, 0x62, 0x86, 0x26,
855
+    0xA6, 0x0A, 0x9A, 0x2A, 0x6A, 0xA8, 0xA2, 0x8A, 0xAA
856
+};
857
+
858
+static const uint8_t huff_a43_cb[5] = { 2, 4, 2, 3, 2 };
859
+
860
+static const uint8_t huff_a43_xlat[7] = { 0, 7, 1, 2, 6, 3, 5 };
861
+
862
+static const uint8_t huff_a44_cb[9] = { 4, 10, 5, 4, 12, 17, 47, 24, 12 };
863
+
864
+static const uint8_t huff_a44_xlat[121] = {
865
+    0x00, 0x10, 0xF0, 0x01, 0x0F, 0x11, 0xF1, 0x1F, 0xFF, 0x20, 0xE0, 0x21,
866
+    0xE1, 0x02, 0x12, 0xF2, 0x0E, 0x1E, 0xFE, 0x2F, 0xEF, 0x30, 0x50, 0xD0,
867
+    0xD1, 0x22, 0xE2, 0x03, 0x13, 0xF3, 0x0D, 0x1D, 0x2D, 0xFD, 0x2E, 0xEE,
868
+    0x3F, 0xDF, 0x40, 0xB0, 0xC0, 0x31, 0x41, 0x51, 0xB1, 0xC1, 0x32, 0xB2,
869
+    0xC2, 0xD2, 0x23, 0xB3, 0xD3, 0xE3, 0x04, 0x14, 0xE4, 0xF4, 0x05, 0x15,
870
+    0xD5, 0xE5, 0xF5, 0x0B, 0x1B, 0x2B, 0x3B, 0xEB, 0xFB, 0x0C, 0x1C, 0x2C,
871
+    0xFC, 0x3D, 0x5D, 0xED, 0x3E, 0x4E, 0x5E, 0xBE, 0xDE, 0x4F, 0x5F, 0xBF,
872
+    0xCF, 0x42, 0x52, 0x33, 0x53, 0xC3, 0x24, 0xB4, 0xD4, 0x25, 0x35, 0xC5,
873
+    0x4B, 0xCB, 0xDB, 0x3C, 0x4C, 0x5C, 0xDC, 0xEC, 0x4D, 0xBD, 0xCD, 0xDD,
874
+    0xCE, 0x43, 0x34, 0x44, 0x54, 0xC4, 0x45, 0x55, 0xB5, 0x5B, 0xBB, 0xBC,
875
+    0xCC
876
+};
877
+
878
+static const uint8_t huff_a45_cb[5] = { 2, 4, 2, 2, 4 };
879
+
880
+static const uint8_t huff_a45_xlat[8] = { 1, 2, 0, 3, 4, 5, 6, 7 };
881
+
882
+static const uint8_t huff_a46_cb[7] = { 5, 9, 1, 16, 31, 36, 172 };
883
+
884
+static const uint8_t huff_a46_xlat[256] = {
885
+    0x02, 0x00, 0x30, 0x21, 0x31, 0x41, 0x61, 0x12, 0x22, 0x42, 0x62, 0x43,
886
+    0x53, 0x24, 0x45, 0x26, 0x27, 0x10, 0x40, 0xB0, 0x01, 0x11, 0x81, 0x32,
887
+    0x52, 0x72, 0x92, 0x03, 0x13, 0x33, 0x63, 0x14, 0x34, 0x54, 0x64, 0x74,
888
+    0x05, 0x15, 0x25, 0x35, 0x55, 0x65, 0x06, 0x46, 0x56, 0x57, 0x67, 0x88,
889
+    0x20, 0x51, 0x91, 0xD1, 0xF2, 0x23, 0x83, 0x93, 0x04, 0x44, 0x84, 0x94,
890
+    0x75, 0x85, 0xC5, 0x36, 0x66, 0x96, 0xB6, 0x07, 0x37, 0x97, 0x08, 0x28,
891
+    0x38, 0x48, 0x68, 0x09, 0x69, 0x79, 0x0A, 0x2A, 0x1B, 0x9B, 0x2C, 0x4D,
892
+    0x50, 0x60, 0x70, 0x80, 0x90, 0xA0, 0xC0, 0xD0, 0xE0, 0xF0, 0x71, 0xA1,
893
+    0xB1, 0xC1, 0xE1, 0xF1, 0x82, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0x73, 0xA3,
894
+    0xB3, 0xC3, 0xD3, 0xE3, 0xF3, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4, 0x95,
895
+    0xA5, 0xB5, 0xD5, 0xE5, 0xF5, 0x16, 0x76, 0x86, 0xA6, 0xC6, 0xD6, 0xE6,
896
+    0xF6, 0x17, 0x47, 0x77, 0x87, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7, 0x18,
897
+    0x58, 0x78, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8, 0x19, 0x29, 0x39,
898
+    0x49, 0x59, 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9, 0x1A, 0x3A,
899
+    0x4A, 0x5A, 0x6A, 0x7A, 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
900
+    0x0B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B, 0x8B, 0xAB, 0xBB, 0xCB, 0xDB,
901
+    0xEB, 0xFB, 0x0C, 0x1C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C, 0x8C, 0x9C, 0xAC,
902
+    0xBC, 0xCC, 0xDC, 0xEC, 0xFC, 0x0D, 0x1D, 0x2D, 0x3D, 0x5D, 0x6D, 0x7D,
903
+    0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD, 0x0E, 0x1E, 0x2E, 0x3E,
904
+    0x4E, 0x5E, 0x6E, 0x7E, 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
905
+    0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F, 0x8F, 0x9F, 0xAF, 0xBF,
906
+    0xCF, 0xDF, 0xEF, 0xFF
907
+};
908
+
909
+static const uint8_t huff_a47_cb[8] = { 4, 9, 5, 12, 9, 12, 15, 10 };
910
+
911
+static const uint8_t huff_a47_xlat[63] = {
912
+     0,  1,  2, 62, 63,  3,  4,  5,  6,  8, 54, 56, 57, 58, 59, 60,
913
+    61,  7,  9, 10, 11, 12, 13, 14, 53, 55, 15, 16, 17, 18, 19, 20,
914
+    21, 36, 37, 39, 42, 52, 22, 25, 28, 35, 38, 40, 41, 43, 45, 46,
915
+    47, 48, 49, 50, 51, 23, 24, 26, 27, 29, 30, 31, 33, 34, 44
916
+};
917
+
918
+static const uint8_t huff_a51_cb[12] = {
919
+    2, 11, 1, 0, 6, 2, 6, 18, 4, 26, 6, 12
920
+};
921
+
922
+static const uint8_t huff_a51_xlat[81] = {
923
+    0x00, 0x40, 0xC0, 0x30, 0x04, 0x01, 0x03, 0x10, 0x0C, 0xD0, 0x70, 0x34,
924
+    0x1C, 0x0D, 0x07, 0x50, 0xF0, 0x44, 0xC4, 0x14, 0x4C, 0xCC, 0x3C, 0x41,
925
+    0xC1, 0x11, 0x31, 0x05, 0x43, 0xC3, 0x13, 0x33, 0x0F, 0x74, 0xDC, 0x1D,
926
+    0x37, 0x54, 0xD4, 0xF4, 0x5C, 0x7C, 0xFC, 0xD1, 0x71, 0xF1, 0xC5, 0x15,
927
+    0x35, 0x4D, 0xCD, 0xDD, 0x3D, 0x53, 0xD3, 0x73, 0x47, 0xC7, 0x17, 0x77,
928
+    0x4F, 0x1F, 0x3F, 0x51, 0x45, 0x55, 0xF3, 0xCF, 0xFF, 0xD5, 0x75, 0xF5,
929
+    0x5D, 0x7D, 0xFD, 0x57, 0xD7, 0xF7, 0x5F, 0xDF, 0x7F
930
+};
931
+
932
+static const uint8_t huff_a52_cb[12] = { 1, 10, 1, 0, 2, 2, 0, 4, 3, 8, 3, 2 };
933
+
934
+static const uint8_t huff_a52_xlat[25] = {
935
+    0x00, 0x08, 0x38, 0x01, 0x07, 0x09, 0x39, 0x0F, 0x3F, 0x10, 0x02, 0x06,
936
+    0x30, 0x11, 0x31, 0x0A, 0x3A, 0x0E, 0x17, 0x37, 0x32, 0x16, 0x3E, 0x12,
937
+    0x36
938
+};
939
+
940
+static const uint8_t huff_a53_xlat[7] = { 0, 1, 2, 6, 7, 3, 5 };
941
+
942
+static const uint8_t huff_a54_cb[8] = { 4, 9, 4, 7, 12, 19, 21, 58 };
943
+
944
+static const uint8_t huff_a54_xlat[121] = {
945
+    0x00, 0x01, 0x0F, 0x1F, 0x10, 0xE0, 0xF0, 0x11, 0xF1, 0x2F, 0xFF, 0x20,
946
+    0x21, 0xE1, 0x02, 0x12, 0xF2, 0x03, 0xF3, 0x0E, 0x2E, 0xFE, 0x3F, 0x30,
947
+    0x40, 0xD0, 0xC1, 0xD1, 0x22, 0xC2, 0x33, 0xE3, 0x0C, 0xCC, 0x0D, 0x1D,
948
+    0x2D, 0xFD, 0x1E, 0x3E, 0x5E, 0xEF, 0xC0, 0x52, 0xB2, 0xD2, 0x43, 0xC3,
949
+    0xD3, 0x24, 0x45, 0xF5, 0x4B, 0x5B, 0xFB, 0x1C, 0x3D, 0xBD, 0xDD, 0xEE,
950
+    0xBF, 0xCF, 0xDF, 0x50, 0xB0, 0x31, 0x41, 0x51, 0xB1, 0x32, 0x42, 0xE2,
951
+    0x13, 0x23, 0x53, 0xB3, 0x04, 0x14, 0x34, 0x44, 0x54, 0xB4, 0xC4, 0xD4,
952
+    0xE4, 0xF4, 0x05, 0x15, 0x25, 0x35, 0x55, 0xB5, 0xC5, 0xD5, 0xE5, 0x0B,
953
+    0x1B, 0x2B, 0x3B, 0xBB, 0xCB, 0xDB, 0xEB, 0x2C, 0x3C, 0x4C, 0x5C, 0xBC,
954
+    0xDC, 0xEC, 0xFC, 0x4D, 0x5D, 0xCD, 0xED, 0x4E, 0xBE, 0xCE, 0xDE, 0x4F,
955
+    0x5F
956
+};
957
+
958
+static const uint8_t huff_a55_cb[8] = { 1, 6, 1, 1, 1, 0, 3, 2 };
959
+
960
+static const uint8_t huff_a55_xlat[8] = { 0, 1, 2, 3, 6, 7, 4, 5 };
961
+
962
+static const uint8_t huff_a56_cb[7] = { 3, 7, 1, 8, 6, 8, 8 };
963
+
964
+static const uint8_t huff_a56_xlat[31] = {
965
+    4,  0,  1,  2,  3, 28, 29, 30, 31,  5,  6,  7, 24, 25, 27, 8,
966
+    9, 14, 19, 21, 22, 23, 26, 10, 11, 12, 13, 15, 17, 18, 20
967
+};
968
+
969
+static const uint8_t huff_a57_cb[9] = { 3, 9, 1, 5, 7, 8, 16, 22, 4 };
970
+
971
+static const uint8_t huff_a57_xlat[63] = {
972
+     0,  1,  2, 61, 62, 63,  3,  4,  5,  6, 58, 59,
973
+    60,  7,  8,  9, 10, 54, 55, 56, 57, 11, 12, 13,
974
+    14, 15, 26, 27, 28, 36, 37, 38, 49, 50, 51, 52,
975
+    53, 16, 17, 18, 19, 20, 21, 23, 24, 25, 29, 30,
976
+    31, 33, 34, 35, 39, 43, 44, 45, 46, 47, 48, 22,
977
+    40, 41, 42
978
+};
979
+
980
+static const uint8_t huff_a61_cb[12] = {
981
+    2, 11, 1, 0, 8, 0, 1, 16, 10, 29, 12, 4
982
+};
983
+
984
+static const uint8_t huff_a61_xlat[81] = {
985
+    0x00, 0x40, 0xC0, 0x10, 0x30, 0x04, 0x0C, 0x01, 0x03, 0x70, 0x50, 0xD0,
986
+    0xF0, 0x44, 0xC4, 0x14, 0x34, 0x4C, 0x1C, 0x3C, 0x31, 0x05, 0x0D, 0x13,
987
+    0x07, 0x0F, 0x74, 0xCC, 0xDC, 0xFC, 0x41, 0xC1, 0x11, 0x43, 0xC3, 0x33,
988
+    0x54, 0xD4, 0xF4, 0x5C, 0x7C, 0x51, 0xD1, 0x71, 0xF1, 0x45, 0xC5, 0x15,
989
+    0x35, 0x4D, 0xCD, 0x1D, 0x3D, 0x53, 0xD3, 0x73, 0xF3, 0x47, 0xC7, 0x17,
990
+    0x37, 0x4F, 0xCF, 0x1F, 0x3F, 0x55, 0xD5, 0x75, 0xF5, 0x5D, 0xDD, 0xFD,
991
+    0x57, 0xD7, 0x77, 0xF7, 0xFF, 0x7D, 0x5F, 0xDF, 0x7F
992
+};
993
+
994
+static const uint8_t huff_a62_cb[8] = { 3, 8, 5, 2, 2, 9, 5, 2 };
995
+
996
+static const uint8_t huff_a62_xlat[25] = {
997
+    0x00, 0x08, 0x38, 0x01, 0x07, 0x39, 0x0F, 0x09, 0x3F, 0x10, 0x30, 0x31,
998
+    0x02, 0x3A, 0x06, 0x0E, 0x17, 0x37, 0x11, 0x0A, 0x32, 0x16, 0x3E, 0x12,
999
+    0x36
1000
+};
1001
+
1002
+static const uint8_t huff_a63_cb[11] = {
1003
+    3, 11, 1, 1, 10, 4, 16, 29, 46, 75, 74
1004
+};
1005
+
1006
+static const uint8_t huff_a63_xlat[256] = {
1007
+    0x00, 0x40, 0x10, 0x50, 0x04, 0x44, 0x14, 0x01, 0x41, 0x05, 0x45, 0x55,
1008
+    0x54, 0x11, 0x51, 0x15, 0x80, 0x90, 0x60, 0x24, 0x64, 0xA4, 0x48, 0x61,
1009
+    0x95, 0x25, 0xA5, 0x02, 0x42, 0x52, 0x16, 0x56, 0x20, 0x84, 0x94, 0x18,
1010
+    0x58, 0x81, 0x91, 0x85, 0x65, 0x09, 0x49, 0x19, 0x59, 0x99, 0x29, 0x69,
1011
+    0x79, 0x5D, 0x12, 0x62, 0x06, 0x46, 0x86, 0x66, 0x1A, 0x5A, 0x6A, 0x47,
1012
+    0x17, 0xC0, 0xA0, 0xE0, 0xC4, 0xD4, 0x74, 0x08, 0x78, 0x0C, 0x4C, 0x1C,
1013
+    0x5C, 0xD1, 0x21, 0xE1, 0x71, 0xC5, 0xE5, 0x75, 0xB5, 0x89, 0xBD, 0x92,
1014
+    0x22, 0x96, 0xA6, 0x36, 0x0A, 0x4A, 0x8A, 0x9A, 0x2A, 0x7A, 0xDE, 0x6E,
1015
+    0x43, 0x13, 0x53, 0x23, 0x07, 0x77, 0x4B, 0x1B, 0x9B, 0x6B, 0x2F, 0xD0,
1016
+    0x30, 0x70, 0xE4, 0x34, 0xF4, 0xC8, 0x98, 0x28, 0x68, 0xA8, 0xE8, 0x38,
1017
+    0xB8, 0xF8, 0x9C, 0x2C, 0x6C, 0x7C, 0xA1, 0xB1, 0xD5, 0x35, 0xC9, 0xD9,
1018
+    0xA9, 0xE9, 0x39, 0xB9, 0xF9, 0xCD, 0x1D, 0x2D, 0xAD, 0x7D, 0xC2, 0xD2,
1019
+    0xA2, 0xB2, 0xF2, 0xC6, 0x26, 0x76, 0xB6, 0xDA, 0xAA, 0xEA, 0x3A, 0xFA,
1020
+    0x0E, 0x4E, 0x2E, 0x7E, 0xBE, 0xFE, 0x03, 0x83, 0x63, 0xA3, 0xB3, 0x87,
1021
+    0x57, 0x97, 0xD7, 0x27, 0x0B, 0x8B, 0x5B, 0x2B, 0xAB, 0xCF, 0x1F, 0x9F,
1022
+    0x7F, 0xBF, 0xB0, 0xF0, 0xB4, 0x88, 0xD8, 0x8C, 0xCC, 0xDC, 0xAC, 0xEC,
1023
+    0x3C, 0xBC, 0xFC, 0xC1, 0x31, 0xF1, 0xF5, 0x0D, 0x4D, 0x8D, 0x9D, 0xDD,
1024
+    0x6D, 0xED, 0x3D, 0xFD, 0x82, 0xE2, 0x32, 0x72, 0xD6, 0xE6, 0xF6, 0xCA,
1025
+    0xBA, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xAE, 0xEE, 0x3E, 0xC3, 0x93, 0xD3,
1026
+    0xE3, 0x33, 0x73, 0xF3, 0xC7, 0x67, 0xA7, 0xE7, 0x37, 0xB7, 0xF7, 0xCB,
1027
+    0xDB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB, 0x0F, 0x4F, 0x8F, 0x5F, 0xDF, 0x6F,
1028
+    0xAF, 0xEF, 0x3F, 0xFF
1029
+};
1030
+
1031
+static const uint8_t huff_a64_cb[8] = { 4, 9, 1, 7, 12, 36, 63, 2 };
1032
+
1033
+static const uint8_t huff_a64_xlat[121] = {
1034
+    0x00, 0x10, 0x20, 0xE0, 0xF0, 0x02, 0x0E, 0xEF, 0x30, 0x01, 0x11, 0x21,
1035
+    0x31, 0xF1, 0x12, 0xF2, 0x1E, 0xEE, 0xDF, 0xFF, 0x40, 0xC0, 0xD0, 0xD1,
1036
+    0xE1, 0x22, 0x32, 0x42, 0xD2, 0xE2, 0x03, 0x13, 0x23, 0xB3, 0xC3, 0xE3,
1037
+    0xF3, 0xE4, 0x05, 0xF5, 0x2B, 0x0C, 0xFC, 0x1D, 0x2D, 0xBD, 0xDD, 0xFD,
1038
+    0x2E, 0x4E, 0xDE, 0xFE, 0x0F, 0x1F, 0x2F, 0x3F, 0x50, 0xB0, 0x41, 0x51,
1039
+    0xB1, 0xC1, 0x52, 0xB2, 0xC2, 0x33, 0x43, 0x53, 0xD3, 0x04, 0x14, 0x24,
1040
+    0x34, 0x44, 0x54, 0xB4, 0xC4, 0xD4, 0xF4, 0x15, 0x25, 0x35, 0x45, 0x55,
1041
+    0xB5, 0xC5, 0xD5, 0xE5, 0x0B, 0x1B, 0x3B, 0x4B, 0x5B, 0xBB, 0xCB, 0xDB,
1042
+    0xEB, 0xFB, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0xBC, 0xCC, 0xDC, 0xEC, 0x0D,
1043
+    0x3D, 0x4D, 0x5D, 0xCD, 0xED, 0x3E, 0x5E, 0xBE, 0xCE, 0x4F, 0xCF, 0x5F,
1044
+    0xBF
1045
+};
1046
+
1047
+static const uint8_t huff_a65_cb[8] = { 2, 7, 3, 0, 1, 3, 4, 4 };
1048
+
1049
+static const uint8_t huff_a65_xlat[15] = {
1050
+    0, 1, 15, 14, 2, 3, 13, 4, 6, 10, 12, 5, 7, 9, 11
1051
+};
1052
+
1053
+static const uint8_t huff_a66_cb[11] = { 2, 10, 1, 2, 2, 6, 8, 6, 3, 1, 2 };
1054
+
1055
+static const uint8_t huff_a66_xlat[31] = {
1056
+     0,  1, 31, 2, 30,  3,  4, 15, 17, 28, 29,  5,  6,  7,  8, 24,
1057
+    25, 26, 27, 9, 10, 11, 21, 22, 23, 12, 19, 20, 13, 14, 18
1058
+};
1059
+
1060
+static const uint8_t huff_a67_cb[10] = { 2, 9, 1, 1, 3, 4, 6, 13, 25, 10 };
1061
+
1062
+static const uint8_t huff_a67_xlat[63] = {
1063
+     0,  1,  2, 62, 63,  3,  4, 60, 61,  5,  6,  7, 57, 58, 59,  8,
1064
+     9, 10, 11, 12, 13, 26, 38, 52, 53, 54, 55, 56, 14, 15, 16, 17,
1065
+    18, 19, 25, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 39, 45, 46,
1066
+    47, 48, 49, 50, 51, 20, 21, 22, 23, 24, 40, 41, 42, 43, 44
1067
+};
1068
+
1069
+static const uint8_t huff_a71_cb[5] = { 1, 3, 1, 1, 2 };
1070
+
1071
+static const uint8_t huff_a72_cb[12] = {
1072
+    2, 11, 1, 0, 4, 8, 3, 8, 24, 17, 12, 4
1073
+};
1074
+
1075
+static const uint8_t huff_a72_xlat[81] = {
1076
+    0x00, 0x40, 0x10, 0x04, 0x01, 0x50, 0x44, 0x14, 0x54, 0x41, 0x11, 0x05,
1077
+    0x15, 0x51, 0x45, 0x55, 0x80, 0x90, 0x20, 0x64, 0x08, 0x19, 0x02, 0x06,
1078
+    0x60, 0x84, 0x94, 0x24, 0x48, 0x18, 0x58, 0x81, 0x91, 0x21, 0x61, 0x85,
1079
+    0x95, 0x25, 0x65, 0x09, 0x49, 0x59, 0x42, 0x12, 0x52, 0x46, 0x16, 0x56,
1080
+    0xA0, 0xA4, 0x98, 0x28, 0x68, 0xA1, 0xA5, 0x99, 0x29, 0x69, 0x96, 0x26,
1081
+    0x66, 0x0A, 0x4A, 0x1A, 0x5A, 0x88, 0xA8, 0x89, 0xA9, 0x82, 0x92, 0x22,
1082
+    0x62, 0x86, 0xA6, 0x2A, 0x6A, 0xA2, 0x8A, 0x9A, 0xAA
1083
+};
1084
+
1085
+static const uint8_t huff_a73_cb[11] = { 2, 10, 1, 1, 5, 2, 8, 7, 13, 8, 4 };
1086
+
1087
+static const uint8_t huff_a73_xlat[49] = {
1088
+    0x00, 0x08, 0x38, 0x01, 0x39, 0x07, 0x0F, 0x09, 0x3F, 0x10, 0x30, 0x31,
1089
+    0x02, 0x3A, 0x06, 0x0E, 0x17, 0x11, 0x0A, 0x32, 0x0D, 0x16, 0x3E, 0x37,
1090
+    0x18, 0x28, 0x19, 0x29, 0x12, 0x2A, 0x03, 0x3B, 0x05, 0x15, 0x1E, 0x1F,
1091
+    0x2F, 0x1A, 0x0B, 0x2B, 0x33, 0x35, 0x3D, 0x2E, 0x36, 0x13, 0x1B, 0x1D,
1092
+    0x2D
1093
+};
1094
+
1095
+static const uint8_t huff_a74_cb[14] = {
1096
+    1, 12, 1, 0, 0, 4, 0, 4, 5, 9, 30, 45, 21, 2
1097
+};
1098
+
1099
+static const uint8_t huff_a74_xlat[121] = {
1100
+    0x00, 0x10, 0xF0, 0x01, 0x0F, 0x11, 0xF1, 0x1F, 0xFF, 0x20, 0xE0, 0x02,
1101
+    0xF2, 0x0E, 0x21, 0xE1, 0x12, 0xE2, 0x1E, 0x2E, 0xFE, 0x2F, 0xEF, 0x30,
1102
+    0x50, 0xB0, 0xC0, 0xD0, 0x31, 0xB1, 0xD1, 0x22, 0xD2, 0x03, 0x13, 0xE3,
1103
+    0xF3, 0xF4, 0x05, 0xE5, 0xF5, 0x0B, 0x1B, 0x0C, 0x0D, 0x1D, 0x2D, 0xFD,
1104
+    0x3E, 0xEE, 0x3F, 0x5F, 0xDF, 0x40, 0x41, 0x51, 0xC1, 0x32, 0x42, 0x52,
1105
+    0xB2, 0xC2, 0x23, 0x33, 0xB3, 0xC3, 0xD3, 0x04, 0x14, 0x24, 0xD4, 0xE4,
1106
+    0x15, 0x25, 0xC5, 0xD5, 0x2B, 0x3B, 0xEB, 0xFB, 0x1C, 0x2C, 0x3C, 0x5C,
1107
+    0xEC, 0xFC, 0x3D, 0x5D, 0xDD, 0xED, 0x4E, 0x5E, 0xBE, 0xCE, 0xDE, 0x4F,
1108
+    0xBF, 0xCF, 0x43, 0x53, 0x34, 0x54, 0xB4, 0xC4, 0x35, 0x45, 0x55, 0xB5,
1109
+    0x4B, 0x5B, 0xCB, 0xDB, 0x4C, 0xBC, 0xCC, 0xDC, 0x4D, 0xBD, 0xCD, 0x44,
1110
+    0xBB
1111
+};
1112
+
1113
+static const uint8_t huff_a75_cb[7] = { 2, 6, 1, 3, 3, 4, 4 };
1114
+
1115
+static const uint8_t huff_a75_xlat[15] = {
1116
+    0, 1, 14, 15, 2, 3, 13, 4, 6, 10, 12, 5, 7, 9, 11
1117
+};
1118
+
1119
+static const uint8_t huff_a76_cb[12] = {
1120
+    3, 12, 1, 3, 4, 8, 10, 36, 60, 78, 48, 8
1121
+};
1122
+
1123
+static const uint8_t huff_a76_xlat[256] = {
1124
+    0x00, 0x10, 0x01, 0x11, 0x20, 0x21, 0x02, 0x12, 0x30, 0x31, 0x41, 0x22,
1125
+    0x03, 0x13, 0x23, 0x14, 0x40, 0x51, 0x61, 0x32, 0x42, 0x33, 0x04, 0x24,
1126
+    0x15, 0x16, 0x50, 0x60, 0xD0, 0x71, 0x81, 0xD1, 0xE1, 0xF1, 0x52, 0x62,
1127
+    0x72, 0xD2, 0x43, 0x53, 0x63, 0xD3, 0x34, 0x44, 0x54, 0x05, 0x25, 0x35,
1128
+    0x45, 0x06, 0x26, 0x36, 0x17, 0x27, 0x18, 0x0D, 0x1D, 0x2D, 0x3D, 0x1E,
1129
+    0x2E, 0x1F, 0x70, 0x80, 0xE0, 0xF0, 0x91, 0xA1, 0xC1, 0x82, 0x92, 0xC2,
1130
+    0xE2, 0xF2, 0x73, 0x83, 0x93, 0xE3, 0xF3, 0x64, 0x74, 0x84, 0xD4, 0xE4,
1131
+    0xF4, 0x55, 0x65, 0xD5, 0xE5, 0xF5, 0x46, 0x56, 0x66, 0xD6, 0x07, 0x37,
1132
+    0x47, 0x57, 0x08, 0x28, 0x38, 0x48, 0x19, 0x29, 0x39, 0x1A, 0x2A, 0x1B,
1133
+    0x1C, 0x2C, 0x3C, 0x4D, 0x5D, 0x6D, 0x0E, 0x3E, 0x4E, 0x5E, 0x0F, 0x2F,
1134
+    0x3F, 0x4F, 0x90, 0xA0, 0xB0, 0xC0, 0xB1, 0xA2, 0xB2, 0xA3, 0xB3, 0xC3,
1135
+    0x94, 0xA4, 0xB4, 0xC4, 0x75, 0x85, 0x95, 0xA5, 0xC5, 0x76, 0x86, 0x96,
1136
+    0xE6, 0xF6, 0x67, 0x77, 0x87, 0xD7, 0xE7, 0xF7, 0x58, 0x68, 0x78, 0x88,
1137
+    0xD8, 0xE8, 0xF8, 0x09, 0x49, 0x59, 0x69, 0xD9, 0xE9, 0xF9, 0x0A, 0x3A,
1138
+    0x4A, 0x5A, 0xDA, 0xEA, 0x0B, 0x2B, 0x3B, 0x4B, 0xDB, 0x0C, 0x4C, 0x5C,
1139
+    0x6C, 0xDC, 0x7D, 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0x6E, 0x7E, 0x8E, 0x9E,
1140
+    0xAE, 0xBE, 0x5F, 0x6F, 0x7F, 0x8F, 0x9F, 0xAF, 0xB5, 0xA6, 0xB6, 0xC6,
1141
+    0x97, 0xA7, 0xC7, 0x98, 0xA8, 0xB8, 0xC8, 0x79, 0x89, 0x99, 0xA9, 0xB9,
1142
+    0xC9, 0x6A, 0x7A, 0x8A, 0x9A, 0xAA, 0xCA, 0xFA, 0x5B, 0x6B, 0x7B, 0x8B,
1143
+    0xCB, 0xEB, 0xFB, 0x7C, 0x8C, 0x9C, 0xAC, 0xBC, 0xEC, 0xFC, 0xDD, 0xED,
1144
+    0xFD, 0xCE, 0xDE, 0xEE, 0xFE, 0xBF, 0xCF, 0xDF, 0xB7, 0xBA, 0x9B, 0xAB,
1145
+    0xBB, 0xCC, 0xEF, 0xFF
1146
+};
1147
+
1148
+static const uint8_t huff_b01_cb[14] = {
1149
+    1, 12, 1, 0, 0, 2, 6, 0, 11, 13, 12, 24, 4, 8
1150
+};
1151
+
1152
+static const uint8_t huff_b01_xlat[81] = {
1153
+    0x00, 0x01, 0x03, 0x40, 0xC0, 0x10, 0x30, 0x04, 0x0C, 0x50, 0xD0, 0x70,
1154
+    0xF0, 0x34, 0x1C, 0x05, 0x0D, 0x13, 0x07, 0x0F, 0x44, 0xC4, 0x14, 0x4C,
1155
+    0xCC, 0x3C, 0x41, 0xC1, 0x11, 0x31, 0x43, 0xC3, 0x33, 0x54, 0x74, 0xDC,
1156
+    0xFC, 0x71, 0x15, 0x4D, 0x1D, 0xD3, 0xC7, 0x37, 0x3F, 0xD4, 0xF4, 0x5C,
1157
+    0x7C, 0x51, 0xD1, 0xF1, 0x45, 0xC5, 0x55, 0x35, 0xCD, 0xDD, 0x3D, 0x53,
1158
+    0x73, 0xF3, 0x47, 0x17, 0x77, 0x4F, 0xCF, 0x1F, 0xFF, 0xF5, 0x7D, 0xD7,
1159
+    0x5F, 0xD5, 0x75, 0x5D, 0xFD, 0x57, 0xF7, 0xDF, 0x7F
1160
+};
1161
+
1162
+static const uint8_t huff_b02_cb[14] = {
1163
+    1, 12, 1, 0, 0, 4, 0, 8, 4, 9, 19, 13, 13, 10
1164
+};
1165
+
1166
+static const uint8_t huff_b02_xlat[81] = {
1167
+    0x00, 0x40, 0x10, 0x04, 0x01, 0x50, 0x44, 0x14, 0x54, 0x41, 0x11, 0x05,
1168
+    0x15, 0x80, 0x51, 0x45, 0x55, 0x90, 0x20, 0x60, 0x24, 0x08, 0x18, 0x09,
1169
+    0x02, 0x06, 0x84, 0x94, 0x64, 0x48, 0x58, 0x81, 0x91, 0x21, 0x61, 0x95,
1170
+    0x25, 0x65, 0x19, 0x59, 0x42, 0x12, 0x46, 0x16, 0x56, 0xA0, 0xA4, 0x28,
1171
+    0x68, 0x85, 0xA5, 0x49, 0x29, 0x69, 0x52, 0x0A, 0x1A, 0x5A, 0x88, 0x98,
1172
+    0xA1, 0x89, 0x99, 0xA9, 0x22, 0x62, 0x96, 0x26, 0x66, 0x4A, 0x6A, 0xA8,
1173
+    0x82, 0x92, 0xA2, 0x86, 0xA6, 0x8A, 0x9A, 0x2A, 0xAA
1174
+};
1175
+
1176
+static const uint8_t huff_b03_cb[11] = { 1, 9, 1, 0, 0, 4, 0, 5, 12, 13, 14 };
1177
+
1178
+static const uint8_t huff_b03_xlat[49] = {
1179
+    0x00, 0x08, 0x38, 0x01, 0x07, 0x30, 0x09, 0x39, 0x0F, 0x3F, 0x10, 0x18,
1180
+    0x28, 0x31, 0x02, 0x3A, 0x03, 0x05, 0x06, 0x0E, 0x17, 0x37, 0x11, 0x19,
1181
+    0x29, 0x0A, 0x32, 0x0B, 0x3B, 0x0D, 0x15, 0x3D, 0x3E, 0x1F, 0x2F, 0x12,
1182
+    0x1A, 0x2A, 0x13, 0x1B, 0x2B, 0x33, 0x1D, 0x2D, 0x35, 0x16, 0x1E, 0x2E,
1183
+    0x36
1184
+};
1185
+
1186
+static const uint8_t huff_b04_cb[12] = {
1187
+    2, 11, 1, 0, 4, 4, 5, 9, 30, 45, 21, 2
1188
+};
1189
+
1190
+static const uint8_t huff_b04_xlat[121] = {
1191
+    0x00, 0x10, 0xF0, 0x01, 0x0F, 0x11, 0xF1, 0x1F, 0xFF, 0x20, 0xE0, 0x02,
1192
+    0xF2, 0x0E, 0x21, 0xE1, 0x12, 0xE2, 0x1E, 0x2E, 0xFE, 0x2F, 0xEF, 0x30,
1193
+    0x50, 0xB0, 0xC0, 0xD0, 0x31, 0xB1, 0xD1, 0x22, 0xD2, 0x03, 0x13, 0xE3,
1194
+    0xF3, 0xF4, 0x05, 0xE5, 0xF5, 0x0B, 0x1B, 0x0C, 0x0D, 0x1D, 0x2D, 0xFD,
1195
+    0x3E, 0xEE, 0x3F, 0x5F, 0xDF, 0x40, 0x41, 0x51, 0xC1, 0x32, 0x42, 0x52,
1196
+    0xB2, 0xC2, 0x23, 0x33, 0xB3, 0xC3, 0xD3, 0x04, 0x14, 0x24, 0xD4, 0xE4,
1197
+    0x15, 0x25, 0xC5, 0xD5, 0x2B, 0x3B, 0xEB, 0xFB, 0x1C, 0x2C, 0x3C, 0x5C,
1198
+    0xEC, 0xFC, 0x3D, 0x5D, 0xDD, 0xED, 0x4E, 0x5E, 0xBE, 0xCE, 0xDE, 0x4F,
1199
+    0xBF, 0xCF, 0x43, 0x53, 0x34, 0x54, 0xB4, 0xC4, 0x35, 0x45, 0x55, 0xB5,
1200
+    0x4B, 0x5B, 0xCB, 0xDB, 0x4C, 0xBC, 0xCC, 0xDC, 0x4D, 0xBD, 0xCD, 0x44,
1201
+    0xBB
1202
+};
1203
+
1204
+static const uint8_t huff_b05_cb[11] = {
1205
+    3, 11, 1, 4, 4, 4, 12, 30, 73, 75, 22
1206
+};
1207
+
1208
+static const uint8_t huff_b05_xlat[225] = {
1209
+    0x00, 0x10, 0xF0, 0x01, 0x0F, 0x11, 0xF1, 0x1F, 0xFF, 0x20, 0xE0, 0x02,
1210
+    0x0E, 0x30, 0xD0, 0x21, 0xE1, 0x12, 0xF2, 0x03, 0x0D, 0x1E, 0xFE, 0x2F,
1211
+    0xEF, 0x40, 0x60, 0x70, 0x90, 0xA0, 0xC0, 0x31, 0xD1, 0x22, 0x32, 0xD2,
1212
+    0xE2, 0x13, 0x23, 0xE3, 0xF3, 0x04, 0x06, 0x07, 0x09, 0x0A, 0x0C, 0x1D,
1213
+    0x2D, 0xFD, 0x2E, 0x3E, 0xEE, 0x3F, 0xDF, 0x50, 0xB0, 0x41, 0x51, 0x61,
1214
+    0x71, 0x91, 0xA1, 0xB1, 0xC1, 0x42, 0x62, 0x72, 0x92, 0xA2, 0xC2, 0x33,
1215
+    0x93, 0xA3, 0xD3, 0x14, 0x24, 0xE4, 0xF4, 0x05, 0x15, 0xF5, 0x16, 0x26,
1216
+    0xD6, 0xE6, 0xF6, 0x17, 0x27, 0xD7, 0xE7, 0xF7, 0x19, 0x29, 0x39, 0xE9,
1217
+    0xF9, 0x1A, 0x2A, 0xEA, 0xFA, 0x0B, 0x1B, 0xFB, 0x1C, 0x2C, 0xEC, 0xFC,
1218
+    0x3D, 0x7D, 0x9D, 0xDD, 0xED, 0x4E, 0x6E, 0x7E, 0x9E, 0xAE, 0xCE, 0xDE,
1219
+    0x4F, 0x5F, 0x6F, 0x7F, 0x9F, 0xAF, 0xBF, 0xCF, 0x52, 0xB2, 0x43, 0x53,
1220
+    0x63, 0x73, 0xB3, 0xC3, 0x34, 0x44, 0x64, 0x74, 0x94, 0xA4, 0xB4, 0xC4,
1221
+    0xD4, 0x25, 0x35, 0x65, 0x75, 0x95, 0xA5, 0xD5, 0xE5, 0x36, 0x46, 0x56,
1222
+    0x66, 0xA6, 0xB6, 0xC6, 0x37, 0x47, 0x57, 0xB7, 0xC7, 0x49, 0x59, 0x69,
1223
+    0xB9, 0xC9, 0xD9, 0x3A, 0x4A, 0x5A, 0x6A, 0xAA, 0xBA, 0xCA, 0xDA, 0x2B,
1224
+    0x3B, 0x6B, 0x7B, 0x9B, 0xAB, 0xDB, 0xEB, 0x3C, 0x4C, 0x6C, 0x7C, 0x9C,
1225
+    0xAC, 0xCC, 0xDC, 0x4D, 0x5D, 0x6D, 0xAD, 0xBD, 0xCD, 0x5E, 0xBE, 0x54,
1226
+    0x45, 0x55, 0xB5, 0xC5, 0x76, 0x96, 0x67, 0x77, 0x97, 0xA7, 0x79, 0x99,
1227
+    0xA9, 0x7A, 0x9A, 0x4B, 0x5B, 0xBB, 0xCB, 0x5C, 0xBC
1228
+};
1229
+
1230
+static const uint8_t huff_b07_cb[9] = { 3, 9, 3, 2, 4, 8, 23, 13, 10 };
1231
+
1232
+static const uint8_t huff_b07_xlat[63] = {
1233
+     0,  1, 63,  2, 62,  3,  4, 60, 61,  5,  6,  7,  8, 56, 57, 58,
1234
+    59,  9, 10, 11, 12, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36,
1235
+    37, 38, 39, 51, 52, 53, 54, 55, 13, 14, 15, 16, 17, 18, 19, 45,
1236
+    46, 47, 48, 49, 50, 20, 21, 22, 23, 24, 40, 41, 42, 43, 44
1237
+};
1238
+
1239
+static const uint8_t huff_b12_cb[10] = { 3, 10, 1, 3, 12, 0, 30, 9, 18, 8 };
1240
+
1241
+static const uint8_t huff_b12_xlat[81] = {
1242
+    0x00, 0x40, 0x04, 0x01, 0x10, 0x50, 0x44, 0x14, 0x54, 0x41, 0x11, 0x51,
1243
+    0x05, 0x45, 0x15, 0x55, 0x80, 0x90, 0x20, 0x60, 0x84, 0x94, 0x24, 0x64,
1244
+    0x08, 0x48, 0x18, 0x81, 0x91, 0x61, 0x85, 0x95, 0x25, 0x65, 0x09, 0x49,
1245
+    0x19, 0x59, 0x02, 0x42, 0x12, 0x52, 0x06, 0x46, 0x16, 0x56, 0xA4, 0x58,
1246
+    0x68, 0x21, 0xA5, 0x29, 0x69, 0x1A, 0x5A, 0xA0, 0x88, 0x98, 0x28, 0xA1,
1247
+    0x89, 0x99, 0xA9, 0x92, 0x22, 0x62, 0x86, 0x96, 0x26, 0x66, 0x0A, 0x4A,
1248
+    0x6A, 0xA8, 0x82, 0xA2, 0xA6, 0x8A, 0x9A, 0x2A, 0xAA
1249
+};
1250
+
1251
+static const uint8_t huff_b14_cb[14] = {
1252
+    1, 12, 1, 0, 0, 4, 0, 3, 5, 16, 28, 34, 26, 4
1253
+};
1254
+
1255
+static const uint8_t huff_b14_xlat[121] = {
1256
+    0x00, 0x10, 0xF0, 0x01, 0x0F, 0xF1, 0x1F, 0xFF, 0x20, 0xE0, 0x11, 0x02,
1257
+    0x0E, 0x30, 0x50, 0xB0, 0xD0, 0x21, 0xE1, 0x12, 0xF2, 0x03, 0x05, 0x0B,
1258
+    0x0D, 0x1E, 0xFE, 0x2F, 0xEF, 0x40, 0xC0, 0x31, 0x51, 0xB1, 0xC1, 0xD1,
1259
+    0x22, 0x52, 0xE2, 0x13, 0xF3, 0x04, 0x15, 0xF5, 0x1B, 0xEB, 0xFB, 0x0C,
1260
+    0x1D, 0xFD, 0x2E, 0x5E, 0xEE, 0x3F, 0x5F, 0xBF, 0xDF, 0x41, 0x32, 0x42,
1261
+    0xB2, 0xD2, 0x23, 0x53, 0xB3, 0xE3, 0x14, 0x24, 0xE4, 0xF4, 0x25, 0x35,
1262
+    0xD5, 0xE5, 0x2B, 0x3B, 0xDB, 0x1C, 0x2C, 0xBC, 0xEC, 0xFC, 0x2D, 0xBD,
1263
+    0xED, 0x3E, 0x4E, 0xBE, 0xDE, 0x4F, 0xCF, 0xC2, 0x33, 0x43, 0xC3, 0xD3,
1264
+    0x34, 0x44, 0x54, 0xB4, 0xD4, 0x45, 0x55, 0xC5, 0x4B, 0xCB, 0x3C, 0x4C,
1265
+    0x5C, 0xCC, 0xDC, 0x3D, 0x4D, 0x5D, 0xCD, 0xDD, 0xCE, 0xC4, 0xB5, 0x5B,
1266
+    0xBB
1267
+};
1268
+
1269
+static const uint8_t huff_b16_cb[11] = {
1270
+    4, 12, 4, 4, 9, 13, 37, 76, 72, 39, 2
1271
+};
1272
+
1273
+static const uint8_t huff_b16_xlat[256] = {
1274
+    0x00, 0x10, 0x01, 0x11, 0x20, 0x21, 0x02, 0x12, 0x30, 0x31, 0x41, 0x22,
1275
+    0x32, 0x03, 0x13, 0x23, 0x14, 0x40, 0x51, 0x61, 0x42, 0x52, 0x33, 0x43,
1276
+    0x04, 0x24, 0x34, 0x15, 0x25, 0x16, 0x50, 0x60, 0x70, 0x71, 0x81, 0xD1,
1277
+    0xE1, 0x62, 0x72, 0x82, 0xD2, 0x53, 0x63, 0x73, 0xD3, 0x44, 0x54, 0x05,
1278
+    0x35, 0x45, 0x55, 0x06, 0x26, 0x36, 0x07, 0x17, 0x27, 0x37, 0x18, 0x28,
1279
+    0x19, 0x1D, 0x2D, 0x3D, 0x1E, 0x2E, 0x1F, 0x80, 0x90, 0xD0, 0xE0, 0xF0,
1280
+    0x91, 0xA1, 0xB1, 0xC1, 0xF1, 0x92, 0xA2, 0xB2, 0xC2, 0xE2, 0xF2, 0x83,
1281
+    0x93, 0xA3, 0xC3, 0xE3, 0xF3, 0x64, 0x74, 0x84, 0x94, 0xD4, 0xE4, 0xF4,
1282
+    0x65, 0x75, 0x85, 0xD5, 0xE5, 0x46, 0x56, 0x66, 0x76, 0xD6, 0xE6, 0x47,
1283
+    0x57, 0x67, 0xD7, 0x08, 0x38, 0x48, 0x58, 0x09, 0x29, 0x39, 0x49, 0x0A,
1284
+    0x1A, 0x2A, 0x3A, 0x1B, 0x2B, 0x0C, 0x1C, 0x2C, 0x3C, 0x0D, 0x4D, 0x5D,
1285
+    0x6D, 0x7D, 0x0E, 0x3E, 0x4E, 0x5E, 0x6E, 0x0F, 0x2F, 0x3F, 0x4F, 0xA0,
1286
+    0xB0, 0xC0, 0xB3, 0xA4, 0xB4, 0xC4, 0x95, 0xA5, 0xB5, 0xC5, 0xF5, 0x86,
1287
+    0x96, 0xA6, 0xB6, 0xC6, 0xF6, 0x77, 0x87, 0x97, 0xA7, 0xC7, 0xE7, 0xF7,
1288
+    0x68, 0x78, 0x88, 0x98, 0xD8, 0xE8, 0xF8, 0x59, 0x69, 0x79, 0x89, 0xD9,
1289
+    0xE9, 0xF9, 0x4A, 0x5A, 0x6A, 0x7A, 0xDA, 0xEA, 0x0B, 0x3B, 0x4B, 0x5B,
1290
+    0xDB, 0xEB, 0x4C, 0x5C, 0x6C, 0x7C, 0x8C, 0xDC, 0x8D, 0x9D, 0xAD, 0xBD,
1291
+    0xCD, 0x7E, 0x8E, 0x9E, 0xAE, 0xBE, 0x5F, 0x6F, 0x7F, 0x8F, 0x9F, 0xB7,
1292
+    0xA8, 0xB8, 0xC8, 0x99, 0xA9, 0xB9, 0xC9, 0x8A, 0x9A, 0xAA, 0xBA, 0xCA,
1293
+    0xFA, 0x6B, 0x7B, 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xFB, 0x9C, 0xAC, 0xBC,
1294
+    0xCC, 0xEC, 0xFC, 0xDD, 0xED, 0xFD, 0xCE, 0xDE, 0xEE, 0xFE, 0xAF, 0xBF,
1295
+    0xCF, 0xDF, 0xEF, 0xFF
1296
+};
1297
+
1298
+static const uint8_t huff_b26_cb[12] = {
1299
+    3, 12, 2, 2, 4, 5, 11, 26, 67, 78, 51, 10
1300
+};
1301
+
1302
+static const uint8_t huff_b26_xlat[256] = {
1303
+    0x00, 0x01, 0x10, 0x11, 0x20, 0x21, 0x02, 0x12, 0x30, 0x31, 0x22, 0x03,
1304
+    0x13, 0x40, 0x41, 0x51, 0x32, 0x42, 0x23, 0x33, 0x04, 0x14, 0x24, 0x15,
1305
+    0x50, 0x61, 0x71, 0xD1, 0xE1, 0x52, 0x62, 0xD2, 0x43, 0x53, 0xD3, 0x34,
1306
+    0x44, 0x05, 0x25, 0x35, 0x06, 0x16, 0x26, 0x17, 0x18, 0x1D, 0x2D, 0x3D,
1307
+    0x1E, 0x2E, 0x60, 0x70, 0x80, 0xD0, 0xE0, 0xF0, 0x81, 0x91, 0xA1, 0xC1,
1308
+    0xF1, 0x72, 0x82, 0x92, 0xC2, 0xE2, 0xF2, 0x63, 0x73, 0xE3, 0xF3, 0x54,
1309
+    0x64, 0x74, 0xD4, 0xE4, 0xF4, 0x45, 0x55, 0x65, 0xD5, 0xE5, 0xF5, 0x36,
1310
+    0x46, 0x56, 0xD6, 0xE6, 0x07, 0x27, 0x37, 0x47, 0xD7, 0x08, 0x28, 0x38,
1311
+    0x19, 0x29, 0x1A, 0x1B, 0x1C, 0x2C, 0x0D, 0x4D, 0x5D, 0x6D, 0x7D, 0x0E,
1312
+    0x3E, 0x4E, 0x5E, 0x6E, 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x90, 0xA0, 0xC0,
1313
+    0xB1, 0xA2, 0xB2, 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0x84, 0x94, 0xA4, 0xC4,
1314
+    0x75, 0x85, 0x95, 0xC5, 0x66, 0x76, 0x86, 0x96, 0xC6, 0xF6, 0x57, 0x67,
1315
+    0x77, 0xE7, 0xF7, 0x48, 0x58, 0x68, 0x78, 0xD8, 0xE8, 0xF8, 0x09, 0x39,
1316
+    0x49, 0x59, 0xD9, 0xE9, 0xF9, 0x0A, 0x2A, 0x3A, 0x4A, 0xDA, 0xEA, 0x0B,
1317
+    0x2B, 0x3B, 0xDB, 0xEB, 0x0C, 0x3C, 0x4C, 0x5C, 0x6C, 0xDC, 0x8D, 0x9D,
1318
+    0xAD, 0xBD, 0xCD, 0x7E, 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0x5F, 0x6F, 0x7F,
1319
+    0x8F, 0x9F, 0xAF, 0xB0, 0xB4, 0xA5, 0xB5, 0xA6, 0xB6, 0x87, 0x97, 0xA7,
1320
+    0xB7, 0xC7, 0x88, 0x98, 0xA8, 0xC8, 0x69, 0x79, 0x89, 0x99, 0xA9, 0xC9,
1321
+    0x5A, 0x6A, 0x7A, 0x9A, 0xCA, 0xFA, 0x4B, 0x5B, 0x6B, 0x7B, 0xCB, 0xFB,
1322
+    0x7C, 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xEC, 0xFC, 0xDD, 0xED, 0xFD, 0xDE,
1323
+    0xEE, 0xFE, 0xBF, 0xCF, 0xDF, 0xEF, 0xB8, 0xB9, 0x8A, 0xAA, 0xBA, 0x8B,
1324
+    0x9B, 0xAB, 0xBB, 0xFF
1325
+};
1326
+
1327
+static const uint8_t huff_b32_cb[12] = {
1328
+    2, 11, 1, 0, 4, 6, 7, 10, 22, 11, 16, 4
1329
+};
1330
+
1331
+static const uint8_t huff_b32_xlat[81] = {
1332
+    0x00, 0x40, 0x10, 0x04, 0x01, 0x50, 0x44, 0x14, 0x41, 0x11, 0x05, 0x80,
1333
+    0x54, 0x51, 0x45, 0x15, 0x55, 0x02, 0x90, 0x20, 0x60, 0x84, 0x24, 0x08,
1334
+    0x18, 0x09, 0x12, 0x06, 0xA0, 0x94, 0x64, 0x48, 0x58, 0x81, 0x91, 0x21,
1335
+    0x61, 0x85, 0x95, 0x25, 0x65, 0x49, 0x19, 0x59, 0x42, 0x52, 0x46, 0x16,
1336
+    0x56, 0x0A, 0xA4, 0x28, 0x68, 0xA1, 0xA5, 0x29, 0x69, 0x26, 0x4A, 0x1A,
1337
+    0x5A, 0x88, 0x98, 0xA8, 0x89, 0x99, 0xA9, 0x82, 0x92, 0x22, 0x62, 0x86,
1338
+    0x96, 0x66, 0x9A, 0x2A, 0x6A, 0xA2, 0xA6, 0x8A, 0xAA
1339
+};
1340
+
1341
+static const uint8_t huff_b33_cb[13] = {
1342
+    2, 12, 1, 0, 0, 4, 11, 8, 28, 92, 97, 13, 2
1343
+};
1344
+
1345
+static const uint8_t huff_b33_xlat[256] = {
1346
+    0x00, 0x40, 0x10, 0x04, 0x01, 0x50, 0x44, 0x14, 0x54, 0x41, 0x11, 0x51,
1347
+    0x05, 0x45, 0x15, 0x55, 0x20, 0x95, 0x65, 0x49, 0x59, 0x52, 0x46, 0x16,
1348
+    0x80, 0x90, 0x60, 0x84, 0x94, 0x24, 0x64, 0xA4, 0x08, 0x48, 0x18, 0x58,
1349
+    0x81, 0x91, 0x21, 0x61, 0x85, 0x25, 0x09, 0x19, 0x69, 0x02, 0x42, 0x12,
1350
+    0x06, 0x56, 0x5A, 0x57, 0xD0, 0x74, 0x68, 0x5C, 0xC1, 0xD5, 0xA5, 0xE5,
1351
+    0x75, 0xB5, 0xF5, 0x99, 0xD9, 0xA9, 0xE9, 0x79, 0xB9, 0xF9, 0x1D, 0x5D,
1352
+    0x9D, 0xDD, 0x6D, 0xAD, 0xED, 0x7D, 0xBD, 0xFD, 0x82, 0x92, 0xD2, 0x62,
1353
+    0x96, 0xD6, 0x26, 0x66, 0xA6, 0xE6, 0x76, 0xB6, 0xF6, 0x0A, 0x4A, 0x1A,
1354
+    0x9A, 0xDA, 0x2A, 0x6A, 0xAA, 0xEA, 0x7A, 0xBA, 0xFA, 0x5E, 0x9E, 0xDE,
1355
+    0x6E, 0xAE, 0xEE, 0x7E, 0xBE, 0xFE, 0x03, 0x13, 0x53, 0x17, 0x97, 0xD7,
1356
+    0x67, 0xA7, 0xE7, 0x77, 0xB7, 0xF7, 0x5B, 0x9B, 0xDB, 0x6B, 0xAB, 0xEB,
1357
+    0x7B, 0xBB, 0xFB, 0x5F, 0x9F, 0xDF, 0x6F, 0xAF, 0xEF, 0x7F, 0xBF, 0xFF,
1358
+    0xC0, 0xA0, 0xE0, 0x30, 0xC4, 0xD4, 0xE4, 0x34, 0xB4, 0xF4, 0x88, 0xC8,
1359
+    0x98, 0xD8, 0x28, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8, 0x0C, 0x4C, 0x1C,
1360
+    0x9C, 0xDC, 0x6C, 0xAC, 0xEC, 0x7C, 0xBC, 0xFC, 0xD1, 0xA1, 0xE1, 0x31,
1361
+    0x71, 0xB1, 0xF1, 0xC5, 0x35, 0x89, 0xC9, 0x29, 0x39, 0x0D, 0x4D, 0x8D,
1362
+    0xCD, 0x2D, 0x3D, 0x22, 0xA2, 0xE2, 0x72, 0xB2, 0xF2, 0x86, 0xC6, 0x36,
1363
+    0x8A, 0xCA, 0x3A, 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x2E, 0x3E, 0x43, 0x83,
1364
+    0x93, 0xD3, 0x23, 0x63, 0xA3, 0xE3, 0x73, 0xB3, 0xF3, 0x07, 0x47, 0x87,
1365
+    0xC7, 0x27, 0x37, 0x4B, 0x8B, 0xCB, 0x1B, 0x2B, 0x3B, 0x4F, 0x8F, 0xCF,
1366
+    0x1F, 0x70, 0xB0, 0xF0, 0x8C, 0xCC, 0x2C, 0x3C, 0xC2, 0x32, 0xC3, 0x0F,
1367
+    0x2F, 0x3F, 0x33, 0x0B
1368
+};
1369
+
1370
+static const uint8_t huff_b35_cb[14] = {
1371
+    1, 12, 1, 0, 0, 0, 4, 6, 6, 14, 42, 63, 59, 30
1372
+};
1373
+
1374
+static const uint8_t huff_b35_xlat[225] = {
1375
+    0x00, 0x10, 0xF0, 0x01, 0x0F, 0x11, 0xF1, 0x02, 0x0E, 0x1F, 0xFF, 0x20,
1376
+    0xE0, 0x21, 0xF2, 0xFE, 0xEF, 0x30, 0xD0, 0xE1, 0x12, 0x22, 0xE2, 0x03,
1377
+    0x0D, 0x1D, 0x1E, 0x2E, 0xEE, 0x2F, 0xDF, 0x40, 0x60, 0x70, 0x90, 0xA0,
1378
+    0xB0, 0xC0, 0x31, 0x71, 0x91, 0xC1, 0xD1, 0x32, 0xD2, 0x13, 0xE3, 0xF3,
1379
+    0x04, 0x05, 0x06, 0x07, 0x17, 0xF7, 0x09, 0x19, 0x0A, 0x1A, 0xFA, 0x0C,
1380
+    0x1C, 0x2D, 0xED, 0xFD, 0x3E, 0x7E, 0xDE, 0x3F, 0x6F, 0x7F, 0x9F, 0xAF,
1381
+    0xCF, 0x50, 0x41, 0x51, 0x61, 0xA1, 0xB1, 0x62, 0x72, 0x92, 0xA2, 0xC2,
1382
+    0x23, 0x33, 0x63, 0x73, 0x93, 0xA3, 0xD3, 0x14, 0x24, 0x34, 0xD4, 0xE4,
1383
+    0xF4, 0x15, 0xF5, 0x16, 0x26, 0xD6, 0xE6, 0xF6, 0x27, 0x37, 0x47, 0xE7,
1384
+    0x29, 0x39, 0xC9, 0xD9, 0xE9, 0xF9, 0x2A, 0xEA, 0x0B, 0x1B, 0xFB, 0x2C,
1385
+    0x7C, 0xEC, 0xFC, 0x3D, 0x4D, 0x6D, 0x7D, 0xDD, 0x4E, 0x5E, 0x6E, 0x9E,
1386
+    0xAE, 0xCE, 0x4F, 0x5F, 0x42, 0x52, 0xB2, 0x43, 0xB3, 0xC3, 0x44, 0x64,
1387
+    0x74, 0x94, 0xA4, 0x25, 0x35, 0x65, 0x75, 0x95, 0xA5, 0xE5, 0x36, 0x46,
1388
+    0x66, 0x76, 0x96, 0xA6, 0xB6, 0xC6, 0x57, 0xA7, 0xB7, 0xC7, 0xD7, 0x59,
1389
+    0xA9, 0xB9, 0x3A, 0x4A, 0x6A, 0xCA, 0xDA, 0x2B, 0x3B, 0x6B, 0x9B, 0xAB,
1390
+    0xDB, 0xEB, 0x3C, 0x6C, 0x9C, 0xAC, 0xCC, 0xDC, 0x5D, 0x9D, 0xAD, 0xBD,
1391
+    0xCD, 0xBE, 0xBF, 0x53, 0x54, 0xB4, 0xC4, 0x45, 0x55, 0xB5, 0xC5, 0xD5,
1392
+    0x56, 0x67, 0x77, 0x97, 0x49, 0x69, 0x79, 0x99, 0x5A, 0x7A, 0x9A, 0xAA,
1393
+    0xBA, 0x4B, 0x5B, 0x7B, 0xBB, 0xCB, 0x4C, 0x5C, 0xBC
1394
+};
1395
+
1396
+static const uint8_t huff_b37_cb[13] = {
1397
+    1, 11, 1, 0, 2, 0, 2, 2, 6, 17, 14, 13, 6
1398
+};
1399
+
1400
+static const uint8_t huff_b37_xlat[63] = {
1401
+     0,  1, 63,  2, 62,  3, 61,  4,  5,  6, 58, 59, 60,  7,  8,  9,
1402
+    10, 25, 26, 27, 28, 29, 34, 35, 37, 38, 39, 55, 56, 57, 11, 13,
1403
+    14, 15, 30, 31, 33, 36, 49, 50, 51, 52, 53, 54, 12, 16, 17, 18,
1404
+    19, 21, 41, 43, 44, 45, 46, 47, 48, 20, 22, 23, 24, 40, 42
1405
+};
1406
+
1407
+static const uint8_t huff_b41_cb[14] = {
1408
+    1, 12, 1, 0, 0, 1, 7, 0, 20, 4, 10, 24, 2, 12
1409
+};
1410
+
1411
+static const uint8_t huff_b41_xlat[81] = {
1412
+    0x00, 0x01, 0x40, 0xC0, 0x10, 0x30, 0x04, 0x0C, 0x03, 0x50, 0xD0, 0x70,
1413
+    0xF0, 0xC4, 0x14, 0x34, 0x4C, 0x1C, 0x3C, 0xC1, 0x11, 0x31, 0x05, 0x0D,
1414
+    0xC3, 0x13, 0x33, 0x07, 0x0F, 0x44, 0xCC, 0x41, 0x43, 0x54, 0x74, 0xDC,
1415
+    0xFC, 0x71, 0x15, 0x4D, 0x1D, 0x37, 0x3F, 0xD4, 0xF4, 0x5C, 0x7C, 0x51,
1416
+    0xD1, 0xF1, 0x45, 0xC5, 0x35, 0xCD, 0xDD, 0x3D, 0x53, 0xD3, 0x73, 0xF3,
1417
+    0x47, 0xC7, 0x17, 0x77, 0x4F, 0xCF, 0x1F, 0x55, 0xFF, 0xD5, 0x75, 0xF5,
1418
+    0x5D, 0x7D, 0xFD, 0x57, 0xD7, 0xF7, 0x5F, 0xDF, 0x7F
1419
+};
1420
+
1421
+static const uint8_t huff_b42_cb[11] = { 1, 9, 1, 0, 1, 3, 2, 3, 7, 4, 4 };
1422
+
1423
+static const uint8_t huff_b42_xlat[25] = {
1424
+    0x00, 0x07, 0x08, 0x38, 0x01, 0x39, 0x0F, 0x10, 0x09, 0x3F, 0x30, 0x31,
1425
+    0x02, 0x3A, 0x06, 0x0E, 0x17, 0x11, 0x0A, 0x3E, 0x37, 0x12, 0x32, 0x16,
1426
+    0x36
1427
+};
1428
+
1429
+static const uint8_t huff_b43_cb[10] = { 2, 9, 1, 1, 3, 4, 9, 15, 12, 4 };
1430
+
1431
+static const uint8_t huff_b43_xlat[49] = {
1432
+    0x00, 0x07, 0x08, 0x38, 0x01, 0x09, 0x39, 0x0F, 0x3F, 0x10, 0x30, 0x31,
1433
+    0x02, 0x3A, 0x06, 0x0E, 0x17, 0x37, 0x18, 0x28, 0x11, 0x19, 0x29, 0x0A,
1434
+    0x03, 0x0B, 0x3B, 0x05, 0x0D, 0x3D, 0x3E, 0x1F, 0x2F, 0x12, 0x1A, 0x2A,
1435
+    0x32, 0x13, 0x33, 0x15, 0x35, 0x16, 0x1E, 0x2E, 0x36, 0x1B, 0x2B, 0x1D,
1436
+    0x2D
1437
+};
1438
+
1439
+static const uint8_t huff_b47_cb[10] = { 2, 9, 1, 1, 3, 4, 6, 14, 22, 12 };
1440
+
1441
+static const uint8_t huff_b47_xlat[63] = {
1442
+     0,  1,  2, 62, 63,  3,  4, 60, 61,  5,  6,  7, 57, 58, 59,  8,
1443
+     9, 10, 11, 12, 26, 27, 37, 38, 52, 53, 54, 55, 56, 13, 14, 15,
1444
+    16, 17, 18, 25, 28, 29, 30, 31, 33, 34, 35, 36, 39, 46, 47, 48,
1445
+    49, 50, 51, 19, 20, 21, 22, 23, 24, 40, 41, 42, 43, 44, 45
1446
+};
1447
+
1448
+static const uint8_t huff_b52_cb[11] = { 1, 9, 1, 0, 1, 3, 2, 3, 7, 4, 4 };
1449
+
1450
+static const uint8_t huff_b52_xlat[25] = {
1451
+    0x00, 0x01, 0x08, 0x38, 0x07, 0x39, 0x0F, 0x30, 0x09, 0x3F, 0x10, 0x31,
1452
+    0x02, 0x3A, 0x06, 0x0E, 0x17, 0x11, 0x0A, 0x3E, 0x37, 0x12, 0x32, 0x16,
1453
+    0x36
1454
+};
1455
+
1456
+static const uint8_t huff_b53_cb[7] = { 1, 5, 1, 1, 1, 0, 4 }; // same as b63!!!
1457
+
1458
+static const uint8_t huff_b53_xlat[7] = { 0, 7, 1, 2, 3, 5, 6 };
1459
+
1460
+static const uint8_t huff_b56_cb[11] = { 1, 9, 1, 0, 2, 0, 2, 4, 11, 9, 2 };
1461
+
1462
+static const uint8_t huff_b56_xlat[31] = {
1463
+     0,  1, 31,  2, 30, 3,  4, 13, 29,  5,  6,  7, 14, 15, 17, 18,
1464
+    19, 26, 27, 28,  8, 9, 12, 20, 21, 22, 23, 24, 25, 10, 11
1465
+};
1466
+
1467
+static const uint8_t huff_b62_cb[14] = {
1468
+    1, 12, 1, 0, 0, 2, 3, 5, 12, 14, 18, 15, 9, 2
1469
+};
1470
+
1471
+static const uint8_t huff_b62_xlat[81] = {
1472
+    0x00, 0x40, 0x01, 0x10, 0x04, 0x02, 0x80, 0x50, 0x90, 0x05, 0x06, 0x20,
1473
+    0x60, 0x44, 0x14, 0x54, 0x24, 0x08, 0x18, 0x41, 0x11, 0x15, 0x09, 0xA0,
1474
+    0x84, 0x94, 0x64, 0xA4, 0x28, 0x51, 0x45, 0x55, 0x19, 0x12, 0x16, 0x0A,
1475
+    0x1A, 0x48, 0x58, 0x68, 0x81, 0x91, 0x21, 0x61, 0x85, 0x95, 0x25, 0x65,
1476
+    0x49, 0x59, 0x29, 0x69, 0x42, 0x46, 0x56, 0x88, 0x98, 0xA8, 0xA1, 0xA5,
1477
+    0x99, 0xA9, 0x52, 0x22, 0x26, 0x66, 0x4A, 0x5A, 0x2A, 0x6A, 0x89, 0x82,
1478
+    0x92, 0x62, 0x86, 0x96, 0xA6, 0x8A, 0xAA, 0xA2, 0x9A
1479
+};
1480
+
1481
+static const uint8_t huff_b63_cb[7] = { 1, 5, 1, 1, 1, 0, 4 };
1482
+
1483
+static const uint8_t huff_b63_xlat[7] = { 0, 1, 7, 2, 3, 5, 6 };
1484
+
1485
+static const uint8_t huff_b64_cb[7] = { 1, 5, 1, 1, 1, 1, 2 };
1486
+
1487
+static const uint8_t huff_b64_xlat[6] = { 1, 0, 2, 5, 3, 4 };
1488
+
1489
+static const uint8_t huff_b65_cb[14] = {
1490
+    1, 12, 1, 0, 0, 2, 2, 2, 6, 12, 34, 92, 54, 20
1491
+};
1492
+
1493
+static const uint8_t huff_b65_xlat[225] = {
1494
+    0x00, 0xF0, 0x01, 0x10, 0x0F, 0x11, 0xF1, 0x20, 0xE0, 0x02, 0x0E, 0x1F,
1495
+    0xFF, 0xD0, 0x21, 0xE1, 0x12, 0xF2, 0x07, 0x0A, 0x0D, 0x1E, 0xFE, 0x2F,
1496
+    0xEF, 0x30, 0x70, 0x90, 0xA0, 0xC0, 0x71, 0x91, 0xC1, 0xD1, 0x32, 0x92,
1497
+    0xE2, 0x03, 0x13, 0x63, 0x04, 0x06, 0xE6, 0xE7, 0xF7, 0x09, 0x19, 0x39,
1498
+    0xFA, 0x0C, 0x1C, 0xDD, 0xED, 0xFD, 0x2E, 0x7E, 0x9E, 0x3F, 0x9F, 0x40,
1499
+    0x50, 0x60, 0xB0, 0x31, 0x41, 0x61, 0xA1, 0xB1, 0x22, 0x42, 0x72, 0xA2,
1500
+    0xB2, 0xC2, 0xD2, 0x23, 0x33, 0x73, 0xA3, 0xC3, 0xD3, 0xE3, 0xF3, 0x14,
1501
+    0x24, 0x34, 0x44, 0x74, 0xD4, 0xE4, 0x05, 0x25, 0x45, 0x65, 0x95, 0xA5,
1502
+    0x16, 0x26, 0x46, 0x76, 0xA6, 0xB6, 0xC6, 0xD6, 0xF6, 0x17, 0x27, 0x37,
1503
+    0x47, 0x67, 0xA7, 0xD7, 0x29, 0x69, 0xB9, 0xD9, 0xE9, 0xF9, 0x1A, 0x2A,
1504
+    0x3A, 0x9A, 0xCA, 0xDA, 0xEA, 0x0B, 0x1B, 0x3B, 0x6B, 0xEB, 0xFB, 0x2C,
1505
+    0x6C, 0xEC, 0xFC, 0x1D, 0x2D, 0x4D, 0x6D, 0x9D, 0xAD, 0x3E, 0x4E, 0x6E,
1506
+    0xAE, 0xCE, 0xEE, 0x4F, 0x5F, 0x6F, 0xDF, 0x51, 0x52, 0x62, 0x43, 0x93,
1507
+    0xB3, 0x54, 0x94, 0xA4, 0xF4, 0x15, 0x75, 0xB5, 0xE5, 0xF5, 0x36, 0x56,
1508
+    0x66, 0x96, 0x57, 0x77, 0x49, 0x59, 0xA9, 0xC9, 0x4A, 0x5A, 0x6A, 0x7A,
1509
+    0xAA, 0xBA, 0x2B, 0x4B, 0x7B, 0x9B, 0xAB, 0xDB, 0x3C, 0x4C, 0x7C, 0x9C,
1510
+    0xAC, 0xBC, 0xCC, 0x3D, 0x5D, 0x7D, 0xBD, 0xCD, 0x5E, 0xBE, 0xDE, 0xBF,
1511
+    0xCF, 0x53, 0x64, 0xB4, 0xC4, 0x35, 0x55, 0xC5, 0xD5, 0x97, 0xB7, 0xC7,
1512
+    0x79, 0x99, 0x5B, 0xBB, 0xCB, 0x5C, 0xDC, 0x7F, 0xAF
1513
+};
1514
+
1515
+static const uint8_t huff_b66_cb[14] = {
1516
+    1, 12, 1, 0, 0, 3, 0, 3, 3, 10, 40, 85, 61, 50
1517
+};
1518
+
1519
+static const uint8_t huff_b66_xlat[256] = {
1520
+    0x00, 0x10, 0x01, 0x11, 0x21, 0x02, 0x12, 0x20, 0x22, 0x13, 0x30, 0x31,
1521
+    0x41, 0xD1, 0xE1, 0x32, 0x52, 0x03, 0x23, 0x2D, 0x40, 0x50, 0x60, 0x80,
1522
+    0xD0, 0xE0, 0x51, 0x61, 0xF1, 0x42, 0x62, 0xD2, 0xE2, 0xF2, 0x33, 0x43,
1523
+    0xC3, 0xD3, 0xE3, 0x04, 0x14, 0xD4, 0xF4, 0x25, 0x35, 0x16, 0x17, 0xF7,
1524
+    0xD8, 0x1C, 0x3C, 0x0D, 0x1D, 0x3D, 0x5D, 0x0E, 0x1E, 0x2E, 0x7E, 0x2F,
1525
+    0xC0, 0xF0, 0x71, 0x81, 0x91, 0xC1, 0x72, 0x82, 0x92, 0xB2, 0xC2, 0x53,
1526
+    0x63, 0x73, 0x93, 0xA3, 0xF3, 0x24, 0x44, 0x64, 0x84, 0xA4, 0xB4, 0x05,
1527
+    0x15, 0x95, 0xD5, 0x06, 0x26, 0x36, 0x46, 0x96, 0xD6, 0xE6, 0xF6, 0x07,
1528
+    0x27, 0x37, 0xD7, 0xE7, 0x08, 0x18, 0x28, 0x38, 0xE8, 0xF8, 0x09, 0x19,
1529
+    0x29, 0xE9, 0xF9, 0x0A, 0x1A, 0xCA, 0xDA, 0xEA, 0x0B, 0x1B, 0xDB, 0xEB,
1530
+    0xFB, 0x2C, 0x4C, 0x5C, 0x7C, 0x8C, 0x4D, 0x6D, 0x8D, 0x9D, 0xFD, 0x3E,
1531
+    0x5E, 0x6E, 0x8E, 0x9E, 0xEE, 0x0F, 0x1F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
1532
+    0xCF, 0x70, 0xA1, 0xA2, 0x83, 0xB3, 0x34, 0x74, 0xC4, 0xE4, 0x55, 0x65,
1533
+    0x85, 0xA5, 0xC5, 0xE5, 0xF5, 0x56, 0x66, 0x76, 0x86, 0xA6, 0xC6, 0x57,
1534
+    0x67, 0x77, 0x97, 0xA7, 0x48, 0x88, 0x98, 0x49, 0x59, 0x79, 0x99, 0x3A,
1535
+    0x4A, 0x8A, 0xBA, 0xFA, 0x2B, 0x7B, 0x0C, 0xAC, 0xBC, 0xCC, 0xEC, 0x7D,
1536
+    0xAD, 0xBD, 0xDD, 0x4E, 0xBE, 0xCE, 0xFE, 0x8F, 0x9F, 0xAF, 0xBF, 0xDF,
1537
+    0xEF, 0xFF, 0x90, 0xA0, 0xB0, 0xB1, 0x54, 0x94, 0x45, 0x75, 0xB5, 0xB6,
1538
+    0x47, 0x87, 0xB7, 0xC7, 0x58, 0x68, 0x78, 0xA8, 0xB8, 0xC8, 0x39, 0x69,
1539
+    0x89, 0xA9, 0xB9, 0xC9, 0xD9, 0x2A, 0x5A, 0x6A, 0x7A, 0x9A, 0xAA, 0x3B,
1540
+    0x4B, 0x5B, 0x6B, 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0x6C, 0x9C, 0xDC, 0xFC,
1541
+    0xCD, 0xED, 0xAE, 0xDE
1542
+};
1543
+
1544
+static const uint8_t huff_b67_cb[10] = { 2, 9, 1, 2, 1, 4, 7, 10, 26, 12 };
1545
+
1546
+static const uint8_t huff_b67_xlat[63] = {
1547
+     0,  1, 63, 62,  2,  3, 60, 61,  4,  5,  6,  7, 57, 58, 59,  8,
1548
+     9, 10, 11, 12, 52, 53, 54, 55, 56, 13, 14, 15, 16, 17, 18, 25,
1549
+    26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 46, 47, 48,
1550
+    49, 50, 51, 19, 20, 21, 22, 23, 24, 40, 41, 42, 43, 44, 45
1551
+};
1552
+
1553
+static const uint8_t huff_b71_cb[14] = {
1554
+    1, 12, 1, 0, 0, 1, 7, 0, 19, 5, 13, 23, 0, 12
1555
+};
1556
+
1557
+static const uint8_t huff_b71_xlat[81] = {
1558
+    0x00, 0x03, 0x40, 0xC0, 0x10, 0x30, 0x04, 0x0C, 0x01, 0x50, 0xD0, 0x70,
1559
+    0xF0, 0xC4, 0x14, 0x34, 0x4C, 0x1C, 0x3C, 0xC1, 0x11, 0x31, 0x05, 0x0D,
1560
+    0x13, 0x33, 0x07, 0x0F, 0x44, 0xCC, 0x41, 0x43, 0xC3, 0x54, 0x74, 0xDC,
1561
+    0xFC, 0xF1, 0xC5, 0x15, 0x1D, 0x53, 0xC7, 0x37, 0x4F, 0x3F, 0xD4, 0xF4,
1562
+    0x5C, 0x7C, 0x51, 0xD1, 0x71, 0x45, 0x55, 0x35, 0x4D, 0xCD, 0xDD, 0x3D,
1563
+    0xD3, 0x73, 0xF3, 0x47, 0x17, 0x77, 0xCF, 0x1F, 0xFF, 0xD5, 0x75, 0xF5,
1564
+    0x5D, 0x7D, 0xFD, 0x57, 0xD7, 0xF7, 0x5F, 0xDF, 0x7F
1565
+};
1566
+
1567
+static const uint8_t huff_b73_cb[13] = {
1568
+    1, 11, 1, 0, 0, 0, 1, 4, 9, 4, 103, 110, 24
1569
+};
1570
+
1571
+static const uint8_t huff_b73_xlat[256] = {
1572
+    0x00, 0x40, 0x10, 0x04, 0x01, 0x05, 0x50, 0x14, 0x54, 0x41, 0x11, 0x51,
1573
+    0x45, 0x15, 0x55, 0x44, 0x95, 0x6A, 0x03, 0x80, 0xC0, 0x90, 0xD0, 0x94,
1574
+    0xD4, 0x24, 0x64, 0x58, 0x91, 0xA1, 0x85, 0xD5, 0x25, 0x65, 0xA5, 0xE5,
1575
+    0x75, 0xB5, 0xF5, 0x19, 0x59, 0x99, 0xD9, 0x69, 0xA9, 0xE9, 0x79, 0xB9,
1576
+    0xF9, 0x4D, 0x5D, 0x9D, 0xDD, 0x6D, 0xAD, 0xED, 0x7D, 0xBD, 0xFD, 0x02,
1577
+    0x42, 0x52, 0x06, 0x46, 0x16, 0x56, 0x96, 0xD6, 0x26, 0x66, 0xA6, 0xE6,
1578
+    0x76, 0xB6, 0xF6, 0x1A, 0x5A, 0x9A, 0xDA, 0xAA, 0xEA, 0x7A, 0xBA, 0xFA,
1579
+    0x5E, 0x9E, 0xDE, 0x6E, 0xAE, 0xEE, 0x7E, 0xBE, 0xFE, 0x07, 0x47, 0x57,
1580
+    0x97, 0xD7, 0x67, 0xA7, 0xE7, 0x77, 0xB7, 0xF7, 0x5B, 0x9B, 0xDB, 0x6B,
1581
+    0xAB, 0xEB, 0x7B, 0xBB, 0xFB, 0x5F, 0x9F, 0xDF, 0x6F, 0xAF, 0xEF, 0x7F,
1582
+    0xBF, 0xFF, 0x20, 0x60, 0x70, 0xB0, 0xF0, 0x84, 0xC4, 0xA4, 0xE4, 0x74,
1583
+    0xB4, 0xF4, 0x08, 0x88, 0x18, 0x98, 0xD8, 0x68, 0xA8, 0xE8, 0x78, 0xB8,
1584
+    0xF8, 0x1C, 0x5C, 0x9C, 0xDC, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
1585
+    0x81, 0xD1, 0x21, 0x61, 0xE1, 0x71, 0xB1, 0xF1, 0xC5, 0x35, 0x09, 0x49,
1586
+    0x89, 0xC9, 0x29, 0x39, 0x0D, 0x8D, 0xCD, 0x1D, 0x2D, 0x3D, 0x92, 0xD2,
1587
+    0x22, 0x62, 0xA2, 0xE2, 0x72, 0xB2, 0xF2, 0x86, 0xC6, 0x36, 0x0A, 0x4A,
1588
+    0x8A, 0xCA, 0x2A, 0x3A, 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x2E, 0x3E, 0x13,
1589
+    0x53, 0x93, 0xD3, 0x63, 0xA3, 0xE3, 0x73, 0xB3, 0xF3, 0x87, 0xC7, 0x17,
1590
+    0x27, 0x37, 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x2B, 0x3B, 0x0F, 0x4F, 0x8F,
1591
+    0xCF, 0x1F, 0x2F, 0x3F, 0xA0, 0xE0, 0x30, 0x34, 0x48, 0xC8, 0x28, 0x38,
1592
+    0x0C, 0x4C, 0x8C, 0xCC, 0x2C, 0xC1, 0x31, 0x82, 0xC2, 0x12, 0x32, 0x43,
1593
+    0x83, 0xC3, 0x23, 0x33
1594
+};
1595
+
1596
+static const uint8_t huff_b74_cb[8] = { 1, 6, 1, 0, 2, 2, 2, 4 };
1597
+
1598
+static const uint8_t huff_b74_xlat[11] = {
1599
+    0, 1, 15, 2, 14, 5, 13, 3, 4, 11, 12
1600
+};
1601
+
1602
+static const uint8_t huff_b75_cb[13] = {
1603
+    2, 12, 1, 4, 0, 0, 0, 8, 11, 24, 53, 64, 60
1604
+};
1605
+
1606
+static const uint8_t huff_b75_xlat[225] = {
1607
+    0x00, 0x10, 0xF0, 0x01, 0x0F, 0x20, 0xE0, 0x11, 0xF1, 0x02, 0x0E, 0x1F,
1608
+    0xFF, 0xD0, 0x21, 0xE1, 0x12, 0xF2, 0x03, 0x0D, 0x1E, 0xFE, 0x2F, 0xEF,
1609
+    0x30, 0x40, 0x60, 0x70, 0x90, 0xA0, 0xC0, 0x31, 0xD1, 0x22, 0xE2, 0x13,
1610
+    0xF3, 0x04, 0x06, 0x07, 0x09, 0x0C, 0x1D, 0xFD, 0x2E, 0xEE, 0x3F, 0xDF,
1611
+    0x50, 0xB0, 0x41, 0x61, 0x71, 0x91, 0xA1, 0xC1, 0x32, 0x62, 0x72, 0x92,
1612
+    0xA2, 0xD2, 0x23, 0xD3, 0xE3, 0x14, 0xF4, 0x05, 0x16, 0x26, 0xE6, 0xF6,
1613
+    0x17, 0x27, 0xE7, 0xF7, 0x19, 0x29, 0xF9, 0x0A, 0x1A, 0x2A, 0xFA, 0x0B,
1614
+    0x1C, 0x2C, 0xFC, 0x2D, 0x3D, 0xED, 0x3E, 0x4E, 0x7E, 0x9E, 0xDE, 0x4F,
1615
+    0x6F, 0x7F, 0x9F, 0xAF, 0xCF, 0x51, 0xB1, 0x42, 0x52, 0xB2, 0xC2, 0x33,
1616
+    0x63, 0x73, 0x93, 0xA3, 0xB3, 0xC3, 0x24, 0x34, 0x74, 0xA4, 0xD4, 0xE4,
1617
+    0x15, 0x25, 0x65, 0x95, 0xE5, 0xF5, 0x36, 0xD6, 0x37, 0x47, 0xC7, 0xD7,
1618
+    0x39, 0x59, 0xB9, 0xC9, 0xD9, 0xE9, 0x3A, 0x6A, 0xDA, 0xEA, 0x1B, 0x2B,
1619
+    0x9B, 0xAB, 0xEB, 0xFB, 0x6C, 0x7C, 0x9C, 0xAC, 0xEC, 0x4D, 0x6D, 0x7D,
1620
+    0x9D, 0xAD, 0xBD, 0xDD, 0x5E, 0x6E, 0xAE, 0xCE, 0x5F, 0x43, 0x53, 0x44,
1621
+    0x54, 0x64, 0x94, 0xB4, 0xC4, 0x35, 0x45, 0x55, 0x75, 0xA5, 0xB5, 0xC5,
1622
+    0xD5, 0x46, 0x56, 0x66, 0x76, 0x96, 0xA6, 0xB6, 0xC6, 0x57, 0x67, 0x77,
1623
+    0x97, 0xA7, 0xB7, 0x49, 0x69, 0x79, 0x99, 0xA9, 0x4A, 0x5A, 0x7A, 0x9A,
1624
+    0xAA, 0xBA, 0xCA, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B, 0xBB, 0xCB, 0xDB, 0x3C,
1625
+    0x4C, 0x5C, 0xBC, 0xCC, 0xDC, 0x5D, 0xCD, 0xBE, 0xBF
1626
+};
1627
+
1628
+static const uint8_t huff_b77_cb[12] = {
1629
+    2, 11, 1, 0, 4, 6, 10, 12, 7, 15, 4, 4
1630
+};
1631
+
1632
+static const uint8_t huff_b77_xlat[63] = {
1633
+     0,  1,  2, 62, 63,  3,  4,  5, 59, 60, 61,  6,  7,  8,  9, 10,
1634
+    54, 55, 56, 57, 58, 11, 12, 13, 14, 15, 16, 47, 49, 50, 51, 52,
1635
+    53, 17, 18, 19, 20, 45, 46, 48, 21, 22, 23, 24, 25, 26, 27, 37,
1636
+    38, 39, 40, 41, 42, 43, 44, 28, 29, 30, 35, 31, 33, 34, 36
1637
+};
1638
+
1639
+/** Tables for spectrum coding. */
1640
+typedef struct Atrac3pSpecCodeTab {
1641
+    uint8_t group_size;  ///< number of coefficients grouped together
1642
+    uint8_t num_coeffs;  ///< 1 - map index to a single value, > 1 - map index to a vector of values
1643
+    uint8_t bits;        ///< number of bits a single coefficient occupy
1644
+    uint8_t is_signed;   ///< 1 - values in that table are signed ones, otherwise - absolute ones
1645
+
1646
+    int redirect;        ///< if >= 0: tells which huffman table must be reused
1647
+    const uint8_t *cb;   ///< pointer to the codebook descriptor
1648
+    const uint8_t *xlat; ///< pointer to the translation table or NULL if none
1649
+} Atrac3pSpecCodeTab;
1650
+
1651
+static const Atrac3pSpecCodeTab atrac3p_spectra_tabs[112] = {
1652
+    /* table set = A */
1653
+    /* code table = 0 */
1654
+    { 1, 4, 2, 1, -1, huff_a01_cb, huff_a01_xlat }, // wordlen = 1
1655
+    { 1, 4, 2, 0, -1, huff_a02_cb, huff_a02_xlat }, // wordlen = 2
1656
+    { 1, 2, 3, 1, -1, huff_a03_cb, huff_a03_xlat }, // wordlen = 3
1657
+    { 1, 1, 3, 0, -1, huff_a04_cb, huff_a04_xlat }, // wordlen = 4
1658
+    { 1, 2, 4, 1, -1, huff_a05_cb, huff_a05_xlat }, // wordlen = 5
1659
+    { 1, 1, 4, 0, -1, huff_a06_cb, huff_a06_xlat }, // wordlen = 6
1660
+    { 1, 1, 6, 1, -1, huff_a07_cb, huff_a07_xlat }, // wordlen = 7
1661
+
1662
+    /* code table = 1 */
1663
+    { 4, 4, 2, 1, -1, huff_a11_cb, huff_a11_xlat }, // wordlen = 1
1664
+    { 1, 4, 2, 0, -1, huff_a12_cb, huff_a12_xlat }, // wordlen = 2
1665
+    { 1, 2, 3, 1, -1, huff_a13_cb, huff_a13_xlat }, // wordlen = 3
1666
+    { 1, 2, 4, 1, -1, huff_a14_cb, huff_a14_xlat }, // wordlen = 4
1667
+    { 1, 2, 4, 1, -1, huff_a15_cb, huff_a15_xlat }, // wordlen = 5
1668
+    { 1, 2, 4, 0, -1, huff_a16_cb, huff_a16_xlat }, // wordlen = 6
1669
+    { 1, 1, 6, 1, -1, huff_a17_cb, huff_a17_xlat }, // wordlen = 7
1670
+
1671
+    /* code table = 2 */
1672
+    { 1, 4, 2, 1, -1, huff_a21_cb, huff_a21_xlat }, // wordlen = 1
1673
+    { 1, 2, 3, 1, -1, huff_a22_cb, huff_a22_xlat }, // wordlen = 2
1674
+    { 1, 2, 3, 1, -1, huff_a23_cb, huff_a23_xlat }, // wordlen = 3
1675
+    { 1, 1, 3, 0, -1, huff_a24_cb, NULL          }, // wordlen = 4
1676
+    { 1, 1, 3, 0, -1, huff_a25_cb, huff_a25_xlat }, // wordlen = 5
1677
+    { 1, 2, 4, 0, -1, huff_a26_cb, huff_a26_xlat }, // wordlen = 6
1678
+    { 1, 1, 6, 1, -1, huff_a27_cb, huff_a27_xlat }, // wordlen = 7
1679
+
1680
+    /* code table = 3 */
1681
+    { 1, 2, 2, 1, -1, huff_a31_cb, huff_a31_xlat }, // wordlen = 1
1682
+    { 1, 4, 2, 0, -1, huff_a32_cb, huff_a32_xlat }, // wordlen = 2
1683
+    { 1, 4, 2, 0, -1, huff_a33_cb, huff_a33_xlat }, // wordlen = 3
1684
+    { 1, 1, 3, 0, -1, huff_a34_cb, huff_a34_xlat }, // wordlen = 4
1685
+    { 1, 2, 4, 1, -1, huff_a35_cb, huff_a35_xlat }, // wordlen = 5
1686
+    { 1, 2, 4, 0, -1, huff_a36_cb, huff_a36_xlat }, // wordlen = 6
1687
+    { 1, 1, 6, 1, -1, huff_a37_cb, huff_a37_xlat }, // wordlen = 7
1688
+
1689
+    /* code table = 4 */
1690
+    { 1, 4, 2, 1, -1, huff_a41_cb, huff_a41_xlat }, // wordlen = 1
1691
+    { 1, 4, 2, 0, -1, huff_a42_cb, huff_a42_xlat }, // wordlen = 2
1692
+    { 1, 1, 3, 1, -1, huff_a43_cb, huff_a43_xlat }, // wordlen = 3
1693
+    { 1, 2, 4, 1, -1, huff_a44_cb, huff_a44_xlat }, // wordlen = 4
1694
+    { 1, 1, 3, 0, -1, huff_a45_cb, huff_a45_xlat }, // wordlen = 5
1695
+    { 1, 2, 4, 0, -1, huff_a46_cb, huff_a46_xlat }, // wordlen = 6
1696
+    { 1, 1, 6, 1, -1, huff_a47_cb, huff_a47_xlat }, // wordlen = 7
1697
+
1698
+    /* code table = 5 */
1699
+    { 1, 4, 2, 1, -1, huff_a51_cb, huff_a51_xlat }, // wordlen = 1
1700
+    { 1, 2, 3, 1, -1, huff_a52_cb, huff_a52_xlat }, // wordlen = 2
1701
+    { 1, 1, 3, 1, -1, huff_a43_cb, huff_a53_xlat }, // wordlen = 3
1702
+    { 1, 2, 4, 1, -1, huff_a54_cb, huff_a54_xlat }, // wordlen = 4
1703
+    { 1, 1, 3, 0, -1, huff_a55_cb, huff_a55_xlat }, // wordlen = 5
1704
+    { 1, 1, 5, 1, -1, huff_a56_cb, huff_a56_xlat }, // wordlen = 6
1705
+    { 1, 1, 6, 1, -1, huff_a57_cb, huff_a57_xlat }, // wordlen = 7
1706
+
1707
+    /* code table = 6 */
1708
+    { 2, 4, 2, 1, -1, huff_a61_cb, huff_a61_xlat }, // wordlen = 1
1709
+    { 1, 2, 3, 1, -1, huff_a62_cb, huff_a62_xlat }, // wordlen = 2
1710
+    { 1, 4, 2, 0, -1, huff_a63_cb, huff_a63_xlat }, // wordlen = 3
1711
+    { 1, 2, 4, 1, -1, huff_a64_cb, huff_a64_xlat }, // wordlen = 4
1712
+    { 1, 1, 4, 1, -1, huff_a65_cb, huff_a65_xlat }, // wordlen = 5
1713
+    { 1, 1, 5, 1, -1, huff_a66_cb, huff_a66_xlat }, // wordlen = 6
1714
+    { 1, 1, 6, 1, -1, huff_a67_cb, huff_a67_xlat }, // wordlen = 7
1715
+
1716
+    /* code table = 7 */
1717
+    { 1, 2, 1, 0, -1, huff_a71_cb, NULL          }, // wordlen = 1
1718
+    { 2, 4, 2, 0, -1, huff_a72_cb, huff_a72_xlat }, // wordlen = 2
1719
+    { 1, 2, 3, 1, -1, huff_a73_cb, huff_a73_xlat }, // wordlen = 3
1720
+    { 1, 2, 4, 1, -1, huff_a74_cb, huff_a74_xlat }, // wordlen = 4
1721
+    { 1, 1, 4, 1, -1, huff_a75_cb, huff_a75_xlat }, // wordlen = 5
1722
+    { 2, 2, 4, 0, -1, huff_a76_cb, huff_a76_xlat }, // wordlen = 6
1723
+    { 4, 1, 6, 1,  6, NULL,        NULL          }, // wordlen = 7
1724
+
1725
+    /* table set = B */
1726
+    /* code table = 0 */
1727
+    { 4, 4, 2, 1, -1, huff_b01_cb, huff_b01_xlat }, // wordlen = 1
1728
+    { 1, 4, 2, 0, -1, huff_b02_cb, huff_b02_xlat }, // wordlen = 2
1729
+    { 4, 2, 3, 1, -1, huff_b03_cb, huff_b03_xlat }, // wordlen = 3
1730
+    { 1, 2, 4, 1, -1, huff_b04_cb, huff_b04_xlat }, // wordlen = 4
1731
+    { 1, 2, 4, 1, -1, huff_b05_cb, huff_b05_xlat }, // wordlen = 5
1732
+    { 1, 1, 4, 0,  5, NULL,        NULL          }, // wordlen = 6
1733
+    { 1, 1, 6, 1, -1, huff_b07_cb, huff_b07_xlat }, // wordlen = 7
1734
+
1735
+    /* code table = 1 */
1736
+    { 1, 4, 2, 1, 14, NULL,        NULL          }, // wordlen = 1
1737
+    { 1, 4, 2, 0, -1, huff_b12_cb, huff_b12_xlat }, // wordlen = 2
1738
+    { 1, 2, 3, 1,  9, NULL,        NULL          }, // wordlen = 3
1739
+    { 1, 2, 4, 1, -1, huff_b14_cb, huff_b14_xlat }, // wordlen = 4
1740
+    { 1, 2, 4, 1, 11, NULL,        NULL          }, // wordlen = 5
1741
+    { 1, 2, 4, 0, -1, huff_b16_cb, huff_b16_xlat }, // wordlen = 6
1742
+    { 1, 1, 6, 1,  6, NULL,        NULL          }, // wordlen = 7
1743
+
1744
+    /* code table = 2 */
1745
+    { 4, 4, 2, 1, 28, NULL,        NULL          }, // wordlen = 1
1746
+    { 4, 4, 2, 0, 22, NULL,        NULL          }, // wordlen = 2
1747
+    { 1, 2, 3, 1,  2, NULL,        NULL          }, // wordlen = 3
1748
+    { 1, 2, 4, 1, 31, NULL,        NULL          }, // wordlen = 4
1749
+    { 2, 2, 4, 1, 60, NULL,        NULL          }, // wordlen = 5
1750
+    { 2, 2, 4, 0, -1, huff_b26_cb, huff_b26_xlat }, // wordlen = 6
1751
+    { 4, 1, 6, 1,  6, NULL,        NULL          }, // wordlen = 7
1752
+
1753
+    /* code table = 3 */
1754
+    { 1, 4, 2, 1, 35, NULL,        NULL          }, // wordlen = 1
1755
+    { 1, 4, 2, 0, -1, huff_b32_cb, huff_b32_xlat }, // wordlen = 2
1756
+    { 1, 4, 2, 0, -1, huff_b33_cb, huff_b33_xlat }, // wordlen = 3
1757
+    { 2, 2, 4, 1, 59, NULL,        NULL          }, // wordlen = 4
1758
+    { 1, 2, 4, 1, -1, huff_b35_cb, huff_b35_xlat }, // wordlen = 5
1759
+    { 1, 2, 4, 0, 75, NULL,        NULL          }, // wordlen = 6
1760
+    { 1, 1, 6, 1, -1, huff_b37_cb, huff_b37_xlat }, // wordlen = 7
1761
+
1762
+    /* code table = 4 */
1763
+    { 1, 4, 2, 1, -1, huff_b41_cb, huff_b41_xlat }, // wordlen = 1
1764
+    { 4, 2, 3, 1, -1, huff_b42_cb, huff_b42_xlat }, // wordlen = 2
1765
+    { 1, 2, 3, 1, -1, huff_b43_cb, huff_b43_xlat }, // wordlen = 3
1766
+    { 4, 2, 4, 1, 66, NULL,        NULL          }, // wordlen = 4
1767
+    { 1, 1, 3, 0, 32, NULL,        NULL          }, // wordlen = 5
1768
+    { 1, 2, 4, 0, 12, NULL,        NULL          }, // wordlen = 6
1769
+    { 1, 1, 6, 1, -1, huff_b47_cb, huff_b47_xlat }, // wordlen = 7
1770
+
1771
+    /* code table = 5 */
1772
+    { 2, 4, 2, 1, 42, NULL,        NULL          }, // wordlen = 1
1773
+    { 1, 2, 3, 1, -1, huff_b52_cb, huff_b52_xlat }, // wordlen = 2
1774
+    { 4, 1, 3, 1, -1, huff_b53_cb, huff_b53_xlat }, // wordlen = 3
1775
+    { 1, 1, 3, 0, 17, NULL,        NULL          }, // wordlen = 4
1776
+    { 1, 1, 3, 0, 39, NULL,        NULL          }, // wordlen = 5
1777
+    { 1, 1, 5, 1, -1, huff_b56_cb, huff_b56_xlat }, // wordlen = 6
1778
+    { 2, 1, 6, 1, 62, NULL,        NULL          }, // wordlen = 7
1779
+
1780
+    /* code table = 6 */
1781
+    { 1, 4, 2, 1, 28, NULL,        NULL          }, // wordlen = 1
1782
+    { 1, 4, 2, 0, -1, huff_b62_cb, huff_b62_xlat }, // wordlen = 2
1783
+    { 1, 1, 3, 1, -1, huff_b63_cb, huff_b63_xlat }, // wordlen = 3
1784
+    { 1, 1, 3, 0, -1, huff_b64_cb, huff_b64_xlat }, // wordlen = 4
1785
+    { 4, 2, 4, 1, -1, huff_b65_cb, huff_b65_xlat }, // wordlen = 5
1786
+    { 1, 2, 4, 0, -1, huff_b66_cb, huff_b66_xlat }, // wordlen = 6
1787
+    { 1, 1, 6, 1, -1, huff_b67_cb, huff_b67_xlat }, // wordlen = 7
1788
+
1789
+    /* code table = 7 */
1790
+    { 1, 4, 2, 1, -1, huff_b71_cb, huff_b71_xlat }, // wordlen = 1
1791
+    { 4, 4, 2, 0, 78, NULL,        NULL          }, // wordlen = 2
1792
+    { 4, 4, 2, 0, -1, huff_b73_cb, huff_b73_xlat }, // wordlen = 3
1793
+    { 1, 1, 4, 1, -1, huff_b74_cb, huff_b74_xlat }, // wordlen = 4
1794
+    { 1, 2, 4, 1, -1, huff_b75_cb, huff_b75_xlat }, // wordlen = 5
1795
+    { 1, 1, 5, 1, 47, NULL,        NULL          }, // wordlen = 6
1796
+    { 1, 1, 6, 1, -1, huff_b77_cb, huff_b77_xlat }, // wordlen = 7
1797
+};
1798
+
1799
+/* Huffman tables for gain control data. */
1800
+static const uint8_t atrac3p_huff_gain_npoints1_cb[9] = {
1801
+    1, 7, 1, 1, 1, 1, 1, 1, 2
1802
+};
1803
+
1804
+static const uint8_t atrac3p_huff_gain_npoints2_xlat[8] = {
1805
+    0, 1, 7, 2, 6, 3, 4, 5
1806
+};
1807
+
1808
+static const uint8_t atrac3p_huff_gain_lev1_cb[9] = { 1, 7, 1, 0, 2, 2, 1, 2, 8 };
1809
+static const uint8_t atrac3p_huff_gain_lev1_xlat[16] = {
1810
+    7, 5, 8, 6, 9, 4, 10, 11, 0, 1, 2, 3, 12, 13, 14, 15
1811
+};
1812
+
1813
+static const uint8_t atrac3p_huff_gain_lev2_cb[11] = {
1814
+    1, 9, 1, 1, 1, 1, 1, 0, 2, 0, 8
1815
+};
1816
+
1817
+static const uint8_t atrac3p_huff_gain_lev2_xlat[15] = {
1818
+    15, 14, 1, 13, 2, 3, 12, 4, 5, 6, 7, 8, 9, 10, 11
1819
+};
1820
+
1821
+static const uint8_t atrac3p_huff_gain_lev3_cb[11] = {
1822
+    1, 9, 1, 0, 3, 1, 1, 0, 2, 0, 8
1823
+};
1824
+
1825
+static const uint8_t atrac3p_huff_gain_lev3_xlat[16] = {
1826
+    0, 1, 14, 15, 2, 13, 3, 12, 4, 5, 6, 7, 8, 9, 10, 11
1827
+};
1828
+
1829
+static const uint8_t atrac3p_huff_gain_lev4_cb[11] = {
1830
+    1, 9, 1, 1, 1, 1, 1, 0, 1, 2, 8
1831
+};
1832
+
1833
+static const uint8_t atrac3p_huff_gain_lev4_xlat[16] = {
1834
+    0, 1, 15, 14, 2, 13, 3, 12, 4, 5, 6, 7, 8, 9, 10, 11
1835
+};
1836
+
1837
+static const uint8_t atrac3p_huff_gain_loc1_cb[9] = { 2, 8, 1, 2, 4, 4, 4, 0, 16 };
1838
+static const uint8_t atrac3p_huff_gain_loc1_xlat[31] = {
1839
+     1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
1840
+    17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
1841
+};
1842
+
1843
+static const uint8_t atrac3p_huff_gain_loc2_cb[8] = { 3, 8, 5, 3, 2, 3, 2, 16 };
1844
+static const uint8_t atrac3p_huff_gain_loc2_xlat[31] = {
1845
+     2,  3,  4,  5,  6,  1,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
1846
+    17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
1847
+};
1848
+
1849
+static const uint8_t atrac3p_huff_gain_loc3_cb[7] = { 2, 6, 1, 0, 2, 11, 18 };
1850
+static const uint8_t atrac3p_huff_gain_loc3_xlat[32] = {
1851
+    0,   1, 31,  2,  3,  4,  5,  6,  7, 26, 27, 28, 29, 30,  8,  9,
1852
+    10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
1853
+};
1854
+
1855
+static const uint8_t atrac3p_huff_gain_loc4_cb[5] = { 4, 6, 3, 23, 6 };
1856
+static const uint8_t atrac3p_huff_gain_loc4_xlat[32] = {
1857
+    0,  28, 29,  1,  2,  3,  4, 11, 12, 13, 14, 15, 16, 17, 18, 19,
1858
+    20, 21, 22, 23, 24, 25, 26, 27, 30, 31,  5,  6,  7,  8,  9, 10
1859
+};
1860
+
1861
+static const uint8_t atrac3p_huff_gain_loc5_cb[9] = { 1, 7, 1, 0, 0, 3, 2, 6, 20 };
1862
+static const uint8_t atrac3p_huff_gain_loc5_xlat[32] = {
1863
+    0,   1,  2, 31,  3,  4,  5,  6,  7,  8, 29, 30,  9, 10, 11, 12,
1864
+    13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
1865
+};
1866
+
1867
+/* Huffman tables for GHA waves data. */
1868
+static const uint8_t atrac3p_huff_tonebands_cb[8] = { 1, 6, 1, 0, 1, 2, 4, 8 };
1869
+static const uint8_t atrac3p_huff_numwavs1_cb[9] = { 1, 7, 1, 1, 1, 1, 1, 1, 2 };
1870
+static const uint8_t atrac3p_huff_numwavs2_cb[8] = { 1, 6, 1, 1, 1, 1, 0, 4 };
1871
+static const uint8_t atrac3p_huff_numwavs2_xlat[8] = { 0, 1, 7, 2, 3, 4, 5, 6 };
1872
+static const uint8_t atrac3p_huff_wav_ampsf1_cb[7] = { 4, 8, 10, 8, 6, 0, 8 };
1873
+static const uint8_t atrac3p_huff_wav_ampsf1_xlat[32] = {
1874
+     8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 5, 6,  7, 18, 19, 20,
1875
+    21, 22,  4, 23, 24, 25, 26, 27,  0,  1, 2, 3, 28, 29, 30, 31
1876
+};
1877
+
1878
+static const uint8_t atrac3p_huff_wav_ampsf2_cb[7] = { 4, 8, 11, 5, 6, 6, 4 };
1879
+static const uint8_t atrac3p_huff_wav_ampsf2_xlat[32] = {
1880
+    18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 14, 15, 16, 17, 29,
1881
+     9, 10, 11, 12, 13, 30,  4,  5,  6,  7,  8, 31,  0,  1,  2,  3
1882
+};
1883
+
1884
+static const uint8_t atrac3p_huff_wav_ampsf3_cb[9] = { 2, 8, 1, 3, 3, 1, 4, 4, 16 };
1885
+static const uint8_t atrac3p_huff_wav_ampsf3_xlat[32] = {
1886
+    0, 1,  2, 31,  3, 29, 30,  4,  5,  6, 27, 28,  7, 24, 25, 26,
1887
+    8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
1888
+};
1889
+
1890
+static const uint8_t atrac3p_huff_freq_cb[13] = {
1891
+    1, 11, 1, 0, 0, 2, 2, 0, 9, 9, 29, 104, 100
1892
+};
1893
+
1894
+static const uint8_t atrac3p_huff_freq_xlat[256] = {
1895
+      0,   1, 255,   2, 254,   3,   4,   5,   6,   7,   8, 251, 252, 253,   9,  10,
1896
+     11,  12, 246, 247, 248, 249, 250,  13,  14,  15,  16,  17,  18,  19,  20,  21,
1897
+     22,  23,  24,  25,  26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,
1898
+     38, 243, 244, 245,  39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,
1899
+     51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,  65,  66,
1900
+     67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,  78,  79,  80,  81,  82,
1901
+     83,  84,  85,  86,  87,  88,  89,  90,  91,  92,  93, 194, 195, 196, 197, 198,
1902
+    199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214,
1903
+    215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230,
1904
+    231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242,  94,  95,  96,  97,
1905
+     98,  99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
1906
+    114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
1907
+    130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
1908
+    146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161,
1909
+    162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
1910
+    178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193
1911
+};
1912
+
1913
+#endif /* AVCODEC_ATRAC3PLUS_DATA_H */
0 1914
new file mode 100644
... ...
@@ -0,0 +1,383 @@
0
+/*
1
+ * ATRAC3+ compatible decoder
2
+ *
3
+ * Copyright (c) 2010-2013 Maxim Poliakovski
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * FFmpeg is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with FFmpeg; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+/**
23
+ * @file
24
+ * Sony ATRAC3+ compatible decoder.
25
+ *
26
+ * Container formats used to store its data:
27
+ * RIFF WAV (.at3) and Sony OpenMG (.oma, .aa3).
28
+ *
29
+ * Technical description of this codec can be found here:
30
+ * http://wiki.multimedia.cx/index.php?title=ATRAC3plus
31
+ *
32
+ * Kudos to Benjamin Larsson and Michael Karcher
33
+ * for their precious technical help!
34
+ */
35
+
36
+#include <stdint.h>
37
+#include <string.h>
38
+
39
+#include "libavutil/channel_layout.h"
40
+#include "libavutil/float_dsp.h"
41
+#include "avcodec.h"
42
+#include "get_bits.h"
43
+#include "internal.h"
44
+#include "atrac.h"
45
+#include "atrac3plus.h"
46
+
47
+typedef struct ATRAC3PContext {
48
+    GetBitContext gb;
49
+    AVFloatDSPContext fdsp;
50
+
51
+    DECLARE_ALIGNED(32, float, samples)[2][ATRAC3P_FRAME_SAMPLES];  ///< quantized MDCT spectrum
52
+    DECLARE_ALIGNED(32, float, mdct_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< output of the IMDCT
53
+    DECLARE_ALIGNED(32, float, time_buf)[2][ATRAC3P_FRAME_SAMPLES]; ///< output of the gain compensation
54
+    DECLARE_ALIGNED(32, float, outp_buf)[2][ATRAC3P_FRAME_SAMPLES];
55
+
56
+    AtracGCContext gainc_ctx;   ///< gain compensation context
57
+    FFTContext mdct_ctx;
58
+    FFTContext ipqf_dct_ctx;    ///< IDCT context used by IPQF
59
+
60
+    Atrac3pChanUnitCtx *ch_units;   ///< global channel units
61
+
62
+    int num_channel_blocks;     ///< number of channel blocks
63
+    uint8_t channel_blocks[5];  ///< channel configuration descriptor
64
+    uint64_t my_channel_layout; ///< current channel layout
65
+} ATRAC3PContext;
66
+
67
+static av_cold int atrac3p_decode_close(AVCodecContext *avctx)
68
+{
69
+    av_free(((ATRAC3PContext *)(avctx->priv_data))->ch_units);
70
+
71
+    return 0;
72
+}
73
+
74
+static av_cold int set_channel_params(ATRAC3PContext *ctx,
75
+                                      AVCodecContext *avctx)
76
+{
77
+    memset(ctx->channel_blocks, 0, sizeof(ctx->channel_blocks));
78
+
79
+    switch (avctx->channel_layout) {
80
+    case AV_CH_FRONT_LEFT:
81
+    case AV_CH_LAYOUT_MONO:
82
+        ctx->num_channel_blocks = 1;
83
+        ctx->channel_blocks[0]  = CH_UNIT_MONO;
84
+        break;
85
+    case AV_CH_LAYOUT_STEREO:
86
+        ctx->num_channel_blocks = 1;
87
+        ctx->channel_blocks[0]  = CH_UNIT_STEREO;
88
+        break;
89
+    case AV_CH_LAYOUT_SURROUND:
90
+        ctx->num_channel_blocks = 2;
91
+        ctx->channel_blocks[0]  = CH_UNIT_STEREO;
92
+        ctx->channel_blocks[1]  = CH_UNIT_MONO;
93
+        break;
94
+    case AV_CH_LAYOUT_4POINT0:
95
+        ctx->num_channel_blocks = 3;
96
+        ctx->channel_blocks[0]  = CH_UNIT_STEREO;
97
+        ctx->channel_blocks[1]  = CH_UNIT_MONO;
98
+        ctx->channel_blocks[2]  = CH_UNIT_MONO;
99
+        break;
100
+    case AV_CH_LAYOUT_5POINT1_BACK:
101
+        ctx->num_channel_blocks = 4;
102
+        ctx->channel_blocks[0]  = CH_UNIT_STEREO;
103
+        ctx->channel_blocks[1]  = CH_UNIT_MONO;
104
+        ctx->channel_blocks[2]  = CH_UNIT_STEREO;
105
+        ctx->channel_blocks[3]  = CH_UNIT_MONO;
106
+        break;
107
+    case AV_CH_LAYOUT_6POINT1_BACK:
108
+        ctx->num_channel_blocks = 5;
109
+        ctx->channel_blocks[0]  = CH_UNIT_STEREO;
110
+        ctx->channel_blocks[1]  = CH_UNIT_MONO;
111
+        ctx->channel_blocks[2]  = CH_UNIT_STEREO;
112
+        ctx->channel_blocks[3]  = CH_UNIT_MONO;
113
+        ctx->channel_blocks[4]  = CH_UNIT_MONO;
114
+        break;
115
+    case AV_CH_LAYOUT_7POINT1:
116
+        ctx->num_channel_blocks = 5;
117
+        ctx->channel_blocks[0]  = CH_UNIT_STEREO;
118
+        ctx->channel_blocks[1]  = CH_UNIT_MONO;
119
+        ctx->channel_blocks[2]  = CH_UNIT_STEREO;
120
+        ctx->channel_blocks[3]  = CH_UNIT_STEREO;
121
+        ctx->channel_blocks[4]  = CH_UNIT_MONO;
122
+        break;
123
+    default:
124
+        av_log(avctx, AV_LOG_ERROR,
125
+               "Unsupported channel layout: %"PRIx64"!\n", avctx->channel_layout);
126
+        return AVERROR_INVALIDDATA;
127
+    }
128
+
129
+    return 0;
130
+}
131
+
132
+static av_cold int atrac3p_decode_init(AVCodecContext *avctx)
133
+{
134
+    ATRAC3PContext *ctx = avctx->priv_data;
135
+    int i, ch, ret;
136
+
137
+    ff_atrac3p_init_vlcs();
138
+
139
+    avpriv_float_dsp_init(&ctx->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
140
+
141
+    /* initialize IPQF */
142
+    ff_mdct_init(&ctx->ipqf_dct_ctx, 5, 1, 32.0 / 32768.0);
143
+
144
+    ff_atrac3p_init_imdct(avctx, &ctx->mdct_ctx);
145
+
146
+    ff_atrac_init_gain_compensation(&ctx->gainc_ctx, 6, 2);
147
+
148
+    ff_atrac3p_init_wave_synth();
149
+
150
+    if ((ret = set_channel_params(ctx, avctx)) < 0)
151
+        return ret;
152
+
153
+    ctx->my_channel_layout = avctx->channel_layout;
154
+
155
+    ctx->ch_units = av_mallocz(sizeof(*ctx->ch_units) *
156
+                               ctx->num_channel_blocks);
157
+    if (!ctx->ch_units) {
158
+        atrac3p_decode_close(avctx);
159
+        return AVERROR(ENOMEM);
160
+    }
161
+
162
+    for (i = 0; i < ctx->num_channel_blocks; i++) {
163
+        for (ch = 0; ch < 2; ch++) {
164
+            ctx->ch_units[i].channels[ch].ch_num          = ch;
165
+            ctx->ch_units[i].channels[ch].wnd_shape       = &ctx->ch_units[i].channels[ch].wnd_shape_hist[0][0];
166
+            ctx->ch_units[i].channels[ch].wnd_shape_prev  = &ctx->ch_units[i].channels[ch].wnd_shape_hist[1][0];
167
+            ctx->ch_units[i].channels[ch].gain_data       = &ctx->ch_units[i].channels[ch].gain_data_hist[0][0];
168
+            ctx->ch_units[i].channels[ch].gain_data_prev  = &ctx->ch_units[i].channels[ch].gain_data_hist[1][0];
169
+            ctx->ch_units[i].channels[ch].tones_info      = &ctx->ch_units[i].channels[ch].tones_info_hist[0][0];
170
+            ctx->ch_units[i].channels[ch].tones_info_prev = &ctx->ch_units[i].channels[ch].tones_info_hist[1][0];
171
+        }
172
+
173
+        ctx->ch_units[i].waves_info      = &ctx->ch_units[i].wave_synth_hist[0];
174
+        ctx->ch_units[i].waves_info_prev = &ctx->ch_units[i].wave_synth_hist[1];
175
+    }
176
+
177
+    avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
178
+
179
+    return 0;
180
+}
181
+
182
+static void decode_residual_spectrum(Atrac3pChanUnitCtx *ctx,
183
+                                     float out[2][ATRAC3P_FRAME_SAMPLES],
184
+                                     int num_channels,
185
+                                     AVCodecContext *avctx)
186
+{
187
+    int i, sb, ch, qu, nspeclines, RNG_index;
188
+    float *dst, q;
189
+    int16_t *src;
190
+    /* calculate RNG table index for each subband */
191
+    int sb_RNG_index[ATRAC3P_SUBBANDS] = { 0 };
192
+
193
+    if (ctx->mute_flag) {
194
+        for (ch = 0; ch < num_channels; ch++)
195
+            memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
196
+        return;
197
+    }
198
+
199
+    for (qu = 0, RNG_index = 0; qu < ctx->used_quant_units; qu++)
200
+        RNG_index += ctx->channels[0].qu_sf_idx[qu] +
201
+                     ctx->channels[1].qu_sf_idx[qu];
202
+
203
+    for (sb = 0; sb < ctx->num_coded_subbands; sb++, RNG_index += 128)
204
+        sb_RNG_index[sb] = RNG_index & 0x3FC;
205
+
206
+    /* inverse quant and power compensation */
207
+    for (ch = 0; ch < num_channels; ch++) {
208
+        /* clear channel's residual spectrum */
209
+        memset(out[ch], 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out[ch]));
210
+
211
+        for (qu = 0; qu < ctx->used_quant_units; qu++) {
212
+            src        = &ctx->channels[ch].spectrum[ff_atrac3p_qu_to_spec_pos[qu]];
213
+            dst        = &out[ch][ff_atrac3p_qu_to_spec_pos[qu]];
214
+            nspeclines = ff_atrac3p_qu_to_spec_pos[qu + 1] -
215
+                         ff_atrac3p_qu_to_spec_pos[qu];
216
+
217
+            if (ctx->channels[ch].qu_wordlen[qu] > 0) {
218
+                q = ff_atrac3p_sf_tab[ctx->channels[ch].qu_sf_idx[qu]] *
219
+                    ff_atrac3p_mant_tab[ctx->channels[ch].qu_wordlen[qu]];
220
+                for (i = 0; i < nspeclines; i++)
221
+                    dst[i] = src[i] * q;
222
+            }
223
+        }
224
+
225
+        for (sb = 0; sb < ctx->num_coded_subbands; sb++)
226
+            ff_atrac3p_power_compensation(ctx, ch, &out[ch][0],
227
+                                          sb_RNG_index[sb], sb);
228
+    }
229
+
230
+    if (ctx->unit_type == CH_UNIT_STEREO) {
231
+        for (sb = 0; sb < ctx->num_coded_subbands; sb++) {
232
+            if (ctx->swap_channels[sb]) {
233
+                for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
234
+                    FFSWAP(float, out[0][sb * ATRAC3P_SUBBAND_SAMPLES + i],
235
+                                  out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
236
+            }
237
+
238
+            /* flip coefficients' sign if requested */
239
+            if (ctx->negate_coeffs[sb])
240
+                for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++)
241
+                    out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i] = -(out[1][sb * ATRAC3P_SUBBAND_SAMPLES + i]);
242
+        }
243
+    }
244
+}
245
+
246
+static void reconstruct_frame(ATRAC3PContext *ctx, Atrac3pChanUnitCtx *ch_unit,
247
+                              int num_channels, AVCodecContext *avctx)
248
+{
249
+    int ch, sb;
250
+
251
+    for (ch = 0; ch < num_channels; ch++) {
252
+        for (sb = 0; sb < ch_unit->num_subbands; sb++) {
253
+            /* inverse transform and windowing */
254
+            ff_atrac3p_imdct(&ctx->fdsp, &ctx->mdct_ctx,
255
+                             &ctx->samples[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
256
+                             &ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
257
+                             (ch_unit->channels[ch].wnd_shape_prev[sb] << 1) +
258
+                             ch_unit->channels[ch].wnd_shape[sb], sb);
259
+
260
+            /* gain compensation and overlapping */
261
+            ff_atrac_gain_compensation(&ctx->gainc_ctx,
262
+                                       &ctx->mdct_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
263
+                                       &ch_unit->prev_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES],
264
+                                       &ch_unit->channels[ch].gain_data_prev[sb],
265
+                                       &ch_unit->channels[ch].gain_data[sb],
266
+                                       ATRAC3P_SUBBAND_SAMPLES,
267
+                                       &ctx->time_buf[ch][sb * ATRAC3P_SUBBAND_SAMPLES]);
268
+        }
269
+
270
+        /* zero unused subbands in both output and overlapping buffers */
271
+        memset(&ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
272
+               0,
273
+               (ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
274
+               ATRAC3P_SUBBAND_SAMPLES *
275
+               sizeof(ch_unit->prev_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
276
+        memset(&ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES],
277
+               0,
278
+               (ATRAC3P_SUBBANDS - ch_unit->num_subbands) *
279
+               ATRAC3P_SUBBAND_SAMPLES *
280
+               sizeof(ctx->time_buf[ch][ch_unit->num_subbands * ATRAC3P_SUBBAND_SAMPLES]));
281
+
282
+        /* resynthesize and add tonal signal */
283
+        if (ch_unit->waves_info->tones_present ||
284
+            ch_unit->waves_info_prev->tones_present) {
285
+            for (sb = 0; sb < ch_unit->num_subbands; sb++)
286
+                if (ch_unit->channels[ch].tones_info[sb].num_wavs ||
287
+                    ch_unit->channels[ch].tones_info_prev[sb].num_wavs) {
288
+                    ff_atrac3p_generate_tones(ch_unit, &ctx->fdsp, ch, sb,
289
+                                              &ctx->time_buf[ch][sb * 128]);
290
+                }
291
+        }
292
+
293
+        /* subband synthesis and acoustic signal output */
294
+        ff_atrac3p_ipqf(&ctx->ipqf_dct_ctx, &ch_unit->ipqf_ctx[ch],
295
+                        &ctx->time_buf[ch][0], &ctx->outp_buf[ch][0]);
296
+    }
297
+
298
+    /* swap window shape and gain control buffers. */
299
+    for (ch = 0; ch < num_channels; ch++) {
300
+        FFSWAP(uint8_t *, ch_unit->channels[ch].wnd_shape,
301
+               ch_unit->channels[ch].wnd_shape_prev);
302
+        FFSWAP(AtracGainInfo *, ch_unit->channels[ch].gain_data,
303
+               ch_unit->channels[ch].gain_data_prev);
304
+        FFSWAP(Atrac3pWavesData *, ch_unit->channels[ch].tones_info,
305
+               ch_unit->channels[ch].tones_info_prev);
306
+    }
307
+
308
+    FFSWAP(Atrac3pWaveSynthParams *, ch_unit->waves_info, ch_unit->waves_info_prev);
309
+}
310
+
311
+static int atrac3p_decode_frame(AVCodecContext *avctx, void *data,
312
+                                int *got_frame_ptr, AVPacket *avpkt)
313
+{
314
+    ATRAC3PContext *ctx = avctx->priv_data;
315
+    AVFrame *frame      = data;
316
+    int i, ret, ch_unit_id, ch_block = 0, out_ch_index = 0, channels_to_process;
317
+    float **samples_p = (float **)frame->extended_data;
318
+
319
+    frame->nb_samples = ATRAC3P_FRAME_SAMPLES;
320
+    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
321
+        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
322
+        return ret;
323
+    }
324
+
325
+    if ((ret = init_get_bits8(&ctx->gb, avpkt->data, avpkt->size)) < 0)
326
+        return ret;
327
+
328
+    if (get_bits1(&ctx->gb)) {
329
+        av_log(avctx, AV_LOG_ERROR, "Invalid start bit!\n");
330
+        return AVERROR_INVALIDDATA;
331
+    }
332
+
333
+    while (get_bits_left(&ctx->gb) >= 2 &&
334
+           (ch_unit_id = get_bits(&ctx->gb, 2)) != CH_UNIT_TERMINATOR) {
335
+        if (ch_unit_id == CH_UNIT_EXTENSION) {
336
+            avpriv_report_missing_feature(avctx, "Channel unit extension");
337
+            return AVERROR_PATCHWELCOME;
338
+        }
339
+        if (ch_block >= ctx->num_channel_blocks ||
340
+            ctx->channel_blocks[ch_block] != ch_unit_id) {
341
+            av_log(avctx, AV_LOG_ERROR,
342
+                   "Frame data doesn't match channel configuration!\n");
343
+            return AVERROR_INVALIDDATA;
344
+        }
345
+
346
+        ctx->ch_units[ch_block].unit_type = ch_unit_id;
347
+        channels_to_process               = ch_unit_id + 1;
348
+
349
+        if ((ret = ff_atrac3p_decode_channel_unit(&ctx->gb,
350
+                                                  &ctx->ch_units[ch_block],
351
+                                                  channels_to_process,
352
+                                                  avctx)) < 0)
353
+            return ret;
354
+
355
+        decode_residual_spectrum(&ctx->ch_units[ch_block], ctx->samples,
356
+                                 channels_to_process, avctx);
357
+        reconstruct_frame(ctx, &ctx->ch_units[ch_block],
358
+                          channels_to_process, avctx);
359
+
360
+        for (i = 0; i < channels_to_process; i++)
361
+            memcpy(samples_p[out_ch_index + i], ctx->outp_buf[i],
362
+                   ATRAC3P_FRAME_SAMPLES * sizeof(**samples_p));
363
+
364
+        ch_block++;
365
+        out_ch_index += channels_to_process;
366
+    }
367
+
368
+    *got_frame_ptr = 1;
369
+
370
+    return avctx->block_align;
371
+}
372
+
373
+AVCodec ff_atrac3p_decoder = {
374
+    .name           = "atrac3plus",
375
+    .long_name      = NULL_IF_CONFIG_SMALL("ATRAC3+ (Adaptive TRansform Acoustic Coding 3+)"),
376
+    .type           = AVMEDIA_TYPE_AUDIO,
377
+    .id             = AV_CODEC_ID_ATRAC3P,
378
+    .priv_data_size = sizeof(ATRAC3PContext),
379
+    .init           = atrac3p_decode_init,
380
+    .close          = atrac3p_decode_close,
381
+    .decode         = atrac3p_decode_frame,
382
+};
0 383
new file mode 100644
... ...
@@ -0,0 +1,637 @@
0
+/*
1
+ * ATRAC3+ compatible decoder
2
+ *
3
+ * Copyright (c) 2010-2013 Maxim Poliakovski
4
+ *
5
+ * This file is part of FFmpeg.
6
+ *
7
+ * FFmpeg is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * FFmpeg is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with FFmpeg; if not, write to the Free Software
19
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ */
21
+
22
+/**
23
+ *  @file
24
+ *  DSP functions for ATRAC3+ decoder.
25
+ */
26
+
27
+#include <math.h>
28
+
29
+#include "libavutil/float_dsp.h"
30
+#include "avcodec.h"
31
+#include "sinewin.h"
32
+#include "fft.h"
33
+#include "atrac3plus.h"
34
+
35
+/**
36
+ *  Map quant unit number to its position in the spectrum.
37
+ *  To get the number of spectral lines in each quant unit do the following:
38
+ *  num_specs = qu_to_spec_pos[i+1] - qu_to_spec_pos[i]
39
+ */
40
+const uint16_t ff_atrac3p_qu_to_spec_pos[33] = {
41
+      0,    16,   32,   48,   64,   80,   96,  112,
42
+    128,   160,  192,  224,  256,  288,  320,  352,
43
+    384,   448,  512,  576,  640,  704,  768,  896,
44
+    1024, 1152, 1280, 1408, 1536, 1664, 1792, 1920,
45
+    2048
46
+};
47
+
48
+/* Scalefactors table. */
49
+/* Approx. Equ: pow(2.0, (i - 16.0 + 0.501783948) / 3.0) */
50
+const float ff_atrac3p_sf_tab[64] = {
51
+    0.027852058,  0.0350914, 0.044212341, 0.055704117,  0.0701828,
52
+    0.088424683, 0.11140823,   0.1403656,  0.17684937, 0.22281647, 0.2807312, 0.35369873,
53
+    0.44563293,   0.5614624,  0.70739746,  0.89126587,  1.1229248, 1.4147949,  1.7825317,
54
+    2.2458496,    2.8295898,   3.5650635,   4.4916992,  5.6591797,  7.130127,  8.9833984,
55
+    11.318359,    14.260254,   17.966797,   22.636719,  28.520508, 35.933594,  45.273438,
56
+    57.041016,    71.867188,   90.546875,   114.08203,  143.73438, 181.09375,  228.16406,
57
+    287.46875,     362.1875,   456.32812,    574.9375,    724.375, 912.65625,   1149.875,
58
+    1448.75,      1825.3125,     2299.75,      2897.5,   3650.625,    4599.5,     5795.0,
59
+    7301.25,         9199.0,     11590.0,     14602.5,    18398.0,   23180.0,    29205.0,
60
+    36796.0,        46360.0,     58410.0
61
+};
62
+
63
+/* Mantissa table. */
64
+/* pow(10, x * log10(2) + 0.05) / 2 / ([1,2,3,5,7,15,31] + 0.5) */
65
+const float ff_atrac3p_mant_tab[8] = {
66
+    0.0,
67
+    0.74801636,
68
+    0.44882202,
69
+    0.32058716,
70
+    0.20400238,
71
+    0.1496048,
72
+    0.07239151,
73
+    0.035619736
74
+};
75
+
76
+#define ATRAC3P_MDCT_SIZE (ATRAC3P_SUBBAND_SAMPLES * 2)
77
+
78
+av_cold void ff_atrac3p_init_imdct(AVCodecContext *avctx, FFTContext *mdct_ctx)
79
+{
80
+    ff_init_ff_sine_windows(7);
81
+    ff_init_ff_sine_windows(6);
82
+
83
+    /* Initialize the MDCT transform. */
84
+    ff_mdct_init(mdct_ctx, 8, 1, -1.0);
85
+}
86
+
87
+#define TWOPI (2 * M_PI)
88
+
89
+#define DEQUANT_PHASE(ph) (((ph) & 0x1F) << 6)
90
+
91
+static DECLARE_ALIGNED(32, float, sine_table)[2048]; ///< wave table
92
+static DECLARE_ALIGNED(32, float, hann_window)[256]; ///< Hann windowing function
93
+static float amp_sf_tab[64];   ///< scalefactors for quantized amplitudes
94
+
95
+av_cold void ff_atrac3p_init_wave_synth(void)
96
+{
97
+    int i;
98
+
99
+    /* generate sine wave table */
100
+    for (i = 0; i < 2048; i++)
101
+        sine_table[i] = sin(TWOPI * i / 2048);
102
+
103
+    /* generate Hann window */
104
+    for (i = 0; i < 256; i++)
105
+        hann_window[i] = (1.0f - cos(TWOPI * i / 256.0f)) * 0.5f;
106
+
107
+    /* generate amplitude scalefactors table */
108
+    for (i = 0; i < 64; i++)
109
+        amp_sf_tab[i] = pow(2.0f, ((double)i - 3) / 4.0f);
110
+}
111
+
112
+/**
113
+ *  Synthesize sine waves according to given parameters.
114
+ *
115
+ *  @param[in]    synth_param   ptr to common synthesis parameters
116
+ *  @param[in]    waves_info    parameters for each sine wave
117
+ *  @param[in]    envelope      envelope data for all waves in a group
118
+ *  @param[in]    reg_offset    region offset for trimming envelope data
119
+ *  @param[out]   out           receives sythesized data
120
+ */
121
+static void waves_synth(Atrac3pWaveSynthParams *synth_param,
122
+                        Atrac3pWavesData *waves_info,
123
+                        Atrac3pWaveEnvelope *envelope,
124
+                        int phase_shift, int reg_offset, float *out)
125
+{
126
+    int i, wn, inc, pos;
127
+    double amp;
128
+    Atrac3pWaveParam *wave_param = &synth_param->waves[waves_info->start_index];
129
+
130
+    for (wn = 0; wn < waves_info->num_wavs; wn++, wave_param++) {
131
+        /* amplitude dequantization */
132
+        amp = amp_sf_tab[wave_param->amp_sf] *
133
+              (!synth_param->amplitude_mode
134
+               ? (wave_param->amp_index + 1) / 15.13f
135
+               : 1.0f);
136
+
137
+        inc = wave_param->freq_index;
138
+        pos = DEQUANT_PHASE(wave_param->phase_index) - (reg_offset ^ 128) * inc & 2047;
139
+
140
+        /* waveform generation */
141
+        for (i = 0; i < 128; i++) {
142
+            out[i] += sine_table[pos] * amp;
143
+            pos     = (pos + inc) & 2047;
144
+        }
145
+    }
146
+
147
+    /* fade in with steep Hann window if requested */
148
+    if (envelope->has_start_point) {
149
+        pos = (envelope->start_pos << 2) - reg_offset;
150
+        if (pos > 0 && pos <= 128) {
151
+            memset(out, 0, pos * sizeof(*out));
152
+            if (!envelope->has_stop_point ||
153
+                envelope->start_pos != envelope->stop_pos) {
154
+                out[pos + 0] *= hann_window[0];
155
+                out[pos + 1] *= hann_window[32];
156
+                out[pos + 2] *= hann_window[64];
157
+                out[pos + 3] *= hann_window[96];
158
+            }
159
+        }
160
+    }
161
+
162
+    /* fade out with steep Hann window if requested */
163
+    if (envelope->has_stop_point) {
164
+        pos = (envelope->stop_pos + 1 << 2) - reg_offset;
165
+        if (pos > 0 && pos <= 128) {
166
+            out[pos - 4] *= hann_window[96];
167
+            out[pos - 3] *= hann_window[64];
168
+            out[pos - 2] *= hann_window[32];
169
+            out[pos - 1] *= hann_window[0];
170
+            memset(&out[pos], 0, (128 - pos) * sizeof(out[pos]));
171
+        }
172
+    }
173
+}
174
+
175
+void ff_atrac3p_generate_tones(Atrac3pChanUnitCtx *ch_unit, AVFloatDSPContext *fdsp,
176
+                               int ch_num, int sb, float *out)
177
+{
178
+    DECLARE_ALIGNED(32, float, wavreg1)[128] = { 0 };
179
+    DECLARE_ALIGNED(32, float, wavreg2)[128] = { 0 };
180
+    int i, reg1_env_nonzero, reg2_env_nonzero;
181
+    Atrac3pWavesData *tones_now  = &ch_unit->channels[ch_num].tones_info_prev[sb];
182
+    Atrac3pWavesData *tones_next = &ch_unit->channels[ch_num].tones_info[sb];
183
+
184
+    /* reconstruct full envelopes for both overlapping regions
185
+     * from truncated bitstream data */
186
+    if (tones_next->pend_env.has_start_point &&
187
+        tones_next->pend_env.start_pos < tones_next->pend_env.stop_pos) {
188
+        tones_next->curr_env.has_start_point = 1;
189
+        tones_next->curr_env.start_pos       = tones_next->pend_env.start_pos + 32;
190
+    } else if (tones_now->pend_env.has_start_point) {
191
+        tones_next->curr_env.has_start_point = 1;
192
+        tones_next->curr_env.start_pos       = tones_now->pend_env.start_pos;
193
+    } else {
194
+        tones_next->curr_env.has_start_point = 0;
195
+        tones_next->curr_env.start_pos       = 0;
196
+    }
197
+
198
+    if (tones_now->pend_env.has_stop_point &&
199
+        tones_now->pend_env.stop_pos >= tones_next->curr_env.start_pos) {
200
+        tones_next->curr_env.has_stop_point = 1;
201
+        tones_next->curr_env.stop_pos       = tones_now->pend_env.stop_pos;
202
+    } else if (tones_next->pend_env.has_stop_point) {
203
+        tones_next->curr_env.has_stop_point = 1;
204
+        tones_next->curr_env.stop_pos       = tones_next->pend_env.stop_pos + 32;
205
+    } else {
206
+        tones_next->curr_env.has_stop_point = 0;
207
+        tones_next->curr_env.stop_pos       = 64;
208
+    }
209
+
210
+    /* is the visible part of the envelope non-zero? */
211
+    reg1_env_nonzero = (tones_now->curr_env.stop_pos    < 32) ? 0 : 1;
212
+    reg2_env_nonzero = (tones_next->curr_env.start_pos >= 32) ? 0 : 1;
213
+
214
+    /* synthesize waves for both overlapping regions */
215
+    if (tones_now->num_wavs && reg1_env_nonzero)
216
+        waves_synth(ch_unit->waves_info_prev, tones_now, &tones_now->curr_env,
217
+                    ch_unit->waves_info_prev->phase_shift[sb] & ch_num,
218
+                    128, wavreg1);
219
+
220
+    if (tones_next->num_wavs && reg2_env_nonzero)
221
+        waves_synth(ch_unit->waves_info, tones_next, &tones_next->curr_env,
222
+                    ch_unit->waves_info->phase_shift[sb] & ch_num, 0, wavreg2);
223
+
224
+    /* Hann windowing for non-faded wave signals */
225
+    if (tones_now->num_wavs && tones_next->num_wavs &&
226
+        reg1_env_nonzero && reg2_env_nonzero) {
227
+        fdsp->vector_fmul(wavreg1, wavreg1, &hann_window[128], 128);
228
+        fdsp->vector_fmul(wavreg2, wavreg2,  hann_window,      128);
229
+    } else {
230
+        if (tones_now->num_wavs && !tones_now->curr_env.has_stop_point)
231
+            fdsp->vector_fmul(wavreg1, wavreg1, &hann_window[128], 128);
232
+
233
+        if (tones_next->num_wavs && !tones_next->curr_env.has_start_point)
234
+            fdsp->vector_fmul(wavreg2, wavreg2, hann_window, 128);
235
+    }
236
+
237
+    /* Overlap and add to residual */
238
+    for (i = 0; i < 128; i++)
239
+        out[i] += wavreg1[i] + wavreg2[i];
240
+}
241
+
242
+static const int subband_to_powgrp[ATRAC3P_SUBBANDS] = {
243
+    0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4
244
+};
245
+
246
+/* noise table for power compensation */
247
+static const float noise_tab[1024] = {
248
+    -0.01358032,  -0.05593872,   0.01696777,  -0.14871216,  -0.26412964,  -0.09893799,   0.25723267,
249
+     0.02008057,  -0.72235107,  -0.44351196,  -0.22985840,   0.16833496,   0.46902466,   0.05917358,
250
+    -0.15179443,   0.41299438,  -0.01287842,   0.13360596,   0.43557739,  -0.09530640,  -0.58422852,
251
+     0.39266968,  -0.08343506,  -0.25604248,   0.22848511,   0.26013184,  -0.65588379,   0.17288208,
252
+    -0.08673096,  -0.05203247,   0.07299805,  -0.28665161,  -0.35806274,   0.06552124,  -0.09387207,
253
+     0.21099854,  -0.28347778,  -0.72402954,   0.05050659,  -0.10635376,  -0.18853760,   0.29724121,
254
+     0.20703125,  -0.29791260,  -0.37634277,   0.47970581,  -0.09976196,   0.32641602,  -0.29248047,
255
+    -0.28237915,   0.26028442,  -0.36157227,   0.22042847,  -0.03222656,  -0.37268066,  -0.03759766,
256
+     0.09909058,   0.23284912,   0.19320679,   0.14453125,  -0.02139282,  -0.19702148,   0.31533813,
257
+    -0.16741943,   0.35031128,  -0.35656738,  -0.66128540,  -0.00701904,   0.20898438,   0.26837158,
258
+    -0.33706665,  -0.04568481,   0.12600708,   0.10284424,   0.07321167,  -0.18280029,   0.38101196,
259
+     0.21301270,   0.04541016,   0.01156616,  -0.26391602,  -0.02346802,  -0.22125244,   0.29760742,
260
+    -0.36233521,  -0.31314087,  -0.13967896,  -0.11276245,  -0.19433594,   0.34490967,   0.02343750,
261
+     0.21963501,  -0.02777100,  -0.67678833,  -0.08999634,   0.14233398,  -0.27697754,   0.51422119,
262
+    -0.05047607,   0.48327637,   0.37167358,  -0.60806274,   0.18728638,  -0.15191650,   0.00637817,
263
+     0.02832031,  -0.15618896,   0.60644531,   0.21826172,   0.06384277,  -0.31863403,   0.08816528,
264
+     0.15447998,  -0.07015991,  -0.08154297,  -0.40966797,  -0.39785767,  -0.11709595,   0.22052002,
265
+     0.18466187,  -0.17257690,   0.03759766,  -0.06195068,   0.00433350,   0.12176514,   0.34011841,
266
+     0.25610352,  -0.05294800,   0.41033936,   0.16854858,  -0.76187134,   0.13845825,  -0.19418335,
267
+    -0.21524048,  -0.44412231,  -0.08160400,  -0.28195190,  -0.01873779,   0.15524292,  -0.37438965,
268
+    -0.44860840,   0.43096924,  -0.24746704,   0.49856567,   0.14859009,   0.38159180,   0.20541382,
269
+    -0.39175415,  -0.65850830,  -0.43716431,   0.13037109,  -0.05111694,   0.39956665,   0.21447754,
270
+    -0.04861450,   0.33654785,   0.10589600,  -0.88085938,  -0.30822754,   0.38577271,   0.30047607,
271
+     0.38836670,   0.09118652,  -0.36477661,  -0.01641846,  -0.23031616,   0.26058960,   0.18859863,
272
+    -0.21868896,  -0.17861938,  -0.29754639,   0.09777832,   0.10806274,  -0.51605225,   0.00076294,
273
+     0.13259888,   0.11090088,  -0.24084473,   0.24957275,   0.01379395,  -0.04141235,  -0.04937744,
274
+     0.57394409,   0.27410889,   0.27587891,   0.45013428,  -0.32592773,   0.11160278,  -0.00970459,
275
+     0.29092407,   0.03356934,  -0.70925903,   0.04882812,   0.43499756,   0.07720947,  -0.27554321,
276
+    -0.01742554,  -0.08413696,  -0.04028320,  -0.52850342,  -0.07330322,   0.05181885,   0.21362305,
277
+    -0.18765259,   0.07058716,  -0.03009033,   0.32662964,   0.27023315,  -0.28002930,   0.17568970,
278
+     0.03338623,   0.30242920,  -0.03921509,   0.32174683,  -0.23733521,   0.08575439,  -0.38269043,
279
+     0.09194946,  -0.07238770,   0.17941284,  -0.51278687,  -0.25146484,   0.19790649,  -0.19195557,
280
+     0.16549683,   0.42456055,   0.39129639,  -0.02868652,   0.17980957,   0.24902344,  -0.76583862,
281
+    -0.20959473,   0.61013794,   0.37011719,   0.36859131,  -0.04486084,   0.10678101,  -0.15994263,
282
+    -0.05328369,   0.28463745,  -0.06420898,  -0.36987305,  -0.28009033,  -0.11764526,   0.04312134,
283
+    -0.08038330,   0.04885864,  -0.03067017,  -0.00042725,   0.34289551,  -0.00988770,   0.34838867,
284
+     0.32516479,  -0.16271973,   0.38269043,   0.03240967,   0.12417603,  -0.14331055,  -0.34902954,
285
+    -0.18325806,   0.29421997,   0.44284058,   0.75170898,  -0.67245483,  -0.12176514,   0.27914429,
286
+    -0.29806519,   0.19863892,   0.30087280,   0.22680664,  -0.36633301,  -0.32534790,  -0.57553101,
287
+    -0.16641235,   0.43811035,   0.08331299,   0.15942383,   0.26516724,  -0.24240112,  -0.11761475,
288
+    -0.16827393,  -0.14260864,   0.46343994,   0.11804199,  -0.55514526,  -0.02520752,  -0.14309692,
289
+     0.00448608,   0.02749634,  -0.30545044,   0.70965576,   0.45108032,   0.66439819,  -0.68255615,
290
+    -0.12496948,   0.09146118,  -0.21109009,  -0.23791504,   0.79943848,  -0.35205078,  -0.24963379,
291
+     0.18719482,  -0.19079590,   0.07458496,   0.07623291,  -0.28781128,  -0.37121582,  -0.19580078,
292
+    -0.01773071,  -0.16717529,   0.13040161,   0.14672852,   0.42379761,   0.03582764,   0.11431885,
293
+     0.05145264,   0.44702148,   0.08963013,   0.01367188,  -0.54519653,  -0.12692261,   0.21176147,
294
+     0.04925537,   0.30670166,  -0.11029053,   0.19555664,  -0.27740479,   0.23043823,   0.15554810,
295
+    -0.19299316,  -0.25729370,   0.17800903,  -0.03579712,  -0.05065918,  -0.06933594,  -0.09500122,
296
+    -0.07821655,   0.23889160,  -0.31900024,   0.03073120,  -0.00415039,   0.61315918,   0.37176514,
297
+    -0.13442993,  -0.15536499,  -0.19216919,  -0.37899780,   0.19992065,   0.02630615,  -0.12573242,
298
+     0.25927734,  -0.02447510,   0.29629517,  -0.40731812,  -0.17333984,   0.24310303,  -0.10607910,
299
+     0.14828491,   0.08792114,  -0.18743896,  -0.05572510,  -0.04833984,   0.10473633,  -0.29028320,
300
+    -0.67687988,  -0.28170776,  -0.41687012,   0.05413818,  -0.23284912,   0.09555054,  -0.08969116,
301
+    -0.15112305,   0.12738037,   0.35986328,   0.28948975,   0.30691528,   0.23956299,   0.06973267,
302
+    -0.31198120,  -0.18450928,   0.22280884,  -0.21600342,   0.23522949,  -0.61840820,  -0.13012695,
303
+     0.26412964,   0.47320557,  -0.26440430,   0.38757324,   0.17352295,  -0.26104736,  -0.25866699,
304
+    -0.12274170,  -0.29733276,   0.07687378,   0.18588257,  -0.08880615,   0.31185913,   0.05313110,
305
+    -0.10885620,  -0.14901733,  -0.22323608,  -0.08538818,   0.19812012,   0.19732666,  -0.18927002,
306
+     0.29058838,   0.25555420,  -0.48599243,   0.18768311,   0.01345825,   0.34887695,   0.21530151,
307
+     0.19857788,   0.18661499,  -0.01394653,  -0.09063721,  -0.38781738,   0.27160645,  -0.20379639,
308
+    -0.32119751,  -0.23889160,   0.27096558,   0.24951172,   0.07922363,   0.07479858,  -0.50946045,
309
+     0.10220337,   0.58364868,  -0.19503784,  -0.18560791,  -0.01165771,   0.47195435,   0.22430420,
310
+    -0.38635254,  -0.03732300,  -0.09179688,   0.06991577,   0.15106201,   0.20605469,  -0.05969238,
311
+    -0.41821289,   0.12231445,  -0.04672241,  -0.05117798,  -0.11523438,  -0.51849365,  -0.04077148,
312
+     0.44284058,  -0.64086914,   0.17019653,   0.02236938,   0.22848511,  -0.23214722,  -0.32354736,
313
+    -0.14068604,  -0.29690552,  -0.19891357,   0.02774048,  -0.20965576,  -0.52191162,  -0.19299316,
314
+    -0.07290649,   0.49053955,  -0.22302246,   0.05642700,   0.13122559,  -0.20819092,  -0.83590698,
315
+    -0.08181763,   0.26797485,  -0.00091553,  -0.09457397,   0.17089844,  -0.27020264,   0.30270386,
316
+     0.05496216,   0.09564209,  -0.08590698,   0.02130127,   0.35931396,   0.21728516,  -0.15396118,
317
+    -0.05053711,   0.02719116,   0.16302490,   0.43212891,   0.10229492,  -0.40820312,   0.21646118,
318
+     0.08435059,  -0.11145020,  -0.39962769,  -0.05618286,  -0.10223389,  -0.60839844,   0.33724976,
319
+    -0.06341553,  -0.47369385,  -0.32852173,   0.05242920,   0.19635010,  -0.19137573,  -0.67901611,
320
+     0.16180420,   0.05133057,  -0.22283936,   0.09646606,   0.24288940,  -0.45007324,   0.08804321,
321
+     0.14053345,   0.22619629,  -0.01000977,   0.36355591,  -0.19863892,  -0.30364990,  -0.24118042,
322
+    -0.57461548,   0.26498413,   0.04345703,  -0.09796143,  -0.47714233,  -0.23739624,   0.18737793,
323
+     0.08926392,  -0.02795410,   0.00305176,  -0.08700562,  -0.38711548,   0.03222656,   0.10940552,
324
+    -0.41906738,  -0.01620483,  -0.47061157,   0.37985229,  -0.21624756,   0.47976685,  -0.20046997,
325
+    -0.62533569,  -0.26907349,  -0.02877808,   0.00671387,  -0.29071045,  -0.24685669,  -0.15722656,
326
+    -0.26055908,   0.29968262,   0.28225708,  -0.08990479,  -0.16748047,  -0.46759033,  -0.25067139,
327
+    -0.25183105,  -0.45932007,   0.05828857,   0.29006958,   0.23840332,  -0.17974854,   0.26931763,
328
+     0.10696411,  -0.06848145,  -0.17126465,  -0.10522461,  -0.55386353,  -0.42306519,  -0.07608032,
329
+     0.24380493,   0.38586426,   0.16882324,   0.26751709,   0.17303467,   0.35809326,  -0.22094727,
330
+    -0.30703735,  -0.28497314,  -0.04321289,   0.15219116,  -0.17071533,  -0.39334106,   0.03439331,
331
+    -0.10809326,  -0.30590820,   0.26449585,  -0.07412720,   0.13638306,  -0.01062012,   0.27996826,
332
+     0.04397583,  -0.05557251,  -0.56933594,   0.03363037,  -0.00949097,   0.52642822,  -0.44329834,
333
+     0.28308105,  -0.05499268,  -0.23312378,  -0.29870605,  -0.05123901,   0.26831055,  -0.35238647,
334
+    -0.30993652,   0.34646606,  -0.19775391,   0.44595337,   0.13769531,   0.45358276,   0.19961548,
335
+     0.42681885,   0.15722656,   0.00128174,   0.23757935,   0.40988159,   0.25164795,  -0.00732422,
336
+    -0.12405396,  -0.43420410,  -0.00402832,   0.34243774,   0.36264038,   0.18807983,  -0.09301758,
337
+    -0.10296631,   0.05532837,  -0.31652832,   0.14337158,   0.35040283,   0.32540894,   0.05728149,
338
+    -0.12030029,  -0.25942993,  -0.20312500,  -0.16491699,  -0.46051025,  -0.08004761,   0.50772095,
339
+     0.16168213,   0.28439331,   0.08105469,  -0.19104004,   0.38589478,  -0.16400146,  -0.25454712,
340
+     0.20281982,  -0.20730591,  -0.06311035,   0.32937622,   0.15032959,  -0.05340576,   0.30487061,
341
+    -0.11648560,   0.38009644,  -0.20062256,   0.43466187,   0.01150513,   0.35754395,  -0.13146973,
342
+     0.67489624,   0.05212402,   0.27914429,  -0.39431763,   0.75308228,  -0.13366699,   0.24453735,
343
+     0.42248535,  -0.65905762,  -0.00546265,  -0.03491211,  -0.13659668,  -0.08294678,  -0.45666504,
344
+     0.27188110,   0.12731934,   0.61148071,   0.10449219,  -0.28836060,   0.00091553,   0.24618530,
345
+     0.13119507,   0.05685425,   0.17355347,   0.42034912,   0.08514404,   0.24536133,   0.18951416,
346
+    -0.19107056,  -0.15036011,   0.02334595,   0.54986572,   0.32321167,  -0.16104126,  -0.03054810,
347
+     0.43594360,   0.17309570,   0.61053467,   0.24731445,   0.33334351,   0.15240479,   0.15588379,
348
+     0.36425781,  -0.30407715,  -0.13302612,   0.00427246,   0.04171753,  -0.33178711,   0.34216309,
349
+    -0.12463379,  -0.02764893,   0.05905151,  -0.31436157,   0.16531372,   0.34542847,  -0.03292847,
350
+     0.12527466,  -0.12313843,  -0.13171387,   0.04757690,  -0.45095825,  -0.19085693,   0.35342407,
351
+    -0.23239136,  -0.34387207,   0.11264038,  -0.15740967,   0.05273438,   0.74942017,   0.21505737,
352
+     0.08514404,  -0.42391968,  -0.19531250,   0.35293579,   0.25305176,   0.15731812,  -0.70324707,
353
+    -0.21591187,   0.35604858,   0.14132690,   0.11724854,   0.15853882,  -0.24597168,   0.07019043,
354
+     0.02127075,   0.12658691,   0.06390381,  -0.12292480,   0.15441895,  -0.47640991,   0.06195068,
355
+     0.58981323,  -0.15151978,  -0.03604126,  -0.45059204,  -0.01672363,  -0.46997070,   0.25750732,
356
+     0.18084717,   0.06661987,   0.13253784,   0.67828369,   0.11370850,   0.11325073,  -0.04611206,
357
+    -0.07791138,  -0.36544800,  -0.06747437,  -0.31594849,   0.16131592,   0.41983032,   0.11071777,
358
+    -0.36889648,   0.30963135,  -0.37875366,   0.58508301,   0.00393677,   0.12338257,   0.03424072,
359
+    -0.21728516,  -0.12838745,  -0.46981812,   0.05868530,  -0.25015259,   0.27407837,   0.65240479,
360
+    -0.34429932,  -0.15179443,   0.14056396,   0.33505249,   0.28826904,   0.09921265,   0.34390259,
361
+     0.13656616,  -0.23608398,   0.00863647,   0.02627563,  -0.19119263,   0.19775391,  -0.07214355,
362
+     0.07809448,   0.03454590,  -0.03417969,   0.00033569,  -0.23095703,   0.18673706,   0.05798340,
363
+     0.03814697,  -0.04318237,   0.05487061,   0.08633423,   0.55950928,  -0.06347656,   0.10333252,
364
+     0.25305176,   0.05853271,   0.12246704,  -0.25543213,  -0.34262085,  -0.36437988,  -0.21304321,
365
+    -0.05093384,   0.02777100,   0.07620239,  -0.21215820,  -0.09326172,   0.19021606,  -0.40579224,
366
+    -0.01193237,   0.19845581,  -0.35336304,  -0.07397461,   0.20104980,   0.08615112,  -0.44375610,
367
+     0.11419678,   0.24453735,  -0.16555786,  -0.05081177,  -0.01406860,   0.27893066,  -0.18692017,
368
+     0.07473755,   0.03451538,  -0.39733887,   0.21548462,  -0.22534180,  -0.39651489,  -0.04989624,
369
+    -0.57662964,   0.06390381,   0.62020874,  -0.13470459,   0.04345703,  -0.21862793,  -0.02789307,
370
+     0.51696777,  -0.27587891,   0.39004517,   0.09857178,  -0.00738525,   0.31317139,   0.00048828,
371
+    -0.46572876,   0.29531860,  -0.10009766,  -0.27856445,   0.03594971,   0.25048828,  -0.74584961,
372
+    -0.25350952,  -0.03302002,   0.31188965,   0.01571655,   0.46710205,   0.21591187,   0.07260132,
373
+    -0.42132568,  -0.53900146,  -0.13674927,  -0.16571045,  -0.34454346,   0.12359619,  -0.11184692,
374
+     0.00967407,   0.34576416,  -0.05761719,   0.34848022,   0.17645264,  -0.39395142,   0.10339355,
375
+     0.18215942,   0.20697021,   0.59109497,  -0.11560059,  -0.07385254,   0.10397339,   0.35437012,
376
+    -0.22863770,   0.01794434,   0.17559814,  -0.17495728,   0.12142944,   0.10928345,  -1.00000000,
377
+    -0.01379395,   0.21237183,  -0.27035522,   0.27319336,  -0.37066650,   0.41354370,  -0.40054321,
378
+     0.00689697,   0.26321411,   0.39266968,   0.65298462,   0.41625977,  -0.13909912,   0.78375244,
379
+    -0.30941772,   0.20169067,  -0.39367676,   0.94021606,  -0.24066162,   0.05557251,  -0.24533081,
380
+    -0.05444336,  -0.76754761,  -0.19375610,  -0.11041260,  -0.17532349,   0.16006470,   0.02188110,
381
+     0.17465210,  -0.04342651,  -0.56777954,  -0.40988159,   0.26687622,   0.11700439,  -0.00344849,
382
+    -0.05395508,   0.37426758,  -0.40719604,  -0.15032959,  -0.01660156,   0.04196167,  -0.04559326,
383
+    -0.12969971,   0.12011719,   0.08419800,  -0.11199951,   0.35174561,   0.10275269,  -0.25686646,
384
+     0.48446655,   0.03225708,   0.28408813,  -0.18701172,   0.36282349,  -0.03280640,   0.32302856,
385
+     0.17233276,   0.48269653,   0.31112671,  -0.04946899,   0.12774658,   0.52685547,   0.10211182,
386
+     0.05953979,   0.05999756,   0.20144653,   0.00744629,   0.27316284,   0.24377441,   0.39672852,
387
+     0.01702881,  -0.35513306,   0.11364746,  -0.13555908,   0.48880005,  -0.15417480,  -0.09149170,
388
+    -0.02615356,   0.46246338,  -0.72250366,   0.22332764,   0.23849487,  -0.25686646,  -0.08514404,
389
+    -0.02062988,  -0.34494019,  -0.02297974,  -0.80386353,  -0.08074951,  -0.12689209,  -0.06896973,
390
+     0.24099731,  -0.35650635,  -0.09558105,   0.29254150,   0.23132324,  -0.16726685,   0.00000000,
391
+    -0.24237061,   0.30899048,   0.29504395,  -0.20898438,   0.17059326,  -0.07672119,  -0.14395142,
392
+     0.05572510,   0.20602417,  -0.51550293,  -0.03167725,  -0.48840332,  -0.20425415,   0.14144897,
393
+     0.07275391,  -0.76669312,  -0.22488403,   0.20651245,   0.03259277,   0.00085449,   0.03039551,
394
+     0.47555542,   0.38351440
395
+};
396
+
397
+/** Noise level table for power compensation.
398
+ *  Equ: pow(2.0f, (double)(6 - i) / 3.0f) where i = 0...15 */
399
+static const float pwc_levs[16] = {
400
+    3.96875, 3.15625,     2.5,    2.0, 1.59375,   1.25,     1.0, 0.78125,
401
+    0.625,       0.5, 0.40625, 0.3125,    0.25, 0.1875, 0.15625, 0.0
402
+};
403
+
404
+/** Map subband number to quant unit number. */
405
+static const int subband_to_qu[17] = {
406
+    0, 8, 12, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
407
+};
408
+
409
+void ff_atrac3p_power_compensation(Atrac3pChanUnitCtx *ctx, int ch_index,
410
+                                   float *sp, int rng_index, int sb)
411
+{
412
+    AtracGainInfo *g1, *g2;
413
+    float pwcsp[ATRAC3P_SUBBAND_SAMPLES], *dst, grp_lev, qu_lev;
414
+    int i, gain_lev, gcv = 0, qu, nsp;
415
+    int swap_ch = (ctx->unit_type == CH_UNIT_STEREO && ctx->swap_channels[sb]) ? 1 : 0;
416
+
417
+    if (ctx->channels[ch_index ^ swap_ch].power_levs[subband_to_powgrp[sb]] == ATRAC3P_POWER_COMP_OFF)
418
+        return;
419
+
420
+    /* generate initial noise spectrum */
421
+    for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES; i++, rng_index++)
422
+        pwcsp[i] = noise_tab[rng_index & 0x3FF];
423
+
424
+    /* check gain control information */
425
+    g1 = &ctx->channels[ch_index ^ swap_ch].gain_data[sb];
426
+    g2 = &ctx->channels[ch_index ^ swap_ch].gain_data_prev[sb];
427
+
428
+    gain_lev = (g1->num_points > 0) ? (6 - g1->lev_code[0]) : 0;
429
+
430
+    for (i = 0; i < g2->num_points; i++)
431
+        gcv = FFMAX(gcv, gain_lev - (g2->lev_code[i] - 6));
432
+
433
+    for (i = 0; i < g1->num_points; i++)
434
+        gcv = FFMAX(gcv, 6 - g1->lev_code[i]);
435
+
436
+    grp_lev = pwc_levs[ctx->channels[ch_index ^ swap_ch].power_levs[subband_to_powgrp[sb]]] / (1 << gcv);
437
+
438
+    /* skip the lowest two quant units (frequencies 0...351 Hz) for subband 0 */
439
+    for (qu = subband_to_qu[sb] + (!sb ? 2 : 0); qu < subband_to_qu[sb + 1]; qu++) {
440
+        if (ctx->channels[ch_index].qu_wordlen[qu] <= 0)
441
+            continue;
442
+
443
+        qu_lev = ff_atrac3p_sf_tab[ctx->channels[ch_index].qu_sf_idx[qu]] *
444
+                 ff_atrac3p_mant_tab[ctx->channels[ch_index].qu_wordlen[qu]] /
445
+                 (1 << ctx->channels[ch_index].qu_wordlen[qu]) * grp_lev;
446
+
447
+        dst = &sp[ff_atrac3p_qu_to_spec_pos[qu]];
448
+        nsp = ff_atrac3p_qu_to_spec_pos[qu + 1] - ff_atrac3p_qu_to_spec_pos[qu];
449
+
450
+        for (i = 0; i < nsp; i++)
451
+            dst[i] += pwcsp[i] * qu_lev;
452
+    }
453
+}
454
+
455
+void ff_atrac3p_imdct(AVFloatDSPContext *fdsp, FFTContext *mdct_ctx, float *pIn,
456
+                      float *pOut, int wind_id, int sb)
457
+{
458
+    int i;
459
+
460
+    if (sb & 1)
461
+        for (i = 0; i < ATRAC3P_SUBBAND_SAMPLES / 2; i++)
462
+            FFSWAP(float, pIn[i], pIn[ATRAC3P_SUBBAND_SAMPLES - 1 - i]);
463
+
464
+    mdct_ctx->imdct_calc(mdct_ctx, pOut, pIn);
465
+
466
+    /* Perform windowing on the output.
467
+     * ATRAC3+ uses two different MDCT windows:
468
+     * - The first one is just the plain sine window of size 256
469
+     * - The 2nd one is the plain sine window of size 128
470
+     *   wrapped into zero (at the start) and one (at the end) regions.
471
+     *   Both regions are 32 samples long. */
472
+    if (wind_id & 2) { /* 1st half: steep window */
473
+        memset(pOut, 0, sizeof(float) * 32);
474
+        fdsp->vector_fmul(&pOut[32], &pOut[32], ff_sine_64, 64);
475
+    } else /* 1st half: simple sine window */
476
+        fdsp->vector_fmul(pOut, pOut, ff_sine_128, ATRAC3P_MDCT_SIZE / 2);
477
+
478
+    if (wind_id & 1) { /* 2nd half: steep window */
479
+        fdsp->vector_fmul_reverse(&pOut[160], &pOut[160], ff_sine_64, 64);
480
+        memset(&pOut[224], 0, sizeof(float) * 32);
481
+    } else /* 2nd half: simple sine window */
482
+        fdsp->vector_fmul_reverse(&pOut[128], &pOut[128], ff_sine_128,
483
+                                  ATRAC3P_MDCT_SIZE / 2);
484
+}
485
+
486
+/* lookup table for fast modulo 23 op required for cyclic buffers of the IPQF */
487
+static const int mod23_lut[26] = {
488
+    23,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,
489
+    12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0
490
+};
491
+
492
+/* First half of the 384-tap IPQF filtering coefficients. */
493
+static const float ipqf_coeffs1[ATRAC3P_PQF_FIR_LEN][16] = {
494
+    { -5.8336207e-7,    -8.0604229e-7,    -4.2005411e-7,    -4.4400572e-8,
495
+       3.226247e-8,      3.530856e-8,      1.2660377e-8,     0.000010516783,
496
+      -0.000011838618,   6.005389e-7,      0.0000014333754,  0.0000023108685,
497
+       0.0000032569742,  0.0000046192422,  0.0000063894258,  0.0000070302972 },
498
+    { -0.0000091622824, -0.000010502935,  -0.0000079212787, -0.0000041712024,
499
+      -0.0000026336629, -0.0000015432918, -5.7168614e-7,     0.0000018111954,
500
+       0.000023530851,   0.00002780562,    0.000032302323,   0.000036968919,
501
+       0.000041575615,   0.000045337845,   0.000046043948,   0.000048585582 },
502
+    { -0.000064464548,  -0.000068306952,  -0.000073081472,  -0.00007612785,
503
+      -0.000074850752,  -0.000070208509,  -0.000062285151,  -0.000058270442,
504
+      -0.000056296329,  -0.000049888811,  -0.000035615325,  -0.000018532943,
505
+       0.0000016657353,  0.00002610587,    0.000053397067,   0.00008079566 },
506
+    { -0.00054488552,   -0.00052537228,   -0.00049731287,   -0.00045778,
507
+      -0.00040612387,   -0.00034301577,   -0.00026866337,   -0.00018248901,
508
+      -0.000084307925,   0.000025081157,   0.00014135583,    0.00026649953,
509
+       0.00039945057,    0.00053928449,    0.00068422867,    0.00083093712 },
510
+    { -0.0014771431,    -0.001283227,     -0.0010566821,    -0.00079780724,
511
+      -0.00050782406,   -0.00018855913,    0.00015771533,    0.00052769453,
512
+       0.00091862219,    0.001326357,      0.0017469483,     0.0021754825,
513
+       0.0026067684,     0.0030352892,     0.0034549395,     0.0038591374 },
514
+    { -0.0022995141,    -0.001443546,     -0.00049266568,    0.00055068987,
515
+       0.001682895,      0.0028992873,     0.0041943151,     0.0055614738,
516
+       0.0069935122,     0.0084823566,     0.010018963,      0.011593862,
517
+       0.013196872,      0.014817309,      0.016444042,      0.018065533 },
518
+    { -0.034426283,     -0.034281436,     -0.033992987,     -0.033563249,
519
+      -0.032995768,     -0.032295227,     -0.031467363,     -0.030518902,
520
+      -0.02945766,      -0.028291954,     -0.027031265,     -0.025685543,
521
+      -0.024265358,     -0.022781773,     -0.021246184,     -0.019670162 },
522
+    { -0.0030586775,    -0.0037203205,    -0.0042847847,    -0.0047529764,
523
+      -0.0051268316,    -0.0054091476,    -0.0056034233,    -0.005714261,
524
+      -0.0057445862,    -0.0057025906,    -0.0055920109,    -0.0054194843,
525
+      -0.0051914565,    -0.0049146507,    -0.0045959447,    -0.0042418269 },
526
+    { -0.0016376863,    -0.0017651899,    -0.0018608454,    -0.0019252141,
527
+      -0.0019593791,    -0.0019653172,    -0.0019450618,    -0.0018990048,
528
+      -0.00183808,      -0.0017501717,    -0.0016481078,    -0.0015320742,
529
+      -0.0014046903,    -0.0012685474,    -0.001125814,     -0.00097943726 },
530
+    { -0.00055432378,   -0.00055472925,   -0.00054783461,   -0.00053276919,
531
+      -0.00051135791,   -0.00048466062,   -0.00045358928,   -0.00042499689,
532
+      -0.00036942671,   -0.0003392619,    -0.00030001783,   -0.00025986304,
533
+      -0.0002197204,    -0.00018116167,   -0.00014691355,   -0.00011279432 },
534
+    { -0.000064147389,  -0.00006174868,   -0.000054267788,  -0.000047133824,
535
+      -0.000042927582,  -0.000039477309,  -0.000036340745,  -0.000029687517,
536
+      -0.000049787737,  -0.000041577889,  -0.000033864744,  -0.000026534748,
537
+      -0.000019841305,  -0.000014789486,  -0.000013131184,  -0.0000099198869 },
538
+    { -0.0000062990207, -0.0000072701259, -0.000011984052,  -0.000017348082,
539
+      -0.000019907106,  -0.000021348773,  -0.000021961965,  -0.000012203576,
540
+      -0.000010840992,   4.6299544e-7,     5.2588763e-7,     2.7792686e-7,
541
+      -2.3649704e-7,    -0.0000010897784, -9.171448e-7,     -5.22682e-7 }
542
+};
543
+
544
+/* Second half of the 384-tap IPQF filtering coefficients. */
545
+static const float ipqf_coeffs2[ATRAC3P_PQF_FIR_LEN][16] = {
546
+    {  5.22682e-7,       9.171448e-7,      0.0000010897784,  2.3649704e-7,
547
+      -2.7792686e-7,    -5.2588763e-7,    -4.6299544e-7,     0.000010840992,
548
+      -0.000012203576,  -0.000021961965,  -0.000021348773,  -0.000019907106,
549
+      -0.000017348082,  -0.000011984052,  -0.0000072701259, -0.0000062990207 },
550
+    {  0.0000099198869,  0.000013131184,   0.000014789486,   0.000019841305,
551
+       0.000026534748,   0.000033864744,   0.000041577889,   0.000049787737,
552
+      -0.000029687517,  -0.000036340745,  -0.000039477309,  -0.000042927582,
553
+      -0.000047133824,  -0.000054267788,  -0.00006174868,   -0.000064147389 },
554
+    {  0.00011279432,    0.00014691355,    0.00018116167,    0.0002197204,
555
+       0.00025986304,    0.00030001783,    0.0003392619,     0.00036942671,
556
+      -0.00042499689,   -0.00045358928,   -0.00048466062,   -0.00051135791,
557
+      -0.00053276919,   -0.00054783461,   -0.00055472925,   -0.00055432378 },
558
+    {  0.00097943726,    0.001125814,      0.0012685474,     0.0014046903,
559
+       0.0015320742,     0.0016481078,     0.0017501717,     0.00183808,
560
+      -0.0018990048,    -0.0019450618,    -0.0019653172,    -0.0019593791,
561
+      -0.0019252141,    -0.0018608454,    -0.0017651899,    -0.0016376863 },
562
+    {  0.0042418269,     0.0045959447,     0.0049146507,     0.0051914565,
563
+       0.0054194843,     0.0055920109,     0.0057025906,     0.0057445862,
564
+      -0.005714261,     -0.0056034233,    -0.0054091476,    -0.0051268316,
565
+      -0.0047529764,    -0.0042847847,    -0.0037203205,    -0.0030586775 },
566
+    {  0.019670162,      0.021246184,      0.022781773,      0.024265358,
567
+       0.025685543,      0.027031265,      0.028291954,      0.02945766,
568
+      -0.030518902,     -0.031467363,     -0.032295227,     -0.032995768,
569
+      -0.033563249,     -0.033992987,     -0.034281436,     -0.034426283 },
570
+    { -0.018065533,     -0.016444042,     -0.014817309,     -0.013196872,
571
+      -0.011593862,     -0.010018963,     -0.0084823566,    -0.0069935122,
572
+       0.0055614738,     0.0041943151,     0.0028992873,     0.001682895,
573
+       0.00055068987,   -0.00049266568,   -0.001443546,     -0.0022995141 },
574
+    { -0.0038591374,    -0.0034549395,    -0.0030352892,    -0.0026067684,
575
+      -0.0021754825,    -0.0017469483,    -0.001326357,     -0.00091862219,
576
+       0.00052769453,    0.00015771533,   -0.00018855913,   -0.00050782406,
577
+      -0.00079780724,   -0.0010566821,    -0.001283227,     -0.0014771431 },
578
+    { -0.00083093712,   -0.00068422867,   -0.00053928449,   -0.00039945057,
579
+      -0.00026649953,   -0.00014135583,   -0.000025081157,   0.000084307925,
580
+      -0.00018248901,   -0.00026866337,   -0.00034301577,   -0.00040612387,
581
+      -0.00045778,      -0.00049731287,   -0.00052537228,   -0.00054488552 },
582
+    { -0.00008079566,   -0.000053397067,  -0.00002610587,   -0.0000016657353,
583
+       0.000018532943,   0.000035615325,   0.000049888811,   0.000056296329,
584
+      -0.000058270442,  -0.000062285151,  -0.000070208509,  -0.000074850752,
585
+      -0.00007612785,   -0.000073081472,  -0.000068306952,  -0.000064464548 },
586
+    { -0.000048585582,  -0.000046043948,  -0.000045337845,  -0.000041575615,
587
+      -0.000036968919,  -0.000032302323,  -0.00002780562,   -0.000023530851,
588
+       0.0000018111954, -5.7168614e-7,    -0.0000015432918, -0.0000026336629,
589
+      -0.0000041712024, -0.0000079212787, -0.000010502935,  -0.0000091622824 },
590
+    { -0.0000070302972, -0.0000063894258, -0.0000046192422, -0.0000032569742,
591
+      -0.0000023108685, -0.0000014333754, -6.005389e-7,      0.000011838618,
592
+       0.000010516783,   1.2660377e-8,     3.530856e-8,      3.226247e-8,
593
+      -4.4400572e-8,    -4.2005411e-7,    -8.0604229e-7,    -5.8336207e-7 }
594
+};
595
+
596
+void ff_atrac3p_ipqf(FFTContext *dct_ctx, Atrac3pIPQFChannelCtx *hist,
597
+                     const float *in, float *out)
598
+{
599
+    int i, s, sb, t, pos_now, pos_next;
600
+    DECLARE_ALIGNED(32, float, idct_in)[ATRAC3P_SUBBANDS];
601
+    DECLARE_ALIGNED(32, float, idct_out)[ATRAC3P_SUBBANDS];
602
+
603
+    memset(out, 0, ATRAC3P_FRAME_SAMPLES * sizeof(*out));
604
+
605
+    for (s = 0; s < ATRAC3P_SUBBAND_SAMPLES; s++) {
606
+        /* pick up one sample from each subband */
607
+        for (sb = 0; sb < ATRAC3P_SUBBANDS; sb++)
608
+            idct_in[sb] = in[sb * ATRAC3P_SUBBAND_SAMPLES + s];
609
+
610
+        /* Calculate the sine and cosine part of the PQF using IDCT-IV */
611
+        dct_ctx->imdct_half(dct_ctx, idct_out, idct_in);
612
+
613
+        /* append the result to the history */
614
+        for (i = 0; i < 8; i++) {
615
+            hist->buf1[hist->pos][i] = idct_out[i + 8];
616
+            hist->buf2[hist->pos][i] = idct_out[7 - i];
617
+        }
618
+
619
+        pos_now  = hist->pos;
620
+        pos_next = mod23_lut[pos_now + 2]; // pos_next = (pos_now + 1) % 23;
621
+
622
+        for (t = 0; t < ATRAC3P_PQF_FIR_LEN; t++) {
623
+            for (i = 0; i < 8; i++) {
624
+                out[s * 16 + i + 0] += hist->buf1[pos_now][i]  * ipqf_coeffs1[t][i] +
625
+                                       hist->buf2[pos_next][i] * ipqf_coeffs2[t][i];
626
+                out[s * 16 + i + 8] += hist->buf1[pos_now][7 - i]  * ipqf_coeffs1[t][i + 8] +
627
+                                       hist->buf2[pos_next][7 - i] * ipqf_coeffs2[t][i + 8];
628
+            }
629
+
630
+            pos_now  = mod23_lut[pos_next + 2]; // pos_now  = (pos_now  + 2) % 23;
631
+            pos_next = mod23_lut[pos_now + 2];  // pos_next = (pos_next + 2) % 23;
632
+        }
633
+
634
+        hist->pos = mod23_lut[hist->pos]; // hist->pos = (hist->pos - 1) % 23;
635
+    }
636
+}
... ...
@@ -29,7 +29,7 @@
29 29
 #include "libavutil/version.h"
30 30
 
31 31
 #define LIBAVCODEC_VERSION_MAJOR 55
32
-#define LIBAVCODEC_VERSION_MINOR  46
32
+#define LIBAVCODEC_VERSION_MINOR  47
33 33
 #define LIBAVCODEC_VERSION_MICRO 100
34 34
 
35 35
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \