annotate libfaad2/hcr.c @ 30118:cdec8d3a2225

Do not needlessly use the BP register in x86_64-specific code, there are enough other registers available that are less likely to cause issues.
author reimar
date Fri, 01 Jan 2010 09:46:24 +0000
parents e83eef58b30a
children
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
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
3 ** Copyright (C) 2004 G.C. Pascutto, Ahead Software AG, http://www.nero.com
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
4 **
10725
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.
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
9 **
10725
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.
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
14 **
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
15 ** You should have received a copy of the GNU General Public License
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
16 ** along with this program; if not, write to the Free Software
10725
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 **
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
25 ** $Id: hcr.c,v 1.18 2004/09/04 14:56:28 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 "specrec.h"
10989
3185f64f6350 synced with current cvs
alex
parents: 10725
diff changeset
35 #include "huffman.h"
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
37 /* ISO/IEC 14496-3/Amd.1
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
38 * 8.5.3.3: Huffman Codeword Reordering for AAC spectral data (HCR)
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
39 *
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
40 * HCR devides the spectral data in known fixed size segments, and
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
41 * sorts it by the importance of the data. The importance is firstly
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
42 * the (lower) position in the spectrum, and secondly the largest
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
43 * value in the used codebook.
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
44 * The most important data is written at the start of each segment
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
45 * (at known positions), the remaining data is interleaved inbetween,
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
46 * with the writing direction alternating.
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
47 * Data length is not increased.
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
48 */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
52 /* 8.5.3.3.1 Pre-sorting */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
53
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
54 #define NUM_CB 6
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
55 #define NUM_CB_ER 22
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
56 #define MAX_CB 32
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
57 #define VCB11_FIRST 16
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
58 #define VCB11_LAST 31
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
59
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
60 static const uint8_t PreSortCB_STD[NUM_CB] =
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
61 { 11, 9, 7, 5, 3, 1};
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
62
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
63 static const uint8_t PreSortCB_ER[NUM_CB_ER] =
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
64 { 11, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 9, 7, 5, 3, 1};
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
65
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
66 /* 8.5.3.3.2 Derivation of segment width */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
67
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
68 static const uint8_t maxCwLen[MAX_CB] = {0, 11, 9, 20, 16, 13, 11, 14, 12, 17, 14, 49,
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
69 0, 0, 0, 0, 14, 17, 21, 21, 25, 25, 29, 29, 29, 29, 33, 33, 33, 37, 37, 41};
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
70
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
71 #define segmentWidth(cb) min(maxCwLen[cb], ics->length_of_longest_codeword)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
72
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
73 /* bit-twiddling helpers */
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
74 static const uint8_t S[] = {1, 2, 4, 8, 16};
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
75 static const uint32_t B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF};
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
76
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
77 typedef struct
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
78 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
79 uint8_t cb;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
80 uint8_t decoded;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
81 uint16_t sp_offset;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
82 bits_t bits;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
83 } codeword_t;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
84
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
85 /* rewind and reverse */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
86 /* 32 bit version */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
87 static uint32_t rewrev_word(uint32_t v, const uint8_t len)
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
88 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
89 /* 32 bit reverse */
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
90 v = ((v >> S[0]) & B[0]) | ((v << S[0]) & ~B[0]);
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
91 v = ((v >> S[1]) & B[1]) | ((v << S[1]) & ~B[1]);
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
92 v = ((v >> S[2]) & B[2]) | ((v << S[2]) & ~B[2]);
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
93 v = ((v >> S[3]) & B[3]) | ((v << S[3]) & ~B[3]);
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
94 v = ((v >> S[4]) & B[4]) | ((v << S[4]) & ~B[4]);
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
95
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
96 /* shift off low bits */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
97 v >>= (32 - len);
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
98
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
99 return v;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
102 /* 64 bit version */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
103 static void rewrev_lword(uint32_t *hi, uint32_t *lo, const uint8_t len)
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
104 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
105 if (len <= 32) {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
106 *hi = 0;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
107 *lo = rewrev_word(*lo, len);
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
108 } else
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
110 uint32_t t = *hi, v = *lo;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
112 /* double 32 bit reverse */
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
113 v = ((v >> S[0]) & B[0]) | ((v << S[0]) & ~B[0]);
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
114 t = ((t >> S[0]) & B[0]) | ((t << S[0]) & ~B[0]);
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
115 v = ((v >> S[1]) & B[1]) | ((v << S[1]) & ~B[1]);
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
116 t = ((t >> S[1]) & B[1]) | ((t << S[1]) & ~B[1]);
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
117 v = ((v >> S[2]) & B[2]) | ((v << S[2]) & ~B[2]);
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
118 t = ((t >> S[2]) & B[2]) | ((t << S[2]) & ~B[2]);
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
119 v = ((v >> S[3]) & B[3]) | ((v << S[3]) & ~B[3]);
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
120 t = ((t >> S[3]) & B[3]) | ((t << S[3]) & ~B[3]);
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
121 v = ((v >> S[4]) & B[4]) | ((v << S[4]) & ~B[4]);
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
122 t = ((t >> S[4]) & B[4]) | ((t << S[4]) & ~B[4]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
124 /* last 32<>32 bit swap is implicit below */
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
125
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
126 /* shift off low bits (this is really only one 64 bit shift) */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
127 *lo = (t >> (64 - len)) | (v << (len - 32));
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
128 *hi = v >> (64 - len);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
132
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
133 /* bits_t version */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
134 static void rewrev_bits(bits_t *bits)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
136 if (bits->len == 0) return;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
137 rewrev_lword(&bits->bufb, &bits->bufa, bits->len);
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
138 }
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
139
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
140
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
141 /* merge bits of a to b */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
142 static void concat_bits(bits_t *b, bits_t *a)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
143 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
144 uint32_t bl, bh, al, ah;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 if (a->len == 0) return;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
148 al = a->bufa;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
149 ah = a->bufb;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
150
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
151 if (b->len > 32)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
153 /* maskoff superfluous high b bits */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
154 bl = b->bufa;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
155 bh = b->bufb & ((1 << (b->len-32)) - 1);
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
156 /* left shift a b->len bits */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
157 ah = al << (b->len - 32);
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
158 al = 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159 } else {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
160 bl = b->bufa & ((1 << (b->len)) - 1);
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
161 bh = 0;
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
162 ah = (ah << (b->len)) | (al >> (32 - b->len));
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
163 al = al << b->len;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
166 /* merge */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
167 b->bufa = bl | al;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
168 b->bufb = bh | ah;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
169
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 b->len += a->len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 }
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
172
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
173 uint8_t is_good_cb(uint8_t this_CB, uint8_t this_sec_CB)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
174 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
175 /* only want spectral data CB's */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
176 if ((this_sec_CB > ZERO_HCB && this_sec_CB <= ESC_HCB) || (this_sec_CB >= VCB11_FIRST && this_sec_CB <= VCB11_LAST))
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
177 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
178 if (this_CB < ESC_HCB)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
179 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
180 /* normal codebook pairs */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
181 return ((this_sec_CB == this_CB) || (this_sec_CB == this_CB + 1));
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
182 } else
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
183 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
184 /* escape codebook */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
185 return (this_sec_CB == this_CB);
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
186 }
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
187 }
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
188 return 0;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
189 }
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
190
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
191 void read_segment(bits_t *segment, uint8_t segwidth, bitfile *ld)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
192 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
193 segment->len = segwidth;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
194
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
195 if (segwidth > 32)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
196 {
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
197 segment->bufb = faad_getbits(ld, segwidth - 32);
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
198 segment->bufa = faad_getbits(ld, 32);
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
199
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
200 } else {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
201 segment->bufa = faad_getbits(ld, segwidth);
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
202 segment->bufb = 0;
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
203 }
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
204 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
206 void fill_in_codeword(codeword_t *codeword, uint16_t index, uint16_t sp, uint8_t cb)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
208 codeword[index].sp_offset = sp;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
209 codeword[index].cb = cb;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
210 codeword[index].decoded = 0;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
211 codeword[index].bits.len = 0;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
212 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
214 uint8_t reordered_spectral_data(NeAACDecHandle hDecoder, ic_stream *ics,
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
215 bitfile *ld, int16_t *spectral_data)
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
216 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
217 uint16_t PCWs_done;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
218 uint16_t numberOfSegments, numberOfSets, numberOfCodewords;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
220 codeword_t codeword[512];
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
221 bits_t segment[512];
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
222
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223 uint16_t sp_offset[8];
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
224 uint16_t g, i, sortloop, set, bitsread;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
225 uint8_t w_idx, sfb, this_CB, last_CB, this_sec_CB;
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
226
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
227 const uint16_t nshort = hDecoder->frameLength/8;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
228 const uint16_t sp_data_len = ics->length_of_reordered_spectral_data;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
229
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
230 const uint8_t *PreSortCb;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
232 /* no data (e.g. silence) */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
233 if (sp_data_len == 0)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
234 return 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
236 /* since there is spectral data, at least one codeword has nonzero length */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
237 if (ics->length_of_longest_codeword == 0)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
238 return 10;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
239
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
240 if (sp_data_len < ics->length_of_longest_codeword)
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
241 return 10;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 sp_offset[0] = 0;
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
244 for (g = 1; g < ics->num_window_groups; g++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
246 sp_offset[g] = sp_offset[g-1] + nshort*ics->window_group_length[g-1];
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
247 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
248
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
249 PCWs_done = 0;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
250 numberOfSegments = 0;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
251 numberOfCodewords = 0;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
252 bitsread = 0;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
254 /* VCB11 code books in use */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
255 if (hDecoder->aacSectionDataResilienceFlag)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
256 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
257 PreSortCb = PreSortCB_ER;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
258 last_CB = NUM_CB_ER;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
259 } else
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
260 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
261 PreSortCb = PreSortCB_STD;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
262 last_CB = NUM_CB;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
263 }
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
264
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
265 /* step 1: decode PCW's (set 0), and stuff data in easier-to-use format */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
266 for (sortloop = 0; sortloop < last_CB; sortloop++)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
267 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
268 /* select codebook to process this pass */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
269 this_CB = PreSortCb[sortloop];
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
270
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
271 /* loop over sfbs */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
272 for (sfb = 0; sfb < ics->max_sfb; sfb++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
274 /* loop over all in this sfb, 4 lines per loop */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
275 for (w_idx = 0; 4*w_idx < (ics->swb_offset[sfb+1] - ics->swb_offset[sfb]); w_idx++)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 for(g = 0; g < ics->num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 for (i = 0; i < ics->num_sec[g]; i++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
281 /* check whether sfb used here is the one we want to process */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
282 if ((ics->sect_start[g][i] <= sfb) && (ics->sect_end[g][i] > sfb))
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
283 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
284 /* check whether codebook used here is the one we want to process */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
285 this_sec_CB = ics->sect_cb[g][i];
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
286
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
287 if (is_good_cb(this_CB, this_sec_CB))
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
289 /* precalculate some stuff */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
290 uint16_t sect_sfb_size = ics->sect_sfb_offset[g][sfb+1] - ics->sect_sfb_offset[g][sfb];
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
291 uint8_t inc = (this_sec_CB < FIRST_PAIR_HCB) ? QUAD_LEN : PAIR_LEN;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
292 uint16_t group_cws_count = (4*ics->window_group_length[g])/inc;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
293 uint8_t segwidth = segmentWidth(this_sec_CB);
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
294 uint16_t cws;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
296 /* read codewords until end of sfb or end of window group (shouldn't only 1 trigger?) */
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
297 for (cws = 0; (cws < group_cws_count) && ((cws + w_idx*group_cws_count) < sect_sfb_size); cws++)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
298 {
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
299 uint16_t sp = sp_offset[g] + ics->sect_sfb_offset[g][sfb] + inc * (cws + w_idx*group_cws_count);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
301 /* read and decode PCW */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
302 if (!PCWs_done)
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
303 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
304 /* read in normal segments */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
305 if (bitsread + segwidth <= sp_data_len)
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
306 {
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
307 read_segment(&segment[numberOfSegments], segwidth, ld);
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
308 bitsread += segwidth;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
309
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
310 huffman_spectral_data_2(this_sec_CB, &segment[numberOfSegments], &spectral_data[sp]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
312 /* keep leftover bits */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
313 rewrev_bits(&segment[numberOfSegments]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
314
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
315 numberOfSegments++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
316 } else {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
317 /* remaining stuff after last segment, we unfortunately couldn't read
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
318 this in earlier because it might not fit in 64 bits. since we already
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
319 decoded (and removed) the PCW it is now guaranteed to fit */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
320 if (bitsread < sp_data_len)
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
321 {
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
322 const uint8_t additional_bits = sp_data_len - bitsread;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
324 read_segment(&segment[numberOfSegments], additional_bits, ld);
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
325 segment[numberOfSegments].len += segment[numberOfSegments-1].len;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
326 rewrev_bits(&segment[numberOfSegments]);
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
327
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
328 if (segment[numberOfSegments-1].len > 32)
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 {
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
330 segment[numberOfSegments-1].bufb = segment[numberOfSegments].bufb +
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
331 showbits_hcr(&segment[numberOfSegments-1], segment[numberOfSegments-1].len - 32);
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
332 segment[numberOfSegments-1].bufa = segment[numberOfSegments].bufa +
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
333 showbits_hcr(&segment[numberOfSegments-1], 32);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
334 } else {
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
335 segment[numberOfSegments-1].bufa = segment[numberOfSegments].bufa +
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
336 showbits_hcr(&segment[numberOfSegments-1], segment[numberOfSegments-1].len);
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
337 segment[numberOfSegments-1].bufb = segment[numberOfSegments].bufb;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
338 }
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
339 segment[numberOfSegments-1].len += additional_bits;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
340 }
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
341 bitsread = sp_data_len;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
342 PCWs_done = 1;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
343
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
344 fill_in_codeword(codeword, 0, sp, this_sec_CB);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
345 }
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
346 } else {
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
347 fill_in_codeword(codeword, numberOfCodewords - numberOfSegments, sp, this_sec_CB);
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
348 }
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
349 numberOfCodewords++;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
350 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352 }
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
353 }
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
354 }
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
355 }
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
356 }
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
357 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
358
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
359 if (numberOfSegments == 0)
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
360 return 10;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
361
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
362 numberOfSets = numberOfCodewords / numberOfSegments;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
364 /* step 2: decode nonPCWs */
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
365 for (set = 1; set <= numberOfSets; set++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
366 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 uint16_t trial;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
368
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
369 for (trial = 0; trial < numberOfSegments; trial++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371 uint16_t codewordBase;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
373 for (codewordBase = 0; codewordBase < numberOfSegments; codewordBase++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
374 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
375 const uint16_t segment_idx = (trial + codewordBase) % numberOfSegments;
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
376 const uint16_t codeword_idx = codewordBase + set*numberOfSegments - numberOfSegments;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
377
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
378 /* data up */
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
379 if (codeword_idx >= numberOfCodewords - numberOfSegments) break;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
381 if (!codeword[codeword_idx].decoded && segment[segment_idx].len > 0)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
382 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
383 uint8_t tmplen;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
384
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
385 if (codeword[codeword_idx].bits.len != 0)
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
386 concat_bits(&segment[segment_idx], &codeword[codeword_idx].bits);
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
387
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
388 tmplen = segment[segment_idx].len;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
389
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
390 if (huffman_spectral_data_2(codeword[codeword_idx].cb, &segment[segment_idx],
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
391 &spectral_data[codeword[codeword_idx].sp_offset]) >= 0)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
392 {
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
393 codeword[codeword_idx].decoded = 1;
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
394 } else
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
395 {
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
396 codeword[codeword_idx].bits = segment[segment_idx];
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
397 codeword[codeword_idx].bits.len = tmplen;
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
398 }
29264
e83eef58b30a Remove all kind of trailing whitespaces from all MPlayer's files.
bircoph
parents: 18141
diff changeset
399
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
400 }
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
401 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
402 }
18141
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
403 for (i = 0; i < numberOfSegments; i++)
59b6fa5b4201 Update to faad2 cvs 20040915+MPlayer fixes
rtognimp
parents: 14727
diff changeset
404 rewrev_bits(&segment[i]);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
405 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
406
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
407 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
408 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
409 #endif