annotate libfaad2/hcr.c @ 10913:49b1a67e7381

Add revision keyword to english xml files, to ease translation synchronization (as in help/help_mp-en.h)
author lumag
date Sun, 21 Sep 2003 13:05:42 +0000
parents e989150f8216
children 3185f64f6350
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
1 /*
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
3 ** Copyright (C) 2002 A. Kurpiers
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
4 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
6 ** it under the terms of the GNU General Public License as published by
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
8 ** (at your option) any later version.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
9 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
10 ** This program is distributed in the hope that it will be useful,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
13 ** GNU General Public License for more details.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
14 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
16 ** along with this program; if not, write to the Free Software
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
18 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
19 ** Any non-GPL usage of this software or parts of this software is strictly
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
20 ** forbidden.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
21 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
22 ** Commercial non-GPL licensing of this software is possible.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
24 **
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
25 ** $Id: hcr.c,v 1.5 2003/07/29 08:20:12 menno Exp $
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
26 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
27
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 #include <string.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include "syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include "specrec.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 #include "bits.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 #include "pulse.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 #include "analysis.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 #include "bits.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 #include "codebook/hcb.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 /* Implements the HCR11 tool as described in ISO/IEC 14496-3/Amd.1, 8.5.3.3 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47 typedef struct
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 /* bit input */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 uint32_t bufa;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 uint32_t bufb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52 int8_t len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 } bits_t;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 static INLINE uint32_t showbits(bits_t *ld, uint8_t bits)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 if (bits == 0) return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 if (ld->len <= 32){
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60 /* huffman_spectral_data_2 needs to read more than may be available, bits maybe
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 > ld->len, deliver 0 than */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 if (ld->len >= bits)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 return ((ld->bufa >> (ld->len - bits)) & (0xFFFFFFFF >> (32 - bits)));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 return ((ld->bufa << (bits - ld->len)) & (0xFFFFFFFF >> (32 - bits)));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 if ((ld->len - bits) < 32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 return ( (ld->bufb & (0xFFFFFFFF >> (64 - ld->len))) << (bits - ld->len + 32)) |
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 (ld->bufa >> (ld->len - bits));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 return ((ld->bufb >> (ld->len - bits - 32)) & (0xFFFFFFFF >> (32 - bits)));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 /* return 1 if position is outside of buffer, 0 otherwise */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 static INLINE int8_t flushbits( bits_t *ld, uint8_t bits)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 ld->len -= bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 if (ld->len <0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 ld->len = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 return 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 static INLINE int8_t getbits(bits_t *ld, uint8_t n, uint32_t *result)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 *result = showbits(ld, n);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 return flushbits(ld, n);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
96 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
97
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 static INLINE int8_t get1bit(bits_t *ld, uint8_t *result)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 uint32_t res;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 int8_t ret;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 ret = getbits(ld, 1, &res);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 *result = (int8_t)(res & 1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 return ret;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 /* Special version of huffman_spectral_data adapted from huffman.h
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 Will not read from a bitfile but a bits_t structure.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 Will keep track of the bits decoded and return the number of bits remaining.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 Do not read more than ld->len, return -1 if codeword would be longer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 static int8_t huffman_spectral_data_2(uint8_t cb, bits_t *ld, int16_t *sp )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 uint32_t cw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 uint16_t offset = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 uint8_t extra_bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 uint8_t save_cb = cb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 switch (cb)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 case 1: /* 2-step method for data quadruples */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 case 2:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 case 4:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 cw = showbits(ld, hcbN[cb]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 offset = hcb_table[cb][cw].offset;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 extra_bits = hcb_table[cb][cw].extra_bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 if (extra_bits)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 /* we know for sure it's more than hcbN[cb] bits long */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 if ( flushbits(ld, hcbN[cb]) ) return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 offset += (uint16_t)showbits(ld, extra_bits);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 if ( flushbits(ld, hcb_2_quad_table[cb][offset].bits - hcbN[cb]) ) return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 if ( flushbits(ld, hcb_2_quad_table[cb][offset].bits) ) return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 sp[0] = hcb_2_quad_table[cb][offset].x;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 sp[1] = hcb_2_quad_table[cb][offset].y;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144 sp[2] = hcb_2_quad_table[cb][offset].v;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 sp[3] = hcb_2_quad_table[cb][offset].w;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 case 6: /* 2-step method for data pairs */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 case 8:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 case 10:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 case 11:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 /* VCB11 uses codebook 11 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 /* TODO: If ER is used, some extra error checking should be done */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157 if (cb >= 16)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158 cb = 11;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 cw = showbits(ld, hcbN[cb]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 offset = hcb_table[cb][cw].offset;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 extra_bits = hcb_table[cb][cw].extra_bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 if (extra_bits)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 /* we know for sure it's more than hcbN[cb] bits long */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 if ( flushbits(ld, hcbN[cb]) ) return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 offset += (uint16_t)showbits(ld, extra_bits);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169 if ( flushbits(ld, hcb_2_pair_table[cb][offset].bits - hcbN[cb]) ) return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 if ( flushbits(ld, hcb_2_pair_table[cb][offset].bits) ) return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 sp[0] = hcb_2_pair_table[cb][offset].x;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 sp[1] = hcb_2_pair_table[cb][offset].y;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 case 3: /* binary search for data quadruples */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179 while (!hcb3[offset].is_leaf)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 uint8_t b;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 if ( get1bit(ld, &b) ) return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 offset += hcb3[offset].data[b];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 sp[0] = hcb3[offset].data[0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 sp[1] = hcb3[offset].data[1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 sp[2] = hcb3[offset].data[2];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 sp[3] = hcb3[offset].data[3];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 case 5: /* binary search for data pairs */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 case 7:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 case 9:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 while (!hcb_bin_table[cb][offset].is_leaf)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 uint8_t b;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 if (get1bit(ld, &b) ) return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 offset += hcb_bin_table[cb][offset].data[b];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 sp[0] = hcb_bin_table[cb][offset].data[0];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 sp[1] = hcb_bin_table[cb][offset].data[1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 /* decode sign bits */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 if (unsigned_cb[cb]) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 for(i = 0; i < ((cb < FIRST_PAIR_HCB) ? QUAD_LEN : PAIR_LEN); i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 if(sp[i])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 uint8_t b;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220 if ( get1bit(ld, &b) ) return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 if (b != 0) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 sp[i] = -sp[i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 /* decode huffman escape bits */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 if ((cb == ESC_HCB) || (cb >= 16))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 uint8_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 for (k = 0; k < 2; k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234 if ((sp[k] == 16) || (sp[k] == -16))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 uint8_t neg, i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 int32_t j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 uint32_t off;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 neg = (sp[k] < 0) ? 1 : 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 for (i = 4; ; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 uint8_t b;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 if (get1bit(ld, &b))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246 return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 if (b == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 // TODO: here we would need to test "off" if VCB11 is used!
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 if (getbits(ld, i, &off))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 return -1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 j = off + (1<<i);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 sp[k] = (int16_t)((neg) ? -j : j);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 return ld->len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 /* rewind len (max. 32) bits so that the MSB becomes LSB */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 static uint32_t rewind_word( uint32_t W, uint8_t len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 uint32_t tmp_W=0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268 for ( i=0; i<len; i++ )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270 tmp_W<<=1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 if (W & (1<<i)) tmp_W |= 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 return tmp_W;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 static void rewind_lword( uint32_t *highW, uint32_t *lowW, uint8_t len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 uint32_t tmp_lW=0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 if (len > 32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 tmp_lW = rewind_word( (*highW << (64-len)) | (*lowW >> (len-32)), 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 *highW = rewind_word( *lowW << (64-len) , 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 *lowW = tmp_lW;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286 *highW = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 *lowW = rewind_word( *lowW, len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291 /* Takes a codeword as stored in r, rewinds the remaining bits and stores it back */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292 static void rewind_bits(bits_t * r)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
294 uint32_t hw, lw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296 if (r->len == 0) return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298 if (r->len >32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 lw = r->bufa;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301 hw = r->bufb & (0xFFFFFFFF >> (64 - r->len));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302 rewind_lword( &hw, &lw, r->len );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 r->bufa = lw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304 r->bufb = hw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
307 lw = showbits(r, r->len );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
308 r->bufa = rewind_word( lw, r->len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
309 r->bufb = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
310 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
312
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
313 /* takes codewords from a and b, concatenate them and store them in b */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
314 static void concat_bits( bits_t * a, bits_t * b)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
315 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
316 uint32_t hwa, lwa, hwb, lwb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
317
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
318 if (a->len == 0) return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
319
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
320 if (a->len >32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
321 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
322 lwa = a->bufa;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323 hwa = a->bufb & (0xFFFFFFFF >> (64 - a->len));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
324 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
325 lwa = showbits(a, a->len );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
326 hwa = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
327 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
328 if (b->len >=32) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 lwb = b->bufa;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
330 hwb = (b->bufb & (0xFFFFFFFF >> (64 - b->len)) ) | ( lwa << (b->len - 32));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
331 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
332 lwb = showbits(b, b->len ) | (lwa << (b->len));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
333 hwb = (lwa >> (32 - b->len)) | (hwa << (b->len));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
334 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
335
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
336 b->bufa = lwb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
337 b->bufb = hwb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
338 b->len += a->len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
339 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
340
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
341 /* 8.5.3.3.1 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
342
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
343 static const uint8_t PresortedCodebook_VCB11[] = { 11, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 9, 7, 5, 3, 1};
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
344 static const uint8_t PresortedCodebook[] = { 11, 9, 7, 5, 3, 1};
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
345
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
346 static const uint8_t maxCwLen[32] = {0, 11, 9, 20, 16, 13, 11, 14, 12, 17, 14, 49,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
347 0, 0, 0, 0, 14, 17, 21, 21, 25, 25, 29, 29, 29, 29, 33, 33, 33, 37, 37, 41};
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
348
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
349 typedef struct
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
350 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 bits_t bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352 uint8_t decoded;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
353 uint16_t sp_offset;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
354 uint8_t cb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
355 } codeword_state;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
356
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
357
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
358 #define segmentWidth( codebook ) min( maxCwLen[codebook], ics->length_of_longest_codeword )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
359
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
360 uint8_t reordered_spectral_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
361 int16_t *spectral_data)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
362 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363 uint16_t sp_offset[8];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
364 uint16_t g,i, presort;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
365 uint16_t NrCodeWords=0, numberOfSegments=0, BitsRead=0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
366 uint8_t numberOfSets, set;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 codeword_state Codewords[ 1024 ]; // FIXME max length? PCWs are not stored, so index is Codewordnr - numberOfSegments!, maybe malloc()?
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
368 bits_t Segment[ 512 ];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
369
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370 uint8_t PCW_decoded=0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371 uint16_t segment_index=0, codeword_index=0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372 uint16_t nshort = hDecoder->frameLength/8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
373
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
374
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
375 memset (spectral_data, 0, hDecoder->frameLength*sizeof(uint16_t));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
376
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
377 if (ics->length_of_reordered_spectral_data == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
378 return 0; /* nothing to do */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
379
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380 /* if we have a corrupted bitstream this can happen... */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
381 if ((ics->length_of_longest_codeword == 0) ||
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
382 (ics->length_of_reordered_spectral_data <
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
383 ics->length_of_longest_codeword) ||
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
384 (ics->max_sfb == 0))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
385 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
386 return 10; /* this is not good... */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
387 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
388
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
389 /* store the offset into the spectral data for all the window groups because we can't do it later */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
390
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
391 sp_offset[0] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
392 for (g=1; g < ics->num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
393 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
394 sp_offset[g] = sp_offset[g-1] + nshort*ics->window_group_length[g-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
395 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
396
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
397 /* All data is sorted according to the codebook used */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
398 for (presort = 0; presort < (hDecoder->aacSectionDataResilienceFlag ? 22 : 6); presort++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
399 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
400 uint8_t sfb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
401
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
402 /* next codebook that has to be processed according to presorting */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
403 uint8_t nextCB = hDecoder->aacSectionDataResilienceFlag ? PresortedCodebook_VCB11[ presort ] : PresortedCodebook[ presort ];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
404
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
405 /* Data belonging to the same spectral unit and having the same codebook comes in consecutive codewords.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
406 This is done by scanning all sfbs for possible codewords. For sfbs with more than 4 elements this has to be
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
407 repeated */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
408
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
409 for (sfb=0; sfb<ics->max_sfb; sfb ++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
410 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
411 uint8_t sect_cb, w;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
412
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
413 for (w=0; w< (ics->swb_offset[sfb+1] - ics->swb_offset[sfb]); w+=4)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
414 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
415 for(g = 0; g < ics->num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
416 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
417 for (i = 0; i < ics->num_sec[g]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
418 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
419 sect_cb = ics->sect_cb[g][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
420
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
421 if (
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
422 /* process only sections that are due now */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
423 (( sect_cb == nextCB ) || (( nextCB < ESC_HCB ) && ( sect_cb == nextCB+1)) ) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
424
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
425 /* process only sfb's that are due now */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
426 ((ics->sect_start[g][i] <= sfb) && (ics->sect_end[g][i] > sfb))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
427 )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
428 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
429 if ((sect_cb != ZERO_HCB) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
430 (sect_cb != NOISE_HCB) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
431 (sect_cb != INTENSITY_HCB) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
432 (sect_cb != INTENSITY_HCB2))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
433 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
434 uint8_t inc = (sect_cb < FIRST_PAIR_HCB) ? QUAD_LEN : PAIR_LEN;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
435 uint16_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
436
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
437 uint32_t hw, lw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
438
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
439 for (k=0; (k < (4/inc)*ics->window_group_length[g]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
440 ( (k+w*ics->window_group_length[g]/inc) < (ics->sect_sfb_offset[g][sfb+1] - ics->sect_sfb_offset[g][sfb])); k++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
441 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
442 uint16_t sp = sp_offset[g] + ics->sect_sfb_offset[g][sfb] + inc*(k+w*ics->window_group_length[g]/inc);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
443
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
444 if (!PCW_decoded)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
445 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
446 /* if we haven't yet read until the end of the buffer, we can directly decode the so-called PCWs */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
447 if ((BitsRead + segmentWidth( sect_cb ))<= ics->length_of_reordered_spectral_data)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
448 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
449 Segment[ numberOfSegments ].len = segmentWidth( sect_cb );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
450
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
451 if (segmentWidth( sect_cb ) > 32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
452 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
453 Segment[ numberOfSegments ].bufb = faad_showbits(ld, segmentWidth( sect_cb ) - 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
454 faad_flushbits(ld, segmentWidth( sect_cb) - 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
455 Segment[ numberOfSegments ].bufa = faad_showbits(ld, 32),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
456 faad_flushbits(ld, 32 );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
457
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
458 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
459 Segment[ numberOfSegments ].bufa = faad_showbits(ld, segmentWidth( sect_cb ));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
460 Segment[ numberOfSegments ].bufb = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
461 faad_flushbits(ld, segmentWidth( sect_cb) );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
462 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
463
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
464 huffman_spectral_data_2(sect_cb, &Segment[ numberOfSegments ], &spectral_data[sp]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
465
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
466 BitsRead += segmentWidth( sect_cb );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
467
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
468 /* skip to next segment, but store left bits in new buffer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
469 rewind_bits( &Segment[ numberOfSegments ]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
470
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
471 numberOfSegments++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
472 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
473
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
474 /* the last segment is extended until length_of_reordered_spectral_data */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
475
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
476 if (BitsRead < ics->length_of_reordered_spectral_data)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
477 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
478
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
479 uint8_t additional_bits = (ics->length_of_reordered_spectral_data - BitsRead);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
480
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
481 if ( additional_bits > 32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
482 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
483 hw = faad_showbits(ld, additional_bits - 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
484 faad_flushbits(ld, additional_bits - 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
485 lw = faad_showbits(ld, 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
486 faad_flushbits(ld, 32 );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
487 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
488 lw = faad_showbits(ld, additional_bits);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
489 hw = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
490 faad_flushbits(ld, additional_bits );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
491 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
492 rewind_lword( &hw, &lw, additional_bits + Segment[ numberOfSegments-1 ].len );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
493 if (Segment[ numberOfSegments-1 ].len > 32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
494 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
495 Segment[ numberOfSegments-1 ].bufb = hw +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
496 showbits(&Segment[ numberOfSegments-1 ], Segment[ numberOfSegments-1 ].len - 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
497 Segment[ numberOfSegments-1 ].bufa = lw +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
498 showbits(&Segment[ numberOfSegments-1 ], 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
499 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
500 Segment[ numberOfSegments-1 ].bufa = lw +
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
501 showbits(&Segment[ numberOfSegments-1 ], Segment[ numberOfSegments-1 ].len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
502 Segment[ numberOfSegments-1 ].bufb = hw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
503 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
504 Segment[ numberOfSegments-1 ].len += additional_bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
505 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
506 BitsRead = ics->length_of_reordered_spectral_data;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
507 PCW_decoded = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
508
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
509 Codewords[ 0 ].sp_offset = sp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
510 Codewords[ 0 ].cb = sect_cb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
511 Codewords[ 0 ].decoded = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
512 Codewords[ 0 ].bits.len = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
513 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
514 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
515 Codewords[ NrCodeWords - numberOfSegments ].sp_offset = sp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
516 Codewords[ NrCodeWords - numberOfSegments ].cb = sect_cb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
517 Codewords[ NrCodeWords - numberOfSegments ].decoded = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
518 Codewords[ NrCodeWords - numberOfSegments ].bits.len = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
519
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
520 } /* PCW decoded */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
521 NrCodeWords++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
522 } /* of k */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
523 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
524 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
525 } /* of i */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
526 } /* of g */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
527 } /* of w */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
528 } /* of sfb */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
529 } /* of presort */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
530
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
531 /* Avoid divide by zero */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
532 if (numberOfSegments == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
533 return 10; /* this is not good... */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
534
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
535 numberOfSets = NrCodeWords / numberOfSegments;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
536
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
537 /* second step: decode nonPCWs */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
538
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
539 for (set = 1; set <= numberOfSets; set++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
540 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
541 uint16_t trial;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
542
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
543 for (trial = 0; trial < numberOfSegments; trial++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
544 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
545 uint16_t codewordBase;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
546 uint16_t set_decoded=numberOfSegments;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
547
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
548 if (set == numberOfSets)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
549 set_decoded = NrCodeWords - set*numberOfSegments; /* last set is shorter than the rest */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
550
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
551 for (codewordBase = 0; codewordBase < numberOfSegments; codewordBase++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
552 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
553 uint16_t segment_index = (trial + codewordBase) % numberOfSegments;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
554 uint16_t codeword_index = codewordBase + set*numberOfSegments - numberOfSegments;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
555
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
556 if ((codeword_index + numberOfSegments) >= NrCodeWords)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
557 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
558 if (!Codewords[ codeword_index ].decoded)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
559 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
560 if ( Segment[ segment_index ].len > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
561 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
562 uint8_t tmplen;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
563
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
564 if (Codewords[ codeword_index ].bits.len != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
565 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
566 /* on the first trial the data is only stored in Segment[], not in Codewords[].
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
567 On next trials first collect the data stored for this codeword and
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
568 concatenate the new data from Segment[] */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
569
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
570 concat_bits( &Codewords[ codeword_index ].bits, &Segment[ segment_index ]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
571 /* Now everthing is stored in Segment[] */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
572 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
573 tmplen = Segment[ segment_index ].len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
574 if ( huffman_spectral_data_2(Codewords[ codeword_index ].cb, &Segment[ segment_index ],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
575 &spectral_data[ Codewords[ codeword_index ].sp_offset ]) >=0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
576 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
577 /* CW did fit into segment */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
578
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
579 Codewords[ codeword_index ].decoded = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
580 set_decoded--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
581 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
582
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
583 /* CW did not fit, so store for later use */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
584
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
585 Codewords[ codeword_index ].bits.len = tmplen;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
586 Codewords[ codeword_index ].bits.bufa = Segment[ segment_index ].bufa;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
587 Codewords[ codeword_index ].bits.bufb = Segment[ segment_index ].bufb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
588 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
589 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
590 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
591 } /* of codewordBase */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
592
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
593 if (set_decoded == 0) break; /* no undecoded codewords left in this set */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
594
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
595 } /* of trial */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
596
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
597 /* rewind all bits in remaining segments with len>0 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
598 for (i=0; i < numberOfSegments; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
599 rewind_bits( &Segment[ i ] );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
600 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
601
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
602 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
603 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
604 int i, r=0, c=0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
605 for (i=0; i< numberOfSegments; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
606 r += Segment[ i ].len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
607 if (r != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
608 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
609 printf("reordered_spectral_data: %d bits remaining!\n", r);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
610 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
611 for (i=0; i< NrCodeWords - numberOfSegments; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
612 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
613 if (Codewords[ i ].decoded == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
614 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
615 c++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
616 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
617 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
618 if (c != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
619 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
620 printf("reordered_spectral_data: %d Undecoded Codewords remaining!\n",c );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
621 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
622 if ((r !=0) || (c!=0)) return 10;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
623 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
624 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
625
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
626 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
627 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
628 #endif