annotate libfaad2/rvlc.c @ 13824:bad703951cf9

a few 10l fixes by Wei Jiang <jiangw98@yahoo.com>
author faust3
date Sun, 31 Oct 2004 10:27:40 +0000
parents d81145997036
children 2ae5ab4331ca
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) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
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 **
12625
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
26 ** $Id: rvlc.c,v 1.3 2004/06/02 22:59:03 diego Exp $
d81145997036 More information about modifications to comply more closely with GPL 2a.
diego
parents: 12527
diff changeset
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
28 **/
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
29
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
30 /* RVLC scalefactor decoding
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
31 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
32 * RVLC works like this:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
33 * 1. Only symmetric huffman codewords are used
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
34 * 2. Total length of the scalefactor data is stored in the bitsream
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
35 * 3. Scalefactors are DPCM coded
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
36 * 4. Next to the starting value for DPCM the ending value is also stored
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
37 *
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
38 * With all this it is possible to read the scalefactor data from 2 sides.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
39 * If there is a bit error in the scalefactor data it is possible to start
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
40 * decoding from the other end of the data, to find all but 1 scalefactor.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
41 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
42
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
43 #include "common.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
44 #include "structs.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
45
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
46 #include <stdlib.h>
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
47
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
48 #include "syntax.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
49 #include "bits.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
50 #include "rvlc.h"
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
51
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
52
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
53 #ifdef ERROR_RESILIENCE
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
54
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
55 //#define PRINT_RVLC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
56
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
57 /* static function declarations */
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
58 static uint8_t rvlc_decode_sf_forward(ic_stream *ics,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
59 bitfile *ld_sf,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
60 bitfile *ld_esc,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
61 uint8_t *is_used);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
62 #if 0
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
63 static uint8_t rvlc_decode_sf_reverse(ic_stream *ics,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
64 bitfile *ld_sf,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
65 bitfile *ld_esc,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
66 uint8_t is_used);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
67 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
68 static int8_t rvlc_huffman_sf(bitfile *ld_sf, bitfile *ld_esc,
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
69 int8_t direction);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
70 static int8_t rvlc_huffman_esc(bitfile *ld_esc, int8_t direction);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
71
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
72
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
73 uint8_t rvlc_scale_factor_data(ic_stream *ics, bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
74 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
75 uint8_t bits = 9;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
76
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
77 ics->sf_concealment = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
78 DEBUGVAR(1,149,"rvlc_scale_factor_data(): sf_concealment"));
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
79 ics->rev_global_gain = (uint8_t)faad_getbits(ld, 8
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
80 DEBUGVAR(1,150,"rvlc_scale_factor_data(): rev_global_gain"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
81
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
82 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
83 bits = 11;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
84
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
85 /* the number of bits used for the huffman codewords */
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
86 ics->length_of_rvlc_sf = (uint16_t)faad_getbits(ld, bits
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
87 DEBUGVAR(1,151,"rvlc_scale_factor_data(): length_of_rvlc_sf"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
88
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
89 if (ics->noise_used)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
90 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
91 ics->dpcm_noise_nrg = (uint16_t)faad_getbits(ld, 9
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
92 DEBUGVAR(1,152,"rvlc_scale_factor_data(): dpcm_noise_nrg"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
93
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
94 ics->length_of_rvlc_sf -= 9;
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 ics->sf_escapes_present = faad_get1bit(ld
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
98 DEBUGVAR(1,153,"rvlc_scale_factor_data(): sf_escapes_present"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
99
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
100 if (ics->sf_escapes_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
101 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
102 ics->length_of_rvlc_escapes = (uint8_t)faad_getbits(ld, 8
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
103 DEBUGVAR(1,154,"rvlc_scale_factor_data(): length_of_rvlc_escapes"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
104 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
105
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
106 if (ics->noise_used)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
107 {
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
108 ics->dpcm_noise_last_position = (uint16_t)faad_getbits(ld, 9
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
109 DEBUGVAR(1,155,"rvlc_scale_factor_data(): dpcm_noise_last_position"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
110 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
111
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
112 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
113 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
114
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
115 uint8_t rvlc_decode_scale_factors(ic_stream *ics, bitfile *ld)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
116 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
117 uint8_t result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
118 uint8_t intensity_used = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
119 uint8_t *rvlc_sf_buffer = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
120 uint8_t *rvlc_esc_buffer = NULL;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
121 bitfile ld_rvlc_sf, ld_rvlc_esc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
122 // bitfile ld_rvlc_sf_rev, ld_rvlc_esc_rev;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
123
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
124 if (ics->length_of_rvlc_sf > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
125 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
126 /* We read length_of_rvlc_sf bits here to put it in a
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
127 seperate bitfile.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
128 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
129 rvlc_sf_buffer = faad_getbitbuffer(ld, ics->length_of_rvlc_sf
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
130 DEBUGVAR(1,156,"rvlc_decode_scale_factors(): bitbuffer: length_of_rvlc_sf"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
131
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
132 faad_initbits(&ld_rvlc_sf, (void*)rvlc_sf_buffer, bit2byte(ics->length_of_rvlc_sf));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
133 // faad_initbits_rev(&ld_rvlc_sf_rev, (void*)rvlc_sf_buffer,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
134 // ics->length_of_rvlc_sf);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
135 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
136
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
137 if (ics->sf_escapes_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
138 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
139 /* We read length_of_rvlc_escapes bits here to put it in a
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
140 seperate bitfile.
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
141 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
142 rvlc_esc_buffer = faad_getbitbuffer(ld, ics->length_of_rvlc_escapes
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
143 DEBUGVAR(1,157,"rvlc_decode_scale_factors(): bitbuffer: length_of_rvlc_escapes"));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
144
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
145 faad_initbits(&ld_rvlc_esc, (void*)rvlc_esc_buffer, bit2byte(ics->length_of_rvlc_escapes));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
146 // faad_initbits_rev(&ld_rvlc_esc_rev, (void*)rvlc_esc_buffer,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
147 // ics->length_of_rvlc_escapes);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
148 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
149
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
150 /* decode the rvlc scale factors and escapes */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
151 result = rvlc_decode_sf_forward(ics, &ld_rvlc_sf,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
152 &ld_rvlc_esc, &intensity_used);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
153 // result = rvlc_decode_sf_reverse(ics, &ld_rvlc_sf_rev,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
154 // &ld_rvlc_esc_rev, intensity_used);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
155
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
156
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
157 if (rvlc_esc_buffer) faad_free(rvlc_esc_buffer);
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
158 if (rvlc_sf_buffer) faad_free(rvlc_sf_buffer);
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
159
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
160 if (ics->length_of_rvlc_sf > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
161 faad_endbits(&ld_rvlc_sf);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
162 if (ics->sf_escapes_present)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
163 faad_endbits(&ld_rvlc_esc);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
164
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
165 return result;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
166 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
167
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
168 static uint8_t rvlc_decode_sf_forward(ic_stream *ics, bitfile *ld_sf, bitfile *ld_esc,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
169 uint8_t *intensity_used)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
170 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
171 int8_t g, sfb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
172 int8_t t = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
173 int8_t error = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
174 int8_t noise_pcm_flag = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
175
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
176 int16_t scale_factor = ics->global_gain;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
177 int16_t is_position = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
178 int16_t noise_energy = ics->global_gain - 90 - 256;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
179
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
180 #ifdef PRINT_RVLC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
181 printf("\nglobal_gain: %d\n", ics->global_gain);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
182 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
183
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
184 for (g = 0; g < ics->num_window_groups; g++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
185 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
186 for (sfb = 0; sfb < ics->max_sfb; sfb++)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
187 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
188 if (error)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
189 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
190 ics->scale_factors[g][sfb] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
191 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
192 switch (ics->sfb_cb[g][sfb])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
193 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
194 case ZERO_HCB: /* zero book */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
195 ics->scale_factors[g][sfb] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
196 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
197 case INTENSITY_HCB: /* intensity books */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
198 case INTENSITY_HCB2:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
199
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
200 *intensity_used = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
201
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
202 /* decode intensity position */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
203 t = rvlc_huffman_sf(ld_sf, ld_esc, +1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
204
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
205 is_position += t;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
206 ics->scale_factors[g][sfb] = is_position;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
207
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
208 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
209 case NOISE_HCB: /* noise books */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
210
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
211 /* decode noise energy */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
212 if (noise_pcm_flag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
213 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
214 int16_t n = ics->dpcm_noise_nrg;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
215 noise_pcm_flag = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
216 noise_energy += n;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
217 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
218 t = rvlc_huffman_sf(ld_sf, ld_esc, +1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
219 noise_energy += t;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
220 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
221
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
222 ics->scale_factors[g][sfb] = noise_energy;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
223
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
224 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
225 default: /* spectral books */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
226
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
227 /* decode scale factor */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
228 t = rvlc_huffman_sf(ld_sf, ld_esc, +1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
229
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
230 scale_factor += t;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
231 if (scale_factor < 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
232 return 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
233
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
234 ics->scale_factors[g][sfb] = scale_factor;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
235
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
236 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
237 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
238 #ifdef PRINT_RVLC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
239 printf("%3d:%4d%4d\n", sfb, ics->sfb_cb[g][sfb],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
240 ics->scale_factors[g][sfb]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
241 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
242 if (t == 99)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
243 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
244 error = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
245 }
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 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
249 #ifdef PRINT_RVLC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
250 printf("\n\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
251 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
252
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
253 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
254 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
255
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
256 #if 0 // not used right now, doesn't work correctly yet
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
257 static uint8_t rvlc_decode_sf_reverse(ic_stream *ics, bitfile *ld_sf, bitfile *ld_esc,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
258 uint8_t intensity_used)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
259 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
260 int8_t g, sfb;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
261 int8_t t = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
262 int8_t error = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
263 int8_t noise_pcm_flag = 1, is_pcm_flag = 1, sf_pcm_flag = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
264
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
265 int16_t scale_factor = ics->rev_global_gain;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
266 int16_t is_position = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
267 int16_t noise_energy = ics->rev_global_gain;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
268
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
269 #ifdef PRINT_RVLC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
270 printf("\nrev_global_gain: %d\n", ics->rev_global_gain);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
271 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
272
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
273 if (intensity_used)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
274 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
275 is_position = rvlc_huffman_sf(ld_sf, ld_esc, -1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
276 #ifdef PRINT_RVLC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
277 printf("is_position: %d\n", is_position);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
278 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
279 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
280
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
281 for (g = ics->num_window_groups-1; g >= 0; g--)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
282 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
283 for (sfb = ics->max_sfb-1; sfb >= 0; sfb--)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
284 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
285 if (error)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
286 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
287 ics->scale_factors[g][sfb] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
288 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
289 switch (ics->sfb_cb[g][sfb])
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
290 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
291 case ZERO_HCB: /* zero book */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
292 ics->scale_factors[g][sfb] = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
293 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
294 case INTENSITY_HCB: /* intensity books */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
295 case INTENSITY_HCB2:
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
296
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
297 if (is_pcm_flag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
298 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
299 is_pcm_flag = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
300 ics->scale_factors[g][sfb] = is_position;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
301 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
302 t = rvlc_huffman_sf(ld_sf, ld_esc, -1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
303 is_position -= t;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
304
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
305 ics->scale_factors[g][sfb] = (uint8_t)is_position;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
306 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
307 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
308 case NOISE_HCB: /* noise books */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
309
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
310 /* decode noise energy */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
311 if (noise_pcm_flag)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
312 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
313 noise_pcm_flag = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
314 noise_energy = ics->dpcm_noise_last_position;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
315 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
316 t = rvlc_huffman_sf(ld_sf, ld_esc, -1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
317 noise_energy -= t;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
318 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
319
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
320 ics->scale_factors[g][sfb] = (uint8_t)noise_energy;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
321 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
322 default: /* spectral books */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
323
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
324 if (sf_pcm_flag || (sfb == 0))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
325 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
326 sf_pcm_flag = 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
327 if (sfb == 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
328 scale_factor = ics->global_gain;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
329 } else {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
330 /* decode scale factor */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
331 t = rvlc_huffman_sf(ld_sf, ld_esc, -1);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
332 scale_factor -= t;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
333 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
334
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
335 if (scale_factor < 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
336 return 4;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
337
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
338 ics->scale_factors[g][sfb] = (uint8_t)scale_factor;
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
339 break;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
340 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
341 #ifdef PRINT_RVLC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
342 printf("%3d:%4d%4d\n", sfb, ics->sfb_cb[g][sfb],
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
343 ics->scale_factors[g][sfb]);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
344 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
345 if (t == 99)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
346 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
347 error = 1;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
348 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
349 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
350 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
351 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
352
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
353 #ifdef PRINT_RVLC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
354 printf("\n\n");
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
355 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
356
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
357 return 0;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
358 }
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
359 #endif
10725
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
360
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
361 /* index == 99 means not allowed codeword */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
362 static rvlc_huff_table book_rvlc[] = {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
363 /*index length codeword */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
364 { 0, 1, 0 }, /* 0 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
365 { -1, 3, 5 }, /* 101 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
366 { 1, 3, 7 }, /* 111 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
367 { -2, 4, 9 }, /* 1001 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
368 { -3, 5, 17 }, /* 10001 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
369 { 2, 5, 27 }, /* 11011 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
370 { -4, 6, 33 }, /* 100001 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
371 { 99, 6, 50 }, /* 110010 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
372 { 3, 6, 51 }, /* 110011 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
373 { 99, 6, 52 }, /* 110100 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
374 { -7, 7, 65 }, /* 1000001 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
375 { 99, 7, 96 }, /* 1100000 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
376 { 99, 7, 98 }, /* 1100010 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
377 { 7, 7, 99 }, /* 1100011 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
378 { 4, 7, 107 }, /* 1101011 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
379 { -5, 8, 129 }, /* 10000001 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
380 { 99, 8, 194 }, /* 11000010 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
381 { 5, 8, 195 }, /* 11000011 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
382 { 99, 8, 212 }, /* 11010100 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
383 { 99, 9, 256 }, /* 100000000 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
384 { -6, 9, 257 }, /* 100000001 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
385 { 99, 9, 426 }, /* 110101010 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
386 { 6, 9, 427 }, /* 110101011 */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
387 { 99, 10, 0 } /* Shouldn't come this far */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
388 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
389
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
390 static rvlc_huff_table book_escape[] = {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
391 /*index length codeword */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
392 { 1, 2, 0 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
393 { 0, 2, 2 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
394 { 3, 3, 2 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
395 { 2, 3, 6 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
396 { 4, 4, 14 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
397 { 7, 5, 13 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
398 { 6, 5, 15 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
399 { 5, 5, 31 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
400 { 11, 6, 24 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
401 { 10, 6, 25 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
402 { 9, 6, 29 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
403 { 8, 6, 61 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
404 { 13, 7, 56 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
405 { 12, 7, 120 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
406 { 15, 8, 114 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
407 { 14, 8, 242 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
408 { 17, 9, 230 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
409 { 16, 9, 486 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
410 { 19, 10, 463 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
411 { 18, 10, 974 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
412 { 22, 11, 925 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
413 { 20, 11, 1950 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
414 { 21, 11, 1951 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
415 { 23, 12, 1848 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
416 { 25, 13, 3698 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
417 { 24, 14, 7399 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
418 { 26, 15, 14797 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
419 { 49, 19, 236736 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
420 { 50, 19, 236737 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
421 { 51, 19, 236738 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
422 { 52, 19, 236739 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
423 { 53, 19, 236740 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
424 { 27, 20, 473482 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
425 { 28, 20, 473483 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
426 { 29, 20, 473484 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
427 { 30, 20, 473485 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
428 { 31, 20, 473486 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
429 { 32, 20, 473487 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
430 { 33, 20, 473488 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
431 { 34, 20, 473489 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
432 { 35, 20, 473490 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
433 { 36, 20, 473491 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
434 { 37, 20, 473492 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
435 { 38, 20, 473493 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
436 { 39, 20, 473494 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
437 { 40, 20, 473495 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
438 { 41, 20, 473496 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
439 { 42, 20, 473497 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
440 { 43, 20, 473498 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
441 { 44, 20, 473499 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
442 { 45, 20, 473500 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
443 { 46, 20, 473501 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
444 { 47, 20, 473502 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
445 { 48, 20, 473503 },
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
446 { 99, 21, 0 } /* Shouldn't come this far */
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
447 };
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
448
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
449 static int8_t rvlc_huffman_sf(bitfile *ld_sf, bitfile *ld_esc,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
450 int8_t direction)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
451 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
452 uint8_t i, j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
453 int8_t index;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
454 uint32_t cw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
455 rvlc_huff_table *h = book_rvlc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
456
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
457 i = h->len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
458 if (direction > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
459 cw = faad_getbits(ld_sf, i DEBUGVAR(1,0,""));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
460 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
461 cw = faad_getbits_rev(ld_sf, i DEBUGVAR(1,0,""));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
462
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
463 while ((cw != h->cw)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
464 && (i < 10))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
465 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
466 h++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
467 j = h->len-i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
468 i += j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
469 cw <<= j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
470 if (direction > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
471 cw |= faad_getbits(ld_sf, j DEBUGVAR(1,0,""));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
472 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
473 cw |= faad_getbits_rev(ld_sf, j DEBUGVAR(1,0,""));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
474 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
475
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
476 index = h->index;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
477
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
478 if (index == +ESC_VAL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
479 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
480 int8_t esc = rvlc_huffman_esc(ld_esc, direction);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
481 if (esc == 99)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
482 return 99;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
483 index += esc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
484 #ifdef PRINT_RVLC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
485 printf("esc: %d - ", esc);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
486 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
487 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
488 if (index == -ESC_VAL)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
489 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
490 int8_t esc = rvlc_huffman_esc(ld_esc, direction);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
491 if (esc == 99)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
492 return 99;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
493 index -= esc;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
494 #ifdef PRINT_RVLC
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
495 printf("esc: %d - ", esc);
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
496 #endif
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
497 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
498
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
499 return index;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
500 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
501
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
502 static int8_t rvlc_huffman_esc(bitfile *ld,
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
503 int8_t direction)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
504 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
505 uint8_t i, j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
506 uint32_t cw;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
507 rvlc_huff_table *h = book_escape;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
508
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
509 i = h->len;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
510 if (direction > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
511 cw = faad_getbits(ld, i DEBUGVAR(1,0,""));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
512 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
513 cw = faad_getbits_rev(ld, i DEBUGVAR(1,0,""));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
514
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
515 while ((cw != h->cw)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
516 && (i < 21))
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
517 {
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
518 h++;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
519 j = h->len-i;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
520 i += j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
521 cw <<= j;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
522 if (direction > 0)
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
523 cw |= faad_getbits(ld, j DEBUGVAR(1,0,""));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
524 else
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
525 cw |= faad_getbits_rev(ld, j DEBUGVAR(1,0,""));
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
526 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
527
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
528 return h->index;
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
529 }
e989150f8216 libfaad2 v2.0rc1 imported
arpi
parents:
diff changeset
530
12527
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
531 #endif
4a370c80fe5c update to the 2.0 release of faad, patch by adland
diego
parents: 10989
diff changeset
532