summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libcook
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libcook')
-rw-r--r--lib/rbcodec/codecs/libcook/README.rockbox47
-rw-r--r--lib/rbcodec/codecs/libcook/SOURCES2
-rw-r--r--lib/rbcodec/codecs/libcook/cook.c907
-rw-r--r--lib/rbcodec/codecs/libcook/cook.h131
-rw-r--r--lib/rbcodec/codecs/libcook/cook_fixpoint.h278
-rw-r--r--lib/rbcodec/codecs/libcook/cookdata.h493
-rw-r--r--lib/rbcodec/codecs/libcook/cookdata_fixpoint.h164
-rw-r--r--lib/rbcodec/codecs/libcook/libcook.make18
8 files changed, 2040 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libcook/README.rockbox b/lib/rbcodec/codecs/libcook/README.rockbox
new file mode 100644
index 0000000000..ae72f2a2f2
--- /dev/null
+++ b/lib/rbcodec/codecs/libcook/README.rockbox
@@ -0,0 +1,47 @@
1Library: libcook
2Imported by : Mohamed Tarek
3
4These files comprise a rm parser and a cook decoder based on the decoder
5from ffmpeg.
6
7LICENSING INFORMATION
8
9ffmpeg is licensed under the Lesser GNU General Public License and the
10file cook.c is Copyright 2003 Sascha Sommer and 2005 Benjamin Larsson.
11
12IMPORT DETAILS
13
14The decoder is based on ffmpeg-svn r18079.
15
16CONVERSION TO FIXED-POINT
17
18A patch from ffmpeg's mailing list was used to convert the decoder to
19use fixed-point arithmetic. The patch was done by Ian Braithwaite, and
20discussed here :
21
22http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/46024
23
24The patch is a bit dated (2007) so the modifications to cook.c had to
25be done manually. The patch was also applied to cookdata.h and was
26used to create cookdata_fixpoint.h, cook_fixpoint.h and
27cook_fixp_mdct.h.
28
29cook_fixp_mdct.h and parts from cookdata_fixpoint.h were dropped and
30rockbox's mdct library is now used in both the test program and the
31real codec.
32
33Note : Only parts of the patch were committed to ffmpeg's repository.
34
35TESTING
36
37The test program should compile in any Unix-like environment using the
38command "make -f Makefile.test".
39
40For ARM targets add -DCPU_ARM to CFLAGS in Makefile.test to make use of
41the asm ARM optimisations in rockbox's mdct library.
42
43For Big-endian targets, change -D"ROCKBOX_LITTLE_ENDIAN=1"
44to -D"ROCKBOX_BIG_ENDIAN=1" in Makefile.test.
45
46Running "./cooktest file.rm" will decode the audio data to a WAV file
47called "output.wav" in the current directory.
diff --git a/lib/rbcodec/codecs/libcook/SOURCES b/lib/rbcodec/codecs/libcook/SOURCES
new file mode 100644
index 0000000000..b656fdd2f7
--- /dev/null
+++ b/lib/rbcodec/codecs/libcook/SOURCES
@@ -0,0 +1,2 @@
1cook.c
2
diff --git a/lib/rbcodec/codecs/libcook/cook.c b/lib/rbcodec/codecs/libcook/cook.c
new file mode 100644
index 0000000000..29a1bab7d6
--- /dev/null
+++ b/lib/rbcodec/codecs/libcook/cook.c
@@ -0,0 +1,907 @@
1/*
2 * COOK compatible decoder
3 * Copyright (c) 2003 Sascha Sommer
4 * Copyright (c) 2005 Benjamin Larsson
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/**
24 * @file cook.c
25 * Cook compatible decoder. Bastardization of the G.722.1 standard.
26 * This decoder handles RealNetworks, RealAudio G2 data.
27 * Cook is identified by the codec name cook in RM files.
28 *
29 * To use this decoder, a calling application must supply the extradata
30 * bytes provided from the RM container; 8+ bytes for mono streams and
31 * 16+ for stereo streams (maybe more).
32 *
33 * Codec technicalities (all this assume a buffer length of 1024):
34 * Cook works with several different techniques to achieve its compression.
35 * In the timedomain the buffer is divided into 8 pieces and quantized. If
36 * two neighboring pieces have different quantization index a smooth
37 * quantization curve is used to get a smooth overlap between the different
38 * pieces.
39 * To get to the transformdomain Cook uses a modulated lapped transform.
40 * The transform domain has 50 subbands with 20 elements each. This
41 * means only a maximum of 50*20=1000 coefficients are used out of the 1024
42 * available.
43 */
44
45#include <math.h>
46#include <stddef.h>
47#include <stdio.h>
48#include <limits.h>
49#include <string.h>
50#include "codeclib.h"
51
52#include "cook.h"
53#include "cookdata.h"
54
55/* the different Cook versions */
56#define MONO 0x1000001
57#define STEREO 0x1000002
58#define JOINT_STEREO 0x1000003
59#define MC_COOK 0x2000000 //multichannel Cook, not supported
60
61#define SUBBAND_SIZE 20
62#define MAX_SUBPACKETS 5
63//#define COOKDEBUG
64#ifndef COOKDEBUG
65#undef DEBUGF
66#define DEBUGF(...)
67#endif
68
69/**
70 * Random bit stream generator.
71 */
72static inline int cook_random(COOKContext *q)
73{
74 q->random_state =
75 q->random_state * 214013 + 2531011; /* typical RNG numbers */
76
77 return (q->random_state/0x1000000)&1; /*>>31*/
78}
79#include "cook_fixpoint.h"
80
81/* debug functions */
82
83#ifdef COOKDEBUG
84static void dump_int_table(int* table, int size, int delimiter) {
85 int i=0;
86 DEBUGF("\n[%d]: ",i);
87 for (i=0 ; i<size ; i++) {
88 DEBUGF("%d, ", table[i]);
89 if ((i+1)%delimiter == 0) DEBUGF("\n[%d]: ",i+1);
90 }
91}
92
93static void dump_short_table(short* table, int size, int delimiter) {
94 int i=0;
95 DEBUGF("\n[%d]: ",i);
96 for (i=0 ; i<size ; i++) {
97 DEBUGF("%d, ", table[i]);
98 if ((i+1)%delimiter == 0) DEBUGF("\n[%d]: ",i+1);
99 }
100}
101
102#endif
103
104/*************** init functions ***************/
105/* Codebook sizes (11586 * 4 bytes in total) */
106/* Used for envelope_quant_index[]. */
107static VLC_TYPE vlcbuf00[ 520][2] IBSS_ATTR_COOK_LARGE_IRAM;
108static VLC_TYPE vlcbuf01[ 640][2] IBSS_ATTR_COOK_LARGE_IRAM;
109static VLC_TYPE vlcbuf02[ 544][2] IBSS_ATTR_COOK_LARGE_IRAM;
110static VLC_TYPE vlcbuf03[ 528][2] IBSS_ATTR_COOK_VLCBUF;
111static VLC_TYPE vlcbuf04[ 544][2] IBSS_ATTR_COOK_VLCBUF;
112static VLC_TYPE vlcbuf05[ 544][2] IBSS_ATTR_COOK_VLCBUF;
113static VLC_TYPE vlcbuf06[ 640][2] IBSS_ATTR_COOK_VLCBUF;
114static VLC_TYPE vlcbuf07[ 576][2] IBSS_ATTR_COOK_VLCBUF;
115static VLC_TYPE vlcbuf08[ 528][2] IBSS_ATTR_COOK_VLCBUF;
116static VLC_TYPE vlcbuf09[ 544][2] IBSS_ATTR_COOK_VLCBUF;
117static VLC_TYPE vlcbuf10[ 544][2] IBSS_ATTR_COOK_VLCBUF;
118static VLC_TYPE vlcbuf11[ 640][2] IBSS_ATTR_COOK_VLCBUF;
119static VLC_TYPE vlcbuf12[ 544][2] IBSS_ATTR_COOK_LARGE_IRAM;
120/* Used for sqvh[]. */
121static VLC_TYPE vlcbuf13[ 622][2] IBSS_ATTR_COOK_LARGE_IRAM;
122static VLC_TYPE vlcbuf14[ 308][2] IBSS_ATTR_COOK_LARGE_IRAM;
123static VLC_TYPE vlcbuf15[ 280][2] IBSS_ATTR_COOK_LARGE_IRAM;
124static VLC_TYPE vlcbuf16[1456][2] IBSS_ATTR_COOK_LARGE_IRAM;
125static VLC_TYPE vlcbuf17[ 694][2] IBSS_ATTR_COOK_LARGE_IRAM;
126static VLC_TYPE vlcbuf18[ 698][2] IBSS_ATTR_COOK_LARGE_IRAM;
127static VLC_TYPE vlcbuf19[ 104][2] IBSS_ATTR_COOK_LARGE_IRAM;
128/* Used for ccpl. */
129static VLC_TYPE vlcbuf20[ 88][2] IBSS_ATTR_COOK_VLCBUF;
130
131/* Code book sizes (11586 entries in total) */
132static int env_size[13] = {520,640,544, 528,544,544,640,576,528,544,544,640,544};
133static int sqvh_size[7] = {622,308,280,1456,694,698,104};
134static int ccpl_size = 88;
135
136
137static int init_cook_vlc_tables(COOKContext *q) {
138 int i, result = 0;
139
140 /* Set pointers for codebooks. */
141 q->envelope_quant_index[ 0].table = vlcbuf00;
142 q->envelope_quant_index[ 1].table = vlcbuf01;
143 q->envelope_quant_index[ 2].table = vlcbuf02;
144 q->envelope_quant_index[ 3].table = vlcbuf03;
145 q->envelope_quant_index[ 4].table = vlcbuf04;
146 q->envelope_quant_index[ 5].table = vlcbuf05;
147 q->envelope_quant_index[ 6].table = vlcbuf06;
148 q->envelope_quant_index[ 7].table = vlcbuf07;
149 q->envelope_quant_index[ 8].table = vlcbuf08;
150 q->envelope_quant_index[ 9].table = vlcbuf09;
151 q->envelope_quant_index[10].table = vlcbuf10;
152 q->envelope_quant_index[11].table = vlcbuf11;
153 q->envelope_quant_index[12].table = vlcbuf12;
154 q->sqvh[0].table = vlcbuf13;
155 q->sqvh[1].table = vlcbuf14;
156 q->sqvh[2].table = vlcbuf15;
157 q->sqvh[3].table = vlcbuf16;
158 q->sqvh[4].table = vlcbuf17;
159 q->sqvh[5].table = vlcbuf18;
160 q->sqvh[6].table = vlcbuf19;
161 q->ccpl.table = vlcbuf20;
162
163 /* Init envelope VLC (13 books) */
164 for (i=0 ; i<13 ; i++) {
165 q->envelope_quant_index[i].table_allocated = env_size[i];
166 result |= init_vlc (&q->envelope_quant_index[i], 9, 24,
167 envelope_quant_index_huffbits[i], 1, 1,
168 envelope_quant_index_huffcodes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
169 }
170
171 /* Init subband VLC (7 books) */
172 for (i=0 ; i<7 ; i++) {
173 q->sqvh[i].table_allocated = sqvh_size[i];
174 result |= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
175 cvh_huffbits[i], 1, 1,
176 cvh_huffcodes[i], 2, 2, INIT_VLC_USE_NEW_STATIC);
177 }
178
179 /* Init Joint-Stereo VLC (1 book) */
180 if (q->nb_channels==2 && q->joint_stereo==1){
181 q->ccpl.table_allocated = ccpl_size;
182 result |= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1,
183 ccpl_huffbits[q->js_vlc_bits-2], 1, 1,
184 ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, INIT_VLC_USE_NEW_STATIC);
185 DEBUGF("Joint-stereo VLC used.\n");
186 }
187
188 DEBUGF("VLC tables initialized. Result = %d\n",result);
189 return result;
190}
191/*************** init functions end ***********/
192
193/**
194 * Cook indata decoding, every 32 bits are XORed with 0x37c511f2.
195 * Why? No idea, some checksum/error detection method maybe.
196 *
197 * Out buffer size: extra bytes are needed to cope with
198 * padding/misalignment.
199 * Subpackets passed to the decoder can contain two, consecutive
200 * half-subpackets, of identical but arbitrary size.
201 * 1234 1234 1234 1234 extraA extraB
202 * Case 1: AAAA BBBB 0 0
203 * Case 2: AAAA ABBB BB-- 3 3
204 * Case 3: AAAA AABB BBBB 2 2
205 * Case 4: AAAA AAAB BBBB BB-- 1 5
206 *
207 * Nice way to waste CPU cycles.
208 *
209 * @param inbuffer pointer to byte array of indata
210 * @param out pointer to byte array of outdata
211 * @param bytes number of bytes
212 */
213#define DECODE_BYTES_PAD1(bytes) (3 - ((bytes)+3) % 4)
214#define DECODE_BYTES_PAD2(bytes) ((bytes) % 4 + DECODE_BYTES_PAD1(2 * (bytes)))
215
216static inline int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){
217 int i, off;
218 uint32_t c;
219 const uint32_t* buf;
220 uint32_t* obuf = (uint32_t*) out;
221 /* FIXME: 64 bit platforms would be able to do 64 bits at a time.
222 * I'm too lazy though, should be something like
223 * for(i=0 ; i<bitamount/64 ; i++)
224 * (int64_t)out[i] = 0x37c511f237c511f2^be2me_64(int64_t)in[i]);
225 * Buffer alignment needs to be checked. */
226
227 off = (intptr_t)inbuffer & 3;
228 buf = (const uint32_t*) (inbuffer - off);
229 c = be2me_32((0x37c511f2 >> (off*8)) | (0x37c511f2 << (32-(off*8))));
230 bytes += 3 + off;
231 for (i = 0; i < bytes/4; i++)
232 obuf[i] = c ^ buf[i];
233
234 return off;
235}
236
237/**
238 * Fill the gain array for the timedomain quantization.
239 *
240 * @param q pointer to the COOKContext
241 * @param gaininfo[9] array of gain indexes
242 */
243
244static void decode_gain_info(GetBitContext *gb, int *gaininfo)
245{
246 int i, n;
247
248 while (get_bits1(gb)) {}
249 n = get_bits_count(gb) - 1; //amount of elements*2 to update
250
251 i = 0;
252 while (n--) {
253 int index = get_bits(gb, 3);
254 int gain = get_bits1(gb) ? (int)get_bits(gb, 4) - 7 : -1;
255
256 while (i <= index) gaininfo[i++] = gain;
257 }
258 while (i <= 8) gaininfo[i++] = 0;
259}
260
261/**
262 * Create the quant index table needed for the envelope.
263 *
264 * @param q pointer to the COOKContext
265 * @param quant_index_table pointer to the array
266 */
267
268static void decode_envelope(COOKContext *q, int* quant_index_table) {
269 int i,j, vlc_index;
270
271 quant_index_table[0]= get_bits(&q->gb,6) - 6; //This is used later in categorize
272
273 for (i=1 ; i < q->total_subbands ; i++){
274 vlc_index=i;
275 if (i >= q->js_subband_start * 2) {
276 vlc_index-=q->js_subband_start;
277 } else {
278 vlc_index/=2;
279 if(vlc_index < 1) vlc_index = 1;
280 }
281 if (vlc_index>13) vlc_index = 13; //the VLC tables >13 are identical to No. 13
282
283 j = get_vlc2(&q->gb, q->envelope_quant_index[vlc_index-1].table,
284 q->envelope_quant_index[vlc_index-1].bits,2);
285 quant_index_table[i] = quant_index_table[i-1] + j - 12; //differential encoding
286 }
287}
288
289/**
290 * Calculate the category and category_index vector.
291 *
292 * @param q pointer to the COOKContext
293 * @param quant_index_table pointer to the array
294 * @param category pointer to the category array
295 * @param category_index pointer to the category_index array
296 */
297
298static void categorize(COOKContext *q, int* quant_index_table,
299 int* category, int* category_index){
300 int exp_idx, bias, tmpbias1, tmpbias2, bits_left, num_bits, index, v, i, j;
301 int exp_index2[102];
302 int exp_index1[102];
303
304 int tmp_categorize_array[128*2];
305 int tmp_categorize_array1_idx=q->numvector_size;
306 int tmp_categorize_array2_idx=q->numvector_size;
307
308 bits_left = q->bits_per_subpacket - get_bits_count(&q->gb);
309
310 if(bits_left > q->samples_per_channel) {
311 bits_left = q->samples_per_channel +
312 ((bits_left - q->samples_per_channel)*5)/8;
313 //av_log(q->avctx, AV_LOG_ERROR, "bits_left = %d\n",bits_left);
314 }
315
316 memset(&exp_index1,0,102*sizeof(int));
317 memset(&exp_index2,0,102*sizeof(int));
318 memset(&tmp_categorize_array,0,128*2*sizeof(int));
319
320 bias=-32;
321
322 /* Estimate bias. */
323 for (i=32 ; i>0 ; i=i/2){
324 num_bits = 0;
325 index = 0;
326 for (j=q->total_subbands ; j>0 ; j--){
327 exp_idx = av_clip((i - quant_index_table[index] + bias) / 2, 0, 7);
328 index++;
329 num_bits+=expbits_tab[exp_idx];
330 }
331 if(num_bits >= bits_left - 32){
332 bias+=i;
333 }
334 }
335
336 /* Calculate total number of bits. */
337 num_bits=0;
338 for (i=0 ; i<q->total_subbands ; i++) {
339 exp_idx = av_clip((bias - quant_index_table[i]) / 2, 0, 7);
340 num_bits += expbits_tab[exp_idx];
341 exp_index1[i] = exp_idx;
342 exp_index2[i] = exp_idx;
343 }
344 tmpbias1 = tmpbias2 = num_bits;
345
346 for (j = 1 ; j < q->numvector_size ; j++) {
347 if (tmpbias1 + tmpbias2 > 2*bits_left) { /* ---> */
348 int max = -999999;
349 index=-1;
350 for (i=0 ; i<q->total_subbands ; i++){
351 if (exp_index1[i] < 7) {
352 v = (-2*exp_index1[i]) - quant_index_table[i] + bias;
353 if ( v >= max) {
354 max = v;
355 index = i;
356 }
357 }
358 }
359 if(index==-1)break;
360 tmp_categorize_array[tmp_categorize_array1_idx++] = index;
361 tmpbias1 -= expbits_tab[exp_index1[index]] -
362 expbits_tab[exp_index1[index]+1];
363 ++exp_index1[index];
364 } else { /* <--- */
365 int min = 999999;
366 index=-1;
367 for (i=0 ; i<q->total_subbands ; i++){
368 if(exp_index2[i] > 0){
369 v = (-2*exp_index2[i])-quant_index_table[i]+bias;
370 if ( v < min) {
371 min = v;
372 index = i;
373 }
374 }
375 }
376 if(index == -1)break;
377 tmp_categorize_array[--tmp_categorize_array2_idx] = index;
378 tmpbias2 -= expbits_tab[exp_index2[index]] -
379 expbits_tab[exp_index2[index]-1];
380 --exp_index2[index];
381 }
382 }
383 memcpy(category, exp_index2, sizeof(int) * q->total_subbands );
384 memcpy(category_index, tmp_categorize_array+tmp_categorize_array2_idx, sizeof(int) * (q->numvector_size-1) );
385}
386
387
388/**
389 * Expand the category vector.
390 *
391 * @param q pointer to the COOKContext
392 * @param category pointer to the category array
393 * @param category_index pointer to the category_index array
394 */
395
396static inline void expand_category(COOKContext *q, int* category,
397 int* category_index){
398 int i;
399 for(i=0 ; i<q->num_vectors ; i++){
400 ++category[category_index[i]];
401 }
402}
403
404/**
405 * Unpack the subband_coef_index and subband_coef_sign vectors.
406 *
407 * @param q pointer to the COOKContext
408 * @param category pointer to the category array
409 * @param subband_coef_index array of indexes to quant_centroid_tab
410 * @param subband_coef_sign signs of coefficients
411 */
412
413static int unpack_SQVH(COOKContext *q, int category, int* subband_coef_index,
414 int* subband_coef_sign) {
415 int i,j;
416 int vlc, vd ,tmp, result;
417
418 vd = vd_tab[category];
419 result = 0;
420 for(i=0 ; i<vpr_tab[category] ; i++)
421 {
422 vlc = get_vlc2(&q->gb, q->sqvh[category].table, q->sqvh[category].bits, 3);
423 if (q->bits_per_subpacket < get_bits_count(&q->gb))
424 {
425 vlc = 0;
426 result = 1;
427 memset(subband_coef_index, 0, sizeof(int)*vd);
428 memset(subband_coef_sign, 0, sizeof(int)*vd);
429 subband_coef_index+=vd;
430 subband_coef_sign+=vd;
431 }
432 else
433 {
434 for(j=vd-1 ; j>=0 ; j--){
435 tmp = (vlc * invradix_tab[category])/0x100000;
436 subband_coef_index[j] = vlc - tmp * (kmax_tab[category]+1);
437 vlc = tmp;
438 }
439
440 for(j=0 ; j<vd ; j++)
441 {
442 if (*subband_coef_index++) {
443 if(get_bits_count(&q->gb) < q->bits_per_subpacket) {
444 *subband_coef_sign++ = get_bits1(&q->gb);
445 } else {
446 result=1;
447 *subband_coef_sign++=0;
448 }
449 } else {
450 *subband_coef_sign++=0;
451 }
452 }
453 }
454 }
455 return result;
456}
457
458
459/**
460 * Fill the mlt_buffer with mlt coefficients.
461 *
462 * @param q pointer to the COOKContext
463 * @param category pointer to the category array
464 * @param quant_index_table pointer to the array
465 * @param mlt_buffer pointer to mlt coefficients
466 */
467
468static void decode_vectors(COOKContext* q, int* category,
469 int *quant_index_table, REAL_T* mlt_buffer)
470 ICODE_ATTR_COOK_DECODE;
471static void decode_vectors(COOKContext* q, int* category,
472 int *quant_index_table, REAL_T* mlt_buffer){
473 /* A zero in this table means that the subband coefficient is
474 random noise coded. */
475 int subband_coef_index[SUBBAND_SIZE];
476 /* A zero in this table means that the subband coefficient is a
477 positive multiplicator. */
478 int subband_coef_sign[SUBBAND_SIZE];
479 int band, j;
480 int index=0;
481
482 for(band=0 ; band<q->total_subbands ; band++){
483 index = category[band];
484 if(category[band] < 7){
485 if(unpack_SQVH(q, category[band], subband_coef_index, subband_coef_sign)){
486 index=7;
487 for(j=0 ; j<q->total_subbands ; j++) category[band+j]=7;
488 }
489 }
490 if(index>=7) {
491 memset(subband_coef_index, 0, sizeof(subband_coef_index));
492 memset(subband_coef_sign, 0, sizeof(subband_coef_sign));
493 }
494 scalar_dequant_math(q, index, quant_index_table[band],
495 subband_coef_index, subband_coef_sign,
496 &mlt_buffer[band * SUBBAND_SIZE]);
497 }
498
499 if(q->total_subbands*SUBBAND_SIZE >= q->samples_per_channel){
500 return;
501 } /* FIXME: should this be removed, or moved into loop above? */
502}
503
504
505/**
506 * function for decoding mono data
507 *
508 * @param q pointer to the COOKContext
509 * @param mlt_buffer pointer to mlt coefficients
510 */
511
512static void mono_decode(COOKContext *q, REAL_T* mlt_buffer) ICODE_ATTR_COOK_DECODE;
513static void mono_decode(COOKContext *q, REAL_T* mlt_buffer) {
514
515 int category_index[128];
516 int quant_index_table[102];
517 int category[128];
518
519 memset(&category, 0, 128*sizeof(int));
520 memset(&category_index, 0, 128*sizeof(int));
521
522 decode_envelope(q, quant_index_table);
523 q->num_vectors = get_bits(&q->gb,q->log2_numvector_size);
524 categorize(q, quant_index_table, category, category_index);
525 expand_category(q, category, category_index);
526 decode_vectors(q, category, quant_index_table, mlt_buffer);
527}
528
529/**
530 * function for getting the jointstereo coupling information
531 *
532 * @param q pointer to the COOKContext
533 * @param decouple_tab decoupling array
534 *
535 */
536
537static void decouple_info(COOKContext *q, int* decouple_tab){
538 int length, i;
539
540 if(get_bits1(&q->gb)) {
541 if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
542
543 length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
544 for (i=0 ; i<length ; i++) {
545 decouple_tab[cplband[q->js_subband_start] + i] = get_vlc2(&q->gb, q->ccpl.table, q->ccpl.bits, 2);
546 }
547 return;
548 }
549
550 if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
551
552 length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
553 for (i=0 ; i<length ; i++) {
554 decouple_tab[cplband[q->js_subband_start] + i] = get_bits(&q->gb, q->js_vlc_bits);
555 }
556 return;
557}
558
559/**
560 * function for decoding joint stereo data
561 *
562 * @param q pointer to the COOKContext
563 * @param mlt_buffer1 pointer to left channel mlt coefficients
564 * @param mlt_buffer2 pointer to right channel mlt coefficients
565 */
566
567static void joint_decode(COOKContext *q, REAL_T* mlt_buffer1,
568 REAL_T* mlt_buffer2) {
569 int i;
570 int decouple_tab[SUBBAND_SIZE];
571 REAL_T *decode_buffer = q->decode_buffer_0;
572 int idx;
573
574 memset(decouple_tab, 0, sizeof(decouple_tab));
575 memset(decode_buffer, 0, sizeof(q->decode_buffer_0));
576
577 /* Make sure the buffers are zeroed out. */
578 memset(mlt_buffer1,0, 1024*sizeof(REAL_T));
579 memset(mlt_buffer2,0, 1024*sizeof(REAL_T));
580 decouple_info(q, decouple_tab);
581 mono_decode(q, decode_buffer);
582
583 /* The two channels are stored interleaved in decode_buffer. */
584 REAL_T * mlt_buffer1_end = mlt_buffer1 + (q->js_subband_start*SUBBAND_SIZE);
585 while(mlt_buffer1 < mlt_buffer1_end)
586 {
587 memcpy(mlt_buffer1,decode_buffer,sizeof(REAL_T)*SUBBAND_SIZE);
588 memcpy(mlt_buffer2,decode_buffer+20,sizeof(REAL_T)*SUBBAND_SIZE);
589 mlt_buffer1 += 20;
590 mlt_buffer2 += 20;
591 decode_buffer += 40;
592 }
593
594 /* When we reach js_subband_start (the higher frequencies)
595 the coefficients are stored in a coupling scheme. */
596 idx = (1 << q->js_vlc_bits) - 1;
597 for (i=q->js_subband_start ; i<q->subbands ; i++) {
598 int i1 = decouple_tab[cplband[i]];
599 int i2 = idx - i1 - 1;
600 mlt_buffer1_end = mlt_buffer1 + SUBBAND_SIZE;
601 while(mlt_buffer1 < mlt_buffer1_end)
602 {
603 *mlt_buffer1++ = cplscale_math(*decode_buffer, q->js_vlc_bits, i1);
604 *mlt_buffer2++ = cplscale_math(*decode_buffer++, q->js_vlc_bits, i2);
605 }
606 mlt_buffer1 += (20-SUBBAND_SIZE);
607 mlt_buffer2 += (20-SUBBAND_SIZE);
608 decode_buffer += (20-SUBBAND_SIZE);
609 }
610}
611
612/**
613 * First part of subpacket decoding:
614 * decode raw stream bytes and read gain info.
615 *
616 * @param q pointer to the COOKContext
617 * @param inbuffer pointer to raw stream data
618 * @param gain_ptr array of current/prev gain pointers
619 */
620
621#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
622
623static inline void
624decode_bytes_and_gain(COOKContext *q, const uint8_t *inbuffer,
625 cook_gains *gains_ptr)
626{
627 int offset;
628
629 offset = decode_bytes(inbuffer, q->decoded_bytes_buffer,
630 q->bits_per_subpacket/8);
631 init_get_bits(&q->gb, q->decoded_bytes_buffer + offset,
632 q->bits_per_subpacket);
633 decode_gain_info(&q->gb, gains_ptr->now);
634
635 /* Swap current and previous gains */
636 FFSWAP(int *, gains_ptr->now, gains_ptr->previous);
637}
638
639/**
640 * Final part of subpacket decoding:
641 * Apply modulated lapped transform, gain compensation,
642 * clip and convert to integer.
643 *
644 * @param q pointer to the COOKContext
645 * @param decode_buffer pointer to the mlt coefficients
646 * @param gain_ptr array of current/prev gain pointers
647 * @param previous_buffer pointer to the previous buffer to be used for overlapping
648 * @param out pointer to the output buffer
649 * @param chan 0: left or single channel, 1: right channel
650 */
651
652static void
653mlt_compensate_output(COOKContext *q, REAL_T *decode_buffer,
654 cook_gains *gains, REAL_T *previous_buffer,
655 int32_t *out, int chan)
656{
657 REAL_T *buffer = q->mono_mdct_output;
658 int i;
659 imlt_math(q, decode_buffer);
660
661 /* Overlap with the previous block. */
662 overlap_math(q, gains->previous[0], previous_buffer);
663
664 /* Apply gain profile */
665 for (i = 0; i < 8; i++) {
666 if (gains->now[i] || gains->now[i + 1])
667 interpolate_math(q, &buffer[q->samples_per_channel/8 * i],
668 gains->now[i], gains->now[i + 1]);
669 }
670
671 /* Save away the current to be previous block. */
672 memcpy(previous_buffer, buffer+q->samples_per_channel,
673 sizeof(REAL_T)*q->samples_per_channel);
674
675 /* Copy output to non-interleaved sample buffer */
676 memcpy(out + (chan * q->samples_per_channel), buffer,
677 sizeof(REAL_T)*q->samples_per_channel);
678}
679
680
681/**
682 * Cook subpacket decoding. This function returns one decoded subpacket,
683 * usually 1024 samples per channel.
684 *
685 * @param q pointer to the COOKContext
686 * @param inbuffer pointer to the inbuffer
687 * @param sub_packet_size subpacket size
688 * @param outbuffer pointer to the outbuffer
689 */
690
691
692static int decode_subpacket(COOKContext *q, const uint8_t *inbuffer,
693 int sub_packet_size, int32_t *outbuffer) {
694 /* packet dump */
695// for (i=0 ; i<sub_packet_size ; i++) {
696// DEBUGF("%02x", inbuffer[i]);
697// }
698// DEBUGF("\n");
699
700 decode_bytes_and_gain(q, inbuffer, &q->gains1);
701
702 if (q->joint_stereo) {
703 joint_decode(q, q->decode_buffer_1, q->decode_buffer_2);
704 } else {
705 mono_decode(q, q->decode_buffer_1);
706
707 if (q->nb_channels == 2) {
708 decode_bytes_and_gain(q, inbuffer + sub_packet_size/2, &q->gains2);
709 mono_decode(q, q->decode_buffer_2);
710 }
711 }
712
713 mlt_compensate_output(q, q->decode_buffer_1, &q->gains1,
714 q->mono_previous_buffer1, outbuffer, 0);
715
716 if (q->nb_channels == 2) {
717 if (q->joint_stereo) {
718 mlt_compensate_output(q, q->decode_buffer_2, &q->gains1,
719 q->mono_previous_buffer2, outbuffer, 1);
720 } else {
721 mlt_compensate_output(q, q->decode_buffer_2, &q->gains2,
722 q->mono_previous_buffer2, outbuffer, 1);
723 }
724 }
725 return q->samples_per_frame * sizeof(int32_t);
726}
727
728
729/**
730 * Cook frame decoding
731 *
732 * @param rmctx pointer to the RMContext
733 */
734
735int cook_decode_frame(RMContext *rmctx,COOKContext *q,
736 int32_t *outbuffer, int *data_size,
737 const uint8_t *inbuffer, int buf_size) {
738 //COOKContext *q = avctx->priv_data;
739 //COOKContext *q;
740
741 if (buf_size < rmctx->block_align)
742 return buf_size;
743
744 *data_size = decode_subpacket(q, inbuffer, rmctx->block_align, outbuffer);
745
746 /* Discard the first two frames: no valid audio. */
747 if (rmctx->frame_number < 2) *data_size = 0;
748
749 return rmctx->block_align;
750}
751
752#ifdef COOKDEBUG
753static void dump_cook_context(COOKContext *q)
754{
755 //int i=0;
756#define PRINT(a,b) DEBUGF(" %s = %d\n", a, b);
757 DEBUGF("COOKextradata\n");
758 DEBUGF("cookversion=%x\n",q->cookversion);
759 if (q->cookversion > STEREO) {
760 PRINT("js_subband_start",q->js_subband_start);
761 PRINT("js_vlc_bits",q->js_vlc_bits);
762 }
763 PRINT("nb_channels",q->nb_channels);
764 PRINT("bit_rate",q->bit_rate);
765 PRINT("sample_rate",q->sample_rate);
766 PRINT("samples_per_channel",q->samples_per_channel);
767 PRINT("samples_per_frame",q->samples_per_frame);
768 PRINT("subbands",q->subbands);
769 PRINT("random_state",q->random_state);
770 PRINT("js_subband_start",q->js_subband_start);
771 PRINT("log2_numvector_size",q->log2_numvector_size);
772 PRINT("numvector_size",q->numvector_size);
773 PRINT("total_subbands",q->total_subbands);
774}
775#endif
776
777/**
778 * Cook initialization
779 */
780
781int cook_decode_init(RMContext *rmctx, COOKContext *q)
782{
783#if defined(CPU_COLDFIRE)
784 coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE);
785#endif
786 /* cook extradata */
787 q->cookversion = rm_get_uint32be(rmctx->codec_extradata);
788 q->samples_per_frame = rm_get_uint16be(&rmctx->codec_extradata[4]);
789 q->subbands = rm_get_uint16be(&rmctx->codec_extradata[6]);
790 q->extradata_size = rmctx->extradata_size;
791 if (q->extradata_size >= 16){
792 q->js_subband_start = rm_get_uint16be(&rmctx->codec_extradata[12]);
793 q->js_vlc_bits = rm_get_uint16be(&rmctx->codec_extradata[14]);
794 }
795
796 /* Take data from the RMContext (RM container). */
797 q->sample_rate = rmctx->sample_rate;
798 q->nb_channels = rmctx->nb_channels;
799 q->bit_rate = rmctx->bit_rate;
800
801 /* Initialize RNG. */
802 q->random_state = 0;
803
804 /* Initialize extradata related variables. */
805 q->samples_per_channel = q->samples_per_frame >> (q->nb_channels-1);
806 q->bits_per_subpacket = rmctx->block_align * 8;
807
808 /* Initialize default data states. */
809 q->log2_numvector_size = 5;
810 q->total_subbands = q->subbands;
811
812 /* Initialize version-dependent variables */
813 DEBUGF("q->cookversion=%x\n",q->cookversion);
814 q->joint_stereo = 0;
815 switch (q->cookversion) {
816 case MONO:
817 if (q->nb_channels != 1) {
818 DEBUGF("Container channels != 1, report sample!\n");
819 return -1;
820 }
821 DEBUGF("MONO\n");
822 break;
823 case STEREO:
824 if (q->nb_channels != 1) {
825 q->bits_per_subpacket = q->bits_per_subpacket/2;
826 }
827 DEBUGF("STEREO\n");
828 break;
829 case JOINT_STEREO:
830 if (q->nb_channels != 2) {
831 DEBUGF("Container channels != 2, report sample!\n");
832 return -1;
833 }
834 DEBUGF("JOINT_STEREO\n");
835 if (q->extradata_size >= 16){
836 q->total_subbands = q->subbands + q->js_subband_start;
837 q->joint_stereo = 1;
838 }
839 if (q->samples_per_channel > 256) {
840 q->log2_numvector_size = 6;
841 }
842 if (q->samples_per_channel > 512) {
843 q->log2_numvector_size = 7;
844 }
845 break;
846 case MC_COOK:
847 DEBUGF("MC_COOK not supported!\n");
848 return -1;
849 break;
850 default:
851 DEBUGF("Unknown Cook version, report sample!\n");
852 return -1;
853 break;
854 }
855
856 /* Initialize variable relations */
857 q->numvector_size = (1 << q->log2_numvector_size);
858 q->mdct_nbits = av_log2(q->samples_per_channel)+1;
859
860 /* Generate tables */
861 if (init_cook_vlc_tables(q) != 0)
862 return -1;
863
864
865 if(rmctx->block_align >= UINT16_MAX/2)
866 return -1;
867
868 q->gains1.now = q->gain_1;
869 q->gains1.previous = q->gain_2;
870 q->gains2.now = q->gain_3;
871 q->gains2.previous = q->gain_4;
872
873
874 /* Initialize COOK signal arithmetic handling */
875 /*
876 if (1) {
877 q->scalar_dequant = scalar_dequant_math;
878 q->interpolate = interpolate_math;
879 }
880 */
881
882 /* Try to catch some obviously faulty streams, othervise it might be exploitable */
883 if (q->total_subbands > 53) {
884 DEBUGF("total_subbands > 53, report sample!\n");
885 return -1;
886 }
887 if (q->subbands > 50) {
888 DEBUGF("subbands > 50, report sample!\n");
889 return -1;
890 }
891 if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) {
892 } else {
893 DEBUGF("unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel);
894 return -1;
895 }
896 if ((q->js_vlc_bits > 6) || (q->js_vlc_bits < 0)) {
897 DEBUGF("q->js_vlc_bits = %d, only >= 0 and <= 6 allowed!\n",q->js_vlc_bits);
898 return -1;
899 }
900
901
902#ifdef COOKDEBUG
903 dump_cook_context(q);
904#endif
905 return 0;
906}
907
diff --git a/lib/rbcodec/codecs/libcook/cook.h b/lib/rbcodec/codecs/libcook/cook.h
new file mode 100644
index 0000000000..fcb437a0e1
--- /dev/null
+++ b/lib/rbcodec/codecs/libcook/cook.h
@@ -0,0 +1,131 @@
1/*
2 * COOK compatible decoder
3 * Copyright (c) 2003 Sascha Sommer
4 * Copyright (c) 2005 Benjamin Larsson
5 *
6 * This file is taken from FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22#ifndef _COOK_H
23#define _COOK_H
24
25#include <inttypes.h>
26#include "ffmpeg_get_bits.h"
27#include "../librm/rm.h"
28#include "cookdata_fixpoint.h"
29
30#include "codeclib.h"
31
32#if (CONFIG_CPU == PP5022) || (CONFIG_CPU == PP5024) || (CONFIG_CPU == MCF5250)
33/* PP5022/24, MCF5250 have large IRAM */
34#define IBSS_ATTR_COOK_LARGE_IRAM IBSS_ATTR
35#define ICODE_ATTR_COOK_LARGE_IRAM ICODE_ATTR
36#define ICONST_ATTR_COOK_LARGE_IRAM ICONST_ATTR
37#define IBSS_ATTR_COOK_VLCBUF
38#define ICODE_ATTR_COOK_DECODE
39
40#elif defined(CPU_S5L870X)
41/* S5L870X have even larger IRAM and it is faster to use ICODE_ATTR. */
42#define IBSS_ATTR_COOK_LARGE_IRAM IBSS_ATTR
43#define ICODE_ATTR_COOK_LARGE_IRAM ICODE_ATTR
44#define ICONST_ATTR_COOK_LARGE_IRAM ICONST_ATTR
45#define IBSS_ATTR_COOK_VLCBUF IBSS_ATTR
46#define ICODE_ATTR_COOK_DECODE ICODE_ATTR
47
48#else
49/* other CPUs IRAM is not large enough */
50#define IBSS_ATTR_COOK_LARGE_IRAM
51#define ICODE_ATTR_COOK_LARGE_IRAM
52#define ICONST_ATTR_COOK_LARGE_IRAM
53#define IBSS_ATTR_COOK_VLCBUF
54#define ICODE_ATTR_COOK_DECODE
55
56#endif
57
58typedef struct {
59 int *now;
60 int *previous;
61} cook_gains;
62
63typedef struct cook {
64 /*
65 * The following 2 functions provide the lowlevel arithmetic on
66 * the internal audio buffers.
67 */
68 void (* scalar_dequant)(struct cook *q, int index, int quant_index,
69 int* subband_coef_index, int* subband_coef_sign,
70 REAL_T* mlt_p);
71
72 void (* interpolate) (struct cook *q, REAL_T* buffer,
73 int gain_index, int gain_index_next);
74
75 GetBitContext gb;
76 int frame_number;
77 int block_align;
78 int extradata_size;
79 /* stream data */
80 int nb_channels;
81 int joint_stereo;
82 int bit_rate;
83 int sample_rate;
84 int samples_per_channel;
85 int samples_per_frame;
86 int subbands;
87 int log2_numvector_size;
88 int numvector_size; //1 << log2_numvector_size;
89 int js_subband_start;
90 int total_subbands;
91 int num_vectors;
92 int bits_per_subpacket;
93 int cookversion;
94 int mdct_nbits; /* is this the same as one of above? */
95 /* states */
96 int random_state;
97
98 /* gain buffers */
99 cook_gains gains1;
100 cook_gains gains2;
101 int gain_1[9];
102 int gain_2[9];
103 int gain_3[9];
104 int gain_4[9];
105
106 /* VLC data */
107 int js_vlc_bits;
108 VLC envelope_quant_index[13];
109 VLC sqvh[7]; //scalar quantization
110 VLC ccpl; //channel coupling
111
112 /* generatable tables and related variables */
113 int gain_size_factor;
114
115 /* data buffers */
116
117 uint8_t decoded_bytes_buffer[1024] MEM_ALIGN_ATTR;
118 REAL_T mono_mdct_output[2048] MEM_ALIGN_ATTR;
119 REAL_T mono_previous_buffer1[1024] MEM_ALIGN_ATTR;
120 REAL_T mono_previous_buffer2[1024] MEM_ALIGN_ATTR;
121 REAL_T decode_buffer_1[1024] MEM_ALIGN_ATTR;
122 REAL_T decode_buffer_2[1024] MEM_ALIGN_ATTR;
123 /* static allocation for joint decode */
124 REAL_T decode_buffer_0[1060] MEM_ALIGN_ATTR;
125} COOKContext;
126
127int cook_decode_init(RMContext *rmctx, COOKContext *q);
128int cook_decode_frame(RMContext *rmctx,COOKContext *q,
129 int32_t *outbuffer, int *data_size,
130 const uint8_t *inbuffer, int buf_size);
131#endif /*_COOK_H */
diff --git a/lib/rbcodec/codecs/libcook/cook_fixpoint.h b/lib/rbcodec/codecs/libcook/cook_fixpoint.h
new file mode 100644
index 0000000000..5c4a5d1a5a
--- /dev/null
+++ b/lib/rbcodec/codecs/libcook/cook_fixpoint.h
@@ -0,0 +1,278 @@
1/*
2 * COOK compatible decoder, fixed point implementation.
3 * Copyright (c) 2007 Ian Braithwaite
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/**
24 * @file cook_fixpoint.h
25 *
26 * Cook AKA RealAudio G2 fixed point functions.
27 *
28 * Fixed point values are represented as 32 bit signed integers,
29 * which can be added and subtracted directly in C (without checks for
30 * overflow/saturation.
31 * Two multiplication routines are provided:
32 * 1) Multiplication by powers of two (2^-31 .. 2^31), implemented
33 * with C's bit shift operations.
34 * 2) Multiplication by 16 bit fractions (0 <= x < 1), implemented
35 * in C using two 32 bit integer multiplications.
36 */
37
38#ifdef ROCKBOX
39/* get definitions of MULT31, MULT31_SHIFT16, vect_add, from codelib */
40#include "codeclib_misc.h"
41#include "codeclib.h"
42#endif
43
44/* cplscales was moved from cookdata_fixpoint.h since only *
45 * cook_fixpoint.h should see/use it. */
46static const FIXPU* cplscales[5] = {
47 cplscale2, cplscale3, cplscale4, cplscale5, cplscale6
48};
49
50/**
51 * Fixed point multiply by power of two.
52 *
53 * @param x fix point value
54 * @param i integer power-of-two, -31..+31
55 */
56static inline FIXP fixp_pow2(FIXP x, int i)
57{
58 if (i < 0)
59 return (x >> -i);
60 else
61 return x << i; /* no check for overflow */
62}
63
64/**
65 * Fixed point multiply by fraction.
66 *
67 * @param a fix point value
68 * @param b fix point fraction, 0 <= b < 1
69 */
70#ifdef ROCKBOX
71#define fixp_mult_su(x,y) (MULT31_SHIFT16(x,y))
72#else
73static inline FIXP fixp_mult_su(FIXP a, FIXPU b)
74{
75 int32_t hb = (a >> 16) * b;
76 uint32_t lb = (a & 0xffff) * b;
77
78 return hb + (lb >> 16) + ((lb & 0x8000) >> 15);
79}
80#endif
81
82/* Faster version of the above using 32x32=64 bit multiply */
83#ifdef ROCKBOX
84#define fixmul31(x,y) (MULT31(x,y))
85#else
86static inline int32_t fixmul31(int32_t x, int32_t y)
87{
88 int64_t temp;
89
90 temp = x;
91 temp *= y;
92
93 temp >>= 31; //16+31-16 = 31 bits
94
95 return (int32_t)temp;
96}
97#endif
98
99/**
100 * Clips a signed integer value into the amin-amax range.
101 * @param a value to clip
102 * @param amin minimum value of the clip range
103 * @param amax maximum value of the clip range
104 * @return clipped value
105 */
106static inline int av_clip(int a, int amin, int amax)
107{
108 if (a < amin) return amin;
109 else if (a > amax) return amax;
110 else return a;
111}
112
113/**
114 * The real requantization of the mltcoefs
115 *
116 * @param q pointer to the COOKContext
117 * @param index index
118 * @param quant_index quantisation index for this band
119 * @param subband_coef_index array of indexes to quant_centroid_tab
120 * @param subband_coef_sign use random noise instead of predetermined value
121 * @param mlt_ptr pointer to the mlt coefficients
122 */
123
124static void scalar_dequant_math(COOKContext *q, int index,
125 int quant_index, int* subband_coef_index,
126 int* subband_coef_sign, REAL_T *mlt_p)
127 ICODE_ATTR_COOK_DECODE;
128static void scalar_dequant_math(COOKContext *q, int index,
129 int quant_index, int* subband_coef_index,
130 int* subband_coef_sign, REAL_T *mlt_p)
131{
132 /* Num. half bits to right shift */
133 const int s = 33 - quant_index + av_log2(q->samples_per_channel);
134 const FIXP *table = quant_tables[s & 1][index];
135 FIXP f;
136 int i;
137
138
139 if(s >= 64)
140 memset(mlt_p, 0, sizeof(REAL_T)*SUBBAND_SIZE);
141 else
142 {
143 for(i=0 ; i<SUBBAND_SIZE ; i++) {
144 f = (table[subband_coef_index[i]]) >> (s >> 1);
145 /* noise coding if subband_coef_index[i] == 0 */
146 if (((subband_coef_index[i] == 0) && cook_random(q)) ||
147 ((subband_coef_index[i] != 0) && subband_coef_sign[i]))
148 f = -f;
149
150 *mlt_p++ = f;
151 }
152 }
153}
154
155/**
156 * The modulated lapped transform, this takes transform coefficients
157 * and transforms them into timedomain samples.
158 * A window step is also included.
159 *
160 * @param q pointer to the COOKContext
161 * @param inbuffer pointer to the mltcoefficients
162 * @param outbuffer pointer to the timedomain buffer
163 * @param mlt_tmp pointer to temporary storage space
164 */
165#include "../lib/mdct_lookup.h"
166
167void imlt_math(COOKContext *q, FIXP *in) ICODE_ATTR;
168void imlt_math(COOKContext *q, FIXP *in)
169{
170 const int n = q->samples_per_channel;
171 const int step = 2 << (10 - av_log2(n));
172 REAL_T *mdct_out = q->mono_mdct_output;
173 REAL_T tmp;
174 int i = 0, j = 0;
175
176 ff_imdct_calc(q->mdct_nbits, q->mono_mdct_output, in);
177
178 do {
179 tmp = mdct_out[i];
180 mdct_out[i ] = fixmul31(-mdct_out[n+i], (sincos_lookup0[j ]));
181 mdct_out[n+i] = fixmul31(tmp , (sincos_lookup0[j+1]));
182
183 j += step;
184 } while (++i < n/2);
185
186 do {
187 j -= step;
188
189 tmp = mdct_out[i];
190 mdct_out[i ] = fixmul31(-mdct_out[n+i], (sincos_lookup0[j+1]));
191 mdct_out[n+i] = fixmul31(tmp , (sincos_lookup0[j ]));
192 } while (++i < n);
193}
194
195/**
196 * Perform buffer overlapping.
197 *
198 * @param q pointer to the COOKContext
199 * @param gain gain correction to apply first to output buffer
200 * @param buffer data to overlap
201 */
202void overlap_math(COOKContext *q, int gain, FIXP buffer[]) ICODE_ATTR;
203void overlap_math(COOKContext *q, int gain, FIXP buffer[])
204{
205 int i;
206#ifdef ROCKBOX
207 if(LIKELY(gain == 0))
208 {
209 vect_add(q->mono_mdct_output, buffer, q->samples_per_channel);
210
211 } else if (gain > 0){
212 for(i=0 ; i<q->samples_per_channel ; i++) {
213 q->mono_mdct_output[i] = (q->mono_mdct_output[i]<< gain) + buffer[i]; }
214
215 } else {
216 for(i=0 ; i<q->samples_per_channel ; i++) {
217 q->mono_mdct_output[i] = (q->mono_mdct_output[i]>>-gain) + buffer[i];
218 }
219 }
220#else
221 for(i=0 ; i<q->samples_per_channel ; i++) {
222 q->mono_mdct_output[i] =
223 fixp_pow2(q->mono_mdct_output[i], gain) + buffer[i];
224 }
225#endif
226}
227
228
229/**
230 * the actual requantization of the timedomain samples
231 *
232 * @param q pointer to the COOKContext
233 * @param buffer pointer to the timedomain buffer
234 * @param gain_index index for the block multiplier
235 * @param gain_index_next index for the next block multiplier
236 */
237static inline void
238interpolate_math(COOKContext *q, register FIXP* buffer,
239 int gain_index, int gain_index_next)
240{
241 int i;
242 int gain_size_factor = q->samples_per_channel / 8;
243
244 if(gain_index == gain_index_next){ //static gain
245 for(i = 0; i < gain_size_factor; i++) {
246 buffer[i] = fixp_pow2(buffer[i], gain_index);
247 }
248 } else { //smooth gain
249 int step = (gain_index_next - gain_index)
250 << (7 - av_log2(gain_size_factor));
251 int x = 0;
252 register FIXP* bufferend = buffer+gain_size_factor;
253 while(buffer < bufferend )
254 {
255 *buffer = fixp_pow2(
256 fixp_mult_su(*buffer, pow128_tab[x]),
257 gain_index+1);
258 buffer++;
259
260 x += step;
261 gain_index += ( (x + 128) >> 7 ) - 1;
262 x = ( (x + 128) & 127 );
263 }
264 }
265}
266
267
268/**
269 * Decoupling calculation for joint stereo coefficients.
270 *
271 * @param x mono coefficient
272 * @param table number of decoupling table
273 * @param i table index
274 */
275static inline FIXP cplscale_math(FIXP x, int table, int i)
276{
277 return fixp_mult_su(x, cplscales[table-2][i]);
278}
diff --git a/lib/rbcodec/codecs/libcook/cookdata.h b/lib/rbcodec/codecs/libcook/cookdata.h
new file mode 100644
index 0000000000..a73b96c5f5
--- /dev/null
+++ b/lib/rbcodec/codecs/libcook/cookdata.h
@@ -0,0 +1,493 @@
1/*
2 * COOK compatible decoder data
3 * Copyright (c) 2003 Sascha Sommer
4 * Copyright (c) 2005 Benjamin Larsson
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 */
23
24/**
25 * @file cookdata.h
26 * Cook AKA RealAudio G2 compatible decoderdata
27 */
28
29/* various data tables */
30
31static const int expbits_tab[8] = {
32 52,47,43,37,29,22,16,0,
33};
34
35static const int invradix_tab[7] = {
36 74899, 104858, 149797, 209716, 262144, 349526, 524288,
37};
38
39static const int kmax_tab[7] = {
40 13, 9, 6, 4, 3, 2, 1,
41};
42
43static const int vd_tab[7] = {
44 2, 2, 2, 4, 4, 5, 5,
45};
46
47static const int vpr_tab[7] = {
48 10, 10, 10, 5, 5, 4, 4,
49};
50
51
52
53/* VLC data */
54
55static const int vhsize_tab[7] = {
56 191, 97, 48, 607, 246, 230, 32,
57};
58
59static const int vhvlcsize_tab[7] = {
60 8, 7, 7, 10, 9, 9, 6,
61};
62
63static const uint8_t envelope_quant_index_huffbits[13][24] = {
64 { 4, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 4, 5, 7, 8, 9, 11, 11, 12, 12, 12, 12 },
65 { 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 7, 9, 11, 12, 13, 15, 15, 15, 16, 16 },
66 { 12, 10, 8, 6, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 4, 4, 5, 5, 7, 9, 11, 13, 14, 14 },
67 { 13, 10, 9, 9, 7, 7, 5, 5, 4, 3, 3, 3, 3, 3, 4, 4, 4, 5, 7, 9, 11, 13, 13, 13 },
68 { 12, 13, 10, 8, 6, 6, 5, 5, 4, 4, 3, 3, 3, 3, 3, 4, 5, 5, 6, 7, 9, 11, 14, 14 },
69 { 12, 11, 9, 8, 8, 7, 5, 4, 4, 3, 3, 3, 3, 3, 4, 4, 5, 5, 7, 8, 10, 13, 14, 14 },
70 { 15, 16, 15, 12, 10, 8, 6, 5, 4, 3, 3, 3, 2, 3, 4, 5, 5, 7, 9, 11, 13, 16, 16, 16 },
71 { 14, 14, 11, 10, 9, 7, 7, 5, 5, 4, 3, 3, 2, 3, 3, 4, 5, 7, 9, 9, 12, 14, 15, 15 },
72 { 9, 9, 9, 8, 7, 6, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 13 },
73 { 14, 12, 10, 8, 6, 6, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 8, 8, 9, 11, 14, 14, 14 },
74 { 13, 10, 9, 8, 6, 6, 5, 4, 4, 4, 3, 3, 2, 3, 4, 5, 6, 8, 9, 9, 11, 12, 14, 14 },
75 { 16, 13, 12, 11, 9, 6, 5, 5, 4, 4, 4, 3, 2, 3, 3, 4, 5, 7, 8, 10, 14, 16, 16, 16 },
76 { 13, 14, 14, 14, 10, 8, 7, 7, 5, 4, 3, 3, 2, 3, 3, 4, 5, 5, 7, 9, 11, 14, 14, 14 },
77};
78
79static const uint16_t envelope_quant_index_huffcodes[13][24] = {
80 {0x0006, 0x003e, 0x001c, 0x001d, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x0000, 0x0001,
81 0x0002, 0x000d, 0x001e, 0x007e, 0x00fe, 0x01fe, 0x07fc, 0x07fd, 0x0ffc, 0x0ffd, 0x0ffe, 0x0fff},
82 {0x03fe, 0x00fe, 0x003e, 0x001c, 0x001d, 0x000c, 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005,
83 0x000d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x0ffe, 0x1ffe, 0x7ffc, 0x7ffd, 0x7ffe, 0xfffe, 0xffff},
84 {0x0ffe, 0x03fe, 0x00fe, 0x003e, 0x001c, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x0000,
85 0x0001, 0x0002, 0x000c, 0x000d, 0x001d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x1ffe, 0x3ffe, 0x3fff},
86 {0x1ffc, 0x03fe, 0x01fc, 0x01fd, 0x007c, 0x007d, 0x001c, 0x001d, 0x000a, 0x0000, 0x0001, 0x0002,
87 0x0003, 0x0004, 0x000b, 0x000c, 0x000d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x1ffd, 0x1ffe, 0x1fff},
88 {0x0ffe, 0x1ffe, 0x03fe, 0x00fe, 0x003c, 0x003d, 0x001a, 0x001b, 0x000a, 0x000b, 0x0000, 0x0001,
89 0x0002, 0x0003, 0x0004, 0x000c, 0x001c, 0x001d, 0x003e, 0x007e, 0x01fe, 0x07fe, 0x3ffe, 0x3fff},
90 {0x0ffe, 0x07fe, 0x01fe, 0x00fc, 0x00fd, 0x007c, 0x001c, 0x000a, 0x000b, 0x0000, 0x0001, 0x0002,
91 0x0003, 0x0004, 0x000c, 0x000d, 0x001d, 0x001e, 0x007d, 0x00fe, 0x03fe, 0x1ffe, 0x3ffe, 0x3fff},
92 {0x7ffc, 0xfffc, 0x7ffd, 0x0ffe, 0x03fe, 0x00fe, 0x003e, 0x001c, 0x000c, 0x0002, 0x0003, 0x0004,
93 0x0000, 0x0005, 0x000d, 0x001d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x1ffe, 0xfffd, 0xfffe, 0xffff},
94 {0x3ffc, 0x3ffd, 0x07fe, 0x03fe, 0x01fc, 0x007c, 0x007d, 0x001c, 0x001d, 0x000c, 0x0002, 0x0003,
95 0x0000, 0x0004, 0x0005, 0x000d, 0x001e, 0x007e, 0x01fd, 0x01fe, 0x0ffe, 0x3ffe, 0x7ffe, 0x7fff},
96 {0x01fc, 0x01fd, 0x01fe, 0x00fc, 0x007c, 0x003c, 0x001c, 0x000c, 0x0000, 0x0001, 0x0002, 0x0003,
97 0x0004, 0x0005, 0x000d, 0x001d, 0x003d, 0x007d, 0x00fd, 0x03fe, 0x07fe, 0x0ffe, 0x1ffe, 0x1fff},
98 {0x3ffc, 0x0ffe, 0x03fe, 0x00fc, 0x003c, 0x003d, 0x001c, 0x000c, 0x0000, 0x0001, 0x0002, 0x0003,
99 0x0004, 0x0005, 0x000d, 0x001d, 0x003e, 0x00fd, 0x00fe, 0x01fe, 0x07fe, 0x3ffd, 0x3ffe, 0x3fff},
100 {0x1ffe, 0x03fe, 0x01fc, 0x00fc, 0x003c, 0x003d, 0x001c, 0x000a, 0x000b, 0x000c, 0x0002, 0x0003,
101 0x0000, 0x0004, 0x000d, 0x001d, 0x003e, 0x00fd, 0x01fd, 0x01fe, 0x07fe, 0x0ffe, 0x3ffe, 0x3fff},
102 {0xfffc, 0x1ffe, 0x0ffe, 0x07fe, 0x01fe, 0x003e, 0x001c, 0x001d, 0x000a, 0x000b, 0x000c, 0x0002,
103 0x0000, 0x0003, 0x0004, 0x000d, 0x001e, 0x007e, 0x00fe, 0x03fe, 0x3ffe, 0xfffd, 0xfffe, 0xffff},
104 {0x1ffc, 0x3ffa, 0x3ffb, 0x3ffc, 0x03fe, 0x00fe, 0x007c, 0x007d, 0x001c, 0x000c, 0x0002, 0x0003,
105 0x0000, 0x0004, 0x0005, 0x000d, 0x001d, 0x001e, 0x007e, 0x01fe, 0x07fe, 0x3ffd, 0x3ffe, 0x3fff},
106};
107
108
109static const uint8_t cvh_huffbits0[191] = {
110 1, 4, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10,
111 11, 11, 4, 5, 6, 7, 7, 8, 8, 9, 9, 9,
112 9, 10, 11, 11, 5, 6, 7, 8, 8, 9, 9, 9,
113 9, 10, 10, 10, 11, 12, 6, 7, 8, 9, 9, 9,
114 9, 10, 10, 10, 10, 11, 12, 13, 7, 7, 8, 9,
115 9, 9, 10, 10, 10, 10, 11, 11, 12, 13, 8, 8,
116 9, 9, 9, 10, 10, 10, 10, 11, 11, 12, 13, 14,
117 8, 8, 9, 9, 10, 10, 11, 11, 11, 12, 12, 13,
118 13, 15, 8, 8, 9, 9, 10, 10, 11, 11, 11, 12,
119 12, 13, 14, 15, 9, 9, 9, 10, 10, 10, 11, 11,
120 12, 13, 12, 14, 15, 16, 9, 9, 10, 10, 10, 10,
121 11, 12, 12, 14, 14, 16, 16, 0, 9, 9, 10, 10,
122 11, 11, 12, 13, 13, 14, 14, 15, 0, 0, 10, 10,
123 10, 11, 11, 12, 12, 13, 15, 15, 16, 0, 0, 0,
124 11, 11, 11, 12, 13, 13, 13, 15, 16, 16, 0, 0,
125 0, 0, 11, 11, 12, 13, 13, 14, 15, 16, 16,
126};
127
128static const uint16_t cvh_huffcodes0[191] = {
129 0x0000,0x0008,0x002c,0x002d,0x0062,0x0063,0x00d4,0x00d5,0x00d6,0x01c6,0x01c7,0x03ca,
130 0x07d6,0x07d7,0x0009,0x0014,0x002e,0x0064,0x0065,0x00d7,0x00d8,0x01c8,0x01c9,0x01ca,
131 0x01cb,0x03cb,0x07d8,0x07d9,0x0015,0x002f,0x0066,0x00d9,0x00da,0x01cc,0x01cd,0x01ce,
132 0x01cf,0x03cc,0x03cd,0x03ce,0x07da,0x0fe4,0x0030,0x0067,0x00db,0x01d0,0x01d1,0x01d2,
133 0x01d3,0x03cf,0x03d0,0x03d1,0x03d2,0x07db,0x0fe5,0x1fea,0x0068,0x0069,0x00dc,0x01d4,
134 0x01d5,0x01d6,0x03d3,0x03d4,0x03d5,0x03d6,0x07dc,0x07dd,0x0fe6,0x1feb,0x00dd,0x00de,
135 0x01d7,0x01d8,0x01d9,0x03d7,0x03d8,0x03d9,0x03da,0x07de,0x07df,0x0fe7,0x1fec,0x3ff2,
136 0x00df,0x00e0,0x01da,0x01db,0x03db,0x03dc,0x07e0,0x07e1,0x07e2,0x0fe8,0x0fe9,0x1fed,
137 0x1fee,0x7ff4,0x00e1,0x00e2,0x01dc,0x01dd,0x03dd,0x03de,0x07e3,0x07e4,0x07e5,0x0fea,
138 0x0feb,0x1fef,0x3ff3,0x7ff5,0x01de,0x01df,0x01e0,0x03df,0x03e0,0x03e1,0x07e6,0x07e7,
139 0x0fec,0x1ff0,0x0fed,0x3ff4,0x7ff6,0xfff8,0x01e1,0x01e2,0x03e2,0x03e3,0x03e4,0x03e5,
140 0x07e8,0x0fee,0x0fef,0x3ff5,0x3ff6,0xfff9,0xfffa,0xfffa,0x01e3,0x01e4,0x03e6,0x03e7,
141 0x07e9,0x07ea,0x0ff0,0x1ff1,0x1ff2,0x3ff7,0x3ff8,0x7ff7,0x7ff7,0xfffa,0x03e8,0x03e9,
142 0x03ea,0x07eb,0x07ec,0x0ff1,0x0ff2,0x1ff3,0x7ff8,0x7ff9,0xfffb,0x3ff8,0x7ff7,0x7ff7,
143 0x07ed,0x07ee,0x07ef,0x0ff3,0x1ff4,0x1ff5,0x1ff6,0x7ffa,0xfffc,0xfffd,0xfffb,0xfffb,
144 0x3ff8,0x7ff7,0x07f0,0x07f1,0x0ff4,0x1ff7,0x1ff8,0x3ff9,0x7ffb,0xfffe,0xffff,
145};
146
147
148static const uint8_t cvh_huffbits1[97] = {
149 1, 4, 5, 6, 7, 8, 8, 9, 10, 10, 4, 5,
150 6, 7, 7, 8, 8, 9, 9, 11, 5, 5, 6, 7,
151 8, 8, 9, 9, 10, 11, 6, 6, 7, 8, 8, 9,
152 9, 10, 11, 12, 7, 7, 8, 8, 9, 9, 10, 11,
153 11, 13, 8, 8, 8, 9, 9, 10, 10, 11, 12, 14,
154 8, 8, 8, 9, 10, 11, 11, 12, 13, 15, 9, 9,
155 9, 10, 11, 12, 12, 14, 14, 0, 9, 9, 9, 10,
156 11, 12, 14, 16, 0, 0, 10, 10, 11, 12, 13, 14,
157 16,
158};
159
160
161static const uint16_t cvh_huffcodes1[97] = {
162 0x0000,0x0008,0x0014,0x0030,0x006a,0x00e2,0x00e3,0x01e4,0x03ec,0x03ed,0x0009,0x0015,
163 0x0031,0x006b,0x006c,0x00e4,0x00e5,0x01e5,0x01e6,0x07f0,0x0016,0x0017,0x0032,0x006d,
164 0x00e6,0x00e7,0x01e7,0x01e8,0x03ee,0x07f1,0x0033,0x0034,0x006e,0x00e8,0x00e9,0x01e9,
165 0x01ea,0x03ef,0x07f2,0x0ff6,0x006f,0x0070,0x00ea,0x00eb,0x01eb,0x01ec,0x03f0,0x07f3,
166 0x07f4,0x1ffa,0x00ec,0x00ed,0x00ee,0x01ed,0x01ee,0x03f1,0x03f2,0x07f5,0x0ff7,0x3ffa,
167 0x00ef,0x00f0,0x00f1,0x01ef,0x03f3,0x07f6,0x07f7,0x0ff8,0x1ffb,0x7ffe,0x01f0,0x01f1,
168 0x01f2,0x03f4,0x07f8,0x0ff9,0x0ffa,0x3ffb,0x3ffc,0x0000,0x01f3,0x01f4,0x01f5,0x03f5,
169 0x07f9,0x0ffb,0x3ffd,0xfffe,0x0000,0x0000,0x03f6,0x03f7,0x07fa,0x0ffc,0x1ffc,0x3ffe,
170 0xffff,
171};
172
173static const uint8_t cvh_huffbits2[48] = {
174 1, 4, 5, 7, 8, 9, 10, 3, 4, 5, 7, 8,
175 9, 10, 5, 5, 6, 7, 8, 10, 10, 7, 6, 7,
176 8, 9, 10, 12, 8, 8, 8, 9, 10, 12, 14, 8,
177 9, 9, 10, 11, 15, 16, 9, 10, 11, 12, 13, 16,
178};
179
180static const uint16_t cvh_huffcodes2[48] = {
181 0x0000,0x000a,0x0018,0x0074,0x00f2,0x01f4,0x03f6,0x0004,0x000b,0x0019,0x0075,0x00f3,
182 0x01f5,0x03f7,0x001a,0x001b,0x0038,0x0076,0x00f4,0x03f8,0x03f9,0x0077,0x0039,0x0078,
183 0x00f5,0x01f6,0x03fa,0x0ffc,0x00f6,0x00f7,0x00f8,0x01f7,0x03fb,0x0ffd,0x3ffe,0x00f9,
184 0x01f8,0x01f9,0x03fc,0x07fc,0x7ffe,0xfffe,0x01fa,0x03fd,0x07fd,0x0ffe,0x1ffe,0xffff,
185};
186
187static const uint8_t cvh_huffbits3[607] = {
188 2, 4, 6, 8, 10, 5, 5, 6, 8, 10, 7, 8,
189 8, 10, 12, 9, 9, 10, 12, 15, 10, 11, 13, 16,
190 16, 5, 6, 8, 10, 11, 5, 6, 8, 10, 12, 7,
191 7, 8, 10, 13, 9, 9, 10, 12, 15, 12, 11, 13,
192 16, 16, 7, 9, 10, 12, 15, 7, 8, 10, 12, 13,
193 9, 9, 11, 13, 16, 11, 11, 12, 14, 16, 12, 12,
194 14, 16, 0, 9, 11, 12, 16, 16, 9, 10, 13, 15,
195 16, 10, 11, 12, 16, 16, 13, 13, 16, 16, 16, 16,
196 16, 15, 16, 0, 11, 13, 16, 16, 15, 11, 13, 15,
197 16, 16, 13, 13, 16, 16, 0, 14, 16, 16, 16, 0,
198 16, 16, 0, 0, 0, 4, 6, 8, 10, 13, 6, 6,
199 8, 10, 13, 9, 8, 10, 12, 16, 10, 10, 11, 15,
200 16, 13, 12, 14, 16, 16, 5, 6, 8, 11, 13, 6,
201 6, 8, 10, 13, 8, 8, 9, 11, 14, 10, 10, 12,
202 12, 16, 13, 12, 13, 15, 16, 7, 8, 9, 12, 16,
203 7, 8, 10, 12, 14, 9, 9, 10, 13, 16, 11, 10,
204 12, 15, 16, 13, 13, 16, 16, 0, 9, 11, 13, 16,
205 16, 9, 10, 12, 15, 16, 10, 11, 13, 16, 16, 13,
206 12, 16, 16, 16, 16, 16, 16, 16, 0, 11, 13, 16,
207 16, 16, 11, 13, 16, 16, 16, 12, 13, 15, 16, 0,
208 16, 16, 16, 16, 0, 16, 16, 0, 0, 0, 6, 8,
209 11, 13, 16, 8, 8, 10, 12, 16, 11, 10, 11, 13,
210 16, 12, 13, 13, 15, 16, 16, 16, 14, 16, 0, 6,
211 8, 10, 13, 16, 8, 8, 10, 12, 16, 10, 10, 11,
212 13, 16, 13, 12, 13, 16, 16, 14, 14, 14, 16, 0,
213 8, 9, 11, 13, 16, 8, 9, 11, 16, 14, 10, 10,
214 12, 15, 16, 12, 12, 13, 16, 16, 15, 16, 16, 16,
215 0, 10, 12, 15, 16, 16, 10, 12, 12, 14, 16, 12,
216 12, 13, 16, 16, 14, 15, 16, 16, 0, 16, 16, 16,
217 0, 0, 12, 15, 15, 16, 0, 13, 13, 16, 16, 0,
218 14, 16, 16, 16, 0, 16, 16, 16, 0, 0, 0, 0,
219 0, 0, 0, 8, 10, 13, 15, 16, 10, 11, 13, 16,
220 16, 13, 13, 14, 16, 16, 16, 16, 16, 16, 16, 16,
221 16, 16, 16, 0, 8, 10, 11, 15, 16, 9, 10, 12,
222 16, 16, 12, 12, 15, 16, 16, 16, 14, 16, 16, 16,
223 16, 16, 16, 16, 0, 9, 11, 14, 16, 16, 10, 11,
224 13, 16, 16, 14, 13, 14, 16, 16, 16, 15, 15, 16,
225 0, 16, 16, 16, 0, 0, 11, 13, 16, 16, 16, 11,
226 13, 15, 16, 16, 13, 16, 16, 16, 0, 16, 16, 16,
227 16, 0, 16, 16, 0, 0, 0, 15, 16, 16, 16, 0,
228 14, 16, 16, 16, 0, 16, 16, 16, 0, 0, 16, 16,
229 0, 0, 0, 0, 0, 0, 0, 0, 9, 13, 16, 16,
230 16, 11, 13, 16, 16, 16, 14, 15, 16, 16, 0, 15,
231 16, 16, 16, 0, 16, 16, 0, 0, 0, 9, 13, 15,
232 15, 16, 12, 13, 14, 16, 16, 16, 15, 16, 16, 0,
233 16, 16, 16, 16, 0, 16, 16, 0, 0, 0, 11, 13,
234 15, 16, 0, 12, 14, 16, 16, 0, 16, 16, 16, 16,
235 0, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 16,
236 16, 16, 16, 0, 16, 16, 16, 16, 0, 16, 16, 16,
237 0, 0, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0,
238 16, 16, 0, 0, 0, 16, 16,
239};
240
241
242static const uint16_t cvh_huffcodes3[607] = {
243 0x0000,0x0004,0x0022,0x00c6,0x03b0,0x000c,0x000d,0x0023,0x00c7,0x03b1,0x005c,0x00c8,
244 0x00c9,0x03b2,0x0fa4,0x01c2,0x01c3,0x03b3,0x0fa5,0x7f72,0x03b4,0x07b2,0x1f9a,0xff24,
245 0xff25,0x000e,0x0024,0x00ca,0x03b5,0x07b3,0x000f,0x0025,0x00cb,0x03b6,0x0fa6,0x005d,
246 0x005e,0x00cc,0x03b7,0x1f9b,0x01c4,0x01c5,0x03b8,0x0fa7,0x7f73,0x0fa8,0x07b4,0x1f9c,
247 0xff26,0xff27,0x005f,0x01c6,0x03b9,0x0fa9,0x7f74,0x0060,0x00cd,0x03ba,0x0faa,0x1f9d,
248 0x01c7,0x01c8,0x07b5,0x1f9e,0xff28,0x07b6,0x07b7,0x0fab,0x3fa2,0xff29,0x0fac,0x0fad,
249 0x3fa3,0xff2a,0x3fa2,0x01c9,0x07b8,0x0fae,0xff2b,0xff2c,0x01ca,0x03bb,0x1f9f,0x7f75,
250 0xff2d,0x03bc,0x07b9,0x0faf,0xff2e,0xff2f,0x1fa0,0x1fa1,0xff30,0xff31,0xff32,0xff33,
251 0xff34,0x7f76,0xff35,0xff31,0x07ba,0x1fa2,0xff36,0xff37,0x7f77,0x07bb,0x1fa3,0x7f78,
252 0xff38,0xff39,0x1fa4,0x1fa5,0xff3a,0xff3b,0xff2e,0x3fa4,0xff3c,0xff3d,0xff3e,0xff31,
253 0xff3f,0xff40,0xff30,0xff31,0xff31,0x0005,0x0026,0x00ce,0x03bd,0x1fa6,0x0027,0x0028,
254 0x00cf,0x03be,0x1fa7,0x01cb,0x00d0,0x03bf,0x0fb0,0xff41,0x03c0,0x03c1,0x07bc,0x7f79,
255 0xff42,0x1fa8,0x0fb1,0x3fa5,0xff43,0xff44,0x0010,0x0029,0x00d1,0x07bd,0x1fa9,0x002a,
256 0x002b,0x00d2,0x03c2,0x1faa,0x00d3,0x00d4,0x01cc,0x07be,0x3fa6,0x03c3,0x03c4,0x0fb2,
257 0x0fb3,0xff45,0x1fab,0x0fb4,0x1fac,0x7f7a,0xff46,0x0061,0x00d5,0x01cd,0x0fb5,0xff47,
258 0x0062,0x00d6,0x03c5,0x0fb6,0x3fa7,0x01ce,0x01cf,0x03c6,0x1fad,0xff48,0x07bf,0x03c7,
259 0x0fb7,0x7f7b,0xff49,0x1fae,0x1faf,0xff4a,0xff4b,0x7f7b,0x01d0,0x07c0,0x1fb0,0xff4c,
260 0xff4d,0x01d1,0x03c8,0x0fb8,0x7f7c,0xff4e,0x03c9,0x07c1,0x1fb1,0xff4f,0xff50,0x1fb2,
261 0x0fb9,0xff51,0xff52,0xff53,0xff54,0xff55,0xff56,0xff57,0xff52,0x07c2,0x1fb3,0xff58,
262 0xff59,0xff5a,0x07c3,0x1fb4,0xff5b,0xff5c,0xff5d,0x0fba,0x1fb5,0x7f7d,0xff5e,0xff4f,
263 0xff5f,0xff60,0xff61,0xff62,0xff52,0xff63,0xff64,0xff51,0xff52,0xff52,0x002c,0x00d7,
264 0x07c4,0x1fb6,0xff65,0x00d8,0x00d9,0x03ca,0x0fbb,0xff66,0x07c5,0x03cb,0x07c6,0x1fb7,
265 0xff67,0x0fbc,0x1fb8,0x1fb9,0x7f7e,0xff68,0xff69,0xff6a,0x3fa8,0xff6b,0x7f7e,0x002d,
266 0x00da,0x03cc,0x1fba,0xff6c,0x00db,0x00dc,0x03cd,0x0fbd,0xff6d,0x03ce,0x03cf,0x07c7,
267 0x1fbb,0xff6e,0x1fbc,0x0fbe,0x1fbd,0xff6f,0xff70,0x3fa9,0x3faa,0x3fab,0xff71,0xff6f,
268 0x00dd,0x01d2,0x07c8,0x1fbe,0xff72,0x00de,0x01d3,0x07c9,0xff73,0x3fac,0x03d0,0x03d1,
269 0x0fbf,0x7f7f,0xff74,0x0fc0,0x0fc1,0x1fbf,0xff75,0xff76,0x7f80,0xff77,0xff78,0xff79,
270 0xff75,0x03d2,0x0fc2,0x7f81,0xff7a,0xff7b,0x03d3,0x0fc3,0x0fc4,0x3fad,0xff7c,0x0fc5,
271 0x0fc6,0x1fc0,0xff7d,0xff7e,0x3fae,0x7f82,0xff7f,0xff80,0xff80,0xff81,0xff82,0xff83,
272 0xff80,0xff80,0x0fc7,0x7f83,0x7f84,0xff84,0xff7a,0x1fc1,0x1fc2,0xff85,0xff86,0x3fad,
273 0x3faf,0xff87,0xff88,0xff89,0xff7d,0xff8a,0xff8b,0xff8c,0xff80,0xff80,0x3fae,0x7f82,
274 0xff7f,0xff80,0xff80,0x00df,0x03d4,0x1fc3,0x7f85,0xff8d,0x03d5,0x07ca,0x1fc4,0xff8e,
275 0xff8f,0x1fc5,0x1fc6,0x3fb0,0xff90,0xff91,0xff92,0xff93,0xff94,0xff95,0xff96,0xff97,
276 0xff98,0xff99,0xff9a,0xff95,0x00e0,0x03d6,0x07cb,0x7f86,0xff9b,0x01d4,0x03d7,0x0fc8,
277 0xff9c,0xff9d,0x0fc9,0x0fca,0x7f87,0xff9e,0xff9f,0xffa0,0x3fb1,0xffa1,0xffa2,0xffa3,
278 0xffa4,0xffa5,0xffa6,0xffa7,0xffa2,0x01d5,0x07cc,0x3fb2,0xffa8,0xffa9,0x03d8,0x07cd,
279 0x1fc7,0xffaa,0xffab,0x3fb3,0x1fc8,0x3fb4,0xffac,0xffad,0xffae,0x7f88,0x7f89,0xffaf,
280 0xffaf,0xffb0,0xffb1,0xffb2,0xffaf,0xffaf,0x07ce,0x1fc9,0xffb3,0xffb4,0xffb5,0x07cf,
281 0x1fca,0x7f8a,0xffb6,0xffb7,0x1fcb,0xffb8,0xffb9,0xffba,0xffba,0xffbb,0xffbc,0xffbd,
282 0xffbe,0xffbe,0xffbf,0xffc0,0xffbd,0xffbe,0xffbe,0x7f8b,0xffc1,0xffc2,0xffc3,0xffb4,
283 0x3fb5,0xffc4,0xffc5,0xffc6,0xffb6,0xffc7,0xffc8,0xffc9,0xffba,0xffba,0xffca,0xffcb,
284 0xffbd,0xffbe,0xffbe,0xffbb,0xffbc,0xffbd,0xffbe,0xffbe,0x01d6,0x1fcc,0xffcc,0xffcd,
285 0xffce,0x07d0,0x1fcd,0xffcf,0xffd0,0xffd1,0x3fb6,0x7f8c,0xffd2,0xffd3,0xff90,0x7f8d,
286 0xffd4,0xffd5,0xffd6,0xff95,0xffd7,0xffd8,0xff94,0xff95,0xff95,0x01d7,0x1fce,0x7f8e,
287 0x7f8f,0xffd9,0x0fcb,0x1fcf,0x3fb7,0xffda,0xffdb,0xffdc,0x7f90,0xffdd,0xffde,0xff9e,
288 0xffdf,0xffe0,0xffe1,0xffe2,0xffa2,0xffe3,0xffe4,0xffa1,0xffa2,0xffa2,0x07d1,0x1fd0,
289 0x7f91,0xffe5,0xffa8,0x0fcc,0x3fb8,0xffe6,0xffe7,0xffaa,0xffe8,0xffe9,0xffea,0xffeb,
290 0xffac,0xffec,0xffed,0xffee,0xffaf,0xffaf,0xffae,0x7f88,0x7f89,0xffaf,0xffaf,0xffef,
291 0xfff0,0xfff1,0xfff2,0xffb4,0xfff3,0xfff4,0xfff5,0xfff6,0xffb6,0xfff7,0xfff8,0xfff9,
292 0xffba,0xffba,0xfffa,0xfffb,0xffbd,0xffbe,0xffbe,0xffbb,0xffbc,0xffbd,0xffbe,0xffbe,
293 0xfffc,0xfffd,0xffb3,0xffb4,0xffb4,0xfffe,0xffff,
294};
295
296static const uint8_t cvh_huffbits4[246] = {
297 2, 4, 7, 10, 4, 5, 7, 10, 7, 8, 10, 14,
298 11, 11, 15, 15, 4, 5, 9, 12, 5, 5, 8, 12,
299 8, 7, 10, 15, 11, 11, 15, 15, 7, 9, 12, 15,
300 8, 8, 12, 15, 10, 10, 13, 15, 14, 14, 15, 0,
301 11, 13, 15, 15, 11, 13, 15, 15, 14, 15, 15, 0,
302 15, 15, 0, 0, 4, 5, 9, 13, 5, 6, 9, 13,
303 9, 9, 11, 15, 14, 13, 15, 15, 4, 6, 9, 12,
304 5, 6, 9, 13, 9, 8, 11, 15, 13, 12, 15, 15,
305 7, 9, 12, 15, 7, 8, 11, 15, 10, 10, 14, 15,
306 14, 15, 15, 0, 10, 12, 15, 15, 11, 13, 15, 15,
307 15, 15, 15, 0, 15, 15, 0, 0, 6, 9, 13, 14,
308 8, 9, 12, 15, 12, 12, 15, 15, 15, 15, 15, 0,
309 7, 9, 13, 15, 8, 9, 12, 15, 11, 12, 15, 15,
310 15, 15, 15, 0, 9, 11, 15, 15, 9, 11, 15, 15,
311 14, 14, 15, 0, 15, 15, 0, 0, 14, 15, 15, 0,
312 14, 15, 15, 0, 15, 15, 0, 0, 0, 0, 0, 0,
313 9, 12, 15, 15, 12, 13, 15, 15, 15, 15, 15, 0,
314 15, 15, 0, 0, 10, 12, 15, 15, 12, 14, 15, 15,
315 15, 15, 15, 0, 15, 15, 0, 0, 14, 15, 15, 0,
316 15, 15, 15, 0, 15, 15, 0, 0, 0, 0, 0, 0,
317 15, 15, 0, 0, 15, 15,
318};
319
320
321static const uint16_t cvh_huffcodes4[246] = {
322 0x0000,0x0004,0x006c,0x03e6,0x0005,0x0012,0x006d,0x03e7,0x006e,0x00e8,0x03e8,0x3fc4,
323 0x07e0,0x07e1,0x7fa4,0x7fa5,0x0006,0x0013,0x01e2,0x0fda,0x0014,0x0015,0x00e9,0x0fdb,
324 0x00ea,0x006f,0x03e9,0x7fa6,0x07e2,0x07e3,0x7fa7,0x7fa8,0x0070,0x01e3,0x0fdc,0x7fa9,
325 0x00eb,0x00ec,0x0fdd,0x7faa,0x03ea,0x03eb,0x1fd6,0x7fab,0x3fc5,0x3fc6,0x7fac,0x1fd6,
326 0x07e4,0x1fd7,0x7fad,0x7fae,0x07e5,0x1fd8,0x7faf,0x7fb0,0x3fc7,0x7fb1,0x7fb2,0x1fd6,
327 0x7fb3,0x7fb4,0x1fd6,0x1fd6,0x0007,0x0016,0x01e4,0x1fd9,0x0017,0x0032,0x01e5,0x1fda,
328 0x01e6,0x01e7,0x07e6,0x7fb5,0x3fc8,0x1fdb,0x7fb6,0x7fb7,0x0008,0x0033,0x01e8,0x0fde,
329 0x0018,0x0034,0x01e9,0x1fdc,0x01ea,0x00ed,0x07e7,0x7fb8,0x1fdd,0x0fdf,0x7fb9,0x7fba,
330 0x0071,0x01eb,0x0fe0,0x7fbb,0x0072,0x00ee,0x07e8,0x7fbc,0x03ec,0x03ed,0x3fc9,0x7fbd,
331 0x3fca,0x7fbe,0x7fbf,0x3fc9,0x03ee,0x0fe1,0x7fc0,0x7fc1,0x07e9,0x1fde,0x7fc2,0x7fc3,
332 0x7fc4,0x7fc5,0x7fc6,0x3fc9,0x7fc7,0x7fc8,0x3fc9,0x3fc9,0x0035,0x01ec,0x1fdf,0x3fcb,
333 0x00ef,0x01ed,0x0fe2,0x7fc9,0x0fe3,0x0fe4,0x7fca,0x7fcb,0x7fcc,0x7fcd,0x7fce,0x7fca,
334 0x0073,0x01ee,0x1fe0,0x7fcf,0x00f0,0x01ef,0x0fe5,0x7fd0,0x07ea,0x0fe6,0x7fd1,0x7fd2,
335 0x7fd3,0x7fd4,0x7fd5,0x7fd1,0x01f0,0x07eb,0x7fd6,0x7fd7,0x01f1,0x07ec,0x7fd8,0x7fd9,
336 0x3fcc,0x3fcd,0x7fda,0x7fda,0x7fdb,0x7fdc,0x7fda,0x7fda,0x3fce,0x7fdd,0x7fde,0x7fd6,
337 0x3fcf,0x7fdf,0x7fe0,0x7fd8,0x7fe1,0x7fe2,0x7fda,0x7fda,0x3fcc,0x3fcd,0x7fda,0x7fda,
338 0x01f2,0x0fe7,0x7fe3,0x7fe4,0x0fe8,0x1fe1,0x7fe5,0x7fe6,0x7fe7,0x7fe8,0x7fe9,0x7fca,
339 0x7fea,0x7feb,0x7fca,0x7fca,0x03ef,0x0fe9,0x7fec,0x7fed,0x0fea,0x3fd0,0x7fee,0x7fef,
340 0x7ff0,0x7ff1,0x7ff2,0x7fd1,0x7ff3,0x7ff4,0x7fd1,0x7fd1,0x3fd1,0x7ff5,0x7ff6,0x7fd6,
341 0x7ff7,0x7ff8,0x7ff9,0x7fd8,0x7ffa,0x7ffb,0x7fda,0x7fda,0x3fcc,0x3fcd,0x7fda,0x7fda,
342 0x7ffc,0x7ffd,0x7fd6,0x7fd6,0x7ffe,0x7fff,
343};
344
345
346static const uint8_t cvh_huffbits5[230] = {
347 2, 4, 8, 4, 5, 9, 9, 10, 14, 4, 6, 11,
348 5, 6, 12, 10, 11, 15, 9, 11, 15, 10, 13, 15,
349 14, 15, 0, 4, 6, 12, 6, 7, 12, 12, 12, 15,
350 5, 7, 13, 6, 7, 13, 12, 13, 15, 10, 12, 15,
351 11, 13, 15, 15, 15, 0, 8, 13, 15, 11, 12, 15,
352 15, 15, 0, 10, 13, 15, 12, 15, 15, 15, 15, 0,
353 15, 15, 0, 15, 15, 0, 0, 0, 0, 4, 5, 11,
354 5, 7, 12, 11, 12, 15, 6, 7, 13, 7, 8, 14,
355 12, 14, 15, 11, 13, 15, 12, 13, 15, 15, 15, 0,
356 5, 6, 13, 7, 8, 15, 12, 14, 15, 6, 8, 14,
357 7, 8, 15, 14, 15, 15, 12, 12, 15, 12, 13, 15,
358 15, 15, 0, 9, 13, 15, 12, 13, 15, 15, 15, 0,
359 11, 13, 15, 13, 13, 15, 15, 15, 0, 14, 15, 0,
360 15, 15, 0, 0, 0, 0, 8, 10, 15, 11, 12, 15,
361 15, 15, 0, 10, 12, 15, 12, 13, 15, 15, 15, 0,
362 14, 15, 0, 15, 15, 0, 0, 0, 0, 8, 12, 15,
363 12, 13, 15, 15, 15, 0, 11, 13, 15, 13, 15, 15,
364 15, 15, 0, 15, 15, 0, 15, 15, 0, 0, 0, 0,
365 14, 15, 0, 15, 15, 0, 0, 0, 0, 15, 15, 0,
366 15, 15,
367};
368
369
370
371static const uint16_t cvh_huffcodes5[230] = {
372 0x0000,0x0004,0x00f0,0x0005,0x0012,0x01f0,0x01f1,0x03e8,0x3fce,0x0006,0x0030,0x07de,
373 0x0013,0x0031,0x0fd2,0x03e9,0x07df,0x7fb0,0x01f2,0x07e0,0x7fb1,0x03ea,0x1fd2,0x7fb2,
374 0x3fcf,0x7fb3,0x0031,0x0007,0x0032,0x0fd3,0x0033,0x0070,0x0fd4,0x0fd5,0x0fd6,0x7fb4,
375 0x0014,0x0071,0x1fd3,0x0034,0x0072,0x1fd4,0x0fd7,0x1fd5,0x7fb5,0x03eb,0x0fd8,0x7fb6,
376 0x07e1,0x1fd6,0x7fb7,0x7fb8,0x7fb9,0x0072,0x00f1,0x1fd7,0x7fba,0x07e2,0x0fd9,0x7fbb,
377 0x7fbc,0x7fbd,0x0070,0x03ec,0x1fd8,0x7fbe,0x0fda,0x7fbf,0x7fc0,0x7fc1,0x7fc2,0x0072,
378 0x7fc3,0x7fc4,0x0071,0x7fc5,0x7fc6,0x0072,0x0034,0x0072,0x0072,0x0008,0x0015,0x07e3,
379 0x0016,0x0073,0x0fdb,0x07e4,0x0fdc,0x7fc7,0x0035,0x0074,0x1fd9,0x0075,0x00f2,0x3fd0,
380 0x0fdd,0x3fd1,0x7fc8,0x07e5,0x1fda,0x7fc9,0x0fde,0x1fdb,0x7fca,0x7fcb,0x7fcc,0x00f2,
381 0x0017,0x0036,0x1fdc,0x0076,0x00f3,0x7fcd,0x0fdf,0x3fd2,0x7fce,0x0037,0x00f4,0x3fd3,
382 0x0077,0x00f5,0x7fcf,0x3fd4,0x7fd0,0x7fd1,0x0fe0,0x0fe1,0x7fd2,0x0fe2,0x1fdd,0x7fd3,
383 0x7fd4,0x7fd5,0x00f5,0x01f3,0x1fde,0x7fd6,0x0fe3,0x1fdf,0x7fd7,0x7fd8,0x7fd9,0x00f3,
384 0x07e6,0x1fe0,0x7fda,0x1fe1,0x1fe2,0x7fdb,0x7fdc,0x7fdd,0x00f5,0x3fd5,0x7fde,0x00f4,
385 0x7fdf,0x7fe0,0x00f5,0x0077,0x00f5,0x00f5,0x00f6,0x03ed,0x7fe1,0x07e7,0x0fe4,0x7fe2,
386 0x7fe3,0x7fe4,0x0073,0x03ee,0x0fe5,0x7fe5,0x0fe6,0x1fe3,0x7fe6,0x7fe7,0x7fe8,0x00f2,
387 0x3fd6,0x7fe9,0x0074,0x7fea,0x7feb,0x00f2,0x0075,0x00f2,0x00f2,0x00f7,0x0fe7,0x7fec,
388 0x0fe8,0x1fe4,0x7fed,0x7fee,0x7fef,0x00f3,0x07e8,0x1fe5,0x7ff0,0x1fe6,0x7ff1,0x7ff2,
389 0x7ff3,0x7ff4,0x00f5,0x7ff5,0x7ff6,0x00f4,0x7ff7,0x7ff8,0x00f5,0x0077,0x00f5,0x00f5,
390 0x3fd7,0x7ff9,0x0036,0x7ffa,0x7ffb,0x00f3,0x0076,0x00f3,0x00f3,0x7ffc,0x7ffd,0x0000,
391 0x7ffe,0x7fff,
392};
393
394
395static const uint8_t cvh_huffbits6[32] = {
396 1, 4, 4, 6, 4, 6, 6, 8, 4, 6, 6, 8,
397 6, 9, 8, 10, 4, 6, 7, 8, 6, 9, 8, 11,
398 6, 9, 8, 10, 8, 10, 9, 11,
399};
400
401static const uint16_t cvh_huffcodes6[32] = {
402 0x0000,0x0008,0x0009,0x0034,0x000a,0x0035,0x0036,0x00f6,0x000b,0x0037,0x0038,0x00f7,
403 0x0039,0x01fa,0x00f8,0x03fc,0x000c,0x003a,0x007a,0x00f9,0x003b,0x01fb,0x00fa,0x07fe,
404 0x003c,0x01fc,0x00fb,0x03fd,0x00fc,0x03fe,0x01fd,0x07ff,
405};
406
407static const uint16_t* cvh_huffcodes[7] = {
408 cvh_huffcodes0, cvh_huffcodes1, cvh_huffcodes2, cvh_huffcodes3,
409 cvh_huffcodes4, cvh_huffcodes5, cvh_huffcodes6,
410};
411
412static const uint8_t* cvh_huffbits[7] = {
413 cvh_huffbits0, cvh_huffbits1, cvh_huffbits2, cvh_huffbits3,
414 cvh_huffbits4, cvh_huffbits5, cvh_huffbits6,
415};
416
417
418static const uint16_t ccpl_huffcodes2[3] = {
419 0x02,0x00,0x03,
420};
421
422static const uint16_t ccpl_huffcodes3[7] = {
423 0x3e,0x1e,0x02,0x00,0x06,0x0e,0x3f,
424};
425
426static const uint16_t ccpl_huffcodes4[15] = {
427 0xfc,0xfd,0x7c,0x3c,0x1c,0x0c,0x04,0x00,0x05,0x0d,0x1d,0x3d,
428 0x7d,0xfe,0xff,
429};
430
431static const uint16_t ccpl_huffcodes5[31] = {
432 0x03f8,0x03f9,0x03fa,0x03fb,0x01f8,0x01f9,0x00f8,0x00f9,0x0078,0x0079,0x0038,0x0039,
433 0x0018,0x0019,0x0004,0x0000,0x0005,0x001a,0x001b,0x003a,0x003b,0x007a,0x007b,0x00fa,
434 0x00fb,0x01fa,0x01fb,0x03fc,0x03fd,0x03fe,0x03ff,
435};
436
437static const uint16_t ccpl_huffcodes6[63] = {
438 0x0004,0x0005,0x0005,0x0006,0x0006,0x0007,0x0007,0x0007,0x0007,0x0008,0x0008,0x0008,
439 0x0008,0x0009,0x0009,0x0009,0x0009,0x000a,0x000a,0x000a,0x000a,0x000a,0x000b,0x000b,
440 0x000b,0x000b,0x000c,0x000d,0x000e,0x000e,0x0010,0x0000,0x000a,0x0018,0x0019,0x0036,
441 0x0037,0x0074,0x0075,0x0076,0x0077,0x00f4,0x00f5,0x00f6,0x00f7,0x01f5,0x01f6,0x01f7,
442 0x01f8,0x03f6,0x03f7,0x03f8,0x03f9,0x03fa,0x07fa,0x07fb,0x07fc,0x07fd,0x0ffd,0x1ffd,
443 0x3ffd,0x3ffe,0xffff,
444};
445
446static const uint8_t ccpl_huffbits2[3] = {
447 2,1,2,
448};
449
450static const uint8_t ccpl_huffbits3[7] = {
451 6,5,2,1,3,4,6,
452};
453
454static const uint8_t ccpl_huffbits4[15] = {
455 8,8,7,6,5,4,3,1,3,4,5,6,7,8,8,
456};
457
458static const uint8_t ccpl_huffbits5[31] = {
459 10,10,10,10,9,9,8,8,7,7,6,6,
460 5,5,3,1,3,5,5,6,6,7,7,8,
461 8,9,9,10,10,10,10,
462};
463
464static const uint8_t ccpl_huffbits6[63] = {
465 16,15,14,13,12,11,11,11,11,10,10,10,
466 10,9,9,9,9,9,8,8,8,8,7,7,
467 7,7,6,6,5,5,3,1,4,5,5,6,
468 6,7,7,7,7,8,8,8,8,9,9,9,
469 9,10,10,10,10,10,11,11,11,11,12,13,
470 14,14,16,
471};
472
473static const uint16_t* ccpl_huffcodes[5] = {
474 ccpl_huffcodes2,ccpl_huffcodes3,
475 ccpl_huffcodes4,ccpl_huffcodes5,ccpl_huffcodes6
476};
477
478static const uint8_t* ccpl_huffbits[5] = {
479 ccpl_huffbits2,ccpl_huffbits3,
480 ccpl_huffbits4,ccpl_huffbits5,ccpl_huffbits6
481};
482
483
484//Coupling tables
485
486static const int cplband[51] = {
487 0,1,2,3,4,5,6,7,8,9,
488 10,11,11,12,12,13,13,14,14,14,
489 15,15,15,15,16,16,16,16,16,17,
490 17,17,17,17,17,18,18,18,18,18,
491 18,18,19,19,19,19,19,19,19,19,
492 19,
493};
diff --git a/lib/rbcodec/codecs/libcook/cookdata_fixpoint.h b/lib/rbcodec/codecs/libcook/cookdata_fixpoint.h
new file mode 100644
index 0000000000..b58666031d
--- /dev/null
+++ b/lib/rbcodec/codecs/libcook/cookdata_fixpoint.h
@@ -0,0 +1,164 @@
1/*
2 * COOK compatible decoder fixed point data types and constants
3 * Copyright (c) 2007 Ian Braithwaite
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/**
24 * @file cookdata_fixpoint.h
25 * Cook AKA RealAudio G2 compatible decoder
26 * fixed point data types and constants
27 */
28
29#include <inttypes.h>
30typedef int32_t FIXP; /* Fixed point variable type */
31typedef uint16_t FIXPU; /* Fixed point fraction 0<=x<1 */
32
33typedef FIXP REAL_T;
34
35
36/* No additional variables in COOKContext
37 * for fixed point routines
38 */
39typedef struct {
40} realvars_t;
41
42static const FIXPU pow128_tab[128] = {
43 /* x_i = 2^(15+i/128) */
44 0x8000, 0x80b2, 0x8165, 0x8219, 0x82ce, 0x8383, 0x843a, 0x84f2, 0x85ab,
45 0x8665, 0x871f, 0x87db, 0x8898, 0x8956, 0x8a15, 0x8ad5, 0x8b96, 0x8c58,
46 0x8d1b, 0x8ddf, 0x8ea4, 0x8f6b, 0x9032, 0x90fa, 0x91c4, 0x928e, 0x935a,
47 0x9427, 0x94f5, 0x95c4, 0x9694, 0x9765, 0x9838, 0x990c, 0x99e0, 0x9ab6,
48 0x9b8d, 0x9c65, 0x9d3f, 0x9e19, 0x9ef5, 0x9fd2, 0xa0b0, 0xa190, 0xa270,
49 0xa352, 0xa435, 0xa519, 0xa5ff, 0xa6e6, 0xa7ce, 0xa8b7, 0xa9a1, 0xaa8d,
50 0xab7a, 0xac69, 0xad58, 0xae49, 0xaf3b, 0xb02f, 0xb124, 0xb21a, 0xb312,
51 0xb40b, 0xb505, 0xb601, 0xb6fe, 0xb7fc, 0xb8fc, 0xb9fd, 0xbaff, 0xbc03,
52 0xbd09, 0xbe0f, 0xbf18, 0xc021, 0xc12c, 0xc239, 0xc347, 0xc456, 0xc567,
53 0xc67a, 0xc78d, 0xc8a3, 0xc9ba, 0xcad2, 0xcbec, 0xcd08, 0xce25, 0xcf43,
54 0xd063, 0xd185, 0xd2a8, 0xd3cd, 0xd4f3, 0xd61b, 0xd745, 0xd870, 0xd99d,
55 0xdacc, 0xdbfc, 0xdd2e, 0xde61, 0xdf96, 0xe0cd, 0xe205, 0xe340, 0xe47b,
56 0xe5b9, 0xe6f8, 0xe839, 0xe97c, 0xeac1, 0xec07, 0xed4f, 0xee99, 0xefe5,
57 0xf132, 0xf281, 0xf3d3, 0xf525, 0xf67a, 0xf7d1, 0xf929, 0xfa84, 0xfbe0,
58 0xfd3e, 0xfe9e
59};
60
61
62
63/* dither_table and quant_centroid_table.
64 * Index 1: [0] - scaled by 2^13, [1] - scaled by 2^13 / sqrt(2)
65 * Index 2: [0..7] - category
66 * Index 3: [0] - dither_table, [1..13] - quant_centroid_table
67 */
68static const FIXP quant_tables[2][8][14] ICONST_ATTR = {{{
69 0x00000000, 0x0645a1cb, 0x0c2d0e56, 0x11eb851f, 0x17a1cac1, 0x1d4fdf3b,
70 0x22ed9168, 0x28a7ef9e, 0x2e49ba5e, 0x33eb851f, 0x39916873, 0x3f126e98,
71 0x449ba5e3, 0x4b958106
72},{
73 0x00000000, 0x08b43958, 0x10f5c28f, 0x19020c4a, 0x2116872b, 0x2922d0e5,
74 0x3126e979, 0x38fdf3b6, 0x411eb852, 0x49eb851f, 0x00000000, 0x00000000,
75 0x00000000, 0x00000000
76},{
77 0x00000000, 0x0bef9db2, 0x176c8b44, 0x22e147ae, 0x2e1cac08, 0x39581062,
78 0x450e5604, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
79 0x00000000, 0x00000000
80},{
81 0x00000000, 0x10189375, 0x20000000, 0x2fe353f8, 0x3fc28f5c, 0x00000000,
82 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
83 0x00000000, 0x00000000
84},{
85 0x00000000, 0x1522d0e5, 0x2b3f7cee, 0x3fba5e35, 0x00000000, 0x00000000,
86 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
87 0x00000000, 0x00000000
88},{
89 0x02d413cd, 0x1a83126f, 0x37db22d1, 0x00000000, 0x00000000, 0x00000000,
90 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
91 0x00000000, 0x00000000
92},{
93 0x04000000, 0x1f6c8b44, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
94 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
95 0x00000000, 0x00000000
96},{
97 0x0b504f33, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
98 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
99 0x00000000, 0x00000000
100}},{{
101 0x00000000, 0x046f5a70, 0x089c1768, 0x0cabddd3, 0x10b5d955, 0x14ba09ed,
102 0x18b2a4b4, 0x1cbf85aa, 0x20bb05e5, 0x24b68620, 0x28b4ebcf, 0x2c994066,
103 0x30835fe6, 0x35722a5e
104},{
105 0x00000000, 0x062797a1, 0x0bfe1683, 0x11aeee7a, 0x1765915b, 0x1d166952,
106 0x22c17660, 0x284ca76c, 0x2e0bfaaa, 0x3444f306, 0x00000000, 0x00000000,
107 0x00000000, 0x00000000
108},{
109 0x00000000, 0x0870a594, 0x1090326a, 0x18a9f456, 0x209b29e3, 0x288c5f70,
110 0x30d478a5, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
111 0x00000000, 0x00000000
112},{
113 0x00000000, 0x0b61afee, 0x16a09e66, 0x21dca76a, 0x2d15caf9, 0x00000000,
114 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
115 0x00000000, 0x00000000
116},{
117 0x00000000, 0x0ef20652, 0x1e94b968, 0x2d100010, 0x00000000, 0x00000000,
118 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
119 0x00000000, 0x00000000
120},{
121 0x02000000, 0x12bf2f44, 0x277f041b, 0x00000000, 0x00000000, 0x00000000,
122 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
123 0x00000000, 0x00000000
124},{
125 0x02d413cd, 0x16385a03, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
126 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
127 0x00000000, 0x00000000
128},{
129 0x08000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
130 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
131 0x00000000, 0x00000000
132}}};
133
134static const FIXPU cplscale2[3] = {
135 /* 2^16 C_ij */
136 0xf3f9, 0xb505, 0x4d8b
137};
138static const FIXPU cplscale3[7] = {
139 /* 2^16 C_ij */
140 0xfb35, 0xefdf, 0xe03d, 0xb505, 0x7b81, 0x596e, 0x314d
141};
142static const FIXPU cplscale4[15] = {
143 /* 2^16 C_ij */
144 0xfdd2, 0xf927, 0xf3f9, 0xee1d, 0xe749, 0xdee9, 0xd381, 0xb505, 0x903b,
145 0x7de2, 0x6dbe, 0x5e02, 0x4d8b, 0x3ad1, 0x2155
146};
147static const FIXPU cplscale5[31] = {
148 /* 2^16 C_ij */
149 0xfef5, 0xfcce, 0xfa8e, 0xf832, 0xf5b5, 0xf314, 0xf049, 0xed4c, 0xea12,
150 0xe68e, 0xe2ab, 0xde4b, 0xd938, 0xd30b, 0xcab6, 0xb505, 0x9c59, 0x90e8,
151 0x8778, 0x7ef9, 0x76fc, 0x6f45, 0x67ab, 0x600e, 0x5850, 0x504d, 0x47db,
152 0x3ebd, 0x3486, 0x2853, 0x1715
153};
154static const FIXPU cplscale6[63] = {
155 /* 2^16 C_ij */
156 0xff7d, 0xfe74, 0xfd65, 0xfc50, 0xfb35, 0xfa14, 0xf8eb, 0xf7bb, 0xf683,
157 0xf543, 0xf3f9, 0xf2a6, 0xf148, 0xefdf, 0xee6a, 0xece6, 0xeb54, 0xe9b2,
158 0xe7fd, 0xe634, 0xe453, 0xe258, 0xe03d, 0xddff, 0xdb94, 0xd8f4, 0xd610,
159 0xd2d2, 0xcf13, 0xca8c, 0xc47c, 0xb505, 0xa41a, 0x9c90, 0x9685, 0x913a,
160 0x8c67, 0x87e5, 0x839c, 0x7f7e, 0x7b81, 0x779b, 0x73c7, 0x6fff, 0x6c3f,
161 0x6883, 0x64c7, 0x6107, 0x5d40, 0x596e, 0x558d, 0x5198, 0x4d8b, 0x495f,
162 0x450d, 0x408b, 0x3bcd, 0x36c1, 0x314d, 0x2b4a, 0x246e, 0x1c1a, 0x1029
163};
164
diff --git a/lib/rbcodec/codecs/libcook/libcook.make b/lib/rbcodec/codecs/libcook/libcook.make
new file mode 100644
index 0000000000..c7bdca90c5
--- /dev/null
+++ b/lib/rbcodec/codecs/libcook/libcook.make
@@ -0,0 +1,18 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id:$
8#
9
10# libcook
11COOKLIB := $(CODECDIR)/libcook.a
12COOKLIB_SRC := $(call preprocess, $(RBCODECLIB_DIR)/codecs/libcook/SOURCES)
13COOKLIB_OBJ := $(call c2obj, $(COOKLIB_SRC))
14OTHER_SRC += $(COOKLIB_SRC)
15
16$(COOKLIB): $(COOKLIB_OBJ)
17 $(SILENT)$(shell rm -f $@)
18 $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null