annotate libfaad2/huffman.c @ 13835:717a3d19e0c4

osx port related
author nplourde
date Sun, 31 Oct 2004 22:43:41 +0000
parents 6d50ef45a058
children 2ae5ab4331ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10989
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
1 /*
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
10989
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
4 **
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
8 ** (at your option) any later version.
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
9 **
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
13 ** GNU General Public License for more details.
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
14 **
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
18 **
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
20 ** forbidden.
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
21 **
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
24 **
12625
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
25 ** Initially modified for use with MPlayer by Alex Beregszaszi on 2003/10/03
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
26 ** $Id: huffman.c,v 1.3 2004/06/23 13:50:50 diego Exp $
12625
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
10989
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
28 **/
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
29
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
30 #include "common.h"
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
31 #include "structs.h"
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
32
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
33 #include <stdlib.h>
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
34 #ifdef ANALYSIS
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
35 #include <stdio.h>
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
36 #endif
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
37
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
38 #include "bits.h"
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
39 #include "huffman.h"
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
40 #include "codebook/hcb.h"
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
41
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
42
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
43 /* static function declarations */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
44 static INLINE void huffman_sign_bits(bitfile *ld, int16_t *sp, uint8_t len);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
45 static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
46 static uint8_t huffman_2step_quad(uint8_t cb, bitfile *ld, int16_t *sp);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
47 static uint8_t huffman_2step_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
48 static uint8_t huffman_2step_pair(uint8_t cb, bitfile *ld, int16_t *sp);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
49 static uint8_t huffman_2step_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
50 static uint8_t huffman_binary_quad(uint8_t cb, bitfile *ld, int16_t *sp);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
51 static uint8_t huffman_binary_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
52 static uint8_t huffman_binary_pair(uint8_t cb, bitfile *ld, int16_t *sp);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
53 static uint8_t huffman_binary_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
54 static int16_t huffman_codebook(uint8_t i);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
55
10989
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
56 int8_t huffman_scale_factor(bitfile *ld)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
57 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
58 uint16_t offset = 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
59
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
60 while (hcb_sf[offset][1])
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
61 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
62 uint8_t b = faad_get1bit(ld
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
63 DEBUGVAR(1,255,"huffman_scale_factor()"));
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
64 offset += hcb_sf[offset][b];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
65
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
66 if (offset > 240)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
67 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
68 /* printf("ERROR: offset into hcb_sf = %d >240!\n", offset); */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
69 return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
70 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
71 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
72
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
73 return hcb_sf[offset][0];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
74 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
75
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
76
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
77 hcb *hcb_table[] = {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
78 0, hcb1_1, hcb2_1, 0, hcb4_1, 0, hcb6_1, 0, hcb8_1, 0, hcb10_1, hcb11_1
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
79 };
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
80
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
81 hcb_2_quad *hcb_2_quad_table[] = {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
82 0, hcb1_2, hcb2_2, 0, hcb4_2, 0, 0, 0, 0, 0, 0, 0
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
83 };
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
84
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
85 hcb_2_pair *hcb_2_pair_table[] = {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
86 0, 0, 0, 0, 0, 0, hcb6_2, 0, hcb8_2, 0, hcb10_2, hcb11_2
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
87 };
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
88
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
89 hcb_bin_pair *hcb_bin_table[] = {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
90 0, 0, 0, 0, 0, hcb5, 0, hcb7, 0, hcb9, 0, 0
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
91 };
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
92
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
93 uint8_t hcbN[] = { 0, 5, 5, 0, 5, 0, 5, 0, 5, 0, 6, 5 };
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
94
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
95 /* defines whether a huffman codebook is unsigned or not */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
96 /* Table 4.6.2 */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
97 uint8_t unsigned_cb[] = { 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
98 /* codebook 16 to 31 */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
99 };
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
100
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
101 int hcb_2_quad_table_size[] = { 0, 114, 86, 0, 185, 0, 0, 0, 0, 0, 0, 0 };
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
102 int hcb_2_pair_table_size[] = { 0, 0, 0, 0, 0, 0, 126, 0, 83, 0, 210, 373 };
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
103 int hcb_bin_table_size[] = { 0, 0, 0, 161, 0, 161, 0, 127, 0, 337, 0, 0 };
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
104
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
105 static INLINE void huffman_sign_bits(bitfile *ld, int16_t *sp, uint8_t len)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
106 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
107 uint8_t i;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
108
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
109 for (i = 0; i < len; i++)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
110 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
111 if(sp[i])
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
112 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
113 if(faad_get1bit(ld
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
114 DEBUGVAR(1,5,"huffman_sign_bits(): sign bit")) & 1)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
115 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
116 sp[i] = -sp[i];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
117 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
118 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
119 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
120 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
121
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
122 static INLINE int16_t huffman_getescape(bitfile *ld, int16_t sp)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
123 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
124 uint8_t neg, i;
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
125 int16_t j;
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
126 int16_t off;
10989
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
127
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
128 if (sp < 0)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
129 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
130 if (sp != -16)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
131 return sp;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
132 neg = 1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
133 } else {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
134 if (sp != 16)
10989
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
135 return sp;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
136 neg = 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
137 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
138
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
139 for (i = 4; ; i++)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
140 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
141 if (faad_get1bit(ld
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
142 DEBUGVAR(1,6,"huffman_getescape(): escape size")) == 0)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
143 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
144 break;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
145 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
146 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
147
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
148 off = (int16_t)faad_getbits(ld, i
10989
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
149 DEBUGVAR(1,9,"huffman_getescape(): escape"));
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
150
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
151 j = off | (1<<i);
10989
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
152 if (neg)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
153 j = -j;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
154
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
155 return j;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
156 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
157
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
158 static uint8_t huffman_2step_quad(uint8_t cb, bitfile *ld, int16_t *sp)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
159 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
160 uint32_t cw;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
161 uint16_t offset = 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
162 uint8_t extra_bits;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
163
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
164 cw = faad_showbits(ld, hcbN[cb]);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
165 offset = hcb_table[cb][cw].offset;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
166 extra_bits = hcb_table[cb][cw].extra_bits;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
167
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
168 if (extra_bits)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
169 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
170 /* we know for sure it's more than hcbN[cb] bits long */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
171 faad_flushbits(ld, hcbN[cb]);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
172 offset += (uint16_t)faad_showbits(ld, extra_bits);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
173 faad_flushbits(ld, hcb_2_quad_table[cb][offset].bits - hcbN[cb]);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
174 } else {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
175 faad_flushbits(ld, hcb_2_quad_table[cb][offset].bits);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
176 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
177
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
178 if (offset > hcb_2_quad_table_size[cb])
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
179 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
180 /* printf("ERROR: offset into hcb_2_quad_table = %d >%d!\n", offset,
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
181 hcb_2_quad_table_size[cb]); */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
182 return 10;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
183 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
184
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
185 sp[0] = hcb_2_quad_table[cb][offset].x;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
186 sp[1] = hcb_2_quad_table[cb][offset].y;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
187 sp[2] = hcb_2_quad_table[cb][offset].v;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
188 sp[3] = hcb_2_quad_table[cb][offset].w;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
189
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
190 return 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
191 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
192
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
193 static uint8_t huffman_2step_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
194 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
195 uint8_t err = huffman_2step_quad(cb, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
196 huffman_sign_bits(ld, sp, QUAD_LEN);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
197
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
198 return err;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
199 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
200
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
201 static uint8_t huffman_2step_pair(uint8_t cb, bitfile *ld, int16_t *sp)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
202 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
203 uint32_t cw;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
204 uint16_t offset = 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
205 uint8_t extra_bits;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
206
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
207 cw = faad_showbits(ld, hcbN[cb]);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
208 offset = hcb_table[cb][cw].offset;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
209 extra_bits = hcb_table[cb][cw].extra_bits;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
210
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
211 if (extra_bits)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
212 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
213 /* we know for sure it's more than hcbN[cb] bits long */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
214 faad_flushbits(ld, hcbN[cb]);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
215 offset += (uint16_t)faad_showbits(ld, extra_bits);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
216 faad_flushbits(ld, hcb_2_pair_table[cb][offset].bits - hcbN[cb]);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
217 } else {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
218 faad_flushbits(ld, hcb_2_pair_table[cb][offset].bits);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
219 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
220
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
221 if (offset > hcb_2_pair_table_size[cb])
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
222 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
223 /* printf("ERROR: offset into hcb_2_pair_table = %d >%d!\n", offset,
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
224 hcb_2_pair_table_size[cb]); */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
225 return 10;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
226 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
227
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
228 sp[0] = hcb_2_pair_table[cb][offset].x;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
229 sp[1] = hcb_2_pair_table[cb][offset].y;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
230
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
231 return 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
232 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
233
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
234 static uint8_t huffman_2step_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp)
10989
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
235 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
236 uint8_t err = huffman_2step_pair(cb, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
237 huffman_sign_bits(ld, sp, PAIR_LEN);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
238
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
239 return err;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
240 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
241
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
242 static uint8_t huffman_binary_quad(uint8_t cb, bitfile *ld, int16_t *sp)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
243 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
244 uint16_t offset = 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
245
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
246 while (!hcb3[offset].is_leaf)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
247 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
248 uint8_t b = faad_get1bit(ld
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
249 DEBUGVAR(1,255,"huffman_spectral_data():3"));
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
250 offset += hcb3[offset].data[b];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
251 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
252
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
253 if (offset > hcb_bin_table_size[cb])
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
254 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
255 /* printf("ERROR: offset into hcb_bin_table = %d >%d!\n", offset,
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
256 hcb_bin_table_size[cb]); */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
257 return 10;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
258 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
259
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
260 sp[0] = hcb3[offset].data[0];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
261 sp[1] = hcb3[offset].data[1];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
262 sp[2] = hcb3[offset].data[2];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
263 sp[3] = hcb3[offset].data[3];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
264
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
265 return 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
266 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
267
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
268 static uint8_t huffman_binary_quad_sign(uint8_t cb, bitfile *ld, int16_t *sp)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
269 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
270 uint8_t err = huffman_binary_quad(cb, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
271 huffman_sign_bits(ld, sp, QUAD_LEN);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
272
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
273 return err;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
274 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
275
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
276 static uint8_t huffman_binary_pair(uint8_t cb, bitfile *ld, int16_t *sp)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
277 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
278 uint16_t offset = 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
279
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
280 while (!hcb_bin_table[cb][offset].is_leaf)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
281 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
282 uint8_t b = faad_get1bit(ld
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
283 DEBUGVAR(1,255,"huffman_spectral_data():9"));
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
284 offset += hcb_bin_table[cb][offset].data[b];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
285 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
286
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
287 if (offset > hcb_bin_table_size[cb])
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
288 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
289 /* printf("ERROR: offset into hcb_bin_table = %d >%d!\n", offset,
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
290 hcb_bin_table_size[cb]); */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
291 return 10;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
292 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
293
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
294 sp[0] = hcb_bin_table[cb][offset].data[0];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
295 sp[1] = hcb_bin_table[cb][offset].data[1];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
296
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
297 return 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
298 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
299
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
300 static uint8_t huffman_binary_pair_sign(uint8_t cb, bitfile *ld, int16_t *sp)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
301 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
302 uint8_t err = huffman_binary_pair(cb, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
303 huffman_sign_bits(ld, sp, PAIR_LEN);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
304
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
305 return err;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
306 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
307
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
308 static int16_t huffman_codebook(uint8_t i)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
309 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
310 static const uint32_t data = 16428320;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
311 if (i == 0) return (int16_t)(data >> 16) & 0xFFFF;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
312 else return (int16_t)data & 0xFFFF;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
313 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
314
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
315 uint8_t huffman_spectral_data(uint8_t cb, bitfile *ld, int16_t *sp)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
316 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
317 switch (cb)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
318 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
319 case 1: /* 2-step method for data quadruples */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
320 case 2:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
321 return huffman_2step_quad(cb, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
322 case 3: /* binary search for data quadruples */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
323 return huffman_binary_quad_sign(cb, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
324 case 4: /* 2-step method for data quadruples */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
325 return huffman_2step_quad_sign(cb, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
326 case 5: /* binary search for data pairs */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
327 return huffman_binary_pair(cb, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
328 case 6: /* 2-step method for data pairs */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
329 return huffman_2step_pair(cb, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
330 case 7: /* binary search for data pairs */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
331 case 9:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
332 return huffman_binary_pair_sign(cb, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
333 case 8: /* 2-step method for data pairs */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
334 case 10:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
335 return huffman_2step_pair_sign(cb, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
336 case 12: {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
337 uint8_t err = huffman_2step_pair(11, ld, sp);
10989
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
338 sp[0] = huffman_codebook(0); sp[1] = huffman_codebook(1);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
339 return err; }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
340 case 11:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
341 #ifdef ERROR_RESILIENCE
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
342 /* VCB11 uses codebook 11 */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
343 case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
344 case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
345 /* TODO: If ER is used, some extra error checking should be done */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
346 #endif
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
347 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
348 uint8_t err = huffman_2step_pair_sign(11, ld, sp);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
349 sp[0] = huffman_getescape(ld, sp[0]);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
350 sp[1] = huffman_getescape(ld, sp[1]);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
351 return err;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
352 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
353 default:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
354 /* Non existent codebook number, something went wrong */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
355 return 11;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
356 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
357
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
358 return 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
359 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
360
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
361
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
362 #ifdef ERROR_RESILIENCE
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
363
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
364 /* Special version of huffman_spectral_data
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
365 Will not read from a bitfile but a bits_t structure.
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
366 Will keep track of the bits decoded and return the number of bits remaining.
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
367 Do not read more than ld->len, return -1 if codeword would be longer */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
368
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
369 int8_t huffman_spectral_data_2(uint8_t cb, bits_t *ld, int16_t *sp)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
370 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
371 uint32_t cw;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
372 uint16_t offset = 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
373 uint8_t extra_bits;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
374 uint8_t i;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
375
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
376
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
377 switch (cb)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
378 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
379 case 1: /* 2-step method for data quadruples */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
380 case 2:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
381 case 4:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
382
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
383 cw = showbits_hcr(ld, hcbN[cb]);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
384 offset = hcb_table[cb][cw].offset;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
385 extra_bits = hcb_table[cb][cw].extra_bits;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
386
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
387 if (extra_bits)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
388 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
389 /* we know for sure it's more than hcbN[cb] bits long */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
390 if ( flushbits_hcr(ld, hcbN[cb]) ) return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
391 offset += (uint16_t)showbits_hcr(ld, extra_bits);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
392 if ( flushbits_hcr(ld, hcb_2_quad_table[cb][offset].bits - hcbN[cb]) ) return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
393 } else {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
394 if ( flushbits_hcr(ld, hcb_2_quad_table[cb][offset].bits) ) return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
395 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
396
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
397 sp[0] = hcb_2_quad_table[cb][offset].x;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
398 sp[1] = hcb_2_quad_table[cb][offset].y;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
399 sp[2] = hcb_2_quad_table[cb][offset].v;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
400 sp[3] = hcb_2_quad_table[cb][offset].w;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
401 break;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
402
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
403 case 6: /* 2-step method for data pairs */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
404 case 8:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
405 case 10:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
406 case 11:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
407 /* VCB11 uses codebook 11 */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
408 case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
409 case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
410
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
411 /* TODO: If ER is used, some extra error checking should be done */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
412 if (cb >= 16)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
413 cb = 11;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
414
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
415 cw = showbits_hcr(ld, hcbN[cb]);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
416 offset = hcb_table[cb][cw].offset;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
417 extra_bits = hcb_table[cb][cw].extra_bits;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
418
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
419 if (extra_bits)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
420 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
421 /* we know for sure it's more than hcbN[cb] bits long */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
422 if ( flushbits_hcr(ld, hcbN[cb]) ) return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
423 offset += (uint16_t)showbits_hcr(ld, extra_bits);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
424 if ( flushbits_hcr(ld, hcb_2_pair_table[cb][offset].bits - hcbN[cb]) ) return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
425 } else {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
426 if ( flushbits_hcr(ld, hcb_2_pair_table[cb][offset].bits) ) return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
427 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
428 sp[0] = hcb_2_pair_table[cb][offset].x;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
429 sp[1] = hcb_2_pair_table[cb][offset].y;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
430 break;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
431
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
432 case 3: /* binary search for data quadruples */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
433
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
434 while (!hcb3[offset].is_leaf)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
435 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
436 uint8_t b;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
437
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
438 if ( get1bit_hcr(ld, &b) ) return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
439 offset += hcb3[offset].data[b];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
440 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
441
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
442 sp[0] = hcb3[offset].data[0];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
443 sp[1] = hcb3[offset].data[1];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
444 sp[2] = hcb3[offset].data[2];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
445 sp[3] = hcb3[offset].data[3];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
446
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
447 break;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
448
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
449 case 5: /* binary search for data pairs */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
450 case 7:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
451 case 9:
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
452
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
453 while (!hcb_bin_table[cb][offset].is_leaf)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
454 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
455 uint8_t b;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
456
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
457 if (get1bit_hcr(ld, &b) ) return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
458 offset += hcb_bin_table[cb][offset].data[b];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
459 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
460
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
461 sp[0] = hcb_bin_table[cb][offset].data[0];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
462 sp[1] = hcb_bin_table[cb][offset].data[1];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
463
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
464 break;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
465 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
466
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
467 /* decode sign bits */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
468 if (unsigned_cb[cb]) {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
469
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
470 for(i = 0; i < ((cb < FIRST_PAIR_HCB) ? QUAD_LEN : PAIR_LEN); i++)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
471 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
472 if(sp[i])
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
473 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
474 uint8_t b;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
475 if ( get1bit_hcr(ld, &b) ) return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
476 if (b != 0) {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
477 sp[i] = -sp[i];
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
478 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
479 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
480 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
481 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
482
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
483 /* decode huffman escape bits */
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
484 if ((cb == ESC_HCB) || (cb >= 16))
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
485 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
486 uint8_t k;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
487 for (k = 0; k < 2; k++)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
488 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
489 if ((sp[k] == 16) || (sp[k] == -16))
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
490 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
491 uint8_t neg, i;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
492 int32_t j;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
493 uint32_t off;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
494
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
495 neg = (sp[k] < 0) ? 1 : 0;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
496
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
497 for (i = 4; ; i++)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
498 {
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
499 uint8_t b;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
500 if (get1bit_hcr(ld, &b))
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
501 return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
502 if (b == 0)
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
503 break;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
504 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
505 // TODO: here we would need to test "off" if VCB11 is used!
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
506 if (getbits_hcr(ld, i, &off))
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
507 return -1;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
508 j = off + (1<<i);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
509 sp[k] = (int16_t)((neg) ? -j : j);
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
510 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
511 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
512 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
513 return ld->len;
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
514 }
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
515
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
516 #endif
3185f64f6350 synced with current cvs
alex
parents:
diff changeset
517