annotate libfaad2/rvlc.c @ 12314:c81c4930cadc

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