annotate libfaad2/hcr.c @ 16503:b7fc08b7e1aa

typo, probably..
author ods15
date Sat, 17 Sep 2005 05:46:20 +0000
parents 2ae5ab4331ca
children 59b6fa5b4201
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
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
3 ** Copyright (C) 2002-2004 A. Kurpiers
10725
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 **
14727
2ae5ab4331ca Remove modification notice from files that have not been locally modified.
diego
parents: 13453
diff changeset
25 ** $Id: hcr.c,v 1.15 2004/03/02 20:09:58 menno Exp $
10725
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 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 #include <string.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34 #include "syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 #include "specrec.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 #include "bits.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 #include "pulse.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 #include "analysis.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 #include "bits.h"
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
40 #include "huffman.h"
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42 /* 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
43
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 /* rewind len (max. 32) bits so that the MSB becomes LSB */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 static uint32_t rewind_word( uint32_t W, uint8_t len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 uint8_t i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51 uint32_t tmp_W=0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 for ( i=0; i<len; i++ )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 tmp_W<<=1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56 if (W & (1<<i)) tmp_W |= 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
57 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
58 return tmp_W;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
60
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
61 static void rewind_lword( uint32_t *highW, uint32_t *lowW, uint8_t len)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
62 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
63 uint32_t tmp_lW=0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
64
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
65 if (len > 32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
66 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
67 tmp_lW = rewind_word( (*highW << (64-len)) | (*lowW >> (len-32)), 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
68 *highW = rewind_word( *lowW << (64-len) , 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
69 *lowW = tmp_lW;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
70 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
71 *highW = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72 *lowW = rewind_word( *lowW, len);
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 /* Takes a codeword as stored in r, rewinds the remaining bits and stores it back */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 static void rewind_bits(bits_t * r)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
79 uint32_t hw, lw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81 if (r->len == 0) return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 if (r->len >32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 lw = r->bufa;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
86 hw = r->bufb & (0xFFFFFFFF >> (64 - r->len));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 rewind_lword( &hw, &lw, r->len );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88 r->bufa = lw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 r->bufb = hw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
91 } else {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
92 lw = showbits_hcr(r, r->len );
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93 r->bufa = rewind_word( lw, r->len);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 r->bufb = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
95 }
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 /* takes codewords from a and b, concatenate them and store them in b */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99 static void concat_bits( bits_t * a, bits_t * b)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 uint32_t hwa, lwa, hwb, lwb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
102
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 if (a->len == 0) return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105 if (a->len >32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 lwa = a->bufa;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
108 hwa = a->bufb & (0xFFFFFFFF >> (64 - a->len));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 } else {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
110 lwa = showbits_hcr(a, a->len );
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111 hwa = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 if (b->len >=32) {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114 lwb = b->bufa;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 hwb = (b->bufb & (0xFFFFFFFF >> (64 - b->len)) ) | ( lwa << (b->len - 32));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 } else {
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
117 lwb = showbits_hcr(b, b->len ) | (lwa << (b->len));
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 hwb = (lwa >> (32 - b->len)) | (hwa << (b->len));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 b->bufa = lwb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 b->bufb = hwb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123 b->len += a->len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 /* 8.5.3.3.1 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 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
129 static const uint8_t PresortedCodebook[] = { 11, 9, 7, 5, 3, 1};
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131 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
132 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
133
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 typedef struct
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136 bits_t bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 uint8_t decoded;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 uint16_t sp_offset;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 uint8_t cb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 } codeword_state;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 #define segmentWidth( codebook ) min( maxCwLen[codebook], ics->length_of_longest_codeword )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144
13453
6d50ef45a058 Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents: 12625
diff changeset
145 uint8_t reordered_spectral_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld,
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 int16_t *spectral_data)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 uint16_t sp_offset[8];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149 uint16_t g,i, presort;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 uint16_t NrCodeWords=0, numberOfSegments=0, BitsRead=0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 uint8_t numberOfSets, set;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 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
153 bits_t Segment[ 512 ];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155 uint8_t PCW_decoded=0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156 uint16_t nshort = hDecoder->frameLength/8;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
157
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
158
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
159 /*memset (spectral_data, 0, hDecoder->frameLength*sizeof(uint16_t));*/
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 if (ics->length_of_reordered_spectral_data == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 return 0; /* nothing to do */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 /* if we have a corrupted bitstream this can happen... */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 if ((ics->length_of_longest_codeword == 0) ||
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 (ics->length_of_reordered_spectral_data <
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167 ics->length_of_longest_codeword) ||
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 (ics->max_sfb == 0))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 return 10; /* this is not good... */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 /* 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
174
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175 sp_offset[0] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176 for (g=1; g < ics->num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178 sp_offset[g] = sp_offset[g-1] + nshort*ics->window_group_length[g-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 /* All data is sorted according to the codebook used */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 for (presort = 0; presort < (hDecoder->aacSectionDataResilienceFlag ? 22 : 6); presort++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 uint8_t sfb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 /* next codebook that has to be processed according to presorting */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 uint8_t nextCB = hDecoder->aacSectionDataResilienceFlag ? PresortedCodebook_VCB11[ presort ] : PresortedCodebook[ presort ];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 /* 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
190 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
191 repeated */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 for (sfb=0; sfb<ics->max_sfb; sfb ++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 uint8_t sect_cb, w;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 for (w=0; w< (ics->swb_offset[sfb+1] - ics->swb_offset[sfb]); w+=4)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199 for(g = 0; g < ics->num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201 for (i = 0; i < ics->num_sec[g]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 sect_cb = ics->sect_cb[g][i];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 if (
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 /* process only sections that are due now */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 (( sect_cb == nextCB ) || (( nextCB < ESC_HCB ) && ( sect_cb == nextCB+1)) ) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 /* process only sfb's that are due now */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210 ((ics->sect_start[g][i] <= sfb) && (ics->sect_end[g][i] > sfb))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 )
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 if ((sect_cb != ZERO_HCB) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 (sect_cb != NOISE_HCB) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 (sect_cb != INTENSITY_HCB) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 (sect_cb != INTENSITY_HCB2))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 uint8_t inc = (sect_cb < FIRST_PAIR_HCB) ? QUAD_LEN : PAIR_LEN;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 uint16_t k;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221 uint32_t hw, lw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 for (k=0; (k < (4/inc)*ics->window_group_length[g]) &&
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 ( (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
225 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226 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
227
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 if (!PCW_decoded)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 /* 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
231 if ((BitsRead + segmentWidth( sect_cb ))<= ics->length_of_reordered_spectral_data)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233 Segment[ numberOfSegments ].len = segmentWidth( sect_cb );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235 if (segmentWidth( sect_cb ) > 32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 Segment[ numberOfSegments ].bufb = faad_showbits(ld, segmentWidth( sect_cb ) - 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 faad_flushbits(ld, segmentWidth( sect_cb) - 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 Segment[ numberOfSegments ].bufa = faad_showbits(ld, 32),
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 faad_flushbits(ld, 32 );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 Segment[ numberOfSegments ].bufa = faad_showbits(ld, segmentWidth( sect_cb ));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 Segment[ numberOfSegments ].bufb = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 faad_flushbits(ld, segmentWidth( sect_cb) );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248 huffman_spectral_data_2(sect_cb, &Segment[ numberOfSegments ], &spectral_data[sp]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 BitsRead += segmentWidth( sect_cb );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252 /* skip to next segment, but store left bits in new buffer */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 rewind_bits( &Segment[ numberOfSegments ]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255 numberOfSegments++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
256 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 /* the last segment is extended until length_of_reordered_spectral_data */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 if (BitsRead < ics->length_of_reordered_spectral_data)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 uint8_t additional_bits = (ics->length_of_reordered_spectral_data - BitsRead);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 if ( additional_bits > 32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267 hw = faad_showbits(ld, additional_bits - 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268 faad_flushbits(ld, additional_bits - 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269 lw = faad_showbits(ld, 32);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270 faad_flushbits(ld, 32 );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272 lw = faad_showbits(ld, additional_bits);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 hw = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 faad_flushbits(ld, additional_bits );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 rewind_lword( &hw, &lw, additional_bits + Segment[ numberOfSegments-1 ].len );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 if (Segment[ numberOfSegments-1 ].len > 32)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 Segment[ numberOfSegments-1 ].bufb = hw +
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
280 showbits_hcr(&Segment[ numberOfSegments-1 ], Segment[ numberOfSegments-1 ].len - 32);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 Segment[ numberOfSegments-1 ].bufa = lw +
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
282 showbits_hcr(&Segment[ numberOfSegments-1 ], 32);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 Segment[ numberOfSegments-1 ].bufa = lw +
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
285 showbits_hcr(&Segment[ numberOfSegments-1 ], Segment[ numberOfSegments-1 ].len);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286 Segment[ numberOfSegments-1 ].bufb = hw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 Segment[ numberOfSegments-1 ].len += additional_bits;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 BitsRead = ics->length_of_reordered_spectral_data;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291 PCW_decoded = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293 Codewords[ 0 ].sp_offset = sp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
294 Codewords[ 0 ].cb = sect_cb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295 Codewords[ 0 ].decoded = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296 Codewords[ 0 ].bits.len = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299 Codewords[ NrCodeWords - numberOfSegments ].sp_offset = sp;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 Codewords[ NrCodeWords - numberOfSegments ].cb = sect_cb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301 Codewords[ NrCodeWords - numberOfSegments ].decoded = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302 Codewords[ NrCodeWords - numberOfSegments ].bits.len = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304 } /* PCW decoded */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
305 NrCodeWords++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 } /* of k */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
307 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
308 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
309 } /* of i */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
310 } /* of g */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311 } /* of w */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
312 } /* of sfb */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
313 } /* of presort */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
314
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
315 /* Avoid divide by zero */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
316 if (numberOfSegments == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
317 return 10; /* this is not good... */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
318
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
319 numberOfSets = NrCodeWords / numberOfSegments;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
320
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
321 /* second step: decode nonPCWs */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
322
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323 for (set = 1; set <= numberOfSets; set++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
324 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
325 uint16_t trial;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
326
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
327 for (trial = 0; trial < numberOfSegments; trial++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
328 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 uint16_t codewordBase;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
330 uint16_t set_decoded=numberOfSegments;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
331
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
332 if (set == numberOfSets)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
333 set_decoded = NrCodeWords - set*numberOfSegments; /* last set is shorter than the rest */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
334
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
335 for (codewordBase = 0; codewordBase < numberOfSegments; codewordBase++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
336 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
337 uint16_t segment_index = (trial + codewordBase) % numberOfSegments;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
338 uint16_t codeword_index = codewordBase + set*numberOfSegments - numberOfSegments;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
339
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
340 if ((codeword_index + numberOfSegments) >= NrCodeWords)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
341 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
342 if (!Codewords[ codeword_index ].decoded)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
343 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
344 if ( Segment[ segment_index ].len > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
345 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
346 uint8_t tmplen;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
347
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
348 if (Codewords[ codeword_index ].bits.len != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
349 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
350 /* on the first trial the data is only stored in Segment[], not in Codewords[].
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 On next trials first collect the data stored for this codeword and
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352 concatenate the new data from Segment[] */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
353
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
354 concat_bits( &Codewords[ codeword_index ].bits, &Segment[ segment_index ]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
355 /* Now everthing is stored in Segment[] */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
356 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
357 tmplen = Segment[ segment_index ].len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
358 if ( huffman_spectral_data_2(Codewords[ codeword_index ].cb, &Segment[ segment_index ],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
359 &spectral_data[ Codewords[ codeword_index ].sp_offset ]) >=0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
360 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
361 /* CW did fit into segment */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
362
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363 Codewords[ codeword_index ].decoded = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
364 set_decoded--;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
365 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
366
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 /* CW did not fit, so store for later use */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
368
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
369 Codewords[ codeword_index ].bits.len = tmplen;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370 Codewords[ codeword_index ].bits.bufa = Segment[ segment_index ].bufa;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371 Codewords[ codeword_index ].bits.bufb = Segment[ segment_index ].bufb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372 }
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 } /* of codewordBase */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
376
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
377 if (set_decoded == 0) break; /* no undecoded codewords left in this set */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
378
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
379 } /* of trial */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
381 /* rewind all bits in remaining segments with len>0 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
382 for (i=0; i < numberOfSegments; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
383 rewind_bits( &Segment[ i ] );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
384 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
385
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
386 #if 0
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
387 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
388 int i, r=0, c=0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
389 for (i=0; i< numberOfSegments; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
390 r += Segment[ i ].len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
391 if (r != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
392 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
393 printf("reordered_spectral_data: %d bits remaining!\n", r);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
394 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
395 for (i=0; i< NrCodeWords - numberOfSegments; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
396 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
397 if (Codewords[ i ].decoded == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
398 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
399 c++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
400 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
401 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
402 if (c != 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
403 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
404 printf("reordered_spectral_data: %d Undecoded Codewords remaining!\n",c );
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
405 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
406 if ((r !=0) || (c!=0)) return 10;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
407 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
408 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
409
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
410 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
411 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
412 #endif